1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00

update CTGradient to 1.8

This commit is contained in:
Mitchell Livingston 2008-05-09 13:50:15 +00:00
parent 92fc96ade1
commit 53309cc96d
2 changed files with 30 additions and 16 deletions

View file

@ -2,10 +2,11 @@
// CTGradient.h
//
// Created by Chad Weider on 2/14/07.
// Copyright (c) 2007 Chad Weider.
// Some rights reserved: <http://creativecommons.org/licenses/by/2.5/>
// Writtin by Chad Weider.
//
// Version: 1.6
// Released into public domain on 4/10/08.
//
// Version: 1.8
#import <Cocoa/Cocoa.h>
@ -52,8 +53,6 @@ typedef enum _CTBlendingMode
- (CTGradient *)gradientWithAlphaComponent:(float)alpha;
- (void)addElement:(CTGradientElement*)newElement;
- (CTGradient *)addColorStop:(NSColor *)color atPosition:(float)position; //positions given relative to [0,1]
- (CTGradient *)removeColorStopAtIndex:(unsigned)index;
- (CTGradient *)removeColorStopAtPosition:(float)position;

View file

@ -2,10 +2,11 @@
// CTGradient.m
//
// Created by Chad Weider on 2/14/07.
// Copyright (c) 2007 Chad Weider.
// Some rights reserved: <http://creativecommons.org/licenses/by/2.5/>
// Writtin by Chad Weider.
//
// Version: 1.6
// Released into public domain on 4/10/08.
//
// Version: 1.8
#import "CTGradient.h"
@ -607,9 +608,9 @@ static void resolveHSV(float *color1, float *color2);
}
return [NSColor colorWithCalibratedRed:components[0]
green:components[1]
blue:components[2]
return [NSColor colorWithCalibratedRed:components[0]/components[3] //undo premultiplication that CG requires
green:components[1]/components[3]
blue:components[2]/components[3]
alpha:components[3]];
}
#pragma mark -
@ -685,7 +686,7 @@ static void resolveHSV(float *color1, float *color2);
//Calls to CoreGraphics
CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState(currentContext);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
#else
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
@ -702,7 +703,7 @@ static void resolveHSV(float *color1, float *color2);
- (void)radialFillRect:(NSRect)rect
{
CGPoint startPoint , endPoint;
CGPoint startPoint, endPoint;
float startRadius, endRadius;
float scalex, scaley, transx, transy;
@ -808,7 +809,7 @@ static void resolveHSV(float *color1, float *color2);
}
- (void)addElement:(CTGradientElement *)newElement
{
{
if(elementList == nil || newElement->position < elementList->position) //inserting at beginning of list
{
CTGradientElement *tmpNext = elementList;
@ -1007,7 +1008,12 @@ void linearEvaluation (void *info, const float *in, float *out)
out[1] = (color2->green - color1->green)*position + color1->green;
out[2] = (color2->blue - color1->blue )*position + color1->blue;
out[3] = (color2->alpha - color1->alpha)*position + color1->alpha;
}
}
//Premultiply the color by the alpha.
out[0] *= out[3];
out[1] *= out[3];
out[2] *= out[3];
}
@ -1096,6 +1102,11 @@ void chromaticEvaluation(void *info, const float *in, float *out)
}
transformHSV_RGB(out);
//Premultiply the color by the alpha.
out[0] *= out[3];
out[1] *= out[3];
out[2] *= out[3];
}
@ -1178,10 +1189,14 @@ void inverseChromaticEvaluation(void *info, const float *in, float *out)
}
transformHSV_RGB(out);
//Premultiply the color by the alpha.
out[0] *= out[3];
out[1] *= out[3];
out[2] *= out[3];
}
void transformRGB_HSV(float *components) //H,S,B -> R,G,B
{
float H, S, V;