# Path: pdfminer/pdftypes.py
# LITERALS_DCT_DECODE = (LIT('DCTDecode'), LIT('DCT'))
# 
# Path: pdfminer/pdfcolor.py
# LITERAL_DEVICE_GRAY = LIT('DeviceGray')
# 
# Path: pdfminer/pdfcolor.py
# LITERAL_DEVICE_RGB = LIT('DeviceRGB')
# 
# Path: 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
    def write_line(self, y, data):
        self.fp.seek(self.pos1 - (y+1)*self.linesize)
        self.fp.write(data)
        return


##  ImageWriter
##
class ImageWriter:

    def __init__(self, outdir):
        self.outdir = outdir
        if not os.path.exists(self.outdir):
            os.makedirs(self.outdir)
        return

    def export_image(self, image):
        stream = image.stream
        filters = stream.get_filters()
        (width, height) = image.srcsize
        if len(filters) == 1 and filters[0][0] in LITERALS_DCT_DECODE:
            ext = '.jpg'
        elif (image.bits == 1 or
              image.bits == 8 and image.colorspace in (LITERAL_DEVICE_RGB, LITERAL_DEVICE_GRAY)):
            ext = '.%dx%d.bmp' % (width, height)
        else:
            ext = '.%d.%dx%d.img' % (image.bits, width, height)
        name = image.name+ext
        path = os.path.join(self.outdir, name)
        with open(path, 'wb') as fp:

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


# Path: 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

    def write_line(self, y, data):
        self.fp.seek(self.pos1 - (y+1)*self.linesize)
        self.fp.write(data)
        return


##  ImageWriter
##
class ImageWriter:

    def __init__(self, outdir):
        self.outdir = outdir
        if not os.path.exists(self.outdir):
            os.makedirs(self.outdir)
        return

    def export_image(self, image):
        stream = image.stream
        filters = stream.get_filters()
        (width, height) = image.srcsize
        if len(filters) == 1 and filters[0][0] in LITERALS_DCT_DECODE:
            ext = '.jpg'
        elif (image.bits == 1 or
              image.bits == 8 and image.colorspace in (LITERAL_DEVICE_RGB, LITERAL_DEVICE_GRAY)):
            ext = '.%dx%d.bmp' % (width, height)
        else:
            ext = '.%d.%dx%d.img' % (image.bits, width, height)
        name = image.name+ext
        path = os.path.join(self.outdir, name)
        with open(path, 'wb') as fp:

            if ext == '.jpg':