SDL and XPM

Is there a way to load a .XPM image file in a
SDL_Surface* using SDL_RWFromMem ?

i’d like to insert the .xpm files as source files…

and without using SDL_Image… :-)–
Bye!
Skunkguru.

Well…

If you don’t want to use SDL Image I guess you wouldn’t want to use any
other lib either. So then you option is to write your own loader I guess…

/ Daniel Liljeberg> ----- Original Message -----

From: skunkguru@hotmail.com (SkunkGuru)
To:
Sent: Monday, March 01, 2004 4:52 PM
Subject: [SDL] SDL and XPM

Is there a way to load a .XPM image file in a
SDL_Surface* using SDL_RWFromMem ?

i’d like to insert the .xpm files as source files…

and without using SDL_Image… :slight_smile:


Bye!
Skunkguru.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

“DAMiEN” <damien_ at hotmail.com> ha scritto nel messaggio
news:BAY9-DAV8W5apelViVK00009f74 at hotmail.com

Well…

If you don’t want to use SDL Image I guess you wouldn’t want to use any
other lib either. So then you option is to write your own loader I
guess…

well…
I don’t want to use SDL image because it means adding
4(four) file .dll (~350kb) only for loading a couple of XPMs…
:slight_smile:

so I was wondering if there is a way to do this with
SDL library itself.–
Bye!
Skunkguru.

“DAMiEN” <damien_ at hotmail.com> ha scritto nel messaggio
news:BAY9-DAV8W5apelViVK00009f74 at hotmail.com

Well…

If you don’t want to use SDL Image I guess you wouldn’t want to use any
other lib either. So then you option is to write your own loader I
guess…

well…
I don’t want to use SDL image because it means adding
4(four) file .dll (~350kb) only for loading a couple of XPMs…
:slight_smile:

so I was wondering if there is a way to do this with
SDL library itself.

No, SDL does not have an XPM loader built into it.

Now, starting chanting:

“SDL is Free Software”
“SDL is Open Source”

just say it a few times… :slight_smile: It you do it long enough it will change
the way you think about programming.

Ok, seriously now, you have the source code for SDL_image. If not, you
can down load it quickly enough. Just extract the XPM code from
SDL_image and put it into your project. You can even build your own .dll
for SDL_image that supports only XPM. Either way, you get what you want
without adding a huge amount of code to your program. You have the code,
you have the freedom to modify the code, just do it. Throw off the
mental chains that bind your mind. The chains that keep you from
thinking of using the code the way you want instead of the way you are
told by the evil source code hoarders!.. Ok, ok, today is Texas
Independence day and I am in a freedom oriented mood… Remember the
Almo and free the source code.

OTOH, you could just convert the XPMs to BMPs , Then convert the BMPs to
C code, and compile them into your program that way. I’ve been doing
that for a while and it works great.

	Bob Pendleton

P.S.

“You all can go to Hell – I’m going to Texas.”

	Davy CrockettOn Tue, 2004-03-02 at 09:02, SkunkGuru wrote:


Bye!
Skunkguru.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

±--------------------------------------+

Just extract the XPM code from SDL_image and put it into your project.

well, my first idea was this… cut/paste… :slight_smile:
but I was wondering if there was already in SDL…

and I didn’t know that I can do this “extraction”…
or at least I was not sure… :slight_smile:

Throw off the mental chains that bind your mind.

:slight_smile:

OTOH, you could just convert the XPMs to BMPs , Then convert the BMPs to
C code, and compile them into your program that way. I’ve been doing
that for a while and it works great.

this sounds great !! How did you do that ?
it’s exactly what I want !

my original images are in BMP format ! :slight_smile:
I converted them in XPM because I thought it’s the only
way to compile them in the program…
#include "myfile.xpm"
and using SDL_Image for reading it…

How did you convert bmp to C code ?
And how to load them ?–
Bye!
Skunkguru.

Bob Pendleton wrote:

[…]

OTOH, you could just convert the XPMs to BMPs , Then convert the BMPs to
C code, and compile them into your program that way. I’ve been doing
that for a while and it works great.

AFAIK, xpm IS the C source code.–

./lxnt

It is, but you still need a reader to deal with it. It’s probably
slightly easier to read the compiled C code (ASCII strings) than the
file, though…

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Tuesday 02 March 2004 17.42, Alexander Sabourenkov wrote:

Bob Pendleton wrote:
[…]

OTOH, you could just convert the XPMs to BMPs , Then convert the
BMPs to C code, and compile them into your program that way. I’ve
been doing that for a while and it works great.

AFAIK, xpm IS the C source code.

David Olofson wrote:> On Tuesday 02 March 2004 17.42, Alexander Sabourenkov wrote:

Bob Pendleton wrote:
[…]

OTOH, you could just convert the XPMs to BMPs , Then convert the
BMPs to C code, and compile them into your program that way. I’ve
been doing that for a while and it works great.

