Imaging.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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 \
  62. 6 + 1 /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
  63. typedef struct {
  64. char *ptr;
  65. int size;
  66. } ImagingMemoryBlock;
  67. struct ImagingMemoryInstance {
  68. /* Format */
  69. char mode[IMAGING_MODE_LENGTH]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK",
  70. "YCbCr", "BGR;xy") */
  71. int type; /* Data type (IMAGING_TYPE_*) */
  72. int depth; /* Depth (ignored in this version) */
  73. int bands; /* Number of bands (1, 2, 3, or 4) */
  74. int xsize; /* Image dimension. */
  75. int ysize;
  76. /* Colour palette (for "P" images only) */
  77. ImagingPalette palette;
  78. /* Data pointers */
  79. UINT8 **image8; /* Set for 8-bit images (pixelsize=1). */
  80. INT32 **image32; /* Set for 32-bit images (pixelsize=4). */
  81. /* Internals */
  82. char **image; /* Actual raster data. */
  83. char *block; /* Set if data is allocated in a single block. */
  84. ImagingMemoryBlock *blocks; /* Memory blocks for pixel storage */
  85. int pixelsize; /* Size of a pixel, in bytes (1, 2 or 4) */
  86. int linesize; /* Size of a line, in bytes (xsize * pixelsize) */
  87. /* Virtual methods */
  88. void (*destroy)(Imaging im);
  89. };
  90. #define IMAGING_PIXEL_1(im, x, y) ((im)->image8[(y)][(x)])
  91. #define IMAGING_PIXEL_L(im, x, y) ((im)->image8[(y)][(x)])
  92. #define IMAGING_PIXEL_LA(im, x, y) ((im)->image[(y)][(x)*4])
  93. #define IMAGING_PIXEL_P(im, x, y) ((im)->image8[(y)][(x)])
  94. #define IMAGING_PIXEL_PA(im, x, y) ((im)->image[(y)][(x)*4])
  95. #define IMAGING_PIXEL_I(im, x, y) ((im)->image32[(y)][(x)])
  96. #define IMAGING_PIXEL_F(im, x, y) (((FLOAT32 *)(im)->image32[y])[x])
  97. #define IMAGING_PIXEL_RGB(im, x, y) ((im)->image[(y)][(x)*4])
  98. #define IMAGING_PIXEL_RGBA(im, x, y) ((im)->image[(y)][(x)*4])
  99. #define IMAGING_PIXEL_CMYK(im, x, y) ((im)->image[(y)][(x)*4])
  100. #define IMAGING_PIXEL_YCbCr(im, x, y) ((im)->image[(y)][(x)*4])
  101. #define IMAGING_PIXEL_UINT8(im, x, y) ((im)->image8[(y)][(x)])
  102. #define IMAGING_PIXEL_INT32(im, x, y) ((im)->image32[(y)][(x)])
  103. #define IMAGING_PIXEL_FLOAT32(im, x, y) (((FLOAT32 *)(im)->image32[y])[x])
  104. struct ImagingAccessInstance {
  105. const char *mode;
  106. void (*get_pixel)(Imaging im, int x, int y, void *pixel);
  107. void (*put_pixel)(Imaging im, int x, int y, const void *pixel);
  108. };
  109. struct ImagingHistogramInstance {
  110. /* Format */
  111. char mode[IMAGING_MODE_LENGTH]; /* Band names (of corresponding source image) */
  112. int bands; /* Number of bands (1, 3, or 4) */
  113. /* Data */
  114. long *histogram; /* Histogram (bands*256 longs) */
  115. };
  116. struct ImagingPaletteInstance {
  117. /* Format */
  118. char mode[IMAGING_MODE_LENGTH]; /* Band names */
  119. /* Data */
  120. int size;
  121. UINT8 palette[1024]; /* Palette data (same format as image data) */
  122. INT16 *cache; /* Palette cache (used for predefined palettes) */
  123. int keep_cache; /* This palette will be reused; keep cache */
  124. };
  125. typedef struct ImagingMemoryArena {
  126. int alignment; /* Alignment in memory of each line of an image */
  127. int block_size; /* Preferred block size, bytes */
  128. int blocks_max; /* Maximum number of cached blocks */
  129. int blocks_cached; /* Current number of blocks not associated with images */
  130. ImagingMemoryBlock *blocks_pool;
  131. int stats_new_count; /* Number of new allocated images */
  132. int stats_allocated_blocks; /* Number of allocated blocks */
  133. int stats_reused_blocks; /* Number of blocks which were retrieved from a pool */
  134. int stats_reallocated_blocks; /* Number of blocks which were actually reallocated
  135. after retrieving */
  136. int stats_freed_blocks; /* Number of freed blocks */
  137. } * ImagingMemoryArena;
  138. /* Objects */
  139. /* ------- */
  140. extern struct ImagingMemoryArena ImagingDefaultArena;
  141. extern int
  142. ImagingMemorySetBlocksMax(ImagingMemoryArena arena, int blocks_max);
  143. extern void
  144. ImagingMemoryClearCache(ImagingMemoryArena arena, int new_size);
  145. extern Imaging
  146. ImagingNew(const char *mode, int xsize, int ysize);
  147. extern Imaging
  148. ImagingNewDirty(const char *mode, int xsize, int ysize);
  149. extern Imaging
  150. ImagingNew2Dirty(const char *mode, Imaging imOut, Imaging imIn);
  151. extern void
  152. ImagingDelete(Imaging im);
  153. extern Imaging
  154. ImagingNewBlock(const char *mode, int xsize, int ysize);
  155. extern Imaging
  156. ImagingNewPrologue(const char *mode, int xsize, int ysize);
  157. extern Imaging
  158. ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int structure_size);
  159. extern void
  160. ImagingCopyPalette(Imaging destination, Imaging source);
  161. extern void
  162. ImagingHistogramDelete(ImagingHistogram histogram);
  163. extern void
  164. ImagingAccessInit(void);
  165. extern ImagingAccess
  166. ImagingAccessNew(Imaging im);
  167. extern void
  168. _ImagingAccessDelete(Imaging im, ImagingAccess access);
  169. #define ImagingAccessDelete(im, access) /* nop, for now */
  170. extern ImagingPalette
  171. ImagingPaletteNew(const char *mode);
  172. extern ImagingPalette
  173. ImagingPaletteNewBrowser(void);
  174. extern ImagingPalette
  175. ImagingPaletteDuplicate(ImagingPalette palette);
  176. extern void
  177. ImagingPaletteDelete(ImagingPalette palette);
  178. extern int
  179. ImagingPaletteCachePrepare(ImagingPalette palette);
  180. extern void
  181. ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b);
  182. extern void
  183. ImagingPaletteCacheDelete(ImagingPalette palette);
  184. #define ImagingPaletteCache(p, r, g, b) \
  185. p->cache[(r >> 2) + (g >> 2) * 64 + (b >> 2) * 64 * 64]
  186. extern Imaging
  187. ImagingQuantize(Imaging im, int colours, int mode, int kmeans);
  188. /* Threading */
  189. /* --------- */
  190. typedef void *ImagingSectionCookie;
  191. extern void
  192. ImagingSectionEnter(ImagingSectionCookie *cookie);
  193. extern void
  194. ImagingSectionLeave(ImagingSectionCookie *cookie);
  195. /* Exceptions */
  196. /* ---------- */
  197. extern void *
  198. ImagingError_OSError(void);
  199. extern void *
  200. ImagingError_MemoryError(void);
  201. extern void *
  202. ImagingError_ModeError(void); /* maps to ValueError by default */
  203. extern void *
  204. ImagingError_Mismatch(void); /* maps to ValueError by default */
  205. extern void *
  206. ImagingError_ValueError(const char *message);
  207. extern void
  208. ImagingError_Clear(void);
  209. /* Transform callbacks */
  210. /* ------------------- */
  211. /* standard transforms */
  212. #define IMAGING_TRANSFORM_AFFINE 0
  213. #define IMAGING_TRANSFORM_PERSPECTIVE 2
  214. #define IMAGING_TRANSFORM_QUAD 3
  215. /* standard filters */
  216. #define IMAGING_TRANSFORM_NEAREST 0
  217. #define IMAGING_TRANSFORM_BOX 4
  218. #define IMAGING_TRANSFORM_BILINEAR 2
  219. #define IMAGING_TRANSFORM_HAMMING 5
  220. #define IMAGING_TRANSFORM_BICUBIC 3
  221. #define IMAGING_TRANSFORM_LANCZOS 1
  222. typedef int (*ImagingTransformMap)(double *X, double *Y, int x, int y, void *data);
  223. typedef int (*ImagingTransformFilter)(void *out, Imaging im, double x, double y);
  224. /* Image Manipulation Methods */
  225. /* -------------------------- */
  226. extern Imaging
  227. ImagingAlphaComposite(Imaging imIn1, Imaging imIn2);
  228. extern Imaging
  229. ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha);
  230. extern Imaging
  231. ImagingCopy(Imaging im);
  232. extern Imaging
  233. ImagingConvert(Imaging im, const char *mode, ImagingPalette palette, int dither);
  234. extern Imaging
  235. ImagingConvertInPlace(Imaging im, const char *mode);
  236. extern Imaging
  237. ImagingConvertMatrix(Imaging im, const char *mode, float m[]);
  238. extern Imaging
  239. ImagingConvertTransparent(Imaging im, const char *mode, int r, int g, int b);
  240. extern Imaging
  241. ImagingCrop(Imaging im, int x0, int y0, int x1, int y1);
  242. extern Imaging
  243. ImagingExpand(Imaging im, int x, int y);
  244. extern Imaging
  245. ImagingFill(Imaging im, const void *ink);
  246. extern int
  247. ImagingFill2(
  248. Imaging into, const void *ink, Imaging mask, int x0, int y0, int x1, int y1);
  249. extern Imaging
  250. ImagingFillBand(Imaging im, int band, int color);
  251. extern Imaging
  252. ImagingFillLinearGradient(const char *mode);
  253. extern Imaging
  254. ImagingFillRadialGradient(const char *mode);
  255. extern Imaging
  256. ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32 *kernel, FLOAT32 offset);
  257. extern Imaging
  258. ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
  259. extern Imaging
  260. ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
  261. extern Imaging
  262. ImagingGaussianBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int passes);
  263. extern Imaging
  264. ImagingGetBand(Imaging im, int band);
  265. extern Imaging
  266. ImagingMerge(const char *mode, Imaging bands[4]);
  267. extern int
  268. ImagingSplit(Imaging im, Imaging bands[4]);
  269. extern int
  270. ImagingGetBBox(Imaging im, int bbox[4], int alpha_only);
  271. typedef struct {
  272. int x, y;
  273. INT32 count;
  274. INT32 pixel;
  275. } ImagingColorItem;
  276. extern ImagingColorItem *
  277. ImagingGetColors(Imaging im, int maxcolors, int *colors);
  278. extern int
  279. ImagingGetExtrema(Imaging im, void *extrema);
  280. extern int
  281. ImagingGetProjection(Imaging im, UINT8 *xproj, UINT8 *yproj);
  282. extern ImagingHistogram
  283. ImagingGetHistogram(Imaging im, Imaging mask, void *extrema);
  284. extern Imaging
  285. ImagingModeFilter(Imaging im, int size);
  286. extern Imaging
  287. ImagingNegative(Imaging im);
  288. extern Imaging
  289. ImagingOffset(Imaging im, int xoffset, int yoffset);
  290. extern int
  291. ImagingPaste(Imaging into, Imaging im, Imaging mask, int x0, int y0, int x1, int y1);
  292. extern Imaging
  293. ImagingPoint(Imaging im, const char *tablemode, const void *table);
  294. extern Imaging
  295. ImagingPointTransform(Imaging imIn, double scale, double offset);
  296. extern Imaging
  297. ImagingPutBand(Imaging im, Imaging imIn, int band);
  298. extern Imaging
  299. ImagingRankFilter(Imaging im, int size, int rank);
  300. extern Imaging
  301. ImagingRotate90(Imaging imOut, Imaging imIn);
  302. extern Imaging
  303. ImagingRotate180(Imaging imOut, Imaging imIn);
  304. extern Imaging
  305. ImagingRotate270(Imaging imOut, Imaging imIn);
  306. extern Imaging
  307. ImagingTranspose(Imaging imOut, Imaging imIn);
  308. extern Imaging
  309. ImagingTransverse(Imaging imOut, Imaging imIn);
  310. extern Imaging
  311. ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]);
  312. extern Imaging
  313. ImagingReduce(Imaging imIn, int xscale, int yscale, int box[4]);
  314. extern Imaging
  315. ImagingTransform(
  316. Imaging imOut,
  317. Imaging imIn,
  318. int method,
  319. int x0,
  320. int y0,
  321. int x1,
  322. int y1,
  323. double a[8],
  324. int filter,
  325. int fill);
  326. extern Imaging
  327. ImagingUnsharpMask(Imaging imOut, Imaging im, float radius, int percent, int threshold);
  328. extern Imaging
  329. ImagingBoxBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int n);
  330. extern Imaging
  331. ImagingColorLUT3D_linear(
  332. Imaging imOut,
  333. Imaging imIn,
  334. int table_channels,
  335. int size1D,
  336. int size2D,
  337. int size3D,
  338. INT16 *table);
  339. extern Imaging
  340. ImagingCopy2(Imaging imOut, Imaging imIn);
  341. extern Imaging
  342. ImagingConvert2(Imaging imOut, Imaging imIn);
  343. /* Channel operations */
  344. /* any mode, except "F" */
  345. extern Imaging
  346. ImagingChopLighter(Imaging imIn1, Imaging imIn2);
  347. extern Imaging
  348. ImagingChopDarker(Imaging imIn1, Imaging imIn2);
  349. extern Imaging
  350. ImagingChopDifference(Imaging imIn1, Imaging imIn2);
  351. extern Imaging
  352. ImagingChopMultiply(Imaging imIn1, Imaging imIn2);
  353. extern Imaging
  354. ImagingChopScreen(Imaging imIn1, Imaging imIn2);
  355. extern Imaging
  356. ImagingChopAdd(Imaging imIn1, Imaging imIn2, float scale, int offset);
  357. extern Imaging
  358. ImagingChopSubtract(Imaging imIn1, Imaging imIn2, float scale, int offset);
  359. extern Imaging
  360. ImagingChopAddModulo(Imaging imIn1, Imaging imIn2);
  361. extern Imaging
  362. ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2);
  363. extern Imaging
  364. ImagingChopSoftLight(Imaging imIn1, Imaging imIn2);
  365. extern Imaging
  366. ImagingChopHardLight(Imaging imIn1, Imaging imIn2);
  367. extern Imaging
  368. ImagingOverlay(Imaging imIn1, Imaging imIn2);
  369. /* "1" images only */
  370. extern Imaging
  371. ImagingChopAnd(Imaging imIn1, Imaging imIn2);
  372. extern Imaging
  373. ImagingChopOr(Imaging imIn1, Imaging imIn2);
  374. extern Imaging
  375. ImagingChopXor(Imaging imIn1, Imaging imIn2);
  376. /* Graphics */
  377. extern int
  378. ImagingDrawArc(
  379. Imaging im,
  380. int x0,
  381. int y0,
  382. int x1,
  383. int y1,
  384. float start,
  385. float end,
  386. const void *ink,
  387. int width,
  388. int op);
  389. extern int
  390. ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap, const void *ink, int op);
  391. extern int
  392. ImagingDrawChord(
  393. Imaging im,
  394. int x0,
  395. int y0,
  396. int x1,
  397. int y1,
  398. float start,
  399. float end,
  400. const void *ink,
  401. int fill,
  402. int width,
  403. int op);
  404. extern int
  405. ImagingDrawEllipse(
  406. Imaging im,
  407. int x0,
  408. int y0,
  409. int x1,
  410. int y1,
  411. const void *ink,
  412. int fill,
  413. int width,
  414. int op);
  415. extern int
  416. ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void *ink, int op);
  417. extern int
  418. ImagingDrawWideLine(
  419. Imaging im, int x0, int y0, int x1, int y1, const void *ink, int width, int op);
  420. extern int
  421. ImagingDrawPieslice(
  422. Imaging im,
  423. int x0,
  424. int y0,
  425. int x1,
  426. int y1,
  427. float start,
  428. float end,
  429. const void *ink,
  430. int fill,
  431. int width,
  432. int op);
  433. extern int
  434. ImagingDrawPoint(Imaging im, int x, int y, const void *ink, int op);
  435. extern int
  436. ImagingDrawPolygon(Imaging im, int points, int *xy, const void *ink, int fill, int width, int op);
  437. extern int
  438. ImagingDrawRectangle(
  439. Imaging im,
  440. int x0,
  441. int y0,
  442. int x1,
  443. int y1,
  444. const void *ink,
  445. int fill,
  446. int width,
  447. int op);
  448. /* Level 2 graphics (WORK IN PROGRESS) */
  449. extern ImagingOutline
  450. ImagingOutlineNew(void);
  451. extern void
  452. ImagingOutlineDelete(ImagingOutline outline);
  453. extern int
  454. ImagingDrawOutline(
  455. Imaging im, ImagingOutline outline, const void *ink, int fill, int op);
  456. extern int
  457. ImagingOutlineMove(ImagingOutline outline, float x, float y);
  458. extern int
  459. ImagingOutlineLine(ImagingOutline outline, float x, float y);
  460. extern int
  461. ImagingOutlineCurve(
  462. ImagingOutline outline, float x1, float y1, float x2, float y2, float x3, float y3);
  463. extern int
  464. ImagingOutlineTransform(ImagingOutline outline, double a[6]);
  465. extern int
  466. ImagingOutlineClose(ImagingOutline outline);
  467. /* Special effects */
  468. extern Imaging
  469. ImagingEffectSpread(Imaging imIn, int distance);
  470. extern Imaging
  471. ImagingEffectNoise(int xsize, int ysize, float sigma);
  472. extern Imaging
  473. ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality);
  474. /* File I/O */
  475. /* -------- */
  476. /* Built-in drivers */
  477. extern Imaging
  478. ImagingOpenPPM(const char *filename);
  479. extern int
  480. ImagingSavePPM(Imaging im, const char *filename);
  481. /* Codecs */
  482. typedef struct ImagingCodecStateInstance *ImagingCodecState;
  483. typedef int (*ImagingCodec)(
  484. Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  485. extern int
  486. ImagingBcnDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  487. extern int
  488. ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  489. extern int
  490. ImagingEpsEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  491. extern int
  492. ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  493. extern int
  494. ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  495. extern int
  496. ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  497. extern int
  498. ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  499. #ifdef HAVE_LIBJPEG
  500. extern int
  501. ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  502. extern int
  503. ImagingJpegDecodeCleanup(ImagingCodecState state);
  504. extern int
  505. ImagingJpegUseJCSExtensions(void);
  506. extern int
  507. ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  508. #endif
  509. #ifdef HAVE_OPENJPEG
  510. extern int
  511. ImagingJpeg2KDecode(
  512. Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  513. extern int
  514. ImagingJpeg2KDecodeCleanup(ImagingCodecState state);
  515. extern int
  516. ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  517. extern int
  518. ImagingJpeg2KEncodeCleanup(ImagingCodecState state);
  519. #endif
  520. #ifdef HAVE_LIBTIFF
  521. extern int
  522. ImagingLibTiffDecode(
  523. Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  524. extern int
  525. ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  526. #endif
  527. #ifdef HAVE_LIBMPEG
  528. extern int
  529. ImagingMpegDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  530. #endif
  531. extern int
  532. ImagingMspDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  533. extern int
  534. ImagingPackbitsDecode(
  535. Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  536. extern int
  537. ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  538. extern int
  539. ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  540. extern int
  541. ImagingPcxEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  542. extern int
  543. ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  544. extern int
  545. ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  546. extern int
  547. ImagingSgiRleDecode(
  548. Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  549. extern int
  550. ImagingSunRleDecode(
  551. Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  552. extern int
  553. ImagingTgaRleDecode(
  554. Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  555. extern int
  556. ImagingTgaRleEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  557. extern int
  558. ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  559. extern int
  560. ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  561. #ifdef HAVE_LIBZ
  562. extern int
  563. ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
  564. extern int
  565. ImagingZipDecodeCleanup(ImagingCodecState state);
  566. extern int
  567. ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
  568. extern int
  569. ImagingZipEncodeCleanup(ImagingCodecState state);
  570. #endif
  571. typedef void (*ImagingShuffler)(UINT8 *out, const UINT8 *in, int pixels);
  572. /* Public shufflers */
  573. extern void
  574. ImagingPackBGR(UINT8 *out, const UINT8 *in, int pixels);
  575. extern void
  576. ImagingUnpackYCC(UINT8 *out, const UINT8 *in, int pixels);
  577. extern void
  578. ImagingUnpackYCCA(UINT8 *out, const UINT8 *in, int pixels);
  579. extern void
  580. ImagingConvertRGB2YCbCr(UINT8 *out, const UINT8 *in, int pixels);
  581. extern void
  582. ImagingConvertYCbCr2RGB(UINT8 *out, const UINT8 *in, int pixels);
  583. extern ImagingShuffler
  584. ImagingFindUnpacker(const char *mode, const char *rawmode, int *bits_out);
  585. extern ImagingShuffler
  586. ImagingFindPacker(const char *mode, const char *rawmode, int *bits_out);
  587. struct ImagingCodecStateInstance {
  588. int count;
  589. int state;
  590. int errcode;
  591. int x, y;
  592. int ystep;
  593. int xsize, ysize, xoff, yoff;
  594. ImagingShuffler shuffle;
  595. int bits, bytes;
  596. UINT8 *buffer;
  597. void *context;
  598. PyObject *fd;
  599. };
  600. /* Codec read/write python fd */
  601. extern Py_ssize_t
  602. _imaging_read_pyFd(PyObject *fd, char *dest, Py_ssize_t bytes);
  603. extern Py_ssize_t
  604. _imaging_write_pyFd(PyObject *fd, char *src, Py_ssize_t bytes);
  605. extern int
  606. _imaging_seek_pyFd(PyObject *fd, Py_ssize_t offset, int whence);
  607. extern Py_ssize_t
  608. _imaging_tell_pyFd(PyObject *fd);
  609. /* Errcodes */
  610. #define IMAGING_CODEC_END 1
  611. #define IMAGING_CODEC_OVERRUN -1
  612. #define IMAGING_CODEC_BROKEN -2
  613. #define IMAGING_CODEC_UNKNOWN -3
  614. #define IMAGING_CODEC_CONFIG -8
  615. #define IMAGING_CODEC_MEMORY -9
  616. #include "ImagingUtils.h"
  617. extern UINT8 *clip8_lookups;
  618. #if defined(__cplusplus)
  619. }
  620. #endif