Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 7:03 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Wed May 16, 2012 2:12 pm 
Offline

Joined: Mon Apr 09, 2012 5:11 pm
Posts: 8
Hi all!

I am implementing an application for android using Slick-AE.
The application must use JPEG images, but this platform only support PNG files through the PNGDecoder class.

I have modified the Slick-AE code to support JPEGDecoder by using the pure-Java Matthias' decoder implementation.
After a lot of work i did work this, but the decoder is not coloring the image correctly... something is bad in there, but i dont know what, and it looks pretty complex to start debugging the JPEGDecoder.

Attachment:
File comment: Bad decoded JPEG image
bad_colors.jpg
bad_colors.jpg [ 82.39 KiB | Viewed 694 times ]


I have also implemented a 'LoadableImageData' class called JPEGImageData that configures the decoder to start working.

There are a lot of things already done, but they dont work. Maybe someone already had this issue and can help me.

Maybe another JPEGDecoder implemenetation :S

Regards,

Pablo


Top
 Profile  
 
PostPosted: Wed May 16, 2012 3:03 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Matthias' pure-java decoders should work great. In fact, if I ever get a chance, I'd love to overhaul Slick2D's texture loaders to use all of Matthias' decoders (instead of just PNG).

I'm guessing GL_UNPACK_ALIGNMENT is causing your problem. Try this before glTexImage2D:
Code:
        GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0);
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // <-- by default this is 4


Also make sure you're setting the right decode formats for JPGDecoder. When you call decodeRGB, the stride is based on how many components your decode format has:
Code:
public class ImageDecoderJPEG extends ImageDecoder {
   
    private JPEGDecoder decoder;

    public ImageDecoderJPEG(URL url) {
        super(url);
    }

    @Override
    public boolean open() throws IOException {
        inputStream = url.openStream();
        decoder = new JPEGDecoder(inputStream);
        decoder.decodeHeader();
        width = decoder.getImageWidth();
        height = decoder.getImageHeight();
        format = Texture.Format.RGBA;
        return decoder.startDecode();
    }

    @Override
    public void decode(ByteBuffer bb) throws IOException {
        decoder.decodeRGB(bb, width*format.getBytesPerPixel(), decoder.getNumMCURows());
    }
}


Top
 Profile  
 
PostPosted: Wed May 16, 2012 3:31 pm 
Offline

Joined: Mon Apr 09, 2012 5:11 pm
Posts: 8
Hi davedes, thank you very much for the fast reply.

I tried to do the GL11 thing, but it does not work... it is still being viewed corrupt.

I am not sure if i will continue try doing this. I dont really understand too much about libgdx and its OpenGL calls, so i am too blind while doing this, and i am just changing code that i am not sure for what it is.

I'll be glad if some day you make it work and you share it with us.

Thx a lot!

Pablo


Top
 Profile  
 
PostPosted: Wed May 16, 2012 3:52 pm 
Offline

Joined: Mon Apr 09, 2012 5:11 pm
Posts: 8
I found another implementation of the decoder:

http://webuser.fh-furtwangen.de/~dersch ... ecoder.zip

I will be working on it, maybe i can make it work!


Top
 Profile  
 
PostPosted: Wed May 16, 2012 4:29 pm 
Offline

Joined: Mon Apr 09, 2012 5:11 pm
Posts: 8
Finally! IT WORKED! :D

I used the decoder i have found on the following link:

http://webuser.fh-furtwangen.de/~dersch ... ecoder.zip

And then using a Slick ImageBuffer i created the image successfully.

The only issue is that it takes a couple of seconds to decode an image of 700x1024...
If someone founds a better decoder, it would be great!

Regards, and if someone needs the code, please let me know!

PAblo


Top
 Profile  
 
PostPosted: Wed May 16, 2012 6:56 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
No idea what you are doing - but my decoder is working 100%

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed May 16, 2012 7:02 pm 
Offline

Joined: Mon Apr 09, 2012 5:11 pm
Posts: 8
I am not saying your decoder does not work, probably i dont really know how to use it.
Dont worry, i guess it should work very well. :)

You said something about RGB and RGBA. What is the output of you decoder? RGB?


Top
 Profile  
 
PostPosted: Wed May 16, 2012 9:25 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
It outputs RGBA (as written in the javadoc). Take a look at my texture loading library

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group