diff options
author | Chien Yang <[email protected]> | 2007-03-30 17:04:44 +0000 |
---|---|---|
committer | Chien Yang <[email protected]> | 2007-03-30 17:04:44 +0000 |
commit | 47740959525d6d650a9a2d25be5f327909c211c2 (patch) | |
tree | 75d683e86df2fcd090a0359d9211cf7f5b849bea /src/classes | |
parent | ecd1e078bb8529490d9951335ab95e041a40f66c (diff) |
Fixed Issue 402 : Off-screen Canvas3D throws Exception on BufferedImage of TYPE_4BYTE_ABGR and TYPE_INT_ARGB
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@805 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/classes')
-rw-r--r-- | src/classes/share/javax/media/j3d/ImageComponentRetained.java | 113 |
1 files changed, 53 insertions, 60 deletions
diff --git a/src/classes/share/javax/media/j3d/ImageComponentRetained.java b/src/classes/share/javax/media/j3d/ImageComponentRetained.java index b1744c6..f2a4ad8 100644 --- a/src/classes/share/javax/media/j3d/ImageComponentRetained.java +++ b/src/classes/share/javax/media/j3d/ImageComponentRetained.java @@ -1961,7 +1961,7 @@ abstract class ImageComponentRetained extends NodeComponentRetained { } /** - * Copy Image from RGBA to the user defined bufferedImage + * Copy image to the user defined bufferedImage ( 3 or 4 components only ) */ void copyToRefImageWithFormatConversion(int depth) { int w, h, i, j; @@ -1993,16 +1993,31 @@ abstract class ImageComponentRetained extends NodeComponentRetained { ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); // Multiply by 4 to get the byte incr and start point j = 0; - for(h = 0; h < height; h++, dstBegin += dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, j+=4, i++) { - intData[i] = (((buf[j+3] &0xff) << 24) | // a - ((buf[j] &0xff) << 16) | // r - ((buf[j+1] &0xff) << 8) | // g - (buf[j+2] & 0xff)); // b - - - } + switch (imageFormatType) { + case TYPE_BYTE_RGBA: + for(h = 0; h < height; h++, dstBegin += dstInc) { + i = dstBegin; + for (w = 0; w < width; w++, j+=4, i++) { + intData[i] = (((buf[j+3] &0xff) << 24) | // a + ((buf[j] &0xff) << 16) | // r + ((buf[j+1] &0xff) << 8) | // g + (buf[j+2] & 0xff)); // b + } + } + break; + case TYPE_BYTE_RGB: + for(h = 0; h < height; h++, dstBegin += dstInc) { + i = dstBegin; + for (w = 0; w < width; w++, j+=3, i++) { + intData[i] = (0xff000000 | // a + ((buf[j] &0xff) << 16) | // r + ((buf[j+1] &0xff) << 8) | // g + (buf[j+2] & 0xff)); // b + } + } + break; + default: + assert false; } break; @@ -2018,8 +2033,6 @@ abstract class ImageComponentRetained extends NodeComponentRetained { ((buf[j] &0xff) << 16) | // r ((buf[j+1] &0xff) << 8) | // g (buf[j+2] & 0xff)); // b - - } } break; @@ -2033,17 +2046,34 @@ abstract class ImageComponentRetained extends NodeComponentRetained { //Issue 381: dstBegin contains pixel count, but we are looping over byte count. In case of YDown, it contains a count that is decremented and if we do not multiply, we have an AIOOB thrown at 25% of the copy. dstBegin <<= 2; - for(h = 0; h < height; h++, dstBegin += (dstInc << 2)) { - i = dstBegin; - for (w = 0; w < width; w++, j+=4) { - - byteData[i++] = buf[j+3]; // a - byteData[i++] = buf[j+2]; // b - byteData[i++] = buf[j+1];// g - byteData[i++] = buf[j]; // r - } + switch (imageFormatType) { + case TYPE_BYTE_RGBA: + for(h = 0; h < height; h++, dstBegin += (dstInc << 2)) { + i = dstBegin; + for (w = 0; w < width; w++, j+=4) { + byteData[i++] = buf[j+3]; // a + byteData[i++] = buf[j+2]; // b + byteData[i++] = buf[j+1];// g + byteData[i++] = buf[j]; // r + } + } + break; + case TYPE_BYTE_RGB: + for(h = 0; h < height; h++, dstBegin += (dstInc << 2)) { + i = dstBegin; + for (w = 0; w < width; w++, j+=3) { + byteData[i++] = (byte) 0xff; // a + byteData[i++] = buf[j+2]; // b + byteData[i++] = buf[j+1];// g + byteData[i++] = buf[j]; // r + } + } + break; + default: + assert false; } break; + case BufferedImage.TYPE_INT_BGR: intData = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); @@ -2057,48 +2087,11 @@ abstract class ImageComponentRetained extends NodeComponentRetained { ((buf[j] &0xff) ) | // r ((buf[j+1] &0xff) << 8) | // g (buf[j+2] & 0xff)<< 16); // b - - - } - } - break; - case BufferedImage.TYPE_BYTE_GRAY: - byteData = - ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); - j = 0; - for( h = 0; h < height; h++, dstBegin += dstInc) { - System.arraycopy(byteData, dstBegin, buf, j, width); - j += width; - } - break; - case BufferedImage.TYPE_USHORT_GRAY: - int pixel; - j = 0; - short[] shortData = - ((DataBufferShort)bi.getRaster().getDataBuffer()).getData(); - // Multiply by 4 to get the byte incr and start point - for(h = 0; h < height; h++, dstBegin+= dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, i++, j++) { - shortData[i] = (short)buf[j]; } } break; - default: - j = 0; - for( h = 0; h < height; h++, dstIndex += dstIndexInc) { - i = dstIndex; - for (w = 0; w < width; w++, j+=4) { - pixel = (((buf[j+3] &0xff) << 24) | // a - ((buf[j] &0xff) << 16) | // r - ((buf[j+1] &0xff) << 8) | // g - (buf[j+2] & 0xff)); // b - bi.setRGB(w, i, pixel); - - } - } - break; + assert false; } } |