IlibP.h
资源名称:ilib [点击查看]
上传用户:changbiao
上传日期:2007-01-13
资源大小:141k
文件大小:7k
源码类别:

图片显示

开发平台:

C/C++

  1. /*
  2.  * Ilib.h
  3.  *
  4.  * Image library Private include
  5.  *
  6.  * Description:
  7.  * To be included only be Ilib internal functions
  8.  *
  9.  * History:
  10.  * 01-Apr-00 Jim Winstead jimw@trainedmonkey.com
  11.  * Added _IReadBMP()
  12.  * 26-Aug-99 Craig Knudsen cknudsen@radix.net
  13.  * Added _IReadXPM()
  14.  * 23-Aug-99 Craig Knudsen cknudsen@radix.net
  15.  * Added text_style to IGCP.
  16.  * 22-Jul-99 Craig Knudsen cknudsen@radix.net
  17.  * Added JPEG support.
  18.  * 19-Jul-99 Craig Knudsen cknudsen@radix.net
  19.  * Added PNG support.
  20.  * 19-May-98 Craig Knudsen cknudsen@radix.net
  21.  * Added _ISetPointRGB macro
  22.  * 20-May-96 Craig Knudsen cknudsen@radix.net
  23.  * Created
  24.  *
  25.  ****************************************************************************/
  26. #ifndef _ilibp_h
  27. #define _ilibp_h
  28. /*
  29. ** Define a magic value to place at the front of each structure.
  30. ** If this value is incorrect, then an invalid structure was
  31. ** passed in.
  32. */
  33. #define IMAGIC_IMAGE 467
  34. #define IMAGIC_GC 333
  35. #define IMAGIC_COLOR 847
  36. #define IMAGIC_FONT 104
  37. #ifndef PI
  38. #define PI 3.14159265358979323846
  39. #endif /* PI */
  40. /*
  41. ** Default comment for images
  42. */
  43. #define IDEFAULT_COMMENT "Creator: Ilib http://www.radix.net/~cknudsen/Ilib/"
  44. /*
  45. ** Structures
  46. */
  47. typedef struct {
  48.   unsigned int magic; /* memory verification */
  49.   unsigned char red; /* red value (0-255) */
  50.   unsigned char green; /* green value (0-255) */
  51.   unsigned char blue; /* blue value (0-255) */
  52.   unsigned long value; /* pixel value */
  53. } IColorP;
  54. typedef struct {
  55.   unsigned int magic; /* memory verification */
  56.   int width; /* width */
  57.   int height; /* height */
  58.   char *comments; /* comments */
  59.   unsigned char *data; /* image data */
  60.   unsigned short interlaced; /* interlaced output? */
  61.   unsigned short greyscale; /* greyscale? */
  62.   IColorP *transparent; /* transparent color */
  63. } IImageP;
  64. typedef struct {
  65.   unsigned int magic; /* memory verification */
  66.   char *name;
  67. } IFontP;
  68. typedef struct {
  69.   unsigned int magic; /* memory verification */
  70.   IColorP *foreground; /* foreground color */
  71.   IColorP *background; /* background color */
  72.   IFontP *font; /* font */
  73.   unsigned short antialiased; /* use anti-aliasing (size is halfed) */
  74.   unsigned int line_width; /* line width */
  75.   ILineStyle line_style; /* line style */
  76.   ITextStyle text_style; /* line style */
  77.   /* add more later ... */
  78. } IGCP;
  79. /*
  80. ** File formats.
  81. */
  82. IError _IWritePGM (
  83. #ifndef _NO_PROTO
  84.   FILE *fp,
  85.   IImageP *image,
  86.   IOptions options
  87. #endif
  88. );
  89. IError _IReadPPM (
  90. #ifndef _NO_PROTO
  91.   FILE *fp,
  92.   IOptions options,
  93.   IImageP **image_return
  94. #endif
  95. );
  96. IError _IWritePPM (
  97. #ifndef _NO_PROTO
  98.   FILE *fp,
  99.   IImageP *image,
  100.   IOptions options
  101. #endif
  102. );
  103. IError _IWriteXPM (
  104. #ifndef _NO_PROTO
  105.   FILE *fp,
  106.   IImageP *image,
  107.   IOptions options
  108. #endif
  109. );
  110. IError _IReadXPM (
  111. #ifndef _NO_PROTO
  112.   FILE *fp,
  113.   IOptions options,
  114.   IImageP **image_return
  115. #endif
  116. );
  117. IError _IReadPNG (
  118. #ifndef _NO_PROTO
  119.   FILE *fp,
  120.   IOptions options,
  121.   IImageP **image_return
  122. #endif
  123. );
  124. IError _IWritePNG (
  125. #ifndef _NO_PROTO
  126.   FILE *fp,
  127.   IImageP *image,
  128.   IOptions options
  129. #endif
  130. );
  131. IError _IReadGIF (
  132. #ifndef _NO_PROTO
  133.   FILE *fp,
  134.   IOptions options,
  135.   IImageP **image_return
  136. #endif
  137. );
  138. IError _IWriteGIF (
  139. #ifndef _NO_PROTO
  140.   FILE *fp,
  141.   IImageP *image,
  142.   IOptions options
  143. #endif
  144. );
  145. #ifdef HAVE_JPEGLIB
  146. IError _IReadJPEG (
  147. #ifndef _NO_PROTO
  148.   FILE *fp,
  149.   IOptions options,
  150.   IImageP **image_return
  151. #endif
  152. );
  153. IError _IWriteJPEG (
  154. #ifndef _NO_PROTO
  155.   FILE *fp,
  156.   IImageP *image,
  157.   IOptions options
  158. #endif
  159. );
  160. #endif
  161. IError _IReadBMP (
  162. #ifndef _NO_PROTO
  163.   FILE *fp,
  164.   IOptions options,
  165.   IImageP **image_return
  166. #endif
  167. );
  168. typedef struct {
  169.   char *name;
  170.   IError (*read_func) (
  171. #ifndef _NO_PROTO
  172.     FILE *fp, /* output file pointer */
  173.     IOptions options, /* read options */
  174.     IImageP **image_return /* returned image */
  175. #endif
  176.   );
  177.   IError (*write_func) (
  178. #ifndef _NO_PROTO
  179.     FILE *fp, /* output file pointer */
  180.     IImageP *image, /* image to save */
  181.     IOptions options /* write options */
  182. #endif
  183.   );
  184.   int maxdepth; /* max depth (1=b/w, 8=256 colors) */
  185.   int grey; /* is grey? */
  186. } IFormatDef;
  187. #ifdef IIncludeFileFormats
  188. static IFormatDef IFileFormats[] = {
  189.   { /* IFORMAT_GIF */ "GIF", _IReadGIF, _IWriteGIF, 8, 0 },
  190.   { /* IFORMAT_PPM */ "PPM", _IReadPPM, _IWritePPM, 24, 0 },
  191.   { /* IFORMAT_PGM */ "PGM", _IReadPPM, _IWritePGM, 8, 1 },
  192.   { /* IFORMAT_PBM */ "PBM", NULL, NULL, 1, 1 },
  193.   { /* IFORMAT_XPM */ "XPM", _IReadXPM, _IWriteXPM, 24, 0 },
  194.   { /* IFORMAT_XBM */ "XBM", NULL, NULL, 1, 1 },
  195. #ifdef HAVE_PNGLIB
  196.   { /* IFORMAT_PNG */ "PNG", _IReadPNG, _IWritePNG, 24, 0 },
  197. #else
  198.   { /* IFORMAT_PNG */ "PNG", NULL, NULL, 24, 0 },
  199. #endif
  200. #ifdef HAVE_JPEGLIB
  201.   { /* IFORMAT_JPEG */ "JPEG", _IReadJPEG, _IWriteJPEG, 24, 0 },
  202. #else
  203.   { /* IFORMAT_JPEG */ "JPEG", NULL, NULL, 24, 0 },
  204. #endif
  205.   { /* IFORMAT_BMP */ "BMP", _IReadBMP, NULL, 24, 0 },
  206. };
  207. #endif /* IIncludeFileFormats */
  208. IColorP *_IGetColor (
  209. #ifndef _NO_PROTO
  210.   int color /* int index to translate */
  211. #endif
  212. );
  213. IError _IFontBDFGetSize (
  214. #ifndef _NO_PROTO
  215.   char *name, /* font name */
  216.   unsigned int *height_return /* out: height of font */
  217. #endif
  218. );
  219. /*
  220. ** Define a function to draw a point.  Must be inline because this
  221. ** is typically within multiple for loops and we don't want all those
  222. ** extra stack pushes and pops slowing us down...
  223. ** Arguments are ( ImageP *, IGCP *, int, int ).
  224. */
  225. #define _IDrawPoint _ISetPoint
  226. #define _ISetPoint(i,g,x,y) 
  227.   unsigned char *ptrX;
  228.   if ( (x) >= 0 && (x) < i->width && (y) >= 0 && (y) < i->height ) {
  229.             if ( i->greyscale ) {
  230.       ptrX = i->data + ( (y) * i->width ) + (x); 
  231.       *ptrX = g->foreground->red; 
  232.             } else {
  233.       ptrX = i->data + ( (y) * i->width * 3 ) + ( (x) * 3 ); 
  234.       *ptrX = g->foreground->red; 
  235.       *(ptrX + 1) = g->foreground->green; 
  236.       *(ptrX + 2) = g->foreground->blue; 
  237.             }
  238.   }
  239. }
  240. #define _ISetPointRGB(i,x,y,r,g,b) 
  241.   unsigned char *ptrX;
  242.   if ( (x) >= 0 && (x) < i->width && (y) >= 0 && (y) < i->height ) {
  243.             if ( i->greyscale ) {
  244.       ptrX = i->data + ( (y) * i->width ) + (x); 
  245.       *ptrX = r; 
  246.             } else {
  247.       ptrX = i->data + ( (y) * i->width * 3 ) + ( (x) * 3 ); 
  248.       *ptrX = r; 
  249.       *(ptrX + 1) = g; 
  250.       *(ptrX + 2) = b; 
  251.             }
  252.   }
  253. }
  254. #define _IGetPointColor(i,x,y,c) 
  255.   unsigned char *ptrX;
  256.   if ( (x) >= 0 && (x) < i->width && (y) >= 0 && (y) < i->height ) {
  257.             if ( i->greyscale ) {
  258.       ptrX = i->data + ( (y) * i->width ) + (x); 
  259.       c.red = c.green = c.blue = *ptrX; 
  260.             } else {
  261.       ptrX = i->data + ( (y) * i->width * 3 ) + ( (x) * 3 ); 
  262.       c.red = *ptrX; 
  263.       c.green = *(ptrX + 1); 
  264.       c.blue = *(ptrX + 2); 
  265.             }
  266.   }
  267. }
  268. #endif /* _ilibp_h */