Back to index

plt-scheme  4.2.1
wx_image.cc
Go to the documentation of this file.
00001 /*
00002  * File:     wx_image.cc
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 #ifdef wx_xview
00031 #include <stdlib.h>
00032 #endif
00033 
00034 #ifdef wx_motif
00035 #include <stdlib.h>
00036 #endif
00037 
00038 #include <string.h>
00039 
00040 #define Uses_XtIntrinsic
00041 
00042 #include "wx_image.h"
00043 #include "wx_canvs.h"
00044 #include "wx_gdi.h"
00045 #include "wx_dcmem.h"
00046 #include "wx_utils.h"
00047 #include "wx_visual.h"
00048 
00049 #ifndef wx_x
00050 #error wxImage should only be compiled under X!
00051 #endif
00052 
00053 #ifdef wx_x
00054 
00055 #include <X11/X.h>
00056 #ifdef wx_xview
00057 #include <xview/screen.h>
00058 #include <xview/cursor.h>
00059 #include <xview/svrimage.h>
00060 extern Xv_Server xview_server;
00061 #endif
00062 #ifdef wx_motif
00063 #endif
00064 
00065 /* file types that can be read */
00066 #define UNKNOWN 0
00067 #define GIF     1
00068 #define PM      2
00069 #define PBM     3
00070 #define XBM     4
00071 #define BMP     5
00072 #define PCX     6
00073 
00074 static unsigned long rootbg, rootfg;  /* fg/bg for root border */
00075 static int    autoquit = 0;     /* quit after loading first pic to rootW */
00076 static int    autogamma = 0;    /* perform gamma correction by default */
00077 static int    rootPattern = 0;  /* pattern used for root border */
00078 static char   initpath[500];
00079 
00080 /* used in XResource reading... */
00081 static char *def_str;
00082 static long int   def_int;
00083 
00084 
00085 wxImage::wxImage(void)
00086 {
00087 //  cMap = new wxColourMap;
00088   int   imap, ctrlmap, gmap, clrroot;
00089   char *display, *fname, *whitestr, *blackstr, 
00090        *infogeom, *fgstr, *bgstr, *ctrlgeom, *gamgeom;
00091   char *rootfgstr, *rootbgstr;
00092 
00093   XColor ecdef;
00094   nfcols = 0;
00095 
00096   cMap = NULL;
00097   filetype = wxUNKNOWN;
00098 
00099   /*****************************************************/
00100   /*** variable Initialization                       ***/
00101   /*****************************************************/
00102 
00103   getcwd(initpath, sizeof(initpath));
00104 
00105   /* init internal variables */
00106   display = fname = whitestr = blackstr = NULL;
00107   fgstr = bgstr = rootfgstr = rootbgstr = NULL;
00108   pic = epic = cpic = NULL;
00109   theImage = NULL;
00110   theMask = NULL;
00111   LocalCmap = 0;
00112   InitFSDTables(); // Only need in xvpbm.c and xvpm.c. Defined in xv24to8.c
00113 
00114   /* init gamma curve */
00115   ghand[0].x =   0;  ghand[0].y =   0;
00116   ghand[1].x =  64;  ghand[1].y =  64;
00117   ghand[2].x = 192;  ghand[2].y = 192;
00118   ghand[3].x = 255;  ghand[3].y = 255;
00119 
00120   /* init command-line options flags */
00121   infogeom = DEFINFOGEOM;  ctrlgeom = DEFCTRLGEOM;  gamgeom = DEFGAMGEOM;
00122   expand = 1;  ncols = -1;  noglob = 0;  revvideo = 0;  mono = 0;  
00123   perfect = 0;  ninstall = 0;  fixedaspect = 0;  
00124   imgDEBUG = 0;  bwidth = 2;
00125   useroot = clrroot = noqcheck = rwcolor = 0;
00126 
00127 #ifdef BROKEFREECOLS
00128   brokeFreeCols = 1;
00129 #else
00130   brokeFreeCols = 0;
00131 #endif
00132 
00133   defaspect = normaspect = 1.0;
00134 
00135   imap = ctrlmap = gmap = 0;
00136 
00137   transparent_index = -2;
00138 
00139   /*****************************************************/
00140   /*** X Resource Initialization                     ***/
00141   /*****************************************************/
00142 
00143   /* open the display */
00144 /*
00145   if ( (theDisp=XOpenDisplay(display)) == NULL) {
00146     fprintf(stderr, "Can't open display.\n");
00147     exit(1);
00148   }
00149 */
00150   theDisp = wxAPP_DISPLAY;
00151 
00152   if (rd_str ("infoGeometry"))  infogeom = def_str;
00153   if (rd_flag("infoMap"))       imap     = def_int;
00154   if (rd_flag("mono"))          mono     = def_int;
00155   if (rd_int ("ncols"))         { ncols  = def_int; if (ncols>=0) noglob = 1; }
00156   if (rd_flag("nglobal"))       noglob   = def_int;
00157   if (rd_flag("ninstall"))      ninstall = def_int;
00158   if (rd_flag("noqcheck"))      noqcheck = def_int;
00159   if (rd_flag("perfect"))       perfect  = def_int;
00160   if (rd_flag("reverseVideo"))  revvideo = def_int;
00161   if (rd_str ("rootBackground")) rootbgstr = def_str;
00162   if (rd_str ("rootForeground")) rootfgstr = def_str;
00163   if (rd_int ("rootPattern"))    rootPattern = def_int;
00164   if (rd_flag("rwColor"))       rwcolor  = def_int;
00165   if (rd_flag("slow24"))        slow24   = def_int;
00166   if (rd_str ("white"))         whitestr = def_str;
00167       
00168   /* if using root, generally gotta map ctrl window, 'cause there won't be
00169      any way to ask for it.  (no kbd or mouse events from rootW) */
00170   if (useroot && !autoquit) 
00171     ctrlmap = 1;    
00172 
00173   /* must not install colormaps on rootW */
00174   if (useroot) { perfect=0;  noglob = 1; } 
00175 
00176 
00177   /*****************************************************/
00178   /*** X Setup                                       ***/
00179   /*****************************************************/
00180   
00181   theScreen = DefaultScreen(theDisp);
00182   theCmap   = wx_default_colormap;
00183   rootW     = RootWindow(theDisp,theScreen);
00184   theVisual = wxAPP_VISUAL;
00185   ncells    = DisplayCells(theDisp, theScreen);
00186   dispWIDE  = DisplayWidth(theDisp,theScreen);
00187   dispHIGH  = DisplayHeight(theDisp,theScreen);
00188   dispDEEP  = wx_visual_depth;
00189 
00190   /* set up white,black colors */
00191   white = WhitePixel(theDisp,theScreen);
00192   black = BlackPixel(theDisp,theScreen);
00193   if (whitestr && XParseColor(theDisp, theCmap, whitestr, &ecdef) &&
00194       XAllocColor(theDisp, theCmap, &ecdef))  white = ecdef.pixel;
00195   if (blackstr && XParseColor(theDisp, theCmap, blackstr, &ecdef) &&
00196       XAllocColor(theDisp, theCmap, &ecdef))  black = ecdef.pixel;
00197 
00198   /* set up fg,bg colors */
00199   fg = black;   bg = white;
00200   if (fgstr && XParseColor(theDisp, theCmap, fgstr, &ecdef) &&
00201       XAllocColor(theDisp, theCmap, &ecdef))  fg = ecdef.pixel;
00202   if (bgstr && XParseColor(theDisp, theCmap, bgstr, &ecdef) &&
00203       XAllocColor(theDisp, theCmap, &ecdef))  bg = ecdef.pixel;
00204 
00205   /* set up root fg,bg colors */
00206   rootfg = white;   rootbg = black;
00207   if (rootfgstr && XParseColor(theDisp, theCmap, rootfgstr, &ecdef) &&
00208       XAllocColor(theDisp, theCmap, &ecdef))  rootfg = ecdef.pixel;
00209   if (rootbgstr && XParseColor(theDisp, theCmap, rootbgstr, &ecdef) &&
00210       XAllocColor(theDisp, theCmap, &ecdef))  rootbg = ecdef.pixel;
00211 
00212   /* set up infofg,infobg colors */
00213   infofg = fg;   infobg = bg;
00214 
00215 
00216   /* if '-mono' not forced, determine if we're on a b/w or color monitor */
00217   if (!mono)
00218   {
00219     if (!wxColourDisplay())
00220       mono = 1;
00221   }
00222   
00223   /* if ncols wasn't set, set it to 2^dispDEEP, unless dispDEEP=1, in which
00224      case ncols = 0;  (ncols = max number of colors allocated.  on 1-bit
00225      displays, no colors are allocated */
00226 
00227   if (ncols == -1) {
00228     if (dispDEEP>1) ncols = 1<<dispDEEP;
00229     else ncols = 0;
00230   }
00231   else if (ncols>256) ncols = 256;       /* so program doesn't blow up */
00232 
00233   GenerateGamma();
00234   GenerateFSGamma();
00235 
00236   /* if we're not on a colormapped display, turn off rwcolor */
00237 /*
00238   if (!(theVisual->class & 1) && rwcolor) {
00239     fprintf(stderr,"xv: not a colormapped display.  'rwcolor' turned off.\n");
00240     rwcolor = 0;
00241   }
00242 */
00243  
00244 }
00245 
00246 wxImage::~wxImage(void)
00247 {
00248   Destroy();
00249 }
00250 
00251 Bool wxImage::Load(char *file)
00252 {
00253   Destroy();
00254   return openPic(file);
00255 }
00256 
00257 Bool wxImage::Destroy(void)
00258 {
00259   closePic();
00260   return TRUE;
00261 }
00262 
00263 void wxImage::GetSize(int *width, int *height)
00264 {
00265   *width = eWIDE;
00266   *height = eHIGH;
00267 }
00268 
00269 wxColourMap *wxImage::GetColourMap(void)
00270 {
00271   SortColormap();
00272 
00273   // save the desired RGB colormap (before gamma-correcting it)
00274   for (int i=0; i<numcols; i++)
00275     { rorg[i] = r[i];  gorg[i] = g[i];  borg[i] = b[i]; }
00276 
00277   DoMonoAndRV();
00278   if (autogamma) GammifyColors();
00279 
00280   if (rwcolor) AllocRWColors();
00281           else AllocColors();
00282 
00283   if (LocalCmap)
00284   {
00285 #if 0
00286     /* MATTHEW: [4] Use PutXColormap */
00287     wxColourMap *colourMap = new wxColourMap;
00288     colourMap->PutXColormap(theDisp, LocalCmap, FALSE);
00289     return colourMap;
00290 //    XSetWindowColormap(theDisp,mainW, LocalCmap);
00291 #endif
00292     return NULL;
00293   } else
00294     return NULL;
00295 }
00296 
00297 /*
00298 void wxImage::SetWindow(wxCanvas *can)
00299 {
00300   canvas = can;
00301   if (!canvas)
00302     return;
00303 
00304   SortColormap();
00305 
00306   // save the desired RGB colormap (before gamma-correcting it)
00307   for (int i=0; i<numcols; i++)
00308     { rorg[i] = r[i];  gorg[i] = g[i];  borg[i] = b[i]; }
00309 
00310   DoMonoAndRV();
00311   if (autogamma) GammifyColors();
00312 
00313   if (rwcolor) AllocRWColors();
00314           else AllocColors();
00315 
00316 //  Resize(eWIDE,eHIGH);
00317 
00318   if (LocalCmap) {
00319 //    XSetWindowAttributes xswa;
00320 //    if (!ninstall) XInstallColormap(theDisp,LocalCmap); // Should only be used by WMs!!
00321 //    xswa.colormap = LocalCmap;
00322 //    XChangeWindowAttributes(theDisp,mainW,CWColormap,&xswa);
00323     XSetWindowColormap(theDisp,mainW, LocalCmap);
00324   }
00325 }
00326 
00327 */
00328 
00329 int wxImage::openPic(char *fullname)
00330 {
00331   /* tries to load file #filenum (from 'namelist' list)
00332    * returns 0 on failure (cleans up after itself)
00333    * if successful, returns 1
00334    */
00335   PICINFO pinfo;
00336   int   i,okay,freename, nw, nh;
00337   char *tmp;
00338   FILE *fp;
00339   char  filename[256], /* full name of the file to be loaded (could be /tmp) */
00340         basename[128], /* just the name of the original file. No path */
00341         magicno[8];    /* first 8 bytes of file */
00342 
00343   xvbzero((char *) &pinfo, sizeof(PICINFO));
00344   
00345   normaspect = defaspect;
00346 
00347   /* clear any old error messages */
00348 
00349   okay = 0;
00350 
00351   /* set up fullname and basename */
00352 
00353   tmp = strchr(fullname,'/');
00354   if (!tmp)  {
00355     tmp = fullname; 
00356   } else {
00357     tmp = tmp XFORM_OK_PLUS 1;
00358   }
00359   strcpy(basename,tmp);
00360   tmp = NULL;
00361 
00362   /* if fullname doesn't start with a '/' (ie, it's a relative path), 
00363      (and it's not the special case '<stdin>') prepend 'initpath' to it */
00364   freename = 0;
00365   if (fullname[0] != '/' && strcmp(fullname,STDINSTR)!=0) {
00366     char *atmp;
00367     atmp = (char *) malloc(strlen(fullname) + strlen(initpath) + 2);
00368     if (!atmp) FatalError("malloc 'filename' failed");
00369     sprintf(atmp,"%s/%s", initpath, fullname);
00370     fullname = atmp;
00371     freename = 1;
00372   }
00373     
00374   strcpy(filename,fullname);
00375 
00376   /* now, try to determine what type of file we've got by reading the
00377      first couple bytes and looking for a Magic Number */
00378 
00379   fp=fopen(filename,"r");
00380   if (!fp) {
00381     goto FAILED;
00382   }
00383 
00384   fread(magicno,8,1,fp);  
00385   fclose(fp);
00386 
00387   filetype = UNKNOWN;
00388   if (strncmp(magicno,"GIF87",5)==0) filetype = GIF;
00389 
00390   else if (strncmp(magicno,"GIF89",5)==0) filetype = GIF;
00391 
00392   else if (strncmp(magicno,"#define",7)==0) filetype = XBM;
00393 
00394   else if (magicno[0] == 'B' && magicno[1] == 'M') filetype = BMP;
00395 
00396   if (filetype == UNKNOWN) {
00397     goto FAILED;
00398   }
00399 
00400   i = 1;
00401   switch (filetype) {
00402   case GIF: i = LoadGIF(filename,ncols); break;
00403   case XBM: i = LoadXBM(filename,ncols); break;
00404   case BMP: 
00405     {
00406       i = !(LoadBMP(filename, &pinfo));
00407       pic   = pinfo.pic;
00408       pWIDE = pinfo.w;
00409       pHIGH = pinfo.h;
00410       break;
00411     }
00412 
00413   }
00414   cpic = NULL;
00415 
00416   if (i) {
00417     goto FAILED;
00418   }
00419 
00420   /* successfully read this picture */
00421 
00422   /* if we read a /tmp file, delete it.  won't be needing it any more */
00423   if (strcmp(fullname,filename)!=0) unlink(filename);
00424 
00425   normFact = 1;  nw = pWIDE;  nh = pHIGH;
00426 
00427   // expand:  if expansion is negative, treat it as a reciprocal
00428   if (expand < 0) { 
00429     int ae;
00430     ae = abs(expand);
00431     eWIDE = pWIDE/ae;
00432     eHIGH = pHIGH/ae;
00433   } else { 
00434     eWIDE = pWIDE * expand; 
00435     eHIGH = pHIGH * expand;
00436   }
00437 
00438   cpic = pic;  cWIDE = pWIDE;  cHIGH = pHIGH;  cXOFF = cYOFF = 0;
00439 
00440   if (freename) free(fullname);
00441 
00442   return 1;
00443 
00444   
00445  FAILED:
00446   if (strcmp(fullname,filename)!=0) unlink(filename);   /* kill /tmp file */
00447   if (freename) free(fullname);
00448   return 0;
00449 }
00450 
00451 
00452 
00453 
00454 /***********************************/
00455 void wxImage::closePic()
00456 {
00457   /* kill all resources used for this picture.
00458      this would include the window, any allocated colors, pic, epic, 
00459      theImage, etc. */
00460 
00461 #if 0 /* Don't free any colors */
00462   if (LocalCmap) {
00463     // Should be destroyed by ~wxColourMap
00464     //    XFreeColormap(theDisp,LocalCmap);
00465     LocalCmap = 0;
00466   }
00467   else if (!brokeFreeCols) {
00468     for (i=0; i<nfcols; i++) 
00469       XFreeColors(theDisp, theCmap, &freecols[i], 1, 0L);
00470   }
00471   else {
00472     for (i=0; i<nfcols; i++) {
00473       int j;
00474       for (j=0; j<i; j++) {
00475         if (freecols[i] == freecols[j])   /* already been freed once */
00476          break;
00477       }
00478       if (j==i)      /* wasn't found in already-freed list */
00479         XFreeColors(theDisp, theCmap, &freecols[i], 1, 0L);
00480     }
00481   }
00482 #endif
00483 
00484   if (epic != cpic && epic != NULL) free(epic);
00485   if (cpic !=  pic && cpic != NULL) free(cpic);
00486   if (pic != NULL) free(pic);
00487   if (theImage != NULL) xvDestroyImage(theImage);
00488   theImage = NULL;
00489   pic = epic = cpic = NULL;
00490 
00491 }
00492 
00493 /***********************************/
00494 void wxImage::FixAspect(int grow,int *w,int *h)
00495 {
00496   /* computes new values of eWIDE and eHIGH which will have aspect ratio
00497      'normaspect'.  If 'grow' it will preserve aspect by enlarging, 
00498      otherwise, it will shrink to preserve aspect ratio.  
00499      Returns these values in 'w' and 'h' */
00500 
00501   float xr,yr,curaspect,a,exp;
00502 
00503   *w = eWIDE;  *h = eHIGH;
00504 
00505   /* xr,yr are expansion factors */
00506   xr = ((float) eWIDE) / cWIDE;
00507   yr = ((float) eHIGH) / cHIGH;
00508   curaspect  = xr / yr;
00509 
00510   /* if too narrow & shrink, shrink height.  too wide and grow, grow height */
00511   if ((curaspect < normaspect && !grow) || 
00512       (curaspect > normaspect &&  grow)) {    /* modify height */
00513     exp = curaspect / normaspect;
00514     *h = (int) (eHIGH * exp + .5);
00515   }
00516 
00517   /* if too narrow & grow, grow width.  too wide and shrink, shrink width */
00518   if ((curaspect < normaspect &&  grow) || 
00519       (curaspect > normaspect && !grow)) {    /* modify width */
00520     exp = normaspect / curaspect;
00521     *w = (int) (eWIDE * exp + .5);
00522   }
00523 
00524 
00525   /* shrink to fit screen without changing aspect ratio */
00526   if ((unsigned)*w > dispWIDE) {
00527     int i;
00528     a = (float) *w / dispWIDE;
00529     *w = dispWIDE;
00530     i = (int) (*h / a + .5);        /* avoid freaking some optimizers */
00531     *h = i;
00532   }
00533 
00534   if ((unsigned)*h > dispHIGH) {
00535     a = (float) *h / dispHIGH;
00536     *h = dispHIGH;
00537     *w = (int) (*w / a + .5);
00538   }
00539 
00540   if (*w < 1) *w = 1;
00541   if (*h < 1) *h = 1;
00542 }
00543 
00544 /************************************************************************/
00545 /* following three rd_* functions swiped from xgraph, by David Harrison */
00546 /************************************************************************/
00547 
00548 /***********************************/
00549 int wxImage::rd_int(char *name)
00550 {
00551   /* returns '1' if successful.  result in def_int */
00552 
00553   def_str = XGetDefault(theDisp, PROGNAME, name);
00554   if (def_str) {
00555     if (sscanf(def_str, "%ld", &def_int) == 1)
00556       return 1;
00557     else {
00558       fprintf(stderr, "wxImage: couldn't read integer value for %s resource\n", 
00559              name);
00560       return 0;
00561     }
00562   }
00563   else return 0;
00564 
00565 }
00566 
00567 /***********************************/
00568 int wxImage::rd_str(char *name)
00569 {
00570   /* returns '1' if successful.  result in def_str */
00571   
00572   def_str = XGetDefault(theDisp, PROGNAME, name);
00573   if (def_str) return 1;
00574   else return 0;
00575 
00576 }
00577 
00578 /***********************************/
00579 int wxImage::rd_flag(char *name)
00580 {
00581   /* returns '1' if successful.  result in def_str */
00582   
00583   def_str = XGetDefault(theDisp, PROGNAME, name);
00584   if (def_str) {
00585     def_int = (strcmp(def_str, "on")==0) || 
00586               (strcmp(def_str, "1")==0) ||
00587              (strcmp(def_str, "true")==0) ||
00588              (strcmp(def_str, "yes")==0);
00589     return 1;
00590     }
00591 
00592   else return 0;
00593 }
00594 
00595 /*
00596  * Get a wxBitmap and wxColourMap
00597  */
00598 Bool wxLoadIntoBitmap(char *filename, wxBitmap *bitmap, wxColourMap **cmap, int getMask)
00599 {
00600   wxImage *tempImage;
00601   tempImage = new wxImage;
00602   if (getMask)
00603     tempImage->transparent_index = -1;
00604   if (FileExists(filename) && tempImage->Load(filename))
00605   {
00606     Pixmap pm;
00607     Display *dpy;
00608     GC agc;
00609     int err;
00610     wxColourMap *tempColourMap;
00611 
00612     if (!bitmap->Create(tempImage->eWIDE, tempImage->eHIGH, 
00613                      tempImage->dispDEEP))
00614       return FALSE;
00615 
00616     if (!tempImage->numcols)
00617       tempColourMap = NULL;
00618     else
00619       tempColourMap = tempImage->GetColourMap();
00620 
00621     tempImage->Resize(tempImage->eWIDE, tempImage->eHIGH);
00622 
00623     if (!tempImage->theImage)
00624       return FALSE;
00625 
00626     wxFlushEvents();
00627 
00628     pm = *(Pixmap *)bitmap->GetHandle();
00629 
00630     dpy = tempImage->theDisp;
00631     agc = XCreateGC(dpy, pm, (unsigned long )NULL, NULL);
00632     
00633 #if 0
00634     bitmap -> free_colors_num = tempImage -> nfcols;
00635     bitmap -> free_colors = new unsigned long [bitmap -> free_colors_num];
00636     long llp;
00637     XColor xcol;
00638     for(llp = 0;llp < bitmap -> free_colors_num;llp++)
00639        {
00640          xcol.pixel = bitmap -> free_colors[llp] = 
00641                       tempImage -> freecols[llp];
00642          XQueryColor(dpy,tempImage -> theCmap, &xcol);
00643          XAllocColor(dpy,tempImage -> theCmap, &xcol);
00644        }
00645 #endif
00646 
00647     err = XPutImage(dpy,pm,agc,tempImage->theImage,
00648                   0,0,
00649                   0,0,
00650                   tempImage->eWIDE,tempImage->eHIGH);
00651 
00652     // Get rid of compiler warning
00653     err = 0;
00654 
00655     XFreeGC(dpy, agc);
00656 
00657     // bitmap->SetOk(TRUE);
00658 
00659     if (tempImage->theMask) {
00660       wxMemoryDC *mdc = (wxMemoryDC *)tempImage->theMask;
00661 
00662       if (mdc->Ok()) {
00663        wxBitmap *mbm;
00664        mbm = mdc->GetObject();
00665        bitmap->SetMask(mbm);
00666        mdc->SelectObject(NULL);
00667       }
00668       tempImage->theMask = NULL;
00669     }
00670 
00671     delete tempImage;
00672 
00673     if (cmap)
00674       *cmap = tempColourMap;
00675     else
00676       delete tempColourMap;
00677     return TRUE;
00678   }
00679   else
00680     return FALSE;
00681 }
00682 
00683 wxBitmap *wxLoadBitmap(char *s, wxColourMap **cmap)
00684 {
00685   wxBitmap *bitmap;
00686   bitmap = new wxBitmap;
00687   if (wxLoadIntoBitmap(s, bitmap, cmap))
00688     return bitmap;
00689   else {
00690     delete bitmap;
00691     return NULL;
00692   }
00693 }
00694 
00695 void *wxiAllocMask(int w, int h)
00696 {
00697   wxMemoryDC *mdc;
00698   wxBitmap *bm;
00699 
00700   mdc = new wxMemoryDC();
00701   bm = new wxBitmap(w, h, 1);
00702   mdc->SelectObject(bm);
00703 
00704   if (mdc->Ok())
00705     return mdc;
00706   else
00707     return NULL;
00708 }
00709 
00710 static wxColour *sm_c;
00711 
00712 void wxiSetMask(void *mask, int w, int h, int on)
00713 {
00714   wxMemoryDC *mdc = (wxMemoryDC *)mask;
00715 
00716   if (mask) {
00717     if (!sm_c) {
00718       wxREGGLOB(sm_c);
00719       sm_c = new wxColour;
00720     }
00721     if (on)
00722       sm_c->Set(0, 0, 0);
00723     else
00724       sm_c->Set(255, 255, 255);
00725     mdc->SetPixel(w, h, sm_c);
00726   }
00727 }
00728  
00729 
00730 #endif // End X implementation
00731 
00732 #ifdef wx_msw // Start MSW implementation
00733 wxImage::wxImage(void)
00734 {
00735 }
00736 
00737 wxImage::~wxImage(void)
00738 {
00739 }
00740 
00741 Bool wxImage::Load(char *file)
00742 {
00743   return FALSE;
00744 }
00745 
00746 Bool wxImage::Destroy(void)
00747 {
00748   return FALSE;
00749 }
00750 
00751 void wxImage::Draw(wxCanvas *canvas, int x, int y, int width, int height)
00752 {
00753 }
00754 
00755 void wxImage::Resize(int width, int height)
00756 {
00757 }
00758 
00759 void wxImage::GetSize(int *width, int *height)
00760 {
00761   *width = 0;
00762   *height = 0;
00763 }
00764 
00765 wxColourMap *wxImage::GetColourMap(void)
00766 {
00767   return NULL;
00768 }
00769 
00770 #endif // End MSW implementation