Mercurial > projects > dwt-mac
comparison dwt/internal/image/JPEGFileFormat.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 380af2bdd8e5 |
children | 5123b17c98ef |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
240 int srcIndex = (yPos * maxV + iv) * srcWidth + (xPos * maxH); | 240 int srcIndex = (yPos * maxV + iv) * srcWidth + (xPos * maxH); |
241 for (int ih = 0; ih < maxH; ih++) { | 241 for (int ih = 0; ih < maxH; ih++) { |
242 sum += dataCbComp[srcIndex + ih] & 0xFF; | 242 sum += dataCbComp[srcIndex + ih] & 0xFF; |
243 } | 243 } |
244 } | 244 } |
245 imageComponents[ID_CB][destRowIndex + xPos] = (byte)(sum / vhFactor); | 245 imageComponents[ID_CB][destRowIndex + xPos] = cast(byte)(sum / vhFactor); |
246 } | 246 } |
247 } | 247 } |
248 frameComponent = frameComponents[componentIds[ID_CR]]; | 248 frameComponent = frameComponents[componentIds[ID_CR]]; |
249 for (int yPos = 0; yPos < srcHeight / maxV; yPos++) { | 249 for (int yPos = 0; yPos < srcHeight / maxV; yPos++) { |
250 int destRowIndex = yPos * frameComponent[CW]; | 250 int destRowIndex = yPos * frameComponent[CW]; |
254 int srcIndex = (yPos * maxV + iv) * srcWidth + (xPos * maxH); | 254 int srcIndex = (yPos * maxV + iv) * srcWidth + (xPos * maxH); |
255 for (int ih = 0; ih < maxH; ih++) { | 255 for (int ih = 0; ih < maxH; ih++) { |
256 sum += dataCrComp[srcIndex + ih] & 0xFF; | 256 sum += dataCrComp[srcIndex + ih] & 0xFF; |
257 } | 257 } |
258 } | 258 } |
259 imageComponents[ID_CR][destRowIndex + xPos] = (byte)(sum / vhFactor); | 259 imageComponents[ID_CR][destRowIndex + xPos] = cast(byte)(sum / vhFactor); |
260 } | 260 } |
261 } | 261 } |
262 for (int iComp = 0; iComp < nComponents; iComp++) { | 262 for (int iComp = 0; iComp < nComponents; iComp++) { |
263 byte[] imageComponent = imageComponents[iComp]; | 263 byte[] imageComponent = imageComponents[iComp]; |
264 frameComponent = frameComponents[componentIds[iComp]]; | 264 frameComponent = frameComponents[componentIds[iComp]]; |
272 int delta = componentWidth - compressedWidth; | 272 int delta = componentWidth - compressedWidth; |
273 for (int yPos = 0; yPos < compressedHeight; yPos++) { | 273 for (int yPos = 0; yPos < compressedHeight; yPos++) { |
274 int dstOfs = ((yPos + 1) * componentWidth - delta); | 274 int dstOfs = ((yPos + 1) * componentWidth - delta); |
275 int dataValue = imageComponent[(dstOfs > 0) ? dstOfs - 1 : 0] & 0xFF; | 275 int dataValue = imageComponent[(dstOfs > 0) ? dstOfs - 1 : 0] & 0xFF; |
276 for (int i = 0; i < delta; i++) { | 276 for (int i = 0; i < delta; i++) { |
277 imageComponent[dstOfs + i] = (byte)dataValue; | 277 imageComponent[dstOfs + i] = cast(byte)dataValue; |
278 } | 278 } |
279 } | 279 } |
280 } | 280 } |
281 if (compressedHeight < componentHeight) { | 281 if (compressedHeight < componentHeight) { |
282 int srcOfs = (compressedHeight > 0) ? (compressedHeight - 1) * componentWidth : 1; | 282 int srcOfs = (compressedHeight > 0) ? (compressedHeight - 1) * componentWidth : 1; |
299 RGB color = rgbs[i]; | 299 RGB color = rgbs[i]; |
300 int r = color.red; | 300 int r = color.red; |
301 int g = color.green; | 301 int g = color.green; |
302 int b = color.blue; | 302 int b = color.blue; |
303 int n = RYTable[r] + GYTable[g] + BYTable[b]; | 303 int n = RYTable[r] + GYTable[g] + BYTable[b]; |
304 yComp[i] = (byte)(n >> 16); | 304 yComp[i] = cast(byte)(n >> 16); |
305 if ((n < 0) && ((n & 0xFFFF) !is 0)) yComp[i]--; | 305 if ((n < 0) && ((n & 0xFFFF) !is 0)) yComp[i]--; |
306 n = RCbTable[r] + GCbTable[g] + BCbTable[b]; | 306 n = RCbTable[r] + GCbTable[g] + BCbTable[b]; |
307 cbComp[i] = (byte)(n >> 16); | 307 cbComp[i] = cast(byte)(n >> 16); |
308 if ((n < 0) && ((n & 0xFFFF) !is 0)) cbComp[i]--; | 308 if ((n < 0) && ((n & 0xFFFF) !is 0)) cbComp[i]--; |
309 n = RCrTable[r] + GCrTable[g] + BCrTable[b]; | 309 n = RCrTable[r] + GCrTable[g] + BCrTable[b]; |
310 crComp[i] = (byte)(n >> 16); | 310 crComp[i] = cast(byte)(n >> 16); |
311 if ((n < 0) && ((n & 0xFFFF) !is 0)) crComp[i]--; | 311 if ((n < 0) && ((n & 0xFFFF) !is 0)) crComp[i]--; |
312 } | 312 } |
313 int bSize = srcWidth * srcHeight; | 313 int bSize = srcWidth * srcHeight; |
314 byte[] dataYComp = new byte[bSize]; | 314 byte[] dataYComp = new byte[bSize]; |
315 byte[] dataCbComp = new byte[bSize]; | 315 byte[] dataCbComp = new byte[bSize]; |
346 RGB color = rgbs[i]; | 346 RGB color = rgbs[i]; |
347 int r = color.red; | 347 int r = color.red; |
348 int g = color.green; | 348 int g = color.green; |
349 int b = color.blue; | 349 int b = color.blue; |
350 int n = RYTable[r] + GYTable[g] + BYTable[b]; | 350 int n = RYTable[r] + GYTable[g] + BYTable[b]; |
351 yComp[i] = (byte)(n >> 16); | 351 yComp[i] = cast(byte)(n >> 16); |
352 if ((n < 0) && ((n & 0xFFFF) !is 0)) yComp[i]--; | 352 if ((n < 0) && ((n & 0xFFFF) !is 0)) yComp[i]--; |
353 n = RCbTable[r] + GCbTable[g] + BCbTable[b]; | 353 n = RCbTable[r] + GCbTable[g] + BCbTable[b]; |
354 cbComp[i] = (byte)(n >> 16); | 354 cbComp[i] = cast(byte)(n >> 16); |
355 if ((n < 0) && ((n & 0xFFFF) !is 0)) cbComp[i]--; | 355 if ((n < 0) && ((n & 0xFFFF) !is 0)) cbComp[i]--; |
356 n = RCrTable[r] + GCrTable[g] + BCrTable[b]; | 356 n = RCrTable[r] + GCrTable[g] + BCrTable[b]; |
357 crComp[i] = (byte)(n >> 16); | 357 crComp[i] = cast(byte)(n >> 16); |
358 if ((n < 0) && ((n & 0xFFFF) !is 0)) crComp[i]--; | 358 if ((n < 0) && ((n & 0xFFFF) !is 0)) crComp[i]--; |
359 } | 359 } |
360 int dstWidth = image.width; | 360 int dstWidth = image.width; |
361 int dstHeight = srcHeight; | 361 int dstHeight = srcHeight; |
362 int stride = ((srcWidth + 3) >> 2) << 2; | 362 int stride = ((srcWidth + 3) >> 2) << 2; |
426 r = (redShift < 0) ? r >>> -redShift : r << redShift; | 426 r = (redShift < 0) ? r >>> -redShift : r << redShift; |
427 int g = pixel & greenMask; | 427 int g = pixel & greenMask; |
428 g = (greenShift < 0) ? g >>> -greenShift : g << greenShift; | 428 g = (greenShift < 0) ? g >>> -greenShift : g << greenShift; |
429 int b = pixel & blueMask; | 429 int b = pixel & blueMask; |
430 b = (blueShift < 0) ? b >>> -blueShift : b << blueShift; | 430 b = (blueShift < 0) ? b >>> -blueShift : b << blueShift; |
431 dataYComp[dstDataIndex] = (byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16); | 431 dataYComp[dstDataIndex] = cast(byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16); |
432 dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16); | 432 dataCbComp[dstDataIndex] = cast(byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16); |
433 dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16); | 433 dataCrComp[dstDataIndex] = cast(byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16); |
434 } | 434 } |
435 } | 435 } |
436 } else { | 436 } else { |
437 for (int yPos = 0; yPos < srcHeight; yPos++) { | 437 for (int yPos = 0; yPos < srcHeight; yPos++) { |
438 image.getPixels(0, yPos, srcWidth, buffer, 0); | 438 image.getPixels(0, yPos, srcWidth, buffer, 0); |
442 int dstDataIndex = dstRowIndex + xPos; | 442 int dstDataIndex = dstRowIndex + xPos; |
443 RGB rgb = palette.getRGB(pixel); | 443 RGB rgb = palette.getRGB(pixel); |
444 int r = rgb.red; | 444 int r = rgb.red; |
445 int g = rgb.green; | 445 int g = rgb.green; |
446 int b = rgb.blue; | 446 int b = rgb.blue; |
447 dataYComp[dstDataIndex] = (byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16); | 447 dataYComp[dstDataIndex] = cast(byte)((RYTable[r] + GYTable[g] + BYTable[b]) >> 16); |
448 dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16); | 448 dataCbComp[dstDataIndex] = cast(byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) >> 16); |
449 dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16); | 449 dataCrComp[dstDataIndex] = cast(byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) >> 16); |
450 } | 450 } |
451 } | 451 } |
452 } | 452 } |
453 compress(image, dataYComp, dataCbComp, dataCrComp); | 453 compress(image, dataYComp, dataCbComp, dataCrComp); |
454 } | 454 } |
468 if (y > 255) y = 255; | 468 if (y > 255) y = 255; |
469 } | 469 } |
470 if (j >= imageWidth) { | 470 if (j >= imageWidth) { |
471 y = 0; | 471 y = 0; |
472 } | 472 } |
473 data[destIndex] = (byte)y; | 473 data[destIndex] = cast(byte)y; |
474 srcIndex++; | 474 srcIndex++; |
475 destIndex++; | 475 destIndex++; |
476 } | 476 } |
477 } | 477 } |
478 return data; | 478 return data; |
535 if (b < 0) { | 535 if (b < 0) { |
536 b = 0; | 536 b = 0; |
537 } else { | 537 } else { |
538 if (b > 255) b = 255; | 538 if (b > 255) b = 255; |
539 } | 539 } |
540 rgbData[destIndex] = (byte)b; | 540 rgbData[destIndex] = cast(byte)b; |
541 rgbData[destIndex + 1] = (byte)g; | 541 rgbData[destIndex + 1] = cast(byte)g; |
542 rgbData[destIndex + 2] = (byte)r; | 542 rgbData[destIndex + 2] = cast(byte)r; |
543 destIndex += 3; | 543 destIndex += 3; |
544 srcIndex++; | 544 srcIndex++; |
545 } | 545 } |
546 } | 546 } |
547 return rgbData; | 547 return rgbData; |
828 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, | 828 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, |
829 16383, 32767, 65535, 131125 | 829 16383, 32767, 65535, 131125 |
830 }; | 830 }; |
831 int code = (huffCode & power2m1[nBits - 1]) << (24 - nBits - currentBitCount); | 831 int code = (huffCode & power2m1[nBits - 1]) << (24 - nBits - currentBitCount); |
832 byte[] codeBuffer = new byte[4]; | 832 byte[] codeBuffer = new byte[4]; |
833 codeBuffer[0] = (byte)(code & 0xFF); | 833 codeBuffer[0] = cast(byte)(code & 0xFF); |
834 codeBuffer[1] = (byte)((code >> 8) & 0xFF); | 834 codeBuffer[1] = cast(byte)((code >> 8) & 0xFF); |
835 codeBuffer[2] = (byte)((code >> 16) & 0xFF); | 835 codeBuffer[2] = cast(byte)((code >> 16) & 0xFF); |
836 codeBuffer[3] = (byte)((code >> 24) & 0xFF); | 836 codeBuffer[3] = cast(byte)((code >> 24) & 0xFF); |
837 int abs = nBits - (8 - currentBitCount); | 837 int abs = nBits - (8 - currentBitCount); |
838 if (abs < 0) abs = -abs; | 838 if (abs < 0) abs = -abs; |
839 if ((abs >> 3) > 0) { | 839 if ((abs >> 3) > 0) { |
840 currentByte += codeBuffer[2]; | 840 currentByte += codeBuffer[2]; |
841 emitByte((byte)currentByte); | 841 emitByte(cast(byte)currentByte); |
842 emitByte(codeBuffer[1]); | 842 emitByte(codeBuffer[1]); |
843 currentByte = codeBuffer[0]; | 843 currentByte = codeBuffer[0]; |
844 currentBitCount += nBits - 16; | 844 currentBitCount += nBits - 16; |
845 } else { | 845 } else { |
846 currentBitCount += nBits; | 846 currentBitCount += nBits; |
847 if (currentBitCount >= 8) { | 847 if (currentBitCount >= 8) { |
848 currentByte += codeBuffer[2]; | 848 currentByte += codeBuffer[2]; |
849 emitByte((byte)currentByte); | 849 emitByte(cast(byte)currentByte); |
850 currentByte = codeBuffer[1]; | 850 currentByte = codeBuffer[1]; |
851 currentBitCount -= 8; | 851 currentBitCount -= 8; |
852 } else { | 852 } else { |
853 currentByte += codeBuffer[2]; | 853 currentByte += codeBuffer[2]; |
854 } | 854 } |
859 resetOutputBuffer(); | 859 resetOutputBuffer(); |
860 } | 860 } |
861 dataBuffer[bufferCurrentPosition] = byteValue; | 861 dataBuffer[bufferCurrentPosition] = byteValue; |
862 bufferCurrentPosition++; | 862 bufferCurrentPosition++; |
863 if (byteValue is -1) { | 863 if (byteValue is -1) { |
864 emitByte((byte)0); | 864 emitByte(cast(byte)0); |
865 } | 865 } |
866 } | 866 } |
867 void encodeACCoefficients(int[] dataUnit, int iComp) { | 867 void encodeACCoefficients(int[] dataUnit, int iComp) { |
868 int[] sParams = scanHeader.componentParameters[iComp]; | 868 int[] sParams = scanHeader.componentParameters[iComp]; |
869 JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]]; | 869 JPEGHuffmanTable acTable = acHuffmanTables[sParams[AC]]; |
945 for (int xmcu = 0; xmcu < interleavedMcuCols; xmcu++) { | 945 for (int xmcu = 0; xmcu < interleavedMcuCols; xmcu++) { |
946 encodeMCUAtXAndY(xmcu, ymcu); | 946 encodeMCUAtXAndY(xmcu, ymcu); |
947 } | 947 } |
948 } | 948 } |
949 if (currentBitCount !is 0) { | 949 if (currentBitCount !is 0) { |
950 emitByte((byte)currentByte); | 950 emitByte(cast(byte)currentByte); |
951 } | 951 } |
952 resetOutputBuffer(); | 952 resetOutputBuffer(); |
953 } | 953 } |
954 void expandImageComponents() { | 954 void expandImageComponents() { |
955 for (int iComp = 0; iComp < nComponents; iComp++) { | 955 for (int iComp = 0; iComp < nComponents; iComp++) { |
1700 static JPEGSegment seekUnspecifiedMarker(LEDataInputStream byteStream) { | 1700 static JPEGSegment seekUnspecifiedMarker(LEDataInputStream byteStream) { |
1701 byte[] byteArray = new byte[2]; | 1701 byte[] byteArray = new byte[2]; |
1702 try { | 1702 try { |
1703 while (true) { | 1703 while (true) { |
1704 if (byteStream.read(byteArray, 0, 1) !is 1) return null; | 1704 if (byteStream.read(byteArray, 0, 1) !is 1) return null; |
1705 if (byteArray[0] is (byte) 0xFF) { | 1705 if (byteArray[0] is cast(byte) 0xFF) { |
1706 if (byteStream.read(byteArray, 1, 1) !is 1) return null; | 1706 if (byteStream.read(byteArray, 1, 1) !is 1) return null; |
1707 if (byteArray[1] !is (byte) 0xFF && byteArray[1] !is 0) { | 1707 if (byteArray[1] !is cast(byte) 0xFF && byteArray[1] !is 0) { |
1708 byteStream.unread(byteArray); | 1708 byteStream.unread(byteArray); |
1709 return new JPEGSegment(byteArray); | 1709 return new JPEGSegment(byteArray); |
1710 } | 1710 } |
1711 } | 1711 } |
1712 } | 1712 } |
1754 if (x < 0) { | 1754 if (x < 0) { |
1755 x = 0; | 1755 x = 0; |
1756 } else { | 1756 } else { |
1757 if (x > 255) x = 255; | 1757 if (x > 255) x = 255; |
1758 } | 1758 } |
1759 compImage[destIndex + col] = (byte)x; | 1759 compImage[destIndex + col] = cast(byte)x; |
1760 srcIndex++; | 1760 srcIndex++; |
1761 } | 1761 } |
1762 destIndex += compWidth; | 1762 destIndex += compWidth; |
1763 } | 1763 } |
1764 } | 1764 } |
1765 void unloadIntoByteStream(ImageLoader loader) { | 1765 void unloadIntoByteStream(ImageLoader loader) { |
1766 ImageData image = loader.data[0]; | 1766 ImageData image = loader.data[0]; |
1767 if (!new JPEGStartOfImage().writeToStream(outputStream)) { | 1767 if (!new JPEGStartOfImage().writeToStream(outputStream)) { |
1768 DWT.error(DWT.ERROR_IO); | 1768 DWT.error(DWT.ERROR_IO); |
1769 } | 1769 } |
1770 JPEGAppn appn = new JPEGAppn(new byte[] {(byte)0xFF, (byte)0xE0, 0, 0x10, 0x4A, 0x46, 0x49, 0x46, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0}); | 1770 JPEGAppn appn = new JPEGAppn(new byte[] {cast(byte)0xFF, cast(byte)0xE0, 0, 0x10, 0x4A, 0x46, 0x49, 0x46, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0}); |
1771 if (!appn.writeToStream(outputStream)) { | 1771 if (!appn.writeToStream(outputStream)) { |
1772 DWT.error(DWT.ERROR_IO); | 1772 DWT.error(DWT.ERROR_IO); |
1773 } | 1773 } |
1774 quantizationTables = new int[4][]; | 1774 quantizationTables = new int[4][]; |
1775 JPEGQuantizationTable chromDQT = JPEGQuantizationTable.defaultChrominanceTable(); | 1775 JPEGQuantizationTable chromDQT = JPEGQuantizationTable.defaultChrominanceTable(); |