Imaging.h 21 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. struct ImagingMemoryInstance {
  63. /* Format */
  64. char mode[IMAGING_MODE_LENGTH]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
  65. int type; /* Data type (IMAGING_TYPE_*) */
  66. int depth; /* Depth (ignored in this version) */
  67. int bands; /* Number of bands (1, 2, 3, or 4) */
  68. int xsize; /* Image dimension. */
  69. int ysize;
  70. /* Colour palette (for "P" images only) */
  71. ImagingPalette palette;
  72. /* Data pointers */
  73. UINT8 **image8; /* Set for 8-bit images (pixelsize=1). */
  74. INT32 **image32; /* Set for 32-bit images (pixelsize=4). */
  75. /* Internals */
  76. char **image; /* Actual raster data. */
  77. char *block; /* Set if data is allocated in a single block. */
  78. int pixelsize; /* Size of a pixel, in bytes (1, 2 or 4) */
  79. int linesize; /* Size of a line, in bytes (xsize * pixelsize) */
  80. /* Virtual methods */
  81. void (*destroy)(Imaging im);
  82. };
  83. #define IMAGING_PIXEL_1(im,x,y) ((im)->image8[(y)][(x)])
  84. #define IMAGING_PIXEL_L(im,x,y) ((im)->image8[(y)][(x)])
  85. #define IMAGING_PIXEL_LA(im,x,y) ((im)->image[(y)][(x)*4])
  86. #define IMAGING_PIXEL_P(im,x,y) ((im)->image8[(y)][(x)])
  87. #define IMAGING_PIXEL_PA(im,x,y) ((im)->image[(y)][(x)*4])
  88. #define IMAGING_PIXEL_I(im,x,y) ((im)->image32[(y)][(x)])
  89. #define IMAGING_PIXEL_F(im,x,y) (((FLOAT32*)(im)->image32[y])[x])
  90. #define IMAGING_PIXEL_RGB(im,x,y) ((im)->image[(y)][(x)*4])
  91. #define IMAGING_PIXEL_RGBA(im,x,y) ((im)->image[(y)][(x)*4])
  92. #define IMAGING_PIXEL_CMYK(im,x,y) ((im)->image[(y)][(x)*4])
  93. #define IMAGING_PIXEL_YCbCr(im,x,y) ((im)->image[(y)][(x)*4])
  94. #define IMAGING_PIXEL_UINT8(im,x,y) ((im)->image8[(y)][(x)])
  95. #define IMAGING_PIXEL_INT32(im,x,y) ((im)->image32[(y)][(x)])
  96. #define IMAGING_PIXEL_FLOAT32(im,x,y) (((FLOAT32*)(im)->image32[y])[x])
  97. struct ImagingAccessInstance {
  98. const char* mode;
  99. void* (*line)(Imaging im, int x, int y);
  100. void (*get_pixel)(Imaging im, int x, int y, void* pixel);
  101. void (*put_pixel)(Imaging im, int x, int y, const void* pixel);
  102. };
  103. struct ImagingHistogramInstance {
  104. /* Format */
  105. char mode[IMAGING_MODE_LENGTH]; /* Band names (of corresponding source image) */
  106. int bands; /* Number of bands (1, 3, or 4) */
  107. /* Data */
  108. long *histogram; /* Histogram (bands*256 longs) */
  109. };
  110. struct ImagingPaletteInstance {
  111. /* Format */
  112. char mode[IMAGING_MODE_LENGTH]; /* Band names */
  113. /* Data */
  114. UINT8 palette[1024];/* Palette data (same format as image data) */
  115. INT16* cache; /* Palette cache (used for predefined palettes) */
  116. int keep_cache; /* This palette will be reused; keep cache */
  117. };
  118. /* Objects */
  119. /* ------- */
  120. extern int ImagingNewCount;
  121. extern Imaging ImagingNew(const char* mode, int xsize, int ysize);
  122. extern Imaging ImagingNew2(const char* mode, Imaging imOut, Imaging imIn);
  123. extern void ImagingDelete(Imaging im);
  124. extern Imaging ImagingNewBlock(const char* mode, int xsize, int ysize);
  125. extern Imaging ImagingNewArray(const char* mode, int xsize, int ysize);
  126. extern Imaging ImagingNewMap(const char* filename, int readonly,
  127. const char* mode, int xsize, int ysize);
  128. extern Imaging ImagingNewPrologue(const char *mode,
  129. unsigned xsize, unsigned ysize);
  130. extern Imaging ImagingNewPrologueSubtype(const char *mode,
  131. unsigned xsize, unsigned ysize,
  132. int structure_size);
  133. extern Imaging ImagingNewEpilogue(Imaging im);
  134. extern void ImagingCopyInfo(Imaging destination, Imaging source);
  135. extern void ImagingHistogramDelete(ImagingHistogram histogram);
  136. extern void ImagingAccessInit(void);
  137. extern ImagingAccess ImagingAccessNew(Imaging im);
  138. extern void _ImagingAccessDelete(Imaging im, ImagingAccess access);
  139. #define ImagingAccessDelete(im, access) /* nop, for now */
  140. /*#define ImagingAccessDelete(im, access) \
  141. ((access)->dynamic ? _ImagingAccessDelete((im), (access)), 0 : 0)) */
  142. extern ImagingPalette ImagingPaletteNew(const char *mode);
  143. extern ImagingPalette ImagingPaletteNewBrowser(void);
  144. extern ImagingPalette ImagingPaletteDuplicate(ImagingPalette palette);
  145. extern void ImagingPaletteDelete(ImagingPalette palette);
  146. extern int ImagingPaletteCachePrepare(ImagingPalette palette);
  147. extern void ImagingPaletteCacheUpdate(ImagingPalette palette,
  148. int r, int g, int b);
  149. extern void ImagingPaletteCacheDelete(ImagingPalette palette);
  150. #define ImagingPaletteCache(p, r, g, b)\
  151. p->cache[(r>>2) + (g>>2)*64 + (b>>2)*64*64]
  152. extern Imaging ImagingQuantize(Imaging im, int colours, int mode, int kmeans);
  153. /* Threading */
  154. /* --------- */
  155. typedef void* ImagingSectionCookie;
  156. extern void ImagingSectionEnter(ImagingSectionCookie* cookie);
  157. extern void ImagingSectionLeave(ImagingSectionCookie* cookie);
  158. /* Exceptions */
  159. /* ---------- */
  160. extern void* ImagingError_IOError(void);
  161. extern void* ImagingError_MemoryError(void);
  162. extern void* ImagingError_ModeError(void); /* maps to ValueError by default */
  163. extern void* ImagingError_Mismatch(void); /* maps to ValueError by default */
  164. extern void* ImagingError_ValueError(const char* message);
  165. extern void ImagingError_Clear(void);
  166. /* Transform callbacks */
  167. /* ------------------- */
  168. /* standard transforms */
  169. #define IMAGING_TRANSFORM_AFFINE 0
  170. #define IMAGING_TRANSFORM_PERSPECTIVE 2
  171. #define IMAGING_TRANSFORM_QUAD 3
  172. /* standard filters */
  173. #define IMAGING_TRANSFORM_NEAREST 0
  174. #define IMAGING_TRANSFORM_LANCZOS 1
  175. #define IMAGING_TRANSFORM_BILINEAR 2
  176. #define IMAGING_TRANSFORM_BICUBIC 3
  177. typedef int (*ImagingTransformMap)(double* X, double* Y,
  178. int x, int y, void* data);
  179. typedef int (*ImagingTransformFilter)(void* out, Imaging im,
  180. double x, double y,
  181. void* data);
  182. /* Image Manipulation Methods */
  183. /* -------------------------- */
  184. extern Imaging ImagingAlphaComposite(Imaging imIn1, Imaging imIn2);
  185. extern Imaging ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha);
  186. extern Imaging ImagingCopy(Imaging im);
  187. extern Imaging ImagingConvert(Imaging im, const char* mode, ImagingPalette palette, int dither);
  188. extern Imaging ImagingConvertInPlace(Imaging im, const char* mode);
  189. extern Imaging ImagingConvertMatrix(Imaging im, const char *mode, float m[]);
  190. extern Imaging ImagingConvertTransparent(Imaging im, const char *mode, int r, int g, int b);
  191. extern Imaging ImagingCrop(Imaging im, int x0, int y0, int x1, int y1);
  192. extern Imaging ImagingExpand(Imaging im, int x, int y, int mode);
  193. extern Imaging ImagingFill(Imaging im, const void* ink);
  194. extern int ImagingFill2(
  195. Imaging into, const void* ink, Imaging mask,
  196. int x0, int y0, int x1, int y1);
  197. extern Imaging ImagingFillBand(Imaging im, int band, int color);
  198. extern Imaging ImagingFillLinearGradient(const char* mode);
  199. extern Imaging ImagingFillRadialGradient(const char* mode);
  200. extern Imaging ImagingFilter(
  201. Imaging im, int xsize, int ysize, const FLOAT32* kernel,
  202. FLOAT32 offset, FLOAT32 divisor);
  203. extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
  204. extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
  205. extern Imaging ImagingGaussianBlur(Imaging imOut, Imaging imIn, float radius,
  206. int passes);
  207. extern Imaging ImagingGetBand(Imaging im, int band);
  208. extern int ImagingGetBBox(Imaging im, int bbox[4]);
  209. typedef struct { int x, y; INT32 count; INT32 pixel; } ImagingColorItem;
  210. extern ImagingColorItem* ImagingGetColors(Imaging im, int maxcolors,
  211. int *colors);
  212. extern int ImagingGetExtrema(Imaging im, void *extrema);
  213. extern int ImagingGetProjection(Imaging im, UINT8* xproj, UINT8* yproj);
  214. extern ImagingHistogram ImagingGetHistogram(
  215. Imaging im, Imaging mask, void *extrema);
  216. extern Imaging ImagingModeFilter(Imaging im, int size);
  217. extern Imaging ImagingNegative(Imaging im);
  218. extern Imaging ImagingOffset(Imaging im, int xoffset, int yoffset);
  219. extern int ImagingPaste(
  220. Imaging into, Imaging im, Imaging mask,
  221. int x0, int y0, int x1, int y1);
  222. extern Imaging ImagingPoint(
  223. Imaging im, const char* tablemode, const void* table);
  224. extern Imaging ImagingPointTransform(
  225. Imaging imIn, double scale, double offset);
  226. extern Imaging ImagingPutBand(Imaging im, Imaging imIn, int band);
  227. extern Imaging ImagingRankFilter(Imaging im, int size, int rank);
  228. extern Imaging ImagingRotate(
  229. Imaging imOut, Imaging imIn, double theta, int filter);
  230. extern Imaging ImagingRotate90(Imaging imOut, Imaging imIn);
  231. extern Imaging ImagingRotate180(Imaging imOut, Imaging imIn);
  232. extern Imaging ImagingRotate270(Imaging imOut, Imaging imIn);
  233. extern Imaging ImagingResample(Imaging imIn, int xsize, int ysize, int filter);
  234. extern Imaging ImagingTranspose(Imaging imOut, Imaging imIn);
  235. extern Imaging ImagingTransposeToNew(Imaging imIn);
  236. extern Imaging ImagingTransformPerspective(
  237. Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1,
  238. double a[8], int filter, int fill);
  239. extern Imaging ImagingTransformAffine(
  240. Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1,
  241. double a[6], int filter, int fill);
  242. extern Imaging ImagingTransformQuad(
  243. Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1,
  244. double a[8], int filter, int fill);
  245. extern Imaging ImagingTransform(
  246. Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1,
  247. ImagingTransformMap transform, void* transform_data,
  248. ImagingTransformFilter filter, void* filter_data,
  249. int fill);
  250. extern Imaging ImagingUnsharpMask(
  251. Imaging imOut, Imaging im, float radius, int percent, int threshold);
  252. extern Imaging ImagingBoxBlur(Imaging imOut, Imaging imIn, float radius, int n);
  253. extern Imaging ImagingCopy2(Imaging imOut, Imaging imIn);
  254. extern Imaging ImagingConvert2(Imaging imOut, Imaging imIn);
  255. /* Channel operations */
  256. /* any mode, except "F" */
  257. extern Imaging ImagingChopLighter(Imaging imIn1, Imaging imIn2);
  258. extern Imaging ImagingChopDarker(Imaging imIn1, Imaging imIn2);
  259. extern Imaging ImagingChopDifference(Imaging imIn1, Imaging imIn2);
  260. extern Imaging ImagingChopMultiply(Imaging imIn1, Imaging imIn2);
  261. extern Imaging ImagingChopScreen(Imaging imIn1, Imaging imIn2);
  262. extern Imaging ImagingChopAdd(
  263. Imaging imIn1, Imaging imIn2, float scale, int offset);
  264. extern Imaging ImagingChopSubtract(
  265. Imaging imIn1, Imaging imIn2, float scale, int offset);
  266. extern Imaging ImagingChopAddModulo(Imaging imIn1, Imaging imIn2);
  267. extern Imaging ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2);
  268. /* "1" images only */
  269. extern Imaging ImagingChopAnd(Imaging imIn1, Imaging imIn2);
  270. extern Imaging ImagingChopOr(Imaging imIn1, Imaging imIn2);
  271. extern Imaging ImagingChopXor(Imaging imIn1, Imaging imIn2);
  272. /* Image measurement */
  273. extern void ImagingCrack(Imaging im, int x0, int y0);
  274. /* Graphics */
  275. struct ImagingAffineMatrixInstance {
  276. float a[9];
  277. };
  278. typedef struct ImagingAffineMatrixInstance *ImagingAffineMatrix;
  279. extern int ImagingDrawArc(Imaging im, int x0, int y0, int x1, int y1,
  280. float start, float end, const void* ink, int op);
  281. extern int ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap,
  282. const void* ink, int op);
  283. extern int ImagingDrawChord(Imaging im, int x0, int y0, int x1, int y1,
  284. float start, float end, const void* ink, int fill,
  285. int op);
  286. extern int ImagingDrawEllipse(Imaging im, int x0, int y0, int x1, int y1,
  287. const void* ink, int fill, int op);
  288. extern int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1,
  289. const void* ink, int op);
  290. extern int ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
  291. const void* ink, int width, int op);
  292. extern int ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1,
  293. float start, float end, const void* ink, int fill,
  294. int op);
  295. extern int ImagingDrawPoint(Imaging im, int x, int y, const void* ink, int op);
  296. extern int ImagingDrawPolygon(Imaging im, int points, int *xy,
  297. const void* ink, int fill, int op);
  298. extern int ImagingDrawRectangle(Imaging im, int x0, int y0, int x1, int y1,
  299. const void* ink, int fill, int op);
  300. /* Level 2 graphics (WORK IN PROGRESS) */
  301. extern ImagingOutline ImagingOutlineNew(void);
  302. extern void ImagingOutlineDelete(ImagingOutline outline);
  303. extern int ImagingDrawOutline(Imaging im, ImagingOutline outline,
  304. const void* ink, int fill, int op);
  305. extern int ImagingOutlineMove(ImagingOutline outline, float x, float y);
  306. extern int ImagingOutlineLine(ImagingOutline outline, float x, float y);
  307. extern int ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
  308. float x2, float y2, float x3, float y3);
  309. extern int ImagingOutlineTransform(ImagingOutline outline, double a[6]);
  310. extern int ImagingOutlineClose(ImagingOutline outline);
  311. /* Special effects */
  312. extern Imaging ImagingEffectSpread(Imaging imIn, int distance);
  313. extern Imaging ImagingEffectNoise(int xsize, int ysize, float sigma);
  314. extern Imaging ImagingEffectMandelbrot(int xsize, int ysize,
  315. double extent[4], int quality);
  316. /* Obsolete */
  317. extern int ImagingToString(Imaging im, int orientation, char *buffer);
  318. extern int ImagingFromString(Imaging im, int orientation, char *buffer);
  319. /* File I/O */
  320. /* -------- */
  321. /* Built-in drivers */
  322. extern Imaging ImagingOpenPPM(const char* filename);
  323. extern int ImagingSavePPM(Imaging im, const char* filename);
  324. /* Utility functions */
  325. extern UINT32 ImagingCRC32(UINT32 crc, UINT8* buffer, int bytes);
  326. /* Codecs */
  327. typedef struct ImagingCodecStateInstance *ImagingCodecState;
  328. typedef int (*ImagingCodec)(Imaging im, ImagingCodecState state,
  329. UINT8* buffer, int bytes);
  330. extern int ImagingBitDecode(Imaging im, ImagingCodecState state,
  331. UINT8* buffer, int bytes);
  332. extern int ImagingEpsEncode(Imaging im, ImagingCodecState state,
  333. UINT8* buffer, int bytes);
  334. extern int ImagingFliDecode(Imaging im, ImagingCodecState state,
  335. UINT8* buffer, int bytes);
  336. extern int ImagingGifDecode(Imaging im, ImagingCodecState state,
  337. UINT8* buffer, int bytes);
  338. extern int ImagingGifEncode(Imaging im, ImagingCodecState state,
  339. UINT8* buffer, int bytes);
  340. extern int ImagingHexDecode(Imaging im, ImagingCodecState state,
  341. UINT8* buffer, int bytes);
  342. #ifdef HAVE_LIBJPEG
  343. extern int ImagingJpegDecode(Imaging im, ImagingCodecState state,
  344. UINT8* buffer, int bytes);
  345. extern int ImagingJpegDecodeCleanup(ImagingCodecState state);
  346. extern int ImagingJpegEncode(Imaging im, ImagingCodecState state,
  347. UINT8* buffer, int bytes);
  348. #endif
  349. #ifdef HAVE_OPENJPEG
  350. extern int ImagingJpeg2KDecode(Imaging im, ImagingCodecState state,
  351. UINT8* buffer, int bytes);
  352. extern int ImagingJpeg2KDecodeCleanup(ImagingCodecState state);
  353. extern int ImagingJpeg2KEncode(Imaging im, ImagingCodecState state,
  354. UINT8* buffer, int bytes);
  355. extern int ImagingJpeg2KEncodeCleanup(ImagingCodecState state);
  356. #endif
  357. extern int ImagingLzwDecode(Imaging im, ImagingCodecState state,
  358. UINT8* buffer, int bytes);
  359. #ifdef HAVE_LIBTIFF
  360. extern int ImagingLibTiffDecode(Imaging im, ImagingCodecState state,
  361. UINT8* buffer, int bytes);
  362. extern int ImagingLibTiffEncode(Imaging im, ImagingCodecState state,
  363. UINT8* buffer, int bytes);
  364. #endif
  365. #ifdef HAVE_LIBMPEG
  366. extern int ImagingMpegDecode(Imaging im, ImagingCodecState state,
  367. UINT8* buffer, int bytes);
  368. #endif
  369. extern int ImagingMspDecode(Imaging im, ImagingCodecState state,
  370. UINT8* buffer, int bytes);
  371. extern int ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
  372. UINT8* buffer, int bytes);
  373. extern int ImagingPcdDecode(Imaging im, ImagingCodecState state,
  374. UINT8* buffer, int bytes);
  375. extern int ImagingPcxDecode(Imaging im, ImagingCodecState state,
  376. UINT8* buffer, int bytes);
  377. extern int ImagingPcxEncode(Imaging im, ImagingCodecState state,
  378. UINT8* buffer, int bytes);
  379. extern int ImagingRawDecode(Imaging im, ImagingCodecState state,
  380. UINT8* buffer, int bytes);
  381. extern int ImagingRawEncode(Imaging im, ImagingCodecState state,
  382. UINT8* buffer, int bytes);
  383. extern int ImagingSunRleDecode(Imaging im, ImagingCodecState state,
  384. UINT8* buffer, int bytes);
  385. extern int ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
  386. UINT8* buffer, int bytes);
  387. extern int ImagingXbmDecode(Imaging im, ImagingCodecState state,
  388. UINT8* buffer, int bytes);
  389. extern int ImagingXbmEncode(Imaging im, ImagingCodecState state,
  390. UINT8* buffer, int bytes);
  391. #ifdef HAVE_LIBZ
  392. extern int ImagingZipDecode(Imaging im, ImagingCodecState state,
  393. UINT8* buffer, int bytes);
  394. extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
  395. UINT8* buffer, int bytes);
  396. #endif
  397. typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels);
  398. /* Public shufflers */
  399. extern void ImagingPackRGB(UINT8* out, const UINT8* in, int pixels);
  400. extern void ImagingPackBGR(UINT8* out, const UINT8* in, int pixels);
  401. extern void ImagingUnpackRGB(UINT8* out, const UINT8* in, int pixels);
  402. extern void ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels);
  403. extern void ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels);
  404. extern void ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels);
  405. extern void ImagingUnpackYCbCr(UINT8* out, const UINT8* in, int pixels);
  406. extern void ImagingConvertRGB2YCbCr(UINT8* out, const UINT8* in, int pixels);
  407. extern void ImagingConvertYCbCr2RGB(UINT8* out, const UINT8* in, int pixels);
  408. extern ImagingShuffler ImagingFindUnpacker(const char* mode,
  409. const char* rawmode, int* bits_out);
  410. extern ImagingShuffler ImagingFindPacker(const char* mode,
  411. const char* rawmode, int* bits_out);
  412. struct ImagingCodecStateInstance {
  413. int count;
  414. int state;
  415. int errcode;
  416. int x, y;
  417. int ystep;
  418. int xsize, ysize, xoff, yoff;
  419. ImagingShuffler shuffle;
  420. int bits, bytes;
  421. UINT8 *buffer;
  422. void *context;
  423. };
  424. /* Incremental encoding/decoding support */
  425. typedef struct ImagingIncrementalCodecStruct *ImagingIncrementalCodec;
  426. typedef int (*ImagingIncrementalCodecEntry)(Imaging im,
  427. ImagingCodecState state,
  428. ImagingIncrementalCodec codec);
  429. enum {
  430. INCREMENTAL_CODEC_READ = 1,
  431. INCREMENTAL_CODEC_WRITE = 2
  432. };
  433. enum {
  434. INCREMENTAL_CODEC_NOT_SEEKABLE = 0,
  435. INCREMENTAL_CODEC_SEEKABLE = 1
  436. };
  437. extern ImagingIncrementalCodec ImagingIncrementalCodecCreate(ImagingIncrementalCodecEntry codec_entry, Imaging im, ImagingCodecState state, int read_or_write, int seekable, int fd);
  438. extern void ImagingIncrementalCodecDestroy(ImagingIncrementalCodec codec);
  439. extern int ImagingIncrementalCodecPushBuffer(ImagingIncrementalCodec codec, UINT8 *buf, int bytes);
  440. extern Py_ssize_t ImagingIncrementalCodecRead(ImagingIncrementalCodec codec, void *buffer, size_t bytes);
  441. extern off_t ImagingIncrementalCodecSkip(ImagingIncrementalCodec codec, off_t bytes);
  442. extern Py_ssize_t ImagingIncrementalCodecWrite(ImagingIncrementalCodec codec, const void *buffer, size_t bytes);
  443. extern off_t ImagingIncrementalCodecSeek(ImagingIncrementalCodec codec, off_t bytes);
  444. extern size_t ImagingIncrementalCodecBytesInBuffer(ImagingIncrementalCodec codec);
  445. /* Errcodes */
  446. #define IMAGING_CODEC_END 1
  447. #define IMAGING_CODEC_OVERRUN -1
  448. #define IMAGING_CODEC_BROKEN -2
  449. #define IMAGING_CODEC_UNKNOWN -3
  450. #define IMAGING_CODEC_CONFIG -8
  451. #define IMAGING_CODEC_MEMORY -9
  452. #if defined(__cplusplus)
  453. }
  454. #endif