File:  [mozdev] / chimera / ColorTest / ImageController.m
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Wed Feb 6 16:48:06 2002 UTC (18 years, 4 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
Adding one more color, for fun.

    1: #import "ImageController.h"
    2: 
    3: @implementation ImageController
    4: 
    5: -(NSBitmapImageRep *)workingImageRep
    6: {
    7:     return workingImageRep;
    8: }
    9: 
   10: -(void)setWorkingImageRep:(NSBitmapImageRep *)newWorkingImageRep
   11: {
   12:     [workingImageRep autorelease];
   13:     workingImageRep = [newWorkingImageRep copy];
   14: }
   15: 
   16: -(NSImage *)workingImage
   17: {
   18:     return workingImage;
   19: }
   20: 
   21: -(void)setWorkingImage:(NSImage *)newWorkingImage
   22: {
   23:     [workingImage autorelease];
   24:     workingImage = [newWorkingImage copy];
   25: }
   26: 
   27: -(void)awakeFromNib
   28: {
   29:     [self loadTestImage:self];
   30: }
   31: 
   32: - (IBAction)loadTestImage:(id)sender
   33: {
   34:     [self setWorkingImage:[NSImage imageNamed:@"testImage"]];
   35:     [self setWorkingImageRep:[NSBitmapImageRep imageRepWithData:[workingImage TIFFRepresentation]]];
   36:     [imageView setImage:workingImage];
   37:     [imageView setNeedsDisplay];
   38:     [statusField setStringValue:@"Test image reset."];
   39: }
   40: 
   41: - (IBAction)colorizeImage:(id)sender
   42: {
   43:     NSImage *colorizedImage = [[NSImage alloc] initWithSize:[workingImageRep size]];
   44:     
   45:     [self setWorkingImage:colorizedImage];
   46: 
   47:     [workingImageRep colorizeByMappingGray:[midPointValueField floatValue]
   48:                                    toColor:[toColorColorWell color]
   49:                               blackMapping:[blackMappingColorWell color]
   50:                               whiteMapping:[whiteMappingColorWell color]];
   51:     
   52:     [workingImage addRepresentation:workingImageRep];
   53:     [colorizedImage release];
   54: }
   55: 
   56: - (IBAction)displayNewImage:(id)sender
   57: {
   58:     [self loadTestImage:self];
   59:     [self colorizeImage:self];
   60:     [imageView setImage:workingImage];
   61:     [imageView setNeedsDisplay];
   62:     [statusField setStringValue:@"Image colorization done. Displaying colorized image."];
   63: }
   64: 
   65: - (IBAction)choosePresetColor:(id)sender
   66: {
   67: 
   68:     // In chimera, replace this with a method that returns
   69:     // an NSColor for a color name string.  The strings will
   70:     // be stored in a text file, and read by the method.  This
   71:     // means that colors can be added by editing 1. the .nib, and
   72:     // 2. the text file.  No code required, and savvy users can do
   73:     // it too.
   74:     
   75:     NSString *selectedColor = [[sender selectedItem] title];
   76: 
   77:     if ( [selectedColor isEqualToString:@"Aqua"] ) {
   78:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.09 / 3.60)
   79:                                                         saturation:0.42
   80:                                                         brightness:0.91
   81:                                                              alpha:1.0]];
   82:     } else if ( [selectedColor isEqualToString:@"Graphite"] ) {
   83:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.13 / 3.60)
   84:                                                         saturation:0.09
   85:                                                         brightness:0.70
   86:                                                              alpha:1.0]];
   87:     } else if ( [selectedColor isEqualToString:@"Apple"] ) {
   88:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.01 / 3.60)
   89:                                                         saturation:0.88
   90:                                                         brightness:0.94
   91:                                                              alpha:1.0]];
   92:     } else if ( [selectedColor isEqualToString:@"Mozilla"] ) {
   93:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.09 / 3.60)
   94:                                                         saturation:0.98
   95:                                                         brightness:1.0
   96:                                                              alpha:1.0]];
   97:     } else if ( [selectedColor isEqualToString:@"Flame"] ) {
   98:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.14 / 3.60)
   99:                                                      saturation:0.90
  100:                                                      brightness:0.98
  101:                                                           alpha:1.0]];
  102:     } else if ( [selectedColor isEqualToString:@"Melon"] ) {
  103:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.24 / 3.60)
  104:                                                         saturation:0.91
  105:                                                         brightness:1.0
  106:                                                              alpha:1.0]];
  107:     } else if ( [selectedColor isEqualToString:@"Marigold"] ) {
  108:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.47 / 3.60)
  109:                                                         saturation:0.91
  110:                                                         brightness:1.0
  111:                                                              alpha:1.0]];
  112:     } else if ( [selectedColor isEqualToString:@"Lemon"] ) {
  113:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.55 / 3.60)
  114:                                                         saturation:0.91
  115:                                                         brightness:1.0
  116:                                                              alpha:1.0]];
  117:     } else if ( [selectedColor isEqualToString:@"Cactus"] ) {
  118:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.78 / 3.60)
  119:                                                         saturation:0.85
  120:                                                         brightness:0.74
  121:                                                              alpha:1.0]];
  122:     } else if ( [selectedColor isEqualToString:@"Clover"] ) {
  123:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(1.12 / 3.600)
  124:                                                         saturation:0.77
  125:                                                         brightness:0.68
  126:                                                              alpha:1.0]];
  127:     } else if ( [selectedColor isEqualToString:@"Pine"] ) {
  128:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(1.38 / 3.60)
  129:                                                         saturation:0.79
  130:                                                         brightness:0.46
  131:                                                              alpha:1.0]];
  132:     } else if ( [selectedColor isEqualToString:@"Ocean"] ) {
  133:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.11 / 3.60)
  134:                                                         saturation:0.81
  135:                                                         brightness:0.51
  136:                                                              alpha:1.0]];
  137:     } else if ( [selectedColor isEqualToString:@"Cerulean"] ) {
  138:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.37 / 3.60)
  139:                                                         saturation:0.79
  140:                                                         brightness:0.89
  141:                                                              alpha:1.0]];
  142:     } else if ( [selectedColor isEqualToString:@"Chimera"] ) {
  143:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.56 / 3.60)
  144:                                                         saturation:0.70
  145:                                                         brightness:0.74
  146:                                                              alpha:1.0]];
  147:     } else if ( [selectedColor isEqualToString:@"Royal Violet"] ) {
  148:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.73 / 3.60)
  149:                                                         saturation:0.86
  150:                                                         brightness:0.69
  151:                                                              alpha:1.0]];
  152:     } else if ( [selectedColor isEqualToString:@"Onyx"] ) {
  153:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:0.0
  154:                                                         saturation:0.0
  155:                                                         brightness:0.15
  156:                                                              alpha:1.0]];
  157:     } else {
  158:         [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.56 / 3.60)
  159:                                                         saturation:0.70
  160:                                                         brightness:0.74
  161:                                                              alpha:1.0]];
  162:     }
  163: 
  164:     [self loadTestImage:self];
  165:     [self displayNewImage:self];
  166: }
  167: 
  168: - (IBAction)addOrRemoveBadge:(id)sender
  169: {
  170:     NSImage *badgeImage;
  171: 
  172:     [self displayNewImage:self];
  173: 
  174:     if ( [[[sender selectedItem] title] isEqualToString:@"Spyglass"] ) {
  175:         badgeImage = [NSImage imageNamed:@"findBadge"];
  176:     } else if ( [[[sender selectedItem] title] isEqualToString:@"Application"] ) {
  177:         badgeImage = [NSImage imageNamed:@"appBadge"];
  178:     } else {
  179:         badgeImage = nil;
  180:     }
  181:     
  182:     [workingImage lockFocus];
  183:     [badgeImage compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver];
  184:     [workingImage unlockFocus];
  185: 
  186:     [imageView setImage:workingImage];
  187:     [imageView setNeedsDisplay];
  188:     [statusField setStringValue:@"Badge composite done. Displaying colorized, badged image."];
  189: }
  190: 
  191: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>