home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Graphics / ToyViewer-2.6a / src / ImageOpr.bproj / MonotoneView.m < prev    next >
Encoding:
Text File  |  1996-02-04  |  1.2 KB  |  75 lines

  1. #import  "MonotoneView.h"
  2. #import  <dpsclient/wraps.h>
  3. #import  <appkit/NXImage.h>
  4. #import  "../common.h"
  5. #import  "imageOperation.h"
  6.  
  7. @implementation MonotoneView
  8.  
  9. /* Overload */
  10. - initFrame:(const NXRect *)frameRect
  11. {
  12.     [super initFrame:frameRect];
  13.     cache = [[NXImage alloc] initSize: &frameRect->size];
  14.     tone = NULL;
  15.     [self drawCache];
  16.     return self;
  17. }
  18.  
  19. /* Overload */
  20. - free
  21. {
  22.     [super free];
  23.     if (cache) [cache free];
  24.     return nil;
  25. }
  26.  
  27. /* Overload */
  28. - drawSelf:(NXRect *)r :(int) count
  29. {
  30.     [cache composite:NX_COPY fromRect:r toPoint:&(r->origin)];
  31.     return self;
  32. }
  33.  
  34. - drawCache
  35. {
  36.     int    i;
  37.     float    half, wid, thick, y;
  38.  
  39.     [cache lockFocus];
  40.     half = (wid = frame.size.width) / 2.0;
  41.     thick = frame.size.height / 256.0;
  42.     PSsetlinewidth(thick);
  43.     if (tone)
  44.         for (i = 0; i < 256; i++) {
  45.             y = thick * i;
  46.             PSsetgray(i/255.0);
  47.             PSmoveto(0.0, y);
  48.             PSlineto(half, y);
  49.             PSstroke();
  50.             PSsetgray(tone[i]/255.0);
  51.             PSmoveto(half, y);
  52.             PSlineto(wid, y);
  53.             PSstroke();
  54.         }
  55.     else
  56.         for (i = 0; i < 256; i++) {
  57.             y = thick * i;
  58.             PSsetgray(i/255.0);
  59.             PSmoveto(0.0, y);
  60.             PSlineto(wid, y);
  61.             PSstroke();
  62.         }
  63.     [cache unlockFocus];
  64.     return self;
  65. }
  66.  
  67. - setTone:(unsigned char *)buffer
  68. {
  69.     tone = buffer;
  70.     [self drawCache];
  71.     return self;
  72. }
  73.  
  74. @end
  75.