Archived

This topic is now archived and is closed to further replies.

SDL_Surface to PNG

This topic is 4944 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


i''m doing this right now:


_RowPtr = sg_AllocPNGPixels(p_Surface->w, p_Surface->h);
_Pixels = (Uint32*) p_Surface->pixels;

for(_Row = 0; _Row < p_Surface->h; _Row++) {
for(_Col = 0; _Col < p_Surface->w; _Col++) {
_Pixels = (Uint32*) p_Surface->pixels;
_Pixels += ((_Row*p_Surface->pitch) >> 2) + _Col;
// _RowPtr[_Row][_Col] = _Pixels[((_Row*p_Surface->pitch) >> 2) + _Col];

_RowPtr[_Row][_Col] = *_Pixels;
}
}

png_init_io(_png_ptr, _File);
png_set_IHDR(_png_ptr,
_info_ptr,
p_Surface->w,
p_Surface->h,
(p_Surface->format->BitsPerPixel) / 4,
PNG_COLOR_TYPE_RGB_ALPHA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_set_rows(_png_ptr, _info_ptr, (png_bytep*)_RowPtr);
png_write_png(_png_ptr, _info_ptr, PNG_TRANSFORM_IDENTITY, png_voidp_NULL);



but output is a PNG file that is squashed horizontally and not all colors come out as they should be. the SDL surface is a 32bit RGBA surface. i''m using libpng.

thanks.

Share this post


Link to post
Share on other sites