Author: fredkiefer
Date: Wed Oct 14 00:04:35 2015
New Revision: 39062
URL: http://svn.gna.org/viewcvs/gnustep?rev=39062&view=rev
Log:
2015-10-13 Fred Kiefer <[email protected]>
* Source/NSBitmapImageRep.m: Correct bug in fast path for image
premultiply/unpremultiply.
Modified:
libs/gui/trunk/ChangeLog
libs/gui/trunk/Source/NSBitmapImageRep.m
Modified: libs/gui/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=39062&r1=39061&r2=39062&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog (original)
+++ libs/gui/trunk/ChangeLog Wed Oct 14 00:04:35 2015
@@ -1,3 +1,8 @@
+2015-10-13 Fred Kiefer <[email protected]>
+
+ * Source/NSBitmapImageRep.m: Correct bug in fast path for image
+ premultiply/unpremultiply.
+
2015-10-10 Gregory Casamento <[email protected]>
* Headers/AppKit/NSAnimationContext.h
Modified: libs/gui/trunk/Source/NSBitmapImageRep.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSBitmapImageRep.m?rev=39062&r1=39061&r2=39062&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSBitmapImageRep.m (original)
+++ libs/gui/trunk/Source/NSBitmapImageRep.m Wed Oct 14 00:04:35 2015
@@ -2088,127 +2088,10 @@
for (y = 0; y < _pixelsHigh; y++)
{
- line_offset = _bytesPerRow * y + _bitsPerPixel / 8;
+ line_offset = _bytesPerRow * y;
for (x = 0; x < _pixelsWide; x++)
{
- offset = x + line_offset;
- a = _imagePlanes[0][offset + ai];
- if ((a != 0) && (a != 255))
- {
- for (i = start; i < end; i++)
- {
- NSUInteger v = _imagePlanes[0][offset + i];
- NSUInteger c;
-
- c = (v * 255) / a;
- if (c >= 255)
- {
- v = 255;
- }
- else
- {
- v = c;
- }
-
- _imagePlanes[0][offset + i] = v;
- }
- }
- }
- }
- }
- else
- {
- NSUInteger a;
-
- for (y = 0; y < _pixelsHigh; y++)
- {
- for (x = 0; x < _pixelsWide; x++)
- {
- //[self getPixel: pixelData atX: x y: y];
- getP(self, getPSel, pixelData, x, y);
- a = pixelData[ai];
- if (a != 255)
- {
- for (i = start; i < end; i++)
- {
- NSUInteger t = a * pixelData[i] + 0x80;
-
- pixelData[i] = ((t >> 8) + t) >> 8;
- }
- //[self setPixel: pixelData atX: x y: y];
- setP(self, setPSel, pixelData, x, y);
- }
- }
- }
- }
- }
- else
- {
- CGFloat scale;
- CGFloat alpha;
-
- scale = (CGFloat)((1 << _bitsPerSample) - 1);
- for (y = 0; y < _pixelsHigh; y++)
- {
- for (x = 0; x < _pixelsWide; x++)
- {
- //[self getPixel: pixelData atX: x y: y];
- getP(self, getPSel, pixelData, x, y);
- alpha = pixelData[ai] / scale;
- for (i = start; i < end; i++)
- {
- pixelData[i] *= alpha;
- }
- //[self setPixel: pixelData atX: x y: y];
- setP(self, setPSel, pixelData, x, y);
- }
- }
- }
-
- _format &= ~NSAlphaNonpremultipliedBitmapFormat;
-}
-
-- (void) _unpremultiply
-{
- NSInteger x, y;
- NSUInteger pixelData[5];
- NSInteger start, end, i, ai;
- SEL getPSel = @selector(getPixel:atX:y:);
- SEL setPSel = @selector(setPixel:atX:y:);
- IMP getP = [self methodForSelector: getPSel];
- IMP setP = [self methodForSelector: setPSel];
-
- if (!_hasAlpha || (_format & NSAlphaNonpremultipliedBitmapFormat))
- return;
-
- if (_format & NSAlphaFirstBitmapFormat)
- {
- ai = 0;
- start = 1;
- end = _numColors;
- }
- else
- {
- ai = _numColors - 1;
- start = 0;
- end = _numColors - 1;
- }
-
- if (_bitsPerSample == 8)
- {
- if (!_isPlanar)
- {
- // Optimize for the most common case
- NSUInteger a;
- NSInteger offset;
- NSInteger line_offset;
-
- for (y = 0; y < _pixelsHigh; y++)
- {
- line_offset = _bytesPerRow * y + _bitsPerPixel / 8;
- for (x = 0; x < _pixelsWide; x++)
- {
- offset = x + line_offset;
+ offset = (_bitsPerPixel * x) / 8 + line_offset;
a = _imagePlanes[0][offset + ai];
if (a != 255)
{
@@ -2229,6 +2112,123 @@
v = ((t >> 8) + t) >> 8;
_imagePlanes[0][offset + i] = v;
}
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ NSUInteger a;
+
+ for (y = 0; y < _pixelsHigh; y++)
+ {
+ for (x = 0; x < _pixelsWide; x++)
+ {
+ //[self getPixel: pixelData atX: x y: y];
+ getP(self, getPSel, pixelData, x, y);
+ a = pixelData[ai];
+ if (a != 255)
+ {
+ for (i = start; i < end; i++)
+ {
+ NSUInteger t = a * pixelData[i] + 0x80;
+
+ pixelData[i] = ((t >> 8) + t) >> 8;
+ }
+ //[self setPixel: pixelData atX: x y: y];
+ setP(self, setPSel, pixelData, x, y);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ CGFloat scale;
+ CGFloat alpha;
+
+ scale = (CGFloat)((1 << _bitsPerSample) - 1);
+ for (y = 0; y < _pixelsHigh; y++)
+ {
+ for (x = 0; x < _pixelsWide; x++)
+ {
+ //[self getPixel: pixelData atX: x y: y];
+ getP(self, getPSel, pixelData, x, y);
+ alpha = pixelData[ai] / scale;
+ for (i = start; i < end; i++)
+ {
+ pixelData[i] *= alpha;
+ }
+ //[self setPixel: pixelData atX: x y: y];
+ setP(self, setPSel, pixelData, x, y);
+ }
+ }
+ }
+
+ _format &= ~NSAlphaNonpremultipliedBitmapFormat;
+}
+
+- (void) _unpremultiply
+{
+ NSInteger x, y;
+ NSUInteger pixelData[5];
+ NSInteger start, end, i, ai;
+ SEL getPSel = @selector(getPixel:atX:y:);
+ SEL setPSel = @selector(setPixel:atX:y:);
+ IMP getP = [self methodForSelector: getPSel];
+ IMP setP = [self methodForSelector: setPSel];
+
+ if (!_hasAlpha || (_format & NSAlphaNonpremultipliedBitmapFormat))
+ return;
+
+ if (_format & NSAlphaFirstBitmapFormat)
+ {
+ ai = 0;
+ start = 1;
+ end = _numColors;
+ }
+ else
+ {
+ ai = _numColors - 1;
+ start = 0;
+ end = _numColors - 1;
+ }
+
+ if (_bitsPerSample == 8)
+ {
+ if (!_isPlanar)
+ {
+ // Optimize for the most common case
+ NSUInteger a;
+ NSInteger offset;
+ NSInteger line_offset;
+
+ for (y = 0; y < _pixelsHigh; y++)
+ {
+ line_offset = _bytesPerRow * y;
+ for (x = 0; x < _pixelsWide; x++)
+ {
+ offset = (_bitsPerPixel * x) / 8 + line_offset;
+ a = _imagePlanes[0][offset + ai];
+ if ((a != 0) && (a != 255))
+ {
+ for (i = start; i < end; i++)
+ {
+ NSUInteger v = _imagePlanes[0][offset + i];
+ NSUInteger c;
+
+ c = (v * 255) / a;
+ if (c >= 255)
+ {
+ v = 255;
+ }
+ else
+ {
+ v = c;
+ }
+
+ _imagePlanes[0][offset + i] = v;
}
}
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs