Improve implementation of NSImage -bestRepresentationForDevice: for

images with multiple representations and fix a related bug.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33211 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2011-05-31 07:35:57 +00:00
parent cef0eae50a
commit 31ff24d0c6
2 changed files with 26 additions and 4 deletions

View file

@ -1,3 +1,12 @@
2011-05-31 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSImage.m (-bestRepresentationForDevice): Prefer
returning an image representation whose size matches the image
size exactly.
* Source/NSImage.m (-_bestRep:withBpsMatch:): Fix test confusing
bits per sample and bits per pixel.
2011-05-29 20:34-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Source/GNUmakefile: Remove NSManagedObjectContext.[hm] from compile

View file

@ -1518,9 +1518,7 @@ Fallback for backends other than Cairo. */
max_rep = nil;
while ((rep = [enumerator nextObject]) != nil)
{
int rep_bps = 0;
if ([rep respondsToSelector: @selector(bitsPerPixel)])
rep_bps = [(NSBitmapImageRep *)rep bitsPerPixel];
int rep_bps = [rep bitsPerSample];
if (rep_bps > max_bps)
{
max_bps = rep_bps;
@ -1608,7 +1606,22 @@ Fallback for backends other than Cairo. */
reps = [self _bestRep: reps withColorMatch: deviceDescription];
}
reps = [self _bestRep: reps withBpsMatch: deviceDescription];
/* Pick an arbitrary representation if there is more than one */
/* If we have more than one match check for a representation whose size
* matches the image size exactly. Otherwise, arbitrarily choose the last
* representation. */
if ([reps count] > 1)
{
NSImageRep *rep;
NSEnumerator *enumerator = [reps objectEnumerator];
while ((rep = [enumerator nextObject]) != nil)
{
if (NSEqualSizes(_size, [rep size]) == YES)
{
return rep;
}
}
}
return [reps lastObject];
}