Mercurial > projects > dwt-mac
comparison dwt/graphics/ImageData.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 1a8b3cb347e0 |
children | b9226997409c |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
216 for (int b = 0; b < 9; ++b) { | 216 for (int b = 0; b < 9; ++b) { |
217 byte[] data = ANY_TO_EIGHT[b] = new byte[1 << b]; | 217 byte[] data = ANY_TO_EIGHT[b] = new byte[1 << b]; |
218 if (b is 0) continue; | 218 if (b is 0) continue; |
219 int inc = 0; | 219 int inc = 0; |
220 for (int bit = 0x10000; (bit >>= b) !is 0;) inc |= bit; | 220 for (int bit = 0x10000; (bit >>= b) !is 0;) inc |= bit; |
221 for (int v = 0, p = 0; v < 0x10000; v+= inc) data[p++] = (byte)(v >> 8); | 221 for (int v = 0, p = 0; v < 0x10000; v+= inc) data[p++] = cast(byte)(v >> 8); |
222 } | 222 } |
223 } | 223 } |
224 static final byte[] ONE_TO_ONE_MAPPING = ANY_TO_EIGHT[8]; | 224 static final byte[] ONE_TO_ONE_MAPPING = ANY_TO_EIGHT[8]; |
225 | 225 |
226 /** | 226 /** |
625 if (getWidth is 0) return; | 625 if (getWidth is 0) return; |
626 | 626 |
627 if (alphaData is null) { | 627 if (alphaData is null) { |
628 int endIndex = startIndex + getWidth; | 628 int endIndex = startIndex + getWidth; |
629 for (int i = startIndex; i < endIndex; i++) { | 629 for (int i = startIndex; i < endIndex; i++) { |
630 alphas[i] = (byte)255; | 630 alphas[i] = cast(byte)255; |
631 } | 631 } |
632 return; | 632 return; |
633 } | 633 } |
634 // may throw an IndexOutOfBoundsException | 634 // may throw an IndexOutOfBoundsException |
635 System.arraycopy(alphaData, y * width + x, alphas, startIndex, getWidth); | 635 System.arraycopy(alphaData, y * width + x, alphas, startIndex, getWidth); |
748 return; | 748 return; |
749 case 4: | 749 case 4: |
750 index = (y * bytesPerLine) + (x >> 1); | 750 index = (y * bytesPerLine) + (x >> 1); |
751 if ((x & 0x1) is 1) { | 751 if ((x & 0x1) is 1) { |
752 theByte = data[index] & 0xFF; | 752 theByte = data[index] & 0xFF; |
753 pixels[i] = (byte)(theByte & 0x0F); | 753 pixels[i] = cast(byte)(theByte & 0x0F); |
754 i++; | 754 i++; |
755 n--; | 755 n--; |
756 srcX++; | 756 srcX++; |
757 if (srcX >= width) { | 757 if (srcX >= width) { |
758 srcY++; | 758 srcY++; |
762 index++; | 762 index++; |
763 } | 763 } |
764 } | 764 } |
765 while (n > 1) { | 765 while (n > 1) { |
766 theByte = data[index] & 0xFF; | 766 theByte = data[index] & 0xFF; |
767 pixels[i] = (byte)(theByte >> 4); | 767 pixels[i] = cast(byte)(theByte >> 4); |
768 i++; | 768 i++; |
769 n--; | 769 n--; |
770 srcX++; | 770 srcX++; |
771 if (srcX >= width) { | 771 if (srcX >= width) { |
772 srcY++; | 772 srcY++; |
773 index = srcY * bytesPerLine; | 773 index = srcY * bytesPerLine; |
774 srcX = 0; | 774 srcX = 0; |
775 } else { | 775 } else { |
776 pixels[i] = (byte)(theByte & 0x0F); | 776 pixels[i] = cast(byte)(theByte & 0x0F); |
777 i++; | 777 i++; |
778 n--; | 778 n--; |
779 srcX++; | 779 srcX++; |
780 if (srcX >= width) { | 780 if (srcX >= width) { |
781 srcY++; | 781 srcY++; |
786 } | 786 } |
787 } | 787 } |
788 } | 788 } |
789 if (n > 0) { | 789 if (n > 0) { |
790 theByte = data[index] & 0xFF; | 790 theByte = data[index] & 0xFF; |
791 pixels[i] = (byte)(theByte >> 4); | 791 pixels[i] = cast(byte)(theByte >> 4); |
792 } | 792 } |
793 return; | 793 return; |
794 case 2: | 794 case 2: |
795 index = (y * bytesPerLine) + (x >> 2); | 795 index = (y * bytesPerLine) + (x >> 2); |
796 theByte = data[index] & 0xFF; | 796 theByte = data[index] & 0xFF; |
797 int offset; | 797 int offset; |
798 while (n > 0) { | 798 while (n > 0) { |
799 offset = 3 - (srcX % 4); | 799 offset = 3 - (srcX % 4); |
800 mask = 3 << (offset * 2); | 800 mask = 3 << (offset * 2); |
801 pixels[i] = (byte)((theByte & mask) >> (offset * 2)); | 801 pixels[i] = cast(byte)((theByte & mask) >> (offset * 2)); |
802 i++; | 802 i++; |
803 n--; | 803 n--; |
804 srcX++; | 804 srcX++; |
805 if (srcX >= width) { | 805 if (srcX >= width) { |
806 srcY++; | 806 srcY++; |
990 theByte = data[index] & 0xFF; | 990 theByte = data[index] & 0xFF; |
991 int offset; | 991 int offset; |
992 while (n > 0) { | 992 while (n > 0) { |
993 offset = 3 - (srcX % 4); | 993 offset = 3 - (srcX % 4); |
994 mask = 3 << (offset * 2); | 994 mask = 3 << (offset * 2); |
995 pixels[i] = (byte)((theByte & mask) >> (offset * 2)); | 995 pixels[i] = cast(byte)((theByte & mask) >> (offset * 2)); |
996 i++; | 996 i++; |
997 n--; | 997 n--; |
998 srcX++; | 998 srcX++; |
999 if (srcX >= width) { | 999 if (srcX >= width) { |
1000 srcY++; | 1000 srcY++; |
1167 public void setAlpha(int x, int y, int alpha) { | 1167 public void setAlpha(int x, int y, int alpha) { |
1168 if (x >= width || y >= height || x < 0 || y < 0 || alpha < 0 || alpha > 255) | 1168 if (x >= width || y >= height || x < 0 || y < 0 || alpha < 0 || alpha > 255) |
1169 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 1169 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
1170 | 1170 |
1171 if (alphaData is null) alphaData = new byte[width * height]; | 1171 if (alphaData is null) alphaData = new byte[width * height]; |
1172 alphaData[y * width + x] = (byte)alpha; | 1172 alphaData[y * width + x] = cast(byte)alpha; |
1173 } | 1173 } |
1174 | 1174 |
1175 /** | 1175 /** |
1176 * Sets the alpha values starting at offset <code>x</code> in | 1176 * Sets the alpha values starting at offset <code>x</code> in |
1177 * scanline <code>y</code> in the receiver's alpha data to the | 1177 * scanline <code>y</code> in the receiver's alpha data to the |
1222 byte theByte; | 1222 byte theByte; |
1223 int mask; | 1223 int mask; |
1224 switch (depth) { | 1224 switch (depth) { |
1225 case 32: | 1225 case 32: |
1226 index = (y * bytesPerLine) + (x * 4); | 1226 index = (y * bytesPerLine) + (x * 4); |
1227 data[index] = (byte)((pixelValue >> 24) & 0xFF); | 1227 data[index] = cast(byte)((pixelValue >> 24) & 0xFF); |
1228 data[index + 1] = (byte)((pixelValue >> 16) & 0xFF); | 1228 data[index + 1] = cast(byte)((pixelValue >> 16) & 0xFF); |
1229 data[index + 2] = (byte)((pixelValue >> 8) & 0xFF); | 1229 data[index + 2] = cast(byte)((pixelValue >> 8) & 0xFF); |
1230 data[index + 3] = (byte)(pixelValue & 0xFF); | 1230 data[index + 3] = cast(byte)(pixelValue & 0xFF); |
1231 return; | 1231 return; |
1232 case 24: | 1232 case 24: |
1233 index = (y * bytesPerLine) + (x * 3); | 1233 index = (y * bytesPerLine) + (x * 3); |
1234 data[index] = (byte)((pixelValue >> 16) & 0xFF); | 1234 data[index] = cast(byte)((pixelValue >> 16) & 0xFF); |
1235 data[index + 1] = (byte)((pixelValue >> 8) & 0xFF); | 1235 data[index + 1] = cast(byte)((pixelValue >> 8) & 0xFF); |
1236 data[index + 2] = (byte)(pixelValue & 0xFF); | 1236 data[index + 2] = cast(byte)(pixelValue & 0xFF); |
1237 return; | 1237 return; |
1238 case 16: | 1238 case 16: |
1239 index = (y * bytesPerLine) + (x * 2); | 1239 index = (y * bytesPerLine) + (x * 2); |
1240 data[index + 1] = (byte)((pixelValue >> 8) & 0xFF); | 1240 data[index + 1] = cast(byte)((pixelValue >> 8) & 0xFF); |
1241 data[index] = (byte)(pixelValue & 0xFF); | 1241 data[index] = cast(byte)(pixelValue & 0xFF); |
1242 return; | 1242 return; |
1243 case 8: | 1243 case 8: |
1244 index = (y * bytesPerLine) + x ; | 1244 index = (y * bytesPerLine) + x ; |
1245 data[index] = (byte)(pixelValue & 0xFF); | 1245 data[index] = cast(byte)(pixelValue & 0xFF); |
1246 return; | 1246 return; |
1247 case 4: | 1247 case 4: |
1248 index = (y * bytesPerLine) + (x >> 1); | 1248 index = (y * bytesPerLine) + (x >> 1); |
1249 if ((x & 0x1) is 0) { | 1249 if ((x & 0x1) is 0) { |
1250 data[index] = (byte)((data[index] & 0x0F) | ((pixelValue & 0x0F) << 4)); | 1250 data[index] = cast(byte)((data[index] & 0x0F) | ((pixelValue & 0x0F) << 4)); |
1251 } else { | 1251 } else { |
1252 data[index] = (byte)((data[index] & 0xF0) | (pixelValue & 0x0F)); | 1252 data[index] = cast(byte)((data[index] & 0xF0) | (pixelValue & 0x0F)); |
1253 } | 1253 } |
1254 return; | 1254 return; |
1255 case 2: | 1255 case 2: |
1256 index = (y * bytesPerLine) + (x >> 2); | 1256 index = (y * bytesPerLine) + (x >> 2); |
1257 theByte = data[index]; | 1257 theByte = data[index]; |
1258 int offset = 3 - (x % 4); | 1258 int offset = 3 - (x % 4); |
1259 mask = 0xFF ^ (3 << (offset * 2)); | 1259 mask = 0xFF ^ (3 << (offset * 2)); |
1260 data[index] = (byte)((data[index] & mask) | (pixelValue << (offset * 2))); | 1260 data[index] = cast(byte)((data[index] & mask) | (pixelValue << (offset * 2))); |
1261 return; | 1261 return; |
1262 case 1: | 1262 case 1: |
1263 index = (y * bytesPerLine) + (x >> 3); | 1263 index = (y * bytesPerLine) + (x >> 3); |
1264 theByte = data[index]; | 1264 theByte = data[index]; |
1265 mask = 1 << (7 - (x & 0x7)); | 1265 mask = 1 << (7 - (x & 0x7)); |
1266 if ((pixelValue & 0x1) is 1) { | 1266 if ((pixelValue & 0x1) is 1) { |
1267 data[index] = (byte)(theByte | mask); | 1267 data[index] = cast(byte)(theByte | mask); |
1268 } else { | 1268 } else { |
1269 data[index] = (byte)(theByte & (mask ^ -1)); | 1269 data[index] = cast(byte)(theByte & (mask ^ -1)); |
1270 } | 1270 } |
1271 return; | 1271 return; |
1272 } | 1272 } |
1273 DWT.error(DWT.ERROR_UNSUPPORTED_DEPTH); | 1273 DWT.error(DWT.ERROR_UNSUPPORTED_DEPTH); |
1274 } | 1274 } |
1308 int srcX = x, srcY = y; | 1308 int srcX = x, srcY = y; |
1309 switch (depth) { | 1309 switch (depth) { |
1310 case 8: | 1310 case 8: |
1311 index = (y * bytesPerLine) + x; | 1311 index = (y * bytesPerLine) + x; |
1312 for (int j = 0; j < putWidth; j++) { | 1312 for (int j = 0; j < putWidth; j++) { |
1313 data[index] = (byte)(pixels[i] & 0xFF); | 1313 data[index] = cast(byte)(pixels[i] & 0xFF); |
1314 i++; | 1314 i++; |
1315 srcX++; | 1315 srcX++; |
1316 if (srcX >= width) { | 1316 if (srcX >= width) { |
1317 srcY++; | 1317 srcY++; |
1318 index = srcY * bytesPerLine; | 1318 index = srcY * bytesPerLine; |
1326 index = (y * bytesPerLine) + (x >> 1); | 1326 index = (y * bytesPerLine) + (x >> 1); |
1327 bool high = (x & 0x1) is 0; | 1327 bool high = (x & 0x1) is 0; |
1328 while (n > 0) { | 1328 while (n > 0) { |
1329 theByte = pixels[i] & 0x0F; | 1329 theByte = pixels[i] & 0x0F; |
1330 if (high) { | 1330 if (high) { |
1331 data[index] = (byte)((data[index] & 0x0F) | (theByte << 4)); | 1331 data[index] = cast(byte)((data[index] & 0x0F) | (theByte << 4)); |
1332 } else { | 1332 } else { |
1333 data[index] = (byte)((data[index] & 0xF0) | theByte); | 1333 data[index] = cast(byte)((data[index] & 0xF0) | theByte); |
1334 } | 1334 } |
1335 i++; | 1335 i++; |
1336 n--; | 1336 n--; |
1337 srcX++; | 1337 srcX++; |
1338 if (srcX >= width) { | 1338 if (srcX >= width) { |
1345 high = !high; | 1345 high = !high; |
1346 } | 1346 } |
1347 } | 1347 } |
1348 return; | 1348 return; |
1349 case 2: | 1349 case 2: |
1350 byte [] masks = { (byte)0xFC, (byte)0xF3, (byte)0xCF, (byte)0x3F }; | 1350 byte [] masks = { cast(byte)0xFC, cast(byte)0xF3, cast(byte)0xCF, cast(byte)0x3F }; |
1351 index = (y * bytesPerLine) + (x >> 2); | 1351 index = (y * bytesPerLine) + (x >> 2); |
1352 int offset = 3 - (x % 4); | 1352 int offset = 3 - (x % 4); |
1353 while (n > 0) { | 1353 while (n > 0) { |
1354 theByte = pixels[i] & 0x3; | 1354 theByte = pixels[i] & 0x3; |
1355 data[index] = (byte)((data[index] & masks[offset]) | (theByte << (offset * 2))); | 1355 data[index] = cast(byte)((data[index] & masks[offset]) | (theByte << (offset * 2))); |
1356 i++; | 1356 i++; |
1357 n--; | 1357 n--; |
1358 srcX++; | 1358 srcX++; |
1359 if (srcX >= width) { | 1359 if (srcX >= width) { |
1360 srcY++; | 1360 srcY++; |
1374 case 1: | 1374 case 1: |
1375 index = (y * bytesPerLine) + (x >> 3); | 1375 index = (y * bytesPerLine) + (x >> 3); |
1376 while (n > 0) { | 1376 while (n > 0) { |
1377 mask = 1 << (7 - (srcX & 0x7)); | 1377 mask = 1 << (7 - (srcX & 0x7)); |
1378 if ((pixels[i] & 0x1) is 1) { | 1378 if ((pixels[i] & 0x1) is 1) { |
1379 data[index] = (byte)((data[index] & 0xFF) | mask); | 1379 data[index] = cast(byte)((data[index] & 0xFF) | mask); |
1380 } else { | 1380 } else { |
1381 data[index] = (byte)((data[index] & 0xFF) & (mask ^ -1)); | 1381 data[index] = cast(byte)((data[index] & 0xFF) & (mask ^ -1)); |
1382 } | 1382 } |
1383 i++; | 1383 i++; |
1384 n--; | 1384 n--; |
1385 srcX++; | 1385 srcX++; |
1386 if (srcX >= width) { | 1386 if (srcX >= width) { |
1434 switch (depth) { | 1434 switch (depth) { |
1435 case 32: | 1435 case 32: |
1436 index = (y * bytesPerLine) + (x * 4); | 1436 index = (y * bytesPerLine) + (x * 4); |
1437 for (int j = 0; j < putWidth; j++) { | 1437 for (int j = 0; j < putWidth; j++) { |
1438 pixel = pixels[i]; | 1438 pixel = pixels[i]; |
1439 data[index] = (byte)((pixel >> 24) & 0xFF); | 1439 data[index] = cast(byte)((pixel >> 24) & 0xFF); |
1440 data[index + 1] = (byte)((pixel >> 16) & 0xFF); | 1440 data[index + 1] = cast(byte)((pixel >> 16) & 0xFF); |
1441 data[index + 2] = (byte)((pixel >> 8) & 0xFF); | 1441 data[index + 2] = cast(byte)((pixel >> 8) & 0xFF); |
1442 data[index + 3] = (byte)(pixel & 0xFF); | 1442 data[index + 3] = cast(byte)(pixel & 0xFF); |
1443 i++; | 1443 i++; |
1444 srcX++; | 1444 srcX++; |
1445 if (srcX >= width) { | 1445 if (srcX >= width) { |
1446 srcY++; | 1446 srcY++; |
1447 index = srcY * bytesPerLine; | 1447 index = srcY * bytesPerLine; |
1453 return; | 1453 return; |
1454 case 24: | 1454 case 24: |
1455 index = (y * bytesPerLine) + (x * 3); | 1455 index = (y * bytesPerLine) + (x * 3); |
1456 for (int j = 0; j < putWidth; j++) { | 1456 for (int j = 0; j < putWidth; j++) { |
1457 pixel = pixels[i]; | 1457 pixel = pixels[i]; |
1458 data[index] = (byte)((pixel >> 16) & 0xFF); | 1458 data[index] = cast(byte)((pixel >> 16) & 0xFF); |
1459 data[index + 1] = (byte)((pixel >> 8) & 0xFF); | 1459 data[index + 1] = cast(byte)((pixel >> 8) & 0xFF); |
1460 data[index + 2] = (byte)(pixel & 0xFF); | 1460 data[index + 2] = cast(byte)(pixel & 0xFF); |
1461 i++; | 1461 i++; |
1462 srcX++; | 1462 srcX++; |
1463 if (srcX >= width) { | 1463 if (srcX >= width) { |
1464 srcY++; | 1464 srcY++; |
1465 index = srcY * bytesPerLine; | 1465 index = srcY * bytesPerLine; |
1471 return; | 1471 return; |
1472 case 16: | 1472 case 16: |
1473 index = (y * bytesPerLine) + (x * 2); | 1473 index = (y * bytesPerLine) + (x * 2); |
1474 for (int j = 0; j < putWidth; j++) { | 1474 for (int j = 0; j < putWidth; j++) { |
1475 pixel = pixels[i]; | 1475 pixel = pixels[i]; |
1476 data[index] = (byte)(pixel & 0xFF); | 1476 data[index] = cast(byte)(pixel & 0xFF); |
1477 data[index + 1] = (byte)((pixel >> 8) & 0xFF); | 1477 data[index + 1] = cast(byte)((pixel >> 8) & 0xFF); |
1478 i++; | 1478 i++; |
1479 srcX++; | 1479 srcX++; |
1480 if (srcX >= width) { | 1480 if (srcX >= width) { |
1481 srcY++; | 1481 srcY++; |
1482 index = srcY * bytesPerLine; | 1482 index = srcY * bytesPerLine; |
1487 } | 1487 } |
1488 return; | 1488 return; |
1489 case 8: | 1489 case 8: |
1490 index = (y * bytesPerLine) + x; | 1490 index = (y * bytesPerLine) + x; |
1491 for (int j = 0; j < putWidth; j++) { | 1491 for (int j = 0; j < putWidth; j++) { |
1492 data[index] = (byte)(pixels[i] & 0xFF); | 1492 data[index] = cast(byte)(pixels[i] & 0xFF); |
1493 i++; | 1493 i++; |
1494 srcX++; | 1494 srcX++; |
1495 if (srcX >= width) { | 1495 if (srcX >= width) { |
1496 srcY++; | 1496 srcY++; |
1497 index = srcY * bytesPerLine; | 1497 index = srcY * bytesPerLine; |
1505 index = (y * bytesPerLine) + (x >> 1); | 1505 index = (y * bytesPerLine) + (x >> 1); |
1506 bool high = (x & 0x1) is 0; | 1506 bool high = (x & 0x1) is 0; |
1507 while (n > 0) { | 1507 while (n > 0) { |
1508 theByte = pixels[i] & 0x0F; | 1508 theByte = pixels[i] & 0x0F; |
1509 if (high) { | 1509 if (high) { |
1510 data[index] = (byte)((data[index] & 0x0F) | (theByte << 4)); | 1510 data[index] = cast(byte)((data[index] & 0x0F) | (theByte << 4)); |
1511 } else { | 1511 } else { |
1512 data[index] = (byte)((data[index] & 0xF0) | theByte); | 1512 data[index] = cast(byte)((data[index] & 0xF0) | theByte); |
1513 } | 1513 } |
1514 i++; | 1514 i++; |
1515 n--; | 1515 n--; |
1516 srcX++; | 1516 srcX++; |
1517 if (srcX >= width) { | 1517 if (srcX >= width) { |
1524 high = !high; | 1524 high = !high; |
1525 } | 1525 } |
1526 } | 1526 } |
1527 return; | 1527 return; |
1528 case 2: | 1528 case 2: |
1529 byte [] masks = { (byte)0xFC, (byte)0xF3, (byte)0xCF, (byte)0x3F }; | 1529 byte [] masks = { cast(byte)0xFC, cast(byte)0xF3, cast(byte)0xCF, cast(byte)0x3F }; |
1530 index = (y * bytesPerLine) + (x >> 2); | 1530 index = (y * bytesPerLine) + (x >> 2); |
1531 int offset = 3 - (x % 4); | 1531 int offset = 3 - (x % 4); |
1532 while (n > 0) { | 1532 while (n > 0) { |
1533 theByte = pixels[i] & 0x3; | 1533 theByte = pixels[i] & 0x3; |
1534 data[index] = (byte)((data[index] & masks[offset]) | (theByte << (offset * 2))); | 1534 data[index] = cast(byte)((data[index] & masks[offset]) | (theByte << (offset * 2))); |
1535 i++; | 1535 i++; |
1536 n--; | 1536 n--; |
1537 srcX++; | 1537 srcX++; |
1538 if (srcX >= width) { | 1538 if (srcX >= width) { |
1539 srcY++; | 1539 srcY++; |
1553 case 1: | 1553 case 1: |
1554 index = (y * bytesPerLine) + (x >> 3); | 1554 index = (y * bytesPerLine) + (x >> 3); |
1555 while (n > 0) { | 1555 while (n > 0) { |
1556 mask = 1 << (7 - (srcX & 0x7)); | 1556 mask = 1 << (7 - (srcX & 0x7)); |
1557 if ((pixels[i] & 0x1) is 1) { | 1557 if ((pixels[i] & 0x1) is 1) { |
1558 data[index] = (byte)((data[index] & 0xFF) | mask); | 1558 data[index] = cast(byte)((data[index] & 0xFF) | mask); |
1559 } else { | 1559 } else { |
1560 data[index] = (byte)((data[index] & 0xFF) & (mask ^ -1)); | 1560 data[index] = cast(byte)((data[index] & 0xFF) & (mask ^ -1)); |
1561 } | 1561 } |
1562 i++; | 1562 i++; |
1563 n--; | 1563 n--; |
1564 srcX++; | 1564 srcX++; |
1565 if (srcX >= width) { | 1565 if (srcX >= width) { |
1774 // these should be supplied as params later | 1774 // these should be supplied as params later |
1775 final int srcAlphaMask = 0, destAlphaMask = 0; | 1775 final int srcAlphaMask = 0, destAlphaMask = 0; |
1776 | 1776 |
1777 /*** Prepare scaling data ***/ | 1777 /*** Prepare scaling data ***/ |
1778 final int dwm1 = destWidth - 1; | 1778 final int dwm1 = destWidth - 1; |
1779 final int sfxi = (dwm1 !is 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; | 1779 final int sfxi = (dwm1 !is 0) ? cast(int)(((cast(long)srcWidth << 16) - 1) / dwm1) : 0; |
1780 final int dhm1 = destHeight - 1; | 1780 final int dhm1 = destHeight - 1; |
1781 final int sfyi = (dhm1 !is 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; | 1781 final int sfyi = (dhm1 !is 0) ? cast(int)(((cast(long)srcHeight << 16) - 1) / dhm1) : 0; |
1782 | 1782 |
1783 /*** Prepare source-related data ***/ | 1783 /*** Prepare source-related data ***/ |
1784 final int sbpp, stype; | 1784 final int sbpp, stype; |
1785 switch (srcDepth) { | 1785 switch (srcDepth) { |
1786 case 8: | 1786 case 8: |
2105 (g >>> destGreenPreShift << destGreenShift) | | 2105 (g >>> destGreenPreShift << destGreenShift) | |
2106 (b >>> destBluePreShift << destBlueShift) | | 2106 (b >>> destBluePreShift << destBlueShift) | |
2107 (a >>> destAlphaPreShift << destAlphaShift); | 2107 (a >>> destAlphaPreShift << destAlphaShift); |
2108 switch (dtype) { | 2108 switch (dtype) { |
2109 case TYPE_GENERIC_8: { | 2109 case TYPE_GENERIC_8: { |
2110 destData[dp] = (byte) data; | 2110 destData[dp] = cast(byte) data; |
2111 } break; | 2111 } break; |
2112 case TYPE_GENERIC_16_MSB: { | 2112 case TYPE_GENERIC_16_MSB: { |
2113 destData[dp] = (byte) (data >>> 8); | 2113 destData[dp] = cast(byte) (data >>> 8); |
2114 destData[dp + 1] = (byte) (data & 0xff); | 2114 destData[dp + 1] = cast(byte) (data & 0xff); |
2115 } break; | 2115 } break; |
2116 case TYPE_GENERIC_16_LSB: { | 2116 case TYPE_GENERIC_16_LSB: { |
2117 destData[dp] = (byte) (data & 0xff); | 2117 destData[dp] = cast(byte) (data & 0xff); |
2118 destData[dp + 1] = (byte) (data >>> 8); | 2118 destData[dp + 1] = cast(byte) (data >>> 8); |
2119 } break; | 2119 } break; |
2120 case TYPE_GENERIC_24: { | 2120 case TYPE_GENERIC_24: { |
2121 destData[dp] = (byte) (data >>> 16); | 2121 destData[dp] = cast(byte) (data >>> 16); |
2122 destData[dp + 1] = (byte) (data >>> 8); | 2122 destData[dp + 1] = cast(byte) (data >>> 8); |
2123 destData[dp + 2] = (byte) (data & 0xff); | 2123 destData[dp + 2] = cast(byte) (data & 0xff); |
2124 } break; | 2124 } break; |
2125 case TYPE_GENERIC_32_MSB: { | 2125 case TYPE_GENERIC_32_MSB: { |
2126 destData[dp] = (byte) (data >>> 24); | 2126 destData[dp] = cast(byte) (data >>> 24); |
2127 destData[dp + 1] = (byte) (data >>> 16); | 2127 destData[dp + 1] = cast(byte) (data >>> 16); |
2128 destData[dp + 2] = (byte) (data >>> 8); | 2128 destData[dp + 2] = cast(byte) (data >>> 8); |
2129 destData[dp + 3] = (byte) (data & 0xff); | 2129 destData[dp + 3] = cast(byte) (data & 0xff); |
2130 } break; | 2130 } break; |
2131 case TYPE_GENERIC_32_LSB: { | 2131 case TYPE_GENERIC_32_LSB: { |
2132 destData[dp] = (byte) (data & 0xff); | 2132 destData[dp] = cast(byte) (data & 0xff); |
2133 destData[dp + 1] = (byte) (data >>> 8); | 2133 destData[dp + 1] = cast(byte) (data >>> 8); |
2134 destData[dp + 2] = (byte) (data >>> 16); | 2134 destData[dp + 2] = cast(byte) (data >>> 16); |
2135 destData[dp + 3] = (byte) (data >>> 24); | 2135 destData[dp + 3] = cast(byte) (data >>> 24); |
2136 } break; | 2136 } break; |
2137 } | 2137 } |
2138 } | 2138 } |
2139 } | 2139 } |
2140 } | 2140 } |
2196 bool flipX, bool flipY) { | 2196 bool flipX, bool flipY) { |
2197 if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode is ALPHA_TRANSPARENT)) return; | 2197 if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode is ALPHA_TRANSPARENT)) return; |
2198 | 2198 |
2199 /*** Prepare scaling data ***/ | 2199 /*** Prepare scaling data ***/ |
2200 final int dwm1 = destWidth - 1; | 2200 final int dwm1 = destWidth - 1; |
2201 final int sfxi = (dwm1 !is 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; | 2201 final int sfxi = (dwm1 !is 0) ? cast(int)(((cast(long)srcWidth << 16) - 1) / dwm1) : 0; |
2202 final int dhm1 = destHeight - 1; | 2202 final int dhm1 = destHeight - 1; |
2203 final int sfyi = (dhm1 !is 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; | 2203 final int sfyi = (dhm1 !is 0) ? cast(int)(((cast(long)srcHeight << 16) - 1) / dhm1) : 0; |
2204 | 2204 |
2205 /*** Prepare source-related data ***/ | 2205 /*** Prepare source-related data ***/ |
2206 final int stype; | 2206 final int stype; |
2207 switch (srcDepth) { | 2207 switch (srcDepth) { |
2208 case 8: | 2208 case 8: |
2303 if (srcDepth <= destDepth) { | 2303 if (srcDepth <= destDepth) { |
2304 paletteMapping = ONE_TO_ONE_MAPPING; | 2304 paletteMapping = ONE_TO_ONE_MAPPING; |
2305 } else { | 2305 } else { |
2306 paletteMapping = new byte[1 << srcDepth]; | 2306 paletteMapping = new byte[1 << srcDepth]; |
2307 int mask = (0xff << destDepth) >>> 8; | 2307 int mask = (0xff << destDepth) >>> 8; |
2308 for (int i = 0; i < paletteMapping.length; ++i) paletteMapping[i] = (byte)(i & mask); | 2308 for (int i = 0; i < paletteMapping.length; ++i) paletteMapping[i] = cast(byte)(i & mask); |
2309 } | 2309 } |
2310 break; | 2310 break; |
2311 } | 2311 } |
2312 case ALPHA_MASK_UNPACKED: | 2312 case ALPHA_MASK_UNPACKED: |
2313 case ALPHA_MASK_PACKED: | 2313 case ALPHA_MASK_PACKED: |
2332 index = j; | 2332 index = j; |
2333 if (distance is 0) break; | 2333 if (distance is 0) break; |
2334 minDistance = distance; | 2334 minDistance = distance; |
2335 } | 2335 } |
2336 } | 2336 } |
2337 paletteMapping[i] = (byte)index; | 2337 paletteMapping[i] = cast(byte)index; |
2338 if (minDistance !is 0) isExactPaletteMapping = false; | 2338 if (minDistance !is 0) isExactPaletteMapping = false; |
2339 } | 2339 } |
2340 break; | 2340 break; |
2341 } | 2341 } |
2342 if ((paletteMapping !is null) && (isExactPaletteMapping || ! ditherEnabled)) { | 2342 if ((paletteMapping !is null) && (isExactPaletteMapping || ! ditherEnabled)) { |
2356 for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { | 2356 for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { |
2357 final int v; | 2357 final int v; |
2358 if ((sp & 1) !is 0) v = paletteMapping[srcData[sp >> 1] & 0x0f]; | 2358 if ((sp & 1) !is 0) v = paletteMapping[srcData[sp >> 1] & 0x0f]; |
2359 else v = (srcData[sp >> 1] >>> 4) & 0x0f; | 2359 else v = (srcData[sp >> 1] >>> 4) & 0x0f; |
2360 sp += (sfx >>> 16); | 2360 sp += (sfx >>> 16); |
2361 if ((dp & 1) !is 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | v); | 2361 if ((dp & 1) !is 0) destData[dp >> 1] = cast(byte)((destData[dp >> 1] & 0xf0) | v); |
2362 else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (v << 4)); | 2362 else destData[dp >> 1] = cast(byte)((destData[dp >> 1] & 0x0f) | (v << 4)); |
2363 } | 2363 } |
2364 } | 2364 } |
2365 break; | 2365 break; |
2366 case TYPE_INDEX_2: | 2366 case TYPE_INDEX_2: |
2367 for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { | 2367 for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { |
2368 for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { | 2368 for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { |
2369 final int index = paletteMapping[(srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03]; | 2369 final int index = paletteMapping[(srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03]; |
2370 sp += (sfx >>> 16); | 2370 sp += (sfx >>> 16); |
2371 final int shift = 6 - (dp & 3) * 2; | 2371 final int shift = 6 - (dp & 3) * 2; |
2372 destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (index << shift)); | 2372 destData[dp >> 2] = cast(byte)(destData[dp >> 2] & ~(0x03 << shift) | (index << shift)); |
2373 } | 2373 } |
2374 } | 2374 } |
2375 break; | 2375 break; |
2376 case TYPE_INDEX_1_MSB: | 2376 case TYPE_INDEX_1_MSB: |
2377 for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { | 2377 for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { |
2378 for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { | 2378 for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { |
2379 final int index = paletteMapping[(srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01]; | 2379 final int index = paletteMapping[(srcData[sp >> 3] >>> (7 - (sp & 7))) & 0x01]; |
2380 sp += (sfx >>> 16); | 2380 sp += (sfx >>> 16); |
2381 final int shift = 7 - (dp & 7); | 2381 final int shift = 7 - (dp & 7); |
2382 destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); | 2382 destData[dp >> 3] = cast(byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); |
2383 } | 2383 } |
2384 } | 2384 } |
2385 break; | 2385 break; |
2386 case TYPE_INDEX_1_LSB: | 2386 case TYPE_INDEX_1_LSB: |
2387 for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { | 2387 for (int dy = destHeight, sfy = sfyi; dy > 0; --dy, sp = spr += (sfy >>> 16) * srcStride, sfy = (sfy & 0xffff) + sfyi, dp = dpr += dpryi) { |
2388 for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { | 2388 for (int dx = destWidth, sfx = sfxi; dx > 0; --dx, dp += dprxi, sfx = (sfx & 0xffff) + sfxi) { |
2389 final int index = paletteMapping[(srcData[sp >> 3] >>> (sp & 7)) & 0x01]; | 2389 final int index = paletteMapping[(srcData[sp >> 3] >>> (sp & 7)) & 0x01]; |
2390 sp += (sfx >>> 16); | 2390 sp += (sfx >>> 16); |
2391 final int shift = dp & 7; | 2391 final int shift = dp & 7; |
2392 destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); | 2392 destData[dp >> 3] = cast(byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); |
2393 } | 2393 } |
2394 } | 2394 } |
2395 break; | 2395 break; |
2396 } | 2396 } |
2397 } else { | 2397 } else { |
2462 index = paletteMapping[index] & 0xff; | 2462 index = paletteMapping[index] & 0xff; |
2463 | 2463 |
2464 /*** WRITE NEXT PIXEL ***/ | 2464 /*** WRITE NEXT PIXEL ***/ |
2465 switch (dtype) { | 2465 switch (dtype) { |
2466 case TYPE_INDEX_8: | 2466 case TYPE_INDEX_8: |
2467 destData[dp] = (byte) index; | 2467 destData[dp] = cast(byte) index; |
2468 break; | 2468 break; |
2469 case TYPE_INDEX_4: | 2469 case TYPE_INDEX_4: |
2470 if ((dp & 1) !is 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | index); | 2470 if ((dp & 1) !is 0) destData[dp >> 1] = cast(byte)((destData[dp >> 1] & 0xf0) | index); |
2471 else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (index << 4)); | 2471 else destData[dp >> 1] = cast(byte)((destData[dp >> 1] & 0x0f) | (index << 4)); |
2472 break; | 2472 break; |
2473 case TYPE_INDEX_2: { | 2473 case TYPE_INDEX_2: { |
2474 final int shift = 6 - (dp & 3) * 2; | 2474 final int shift = 6 - (dp & 3) * 2; |
2475 destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (index << shift)); | 2475 destData[dp >> 2] = cast(byte)(destData[dp >> 2] & ~(0x03 << shift) | (index << shift)); |
2476 } break; | 2476 } break; |
2477 case TYPE_INDEX_1_MSB: { | 2477 case TYPE_INDEX_1_MSB: { |
2478 final int shift = 7 - (dp & 7); | 2478 final int shift = 7 - (dp & 7); |
2479 destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); | 2479 destData[dp >> 3] = cast(byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); |
2480 } break; | 2480 } break; |
2481 case TYPE_INDEX_1_LSB: { | 2481 case TYPE_INDEX_1_LSB: { |
2482 final int shift = dp & 7; | 2482 final int shift = dp & 7; |
2483 destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); | 2483 destData[dp >> 3] = cast(byte)(destData[dp >> 3] & ~(0x01 << shift) | (index << shift)); |
2484 } break; | 2484 } break; |
2485 } | 2485 } |
2486 } | 2486 } |
2487 } | 2487 } |
2488 } | 2488 } |
2642 } | 2642 } |
2643 | 2643 |
2644 /*** WRITE NEXT PIXEL ***/ | 2644 /*** WRITE NEXT PIXEL ***/ |
2645 switch (dtype) { | 2645 switch (dtype) { |
2646 case TYPE_INDEX_8: | 2646 case TYPE_INDEX_8: |
2647 destData[dp] = (byte) lastindex; | 2647 destData[dp] = cast(byte) lastindex; |
2648 break; | 2648 break; |
2649 case TYPE_INDEX_4: | 2649 case TYPE_INDEX_4: |
2650 if ((dp & 1) !is 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | lastindex); | 2650 if ((dp & 1) !is 0) destData[dp >> 1] = cast(byte)((destData[dp >> 1] & 0xf0) | lastindex); |
2651 else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (lastindex << 4)); | 2651 else destData[dp >> 1] = cast(byte)((destData[dp >> 1] & 0x0f) | (lastindex << 4)); |
2652 break; | 2652 break; |
2653 case TYPE_INDEX_2: { | 2653 case TYPE_INDEX_2: { |
2654 final int shift = 6 - (dp & 3) * 2; | 2654 final int shift = 6 - (dp & 3) * 2; |
2655 destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (lastindex << shift)); | 2655 destData[dp >> 2] = cast(byte)(destData[dp >> 2] & ~(0x03 << shift) | (lastindex << shift)); |
2656 } break; | 2656 } break; |
2657 case TYPE_INDEX_1_MSB: { | 2657 case TYPE_INDEX_1_MSB: { |
2658 final int shift = 7 - (dp & 7); | 2658 final int shift = 7 - (dp & 7); |
2659 destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); | 2659 destData[dp >> 3] = cast(byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); |
2660 } break; | 2660 } break; |
2661 case TYPE_INDEX_1_LSB: { | 2661 case TYPE_INDEX_1_LSB: { |
2662 final int shift = dp & 7; | 2662 final int shift = dp & 7; |
2663 destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); | 2663 destData[dp >> 3] = cast(byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); |
2664 } break; | 2664 } break; |
2665 } | 2665 } |
2666 } | 2666 } |
2667 } | 2667 } |
2668 } | 2668 } |
2726 // these should be supplied as params later | 2726 // these should be supplied as params later |
2727 final int destAlphaMask = 0; | 2727 final int destAlphaMask = 0; |
2728 | 2728 |
2729 /*** Prepare scaling data ***/ | 2729 /*** Prepare scaling data ***/ |
2730 final int dwm1 = destWidth - 1; | 2730 final int dwm1 = destWidth - 1; |
2731 final int sfxi = (dwm1 !is 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; | 2731 final int sfxi = (dwm1 !is 0) ? cast(int)(((cast(long)srcWidth << 16) - 1) / dwm1) : 0; |
2732 final int dhm1 = destHeight - 1; | 2732 final int dhm1 = destHeight - 1; |
2733 final int sfyi = (dhm1 !is 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; | 2733 final int sfyi = (dhm1 !is 0) ? cast(int)(((cast(long)srcHeight << 16) - 1) / dhm1) : 0; |
2734 | 2734 |
2735 /*** Prepare source-related data ***/ | 2735 /*** Prepare source-related data ***/ |
2736 final int stype; | 2736 final int stype; |
2737 switch (srcDepth) { | 2737 switch (srcDepth) { |
2738 case 8: | 2738 case 8: |
2971 (g >>> destGreenPreShift << destGreenShift) | | 2971 (g >>> destGreenPreShift << destGreenShift) | |
2972 (b >>> destBluePreShift << destBlueShift) | | 2972 (b >>> destBluePreShift << destBlueShift) | |
2973 (a >>> destAlphaPreShift << destAlphaShift); | 2973 (a >>> destAlphaPreShift << destAlphaShift); |
2974 switch (dtype) { | 2974 switch (dtype) { |
2975 case TYPE_GENERIC_8: { | 2975 case TYPE_GENERIC_8: { |
2976 destData[dp] = (byte) data; | 2976 destData[dp] = cast(byte) data; |
2977 } break; | 2977 } break; |
2978 case TYPE_GENERIC_16_MSB: { | 2978 case TYPE_GENERIC_16_MSB: { |
2979 destData[dp] = (byte) (data >>> 8); | 2979 destData[dp] = cast(byte) (data >>> 8); |
2980 destData[dp + 1] = (byte) (data & 0xff); | 2980 destData[dp + 1] = cast(byte) (data & 0xff); |
2981 } break; | 2981 } break; |
2982 case TYPE_GENERIC_16_LSB: { | 2982 case TYPE_GENERIC_16_LSB: { |
2983 destData[dp] = (byte) (data & 0xff); | 2983 destData[dp] = cast(byte) (data & 0xff); |
2984 destData[dp + 1] = (byte) (data >>> 8); | 2984 destData[dp + 1] = cast(byte) (data >>> 8); |
2985 } break; | 2985 } break; |
2986 case TYPE_GENERIC_24: { | 2986 case TYPE_GENERIC_24: { |
2987 destData[dp] = (byte) (data >>> 16); | 2987 destData[dp] = cast(byte) (data >>> 16); |
2988 destData[dp + 1] = (byte) (data >>> 8); | 2988 destData[dp + 1] = cast(byte) (data >>> 8); |
2989 destData[dp + 2] = (byte) (data & 0xff); | 2989 destData[dp + 2] = cast(byte) (data & 0xff); |
2990 } break; | 2990 } break; |
2991 case TYPE_GENERIC_32_MSB: { | 2991 case TYPE_GENERIC_32_MSB: { |
2992 destData[dp] = (byte) (data >>> 24); | 2992 destData[dp] = cast(byte) (data >>> 24); |
2993 destData[dp + 1] = (byte) (data >>> 16); | 2993 destData[dp + 1] = cast(byte) (data >>> 16); |
2994 destData[dp + 2] = (byte) (data >>> 8); | 2994 destData[dp + 2] = cast(byte) (data >>> 8); |
2995 destData[dp + 3] = (byte) (data & 0xff); | 2995 destData[dp + 3] = cast(byte) (data & 0xff); |
2996 } break; | 2996 } break; |
2997 case TYPE_GENERIC_32_LSB: { | 2997 case TYPE_GENERIC_32_LSB: { |
2998 destData[dp] = (byte) (data & 0xff); | 2998 destData[dp] = cast(byte) (data & 0xff); |
2999 destData[dp + 1] = (byte) (data >>> 8); | 2999 destData[dp + 1] = cast(byte) (data >>> 8); |
3000 destData[dp + 2] = (byte) (data >>> 16); | 3000 destData[dp + 2] = cast(byte) (data >>> 16); |
3001 destData[dp + 3] = (byte) (data >>> 24); | 3001 destData[dp + 3] = cast(byte) (data >>> 24); |
3002 } break; | 3002 } break; |
3003 } | 3003 } |
3004 } | 3004 } |
3005 } | 3005 } |
3006 } | 3006 } |
3064 // these should be supplied as params later | 3064 // these should be supplied as params later |
3065 final int srcAlphaMask = 0; | 3065 final int srcAlphaMask = 0; |
3066 | 3066 |
3067 /*** Prepare scaling data ***/ | 3067 /*** Prepare scaling data ***/ |
3068 final int dwm1 = destWidth - 1; | 3068 final int dwm1 = destWidth - 1; |
3069 final int sfxi = (dwm1 !is 0) ? (int)((((long)srcWidth << 16) - 1) / dwm1) : 0; | 3069 final int sfxi = (dwm1 !is 0) ? cast(int)(((cast(long)srcWidth << 16) - 1) / dwm1) : 0; |
3070 final int dhm1 = destHeight - 1; | 3070 final int dhm1 = destHeight - 1; |
3071 final int sfyi = (dhm1 !is 0) ? (int)((((long)srcHeight << 16) - 1) / dhm1) : 0; | 3071 final int sfyi = (dhm1 !is 0) ? cast(int)(((cast(long)srcHeight << 16) - 1) / dhm1) : 0; |
3072 | 3072 |
3073 /*** Prepare source-related data ***/ | 3073 /*** Prepare source-related data ***/ |
3074 final int sbpp, stype; | 3074 final int sbpp, stype; |
3075 switch (srcDepth) { | 3075 switch (srcDepth) { |
3076 case 8: | 3076 case 8: |
3349 } | 3349 } |
3350 | 3350 |
3351 /*** WRITE NEXT PIXEL ***/ | 3351 /*** WRITE NEXT PIXEL ***/ |
3352 switch (dtype) { | 3352 switch (dtype) { |
3353 case TYPE_INDEX_8: | 3353 case TYPE_INDEX_8: |
3354 destData[dp] = (byte) lastindex; | 3354 destData[dp] = cast(byte) lastindex; |
3355 break; | 3355 break; |
3356 case TYPE_INDEX_4: | 3356 case TYPE_INDEX_4: |
3357 if ((dp & 1) !is 0) destData[dp >> 1] = (byte)((destData[dp >> 1] & 0xf0) | lastindex); | 3357 if ((dp & 1) !is 0) destData[dp >> 1] = cast(byte)((destData[dp >> 1] & 0xf0) | lastindex); |
3358 else destData[dp >> 1] = (byte)((destData[dp >> 1] & 0x0f) | (lastindex << 4)); | 3358 else destData[dp >> 1] = cast(byte)((destData[dp >> 1] & 0x0f) | (lastindex << 4)); |
3359 break; | 3359 break; |
3360 case TYPE_INDEX_2: { | 3360 case TYPE_INDEX_2: { |
3361 final int shift = 6 - (dp & 3) * 2; | 3361 final int shift = 6 - (dp & 3) * 2; |
3362 destData[dp >> 2] = (byte)(destData[dp >> 2] & ~(0x03 << shift) | (lastindex << shift)); | 3362 destData[dp >> 2] = cast(byte)(destData[dp >> 2] & ~(0x03 << shift) | (lastindex << shift)); |
3363 } break; | 3363 } break; |
3364 case TYPE_INDEX_1_MSB: { | 3364 case TYPE_INDEX_1_MSB: { |
3365 final int shift = 7 - (dp & 7); | 3365 final int shift = 7 - (dp & 7); |
3366 destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); | 3366 destData[dp >> 3] = cast(byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); |
3367 } break; | 3367 } break; |
3368 case TYPE_INDEX_1_LSB: { | 3368 case TYPE_INDEX_1_LSB: { |
3369 final int shift = dp & 7; | 3369 final int shift = dp & 7; |
3370 destData[dp >> 3] = (byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); | 3370 destData[dp >> 3] = cast(byte)(destData[dp >> 3] & ~(0x01 << shift) | (lastindex << shift)); |
3371 } break; | 3371 } break; |
3372 } | 3372 } |
3373 } | 3373 } |
3374 } | 3374 } |
3375 } | 3375 } |
3489 if (vertical) { | 3489 if (vertical) { |
3490 for (int dy = 0, blend = 0, dp = 0; dy < bandHeight; | 3490 for (int dy = 0, blend = 0, dp = 0; dy < bandHeight; |
3491 ++dy, blend += blendi, dp += bytesPerLine) { | 3491 ++dy, blend += blendi, dp += bytesPerLine) { |
3492 for (int dx = 0; dx < bandWidth; ++dx) { | 3492 for (int dx = 0; dx < bandWidth; ++dx) { |
3493 bitmapData[dp + dx] = (blend + DITHER_MATRIX[dy & 7][dx]) < | 3493 bitmapData[dp + dx] = (blend + DITHER_MATRIX[dy & 7][dx]) < |
3494 0x1000000 ? (byte)0 : (byte)1; | 3494 0x1000000 ? cast(byte)0 : cast(byte)1; |
3495 } | 3495 } |
3496 } | 3496 } |
3497 } else { | 3497 } else { |
3498 for (int dx = 0, blend = 0; dx < bandWidth; ++dx, blend += blendi) { | 3498 for (int dx = 0, blend = 0; dx < bandWidth; ++dx, blend += blendi) { |
3499 for (int dy = 0, dptr = dx; dy < bandHeight; ++dy, dptr += bytesPerLine) { | 3499 for (int dy = 0, dptr = dx; dy < bandHeight; ++dy, dptr += bytesPerLine) { |
3500 bitmapData[dptr] = (blend + DITHER_MATRIX[dy][dx & 7]) < | 3500 bitmapData[dptr] = (blend + DITHER_MATRIX[dy][dx & 7]) < |
3501 0x1000000 ? (byte)0 : (byte)1; | 3501 0x1000000 ? cast(byte)0 : cast(byte)1; |
3502 } | 3502 } |
3503 } | 3503 } |
3504 } | 3504 } |
3505 } | 3505 } |
3506 return new ImageData(bandWidth, bandHeight, bitmapDepth, paletteData, 4, bitmapData); | 3506 return new ImageData(bandWidth, bandHeight, bitmapDepth, paletteData, 4, bitmapData); |
3514 byte[] bitmapData, int dp, int bytesPerLine) { | 3514 byte[] bitmapData, int dp, int bytesPerLine) { |
3515 int val = from << 16; | 3515 int val = from << 16; |
3516 final int inc = ((to << 16) - val) / steps + 1; | 3516 final int inc = ((to << 16) - val) / steps + 1; |
3517 if (vertical) { | 3517 if (vertical) { |
3518 for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) { | 3518 for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) { |
3519 bitmapData[dp] = (byte)(val >>> 16); | 3519 bitmapData[dp] = cast(byte)(val >>> 16); |
3520 val += inc; | 3520 val += inc; |
3521 } | 3521 } |
3522 } else { | 3522 } else { |
3523 for (int dx = 0; dx < bandWidth; ++dx, dp += 4) { | 3523 for (int dx = 0; dx < bandWidth; ++dx, dp += 4) { |
3524 bitmapData[dp] = (byte)(val >>> 16); | 3524 bitmapData[dp] = cast(byte)(val >>> 16); |
3525 val += inc; | 3525 val += inc; |
3526 } | 3526 } |
3527 } | 3527 } |
3528 } | 3528 } |
3529 | 3529 |
3540 for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) { | 3540 for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) { |
3541 for (int dx = 0, dptr = dp; dx < bandWidth; ++dx, dptr += 4) { | 3541 for (int dx = 0, dptr = dp; dx < bandWidth; ++dx, dptr += 4) { |
3542 final int thresh = DITHER_MATRIX[dy & 7][dx] >>> bits; | 3542 final int thresh = DITHER_MATRIX[dy & 7][dx] >>> bits; |
3543 int temp = val + thresh; | 3543 int temp = val + thresh; |
3544 if (temp > 0xffffff) bitmapData[dptr] = -1; | 3544 if (temp > 0xffffff) bitmapData[dptr] = -1; |
3545 else bitmapData[dptr] = (byte)((temp >>> 16) & mask); | 3545 else bitmapData[dptr] = cast(byte)((temp >>> 16) & mask); |
3546 } | 3546 } |
3547 val += inc; | 3547 val += inc; |
3548 } | 3548 } |
3549 } else { | 3549 } else { |
3550 for (int dx = 0; dx < bandWidth; ++dx, dp += 4) { | 3550 for (int dx = 0; dx < bandWidth; ++dx, dp += 4) { |
3551 for (int dy = 0, dptr = dp; dy < bandHeight; ++dy, dptr += bytesPerLine) { | 3551 for (int dy = 0, dptr = dp; dy < bandHeight; ++dy, dptr += bytesPerLine) { |
3552 final int thresh = DITHER_MATRIX[dy][dx & 7] >>> bits; | 3552 final int thresh = DITHER_MATRIX[dy][dx & 7] >>> bits; |
3553 int temp = val + thresh; | 3553 int temp = val + thresh; |
3554 if (temp > 0xffffff) bitmapData[dptr] = -1; | 3554 if (temp > 0xffffff) bitmapData[dptr] = -1; |
3555 else bitmapData[dptr] = (byte)((temp >>> 16) & mask); | 3555 else bitmapData[dptr] = cast(byte)((temp >>> 16) & mask); |
3556 } | 3556 } |
3557 val += inc; | 3557 val += inc; |
3558 } | 3558 } |
3559 } | 3559 } |
3560 } | 3560 } |