AFAIK, xpm IS the C source code.

It is, but you still need a reader to deal with it. It’s probably
slightly easier to read the compiled C code (ASCII strings) than the
file, though…

Hm.
Looking at an actual xpm file I now understand that that is the case.

Though the complexity of the reader is comparable with one of any example from
a chapter on scanf and friends from any decent C textbook.

Ripping one from any of available 1+N (1 being the SDL_Image itself) sources
must be only slightly easier that writing one from scratch.

Now is the time of the obligatory licensing flamewar :slight_smile:

./lxnt

David Olofson wrote:

Bob Pendleton wrote:
[…]

OTOH, you could just convert the XPMs to BMPs , Then convert the
BMPs to C code, and compile them into your program that way.
I’ve been doing that for a while and it works great.

AFAIK, xpm IS the C source code.

It is, but you still need a reader to deal with it. It’s probably
slightly easier to read the compiled C code (ASCII strings) than
the file, though…

Hm.
Looking at an actual xpm file I now understand that that is the
case.

Though the complexity of the reader is comparable with one of any
example from a chapter on scanf and friends from any decent C
textbook.

Ripping one from any of available 1+N (1 being the SDL_Image
itself) sources must be only slightly easier that writing one from
scratch.

Probably…

I hacked a basic XPM writer the other week, and that was simple enough
that it would probably have been more work to understand someone
else’s implementation. Writing that sort of files is usually slightly
easier than parsing them, though.

Now is the time of the obligatory licensing flamewar :slight_smile:

Noooo, not agaaaaaain…! hehe

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Tuesday 02 March 2004 18.49, Alexander Sabourenkov wrote:

On Tuesday 02 March 2004 17.42, Alexander Sabourenkov wrote:

XPM is C source code, but it is not the source code equivalent to a BMP
file. Very different formats.

	Bob PendletonOn Tue, 2004-03-02 at 10:42, Alexander Sabourenkov wrote:

Bob Pendleton wrote:

[…]

OTOH, you could just convert the XPMs to BMPs , Then convert the BMPs to
C code, and compile them into your program that way. I’ve been doing
that for a while and it works great.

AFAIK, xpm IS the C source code.


±--------------------------------------+

Just extract the XPM code from SDL_image and put it into your project.

well, my first idea was this… cut/paste… :slight_smile:
but I was wondering if there was already in SDL…

and I didn’t know that I can do this “extraction”…
or at least I was not sure… :slight_smile:

Throw off the mental chains that bind your mind.

:slight_smile:

OTOH, you could just convert the XPMs to BMPs , Then convert the BMPs to
C code, and compile them into your program that way. I’ve been doing
that for a while and it works great.

this sounds great !! How did you do that ?
it’s exactly what I want !

my original images are in BMP format ! :slight_smile:
I converted them in XPM because I thought it’s the only
way to compile them in the program…
#include "myfile.xpm"
and using SDL_Image for reading it…

How did you convert bmp to C code ?

Just read them and wrote them in the format I wanted. I’ve attached a
simple program that will convert anything to C code. Its name is
toch.cpp which is pronounced “to C H”.

The rest is easy:
SDL_Surface *loadImage(unsigned char *iaddr, int ilen)
{
SDL_RWops *src = NULL;
SDL_Surface *s0, *s1;

src = SDL_RWFromMem(iaddr, ilen);
s0 = SDL_LoadBMP_RW(src, 1);
if (NULL == s0)
{
errorExit(“Can’t load image file”);
}

s1 = SDL_DisplayFormat(s0);
if (NULL == s1)
{
errorExit(“Can’t convert image file”);
}

SDL_FreeSurface(s0);

return s1;
}

The address and the length are just the name of the image and
sizeof(image).

	Bob PendletonOn Tue, 2004-03-02 at 10:38, SkunkGuru wrote:

And how to load them ?

±--------------------------------------+

Just read them and wrote them in the format I wanted. I’ve attached a
simple program that will convert anything to C code. Its name is
toch.cpp which is pronounced “to C H”.

The rest is easy:
SDL_Surface *loadImage(unsigned char *iaddr, int ilen);
The address and the length are just the name of the image and
sizeof(image).

Great !!!
Thank you VERY VERY much !!! It’s exactly what I need!!!

simple and working… :-)))–
Bye!
Skunkguru.

You are very welcome.

	Bob PendletonOn Wed, 2004-03-03 at 03:09, SkunkGuru wrote:

Just read them and wrote them in the format I wanted. I’ve attached a
simple program that will convert anything to C code. Its name is
toch.cpp which is pronounced “to C H”.

The rest is easy:
SDL_Surface *loadImage(unsigned char *iaddr, int ilen);
The address and the length are just the name of the image and
sizeof(image).

Great !!!
Thank you VERY VERY much !!! It’s exactly what I need!!!

simple and working… :-)))


±--------------------------------------+