home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Graphics / ToyViewer-2.6a / src / ToyWinBMP.m < prev    next >
Encoding:
Text File  |  1996-03-17  |  1.1 KB  |  47 lines

  1. #import "ToyWinBMP.h"
  2. #import "bmp.h"
  3.  
  4. @implementation ToyWinBMP
  5.  
  6. - (commonInfo *)drawToyWin:(const char *)fileName type:(int)type
  7.     map:(unsigned char **)map err:(int *)err
  8. {
  9.     FILE *fp;
  10.     bmpHeader *bh = NULL;
  11.     commonInfo *cinf = NULL;
  12.     int bits = 8, alert;
  13.  
  14.     *err = 0;
  15.     if ((fp = fopen(fileName, "r")) == NULL) {
  16.         *err = Err_OPEN;
  17.         return NULL;
  18.     }
  19.     if ((bh = loadBmpHeader(fp, err)) == NULL) {
  20.         (void)fclose(fp);
  21.         return NULL;
  22.     }
  23.  
  24.     if (!makeMapOnly)
  25.         [self initLocateWindow:fileName width:bh->x height:bh->y];
  26.  
  27. /* Bitmap data of planes in 'map[]' is one block of memory area.
  28.    map[0] is beginning of the area, and map[1] = map[0] + (size of plane),
  29.    and so on. But, if the image is monochrome, map[1] is NULL.
  30.    The area of map[0] and (commonInfo *)cinf are kept in an object of
  31.    ToyView, and freed by it.
  32. */
  33.     alert = bmpGetImage(fp, bh, &bits, map);
  34.     cinf = bmpInfo(bh, bits, (map[1] == NULL));
  35.     freeBmpHeader(bh);
  36.     (void)fclose(fp);
  37.     if (alert) /* Alert Only */
  38.         warnAlert(fileName, alert);
  39.     if (makeMapOnly)
  40.         return cinf;
  41.     if ([self drawView:map info: cinf] == nil)
  42.         *err = -1;
  43.     return cinf;
  44. }
  45.  
  46. @end
  47.