Hello all,
i’ve a little problem when copying SDL_Surface pixels to allocated data :
void* data;
int imageSize;
SDL_Surface image = IMG_Load(“c:\test.jpg”); // image successfully loaded
using SDL_Image
imageSize= 32/because my image depth is 32/ * image->w * image->h;
data = (void) malloc (imageSize);
memcpy (data, image->pixels, imageSize); //the program hangs here
Does anyone have encountered the same problem ?
Thanks
[…]
imageSize= 32/because my image depth is 32/ * image->w * image->h;
[…]
Last time I used it, malloc(), memcpy() and co wanted the size in
bytes, not bits. 
//David Olofson - Programmer, Composer, Open Source Advocate
.- Coming soon from VaporWare Inc…------------------------.
| The Return of Audiality! Real, working software. Really! |
| Real time and off-line synthesis, scripting, MIDI, LGPL…|
-----------------------------------> (Public Release RSN) -' .- M A I A -------------------------------------------------. | The Multimedia Application Integration Architecture |
----------------------------> http://www.linuxdj.com/maia -’
— http://olofson.net — http://www.reologica.se —On Friday 04 October 2002 14:04, DAVOINE J?r?me wrote:
Hello!
imageSize= 32/because my image depth is 32/ * image->w * image->h;
Shouldn’t you use 4 (Bytes) instead of 32 (Bits)?
Ciao,
Eike
Oups…Ok, what a stupid mistake 
Thank you
-----Message d’origine-----De : David Olofson [mailto:david.olofson at reologica.se]
Envoy? : vendredi 4 octobre 2002 14:22
? : sdl at libsdl.org
Objet : Re: [SDL] Copy problem
On Friday 04 October 2002 14:04, DAVOINE J?r?me wrote:
[…]
imageSize= 32/because my image depth is 32/ * image->w * image->h;
[…]
Last time I used it, malloc(), memcpy() and co wanted the size in
bytes, not bits. 
//David Olofson - Programmer, Composer, Open Source Advocate
.- Coming soon from VaporWare Inc…------------------------.
| The Return of Audiality! Real, working software. Really! |
| Real time and off-line synthesis, scripting, MIDI, LGPL…|
-----------------------------------> (Public Release RSN) -' .- M A I A -------------------------------------------------. | The Multimedia Application Integration Architecture |
----------------------------> http://www.linuxdj.com/maia -’
— http://olofson.net — http://www.reologica.se —
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
imageSize= 32/because my image depth is 32/ * image->w *
image->h;
Hmm, your image depth is 32 bytes per pixel? I think you mean 32
bits (which, of course, is 4 bytes):
imageSize = 4 * image->w * image->h;
or better:
imageSize = image->format->BytesPerPixel * image->w * image->h;
and better yet:
imageSize = image->pitch * image->h;–
Matthijs Hollemans
All Your Software
www.allyoursoftware.com
Hello all,
i’ve a little problem when copying SDL_Surface pixels to allocated data :
void* data;
int imageSize;
SDL_Surface *image = IMG_Load(“c:\test.jpg”); // image successfully loaded
using SDL_Image
imageSize= 32/because my image depth is 32/ * image->w * image->h;
32*8 = 256
Your image depth is 256 ?
:))
data = (void*) malloc (imageSize);
memcpy (data, image->pixels, imageSize); //the program hangs here
Does anyone have encountered the same problem ?
Yep.
AlexAm Freitag, 4. Oktober 2002 14:04 schrieb DAVOINE J?r?me:
Thank you
-----Message d’origine-----De : Eike Sauer [mailto:sauer at nanocosmos.de]
Envoy? : vendredi 4 octobre 2002 14:21
? : sdl at libsdl.org
Objet : RE: [SDL] Copy problem
Hello!
imageSize= 32/because my image depth is 32/ * image->w * image->h;
Shouldn’t you use 4 (Bytes) instead of 32 (Bits)?
Ciao,
Eike