summaryrefslogtreecommitdiffstats
path: root/third_party/icon_family
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-23 00:48:43 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-23 00:48:43 +0000
commit04340ffdfe0b4515e996826b3e9ab3d04adc91a0 (patch)
tree0dff1e07b4a94ec1f54a0dda23236f5f8158a46c /third_party/icon_family
parentecb35af130195713f5ea44d9d58ac71da7b2a0a3 (diff)
downloadchromium_src-04340ffdfe0b4515e996826b3e9ab3d04adc91a0.zip
chromium_src-04340ffdfe0b4515e996826b3e9ab3d04adc91a0.tar.gz
chromium_src-04340ffdfe0b4515e996826b3e9ab3d04adc91a0.tar.bz2
Extend image format support in third_party/icon_family
This CL adds support for alpha first and non-premultiplied image formats. BUG=112651 TEST= Review URL: http://codereview.chromium.org/9433057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123155 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/icon_family')
-rw-r--r--third_party/icon_family/IconFamily.m106
-rw-r--r--third_party/icon_family/README.chromium1
-rw-r--r--third_party/icon_family/chromium_icon_family_2.patch189
3 files changed, 263 insertions, 33 deletions
diff --git a/third_party/icon_family/IconFamily.m b/third_party/icon_family/IconFamily.m
index 439c2de..911ea31 100644
--- a/third_party/icon_family/IconFamily.m
+++ b/third_party/icon_family/IconFamily.m
@@ -1236,6 +1236,43 @@ enum {
return [newImage autorelease];
}
+void GetRGBAFrom32BitSource(unsigned char src1, unsigned char src2, unsigned char src3, unsigned char src4,
+ unsigned char* redOut, unsigned char* greenOut, unsigned char* blueOut, unsigned char* alphaOut,
+ bool isAlphaFirst, bool isAlphaPremultiplied) {
+ unsigned char r, g, b, a;
+ if (isAlphaFirst) {
+ a = src1;
+ r = src2;
+ g = src3;
+ b = src4;
+ } else {
+ r = src1;
+ g = src2;
+ b = src3;
+ a = src4;
+ }
+
+ if (isAlphaPremultiplied) {
+ // The RGB values are premultiplied by the alpha (so that
+ // Quartz can save time when compositing the bitmap to a
+ // destination), and we undo this premultiplication (with some
+ // lossiness unfortunately) when retrieving the bitmap data.
+ float oneOverAlpha = 255.0f / (float)a;
+ r = r * oneOverAlpha;
+ g = g * oneOverAlpha;
+ b = b * oneOverAlpha;
+ }
+
+ if (redOut)
+ *redOut = r;
+ if (greenOut)
+ *greenOut = g;
+ if (blueOut)
+ *blueOut = b;
+ if (alphaOut)
+ *alphaOut = a;
+}
+
+ (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize
{
Handle hRawData;
@@ -1244,9 +1281,7 @@ enum {
unsigned char* pSrc;
unsigned char* pDest;
int x, y;
- unsigned char alphaByte;
- float oneOverAlpha;
-
+
// Get information about the bitmapImageRep.
long pixelsWide = [bitmapImageRep pixelsWide];
long pixelsHigh = [bitmapImageRep pixelsHigh];
@@ -1256,6 +1291,8 @@ enum {
BOOL isPlanar = [bitmapImageRep isPlanar];
long bytesPerRow = [bitmapImageRep bytesPerRow];
unsigned char* bitmapData = [bitmapImageRep bitmapData];
+ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
+ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
// Make sure bitmap has the required dimensions.
if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
@@ -1289,23 +1326,14 @@ enum {
for (y = 0; y < pixelsHigh; y++) {
pSrc = bitmapData + y * bytesPerRow;
for (x = 0; x < pixelsWide; x++) {
- // Each pixel is 3 bytes of RGB data, followed by 1 byte of
- // alpha. The RGB values are premultiplied by the alpha (so
- // that Quartz can save time when compositing the bitmap to a
- // destination), and we undo this premultiplication (with some
- // lossiness unfortunately) when retrieving the bitmap data.
- *pDest++ = alphaByte = *(pSrc+3);
- if (alphaByte) {
- oneOverAlpha = 255.0f / (float)alphaByte;
- *pDest++ = *(pSrc+0) * oneOverAlpha;
- *pDest++ = *(pSrc+1) * oneOverAlpha;
- *pDest++ = *(pSrc+2) * oneOverAlpha;
- } else {
- *pDest++ = 0;
- *pDest++ = 0;
- *pDest++ = 0;
- }
- pSrc+=4;
+ unsigned char r, g, b, a;
+ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
+ &r, &g, &b, &a, isAlphaFirst, isAlphaPremultiplied);
+ *pDest++ = a;
+ *pDest++ = r;
+ *pDest++ = g;
+ *pDest++ = b;
+ pSrc += 4;
}
}
} else if (bitsPerPixel == 24) {
@@ -1347,6 +1375,8 @@ enum {
BOOL isPlanar = [bitmapImageRep isPlanar];
long bytesPerRow = [bitmapImageRep bytesPerRow];
unsigned char* bitmapData = [bitmapImageRep bitmapData];
+ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
+ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
// Make sure bitmap has the required dimensions.
if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
@@ -1383,9 +1413,12 @@ enum {
for (y = 0; y < pixelsHigh; y++) {
pSrc = bitmapData + y * bytesPerRow;
for (x = 0; x < pixelsWide; x++) {
- cgCol.red = ((float)*(pSrc)) / 255;
- cgCol.green = ((float)*(pSrc+1)) / 255;
- cgCol.blue = ((float)*(pSrc+2)) / 255;
+ unsigned char r, g, b;
+ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
+ &r, &g, &b, NULL, isAlphaFirst, isAlphaPremultiplied);
+ cgCol.red = (float)r / 255;
+ cgCol.green = (float)g / 255;
+ cgCol.blue = (float)b / 255;
*pDest++ = CGPaletteGetIndexForColor(cgPal, cgCol);
@@ -1436,6 +1469,8 @@ enum {
BOOL isPlanar = [bitmapImageRep isPlanar];
long bytesPerRow = [bitmapImageRep bytesPerRow];
unsigned char* bitmapData = [bitmapImageRep bitmapData];
+ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
+ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
// Make sure bitmap has the required dimensions.
if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
@@ -1469,8 +1504,11 @@ enum {
for (y = 0; y < pixelsHigh; y++) {
pSrc = bitmapData + y * bytesPerRow;
for (x = 0; x < pixelsWide; x++) {
- pSrc += 3;
- *pDest++ = *pSrc++;
+ unsigned char a;
+ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
+ NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
+ *pDest++ = a;
+ pSrc += 4;
}
}
}
@@ -1514,6 +1552,8 @@ enum {
BOOL isPlanar = [bitmapImageRep isPlanar];
long bytesPerRow = [bitmapImageRep bytesPerRow];
unsigned char* bitmapData = [bitmapImageRep bitmapData];
+ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
+ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
// Make sure bitmap has the required dimensions.
if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
@@ -1544,14 +1584,14 @@ enum {
pSrc = bitmapData + y * bytesPerRow;
for (x = 0; x < pixelsWide; x += 8) {
maskByte = 0;
- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x80 : 0; pSrc += 4;
- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x40 : 0; pSrc += 4;
- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x20 : 0; pSrc += 4;
- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x10 : 0; pSrc += 4;
- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x08 : 0; pSrc += 4;
- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x04 : 0; pSrc += 4;
- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x02 : 0; pSrc += 4;
- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x01 : 0; pSrc += 4;
+ for (int i = 7; i >= 0; i--) {
+ unsigned char a;
+ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
+ NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
+ if (a)
+ maskByte |= 1 << i;
+ pSrc += 4;
+ }
*pDest++ = maskByte;
}
}
diff --git a/third_party/icon_family/README.chromium b/third_party/icon_family/README.chromium
index 915d197..fe3473f 100644
--- a/third_party/icon_family/README.chromium
+++ b/third_party/icon_family/README.chromium
@@ -12,3 +12,4 @@ This is an Objective-C wrapper around Mac OS X Icon Services' "IconFamily" data
Local Modifications:
chromium_icon_family.patch: Fix minor erors and warnings. Put code that the custom icon code behind a DISABLE_CUSTOM_ICON flag.
+chromium_icon_family_2.patch: Add support for alpha first and non-premultiplied image formats. Patch submitted to project page: https://sourceforge.net/tracker/?func=detail&aid=3491306&group_id=164783&atid=833111
diff --git a/third_party/icon_family/chromium_icon_family_2.patch b/third_party/icon_family/chromium_icon_family_2.patch
new file mode 100644
index 0000000..65e7096d
--- /dev/null
+++ b/third_party/icon_family/chromium_icon_family_2.patch
@@ -0,0 +1,189 @@
+diff --git a/third_party/icon_family/IconFamily.m b/third_party/icon_family/IconFamily.m
+index 439c2de..911ea31 100644
+--- a/third_party/icon_family/IconFamily.m
++++ b/third_party/icon_family/IconFamily.m
+@@ -1236,6 +1236,43 @@ enum {
+ return [newImage autorelease];
+ }
+
++void GetRGBAFrom32BitSource(unsigned char src1, unsigned char src2, unsigned char src3, unsigned char src4,
++ unsigned char* redOut, unsigned char* greenOut, unsigned char* blueOut, unsigned char* alphaOut,
++ bool isAlphaFirst, bool isAlphaPremultiplied) {
++ unsigned char r, g, b, a;
++ if (isAlphaFirst) {
++ a = src1;
++ r = src2;
++ g = src3;
++ b = src4;
++ } else {
++ r = src1;
++ g = src2;
++ b = src3;
++ a = src4;
++ }
++
++ if (isAlphaPremultiplied) {
++ // The RGB values are premultiplied by the alpha (so that
++ // Quartz can save time when compositing the bitmap to a
++ // destination), and we undo this premultiplication (with some
++ // lossiness unfortunately) when retrieving the bitmap data.
++ float oneOverAlpha = 255.0f / (float)a;
++ r = r * oneOverAlpha;
++ g = g * oneOverAlpha;
++ b = b * oneOverAlpha;
++ }
++
++ if (redOut)
++ *redOut = r;
++ if (greenOut)
++ *greenOut = g;
++ if (blueOut)
++ *blueOut = b;
++ if (alphaOut)
++ *alphaOut = a;
++}
++
+ + (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize
+ {
+ Handle hRawData;
+@@ -1244,9 +1281,7 @@ enum {
+ unsigned char* pSrc;
+ unsigned char* pDest;
+ int x, y;
+- unsigned char alphaByte;
+- float oneOverAlpha;
+-
++
+ // Get information about the bitmapImageRep.
+ long pixelsWide = [bitmapImageRep pixelsWide];
+ long pixelsHigh = [bitmapImageRep pixelsHigh];
+@@ -1256,6 +1291,8 @@ enum {
+ BOOL isPlanar = [bitmapImageRep isPlanar];
+ long bytesPerRow = [bitmapImageRep bytesPerRow];
+ unsigned char* bitmapData = [bitmapImageRep bitmapData];
++ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
++ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
+
+ // Make sure bitmap has the required dimensions.
+ if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
+@@ -1289,23 +1326,14 @@ enum {
+ for (y = 0; y < pixelsHigh; y++) {
+ pSrc = bitmapData + y * bytesPerRow;
+ for (x = 0; x < pixelsWide; x++) {
+- // Each pixel is 3 bytes of RGB data, followed by 1 byte of
+- // alpha. The RGB values are premultiplied by the alpha (so
+- // that Quartz can save time when compositing the bitmap to a
+- // destination), and we undo this premultiplication (with some
+- // lossiness unfortunately) when retrieving the bitmap data.
+- *pDest++ = alphaByte = *(pSrc+3);
+- if (alphaByte) {
+- oneOverAlpha = 255.0f / (float)alphaByte;
+- *pDest++ = *(pSrc+0) * oneOverAlpha;
+- *pDest++ = *(pSrc+1) * oneOverAlpha;
+- *pDest++ = *(pSrc+2) * oneOverAlpha;
+- } else {
+- *pDest++ = 0;
+- *pDest++ = 0;
+- *pDest++ = 0;
+- }
+- pSrc+=4;
++ unsigned char r, g, b, a;
++ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
++ &r, &g, &b, &a, isAlphaFirst, isAlphaPremultiplied);
++ *pDest++ = a;
++ *pDest++ = r;
++ *pDest++ = g;
++ *pDest++ = b;
++ pSrc += 4;
+ }
+ }
+ } else if (bitsPerPixel == 24) {
+@@ -1347,6 +1375,8 @@ enum {
+ BOOL isPlanar = [bitmapImageRep isPlanar];
+ long bytesPerRow = [bitmapImageRep bytesPerRow];
+ unsigned char* bitmapData = [bitmapImageRep bitmapData];
++ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
++ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
+
+ // Make sure bitmap has the required dimensions.
+ if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
+@@ -1383,9 +1413,12 @@ enum {
+ for (y = 0; y < pixelsHigh; y++) {
+ pSrc = bitmapData + y * bytesPerRow;
+ for (x = 0; x < pixelsWide; x++) {
+- cgCol.red = ((float)*(pSrc)) / 255;
+- cgCol.green = ((float)*(pSrc+1)) / 255;
+- cgCol.blue = ((float)*(pSrc+2)) / 255;
++ unsigned char r, g, b;
++ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
++ &r, &g, &b, NULL, isAlphaFirst, isAlphaPremultiplied);
++ cgCol.red = (float)r / 255;
++ cgCol.green = (float)g / 255;
++ cgCol.blue = (float)b / 255;
+
+ *pDest++ = CGPaletteGetIndexForColor(cgPal, cgCol);
+
+@@ -1436,6 +1469,8 @@ enum {
+ BOOL isPlanar = [bitmapImageRep isPlanar];
+ long bytesPerRow = [bitmapImageRep bytesPerRow];
+ unsigned char* bitmapData = [bitmapImageRep bitmapData];
++ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
++ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
+
+ // Make sure bitmap has the required dimensions.
+ if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
+@@ -1469,8 +1504,11 @@ enum {
+ for (y = 0; y < pixelsHigh; y++) {
+ pSrc = bitmapData + y * bytesPerRow;
+ for (x = 0; x < pixelsWide; x++) {
+- pSrc += 3;
+- *pDest++ = *pSrc++;
++ unsigned char a;
++ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
++ NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
++ *pDest++ = a;
++ pSrc += 4;
+ }
+ }
+ }
+@@ -1514,6 +1552,8 @@ enum {
+ BOOL isPlanar = [bitmapImageRep isPlanar];
+ long bytesPerRow = [bitmapImageRep bytesPerRow];
+ unsigned char* bitmapData = [bitmapImageRep bitmapData];
++ BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
++ BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
+
+ // Make sure bitmap has the required dimensions.
+ if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
+@@ -1544,14 +1584,14 @@ enum {
+ pSrc = bitmapData + y * bytesPerRow;
+ for (x = 0; x < pixelsWide; x += 8) {
+ maskByte = 0;
+- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x80 : 0; pSrc += 4;
+- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x40 : 0; pSrc += 4;
+- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x20 : 0; pSrc += 4;
+- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x10 : 0; pSrc += 4;
+- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x08 : 0; pSrc += 4;
+- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x04 : 0; pSrc += 4;
+- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x02 : 0; pSrc += 4;
+- maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x01 : 0; pSrc += 4;
++ for (int i = 7; i >= 0; i--) {
++ unsigned char a;
++ GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
++ NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
++ if (a)
++ maskByte |= 1 << i;
++ pSrc += 4;
++ }
+ *pDest++ = maskByte;
+ }
+ }
+diff --git a/third_party/icon_family/README.chromium b/third_party/icon_family/README.chromium
+index 915d197..bbe5096 100644
+--- a/third_party/icon_family/README.chromium
++++ b/third_party/icon_family/README.chromium
+@@ -12,3 +12,4 @@ This is an Objective-C wrapper around Mac OS X Icon Services' "IconFamily" data
+
+ Local Modifications:
+ chromium_icon_family.patch: Fix minor erors and warnings. Put code that the custom icon code behind a DISABLE_CUSTOM_ICON flag.
++chromium_icon_family_2.patch: Add support for alpha first and non-premultiplied image formats.