OLD | NEW |
(Empty) | |
| 1 diff --git a/third_party/icon_family/IconFamily.m b/third_party/icon_family/Icon
Family.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]; |
| 7 } |
| 8 |
| 9 +void GetRGBAFrom32BitSource(unsigned char src1, unsigned char src2, unsigned ch
ar src3, unsigned char src4, |
| 10 + unsigned char* redOut, unsigned char* greenOut, uns
igned char* blueOut, unsigned char* alphaOut, |
| 11 + bool isAlphaFirst, bool isAlphaPremultiplied) { |
| 12 + unsigned char r, g, b, a; |
| 13 + if (isAlphaFirst) { |
| 14 + a = src1; |
| 15 + r = src2; |
| 16 + g = src3; |
| 17 + b = src4; |
| 18 + } else { |
| 19 + r = src1; |
| 20 + g = src2; |
| 21 + b = src3; |
| 22 + a = src4; |
| 23 + } |
| 24 + |
| 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; |
| 34 + } |
| 35 + |
| 36 + if (redOut) |
| 37 + *redOut = r; |
| 38 + if (greenOut) |
| 39 + *greenOut = g; |
| 40 + if (blueOut) |
| 41 + *blueOut = b; |
| 42 + if (alphaOut) |
| 43 + *alphaOut = a; |
| 44 +} |
| 45 + |
| 46 + (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep req
uiredPixelSize:(int)requiredPixelSize |
| 47 { |
| 48 Handle hRawData; |
| 49 @@ -1244,9 +1281,7 @@ enum { |
| 50 unsigned char* pSrc; |
| 51 unsigned char* pDest; |
| 52 int x, y; |
| 53 - unsigned char alphaByte; |
| 54 - float oneOverAlpha; |
| 55 - |
| 56 + |
| 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] & NSAlphaFirstBitmapForma
t; |
| 65 + BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpre
multipliedBitmapFormat); |
| 66 |
| 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 pr
emultiplied by the alpha (so |
| 75 - // that Quartz can save time whe
n compositing the bitmap to a |
| 76 - // destination), and we undo thi
s premultiplication (with some |
| 77 - // lossiness unfortunately) when
retrieving the bitmap data. |
| 78 - *pDest++ = alphaByte = *(pSrc+3)
; |
| 79 - if (alphaByte) { |
| 80 - oneOverAlpha = 255.0f /
(float)alphaByte; |
| 81 - *pDest++ = *(pSrc+0) * o
neOverAlpha; |
| 82 - *pDest++ = *(pSrc+1) * o
neOverAlpha; |
| 83 - *pDest++ = *(pSrc+2) * o
neOverAlpha; |
| 84 - } else { |
| 85 - *pDest++ = 0; |
| 86 - *pDest++ = 0; |
| 87 - *pDest++ = 0; |
| 88 - } |
| 89 - pSrc+=4; |
| 90 + unsigned char r, g, b, a; |
| 91 + GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[
3], |
| 92 + &r, &g, &b, &a, isAlphaFirst, is
AlphaPremultiplied); |
| 93 + *pDest++ = a; |
| 94 + *pDest++ = r; |
| 95 + *pDest++ = g; |
| 96 + *pDest++ = b; |
| 97 + pSrc += 4; |
| 98 } |
| 99 } |
| 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] & NSAlphaFirstBitmapForma
t; |
| 106 + BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpre
multipliedBitmapFormat); |
| 107 |
| 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, isAl
phaPremultiplied); |
| 120 + cgCol.red = (float)r / 255; |
| 121 + cgCol.green = (float)g / 255; |
| 122 + cgCol.blue = (float)b / 255; |
| 123 |
| 124 *pDest++ = CGPaletteGetIndexForColor(cgP
al, cgCol); |
| 125 |
| 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] & NSAlphaFirstBitmapForma
t; |
| 131 + BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpre
multipliedBitmapFormat); |
| 132 |
| 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++) { |
| 139 - pSrc += 3; |
| 140 - *pDest++ = *pSrc++; |
| 141 + unsigned char a; |
| 142 + GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3], |
| 143 + NULL, NULL, NULL, &a, isAlphaFirst,
isAlphaPremultiplied); |
| 144 + *pDest++ = a; |
| 145 + pSrc += 4; |
| 146 } |
| 147 } |
| 148 } |
| 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] & NSAlphaFirstBitmapForma
t; |
| 154 + BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonpre
multipliedBitmapFormat); |
| 155 |
| 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) { |
| 161 maskByte = 0; |
| 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--) { |
| 171 + unsigned char a; |
| 172 + GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[
3], |
| 173 + NULL, NULL, NULL, &a, isAlphaFir
st, isAlphaPremultiplied); |
| 174 + if (a) |
| 175 + maskByte |= 1 << i; |
| 176 + pSrc += 4; |
| 177 + } |
| 178 *pDest++ = maskByte; |
| 179 } |
| 180 } |
| 181 diff --git a/third_party/icon_family/README.chromium b/third_party/icon_family/R
EADME.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 |
| 186 |
| 187 Local Modifications: |
| 188 chromium_icon_family.patch: Fix minor erors and warnings. Put code that the cus
tom icon code behind a DISABLE_CUSTOM_ICON flag. |
| 189 +chromium_icon_family_2.patch: Add support for alpha first and non-premultiplied
image formats. |
OLD | NEW |