Back to index

plt-scheme  4.2.1
Public Member Functions | Public Attributes
wxBitmap Class Reference

#include <Bitmap.h>

Inheritance diagram for wxBitmap:
Inheritance graph
[legend]
Collaboration diagram for wxBitmap:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 wxBitmap (void)
 wxBitmap (char bits[], int width, int height)
 wxBitmap (int width, int height, Bool blackAndWhite=FALSE)
 wxBitmap (char *name, long flags=wxBITMAP_DEFAULT, wxColour *bg=NULL)
 ~wxBitmap (void)
Bool Create (int width, int height, int depth=-1)
void Destroy (void)
int GetDepth (void)
int GetHeight (void)
void GetHotSpot (int *x, int *y)
int GetWidth (void)
wxColourMapGetColourMap (void)
void SetColourMap (wxColourMap *new_cmap)
Bool LoadFile (char *name, long flags=wxBITMAP_DEFAULT, wxColour *bg=NULL)
Bool SaveFile (char *name, int type, int quality=75, wxColourMap *cmap=NULL)
virtual Bool Ok (void)
virtual voidGetHandle (void)
void SetMask (wxBitmap *bm)
wxBitmapGetMask ()
wxBitmapGetMaskBit ()
void FreeMaskBit ()
voidGetLabelPixmap (Bool for_button=FALSE)
void ReleaseLabel ()
void SetGLConfig (wxGLConfig *gl_cfg)
wxGLConfigGetGLConfig (void)
void install_cleanup ()
voidoperator new (size_t size)
voidoperator new (size_t size, GCPlacement gcp)
voidoperator new (size_t size, void *p)
voidoperator new (size_t size)
voidoperator new (size_t size, GCPlacement gcp)
void operator delete (void *obj)
void operator delete (void *, void *)
void operator delete (void *obj)
voidoperator new[] (size_t size)
voidoperator new[] (size_t size, GCPlacement gcp)
voidoperator new[] (size_t size, void *p)
void operator delete[] (void *obj)
void operator delete[] (void *, void *)

Public Attributes

wxBitmap_XinternXbitmap
wxColourMapcmap
wxBitmaploaded_mask
wxBitmapmaskBit
wxBitmaplabel_bm
wxBitmapbutton_label_bm
wxGLConfiggl_cfg
int selectedIntoDC
wxMemoryDCselectedTo
WXTYPE __type
void__gc_external

Detailed Description

Definition at line 48 of file Bitmap.h.


Constructor & Destructor Documentation

Definition at line 94 of file Bitmap.cc.

Here is the caller graph for this function:

wxBitmap::wxBitmap ( char  bits[],
int  width,
int  height 
)

Definition at line 103 of file Bitmap.cc.

{
    __type = wxTYPE_BITMAP;

    Xbitmap = new wxBitmap_Xintern;
    cmap    = wxAPP_COLOURMAP;

    // set bitmap specific data
    Xbitmap->type   = __BITMAP_NORMAL;
    Xbitmap->width  = w;
    Xbitmap->height = h;
    Xbitmap->depth  = 1; // don't know what to do if depth > 1 !!!
    Xbitmap->x_hot  = 0;
    Xbitmap->y_hot  = 0;

    // create pixmap with depth 1
    Xbitmap->x_pixmap = XCreateBitmapFromData(wxAPP_DISPLAY, wxAPP_ROOT, bits, w, h);
    if (Xbitmap->x_pixmap == None) {
      // create failed
      DELETE_OBJ Xbitmap;
      Xbitmap = NULL;
    }
    Xbitmap->account = GC_malloc_accounting_shadow((w * h) >> 3);

    WXGC_IGNORE(this, selectedTo);
}

Here is the call graph for this function:

wxBitmap::wxBitmap ( int  width,
int  height,
Bool  blackAndWhite = FALSE 
)

Definition at line 200 of file Bitmap.cc.

{
    __type = wxTYPE_BITMAP;

    Xbitmap = NULL;
    cmap    = wxAPP_COLOURMAP;

    // use create method
    (void)Create(w, h, b_and_w ? 1 : -1);

    WXGC_IGNORE(this, selectedTo);
}

