Problem loading a Jpeg as texture

Loading PNG textures or such in Xith works great.
Also Kev’s 3dloader can load models having Jpeg texture files and it works here. But when I try to load a Jpeg texture manually, an exception is being reported. I’ve checked with Kev’s texture loading method but can’t find any significant difference.

This


BufferedImage bimg = ImageIO.read(new File("Pic.jpg"));
Texture t = TextureLoader.tf.loadTexture(bimg, "RGB", true, Texture.NICEST, Texture.NICEST, Texture.WRAP);

results in the following stacktrace

No matter how large my Jpeg picture is (it’s 256x256 24bpp, or 512x512, etc). I’ve also used the same texture which Kev’s loader loads but his method works, mine fails. Why?

Would anybody like to call these two lines of code on his PC and look if it works, please? Thanks.

PS: I use a current Xith version; just downloaded some days ago from CVS.

Just out of curiosity, why aren’t you using the built-in get* functions from the TextureLoader?

TextureLoader.tf.getTextureWrap("Pic.jpg");

[quote]Just out of curiosity, why aren’t you using the built-in get* functions from the TextureLoader?
[/quote]
I usually use BufferedImages because many times I build a RGBA BufferedImage in memory on the fly, from a RGB PNG file (24bpp) plus an extra Alpha PNG file (8bpp). The resulting BufferdImage I feed to Xith. Now I’ve for the first time tried to do the same with some Jpeg files and it crashes. :slight_smile:

Do my two lines of code (posted in my previous article) work for you?

To answer your question, no I can’t run your code. I get the same error:

[quote]Exception in thread “main” java.awt.image.ImagingOpException: Unable to transform src image
at java.awt.image.AffineTransformOp.filter(AffineTransformOp.java:263)
at com.xith3d.loaders.texture.TextureLoader.flipImageVertical(TextureLoader.java:431)
at com.xith3d.loaders.texture.TextureLoader.constructTexture(TextureLoader.java:481)
at com.xith3d.loaders.texture.TextureLoader.loadTexture(TextureLoader.java:361)
at testTex.doTest(testTex.java:53)
at testTex.main(testTex.java:24)
[/quote]
To get this working in my own code, I had to use DirectBufferedImage.make().

Try this in place of your code:


import com.xith3d.loaders.texture.*;
import com.xith3d.image.*;

BufferedImage texImage = <whatever you do to make your image>;
Texture2D texture = (Texture2D)TextureLoader.tf.loadTexture(
  DirectBufferedImage.make(texImage), 
  "RGB", 
  true, 
  Texture.NICEST, 
  Texture.NICEST, 
  Texture.WRAP
);

[quote]To answer your question, no I can’t run your code. I get the same error
[/quote]
Many thanks for testing it.

So how does Kev manage to use this method in his 3dsloader…?

[quote]To get this working in my own code, I had to use DirectBufferedImage.make().
[/quote]
Thanks a lot. It’s a good workaround. Still do we have to worry why it doesn’t work with the original method?

/me looks around at Xith developers


    public static BufferedImage flipImageVertical(BufferedImage bi)
    {

        AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
          tx.translate(0, -bi.getHeight(null));
          AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

          BufferedImage bi2;
          if (bi.getColorModel().hasAlpha()) bi2= DirectBufferedImage.getDirectImageRGBA(bi.getWidth(),bi.getHeight());
          else bi2 = DirectBufferedImage.getDirectImageRGB(bi.getWidth(),bi.getHeight());

          op.filter(bi, bi2);
          return bi2;

    }