home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / Venus / display.cc next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  1.6 KB  |  62 lines  |  [TEXT/KAHL]

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *
  5.  *                               Grayscale Image
  6.  *                     Display an image on Macintosh
  7.  *
  8.  * The program converts an image to a pixmap in an offscreen Grafport
  9.  * and has it displayed in a window
  10.  *
  11.  *
  12.  ***********************************************************************
  13.  */
  14.  
  15. #include "image.h"
  16. #include "window.h"
  17.  
  18. /*
  19.  *----------------------------------------------------------------------
  20.  *                An instance of a generic screen window to display
  21.  *                                     an image
  22.  */
  23.  
  24. class MapWindow : public OffScreenWindow
  25. {
  26. public:
  27.     MapWindow(const IMAGE& image, const char * title);
  28.     ~MapWindow(void)  {}
  29. };
  30.  
  31.  
  32.                                 // Creating a window that would have our picture
  33.                                 // displayed. This function also creates an
  34.                                 // offscreen grafworld and draws the picture in it
  35. MapWindow::MapWindow(const IMAGE& image, const char * title)
  36.     : OffScreenWindow((ScreenRect)image,title,256)
  37. {
  38.     PixMapHandle pixmap = get_pixmap();
  39.     assert( LockPixels(pixmap) );
  40.  
  41.     char * pixp = GetPixBaseAddr(pixmap);
  42.     register int i;                                // "Draw" the image
  43.     for(i=0; i<height(); i++, pixp += bytes_per_row())
  44.     {                                            // Note, bytes_per_row is generally GREATER
  45.       register int j;                            // than width, and is always a multiple of 4
  46.       for(j=0; j<width(); j++)
  47.            pixp[j] = image(i,j);
  48.     }
  49.  
  50.     UnlockPixels(pixmap);
  51. }
  52.  
  53.  
  54. /*
  55.  *----------------------------------------------------------------------
  56.  *                        Routing display function
  57.  */
  58. void display_map(const IMAGE& image, const char * title)
  59. {
  60.     MapWindow image_window(image,title);
  61.     image_window.handle();
  62. }