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 (15 years, 10 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
Adding one more color, for fun.

#import "ImageController.h"

@implementation ImageController

-(NSBitmapImageRep *)workingImageRep
{
    return workingImageRep;
}

-(void)setWorkingImageRep:(NSBitmapImageRep *)newWorkingImageRep
{
    [workingImageRep autorelease];
    workingImageRep = [newWorkingImageRep copy];
}

-(NSImage *)workingImage
{
    return workingImage;
}

-(void)setWorkingImage:(NSImage *)newWorkingImage
{
    [workingImage autorelease];
    workingImage = [newWorkingImage copy];
}

-(void)awakeFromNib
{
    [self loadTestImage:self];
}

- (IBAction)loadTestImage:(id)sender
{
    [self setWorkingImage:[NSImage imageNamed:@"testImage"]];
    [self setWorkingImageRep:[NSBitmapImageRep imageRepWithData:[workingImage TIFFRepresentation]]];
    [imageView setImage:workingImage];
    [imageView setNeedsDisplay];
    [statusField setStringValue:@"Test image reset."];
}

- (IBAction)colorizeImage:(id)sender
{
    NSImage *colorizedImage = [[NSImage alloc] initWithSize:[workingImageRep size]];
    
    [self setWorkingImage:colorizedImage];

    [workingImageRep colorizeByMappingGray:[midPointValueField floatValue]
                                   toColor:[toColorColorWell color]
                              blackMapping:[blackMappingColorWell color]
                              whiteMapping:[whiteMappingColorWell color]];
    
    [workingImage addRepresentation:workingImageRep];
    [colorizedImage release];
}

- (IBAction)displayNewImage:(id)sender
{
    [self loadTestImage:self];
    [self colorizeImage:self];
    [imageView setImage:workingImage];
    [imageView setNeedsDisplay];
    [statusField setStringValue:@"Image colorization done. Displaying colorized image."];
}

- (IBAction)choosePresetColor:(id)sender
{

    // In chimera, replace this with a method that returns
    // an NSColor for a color name string.  The strings will
    // be stored in a text file, and read by the method.  This
    // means that colors can be added by editing 1. the .nib, and
    // 2. the text file.  No code required, and savvy users can do
    // it too.
    
    NSString *selectedColor = [[sender selectedItem] title];

    if ( [selectedColor isEqualToString:@"Aqua"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.09 / 3.60)
                                                        saturation:0.42
                                                        brightness:0.91
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Graphite"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.13 / 3.60)
                                                        saturation:0.09
                                                        brightness:0.70
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Apple"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.01 / 3.60)
                                                        saturation:0.88
                                                        brightness:0.94
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Mozilla"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.09 / 3.60)
                                                        saturation:0.98
                                                        brightness:1.0
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Flame"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.14 / 3.60)
                                                     saturation:0.90
                                                     brightness:0.98
                                                          alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Melon"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.24 / 3.60)
                                                        saturation:0.91
                                                        brightness:1.0
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Marigold"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.47 / 3.60)
                                                        saturation:0.91
                                                        brightness:1.0
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Lemon"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.55 / 3.60)
                                                        saturation:0.91
                                                        brightness:1.0
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Cactus"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(0.78 / 3.60)
                                                        saturation:0.85
                                                        brightness:0.74
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Clover"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(1.12 / 3.600)
                                                        saturation:0.77
                                                        brightness:0.68
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Pine"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(1.38 / 3.60)
                                                        saturation:0.79
                                                        brightness:0.46
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Ocean"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.11 / 3.60)
                                                        saturation:0.81
                                                        brightness:0.51
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Cerulean"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.37 / 3.60)
                                                        saturation:0.79
                                                        brightness:0.89
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Chimera"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.56 / 3.60)
                                                        saturation:0.70
                                                        brightness:0.74
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Royal Violet"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.73 / 3.60)
                                                        saturation:0.86
                                                        brightness:0.69
                                                             alpha:1.0]];
    } else if ( [selectedColor isEqualToString:@"Onyx"] ) {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:0.0
                                                        saturation:0.0
                                                        brightness:0.15
                                                             alpha:1.0]];
    } else {
        [toColorColorWell setColor:[NSColor colorWithCalibratedHue:(2.56 / 3.60)
                                                        saturation:0.70
                                                        brightness:0.74
                                                             alpha:1.0]];
    }

    [self loadTestImage:self];
    [self displayNewImage:self];
}

- (IBAction)addOrRemoveBadge:(id)sender
{
    NSImage *badgeImage;

    [self displayNewImage:self];

    if ( [[[sender selectedItem] title] isEqualToString:@"Spyglass"] ) {
        badgeImage = [NSImage imageNamed:@"findBadge"];
    } else if ( [[[sender selectedItem] title] isEqualToString:@"Application"] ) {
        badgeImage = [NSImage imageNamed:@"appBadge"];
    } else {
        badgeImage = nil;
    }
    
    [workingImage lockFocus];
    [badgeImage compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver];
    [workingImage unlockFocus];

    [imageView setImage:workingImage];
    [imageView setNeedsDisplay];
    [statusField setStringValue:@"Badge composite done. Displaying colorized, badged image."];
}

@end

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