1 diff --git a/third_party/icon_family/IconFamily.m b/third_party/icon_family/IconFamily.m
2 index 439c2de..911ea31 100644
3 --- a/third_party/icon_family/IconFamily.m
4 +++ b/third_party/icon_family/IconFamily.m
5 @@ -1236,6 +1236,43 @@ enum {
6 return [newImage autorelease];
9 +void GetRGBAFrom32BitSource(unsigned char src1, unsigned char src2, unsigned char src3, unsigned char src4,
10 + unsigned char* redOut, unsigned char* greenOut, unsigned char* blueOut, unsigned char* alphaOut,
11 + bool isAlphaFirst, bool isAlphaPremultiplied) {
12 + unsigned char r, g, b, a;
25 + if (isAlphaPremultiplied) {
26 + // The RGB values are premultiplied by the alpha (so that
27 + // Quartz can save time when compositing the bitmap to a
28 + // destination), and we undo this premultiplication (with some
29 + // lossiness unfortunately) when retrieving the bitmap data.
30 + float oneOverAlpha = 255.0f / (float)a;
31 + r = r * oneOverAlpha;
32 + g = g * oneOverAlpha;
33 + b = b * oneOverAlpha;
46 + (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requiredPixelSize:(int)requiredPixelSize
49 @@ -1244,9 +1281,7 @@ enum {
53 - unsigned char alphaByte;
57 // Get information about the bitmapImageRep.
58 long pixelsWide = [bitmapImageRep pixelsWide];
59 long pixelsHigh = [bitmapImageRep pixelsHigh];
60 @@ -1256,6 +1291,8 @@ enum {
61 BOOL isPlanar = [bitmapImageRep isPlanar];
62 long bytesPerRow = [bitmapImageRep bytesPerRow];
63 unsigned char* bitmapData = [bitmapImageRep bitmapData];
64 + BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
65 + BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
67 // Make sure bitmap has the required dimensions.
68 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
69 @@ -1289,23 +1326,14 @@ enum {
70 for (y = 0; y < pixelsHigh; y++) {
71 pSrc = bitmapData + y * bytesPerRow;
72 for (x = 0; x < pixelsWide; x++) {
73 - // Each pixel is 3 bytes of RGB data, followed by 1 byte of
74 - // alpha. The RGB values are premultiplied by the alpha (so
75 - // that Quartz can save time when compositing the bitmap to a
76 - // destination), and we undo this premultiplication (with some
77 - // lossiness unfortunately) when retrieving the bitmap data.
78 - *pDest++ = alphaByte = *(pSrc+3);
80 - oneOverAlpha = 255.0f / (float)alphaByte;
81 - *pDest++ = *(pSrc+0) * oneOverAlpha;
82 - *pDest++ = *(pSrc+1) * oneOverAlpha;
83 - *pDest++ = *(pSrc+2) * oneOverAlpha;
90 + unsigned char r, g, b, a;
91 + GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
92 + &r, &g, &b, &a, isAlphaFirst, isAlphaPremultiplied);
100 } else if (bitsPerPixel == 24) {
101 @@ -1347,6 +1375,8 @@ enum {
102 BOOL isPlanar = [bitmapImageRep isPlanar];
103 long bytesPerRow = [bitmapImageRep bytesPerRow];
104 unsigned char* bitmapData = [bitmapImageRep bitmapData];
105 + BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
106 + BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
108 // Make sure bitmap has the required dimensions.
109 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
110 @@ -1383,9 +1413,12 @@ enum {
111 for (y = 0; y < pixelsHigh; y++) {
112 pSrc = bitmapData + y * bytesPerRow;
113 for (x = 0; x < pixelsWide; x++) {
114 - cgCol.red = ((float)*(pSrc)) / 255;
115 - cgCol.green = ((float)*(pSrc+1)) / 255;
116 - cgCol.blue = ((float)*(pSrc+2)) / 255;
117 + unsigned char r, g, b;
118 + GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
119 + &r, &g, &b, NULL, isAlphaFirst, isAlphaPremultiplied);
120 + cgCol.red = (float)r / 255;
121 + cgCol.green = (float)g / 255;
122 + cgCol.blue = (float)b / 255;
124 *pDest++ = CGPaletteGetIndexForColor(cgPal, cgCol);
126 @@ -1436,6 +1469,8 @@ enum {
127 BOOL isPlanar = [bitmapImageRep isPlanar];
128 long bytesPerRow = [bitmapImageRep bytesPerRow];
129 unsigned char* bitmapData = [bitmapImageRep bitmapData];
130 + BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
131 + BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
133 // Make sure bitmap has the required dimensions.
134 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
135 @@ -1469,8 +1504,11 @@ enum {
136 for (y = 0; y < pixelsHigh; y++) {
137 pSrc = bitmapData + y * bytesPerRow;
138 for (x = 0; x < pixelsWide; x++) {
140 - *pDest++ = *pSrc++;
142 + GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
143 + NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
149 @@ -1514,6 +1552,8 @@ enum {
150 BOOL isPlanar = [bitmapImageRep isPlanar];
151 long bytesPerRow = [bitmapImageRep bytesPerRow];
152 unsigned char* bitmapData = [bitmapImageRep bitmapData];
153 + BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat;
154 + BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpremultipliedBitmapFormat);
156 // Make sure bitmap has the required dimensions.
157 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize)
158 @@ -1544,14 +1584,14 @@ enum {
159 pSrc = bitmapData + y * bytesPerRow;
160 for (x = 0; x < pixelsWide; x += 8) {
162 - maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x80 : 0; pSrc += 4;
163 - maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x40 : 0; pSrc += 4;
164 - maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x20 : 0; pSrc += 4;
165 - maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x10 : 0; pSrc += 4;
166 - maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x08 : 0; pSrc += 4;
167 - maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x04 : 0; pSrc += 4;
168 - maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x02 : 0; pSrc += 4;
169 - maskByte |= (*(unsigned*)pSrc & 0xff) ? 0x01 : 0; pSrc += 4;
170 + for (int i = 7; i >= 0; i--) {
172 + GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3],
173 + NULL, NULL, NULL, &a, isAlphaFirst, isAlphaPremultiplied);
175 + maskByte |= 1 << i;
181 diff --git a/third_party/icon_family/README.chromium b/third_party/icon_family/README.chromium
182 index 915d197..bbe5096 100644
183 --- a/third_party/icon_family/README.chromium
184 +++ b/third_party/icon_family/README.chromium
185 @@ -12,3 +12,4 @@ This is an Objective-C wrapper around Mac OS X Icon Services' "IconFamily" data
188 chromium_icon_family.patch: Fix minor erors and warnings. Put code that the custom icon code behind a DISABLE_CUSTOM_ICON flag.
189 +chromium_icon_family_2.patch: Add support for alpha first and non-premultiplied image formats.