Back to index

plt-scheme  4.2.1
wx_image.h
Go to the documentation of this file.
00001 /*
00002  * File:     wx_image.h
00003  * Purpose:  
00004  *
00005  *                       wxWindows 1.50
00006  * Copyright (c) 2004-2009 PLT Scheme Inc.
00007  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
00008  *                   The University of Edinburgh
00009  *
00010  *                     Author: Julian Smart
00011  *                        Date: 7-9-93
00012  *
00013  * Permission to use, copy, modify, and distribute this software and its
00014  * documentation for any purpose is hereby granted without fee, provided
00015  * that the above copyright notice, author statement and this permission
00016  * notice appear in all copies of this software and related documentation.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
00019  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
00020  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00021  *
00022  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
00023  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
00024  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
00025  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
00026  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
00027  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
00028  *
00029  */
00030 
00031 #ifndef wx_imageh
00032 #define wx_imageh
00033 
00034 #ifndef WXI_SKIP_WX_INCLUDES
00035 #include "common.h"
00036 #include "wx_obj.h"
00037 #endif
00038 
00039 #include "wx_imgx.h"
00040 
00041 #define wxUNKNOWN 0
00042 #define wxGIF     1
00043 #define wxPM      2
00044 #define wxPBM     3
00045 #define wxXBM     4
00046 
00047 class wxColourMap;
00048 class wxBitmap;
00049 class wxCanvas;
00050 
00051 wxBitmap *wxLoadBitmap(char *filename, wxColourMap **cmap = NULL);
00052 Bool wxLoadIntoBitmap(char *filename, wxBitmap *bitmap, wxColourMap **cmap = NULL, int getMask = 0);
00053 
00054 class wxImage: public wxObject
00055 {
00056   int filetype;
00057   wxColourMap *cMap;
00058  public:
00059 
00060   /*
00061    * Public interface
00062    */
00063 
00064   wxImage(void);
00065   ~wxImage(void);
00066 
00067   Bool Load(char *file);
00068   Bool Destroy(void);
00069   void Draw(wxCanvas *canvas, int x = 0, int y = 0, int width = -1, int height = -1);
00070   void Resize(int, int);
00071   void GetSize(int *width, int *height);
00072   inline int GetType(void) { return filetype; }
00073   wxColourMap *GetColourMap(void);
00074 
00075   /*
00076    * X stuff
00077    */
00078 
00079 #ifdef wx_x
00080   Display       *theDisp;
00081   int           theScreen;
00082   unsigned int  ncells, dispWIDE, dispHIGH, dispDEEP;
00083   Colormap      theCmap, LocalCmap;
00084   Window        rootW;
00085   unsigned long black, white, fg, bg, infofg, infobg;
00086   Visual        *theVisual;
00087 
00088   /* global vars used by LOAD routines */
00089   byte          *pic;                   /* ptr to loaded picture */
00090   byte *pic24;  /* Used by 25-8 bit conversion */
00091   unsigned int   pWIDE,pHIGH;           /* size of 'pic' */
00092   int            imgDEBUG;                 /* print debugging info */
00093   int            mono;                  /* true if displaying grayscale */
00094 
00095 
00096   /* more global variables, used by xv and xvmisc */
00097   byte          *cpic;         /* cropped version of pic */
00098   unsigned int  cWIDE, cHIGH,  /* size of cropped region */
00099                 cXOFF, cYOFF;  /* offset of region from 0,0 of pic */
00100 
00101   byte          *epic;         /* expanded version of cpic */
00102                                    /* points to pic when at 1:1 expansion */
00103                                    /* this is converted to 'theImage' */
00104   unsigned int  eWIDE, eHIGH;  /* size of epic */
00105   unsigned int  normFact;      /* factor to shrink picture by for 'norm' */
00106 
00107   byte           r[256],g[256],b[256];  /* colormap */
00108   byte           rorg[256],gorg[256],borg[256];  /* ORIGINAL colormap */
00109 
00110   int            transparent_index;
00111 
00112 
00113   XImage        *theImage;     /* X version of epic */
00114 
00115   void          *theMask; /* actually a wxMemoryDC */
00116 
00117   unsigned long freecols[256]; /* list of pixel values to free */
00118   int           nfcols;        /* number of colors to free */
00119   unsigned long cols[256];     /* maps pic pixel values to X pixel vals */
00120   int           fc2pcol[256];  /* maps freecols into pic pixel values */
00121   int           numcols;       /* # of desired colors in picture */
00122   int           ncols;         /* max # of (different) colors to alloc */
00123 
00124   int           expand,        /* expansion amount */
00125                 bwidth,        /* border width of created windows */
00126                 noglob,        /* force to only use colors it alloced */
00127                 revvideo,      /* reverse video */
00128                 perfect,       /* perfect color.  install own colormap */
00129                 fixedaspect,   /* fixed aspect ratio */
00130                 slow24,        /* use slow 24to8 algorithm */
00131                 ninstall,      /* true if using icccm-complaint WM
00132                                   (a WM that will does install CMaps */
00133                 useroot,       /* true if we should draw in rootW */
00134                 noqcheck,      /* true if we should NOT do QuickCheck */
00135                 rwcolor,       /* true if we should use R/W color cells */
00136                 rwthistime,    /* true if we DID use R/W color cells */
00137                 brokeFreeCols; /* true if server has broken XFreeColors */
00138 
00139   float         defaspect,     /* default aspect ratio to use */
00140                 normaspect;    /* normal aspect ratio of this picture */
00141 
00142 
00143 
00144   /*************************** XVMISC.C ***************************/
00145 
00146 #if 0
00147   void Rotate(int);
00148 #endif
00149   void SortColormap(void);
00150   void AllocColors(void);
00151   void AllocRWColors(void);
00152   void DoMonoAndRV(void);
00153   void FSDither(byte *, int, int, byte *);
00154   void CreateXImage(void);
00155   void FatalError(char *);
00156 
00157   /*************************** XV24TO8.C **************************/
00158   int  Conv24to8(byte *, int, int, int);
00159 
00160   int Quick24to8(byte *p24, int w, int h);
00161   int QuickCheck(byte *pic24, int w, int h, int maxcol);
00162   void get_histogram(CBOX *box);
00163   CBOX *largest_box();
00164   void splitbox(CBOX *ptr);
00165   void shrinkbox(CBOX *box);
00166   int quant_fsdither();
00167 
00168   /**************************** XVGAM.C **************************/
00169   void GenerateGamma(void);
00170   void GenerateFSGamma(void);
00171   void GammifyColors(void);
00172   void HSVgamma(void);
00173 
00174   /**************************** XVGIF.C ***************************/
00175   int LoadGIF(char *, int);
00176   int WriteGIF(FILE *fp, byte *pic, int w, int h, byte *rmap, byte *gmap, byte *bmap, int numcols, int colorstyle);
00177 
00178 #if 0
00179   /**************************** XVPM.C ****************************/
00180   int LoadPM(char *, int);
00181   int WritePM(FILE *, byte *, int, int, byte *, byte *, byte *, int, int);
00182 #endif
00183 
00184 #if 0
00185   /**************************** XVPBM.C ***************************/
00186   int LoadPBM(char *, int);
00187   int WritePBM(FILE *, byte *, int, int, byte *, byte *, byte *, int, int, int);
00188   int loadpbm(FILE *fp, int w, int h, int raw);
00189   int loadpgm(FILE *fp, int w, int h, int maxv, int raw);
00190   int loadppm(FILE *fp, int w, int h, int maxv, int raw, int nc);
00191 #endif
00192 
00193   /**************************** XVXBM.C ***************************/
00194   int LoadXBM(char *, int);
00195   int WriteXBM(FILE *, byte *, int, int, char *);
00196 
00197   /* xvbmp.c */
00198   int LoadBMP(char *fname, PICINFO *pinfo);
00199   int WriteBMP(FILE *fp, byte *pic824, int ptype, int w, int h, byte *rmap, byte *gmap, byte *bmap, int numcols, int colorstyle);
00200 
00201 #if 0
00202   /* xvpcx.c */
00203   int LoadPCX(char *fname, PICINFO *pinfo);
00204 #endif
00205 
00206    /* Taken from xvmisc.c */
00207 #if 0
00208   void RotatePic(byte *, unsigned int *, unsigned int *, int);
00209 #endif
00210   void FloydDitherize8(byte *);
00211   void FloydDitherize1(XImage *);
00212   void FreeMostResources(void);
00213 
00214   /* Taken from xvgif.c */
00215   int  ReadCode();
00216   void DoInterlace(byte);
00217   int  GifError(char *);
00218 
00219   /* Taken from xv.c */
00220   int  openPic(char *file);
00221   void closePic();
00222   void FixAspect(int, int *, int *);
00223   void GetWindowPos(XWindowAttributes *);
00224   void SetWindowPos(XWindowAttributes *);
00225   int  rd_int(char *);
00226   int  rd_str(char *);
00227   int  rd_flag(char *);
00228 #endif
00229 };
00230 
00231 
00232 void *wxiAllocMask(int w, int h);
00233 void wxiSetMask(void *mask, int w, int h, int on);
00234 
00235 #endif // wx_imageh