Imaging.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /*
  2. * The Python Imaging Library
  3. * $Id$
  4. *
  5. * declarations for the imaging core library
  6. *
  7. * Copyright (c) 1997-2005 by Secret Labs AB
  8. * Copyright (c) 1995-2005 by Fredrik Lundh
  9. *
  10. * See the README file for information on usage and redistribution.
  11. */
  12. #include "ImPlatform.h"
  13. #if defined(__cplusplus)
  14. extern "C" {
  15. #endif
  16. #ifndef M_PI
  17. #define M_PI 3.1415926535897932384626433832795
  18. #endif
  19. /* -------------------------------------------------------------------- */
  20. /*
  21. * Image data organization:
  22. *
  23. * mode bytes byte order
  24. * -------------------------------
  25. * 1 1 1
  26. * L 1 L
  27. * P 1 P
  28. * I 4 I (32-bit integer, native byte order)
  29. * F 4 F (32-bit IEEE float, native byte order)
  30. * RGB 4 R, G, B, -
  31. * RGBA 4 R, G, B, A
  32. * CMYK 4 C, M, Y, K
  33. * YCbCr 4 Y, Cb, Cr, -
  34. * Lab 4 L, a, b, -
  35. *
  36. * experimental modes (incomplete):
  37. * LA 4 L, -, -, A
  38. * PA 4 P, -, -, A
  39. * I;16 2 I (16-bit integer, native byte order)
  40. *
  41. * "P" is an 8-bit palette mode, which should be mapped through the
  42. * palette member to get an output image. Check palette->mode to
  43. * find the corresponding "real" mode.
  44. *
  45. * For information on how to access Imaging objects from your own C
  46. * extensions, see http://www.effbot.org/zone/pil-extending.htm
  47. */
  48. /* Handles */
  49. typedef struct ImagingMemoryInstance* Imaging;
  50. typedef struct ImagingAccessInstance* ImagingAccess;
  51. typedef struct ImagingHistogramInstance* ImagingHistogram;
  52. typedef struct ImagingOutlineInstance* ImagingOutline;
  53. typedef struct ImagingPaletteInstance* ImagingPalette;
  54. /* handle magics (used with PyCObject). */
  55. #define IMAGING_MAGIC "PIL Imaging"
  56. /* pixel types */
  57. #define IMAGING_TYPE_UINT8 0
  58. #define IMAGING_TYPE_INT32 1
  59. #define IMAGING_TYPE_FLOAT32 2
  60. #define IMAGING_TYPE_SPECIAL 3 /* check mode for details */
  61. #define IMAGING_MODE_LENGTH 6+1 /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
  62. typedef struct {
  63. char *ptr;
  64. int size;
  65. } ImagingMemoryBlock;
  66. struct ImagingMemoryInstance {
  67. /* Format */
  68. char mode[IMAGING_MODE_LENGTH]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
  69. int type; /* Data type (IMAGING_TYPE_*) */
  70. int depth; /* Depth (ignored in this version) */
  71. int bands; /* Number of bands (1, 2, 3, or 4) */
  72. int xsize; /* Image dimension. */
  73. int ysize;
  74. /* Colour palette (for "P" images only) */
  75. ImagingPalette palette;
  76. /* Data pointers */
  77. UINT8 **image8; /* Set for 8-bit images (pixelsize=1). */
  78. INT32 **image32; /* Set for 32-bit images (pixelsize=4). */
  79. /* Internals */
  80. char **image; /* Actual raster data. */
  81. char *block; /* Set if data is allocated in a single block. */
  82. ImagingMemoryBlock *blocks; /* Memory blocks for pixel storage */
  83. int pixelsize; /* Size of a pixel, in bytes (1, 2 or 4) */
  84. int linesize; /* Size of a line, in bytes (xsize * pixelsize) */
  85. /* Virtual methods */
  86. void (*destroy)(Imaging im);
  87. };
  88. #define IMAGING_PIXEL_1(im,x,y) ((im)->image8[(y)][(x)])
  89. #define IMAGING_PIXEL_L(im,x,y) ((im)->image8[(y)][(x)])
  90. #define IMAGING_PIXEL_LA(im,x,y) ((im)->image[(y)][(x)*4])
  91. #define IMAGING_PIXEL_P(im,x,y) ((im)->image8[(y)][(x)])
  92. #define IMAGING_PIXEL_PA(im,x,y) ((im)->image[(y)][(x)*4])
  93. #define IMAGING_PIXEL_I(im,x,y) ((im)->image32[(y)][(x)])
  94. #define IMAGING_PIXEL_F(im,x,y) (((FLOAT32*)(im)->image32[y])[x])
  95. #define IMAGING_PIXEL_RGB(im,x,y) ((im)->image[(y)][(x)*4])
  96. #define IMAGING_PIXEL_RGBA(im,x,y) ((im)->image[(y)][(x)*4])
  97. #define IMAGING_PIXEL_CMYK(im,x,y) ((im)->image[(y)][(x)*4])
  98. #define IMAGING_PIXEL_YCbCr(im,x,y) ((im)->image[(y)][(x)*4])
  99. #define IMAGING_PIXEL_UINT8(im,x,y) ((im)->image8[(y)][(x)])
  100. #define IMAGING_PIXEL_INT32(im,x,y) ((im)->image32[(y)][(x)])
  101. #define IMAGING_PIXEL_FLOAT32(im,x,y) (((FLOAT32*)(im)->image32[y])[x])
  102. struct ImagingAccessInstance {
  103. const char* mode;
  104. void* (*line)(Imaging im, int x, int y);
  105. void (*get_pixel)(Imaging im, int x, int y, void* pixel);
  106. void (*put_pixel)(Imaging im, int x, int y, const void* pixel);
  107. };
  108. struct ImagingHistogramInstance {
  109. /* Format */
  110. char mode[IMAGING_MODE_LENGTH]; /* Band names (of corresponding source image) */
  111. int bands; /* Number of bands (1, 3, or 4) */
  112. /* Data */
  113. long *histogram; /* Histogram (bands*256 longs) */
  114. };
  115. struct ImagingPaletteInstance {
  116. /* Format */
  117. char mode[IMAGING_MODE_LENGTH]; /* Band names */
  118. /* Data */
  119. UINT8 palette[1024];/* Palette data (same format as image data) */
  120. INT16* cache; /* Palette cache (used for predefined palettes) */
  121. int keep_cache; /* This palette will be reused; keep cache */
  122. };
  123. typedef struct ImagingMemoryArena {
  124. int alignment; /* Alignment in memory of each line of an image */
  125. int block_size; /* Preferred block size, bytes */
  126. int blocks_max; /* Maximum number of cached blocks */
  127. int blocks_cached; /* Current number of blocks not associated with images */
  128. ImagingMemoryBlock *blocks_pool;
  129. int stats_new_count; /* Number of new allocated images */
  130. int stats_allocated_blocks; /* Number of allocated blocks */
  131. int stats_reused_blocks; /* Number of blocks which were retrieved from a pool */
  132. int stats_reallocated_blocks; /* Number of blocks which were actually reallocated after retrieving */
  133. int stats_freed_blocks; /* Number of freed blocks */
  134. } *ImagingMemoryArena;
  135. /* Objects */
  136. /* ------- */
  137. extern struct ImagingMemoryArena ImagingDefaultArena;
  138. extern int ImagingMemorySetBlocksMax(ImagingMemoryArena arena, int blocks_max);
  139. extern void ImagingMemoryClearCache(ImagingMemoryArena arena, int new_size);
  140. extern Imaging ImagingNew(const char* mode, int xsize, int ysize);
  141. extern Imaging ImagingNewDirty(const char* mode, int xsize, int ysize);
  142. extern Imaging ImagingNew2Dirty(const char* mode, Imaging imOut, Imaging imIn);
  143. extern void ImagingDelete(Imaging im);
  144. extern Imaging ImagingNewBlock(const char* mode, int xsize, int ysize);
  145. extern Imaging ImagingNewMap(const char* filename, int readonly,
  146. const char* mode, int xsize, int ysize);
  147. extern Imaging ImagingNewPrologue(const char *mode,
  148. int xsize, int ysize);
  149. extern Imaging ImagingNewPrologueSubtype(const char *mode,
  150. int xsize, int ysize,
  151. int structure_size);
  152. extern void ImagingCopyPalette(Imaging destination, Imaging source);
  153. extern void ImagingHistogramDelete(ImagingHistogram histogram);
  154. extern void ImagingAccessInit(void);
  155. extern ImagingAccess ImagingAccessNew(Imaging im);
  156. extern void _ImagingAccessDelete(Imaging im, ImagingAccess access);
  157. #define ImagingAccessDelete(im, access) /* nop, for now */
  158. extern ImagingPalette ImagingPaletteNew(const char *mode);
  159. extern ImagingPalette ImagingPaletteNewBrowser(void);
  160. extern ImagingPalette ImagingPaletteDuplicate(ImagingPalette palette);
  161. extern void ImagingPaletteDelete(ImagingPalette palette);
  162. extern int ImagingPaletteCachePrepare(ImagingPalette palette);
  163. extern void ImagingPaletteCacheUpdate(ImagingPalette palette,
  164. int r, int g, int b);
  165. extern void ImagingPaletteCacheDelete(ImagingPalette palette);
  166. #define ImagingPaletteCache(p, r, g, b)\
  167. p->cache[(r>>2) + (g>>2)*64 + (b>>2)*64*64]
  168. extern Imaging ImagingQuantize(Imaging im, int colours, int mode, int kmeans);
  169. /* Threading */
  170. /* --------- */
  171. typedef void* ImagingSectionCookie;
  172. extern void ImagingSectionEnter(ImagingSectionCookie* cookie);
  173. extern void ImagingSectionLeave(ImagingSectionCookie* cookie);
  174. /* Exceptions */
  175. /* ---------- */
  176. extern void* ImagingError_IOError(void);
  177. extern void* ImagingError_MemoryError(void);
  178. extern void* ImagingError_ModeError(void); /* maps to ValueError by default */
  179. extern void* ImagingError_Mismatch(void); /* maps to ValueError by default */
  180. extern void* ImagingError_ValueError(const char* message);
  181. extern void ImagingError_Clear(void);
  182. /* Transform callbacks */
  183. /* ------------------- */
  184. /* standard transforms */
  185. #define IMAGING_TRANSFORM_AFFINE 0
  186. #define IMAGING_TRANSFORM_PERSPECTIVE 2
  187. #define IMAGING_TRANSFORM_QUAD 3
  188. /* standard filters */
  189. #define IMAGING_TRANSFORM_NEAREST 0
  190. #define IMAGING_TRANSFORM_BOX 4
  191. #define IMAGING_TRANSFORM_BILINEAR 2
  192. #define IMAGING_TRANSFORM_HAMMING 5
  193. #define IMAGING_TRANSFORM_BICUBIC 3
  194. #define IMAGING_TRANSFORM_LANCZOS 1
  195. typedef int (*ImagingTransformMap)(double* X, double* Y,
  196. int x, int y, void* data);
  197. typedef int (*ImagingTransformFilter)(void* out, Imaging im,
  198. double x, double y);
  199. /* Image Manipulation Methods */
  200. /* -------------------------- */
  201. extern Imaging ImagingAlphaComposite(Imaging imIn1, Imaging imIn2);
  202. extern Imaging ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha);
  203. extern Imaging ImagingCopy(Imaging im);
  204. extern Imaging ImagingConvert(Imaging im, const char* mode, ImagingPalette palette, int dither);
  205. extern Imaging ImagingConvertInPlace(Imaging im, const char* mode);
  206. extern Imaging ImagingConvertMatrix(Imaging im, const char *mode, float m[]);
  207. extern Imaging ImagingConvertTransparent(Imaging im, const char *mode, int r, int g, int b);
  208. extern Imaging ImagingCrop(Imaging im, int x0, int y0, int x1, int y1);
  209. extern Imaging ImagingExpand(Imaging im, int x, int y, int mode);
  210. extern Imaging ImagingFill(Imaging im, const void* ink);
  211. extern int ImagingFill2(
  212. Imaging into, const void* ink, Imaging mask,
  213. int x0, int y0, int x1, int y1);
  214. extern Imaging ImagingFillBand(Imaging im, int band, int color);
  215. extern Imaging ImagingFillLinearGradient(const char* mode);
  216. extern Imaging ImagingFillRadialGradient(const char* mode);
  217. extern Imaging ImagingFilter(
  218. Imaging im, int xsize, int ysize, const FLOAT32* kernel,
  219. FLOAT32 offset);
  220. extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
  221. extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
  222. extern Imaging ImagingGaussianBlur(Imaging imOut, Imaging imIn, float radius,
  223. int passes);
  224. extern Imaging ImagingGetBand(Imaging im, int band);
  225. extern Imaging ImagingMerge(const char* mode, Imaging bands[4]);
  226. extern int ImagingSplit(Imaging im, Imaging bands[4]);
  227. extern int ImagingGetBBox(Imaging im, int bbox[4]);
  228. typedef struct { int x, y; INT32 count; INT32 pixel; } ImagingColorItem;
  229. extern ImagingColorItem* ImagingGetColors(Imaging im, int maxcolors,
  230. int *colors);
  231. extern int ImagingGetExtrema(Imaging im, void *extrema);
  232. extern int ImagingGetProjection(Imaging im, UINT8* xproj, UINT8* yproj);
  233. extern ImagingHistogram ImagingGetHistogram(
  234. Imaging im, Imaging mask, void *extrema);
  235. extern Imaging ImagingModeFilter(Imaging im, int size);
  236. extern Imaging ImagingNegative(Imaging im);
  237. extern Imaging ImagingOffset(Imaging im, int xoffset, int yoffset);
  238. extern int ImagingPaste(
  239. Imaging into, Imaging im, Imaging mask,
  240. int x0, int y0, int x1, int y1);
  241. extern Imaging ImagingPoint(
  242. Imaging im, const char* tablemode, const void* table);
  243. extern Imaging ImagingPointTransform(
  244. Imaging imIn, double scale, double offset);
  245. extern Imaging ImagingPutBand(Imaging im, Imaging imIn, int band);
  246. extern Imaging ImagingRankFilter(Imaging im, int size, int rank);
  247. extern Imaging ImagingRotate90(Imaging imOut, Imaging imIn);
  248. extern Imaging ImagingRotate180(Imaging imOut, Imaging imIn);
  249. extern Imaging ImagingRotate270(Imaging imOut, Imaging imIn);
  250. extern Imaging ImagingTranspose(Imaging imOut, Imaging imIn);
  251. extern Imaging ImagingTransverse(Imaging imOut, Imaging imIn);
  252. extern Imaging ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]);
  253. extern Imaging ImagingTransform(
  254. Imaging imOut, Imaging imIn, int method, int x0, int y0, int x1, int y1,
  255. double *a, int filter, int fill);
  256. extern Imaging ImagingUnsharpMask(
  257. Imaging imOut, Imaging im, float radius, int percent, int threshold);
  258. extern Imaging ImagingBoxBlur(Imaging imOut, Imaging imIn, float radius, int n);
  259. extern Imaging ImagingColorLUT3D_linear(Imaging imOut, Imaging imIn,
  260. int table_channels, int size1D, int size2D, int size3D, INT16* table);
  261. extern Imaging ImagingCopy2(Imaging imOut, Imaging imIn);
  262. extern Imaging ImagingConvert2(Imaging imOut, Imaging imIn);
  263. /* Channel operations */
  264. /* any mode, except "F" */
  265. extern Imaging ImagingChopLighter(Imaging imIn1, Imaging imIn2);
  266. extern Imaging ImagingChopDarker(Imaging imIn1, Imaging imIn2);
  267. extern Imaging ImagingChopDifference(Imaging imIn1, Imaging imIn2);
  268. extern Imaging ImagingChopMultiply(Imaging imIn1, Imaging imIn2);
  269. extern Imaging ImagingChopScreen(Imaging imIn1, Imaging imIn2);
  270. extern Imaging ImagingChopAdd(
  271. Imaging imIn1, Imaging imIn2, float scale, int offset);
  272. extern Imaging ImagingChopSubtract(
  273. Imaging imIn1, Imaging imIn2, float scale, int offset);
  274. extern Imaging ImagingChopAddModulo(Imaging imIn1, Imaging imIn2);
  275. extern Imaging ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2);
  276. /* "1" images only */
  277. extern Imaging ImagingChopAnd(Imaging imIn1, Imaging imIn2);
  278. extern Imaging ImagingChopOr(Imaging imIn1, Imaging imIn2);
  279. extern Imaging ImagingChopXor(Imaging imIn1, Imaging imIn2);
  280. /* Image measurement */
  281. extern void ImagingCrack(Imaging im, int x0, int y0);
  282. /* Graphics */
  283. extern int ImagingDrawArc(Imaging im, int x0, int y0, int x1, int y1,
  284. float start, float end, const void* ink, int width,
  285. int op);
  286. extern int ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap,
  287. const void* ink, int op);
  288. extern int ImagingDrawChord(Imaging im, int x0, int y0, int x1, int y1,
  289. float start, float end, const void* ink, int fill,
  290. int width, int op);
  291. extern int ImagingDrawEllipse(Imaging im, int x0, int y0, int x1, int y1,
  292. const void* ink, int fill, int width, int op);
  293. extern int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1,
  294. const void* ink, int op);
  295. extern int ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
  296. const void* ink, int width, int op);
  297. extern int ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1,
  298. float start, float end, const void* ink, int fill,
  299. int width, int op);
  300. extern int ImagingDrawPoint(Imaging im, int x, int y, const void* ink, int op);
  301. extern int ImagingDrawPolygon(Imaging im, int points, int *xy,
  302. const void* ink, int fill, int op);
  303. extern int ImagingDrawRectangle(Imaging im, int x0, int y0, int x1, int y1,
  304. const void* ink, int fill, int width, int op);
  305. /* Level 2 graphics (WORK IN PROGRESS) */
  306. extern ImagingOutline ImagingOutlineNew(void);
  307. extern void ImagingOutlineDelete(ImagingOutline outline);
  308. extern int ImagingDrawOutline(Imaging im, ImagingOutline outline,
  309. const void* ink, int fill, int op);
  310. extern int ImagingOutlineMove(ImagingOutline outline, float x, float y);
  311. extern int ImagingOutlineLine(ImagingOutline outline, float x, float y);
  312. extern int ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
  313. float x2, float y2, float x3, float y3);
  314. extern int ImagingOutlineTransform(ImagingOutline outline, double a[6]);
  315. extern int ImagingOutlineClose(ImagingOutline outline);
  316. /* Special effects */
  317. extern Imaging ImagingEffectSpread(Imaging imIn, int distance);
  318. extern Imaging ImagingEffectNoise(int xsize, int ysize, float sigma);
  319. extern Imaging ImagingEffectMandelbrot(int xsize, int ysize,
  320. double extent[4], int quality);
  321. /* Obsolete */
  322. extern int ImagingToString(Imaging im, int orientation, char *buffer);
  323. extern int ImagingFromString(Imaging im, int orientation, char *buffer);
  324. /* File I/O */
  325. /* -------- */
  326. /* Built-in drivers */
  327. extern Imaging ImagingOpenPPM(const char* filename);
  328. extern int ImagingSavePPM(Imaging im, const char* filename);
  329. /* Utility functions */
  330. extern UINT32 ImagingCRC32(UINT32 crc, UINT8* buffer, int bytes);
  331. /* Codecs */
  332. typedef struct ImagingCodecStateInstance *ImagingCodecState;
  333. typedef int (*ImagingCodec)(Imaging im, ImagingCodecState state,
  334. UINT8* buffer, int bytes);
  335. extern int ImagingBcnDecode(Imaging im, ImagingCodecState state,
  336. UINT8* buffer, Py_ssize_t bytes);
  337. extern int ImagingBitDecode(Imaging im, ImagingCodecState state,
  338. UINT8* buffer, Py_ssize_t bytes);
  339. extern int ImagingEpsEncode(Imaging im, ImagingCodecState state,
  340. UINT8* buffer, int bytes);
  341. extern int ImagingFliDecode(Imaging im, ImagingCodecState state,
  342. UINT8* buffer, Py_ssize_t bytes);
  343. extern int ImagingGifDecode(Imaging im, ImagingCodecState state,
  344. UINT8* buffer, Py_ssize_t bytes);
  345. extern int ImagingGifEncode(Imaging im, ImagingCodecState state,
  346. UINT8* buffer, int bytes);
  347. extern int ImagingHexDecode(Imaging im, ImagingCodecState state,
  348. UINT8* buffer, Py_ssize_t bytes);
  349. #ifdef HAVE_LIBJPEG
  350. extern int ImagingJpegDecode(Imaging im, ImagingCodecState state,
  351. UINT8* buffer, Py_ssize_t bytes);
  352. extern int ImagingJpegDecodeCleanup(ImagingCodecState state);
  353. extern int ImagingJpegUseJCSExtensions(void);
  354. extern int ImagingJpegEncode(Imaging im, ImagingCodecState state,
  355. UINT8* buffer, int bytes);
  356. #endif
  357. #ifdef HAVE_OPENJPEG
  358. extern int ImagingJpeg2KDecode(Imaging im, ImagingCodecState state,
  359. UINT8* buffer, Py_ssize_t bytes);
  360. extern int ImagingJpeg2KDecodeCleanup(ImagingCodecState state);
  361. extern int ImagingJpeg2KEncode(Imaging im, ImagingCodecState state,
  362. UINT8* buffer, int bytes);
  363. extern int ImagingJpeg2KEncodeCleanup(ImagingCodecState state);
  364. #endif
  365. #ifdef HAVE_LIBTIFF
  366. extern int ImagingLibTiffDecode(Imaging im, ImagingCodecState state,
  367. UINT8* buffer, Py_ssize_t bytes);
  368. extern int ImagingLibTiffEncode(Imaging im, ImagingCodecState state,
  369. UINT8* buffer, int bytes);
  370. #endif
  371. #ifdef HAVE_LIBMPEG
  372. extern int ImagingMpegDecode(Imaging im, ImagingCodecState state,
  373. UINT8* buffer, Py_ssize_t bytes);
  374. #endif
  375. extern int ImagingMspDecode(Imaging im, ImagingCodecState state,
  376. UINT8* buffer, Py_ssize_t bytes);
  377. extern int ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
  378. UINT8* buffer, Py_ssize_t bytes);
  379. extern int ImagingPcdDecode(Imaging im, ImagingCodecState state,
  380. UINT8* buffer, Py_ssize_t bytes);
  381. extern int ImagingPcxDecode(Imaging im, ImagingCodecState state,
  382. UINT8* buffer, Py_ssize_t bytes);
  383. extern int ImagingPcxEncode(Imaging im, ImagingCodecState state,
  384. UINT8* buffer, int bytes);
  385. extern int ImagingRawDecode(Imaging im, ImagingCodecState state,
  386. UINT8* buffer, Py_ssize_t bytes);
  387. extern int ImagingRawEncode(Imaging im, ImagingCodecState state,
  388. UINT8* buffer, int bytes);
  389. extern int ImagingSgiRleDecode(Imaging im, ImagingCodecState state,
  390. UINT8* buffer, Py_ssize_t bytes);
  391. extern int ImagingSgiRleDecodeCleanup(ImagingCodecState state);
  392. extern int ImagingSunRleDecode(Imaging im, ImagingCodecState state,
  393. UINT8* buffer, Py_ssize_t bytes);
  394. extern int ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
  395. UINT8* buffer, Py_ssize_t bytes);
  396. extern int ImagingTgaRleEncode(Imaging im, ImagingCodecState state,
  397. UINT8* buffer, int bytes);
  398. extern int ImagingXbmDecode(Imaging im, ImagingCodecState state,
  399. UINT8* buffer, Py_ssize_t bytes);
  400. extern int ImagingXbmEncode(Imaging im, ImagingCodecState state,
  401. UINT8* buffer, int bytes);
  402. #ifdef HAVE_LIBZ
  403. extern int ImagingZipDecode(Imaging im, ImagingCodecState state,
  404. UINT8* buffer, Py_ssize_t bytes);
  405. extern int ImagingZipDecodeCleanup(ImagingCodecState state);
  406. extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
  407. UINT8* buffer, int bytes);
  408. extern int ImagingZipEncodeCleanup(ImagingCodecState state);
  409. #endif
  410. typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels);
  411. /* Public shufflers */
  412. extern void ImagingPackBGR(UINT8* out, const UINT8* in, int pixels);
  413. extern void ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels);
  414. extern void ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels);
  415. extern void ImagingConvertRGB2YCbCr(UINT8* out, const UINT8* in, int pixels);
  416. extern void ImagingConvertYCbCr2RGB(UINT8* out, const UINT8* in, int pixels);
  417. extern ImagingShuffler ImagingFindUnpacker(const char* mode,
  418. const char* rawmode, int* bits_out);
  419. extern ImagingShuffler ImagingFindPacker(const char* mode,
  420. const char* rawmode, int* bits_out);
  421. struct ImagingCodecStateInstance {
  422. int count;
  423. int state;
  424. int errcode;
  425. int x, y;
  426. int ystep;
  427. int xsize, ysize, xoff, yoff;
  428. ImagingShuffler shuffle;
  429. int bits, bytes;
  430. UINT8 *buffer;
  431. void *context;
  432. PyObject *fd;
  433. };
  434. /* Codec read/write python fd */
  435. extern Py_ssize_t _imaging_read_pyFd(PyObject *fd, char* dest, Py_ssize_t bytes);
  436. extern Py_ssize_t _imaging_write_pyFd(PyObject *fd, char* src, Py_ssize_t bytes);
  437. extern int _imaging_seek_pyFd(PyObject *fd, Py_ssize_t offset, int whence);
  438. extern Py_ssize_t _imaging_tell_pyFd(PyObject *fd);
  439. /* Errcodes */
  440. #define IMAGING_CODEC_END 1
  441. #define IMAGING_CODEC_OVERRUN -1
  442. #define IMAGING_CODEC_BROKEN -2
  443. #define IMAGING_CODEC_UNKNOWN -3
  444. #define IMAGING_CODEC_CONFIG -8
  445. #define IMAGING_CODEC_MEMORY -9
  446. #include "ImagingUtils.h"
  447. extern UINT8 *clip8_lookups;
  448. #if defined(__cplusplus)
  449. }
  450. #endif