Here is the call graph for this function:

wxBitmap::wxBitmap ( char *  name,
long  flags = wxBITMAP_DEFAULT,
wxColour bg = NULL 
)

Definition at line 131 of file Bitmap.cc.

{
    __type = wxTYPE_BITMAP;

    Xbitmap = NULL;
    cmap    = wxAPP_COLOURMAP;

    // use load method
    (void)LoadFile(bitmap_file, flags, bg);

    WXGC_IGNORE(this, selectedTo);
}

Here is the call graph for this function:

Definition at line 214 of file Bitmap.cc.

{
    // free pixmap and infos
    Destroy();

    selectedTo = NULL;
}

Here is the call graph for this function:


Member Function Documentation

Bool wxBitmap::Create ( int  width,
int  height,
int  depth = -1 
)

Definition at line 232 of file Bitmap.cc.

{
    X_Err_Handler old_handler;

    Destroy(); // destroy old bitmap if any

    Xbitmap = new wxBitmap_Xintern;
    // set pixmap specific data
    Xbitmap->type   = __BITMAP_NORMAL;
    Xbitmap->width  = w;
    Xbitmap->height = h;
    if (d < 1) {
      Xbitmap->depth = wxDisplayDepth();
    } else {
      Xbitmap->depth = d;
    }
    Xbitmap->x_hot  = 0;
    Xbitmap->y_hot  = 0;
    // create pixmap

    old_handler = XSetErrorHandler(FlagError);
    errorFlagged = 0;

    Xbitmap->x_pixmap = XCreatePixmap(wxAPP_DISPLAY, wxAPP_ROOT, w, h, Xbitmap->depth);
    
    XSync(wxAPP_DISPLAY, FALSE);

    if (errorFlagged)
      Xbitmap->x_pixmap = None;

    XSetErrorHandler(old_handler);

    if (Xbitmap->x_pixmap == None) {
      // create failed!
      DELETE_OBJ Xbitmap;
      Xbitmap = NULL;
    } else {
      Xbitmap->account = GC_malloc_accounting_shadow((w * h * ((Xbitmap->depth == 1) ? 1 : 32)) >> 3);
    }

    return Ok();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 276 of file Bitmap.cc.

{
  FreeMaskBit();

  if (Xbitmap) {
    XFreePixmap(wxAPP_DISPLAY, Xbitmap->x_pixmap); // free pixmap
    GC_free_accounting_shadow(Xbitmap->account);
    Xbitmap->account = NULL;
# ifdef WX_USE_XRENDER
    if (Xbitmap->picture) {
      wxFreePicture(Xbitmap->picture);
    }
# endif
    
    switch (Xbitmap->type) { // free type specific data
    case __BITMAP_XPM:
      {
       // free XPM data
       Colormap cm;
       cm = *((Colormap*)(cmap->GetHandle()));
       XFreeColors(wxAPP_DISPLAY, cm, Xbitmap->xpm->pixels, Xbitmap->xpm->npixels, 0);
       XpmFreeAttributes(Xbitmap->xpm);
      }
      break;
    default:
      break; // no other formats so far
    }
    DELETE_OBJ Xbitmap;
  }
  // contains no pixmap
  Xbitmap = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 624 of file Bitmap.cc.

{
  if (maskBit) {
    DELETE_OBJ maskBit;
    maskBit = NULL;
  }
}

Here is the caller graph for this function:

Definition at line 67 of file Bitmap.h.

        { return cmap; }

Here is the caller graph for this function:

Definition at line 527 of file Bitmap.cc.

{ return (Xbitmap ? Xbitmap->depth : 0); }

Here is the caller graph for this function:

Definition at line 717 of file Bitmap.cc.

{
  if (gl_cfg)
    return gl_cfg->Clone();
  else
    return NULL;
}

Here is the call graph for this function:

void * wxBitmap::GetHandle ( void  ) [virtual]

Reimplemented in wxCursor.

Definition at line 536 of file Bitmap.cc.

                              {
  return (Xbitmap ? &(Xbitmap->x_pixmap) : NULL);
}

Definition at line 528 of file Bitmap.cc.

{ return (Xbitmap ? Xbitmap->height : 0); }

Here is the caller graph for this function:

void wxBitmap::GetHotSpot ( int x,
int y 
)

Definition at line 530 of file Bitmap.cc.

{
    if (Xbitmap) { *x = Xbitmap->x_hot; *y = Xbitmap->y_hot; }
    else         { *x = *y = 0; }
}
void * wxBitmap::GetLabelPixmap ( Bool  for_button = FALSE)

Definition at line 632 of file Bitmap.cc.

{
  int can_x_render;

#ifdef WX_USE_XRENDER
  can_x_render = wxXRenderHere();
#else
  can_x_render = 0;
#endif

  if (!can_x_render
      && ((for_button && !button_label_bm)
         || (!for_button && !label_bm))
      && loaded_mask
      && (loaded_mask->GetDepth() != 1)
      && (loaded_mask->GetWidth() == GetWidth())
      && (loaded_mask->GetHeight() == GetHeight())) {
    /* Manually construct the alpha-masked image */
    int w, h;
    wxBitmap *bm;

    w = GetWidth();
    h = GetHeight();
    bm = new wxBitmap(w, h, 0);
    if (bm->Ok()) {
      int r, g, b;

      if (selectedTo)
       selectedTo->EndSetPixel();
      if (loaded_mask->selectedTo)
       loaded_mask->selectedTo->EndSetPixel();

      {
       wxColor *co;
       if (for_button)
         co = wxBUTTON_COLOR;
       else
         co = wxGREY;
       r = co->Red();
       g = co->Green();
       b = co->Blue();
      }

      wxAlphaBlit(bm, this, loaded_mask, r, g, b);

      if (for_button)
       button_label_bm = bm;
      else
       label_bm = bm;
    }
  }

  if (for_button) {
    if (button_label_bm)
      return (void *)GETPIXMAP(button_label_bm);
  } else {
    if (label_bm)
      return (void *)GETPIXMAP(label_bm);
  }

  return (void *)GETPIXMAP(this);
}

Here is the call graph for this function:

Here is the caller graph for this function:

wxBitmap* wxBitmap::GetMask ( ) [inline]

Definition at line 82 of file Bitmap.h.

{ return loaded_mask; }

Here is the caller graph for this function:

Definition at line 554 of file Bitmap.cc.

{
  wxBitmap *bm;
  wxMemoryDC *tmp;
  wxColour *c;
  int mw, mh, v, mono;

  /* Need to create an 8-bit alpha (grayscale) pixmap or 1-bit mask by
     reading pixels of the mask pixmap. Even in the 8-bit case, we
     don't worry about a colormap for this pixmap; it will be
     interpreted as graysacle by Xrender. */

  if (maskBit)
    return maskBit;

#ifdef WX_USE_XRENDER
  mono = !wxXRenderHere();
#else
  mono = 1;
#endif

  mw = GetWidth();
  mh = GetHeight();
         
  bm = new wxBitmap();
  bm->Create(mw, mh, mono ? 1 : 8);
         
  if (bm->Ok()) {
    Pixmap bpm;
    XImage *img;
    int i, j;
         
    bpm = GETPIXMAP(bm);

    tmp = new wxMemoryDC(1);
    tmp->SelectObject(this);
           
    c = new wxColour(0, 0, 0);
    img = XGetImage(wxAPP_DISPLAY, bpm, 0, 0, mw, mh, AllPlanes, ZPixmap);
           
    tmp->BeginGetPixelFast(0, 0, mw, mh);
    for (i = 0; i < mw; i++) {
      for (j = 0; j < mh; j++) {
       int r_c, g_c, b_c;
       tmp->GetPixelFast(i, j, &r_c, &g_c, &b_c);
       v = (r_c + g_c + b_c) / 3;
       XPutPixel(img, i, j, 255 - v);
      }
    }
    tmp->EndGetPixelFast();

    tmp->SelectObject(NULL);

    {
      GC agc;
      agc = XCreateGC(wxAPP_DISPLAY, bpm, 0, NULL);
      XPutImage(wxAPP_DISPLAY, bpm, agc, img, 0, 0, 0, 0, mw, mh);
      XFreeGC(wxAPP_DISPLAY, agc);
    }

    XDestroyImage(img);

    maskBit = bm;
  } else {
    DELETE_OBJ bm;
  }

  return maskBit;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 529 of file Bitmap.cc.

{ return (Xbitmap ? Xbitmap->width : 0); }

Here is the caller graph for this function:

Definition at line 99 of file wxGC.cxx.

{
  GC_finalization_proc old_fn;
  void *old_data;

# ifdef MZ_PRECISE_GC
#  define ALLOW_NON_BASE 0
#  define CHECK_BASE 0
# else
#  ifdef wx_xt
#   define ALLOW_NON_BASE 0
#   define CHECK_BASE 0
#  else
#   ifdef WIN32
#    define ALLOW_NON_BASE 0
#    define CHECK_BASE 1
#    define CRASH_ON_NONBASE 1
#   else
#    define ALLOW_NON_BASE 1
#    define CHECK_BASE 0
#   endif
#  endif
# endif

# if CHECK_BASE || ALLOW_NON_BASE
  if (GC_base(this) != (void *)this) {
#  if ALLOW_NON_BASE
    return;
#  else
#   ifdef CRASH_ON_NONBASE
    *(long *)0x0 = 1;
#   else
    printf("Clean-up object is not the base object\n");
    abort();
#   endif
#  endif
  }
# endif

  GC_register_finalizer_ignore_self(gcOBJ_TO_PTR(this), 
                                CAST_GCP GC_cleanup, NULL, 
                                CAST_GCPP &old_fn, &old_data);

# if CHECK_BASE
  if (old_fn) {
#  ifdef CRASH_ON_NONBASE
       *(long *)0x0 = 1;
#  else
    printf("Object already has a clean-up\n");
    abort();
#  endif
  }
# endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Bool wxBitmap::LoadFile ( char *  name,
long  flags = wxBITMAP_DEFAULT,
wxColour bg = NULL 
)

Definition at line 312 of file Bitmap.cc.

{
  int getMask;

  if (selectedIntoDC)
    return FALSE;

  Destroy(); // destroy old pixmap if any

  if (flags & wxBITMAP_TYPE_MASK)
    getMask = 1;
  else
    getMask = 0;

  if (!flags || (flags == wxBITMAP_TYPE_MASK))
    flags = wxsGetImageType(fname);

  /* MATTHEW: move "Xbitmap = new wxBitmap_Xintern" into
     two appropriate cases. */

  if (flags & wxBITMAP_TYPE_XBM) { // XBM file format
    Xbitmap = new wxBitmap_Xintern;

    if (XReadBitmapFile(wxAPP_DISPLAY, wxAPP_ROOT, fname,
                     &(Xbitmap->width), &(Xbitmap->height),
                     &(Xbitmap->x_pixmap), 
                     &(Xbitmap->x_hot), &(Xbitmap->y_hot))
       == BitmapSuccess)
      {
       Xbitmap->type  = __BITMAP_NORMAL;
       Xbitmap->depth = 1;
       Xbitmap->account = GC_malloc_accounting_shadow((Xbitmap->width * Xbitmap->height) >> 3);
      } else {
       DELETE_OBJ Xbitmap;
       Xbitmap = NULL;
      }
  }
  else if (flags & wxBITMAP_TYPE_JPEG) {
    if (!read_JPEG_file(fname, this)) {
      Destroy();
    }
  }
  else if (flags & wxBITMAP_TYPE_PNG) {
    if (!wx_read_png(fname, this, getMask, bg)) {
      Destroy();
    }
  }
#if USE_XPM
else if (flags & wxBITMAP_TYPE_XPM) { // XPM file format
  Xbitmap = new wxBitmap_Xintern;

  // what I want to get
#ifdef MZ_PRECISE_GC
  {
    XpmAttributes *attr;
    attr = (XpmAttributes *)GC_malloc_atomic(sizeof(XpmAttributes));
    Xbitmap->xpm = attr;
  }
#else
  Xbitmap->xpm = new WXGC_ATOMIC XpmAttributes;
#endif
  Xbitmap->xpm->valuemask = XpmReturnInfos | XpmReturnPixels | XpmCloseness | XpmDepth;
  Xbitmap->xpm->closeness = 40000;
  Xbitmap->xpm->depth = DefaultDepth(wxAPP_DISPLAY, DefaultScreen(wxAPP_DISPLAY));
  
  if (XpmReadFileToPixmap(wxAPP_DISPLAY, wxAPP_ROOT, fname,
                       &(Xbitmap->x_pixmap), (Pixmap*)NULL, Xbitmap->xpm)
      == XpmSuccess)
    {
      // read pixmap ok!
      int sdummy; unsigned int udummy; Window wdummy;
      Xbitmap->type   = __BITMAP_XPM;
      Xbitmap->width  = Xbitmap->xpm->width;
      Xbitmap->height = Xbitmap->xpm->height;
      Xbitmap->x_hot  = Xbitmap->xpm->x_hotspot;
      Xbitmap->y_hot  = Xbitmap->xpm->y_hotspot;
      XGetGeometry(wxAPP_DISPLAY, Xbitmap->x_pixmap, &wdummy, &sdummy, &sdummy,
                 &udummy, &udummy, &udummy, &(Xbitmap->depth));
      Xbitmap->account = GC_malloc_accounting_shadow(Xbitmap->width * Xbitmap->height * 4);
    } else {
      // read failed: free all memory
      XpmFreeAttributes(Xbitmap->xpm);
      DELETE_OBJ Xbitmap;
      Xbitmap = NULL;
    }
}
#endif
#if USE_IMAGE_LOADING_IN_X
else if ((flags & wxBITMAP_TYPE_ANY) || (flags & wxBITMAP_TYPE_BMP) ||
        (flags & wxBITMAP_TYPE_GIF))
  {
    wxColourMap *map = NULL;
    Bool success = FALSE;

    if (flags & wxBITMAP_DISCARD_COLOURMAP)
      success = wxLoadIntoBitmap(fname, this, NULL, getMask);
    else {
      wxColourMap *cm;
      success = wxLoadIntoBitmap(fname, this, &cm, getMask);
      cmap = cm;
    }

    if (!success && map) {
      DELETE_OBJ map;
      map = NULL;
    }

    if (map)
      cmap = map;
  }
#endif

  return Ok();
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual Bool wxBitmap::Ok ( void  ) [inline, virtual]

Reimplemented in wxCursor.

Definition at line 75 of file Bitmap.h.

{ return (Xbitmap != NULL); }

Here is the caller graph for this function:

void gc::operator delete ( void obj) [inline, inherited]
void gc::operator delete ( void obj) [inline, inherited]

Definition at line 287 of file gc_cpp.h.

                                           {
    GC_FREE( obj );}

Here is the caller graph for this function:

void gc::operator delete ( void ,
void  
) [inline, inherited]

Definition at line 291 of file gc_cpp.h.

{}
void gc::operator delete[] ( void obj) [inline, inherited]

Definition at line 305 of file gc_cpp.h.

                                             {
    gc::operator delete( obj );}

Here is the call graph for this function:

void gc::operator delete[] ( void ,
void  
) [inline, inherited]

Definition at line 309 of file gc_cpp.h.

{}
void* gc::operator new ( size_t  size) [inline, inherited]
void* gc::operator new ( size_t  size,
GCPlacement  gcp 
) [inline, inherited]
void * gc::operator new ( size_t  size) [inline, inherited]

Definition at line 273 of file gc_cpp.h.

                                           {
    return GC_MALLOC( size );}

Here is the caller graph for this function:

void * gc::operator new ( size_t  size,
GCPlacement  gcp 
) [inline, inherited]

Definition at line 276 of file gc_cpp.h.

                                                            {
    if (gcp == UseGC) 
        return GC_MALLOC( size );
    else if (gcp == PointerFreeGC)
       return GC_MALLOC_ATOMIC( size );
    else
        return GC_MALLOC_UNCOLLECTABLE( size );}
void * gc::operator new ( size_t  size,
void p 
) [inline, inherited]

Definition at line 284 of file gc_cpp.h.

                                                    {
    return p;}
void * gc::operator new[] ( size_t  size) [inline, inherited]

Definition at line 296 of file gc_cpp.h.

                                             {
    return gc::operator new( size );}

Here is the call graph for this function:

void * gc::operator new[] ( size_t  size,
GCPlacement  gcp 
) [inline, inherited]

Definition at line 299 of file gc_cpp.h.

                                                              {
    return gc::operator new( size, gcp );}

Here is the call graph for this function:

void * gc::operator new[] ( size_t  size,
void p 
) [inline, inherited]

Definition at line 302 of file gc_cpp.h.

                                                      {
    return p;}

Definition at line 695 of file Bitmap.cc.

{
  if (!selectedIntoDC) {
    if (label_bm) {
      DELETE_OBJ label_bm;
      label_bm = NULL;
    }
    if (button_label_bm) {
      DELETE_OBJ button_label_bm;
      button_label_bm = NULL;
    }
  }
}

Here is the caller graph for this function:

Bool wxBitmap::SaveFile ( char *  name,
int  type,
int  quality = 75,
wxColourMap cmap = NULL 
)

Definition at line 490 of file Bitmap.cc.

{
  if (Xbitmap) {
    if (selectedTo)
      selectedTo->EndSetPixel();
    
    switch (type) {
    case wxBITMAP_TYPE_XBM:
      if (Xbitmap->depth == 1)
       return (XWriteBitmapFile(wxAPP_DISPLAY, fname, Xbitmap->x_pixmap,
                             Xbitmap->width, Xbitmap->height,
                             Xbitmap->x_hot, Xbitmap->y_hot)
              == BitmapSuccess);
      else {
       return write_pixmap_as_bitmap(wxAPP_DISPLAY, Xbitmap->x_pixmap,  fname, 
                                  Xbitmap->width, Xbitmap->height);
      }
      break; // write failed or depth != 1
    case wxBITMAP_TYPE_XPM:
      return (XpmWriteFileFromPixmap(wxAPP_DISPLAY, fname, Xbitmap->x_pixmap,
                                 (Pixmap)NULL, (XpmAttributes*)NULL)
             == XpmSuccess);
      break; // write failed
    case wxBITMAP_TYPE_JPEG:
      return write_JPEG_file(fname, this, quality);
      break; // write failed
    case wxBITMAP_TYPE_PNG:
      return wx_write_png(fname, this);
      break; // write failed
    default:
      break; // no other save methods so far
    }
  }
  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void wxBitmap::SetColourMap ( wxColourMap new_cmap) [inline]

Definition at line 69 of file Bitmap.h.

        { cmap = (new_cmap ? new_cmap : wxAPP_COLOURMAP); }

Definition at line 710 of file Bitmap.cc.

{
  if (_gl_cfg)
    _gl_cfg = _gl_cfg->Clone();
  gl_cfg = _gl_cfg;
}

Here is the call graph for this function:

void wxBitmap::SetMask ( wxBitmap bm) [inline]

Definition at line 81 of file Bitmap.h.

{ loaded_mask = bm; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 146 of file wxGC.h.

WXTYPE wxObject::__type [inherited]

Definition at line 77 of file Object.h.

Definition at line 98 of file Bitmap.h.

Definition at line 95 of file Bitmap.h.

Definition at line 99 of file Bitmap.h.

Definition at line 98 of file Bitmap.h.

Definition at line 96 of file Bitmap.h.

Definition at line 97 of file Bitmap.h.

Definition at line 102 of file Bitmap.h.

Definition at line 103 of file Bitmap.h.

Definition at line 94 of file Bitmap.h.


The documentation for this class was generated from the following files: