Original Post
🔒 Locked
SDL Surface data saving using Devil
Advertisement
How are you doing the copying?
I imagine you would do it something like this:
Create a new texture.[Save state]
ilGenImages(1,&mytex);
Make it the current image.
ilBindImage(&mytex);
Resize the texture and copy SDL_Surface data to it.
(Note: Actual parameters depend on the format of the SDL_Surface data)
(Note: Make sure you lock the SDL_Surface.[SDL_LockSurface(sdlimage);])
ilTexImage(
sdlimage->w,
sdlimage->h,
1, //Depth 1 = 2d,2 = 3d
3, //Bytes per pixel
IL_RGB, //format
IL_UNSIGNED_BYTE, //type
sdlimage->pixels
);
Unlock the surface.[SDL_UnlockSurface(sdlimage)]
Save it to whatever format you want.
ilSave(IL_TGA,"myimage.tga");
Delete the texture.[Restore state]
ilDeleteImages(1,&mytex);
Good Luck.
I imagine you would do it something like this:
Create a new texture.[Save state]
ilGenImages(1,&mytex);
Make it the current image.
ilBindImage(&mytex);
Resize the texture and copy SDL_Surface data to it.
(Note: Actual parameters depend on the format of the SDL_Surface data)
(Note: Make sure you lock the SDL_Surface.[SDL_LockSurface(sdlimage);])
ilTexImage(
sdlimage->w,
sdlimage->h,
1, //Depth 1 = 2d,2 = 3d
3, //Bytes per pixel
IL_RGB, //format
IL_UNSIGNED_BYTE, //type
sdlimage->pixels
);
Unlock the surface.[SDL_UnlockSurface(sdlimage)]
Save it to whatever format you want.
ilSave(IL_TGA,"myimage.tga");
Delete the texture.[Restore state]
ilDeleteImages(1,&mytex);
Good Luck.
thanks so much for your answers but i think i got another problem i first tried the pitch as basement said but it gave the wrong output... So i thought i can try width but it gave another 'wrong output'. So here is my code and what my output [with pitch] looks like
ILuint img;
ilGenImages(1, &img);
ilBindImage(img);
if (Bitmap == NULL || Bitmap->w == 0 || Bitmap->h == 0) {
ilSetError(ILUT_INVALID_PARAM);
return IL_FALSE;
}
SDL_LockSurface(Bitmap);
if (!ilTexImage(Bitmap->pitch, Bitmap->h, 1, Bitmap->format->BytesPerPixel, IL_RGB, IL_UNSIGNED_BYTE, Bitmap->pixels))
return IL_FALSE;
SDL_UnlockSurface(Bitmap);
ilEnable(IL_FILE_OVERWRITE);
ilSave(type, filename);
ilDeleteImages(1, &img);
return IL_TRUE;
output:

and here is the input:

ok as you can see i don't thik pitch is what i need; i think w is what i need because my output image looks good [in sizes i mean] with Bitmap->w; but there's still something missing... look at the next output:

[Edited by - Dec1pher on April 5, 2006 10:41:12 AM]
ILuint img;
ilGenImages(1, &img);
ilBindImage(img);
if (Bitmap == NULL || Bitmap->w == 0 || Bitmap->h == 0) {
ilSetError(ILUT_INVALID_PARAM);
return IL_FALSE;
}
SDL_LockSurface(Bitmap);
if (!ilTexImage(Bitmap->pitch, Bitmap->h, 1, Bitmap->format->BytesPerPixel, IL_RGB, IL_UNSIGNED_BYTE, Bitmap->pixels))
return IL_FALSE;
SDL_UnlockSurface(Bitmap);
ilEnable(IL_FILE_OVERWRITE);
ilSave(type, filename);
ilDeleteImages(1, &img);
return IL_TRUE;
output:

and here is the input:

ok as you can see i don't thik pitch is what i need; i think w is what i need because my output image looks good [in sizes i mean] with Bitmap->w; but there's still something missing... look at the next output:

[Edited by - Dec1pher on April 5, 2006 10:41:12 AM]
Make sure the SDL surface is either 3 or 4 bytes per pixel. If it is not, convert it to the correct format using SDL_ConvertSurface(). Imagelib wouldn't handle any surface format besides these two.
I noticed in the ilut.h header a stub for ilutSDLSurfaceFromBitmap(). It would be good if you submitted this code to the imagelib people:)
I noticed in the ilut.h header a stub for ilutSDLSurfaceFromBitmap(). It would be good if you submitted this code to the imagelib people:)
It looks like SDL surfaces use padding(on 32bit boundaries) for each image row.
Imagelib doesn't appear to be able to detect the padding. A pitch parameter for ilTexImage() would solve this problem.
A work around would be to convert all images to 32bit and then you won't have to deal with the padding issue.
Note that SDL_SaveBMP() is available if this format is an option for you.
Imagelib doesn't appear to be able to detect the padding. A pitch parameter for ilTexImage() would solve this problem.
A work around would be to convert all images to 32bit and then you won't have to deal with the padding issue.
Note that SDL_SaveBMP() is available if this format is an option for you.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement