Fw: IMG_Load_RW

Apparently, I’m not the only one having problems with IMG_Load_RW:----- Forwarded Message ----

From: “kidfruit at hotmail.com
To: @Kevron_Rees
Sent: Friday, December 12, 2008 7:29:04 AM
Subject: About IMG_Load_RW

Actually I have the same problem.

When I use IMG_Load_RW to read the PNG picture directly ,it can complete
compiling but con’t show the picture and quickly flash and close. But IMG_Load
can do well if I unpack the picture to file. The same situation as you do with
JPEG file.

Luckily? I found an solution with that. You can convert the file to bmp and pack
again, then you will find you can read the picture by IMG_Load_RW. But bmp is
too big so this is not the best method.

I think there is something wrong in SDL_image lib, so maybe asking SDL official
is the best way.

PS: If you find solution, hope you can share it to me, thanks :smiley:

kidfruit
emai: kidfruit at gmail.com

Here is the code I’m using again:

For some reason IMG_Load_RW is reporting unsupported type however, if I
write it to a file, I can load it fine with a normal IMG_Load(). Any
hints on why it won’t load with IMG_Load_RW ?

Here’s the relevant code.

SDL_RWops * picData = SDL_RWFromMem(pic->picture().data(),pic->picture().size());

///temp write to disk to examine jpeg:
ofstream temppic;
temppic.open("/tmp/album-image.jpg",ios::binary | ios::trunc);

if(temppic)
{
   ///write to a file.
    temppic.write(pic->picture().data(),pic->picture().size());
    temppic.close();
}

if(!picData)
{
    ndebug::out(ndebug::LOG_DEBUG,"SearchDir: failed to conver album art into SDL RWop for %s",path.c_str());
    return NULL;
}

SDL_Surface * image;

   /// This works:
image = IMG_Load("/tmp/album-image.jpg");

/// This doesn’t work:
//image = IMG_Load_RW(picData,1);

if(!image)
{
    ndebug::out(ndebug::LOG_ERR,"SearchDir: Failed to load album art image.  Error: (%s)",IMG_GetError());
    ndebug::out(ndebug::LOG_ERR,"SearchDir: mime type of image: %s",pic->mimeType().toCString());
    
    return NULL;
}

return image;

Are you certain that pic->picture().data() and pic->picture().size()
are returning the values you think they are? Maybe compile with -Wall
(gcc option) and see if you get any more clues (since we can’t tell
what type ‘pic’ is of, or its member functions, etc.)On Fri, Dec 12, 2008 at 7:55 PM, Kevron Rees wrote:

SDL_RWops * picData = SDL_RWFromMem(pic->picture().data(),pic->picture().size());


http://codebad.com/

Are you certain that pic->picture().data() and pic->picture().size()
are returning the values you think they are? Maybe compile with -Wall
(gcc option) and see if you get any more clues (since we can’t tell
what type ‘pic’ is of, or its member functions, etc.)

Oh sorry, the relevant information was right there all along…On Sat, Dec 13, 2008 at 10:33 AM, Donny Viszneki <@Donny_Viszneki> wrote:

On Fri, Dec 12, 2008 at 7:55 PM, Kevron Rees wrote:

   temppic.write(pic->picture().data(),pic->picture().size());

I believe SDL_image actually uses SDL_RWops when it loads from either
a file or from an arbitrary RWop. If that’s true, then maybe there’s a
problem with SDL_RWops, not SDL_image. Right?

Question: Have you tried reading the file into memory (perhaps without
using whatever image library you seem to be using, so that you can
share the code and others can work with it more easily) and then
decoding it with SDL_image using rwops?


http://codebad.com/