# # THIS IS WORK IN PROGRESS # # The Python Imaging Library. # $Id$ # # FlashPix support for PIL # # History: # 97-01-25 fl Created (reads uncompressed RGB images only) # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # import olefile from . import Image, ImageFile from ._binary import i8 from ._binary import i32le as i32 # we map from colour field tuples to (mode, rawmode) descriptors MODES = { # opacity (0x00007FFE): ("A", "L"), # monochrome (0x00010000,): ("L", "L"), (0x00018000, 0x00017FFE): ("RGBA", "LA"), # photo YCC (0x00020000, 0x00020001, 0x00020002): ("RGB", "YCC;P"), (0x00028000, 0x00028001, 0x00028002, 0x00027FFE): ("RGBA", "YCCA;P"), # standard RGB (NIFRGB) (0x00030000, 0x00030001, 0x00030002): ("RGB", "RGB"), (0x00038000, 0x00038001, 0x00038002, 0x00037FFE): ("RGBA", "RGBA"), } # # -------------------------------------------------------------------- def _accept(prefix): return prefix[:8] == olefile.MAGIC ## # Image plugin for the FlashPix images. class FpxImageFile(ImageFile.ImageFile): format = "FPX" format_description = "FlashPix" def _open(self): # # read the OLE directory and see if this is a likely # to be a FlashPix file try: self.ole = olefile.OleFileIO(self.fp) except OSError as e: raise SyntaxError("not an FPX file; invalid OLE file") from e if self.ole.root.clsid != "56616700-C154-11CE-8553-00AA00A1F95B": raise SyntaxError("not an FPX file; bad root CLSID") self._open_index(1) def _open_index(self, index=1): # # get the Image Contents Property Set prop = self.ole.getproperties( [f"Data Object Store {index:06d}", "\005Image Contents"] ) # size (highest resolution) self._size = prop[0x1000002], prop[0x1000003] size = max(self.size) i = 1 while size > 64: size = size / 2 i += 1 self.maxid = i - 1 # mode. instead of using a single field for this, flashpix # requires you to specify the mode for each channel in each # resolution subimage, and leaves it to the decoder to make # sure that they all match. for now, we'll cheat and assume # that this is always the case. id = self.maxid << 16 s = prop[0x2000002 | id] colors = [] bands = i32(s, 4) if bands > 4: raise OSError("Invalid number of bands") for i in range(bands): # note: for now, we ignore the "uncalibrated" flag colors.append(i32(s, 8 + i * 4) & 0x7FFFFFFF) self.mode, self.rawmode = MODES[tuple(colors)] # load JPEG tables, if any self.jpeg = {} for i in range(256): id = 0x3000001 | (i << 16) if id in prop: self.jpeg[i] = prop[id] self._open_subimage(1, self.maxid) def _open_subimage(self, index=1, subimage=0): # # setup tile descriptors for a given subimage stream = [ f"Data Object Store {index:06d}", f"Resolution {subimage:04d}", "Subimage 0000 Header", ] fp = self.ole.openstream(stream) # skip prefix fp.read(28) # header stream s = fp.read(36) size = i32(s, 4), i32(s, 8) # tilecount = i32(s, 12) tilesize = i32(s, 16), i32(s, 20) # channels = i32(s, 24) offset = i32(s, 28) length = i32(s, 32) if size != self.size: raise OSError("subimage mismatch") # get tile descriptors fp.seek(28 + offset) s = fp.read(i32(s, 12) * length) x = y = 0 xsize, ysize = size xtile, ytile = tilesize self.tile = [] for i in range(0, len(s), length): compression = i32(s, i + 8) if compression == 0: self.tile.append( ( "raw", (x, y, x + xtile, y + ytile), i32(s, i) + 28, (self.rawmode), ) ) elif compression == 1: # FIXME: the fill decoder is not implemented self.tile.append( ( "fill", (x, y, x + xtile, y + ytile), i32(s, i) + 28, (self.rawmode, s[12:16]), ) ) elif compression == 2: internal_color_conversion = i8(s[14]) jpeg_tables = i8(s[15]) rawmode = self.rawmode if internal_color_conversion: # The image is stored as usual (usually YCbCr). if rawmode == "RGBA": # For "RGBA", data is stored as YCbCrA based on # negative RGB. The following trick works around # this problem : jpegmode, rawmode = "YCbCrK", "CMYK" else: jpegmode = None # let the decoder decide else: # The image is stored as defined by rawmode jpegmode = rawmode self.tile.append( ( "jpeg", (x, y, x + xtile, y + ytile), i32(s, i) + 28, (rawmode, jpegmode), ) ) # FIXME: jpeg tables are tile dependent; the prefix # data must be placed in the tile descriptor itself! if jpeg_tables: self.tile_prefix = self.jpeg[jpeg_tables] else: raise OSError("unknown/invalid compression") x = x + xtile if x >= xsize: x, y = 0, y + ytile if y >= ysize: break # isn't really required self.stream = stream self.fp = None def load(self): if not self.fp: self.fp = self.ole.openstream(self.stream[:2] + ["Subimage 0000 Data"]) return ImageFile.ImageFile.load(self) # # -------------------------------------------------------------------- Image.register_open(FpxImageFile.format, FpxImageFile, _accept) Image.register_extension(FpxImageFile.format, ".fpx")
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 2755 |
|
|
BdfFontFile.py | File | 2.75 KB | 0644 |
|
BlpImagePlugin.py | File | 14 KB | 0644 |
|
BmpImagePlugin.py | File | 13.92 KB | 0644 |
|
BufrStubImagePlugin.py | File | 1.48 KB | 0644 |
|
ContainerIO.py | File | 2.82 KB | 0644 |
|
CurImagePlugin.py | File | 1.68 KB | 0644 |
|
DcxImagePlugin.py | File | 2.09 KB | 0644 |
|
DdsImagePlugin.py | File | 5.34 KB | 0644 |
|
EpsImagePlugin.py | File | 11.82 KB | 0644 |
|
ExifTags.py | File | 8.8 KB | 0644 |
|
FitsStubImagePlugin.py | File | 1.59 KB | 0644 |
|
FliImagePlugin.py | File | 4.23 KB | 0644 |
|
FontFile.py | File | 2.7 KB | 0644 |
|
FpxImagePlugin.py | File | 6.53 KB | 0644 |
|
FtexImagePlugin.py | File | 3.23 KB | 0644 |
|
GbrImagePlugin.py | File | 2.73 KB | 0644 |
|
GdImageFile.py | File | 2.47 KB | 0644 |
|
GifImagePlugin.py | File | 28.25 KB | 0644 |
|
GimpGradientFile.py | File | 3.27 KB | 0644 |
|
GimpPaletteFile.py | File | 1.24 KB | 0644 |
|
GribStubImagePlugin.py | File | 1.51 KB | 0644 |
|
Hdf5StubImagePlugin.py | File | 1.48 KB | 0644 |
|
IcnsImagePlugin.py | File | 11.44 KB | 0644 |
|
IcoImagePlugin.py | File | 9.94 KB | 0644 |
|
ImImagePlugin.py | File | 10.53 KB | 0644 |
|
Image.py | File | 113.4 KB | 0644 |
|
ImageChops.py | File | 7.13 KB | 0644 |
|
ImageCms.py | File | 36.22 KB | 0644 |
|
ImageColor.py | File | 8.44 KB | 0644 |
|
ImageDraw.py | File | 29.94 KB | 0644 |
|
ImageDraw2.py | File | 4.9 KB | 0644 |
|
ImageEnhance.py | File | 3.12 KB | 0644 |
|
ImageFile.py | File | 20.74 KB | 0644 |
|
ImageFilter.py | File | 15.46 KB | 0644 |
|
ImageFont.py | File | 43.49 KB | 0644 |
|
ImageGrab.py | File | 3.54 KB | 0644 |
|
ImageMath.py | File | 6.88 KB | 0644 |
|
ImageMode.py | File | 1.6 KB | 0644 |
|
ImageMorph.py | File | 7.67 KB | 0644 |
|
ImageOps.py | File | 18.03 KB | 0644 |
|
ImagePalette.py | File | 6.2 KB | 0644 |
|
ImagePath.py | File | 336 B | 0644 |
|
ImageQt.py | File | 5.67 KB | 0644 |
|
ImageSequence.py | File | 1.81 KB | 0644 |
|
ImageShow.py | File | 6.15 KB | 0644 |
|
ImageStat.py | File | 3.81 KB | 0644 |
|
ImageTk.py | File | 9.11 KB | 0644 |
|
ImageTransform.py | File | 2.78 KB | 0644 |
|
ImageWin.py | File | 7.02 KB | 0644 |
|
ImtImagePlugin.py | File | 2.15 KB | 0644 |
|
IptcImagePlugin.py | File | 5.6 KB | 0644 |
|
Jpeg2KImagePlugin.py | File | 8.52 KB | 0644 |
|
JpegImagePlugin.py | File | 27.16 KB | 0644 |
|
JpegPresets.py | File | 12.41 KB | 0644 |
|
McIdasImagePlugin.py | File | 1.71 KB | 0644 |
|
MicImagePlugin.py | File | 2.54 KB | 0644 |
|
MpegImagePlugin.py | File | 1.76 KB | 0644 |
|
MpoImagePlugin.py | File | 4.14 KB | 0644 |
|
MspImagePlugin.py | File | 5.43 KB | 0644 |
|
PSDraw.py | File | 6.51 KB | 0644 |
|
PaletteFile.py | File | 1.08 KB | 0644 |
|
PalmImagePlugin.py | File | 8.89 KB | 0644 |
|
PcdImagePlugin.py | File | 1.47 KB | 0644 |
|
PcfFontFile.py | File | 6.2 KB | 0644 |
|
PcxImagePlugin.py | File | 5.41 KB | 0644 |
|
PdfImagePlugin.py | File | 7.49 KB | 0644 |
|
PdfParser.py | File | 33.58 KB | 0644 |
|
PixarImagePlugin.py | File | 1.61 KB | 0644 |
|
PngImagePlugin.py | File | 42.79 KB | 0644 |
|
PpmImagePlugin.py | File | 4.34 KB | 0644 |
|
PsdImagePlugin.py | File | 7.56 KB | 0644 |
|
PyAccess.py | File | 9.37 KB | 0644 |
|
SgiImagePlugin.py | File | 5.96 KB | 0644 |
|
SpiderImagePlugin.py | File | 9.31 KB | 0644 |
|
SunImagePlugin.py | File | 4.2 KB | 0644 |
|
TarIO.py | File | 1.41 KB | 0644 |
|
TgaImagePlugin.py | File | 6.18 KB | 0644 |
|
TiffImagePlugin.py | File | 66.86 KB | 0644 |
|
TiffTags.py | File | 14.22 KB | 0644 |
|
WalImageFile.py | File | 5.4 KB | 0644 |
|
WebPImagePlugin.py | File | 10.54 KB | 0644 |
|
WmfImagePlugin.py | File | 4.56 KB | 0644 |
|
XVThumbImagePlugin.py | File | 1.9 KB | 0644 |
|
XbmImagePlugin.py | File | 2.37 KB | 0644 |
|
XpmImagePlugin.py | File | 3 KB | 0644 |
|
__init__.py | File | 3.18 KB | 0644 |
|
__main__.py | File | 41 B | 0644 |
|
_binary.py | File | 1.75 KB | 0644 |
|
_imaging.cpython-36m-x86_64-linux-gnu.so | File | 650.13 KB | 0755 |
|
_imagingcms.cpython-36m-x86_64-linux-gnu.so | File | 38.05 KB | 0755 |
|
_imagingft.cpython-36m-x86_64-linux-gnu.so | File | 41.98 KB | 0755 |
|
_imagingmath.cpython-36m-x86_64-linux-gnu.so | File | 24.43 KB | 0755 |
|
_imagingmorph.cpython-36m-x86_64-linux-gnu.so | File | 8.12 KB | 0755 |
|
_imagingtk.cpython-36m-x86_64-linux-gnu.so | File | 9.37 KB | 0755 |
|
_tkinter_finder.py | File | 224 B | 0644 |
|
_util.py | File | 359 B | 0644 |
|
_version.py | File | 50 B | 0644 |
|
_webp.cpython-36m-x86_64-linux-gnu.so | File | 40.82 KB | 0755 |
|
features.py | File | 8.8 KB | 0644 |
|