# Path: resources/lib/pdfminer/pdftypes.py
# LITERALS_DCT_DECODE = (LIT('DCTDecode'), LIT('DCT'))
# 
# Path: resources/lib/pdfminer/pdfcolor.py
# LITERAL_DEVICE_GRAY = LIT('DeviceGray')
# 
# Path: resources/lib/pdfminer/pdfcolor.py
# LITERAL_DEVICE_RGB = LIT('DeviceRGB')
# 
# Path: resources/lib/pdfminer/pdfcolor.py
# LITERAL_DEVICE_CMYK = LIT('DeviceCMYK')


import struct
import os
import os.path
from io import BytesIO
from .pdftypes import LITERALS_DCT_DECODE
from .pdfcolor import LITERAL_DEVICE_GRAY
from .pdfcolor import LITERAL_DEVICE_RGB
from .pdfcolor import LITERAL_DEVICE_CMYK
                from PIL import Image
                from PIL import ImageChops
            ext = '.%d.%dx%d.img' % (image.bits, width, height)
        name = image.name+ext
        path = os.path.join(self.outdir, name)
        fp = file(path, 'wb')
        if ext == '.jpg':
            raw_data = stream.get_rawdata()
            if LITERAL_DEVICE_CMYK in image.colorspace:
                ifp = BytesIO(raw_data)
                i = Image.open(ifp)
                i = ImageChops.invert(i)
                i = i.convert('RGB')
                i.save(fp, 'JPEG')
            else:
                fp.write(raw_data)
        elif image.bits == 1:
            bmp = BMPWriter(fp, 1, width, height)
            data = stream.get_data()
            i = 0
            width = (width+7)//8
            for y in xrange(height):
                bmp.write_line(y, data[i:i+width])
                i += width
        elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_RGB:
            bmp = BMPWriter(fp, 24, width, height)
            data = stream.get_data()
            i = 0
            width = width*3
            for y in xrange(height):
                bmp.write_line(y, data[i:i+width])
                i += width

# Path: resources/lib/pdfminer/pdftypes.py
# LITERALS_DCT_DECODE = (LIT('DCTDecode'), LIT('DCT'))
# 
# Path: resources/lib/pdfminer/pdfcolor.py
# LITERAL_DEVICE_GRAY = LIT('DeviceGray')
# 
# Path: resources/lib/pdfminer/pdfcolor.py
# LITERAL_DEVICE_RGB = LIT('DeviceRGB')
# 
# Path: resources/lib/pdfminer/pdfcolor.py
# LITERAL_DEVICE_CMYK = LIT('DeviceCMYK')


# Path: resources/lib/pdfminer/image.py
import struct
import os
import os.path
from io import BytesIO
from .pdftypes import LITERALS_DCT_DECODE
from .pdfcolor import LITERAL_DEVICE_GRAY
from .pdfcolor import LITERAL_DEVICE_RGB
from .pdfcolor import LITERAL_DEVICE_CMYK
                from PIL import Image
                from PIL import ImageChops

            ext = '.%d.%dx%d.img' % (image.bits, width, height)
        name = image.name+ext
        path = os.path.join(self.outdir, name)
        fp = file(path, 'wb')
        if ext == '.jpg':
            raw_data = stream.get_rawdata()
            if LITERAL_DEVICE_CMYK in image.colorspace:
                ifp = BytesIO(raw_data)
                i = Image.open(ifp)
                i = ImageChops.invert(i)
                i = i.convert('RGB')
                i.save(fp, 'JPEG')
            else:
                fp.write(raw_data)
        elif image.bits == 1:
            bmp = BMPWriter(fp, 1, width, height)
            data = stream.get_data()
            i = 0
            width = (width+7)//8
            for y in xrange(height):
                bmp.write_line(y, data[i:i+width])
                i += width
        elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_RGB:
            bmp = BMPWriter(fp, 24, width, height)
            data = stream.get_data()
            i = 0
            width = width*3
            for y in xrange(height):
                bmp.write_line(y, data[i:i+width])
                i += width

        elif image.bits == 8 and image.colorspace is LITERAL_DEVICE_GRAY: