Imaging.h
001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014: #include "ImPlatform.h"
015:
016:
017: #if defined(__cplusplus)
018: extern "C" {
019: #endif
020:
021:
022: #ifndef M_PI
023: #define M_PI 3.14159265359
024: #endif
025:
026:
027:
028:
029:
030:
031:
032:
033:
034:
035:
036:
037:
038:
039:
040:
041:
042:
043:
044:
045:
046:
047:
048:
049:
050:
051:
052:
053:
054: http://www.effbot.org/zone/pil-extending.htm
055:
056:
057:
058:
059: typedef struct ImagingMemoryInstance* Imaging;
060:
061: typedef struct ImagingAccessInstance* ImagingAccess;
062: typedef struct ImagingHistogramInstance* ImagingHistogram;
063: typedef struct ImagingOutlineInstance* ImagingOutline;
064: typedef struct ImagingPaletteInstance* ImagingPalette;
065:
066:
067: #define IMAGING_MAGIC "PIL Imaging"
068:
069:
070: #define IMAGING_TYPE_UINT8 0
071: #define IMAGING_TYPE_INT32 1
072: #define IMAGING_TYPE_FLOAT32 2
073: #define IMAGING_TYPE_SPECIAL 3
074:
075: struct ImagingMemoryInstance {
076:
077:
078: char mode[6+1];
079: int type;
080: int depth;
081: int bands;
082: int xsize;
083: int ysize;
084:
085:
086: ImagingPalette palette;
087:
088:
089: UINT8 **image8;
090: INT32 **image32;
091:
092:
093: char **image;
094: char *block;
095:
096: int pixelsize;
097: int linesize;
098:
099:
100: void (*destroy)(Imaging im);
101: };
102:
103:
104: #define IMAGING_PIXEL_1(im,x,y) ((im)->image8[(y)][(x)])
105: #define IMAGING_PIXEL_L(im,x,y) ((im)->image8[(y)][(x)])
106: #define IMAGING_PIXEL_LA(im,x,y) ((im)->image[(y)][(x)*4])
107: #define IMAGING_PIXEL_P(im,x,y) ((im)->image8[(y)][(x)])
108: #define IMAGING_PIXEL_PA(im,x,y) ((im)->image[(y)][(x)*4])
109: #define IMAGING_PIXEL_I(im,x,y) ((im)->image32[(y)][(x)])
110: #define IMAGING_PIXEL_F(im,x,y) (((FLOAT32*)(im)->image32[y])[x])
111: #define IMAGING_PIXEL_RGB(im,x,y) ((im)->image[(y)][(x)*4])
112: #define IMAGING_PIXEL_RGBA(im,x,y) ((im)->image[(y)][(x)*4])
113: #define IMAGING_PIXEL_CMYK(im,x,y) ((im)->image[(y)][(x)*4])
114: #define IMAGING_PIXEL_YCbCr(im,x,y) ((im)->image[(y)][(x)*4])
115:
116: #define IMAGING_PIXEL_UINT8(im,x,y) ((im)->image8[(y)][(x)])
117: #define IMAGING_PIXEL_INT32(im,x,y) ((im)->image32[(y)][(x)])
118: #define IMAGING_PIXEL_FLOAT32(im,x,y) (((FLOAT32*)(im)->image32[y])[x])
119:
120: struct ImagingAccessInstance {
121: const char* mode;
122: void* (*line)(Imaging im, int x, int y);
123: void (*get_pixel)(Imaging im, int x, int y, void* pixel);
124: void (*put_pixel)(Imaging im, int x, int y, const void* pixel);
125: };
126:
127: struct ImagingHistogramInstance {
128:
129:
130: char mode[4+1];
131: int bands;
132:
133:
134: long *histogram;
135:
136: };
137:
138:
139: struct ImagingPaletteInstance {
140:
141:
142: char mode[4+1];
143:
144:
145: UINT8 palette[1024];
146:
147: INT16* cache;
148: int keep_cache;
149:
150: };
151:
152:
153:
154:
155:
156: extern int ImagingNewCount;
157:
158: extern Imaging ImagingNew(const char* mode, int xsize, int ysize);
159: extern Imaging ImagingNew2(const char* mode, Imaging imOut, Imaging imIn);
160: extern void ImagingDelete(Imaging im);
161:
162: extern Imaging ImagingNewBlock(const char* mode, int xsize, int ysize);
163: extern Imaging ImagingNewArray(const char* mode, int xsize, int ysize);
164: extern Imaging ImagingNewMap(const char* filename, int readonly,
165: const char* mode, int xsize, int ysize);
166:
167: extern Imaging ImagingNewPrologue(const char *mode,
168: unsigned xsize, unsigned ysize);
169: extern Imaging ImagingNewPrologueSubtype(const char *mode,
170: unsigned xsize, unsigned ysize,
171: int structure_size);
172: extern Imaging ImagingNewEpilogue(Imaging im);
173:
174: extern void ImagingCopyInfo(Imaging destination, Imaging source);
175:
176: extern void ImagingHistogramDelete(ImagingHistogram histogram);
177:
178: extern void ImagingAccessInit(void);
179: extern ImagingAccess ImagingAccessNew(Imaging im);
180: extern void _ImagingAccessDelete(Imaging im, ImagingAccess access);
181: #define ImagingAccessDelete(im, access)
182:
183:
184:
185: extern ImagingPalette ImagingPaletteNew(const char *mode);
186: extern ImagingPalette ImagingPaletteNewBrowser(void);
187: extern ImagingPalette ImagingPaletteDuplicate(ImagingPalette palette);
188: extern void ImagingPaletteDelete(ImagingPalette palette);
189:
190: extern int ImagingPaletteCachePrepare(ImagingPalette palette);
191: extern void ImagingPaletteCacheUpdate(ImagingPalette palette,
192: int r, int g, int b);
193: extern void ImagingPaletteCacheDelete(ImagingPalette palette);
194:
195: #define ImagingPaletteCache(p, r, g, b)\
196: p->cache[(r>>2) + (g>>2)*64 + (b>>2)*64*64]
197:
198: extern Imaging ImagingQuantize(Imaging im, int colours, int mode, int kmeans);
199:
200:
201:
202:
203: typedef void* ImagingSectionCookie;
204:
205: extern void ImagingSectionEnter(ImagingSectionCookie* cookie);
206: extern void ImagingSectionLeave(ImagingSectionCookie* cookie);
207:
208:
209:
210:
211: extern void* ImagingError_IOError(void);
212: extern void* ImagingError_MemoryError(void);
213: extern void* ImagingError_ModeError(void);
214: extern void* ImagingError_Mismatch(void);
215: extern void* ImagingError_ValueError(const char* message);
216: extern void ImagingError_Clear(void);
217:
218:
219:
220:
221:
222: #define IMAGING_TRANSFORM_AFFINE 0
223: #define IMAGING_TRANSFORM_PERSPECTIVE 2
224: #define IMAGING_TRANSFORM_QUAD 3
225:
226:
227:
228: #define IMAGING_TRANSFORM_NEAREST 0
229: #define IMAGING_TRANSFORM_ANTIALIAS 1
230: #define IMAGING_TRANSFORM_BILINEAR 2
231: #define IMAGING_TRANSFORM_BICUBIC 3
232:
233: typedef int (*ImagingTransformMap)(double* X, double* Y,
234: int x, int y, void* data);
235: typedef int (*ImagingTransformFilter)(void* out, Imaging im,
236: double x, double y,
237: void* data);
238:
239:
240:
241:
242: extern Imaging ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha);
243: extern Imaging ImagingCopy(Imaging im);
244: extern Imaging ImagingConvert(Imaging im, const char* mode, ImagingPalette palette, int dither);
245: extern Imaging ImagingConvertInPlace(Imaging im, const char* mode);
246: extern Imaging ImagingConvertMatrix(Imaging im, const char *mode, float m[]);
247: extern Imaging ImagingCrop(Imaging im, int x0, int y0, int x1, int y1);
248: extern Imaging ImagingExpand(Imaging im, int x, int y, int mode);
249: extern Imaging ImagingFill(Imaging im, const void* ink);
250: extern int ImagingFill2(
251: Imaging into, const void* ink, Imaging mask,
252: int x0, int y0, int x1, int y1);
253: extern Imaging ImagingFillBand(Imaging im, int band, int color);
254: extern Imaging ImagingFillLinearGradient(const char* mode);
255: extern Imaging ImagingFillRadialGradient(const char* mode);
256: extern Imaging ImagingFilter(
257: Imaging im, int xsize, int ysize, const FLOAT32* kernel,
258: FLOAT32 offset, FLOAT32 divisor);
259: extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
260: extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
261: extern Imaging ImagingGaussianBlur(Imaging im, Imaging imOut, float radius);
262: extern Imaging ImagingGetBand(Imaging im, int band);
263: extern int ImagingGetBBox(Imaging im, int bbox[4]);
264: typedef struct { int x, y; INT32 count; INT32 pixel; } ImagingColorItem;
265: extern ImagingColorItem* ImagingGetColors(Imaging im, int maxcolors,
266: int *colors);
267: extern int ImagingGetExtrema(Imaging im, void *extrema);
268: extern int ImagingGetProjection(Imaging im, UINT8* xproj, UINT8* yproj);
269: extern ImagingHistogram ImagingGetHistogram(
270: Imaging im, Imaging mask, void *extrema);
271: extern Imaging ImagingModeFilter(Imaging im, int size);
272: extern Imaging ImagingNegative(Imaging im);
273: extern Imaging ImagingOffset(Imaging im, int xoffset, int yoffset);
274: extern int ImagingPaste(
275: Imaging into, Imaging im, Imaging mask,
276: int x0, int y0, int x1, int y1);
277: extern Imaging ImagingPoint(
278: Imaging im, const char* tablemode, const void* table);
279: extern Imaging ImagingPointTransform(
280: Imaging imIn, double scale, double offset);
281: extern Imaging ImagingPutBand(Imaging im, Imaging imIn, int band);
282: extern Imaging ImagingRankFilter(Imaging im, int size, int rank);
283: extern Imaging ImagingResize(Imaging imOut, Imaging imIn, int filter);
284: extern Imaging ImagingRotate(
285: Imaging imOut, Imaging imIn, double theta, int filter);
286: extern Imaging ImagingRotate90(Imaging imOut, Imaging imIn);
287: extern Imaging ImagingRotate180(Imaging imOut, Imaging imIn);
288: extern Imaging ImagingRotate270(Imaging imOut, Imaging imIn);
289: extern Imaging ImagingStretch(Imaging imOut, Imaging imIn, int filter);
290: extern Imaging ImagingTransformPerspective(
291: Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1,
292: double a[8], int filter, int fill);
293: extern Imaging ImagingTransformAffine(
294: Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1,
295: double a[6], int filter, int fill);
296: extern Imaging ImagingTransformQuad(
297: Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1,
298: double a[8], int filter, int fill);
299: extern Imaging ImagingTransform(
300: Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1,
301: ImagingTransformMap transform, void* transform_data,
302: ImagingTransformFilter filter, void* filter_data,
303: int fill);
304: extern Imaging ImagingUnsharpMask(
305: Imaging im, Imaging imOut, float radius, int percent, int threshold);
306:
307: extern Imaging ImagingCopy2(Imaging imOut, Imaging imIn);
308: extern Imaging ImagingConvert2(Imaging imOut, Imaging imIn);
309:
310:
311:
312: extern Imaging ImagingChopLighter(Imaging imIn1, Imaging imIn2);
313: extern Imaging ImagingChopDarker(Imaging imIn1, Imaging imIn2);
314: extern Imaging ImagingChopDifference(Imaging imIn1, Imaging imIn2);
315: extern Imaging ImagingChopMultiply(Imaging imIn1, Imaging imIn2);
316: extern Imaging ImagingChopScreen(Imaging imIn1, Imaging imIn2);
317: extern Imaging ImagingChopAdd(
318: Imaging imIn1, Imaging imIn2, float scale, int offset);
319: extern Imaging ImagingChopSubtract(
320: Imaging imIn1, Imaging imIn2, float scale, int offset);
321: extern Imaging ImagingChopAddModulo(Imaging imIn1, Imaging imIn2);
322: extern Imaging ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2);
323:
324:
325: extern Imaging ImagingChopAnd(Imaging imIn1, Imaging imIn2);
326: extern Imaging ImagingChopOr(Imaging imIn1, Imaging imIn2);
327: extern Imaging ImagingChopXor(Imaging imIn1, Imaging imIn2);
328:
329:
330: extern void ImagingCrack(Imaging im, int x0, int y0);
331:
332:
333: struct ImagingAffineMatrixInstance {
334: float a[9];
335: };
336:
337: typedef struct ImagingAffineMatrixInstance *ImagingAffineMatrix;
338:
339: extern int ImagingDrawArc(Imaging im, int x0, int y0, int x1, int y1,
340: int start, int end, const void* ink, int op);
341: extern int ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap,
342: const void* ink, int op);
343: extern int ImagingDrawChord(Imaging im, int x0, int y0, int x1, int y1,
344: int start, int end, const void* ink, int fill,
345: int op);
346: extern int ImagingDrawEllipse(Imaging im, int x0, int y0, int x1, int y1,
347: const void* ink, int fill, int op);
348: extern int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1,
349: const void* ink, int op);
350: extern int ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
351: const void* ink, int width, int op);
352: extern int ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1,
353: int start, int end, const void* ink, int fill,
354: int op);
355: extern int ImagingDrawPoint(Imaging im, int x, int y, const void* ink, int op);
356: extern int ImagingDrawPolygon(Imaging im, int points, int *xy,
357: const void* ink, int fill, int op);
358: extern int ImagingDrawRectangle(Imaging im, int x0, int y0, int x1, int y1,
359: const void* ink, int fill, int op);
360:
361:
362: extern ImagingOutline ImagingOutlineNew(void);
363: extern void ImagingOutlineDelete(ImagingOutline outline);
364:
365: extern int ImagingDrawOutline(Imaging im, ImagingOutline outline,
366: const void* ink, int fill, int op);
367:
368: extern int ImagingOutlineMove(ImagingOutline outline, float x, float y);
369: extern int ImagingOutlineLine(ImagingOutline outline, float x, float y);
370: extern int ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
371: float x2, float y2, float x3, float y3);
372: extern int ImagingOutlineTransform(ImagingOutline outline, double a[6]);
373:
374: extern int ImagingOutlineClose(ImagingOutline outline);
375:
376:
377: extern Imaging ImagingEffectSpread(Imaging imIn, int distance);
378: extern Imaging ImagingEffectNoise(int xsize, int ysize, float sigma);
379: extern Imaging ImagingEffectMandelbrot(int xsize, int ysize,
380: double extent[4], int quality);
381:
382:
383: extern int ImagingToString(Imaging im, int orientation, char *buffer);
384: extern int ImagingFromString(Imaging im, int orientation, char *buffer);
385:
386:
387:
388:
389:
390:
391: extern Imaging ImagingOpenPPM(const char* filename);
392: extern int ImagingSavePPM(Imaging im, const char* filename);
393:
394:
395: extern UINT32 ImagingCRC32(UINT32 crc, UINT8* buffer, int bytes);
396:
397:
398: typedef struct ImagingCodecStateInstance *ImagingCodecState;
399: typedef int (*ImagingCodec)(Imaging im, ImagingCodecState state,
400: UINT8* buffer, int bytes);
401:
402: extern int ImagingBitDecode(Imaging im, ImagingCodecState state,
403: UINT8* buffer, int bytes);
404: extern int ImagingEpsEncode(Imaging im, ImagingCodecState state,
405: UINT8* buffer, int bytes);
406: extern int ImagingFliDecode(Imaging im, ImagingCodecState state,
407: UINT8* buffer, int bytes);
408: extern int ImagingGifDecode(Imaging im, ImagingCodecState state,
409: UINT8* buffer, int bytes);
410: extern int ImagingGifEncode(Imaging im, ImagingCodecState state,
411: UINT8* buffer, int bytes);
412: extern int ImagingHexDecode(Imaging im, ImagingCodecState state,
413: UINT8* buffer, int bytes);
414: #ifdef HAVE_LIBJPEG
415: extern int ImagingJpegDecode(Imaging im, ImagingCodecState state,
416: UINT8* buffer, int bytes);
417: extern int ImagingJpegEncode(Imaging im, ImagingCodecState state,
418: UINT8* buffer, int bytes);
419: #endif
420: extern int ImagingLzwDecode(Imaging im, ImagingCodecState state,
421: UINT8* buffer, int bytes);
422: #ifdef HAVE_LIBMPEG
423: extern int ImagingMpegDecode(Imaging im, ImagingCodecState state,
424: UINT8* buffer, int bytes);
425: #endif
426: extern int ImagingMspDecode(Imaging im, ImagingCodecState state,
427: UINT8* buffer, int bytes);
428: extern int ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
429: UINT8* buffer, int bytes);
430: extern int ImagingPcdDecode(Imaging im, ImagingCodecState state,
431: UINT8* buffer, int bytes);
432: extern int ImagingPcxDecode(Imaging im, ImagingCodecState state,
433: UINT8* buffer, int bytes);
434: extern int ImagingPcxEncode(Imaging im, ImagingCodecState state,
435: UINT8* buffer, int bytes);
436: extern int ImagingRawDecode(Imaging im, ImagingCodecState state,
437: UINT8* buffer, int bytes);
438: extern int ImagingRawEncode(Imaging im, ImagingCodecState state,
439: UINT8* buffer, int bytes);
440: extern int ImagingSunRleDecode(Imaging im, ImagingCodecState state,
441: UINT8* buffer, int bytes);
442: extern int ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
443: UINT8* buffer, int bytes);
444: extern int ImagingXbmDecode(Imaging im, ImagingCodecState state,
445: UINT8* buffer, int bytes);
446: extern int ImagingXbmEncode(Imaging im, ImagingCodecState state,
447: UINT8* buffer, int bytes);
448: #ifdef HAVE_LIBZ
449: extern int ImagingZipDecode(Imaging im, ImagingCodecState state,
450: UINT8* buffer, int bytes);
451: extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
452: UINT8* buffer, int bytes);
453: #endif
454:
455: typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels);
456:
457:
458: extern void ImagingPackRGB(UINT8* out, const UINT8* in, int pixels);
459: extern void ImagingPackBGR(UINT8* out, const UINT8* in, int pixels);
460: extern void ImagingUnpackRGB(UINT8* out, const UINT8* in, int pixels);
461: extern void ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels);
462: extern void ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels);
463: extern void ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels);
464: extern void ImagingUnpackYCbCr(UINT8* out, const UINT8* in, int pixels);
465:
466: extern void ImagingConvertRGB2YCbCr(UINT8* out, const UINT8* in, int pixels);
467: extern void ImagingConvertYCbCr2RGB(UINT8* out, const UINT8* in, int pixels);
468:
469: extern ImagingShuffler ImagingFindUnpacker(const char* mode,
470: const char* rawmode, int* bits_out);
471: extern ImagingShuffler ImagingFindPacker(const char* mode,
472: const char* rawmode, int* bits_out);
473:
474: struct ImagingCodecStateInstance {
475: int count;
476: int state;
477: int errcode;
478: int x, y;
479: int ystep;
480: int xsize, ysize, xoff, yoff;
481: ImagingShuffler shuffle;
482: int bits, bytes;
483: UINT8 *buffer;
484: void *context;
485: };
486:
487:
488: #define IMAGING_CODEC_END 1
489: #define IMAGING_CODEC_OVERRUN -1
490: #define IMAGING_CODEC_BROKEN -2
491: #define IMAGING_CODEC_UNKNOWN -3
492: #define IMAGING_CODEC_CONFIG -8
493: #define IMAGING_CODEC_MEMORY -9
494:
495: #if defined(__cplusplus)
496: }
497: #endif
498:
© Andrew Scott 2006 -
2025,
All Rights Reserved