'Write the image *data* of size *height* x *width*, as grayscale
if *grayscale* is true and RGB otherwise, as pdf object *id*
and with the soft mask (alpha channel) *smask*, which should be
either None or a *height* x *width* x 1 array.'

def _writeImg(self, data, height, width, grayscale, id, smask=None):

    obj = {u'Type': Name(u'XObject'), u'Subtype': Name(u'Image'), u'Width': width, u'Height': height, u'ColorSpace': Name((u'DeviceGray' if grayscale else u'DeviceRGB')), u'BitsPerComponent': 8}
    if smask:
        obj[u'SMask'] = smask
    if rcParams[u'pdf.compression']:
        png = {u'Predictor': 10, u'Colors': (1 if grayscale else 3), u'Columns': width}
    else:
        png = None
    self.beginStream(id, self.reserveObject(u'length    of    image    stream'), obj, png=png)
    if png:
        self._writePng(data)
    else:
        self.currentstream.write(data.tostring())
    self.endStream()
