home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / imlib_DR-0.2.tar.gz / imlib_DR-0.2.tar / imlib / imlib.h < prev    next >
C/C++ Source or Header  |  1997-05-13  |  15KB  |  301 lines

  1. /*****************************************************************************/
  2. /*                                  I M L I B                                */
  3. /*****************************************************************************/
  4. /* This is a general, all-purpose Image loading and rendering (Image data to */
  5. /* screen data) library. It will only load PPM format images itself. If you  */
  6. /* wish to load other formats, you will have to install the PBM PLUS         */
  7. /* distribution. This consist of commands like "giftopnm", "tgatoppm",       */
  8. /* "bmptoppm", "djpeg", "xpmtoppm", "ilbmtoppm", etc. Via using these        */
  9. /* commands internally, imlib is capable of currently loading 25 different   */
  10. /* image formats. It uses the extension to determine the Imageformat, but if */
  11. /* that is not possible, it will ask the "anytopnm" program from the PBM     */
  12. /* distribution to figrue it out for it. If you dont have the PBM PLUS       */
  13. /* package, GET IT NOW! Try looking in sunsite (sunsite.unc.edu) in          */
  14. /* /pub/Linux/apps/graphics/convert/    for the latest version you can find. */
  15. /* Imlib works on the following display types:                               */
  16. /*     8 bit pseudocolour                                                    */
  17. /*     15 bit RGB (5/5/5) HiColour                                           */
  18. /*     16 bit RGB (5/6/5) HiColour                                           */
  19. /*     24/32 bit RGB (8/8/8) TrueColor                                       */
  20. /* Imlib shoudl do the following displays, but is untested, as my X server   */
  21. /* not capable of these (well i could run a different one... but have too    */
  22. /* much else to do....)                                                      */
  23. /*     1 bit monochrome                                                      */
  24. /*     2 bit (whatever this is... rare but amigas can do it :-) )            */
  25. /*     3 bit (same as above)                                                 */
  26. /*     4 bit (amigas, and PC's do this too... 16 color mode......)           */
  27. /*     5 bit (WOW 32 colors!!!!!!!1)                                         */
  28. /*     6 bit (64 colors.. or even Extra Half Bright on Amigas.....)          */
  29. /*     7 bit (128 colors.. well amigas can do this too.......)               */
  30. /*     8 bit fixed. any fixed color visual chould, if its depth is supported */
  31. /*  support for these bit depths above was an afterthought. I dont really    */
  32. /*  support them. If they work. great, but i belive they wont be as fast as  */
  33. /*  lets say 8bit, 15,16 and 24/32 bit support, whic I concentrated on....   */
  34. /*  infact the only major one of these is monochrome.. see below as to what  */
  35. /*  I think of B&W displays :-)                                              */
  36. /* Why not Monochrome (1bit) ? Monochrome is outdated. SEVERELY so. Many     */
  37. /* institutions still insist on running and purchasing mono display          */
  38. /* terminals. Why this persists beats me. Admittedly they are cheap, but     */
  39. /* crap. In an effort to get the Wrold to MOVE ON, I have decided to not     */
  40. /* support mono displays. I almost tossed 8 bit support out, but decided to  */
  41. /* keep it. Call me an elitist if you want, and I will gladly direct all     */
  42. /* your flames to /dev/null, and reply with /dev/zero :-). The World has to  */
  43. /* move on. In a few years everyone will be running absolute minimum 8 bit   */
  44. /* displays, and most will; run 15/16 bit, and many will run 24/32 bit. I am */
  45. /* desigining for the future, not the past.                                  */
  46. /*                                                                           */
  47. /* NOTE: If you are using an 8-bit display, or programming for one. You must */
  48. /* load a palette via ImlibLoadColors BEFORE you Load or Render any Images.  */
  49. /* If you don't they will all end up blank. This is necessary for Imlib to   */
  50. /* allocate colours in X for you. On 15 bit displays and up this is only an  */
  51. /* option.                                                                   */
  52. /*****************************************************************************/
  53. /* All Imlib source code it Copyright (C) 1997 Carsten Haitzler (Rasterman)  */
  54. /* and falls, in its current version under the GNU Public LICENSE (GPL). If  */
  55. /* you dont know what this means, go read up about it. Simply it means you   */
  56. /* can freely copy it, modify it etc. I do however hold ONE EXCEPTION to the */
  57. /* GPL, Imlib, and any derivative source may not be  run or compiled on any  */
  58. /* Windows or DOS Platfroms (that is Windows1.0-3.11, Windows 95, Windows NT */
  59. /* MS-DOS versions 1.0 and up (all (R) (TM) etc.) etc. all from Microsoft.   */
  60. /* Doing so will violate this license agreement.                             */
  61. /*****************************************************************************/
  62. /* To contact Me (The Author) You can find me:                               */
  63. /* Email: s2154962@cse.unsw.edu.au                                           */
  64. /*        raster@zip.com.au                                                  */
  65. /* Web: http://www.cse.unsw.edu.au                                           */
  66. /* IRC: #zip on Icenet (zipper.zip.com.au is a server on Icenet)             */
  67. /* SnailMail: 16/67 St. Mark Rd.                                             */
  68. /*            Randwick 2031                                                  */
  69. /*            Sydney NSW Australia                                           */
  70. /* Telephone: +61 2 9399 8786                                                */
  71. /* This above contact information is as of Janruary 1997                     */
  72. /*****************************************************************************/
  73.  
  74. #ifndef IMLIB_H
  75. #define IMLIB_H
  76.  
  77. /* defines................... */
  78.  
  79. /*
  80.  * This is where imlib will look for the system imrc config file if it cant
  81.  * find a ~/.imrc file.... it NEEEEEEEEEEDS this file.
  82.  */
  83.  
  84. #ifndef SYSTEM_IMRC
  85. #define SYSTEM_IMRC "/etc/imrc"
  86. #endif /* ndef SYSTEM_IMRC */
  87.  
  88. /*
  89.  * X includes
  90.  */
  91. #include <X11/Xlib.h>
  92. #include <X11/Xutil.h>
  93. #include <X11/Xatom.h>
  94. #include <X11/Xos.h>
  95. #include <X11/extensions/XShm.h>
  96. #include <X11/cursorfont.h>
  97.  
  98. /*
  99.  * Standard system includes
  100.  */
  101. #include <stdio.h>
  102. #include <unistd.h>
  103. #include <stdlib.h>
  104. #include <math.h>
  105. #include <ctype.h>
  106. #include <time.h>                                                            
  107. #include <sys/ipc.h>
  108. #include <sys/shm.h>
  109.  
  110. /* Rendering methods */
  111.  
  112. #define RT_PLAIN_PALETTE       0
  113. #define RT_PLAIN_PALETTE_FAST  1
  114. #define RT_DITHER_PALETTE      2
  115. #define RT_DITHER_PALETTE_FAST 3
  116. #define RT_PLAIN_TRUECOL       4
  117.  
  118. /* Atructures used in Imlib */
  119.  
  120. /* A color in Imlib is stored in this structure */
  121. typedef struct
  122. {
  123.    int r; /* Red value (0-255) */
  124.    int g; /* Green value (0-255) */
  125.    int b; /* Blue value (0-255) */
  126.    int pixel; /* The actual pixel value on screen for the closest match to */
  127.               /* this RGB color value. It may be an exact or very bad match. */
  128. } ImColor;
  129. /* This is a data struc where Imlib stores the info it needs about the */
  130. /* display it is rendering for. This is used internally and need not be */
  131. /* looked at and MUST NOT BE MODIFIED after executing ImlibInit. That could */
  132. /* lead to a segfault and Imlib not working properly. If you want Imlib to */
  133. /* render for multiple displays, create 1 ImlibData struct (via ImlibInit) */
  134. /* per display you open, and when Rendering or Loading an Image, just use */
  135. /* that ImlibData identifier, for that display. NOTE: If you are running */
  136. /* in 8bpp you must also after initialising the ImlibData, load the pallette */
  137. /* into the ImlibData via ImlibLoadColors */
  138. typedef struct
  139. {
  140.    Display *disp; /* Display Imlib is rendering for */
  141.    int screen; /* Screen Number Imlib is rendering for */
  142.    Window root; /* The root window of the display where the Imlib images go */
  143.    Visual *visual; /* The Visual Type of the diplay Imlib is rendering for */
  144.    int depth; /* The depth in bits per pixel of the display for Imlib */
  145.    Colormap root_cmap; /* The colormap of root, so Imlib can alloc colours */
  146.    char shm; /* wether MIT SHM is available */
  147.    int shm_event; /* event id of completion event */
  148.    XImage *last_xim;
  149.    XImage *last_sxim;
  150.    XShmSegmentInfo last_shminfo;
  151.    XShmSegmentInfo last_sshminfo;   
  152. } Xdata;
  153.  
  154. /* Imlib Data. This is all internal and should not be altered. You may look */
  155. /* at the data youself if you want, but this should be left for internal */
  156. /* purposes only */
  157. typedef struct
  158. {
  159.    int num_colors; /* Number of colours in the allocated Palette */
  160.    ImColor palette[256]; /* The allocated Palette itself (MAX 256 Entries) */
  161.    ImColor palette_orig[256]; /* The desired palette (what was wanted) */
  162.    int fast_rgb[32][32][32]; /* A quick lookuptable for faster rendering */
  163.    int fast_err[32][32][32]; /* Internal RGB error information */
  164.    int fast_erg[32][32][32];
  165.    int fast_erb[32][32][32];
  166.    int render_type; /* What render method to use (see above) */
  167.     int max_shm;
  168.    Xdata x; /* data about the display Imlib is rendering for */
  169. } ImlibData;
  170.  
  171. /* This is the data structure of an Image after Imlib is done with it. You */
  172. /* will need thsi if you wish to re-render or rescale in imlib, if all you */
  173. /* want is to load an Image, and get a pixmap, then use that only, you can */
  174. /* copy the pixmap out of this data struct using ImlibCopyImageToPixmap and */
  175. /* then Destroy this Image via ImlibDestroyImage. A similar story applies to */
  176. /* the shape mask. */
  177. typedef struct
  178. {
  179.    int rgb_width; /* width of the original image */
  180.    int rgb_height; /* height of the original image */
  181.    unsigned char *rgb_data; /* the original RGB data in the format RGBRGB... */
  182.    int width; /* width (scaled) rendered Pixmap */
  183.    int height; /* height of (scaled) rendered Pixmap */
  184.    ImColor shape_color; /* RGB colour of the transparent pixel. RGB where */
  185.                         /* value is < 0 means there is no transparency */
  186.    Pixmap pixmap; /* rendered (and scaled) Color Pixmap data */
  187.    Pixmap shape_mask; /* a 1 bit shape mask for the X Shape Extension */
  188. } Image;
  189.  
  190. /* This routine initialises the Imlib  data structure with values for basic */
  191. /* defaults, according to display. You must have already opened the Display */
  192. /* for X before invoking this command. If NULL is returned, it was unable to */
  193. /* properly intitialise the ImlibData data structure. Normally it will */
  194. /* return a pointer to the ImlibData */
  195. ImlibData 
  196. *ImlibInit(Display *disp);
  197.  
  198. /* This will return the current Rendering method, or -1 if there was an */
  199. /* error in obtaining the method */
  200. int 
  201. ImlibGetRenderType(ImlibData *id);
  202.  
  203. /* This sets the current rendering method to rend_type. If you are running */
  204. /* on an 8 bit display, and you request TRUE COLOR rendering, the render */
  205. /* method will be capped at FAST PALETTED DITHERING, due to you not being */
  206. /* able to do truecolor rendiring on that display type. If an error occured */
  207. /* this routine will return 0, otherwise 1 */
  208. int 
  209. ImlibSetRenderType(ImlibData *id, int rend_type);
  210.  
  211. /* This loads a palette file in and allocates the colors specified in it. */
  212. /* you only need to and should to this once. If there was an error, it will */
  213. /* return 0, otherwise 1 */
  214. /* the palette file format is: */
  215. /* 1 colour entry per line, lines starting wiht # are ignored, as follows: */
  216. /* 0xRR 0xGG 0xBB */
  217. /* 0xRR 0xGG 0xBB */
  218. /* etc...... */
  219. int 
  220. ImlibLoadColors(ImlibData *id, char *file);
  221.  
  222. /* This loads an Image file and returns an Image structure. If NULL is */
  223. /* returned instead, something went wrong. icl is a pointer to an ImColor */
  224. /* that specifies the trasnapernt colour to be used. If this is NULL, no */
  225. /* transparent color is used. Once the Image is loaded, it is rendered */
  226. /* using the current render type at the image size specified in the file. */
  227. /* this routine detrmines file-type from the extension. This is the list of */
  228. /* extensions it recognises: */
  229. /* jpeg,jpg : JPEG image file*/
  230. /* bmp : Windows / OS/2 BMP file */
  231. /* ilbm,ilb,iff: Amiga IFF ILBM format */
  232. /* img: Img-whatnot file */
  233. /* mtv: MTV raytracer file */
  234. /* pcx: PCX file */
  235. /* pgm: Protable Graymap file */
  236. /* pi1: Atari Degas file */
  237. /* pict,pic: Macintosh PICT file */
  238. /* pj: HP PaintJet file */
  239. /* qrt: QRT Raytracer file */
  240. /* sld: AutoCad slide file */
  241. /* spc: Atari compressed Spectrum file */
  242. /* spu: Atari uncompressed Spectrum file */
  243. /* tga: Truevison Targa file */
  244. /* xim: Xim file */
  245. /* xpm: X11 protablepixmap */
  246. /* gif: GIF file (only color, not greyscale/b&w) */
  247. /* rast,ras: Sun rasterfile (only color, not greyscale/b&w) */
  248. /* sgi: SGI file (only color, not greyscale/b&w) */
  249. /* sir: Solitare Image recorder file (only color, not greyscale/b&w) */
  250. /* tiff,tif: TIFF file (only color, not greyscale/b&w) */
  251. /* wxd: X10/X11 Window dump (only color, not greyscale/b&w) */
  252. /* zeiss,zei,zis: Zeiss confocal file (only color, not greyscale/b&w) */
  253. /* ppm: Portable Pixmap file */
  254. Image 
  255. *ImlibLoadImage(ImlibData *id, char *file, ImColor *icl);
  256.  
  257. /* This routine returns the closest match for the RGB color specified with */
  258. /* r,g and b (0-255 each), and returns the pixel value for the screen and */
  259. /* r,g, and b are modified to contain the RGB error of the match (0,0,0 */
  260. /* means a perfect mactch. returns -1 if there was an error */
  261. int 
  262. ImlibBestColorMatch(ImlibData *id, int *r,int *g,int *b);
  263.  
  264. /* This Routine Re-Renders the image (destroying any old rendered pixmap) */
  265. /* using the current render tpe, and at the width (w) and height (h) */
  266. /* specified. If something went wrong, 0, will be returned, otherwise 1 */
  267. int 
  268. ImlibRender(ImlibData *id, Image *im, int w, int h);
  269.  
  270. /* This copies the rendered pixmap from and Image into a Pixmap, and retruns */
  271. /* that. */
  272. Pixmap 
  273. ImlibCopyImageToPixmap(ImlibData *id, Image *im);
  274.  
  275. /* This is exactly the same as ImlibCopyImageToPixmap, but is faster, and */
  276. /* makes the rescaled pixmap in the Image structure invalid */
  277. Pixmap 
  278. ImlibMoveImageToPixmap(ImlibData *id, Image *im);
  279.  
  280. /* This copies the rendered pixmap from and Image into a Pixmap, and retruns */
  281. /* that. */
  282. Pixmap 
  283. ImlibCopyMaskToPixmap(ImlibData *id, Image *im);
  284.  
  285. /* This is exactly the same as ImlibCopyImageToPixmap, but is faster, and */
  286. /* makes the rescaled pixmap in the Image structure invalid */
  287. Pixmap 
  288. ImlibMoveMaskToPixmap(ImlibData *id, Image *im);
  289.  
  290. /* This destroys an Image and all data associated wiht it, freeing up the */
  291. /* memory it uses. */
  292. void 
  293. ImlibDestroyImage(ImlibData *id, Image *im);
  294.  
  295. /* This function frees all the colors allocated int he palette for imlib */
  296. /* the nullifies the palette, so no colors exist anymore in the palette */
  297. void
  298. ImlibFreeColors(ImlibData *id);
  299.  
  300. #endif
  301.