Image caching improvements

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5406 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-12-07 21:30:04 +00:00
parent 17c1c9b3bf
commit 2fe9a3b83d
3 changed files with 81 additions and 23 deletions

View file

@ -1,3 +1,8 @@
Tue Dec 7 21:30:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSColor.m: Implemented ([-isEqual:])
* Source/NSImage.m: Fix so any cache is ok if the image rep is opaque.
1999-12-07 Adam Fedor <fedor@gnu.org>
* Source/NSColorWell.m: Added ([+cellClass]) to set cell class to

View file

@ -809,6 +809,53 @@ static NSMutableDictionary *colorStrings = nil;
*alpha = alpha_component;
}
- (BOOL) isEqual: (id)other
{
if (other == self)
return YES;
if ([other isKindOfClass: [NSColor class]] == NO)
return NO;
else
{
NSColor *col = (NSColor*)other;
if (col->active_component != active_component)
return NO;
if (col->alpha_component != alpha_component)
return NO;
switch (active_component)
{
case GNUSTEP_GUI_RGB_ACTIVE:
if (col->RGB_component.red != RGB_component.red
|| col->RGB_component.green != RGB_component.green
|| col->RGB_component.blue != RGB_component.blue)
return NO;
return YES;
case GNUSTEP_GUI_CMYK_ACTIVE:
if (col->CMYK_component.cyan != CMYK_component.cyan
|| col->CMYK_component.magenta != CMYK_component.magenta
|| col->CMYK_component.yellow != CMYK_component.yellow
|| col->CMYK_component.black != CMYK_component.black)
return NO;
return YES;
case GNUSTEP_GUI_HSB_ACTIVE:
if (col->HSB_component.hue != HSB_component.hue
|| col->HSB_component.saturation != HSB_component.saturation
|| col->HSB_component.brightness != HSB_component.brightness)
return NO;
return YES;
case GNUSTEP_GUI_WHITE_ACTIVE:
if (col->white_component != white_component)
return NO;
return YES;
}
return NO;
}
}
//
// Retrieving Individual Components
//
@ -1052,31 +1099,31 @@ static NSMutableDictionary *colorStrings = nil;
{
switch (active_component)
{
case GNUSTEP_GUI_RGB_ACTIVE:
NSDebugLLog(@"NSColor", @"RGB %f %f %f\n", RGB_component.red,
RGB_component.green, RGB_component.blue);
PSsetrgbcolor(RGB_component.red, RGB_component.green,
RGB_component.blue);
break;
case GNUSTEP_GUI_RGB_ACTIVE:
NSDebugLLog(@"NSColor", @"RGB %f %f %f\n", RGB_component.red,
RGB_component.green, RGB_component.blue);
PSsetrgbcolor(RGB_component.red, RGB_component.green,
RGB_component.blue);
break;
case GNUSTEP_GUI_CMYK_ACTIVE:
NSDebugLLog(@"NSColor", @"CMYK %f %f %f %f\n", CMYK_component.cyan,
CMYK_component.magenta,
CMYK_component.yellow, CMYK_component.black);
PSsetcmykcolor(CMYK_component.cyan, CMYK_component.magenta,
CMYK_component.yellow, CMYK_component.black);
break;
case GNUSTEP_GUI_CMYK_ACTIVE:
NSDebugLLog(@"NSColor", @"CMYK %f %f %f %f\n", CMYK_component.cyan,
CMYK_component.magenta,
CMYK_component.yellow, CMYK_component.black);
PSsetcmykcolor(CMYK_component.cyan, CMYK_component.magenta,
CMYK_component.yellow, CMYK_component.black);
break;
case GNUSTEP_GUI_HSB_ACTIVE:
NSDebugLLog(@"NSColor", @"HSB %f %f %f\n", HSB_component.hue,
HSB_component.saturation, HSB_component.brightness);
PSsethsbcolor(HSB_component.hue, HSB_component.saturation,
HSB_component.brightness);
break;
case GNUSTEP_GUI_HSB_ACTIVE:
NSDebugLLog(@"NSColor", @"HSB %f %f %f\n", HSB_component.hue,
HSB_component.saturation, HSB_component.brightness);
PSsethsbcolor(HSB_component.hue, HSB_component.saturation,
HSB_component.brightness);
break;
case GNUSTEP_GUI_WHITE_ACTIVE:
NSDebugLLog(@"NSColor", @"Gray %f\n", white_component);
PSsetgray(white_component);
case GNUSTEP_GUI_WHITE_ACTIVE:
NSDebugLLog(@"NSColor", @"Gray %f\n", white_component);
PSsetgray(white_component);
}
PSsetalpha(alpha_component);
}

View file

@ -888,6 +888,7 @@ static Class cacheClass = 0;
GSRepData *validCache = nil;
GSRepData *reps[count];
unsigned i;
BOOL opaque = [rep isOpaque];
[_reps getObjects: reps];
@ -896,6 +897,8 @@ static Class cacheClass = 0;
* 'best' image rep. See if we can notice any invalidated
* cache as we go - if we don't find a valid cache, we want to
* re-use an invalidated one rather than createing a new one.
* NB. If the image rep is opaque, then any cached rep is valid
* irrespective of the background color it was drawn with.
*/
for (i = 0; i < count; i++)
{
@ -905,15 +908,18 @@ static Class cacheClass = 0;
{
if (repd->bg == nil)
{
NSDebugLLog(@"NSImage", @"Invalid %@ ... %@ %d", repd->bg, _color, repd->rep);
invalidCache = repd;
}
else if ([repd->bg isEqual: _color] == YES)
else if (opaque == YES || [repd->bg isEqual: _color] == YES)
{
NSDebugLLog(@"NSImage", @"Exact %@ ... %@ %d", repd->bg, _color, repd->rep);
validCache = repd;
break;
}
else
{
NSDebugLLog(@"NSImage", @"Partial %@ ... %@ %d", repd->bg, _color, repd->rep);
partialCache = repd;
}
}