1// 2// PRCumHisto.m 3// PRICE 4// 5// Created by Riccardo Mottola on Thu Dec 18 2003. 6// Copyright (c) 2003-2014 Carduus. All rights reserved. 7// 8// This application is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 9// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 11#import "PRCumHisto.h" 12 13 14@implementation PRCumHisto 15 16- (void)displayHistogram :(NSRect)viewRect 17{ 18 NSRect bar; 19 NSBezierPath *bez; 20 NSBezierPath *redBez, *greenBez, *blueBez; 21 NSColor *fillRed, *fillGreen, *fillBlue; 22 int i; 23 float barWidth; 24 float barHeightScale; 25 26 NSLog(@"Cumulative Histogram drawing"); 27 NSLog(@"maxHisto: %f", maxHisto); 28 29 barWidth = viewRect.size.width / UCHAR_MAX; 30 barHeightScale = viewRect.size.height; 31 NSLog(@"frame height: %f", viewRect.size.height); 32 NSLog(@"scale: %f", barHeightScale); 33 bez = [NSBezierPath bezierPath]; 34 redBez = [NSBezierPath bezierPath]; 35 greenBez = [NSBezierPath bezierPath]; 36 blueBez = [NSBezierPath bezierPath]; 37 38 if (hasColor) 39 { 40 fillRed = [NSColor redColor]; 41 fillGreen = [NSColor greenColor]; 42 fillBlue = [NSColor blueColor]; 43 for(i = 0; i < UCHAR_MAX; i++) 44 { 45 float redHeight; 46 float greenHeight; 47 float blueHeight; 48 49 redHeight = cumulativeHistogramR[i]*barHeightScale/3; 50 greenHeight = cumulativeHistogramG[i]*barHeightScale/3; 51 blueHeight = cumulativeHistogramB[i]*barHeightScale/3; 52 bar = NSMakeRect(i*barWidth, 0, barWidth, greenHeight); 53 [greenBez appendBezierPathWithRect:bar]; 54 bar = NSMakeRect(i*barWidth, greenHeight, barWidth, redHeight); 55 [redBez appendBezierPathWithRect:bar]; 56 bar = NSMakeRect(i*barWidth, greenHeight + redHeight, barWidth, blueHeight); 57 [blueBez appendBezierPathWithRect:bar]; 58 } 59 [fillRed set]; 60 [redBez fill]; 61 [fillGreen set]; 62 [greenBez fill]; 63 [fillBlue set]; 64 [blueBez fill]; 65 } else /* greyscale */ 66 { 67 for(i = 0; i < UCHAR_MAX; i++) 68 { 69 bar = NSMakeRect(i*barWidth, 0, barWidth, cumulativeHistogram[i]*barHeightScale); 70 [bez appendBezierPathWithRect:bar]; 71 } 72 [bez fill]; 73 } 74} 75 76 77@end 78