| OLD | NEW |
| 1 // IconFamily.m | 1 // IconFamily.m |
| 2 // IconFamily class implementation | 2 // IconFamily class implementation |
| 3 // by Troy Stephens, Thomas Schnitzer, David Remahl, Nathan Day, Ben Haller, Sve
n Janssen, Peter Hosey, Conor Dearden, Elliot Glaysher, and Dave MacLachlan | 3 // by Troy Stephens, Thomas Schnitzer, David Remahl, Nathan Day, Ben Haller, Sve
n Janssen, Peter Hosey, Conor Dearden, Elliot Glaysher, and Dave MacLachlan |
| 4 // version 0.9.4 | 4 // version 0.9.4 |
| 5 // | 5 // |
| 6 // Project Home Page: | 6 // Project Home Page: |
| 7 // http://iconfamily.sourceforge.net/ | 7 // http://iconfamily.sourceforge.net/ |
| 8 // | 8 // |
| 9 // Problems, shortcomings, and uncertainties that I'm aware of are flagged with
"NOTE:". Please address bug reports, bug fixes, suggestions, etc. to the projec
t Forums and bug tracker at https://sourceforge.net/projects/iconfamily/ | 9 // Problems, shortcomings, and uncertainties that I'm aware of are flagged with
"NOTE:". Please address bug reports, bug fixes, suggestions, etc. to the projec
t Forums and bug tracker at https://sourceforge.net/projects/iconfamily/ |
| 10 | 10 |
| (...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 [graphicsContext setImageInterpolation:previousImageInterpolation]; | 1229 [graphicsContext setImageInterpolation:previousImageInterpolation]; |
| 1230 | 1230 |
| 1231 [newImage unlockFocus]; | 1231 [newImage unlockFocus]; |
| 1232 | 1232 |
| 1233 [workingImage release]; | 1233 [workingImage release]; |
| 1234 | 1234 |
| 1235 // Return the new image! | 1235 // Return the new image! |
| 1236 return [newImage autorelease]; | 1236 return [newImage autorelease]; |
| 1237 } | 1237 } |
| 1238 | 1238 |
| 1239 void GetRGBAFrom32BitSource(unsigned char src1, unsigned char src2, unsigned cha
r src3, unsigned char src4, |
| 1240 unsigned char* redOut, unsigned char* greenOut, unsi
gned char* blueOut, unsigned char* alphaOut, |
| 1241 bool isAlphaFirst, bool isAlphaPremultiplied) { |
| 1242 unsigned char r, g, b, a; |
| 1243 if (isAlphaFirst) { |
| 1244 a = src1; |
| 1245 r = src2; |
| 1246 g = src3; |
| 1247 b = src4; |
| 1248 } else { |
| 1249 r = src1; |
| 1250 g = src2; |
| 1251 b = src3; |
| 1252 a = src4; |
| 1253 } |
| 1254 |
| 1255 if (isAlphaPremultiplied) { |
| 1256 // The RGB values are premultiplied by the alpha (so that |
| 1257 // Quartz can save time when compositing the bitmap to a |
| 1258 // destination), and we undo this premultiplication (with some |
| 1259 // lossiness unfortunately) when retrieving the bitmap data. |
| 1260 float oneOverAlpha = 255.0f / (float)a; |
| 1261 r = r * oneOverAlpha; |
| 1262 g = g * oneOverAlpha; |
| 1263 b = b * oneOverAlpha; |
| 1264 } |
| 1265 |
| 1266 if (redOut) |
| 1267 *redOut = r; |
| 1268 if (greenOut) |
| 1269 *greenOut = g; |
| 1270 if (blueOut) |
| 1271 *blueOut = b; |
| 1272 if (alphaOut) |
| 1273 *alphaOut = a; |
| 1274 } |
| 1275 |
| 1239 + (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requ
iredPixelSize:(int)requiredPixelSize | 1276 + (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requ
iredPixelSize:(int)requiredPixelSize |
| 1240 { | 1277 { |
| 1241 Handle hRawData; | 1278 Handle hRawData; |
| 1242 unsigned char* pRawData; | 1279 unsigned char* pRawData; |
| 1243 Size rawDataSize; | 1280 Size rawDataSize; |
| 1244 unsigned char* pSrc; | 1281 unsigned char* pSrc; |
| 1245 unsigned char* pDest; | 1282 unsigned char* pDest; |
| 1246 int x, y; | 1283 int x, y; |
| 1247 unsigned char alphaByte; | 1284 |
| 1248 float oneOverAlpha; | |
| 1249 | |
| 1250 // Get information about the bitmapImageRep. | 1285 // Get information about the bitmapImageRep. |
| 1251 long pixelsWide = [bitmapImageRep pixelsWide]; | 1286 long pixelsWide = [bitmapImageRep pixelsWide]; |
| 1252 long pixelsHigh = [bitmapImageRep pixelsHigh]; | 1287 long pixelsHigh = [bitmapImageRep pixelsHigh]; |
| 1253 long bitsPerSample = [bitmapImageRep bitsPerSample]; | 1288 long bitsPerSample = [bitmapImageRep bitsPerSample]; |
| 1254 long samplesPerPixel = [bitmapImageRep samplesPerPixel]; | 1289 long samplesPerPixel = [bitmapImageRep samplesPerPixel]; |
| 1255 long bitsPerPixel = [bitmapImageRep bitsPerPixel]; | 1290 long bitsPerPixel = [bitmapImageRep bitsPerPixel]; |
| 1256 BOOL isPlanar = [bitmapImageRep isPlanar]; | 1291 BOOL isPlanar = [bitmapImageRep isPlanar]; |
| 1257 long bytesPerRow = [bitmapImageRep bytesPerRow]; | 1292 long bytesPerRow = [bitmapImageRep bytesPerRow]; |
| 1258 unsigned char* bitmapData = [bitmapImageRep bitmapData]; | 1293 unsigned char* bitmapData = [bitmapImageRep bitmapData]; |
| 1294 BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat
; |
| 1295 BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonprem
ultipliedBitmapFormat); |
| 1259 | 1296 |
| 1260 // Make sure bitmap has the required dimensions. | 1297 // Make sure bitmap has the required dimensions. |
| 1261 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize) | 1298 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize) |
| 1262 return NULL; | 1299 return NULL; |
| 1263 | 1300 |
| 1264 // So far, this code only handles non-planar 32-bit RGBA and 24-bit RGB sour
ce bitmaps. | 1301 // So far, this code only handles non-planar 32-bit RGBA and 24-bit RGB sour
ce bitmaps. |
| 1265 // This could be made more flexible with some additional programming to acco
mmodate other possible | 1302 // This could be made more flexible with some additional programming to acco
mmodate other possible |
| 1266 // formats... | 1303 // formats... |
| 1267 if (isPlanar) | 1304 if (isPlanar) |
| 1268 { | 1305 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1282 if (hRawData == NULL) | 1319 if (hRawData == NULL) |
| 1283 return NULL; | 1320 return NULL; |
| 1284 pRawData = (unsigned char*) *hRawData; | 1321 pRawData = (unsigned char*) *hRawData; |
| 1285 | 1322 |
| 1286 pDest = pRawData; | 1323 pDest = pRawData; |
| 1287 | 1324 |
| 1288 if (bitsPerPixel == 32) { | 1325 if (bitsPerPixel == 32) { |
| 1289 for (y = 0; y < pixelsHigh; y++) { | 1326 for (y = 0; y < pixelsHigh; y++) { |
| 1290 pSrc = bitmapData + y * bytesPerRow; | 1327 pSrc = bitmapData + y * bytesPerRow; |
| 1291 for (x = 0; x < pixelsWide; x++) { | 1328 for (x = 0; x < pixelsWide; x++) { |
| 1292 » » » » » » // Each pixel is 3 bytes of RGB
data, followed by 1 byte of | 1329 unsigned char r, g, b, a; |
| 1293 » » » » » » // alpha. The RGB values are pr
emultiplied by the alpha (so | 1330 GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3
], |
| 1294 » » » » » » // that Quartz can save time whe
n compositing the bitmap to a | 1331 &r, &g, &b, &a, isAlphaFirst, isA
lphaPremultiplied); |
| 1295 » » » » » » // destination), and we undo thi
s premultiplication (with some | 1332 *pDest++ = a; |
| 1296 » » » » » » // lossiness unfortunately) when
retrieving the bitmap data. | 1333 *pDest++ = r; |
| 1297 » » » » » » *pDest++ = alphaByte = *(pSrc+3)
; | 1334 *pDest++ = g; |
| 1298 » » » » » » if (alphaByte) { | 1335 *pDest++ = b; |
| 1299 » » » » » » » oneOverAlpha = 255.0f /
(float)alphaByte; | 1336 pSrc += 4; |
| 1300 » » » » » » » *pDest++ = *(pSrc+0) * o
neOverAlpha; | |
| 1301 » » » » » » » *pDest++ = *(pSrc+1) * o
neOverAlpha; | |
| 1302 » » » » » » » *pDest++ = *(pSrc+2) * o
neOverAlpha; | |
| 1303 » » » » » » } else { | |
| 1304 » » » » » » » *pDest++ = 0; | |
| 1305 » » » » » » » *pDest++ = 0; | |
| 1306 » » » » » » » *pDest++ = 0; | |
| 1307 » » » » » » } | |
| 1308 » » » » » » pSrc+=4; | |
| 1309 } | 1337 } |
| 1310 } | 1338 } |
| 1311 } else if (bitsPerPixel == 24) { | 1339 } else if (bitsPerPixel == 24) { |
| 1312 for (y = 0; y < pixelsHigh; y++) { | 1340 for (y = 0; y < pixelsHigh; y++) { |
| 1313 pSrc = bitmapData + y * bytesPerRow; | 1341 pSrc = bitmapData + y * bytesPerRow; |
| 1314 for (x = 0; x < pixelsWide; x++) { | 1342 for (x = 0; x < pixelsWide; x++) { |
| 1315 *pDest++ = 0xFF; | 1343 *pDest++ = 0xFF; |
| 1316 *pDest++ = *pSrc++; | 1344 *pDest++ = *pSrc++; |
| 1317 *pDest++ = *pSrc++; | 1345 *pDest++ = *pSrc++; |
| 1318 *pDest++ = *pSrc++; | 1346 *pDest++ = *pSrc++; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1340 | 1368 |
| 1341 // Get information about the bitmapImageRep. | 1369 // Get information about the bitmapImageRep. |
| 1342 long pixelsWide = [bitmapImageRep pixelsWide]; | 1370 long pixelsWide = [bitmapImageRep pixelsWide]; |
| 1343 long pixelsHigh = [bitmapImageRep pixelsHigh]; | 1371 long pixelsHigh = [bitmapImageRep pixelsHigh]; |
| 1344 long bitsPerSample = [bitmapImageRep bitsPerSample]; | 1372 long bitsPerSample = [bitmapImageRep bitsPerSample]; |
| 1345 long samplesPerPixel = [bitmapImageRep samplesPerPixel]; | 1373 long samplesPerPixel = [bitmapImageRep samplesPerPixel]; |
| 1346 long bitsPerPixel = [bitmapImageRep bitsPerPixel]; | 1374 long bitsPerPixel = [bitmapImageRep bitsPerPixel]; |
| 1347 BOOL isPlanar = [bitmapImageRep isPlanar]; | 1375 BOOL isPlanar = [bitmapImageRep isPlanar]; |
| 1348 long bytesPerRow = [bitmapImageRep bytesPerRow]; | 1376 long bytesPerRow = [bitmapImageRep bytesPerRow]; |
| 1349 unsigned char* bitmapData = [bitmapImageRep bitmapData]; | 1377 unsigned char* bitmapData = [bitmapImageRep bitmapData]; |
| 1378 BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat
; |
| 1379 BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonprem
ultipliedBitmapFormat); |
| 1350 | 1380 |
| 1351 // Make sure bitmap has the required dimensions. | 1381 // Make sure bitmap has the required dimensions. |
| 1352 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize) | 1382 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize) |
| 1353 return NULL; | 1383 return NULL; |
| 1354 | 1384 |
| 1355 // So far, this code only handles non-planar 32-bit RGBA and 24-bit RGB sour
ce bitmaps. | 1385 // So far, this code only handles non-planar 32-bit RGBA and 24-bit RGB sour
ce bitmaps. |
| 1356 // This could be made more flexible with some additional programming... | 1386 // This could be made more flexible with some additional programming... |
| 1357 if (isPlanar) | 1387 if (isPlanar) |
| 1358 { | 1388 { |
| 1359 NSLog(@"get8BitDataFromBitmapImageRep:requiredPixelSize: returni
ng NULL due to isPlanar == YES"); | 1389 NSLog(@"get8BitDataFromBitmapImageRep:requiredPixelSize: returni
ng NULL due to isPlanar == YES"); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1376 return NULL; | 1406 return NULL; |
| 1377 pRawData = (unsigned char*) *hRawData; | 1407 pRawData = (unsigned char*) *hRawData; |
| 1378 | 1408 |
| 1379 cgPal = CGPaletteCreateDefaultColorPalette(); | 1409 cgPal = CGPaletteCreateDefaultColorPalette(); |
| 1380 | 1410 |
| 1381 pDest = pRawData; | 1411 pDest = pRawData; |
| 1382 if (bitsPerPixel == 32) { | 1412 if (bitsPerPixel == 32) { |
| 1383 for (y = 0; y < pixelsHigh; y++) { | 1413 for (y = 0; y < pixelsHigh; y++) { |
| 1384 pSrc = bitmapData + y * bytesPerRow; | 1414 pSrc = bitmapData + y * bytesPerRow; |
| 1385 for (x = 0; x < pixelsWide; x++) { | 1415 for (x = 0; x < pixelsWide; x++) { |
| 1386 » » » » » cgCol.red = ((float)*(pSrc)) / 255; | 1416 unsigned char r, g, b; |
| 1387 » » » » » cgCol.green = ((float)*(pSrc+1)) / 255; | 1417 GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3], |
| 1388 » » » » » cgCol.blue = ((float)*(pSrc+2)) / 255; | 1418 &r, &g, &b, NULL, isAlphaFirst, isAlp
haPremultiplied); |
| 1419 » » » » » cgCol.red = (float)r / 255; |
| 1420 » » » » » cgCol.green = (float)g / 255; |
| 1421 » » » » » cgCol.blue = (float)b / 255; |
| 1389 | 1422 |
| 1390 *pDest++ = CGPaletteGetIndexForColor(cgP
al, cgCol); | 1423 *pDest++ = CGPaletteGetIndexForColor(cgP
al, cgCol); |
| 1391 | 1424 |
| 1392 pSrc+=4; | 1425 pSrc+=4; |
| 1393 } | 1426 } |
| 1394 } | 1427 } |
| 1395 } else if (bitsPerPixel == 24) { | 1428 } else if (bitsPerPixel == 24) { |
| 1396 for (y = 0; y < pixelsHigh; y++) { | 1429 for (y = 0; y < pixelsHigh; y++) { |
| 1397 pSrc = bitmapData + y * bytesPerRow; | 1430 pSrc = bitmapData + y * bytesPerRow; |
| 1398 for (x = 0; x < pixelsWide; x++) { | 1431 for (x = 0; x < pixelsWide; x++) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1429 | 1462 |
| 1430 // Get information about the bitmapImageRep. | 1463 // Get information about the bitmapImageRep. |
| 1431 long pixelsWide = [bitmapImageRep pixelsWide]; | 1464 long pixelsWide = [bitmapImageRep pixelsWide]; |
| 1432 long pixelsHigh = [bitmapImageRep pixelsHigh]; | 1465 long pixelsHigh = [bitmapImageRep pixelsHigh]; |
| 1433 long bitsPerSample = [bitmapImageRep bitsPerSample]; | 1466 long bitsPerSample = [bitmapImageRep bitsPerSample]; |
| 1434 long samplesPerPixel = [bitmapImageRep samplesPerPixel]; | 1467 long samplesPerPixel = [bitmapImageRep samplesPerPixel]; |
| 1435 long bitsPerPixel = [bitmapImageRep bitsPerPixel]; | 1468 long bitsPerPixel = [bitmapImageRep bitsPerPixel]; |
| 1436 BOOL isPlanar = [bitmapImageRep isPlanar]; | 1469 BOOL isPlanar = [bitmapImageRep isPlanar]; |
| 1437 long bytesPerRow = [bitmapImageRep bytesPerRow]; | 1470 long bytesPerRow = [bitmapImageRep bytesPerRow]; |
| 1438 unsigned char* bitmapData = [bitmapImageRep bitmapData]; | 1471 unsigned char* bitmapData = [bitmapImageRep bitmapData]; |
| 1472 BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat
; |
| 1473 BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonprem
ultipliedBitmapFormat); |
| 1439 | 1474 |
| 1440 // Make sure bitmap has the required dimensions. | 1475 // Make sure bitmap has the required dimensions. |
| 1441 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize) | 1476 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize) |
| 1442 return NULL; | 1477 return NULL; |
| 1443 | 1478 |
| 1444 // So far, this code only handles non-planar 32-bit RGBA, 24-bit RGB and 8-b
it grayscale source bitmaps. | 1479 // So far, this code only handles non-planar 32-bit RGBA, 24-bit RGB and 8-b
it grayscale source bitmaps. |
| 1445 // This could be made more flexible with some additional programming... | 1480 // This could be made more flexible with some additional programming... |
| 1446 if (isPlanar) | 1481 if (isPlanar) |
| 1447 { | 1482 { |
| 1448 NSLog(@"get8BitMaskFromBitmapImageRep:requiredPixelSize: returni
ng NULL due to isPlanar == YES"); | 1483 NSLog(@"get8BitMaskFromBitmapImageRep:requiredPixelSize: returni
ng NULL due to isPlanar == YES"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1462 return NULL; | 1497 return NULL; |
| 1463 pRawData = (unsigned char*) *hRawData; | 1498 pRawData = (unsigned char*) *hRawData; |
| 1464 | 1499 |
| 1465 pSrc = bitmapData; | 1500 pSrc = bitmapData; |
| 1466 pDest = pRawData; | 1501 pDest = pRawData; |
| 1467 | 1502 |
| 1468 if (bitsPerPixel == 32) { | 1503 if (bitsPerPixel == 32) { |
| 1469 for (y = 0; y < pixelsHigh; y++) { | 1504 for (y = 0; y < pixelsHigh; y++) { |
| 1470 pSrc = bitmapData + y * bytesPerRow; | 1505 pSrc = bitmapData + y * bytesPerRow; |
| 1471 for (x = 0; x < pixelsWide; x++) { | 1506 for (x = 0; x < pixelsWide; x++) { |
| 1472 » » » » » pSrc += 3; | 1507 unsigned char a; |
| 1473 » » » » » *pDest++ = *pSrc++; | 1508 GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3], |
| 1509 NULL, NULL, NULL, &a, isAlphaFirst, i
sAlphaPremultiplied); |
| 1510 *pDest++ = a; |
| 1511 » » » » » pSrc += 4; |
| 1474 } | 1512 } |
| 1475 } | 1513 } |
| 1476 } | 1514 } |
| 1477 else if (bitsPerPixel == 24) { | 1515 else if (bitsPerPixel == 24) { |
| 1478 memset( pDest, 255, rawDataSize ); | 1516 memset( pDest, 255, rawDataSize ); |
| 1479 } | 1517 } |
| 1480 else if (bitsPerPixel == 8) { | 1518 else if (bitsPerPixel == 8) { |
| 1481 for (y = 0; y < pixelsHigh; y++) { | 1519 for (y = 0; y < pixelsHigh; y++) { |
| 1482 memcpy( pDest, pSrc, pixelsWide ); | 1520 memcpy( pDest, pSrc, pixelsWide ); |
| 1483 pSrc += bytesPerRow; | 1521 pSrc += bytesPerRow; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1507 | 1545 |
| 1508 // Get information about the bitmapImageRep. | 1546 // Get information about the bitmapImageRep. |
| 1509 long pixelsWide = [bitmapImageRep pixelsWide]; | 1547 long pixelsWide = [bitmapImageRep pixelsWide]; |
| 1510 long pixelsHigh = [bitmapImageRep pixelsHigh]; | 1548 long pixelsHigh = [bitmapImageRep pixelsHigh]; |
| 1511 long bitsPerSample = [bitmapImageRep bitsPerSample]; | 1549 long bitsPerSample = [bitmapImageRep bitsPerSample]; |
| 1512 long samplesPerPixel = [bitmapImageRep samplesPerPixel]; | 1550 long samplesPerPixel = [bitmapImageRep samplesPerPixel]; |
| 1513 long bitsPerPixel = [bitmapImageRep bitsPerPixel]; | 1551 long bitsPerPixel = [bitmapImageRep bitsPerPixel]; |
| 1514 BOOL isPlanar = [bitmapImageRep isPlanar]; | 1552 BOOL isPlanar = [bitmapImageRep isPlanar]; |
| 1515 long bytesPerRow = [bitmapImageRep bytesPerRow]; | 1553 long bytesPerRow = [bitmapImageRep bytesPerRow]; |
| 1516 unsigned char* bitmapData = [bitmapImageRep bitmapData]; | 1554 unsigned char* bitmapData = [bitmapImageRep bitmapData]; |
| 1555 BOOL isAlphaFirst = [bitmapImageRep bitmapFormat] & NSAlphaFirstBitmapFormat
; |
| 1556 BOOL isAlphaPremultiplied = !([bitmapImageRep bitmapFormat] & NSAlphaNonprem
ultipliedBitmapFormat); |
| 1517 | 1557 |
| 1518 // Make sure bitmap has the required dimensions. | 1558 // Make sure bitmap has the required dimensions. |
| 1519 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize) | 1559 if (pixelsWide != requiredPixelSize || pixelsHigh != requiredPixelSize) |
| 1520 return NULL; | 1560 return NULL; |
| 1521 | 1561 |
| 1522 // So far, this code only handles non-planar 32-bit RGBA, 24-bit RGB, 8-bit
grayscale, and 1-bit source bitmaps. | 1562 // So far, this code only handles non-planar 32-bit RGBA, 24-bit RGB, 8-bit
grayscale, and 1-bit source bitmaps. |
| 1523 // This could be made more flexible with some additional programming... | 1563 // This could be made more flexible with some additional programming... |
| 1524 if (isPlanar) | 1564 if (isPlanar) |
| 1525 { | 1565 { |
| 1526 NSLog(@"get1BitMaskFromBitmapImageRep:requiredPixelSize: returni
ng NULL due to isPlanar == YES"); | 1566 NSLog(@"get1BitMaskFromBitmapImageRep:requiredPixelSize: returni
ng NULL due to isPlanar == YES"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1537 pRawData = (unsigned char*) *hRawData; | 1577 pRawData = (unsigned char*) *hRawData; |
| 1538 | 1578 |
| 1539 pSrc = bitmapData; | 1579 pSrc = bitmapData; |
| 1540 pDest = pRawData; | 1580 pDest = pRawData; |
| 1541 | 1581 |
| 1542 if (bitsPerPixel == 32) { | 1582 if (bitsPerPixel == 32) { |
| 1543 for (y = 0; y < pixelsHigh; y++) { | 1583 for (y = 0; y < pixelsHigh; y++) { |
| 1544 pSrc = bitmapData + y * bytesPerRow; | 1584 pSrc = bitmapData + y * bytesPerRow; |
| 1545 for (x = 0; x < pixelsWide; x += 8) { | 1585 for (x = 0; x < pixelsWide; x += 8) { |
| 1546 maskByte = 0; | 1586 maskByte = 0; |
| 1547 » » » » » maskByte |= (*(unsigned*)pSrc & 0xff) ?
0x80 : 0; pSrc += 4; | 1587 for (int i = 7; i >= 0; i--) { |
| 1548 » » » » » maskByte |= (*(unsigned*)pSrc & 0xff) ?
0x40 : 0; pSrc += 4; | 1588 unsigned char a; |
| 1549 » » » » » maskByte |= (*(unsigned*)pSrc & 0xff) ?
0x20 : 0; pSrc += 4; | 1589 GetRGBAFrom32BitSource(pSrc[0], pSrc[1], pSrc[2], pSrc[3
], |
| 1550 » » » » » maskByte |= (*(unsigned*)pSrc & 0xff) ?
0x10 : 0; pSrc += 4; | 1590 NULL, NULL, NULL, &a, isAlphaFirs
t, isAlphaPremultiplied); |
| 1551 » » » » » maskByte |= (*(unsigned*)pSrc & 0xff) ?
0x08 : 0; pSrc += 4; | 1591 if (a) |
| 1552 » » » » » maskByte |= (*(unsigned*)pSrc & 0xff) ?
0x04 : 0; pSrc += 4; | 1592 maskByte |= 1 << i; |
| 1553 » » » » » maskByte |= (*(unsigned*)pSrc & 0xff) ?
0x02 : 0; pSrc += 4; | 1593 pSrc += 4; |
| 1554 » » » » » maskByte |= (*(unsigned*)pSrc & 0xff) ?
0x01 : 0; pSrc += 4; | 1594 } |
| 1555 *pDest++ = maskByte; | 1595 *pDest++ = maskByte; |
| 1556 } | 1596 } |
| 1557 } | 1597 } |
| 1558 } | 1598 } |
| 1559 else if (bitsPerPixel == 24) { | 1599 else if (bitsPerPixel == 24) { |
| 1560 memset( pDest, 255, rawDataSize ); | 1600 memset( pDest, 255, rawDataSize ); |
| 1561 } | 1601 } |
| 1562 else if (bitsPerPixel == 8) { | 1602 else if (bitsPerPixel == 8) { |
| 1563 for (y = 0; y < pixelsHigh; y++) { | 1603 for (y = 0; y < pixelsHigh; y++) { |
| 1564 pSrc = bitmapData + y * bytesPerRow; | 1604 pSrc = bitmapData + y * bytesPerRow; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1715 if (![self respondsToSelector:@selector(bestRepresentationForRect:contex
t:hints:)]) | 1755 if (![self respondsToSelector:@selector(bestRepresentationForRect:contex
t:hints:)]) |
| 1716 { | 1756 { |
| 1717 return [self bestRepresentationForDevice:nil]; | 1757 return [self bestRepresentationForDevice:nil]; |
| 1718 } | 1758 } |
| 1719 #endif | 1759 #endif |
| 1720 | 1760 |
| 1721 return [self bestRepresentationForRect:(NSRect){NSZeroPoint, [self size]
} context:nil hints:nil]; | 1761 return [self bestRepresentationForRect:(NSRect){NSZeroPoint, [self size]
} context:nil hints:nil]; |
| 1722 } | 1762 } |
| 1723 | 1763 |
| 1724 @end | 1764 @end |
| OLD | NEW |