summaryrefslogtreecommitdiffstats
path: root/src/classes/share/com/sun/j3d
diff options
context:
space:
mode:
authorChien Yang <[email protected]>2006-11-06 19:11:31 +0000
committerChien Yang <[email protected]>2006-11-06 19:11:31 +0000
commit796af38d4d9bcc5214052066f812e7f7322a6bbe (patch)
treec34be0e7731445b0b74f96d6b781a16d148a84eb /src/classes/share/com/sun/j3d
parent70e4f2ff11fd7d7f5dbcbb9c2cb8cba46398ffc1 (diff)
Completed fix to Issue 344, handle case where imageType is of TYPE_CUSTOM.
git-svn-id: https://svn.java.net/svn/j3d-core-utils~svn/trunk@135 9497e636-51bd-65ba-982d-a4982e1767a5
Diffstat (limited to 'src/classes/share/com/sun/j3d')
-rw-r--r--src/classes/share/com/sun/j3d/utils/image/TextureLoader.java60
1 files changed, 50 insertions, 10 deletions
diff --git a/src/classes/share/com/sun/j3d/utils/image/TextureLoader.java b/src/classes/share/com/sun/j3d/utils/image/TextureLoader.java
index 4d1b560..0376bd2 100644
--- a/src/classes/share/com/sun/j3d/utils/image/TextureLoader.java
+++ b/src/classes/share/com/sun/j3d/utils/image/TextureLoader.java
@@ -798,18 +798,58 @@ public class TextureLoader extends Object {
if (xScale == 1.0f && yScale == 1.0f)
return origImage;
else {
- int scaleW = (int)(origImage.getWidth() * xScale + 0.5);
- int scaleH = (int)(origImage.getHeight() * yScale + 0.5);
-
- WritableRaster origWr = origImage.getRaster();
- WritableRaster wr = origWr.createCompatibleWritableRaster(0, 0, scaleW, scaleH);
- BufferedImage scaledImage = new BufferedImage(scaleW, scaleH, origImage.getType());
+ int scaleW = (int)(origImage.getWidth() * xScale + 0.5);
+ int scaleH = (int)(origImage.getHeight() * yScale + 0.5);
+
+ int origImageType = origImage.getType();
+ BufferedImage scaledImage;
+ WritableRaster wr;
+
+ if (origImageType != BufferedImage.TYPE_CUSTOM) {
+ WritableRaster origWr = origImage.getRaster();
+ wr = origWr.createCompatibleWritableRaster(0, 0, scaleW, scaleH);
+ scaledImage = new BufferedImage(scaleW, scaleH, origImageType);
+ } else {
+ int numComponents = origImage.getSampleModel().getNumBands();
+ int[] bandOffset = new int[numComponents];
+ int[] nBits = new int[numComponents];
+ for (int ii=0; ii < numComponents; ii++) {
+ bandOffset[ii] = ii;
+ nBits[ii] = 8;
+ }
+ ComponentColorModel colorModel = new ComponentColorModel(cs, nBits, true, false, Transparency.TRANSLUCENT, 0);
+
+ wr = java.awt.image.Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
+ scaleW, scaleH,
+ scaleW * numComponents, numComponents,
+ bandOffset, null);
+
+ int imageType;
+
+ switch (numComponents) {
+ case 1:
+ imageType = BufferedImage.TYPE_BYTE_GRAY;
+ break;
+ case 3:
+ imageType = BufferedImage.TYPE_3BYTE_BGR;
+ break;
+ case 4:
+ imageType = BufferedImage.TYPE_4BYTE_ABGR;
+ break;
+ default:
+ throw new ImageException("Illegal number of bands : " + numComponents);
+
+ }
+
+ scaledImage = new BufferedImage(scaleW, scaleH, imageType);
+ }
+
scaledImage.setData(wr);
- java.awt.Graphics2D g2 = scaledImage.createGraphics();
+ java.awt.Graphics2D g2 = scaledImage.createGraphics();
AffineTransform at = AffineTransform.getScaleInstance(xScale,
- yScale);
- g2.transform(at);
- g2.drawImage(origImage, 0, 0, null);
+ yScale);
+ g2.transform(at);
+ g2.drawImage(origImage, 0, 0, null);
return scaledImage;
}