1
0
forked from 0ad/0ad

improved png write code while searching for cause of bug #24

This was SVN commit r1373.
This commit is contained in:
janwas 2004-11-22 00:10:16 +00:00
parent 73834cee73
commit af56d5829b

View File

@ -855,6 +855,10 @@ static void png_write(png_struct* const png_ptr, u8* const data, const png_size_
png_error(png_ptr, "png_write: !"); png_error(png_ptr, "png_write: !");
} }
static void png_flush(png_structp png_ptr)
{
}
// limitation: palette images aren't supported // limitation: palette images aren't supported
static int png_encode(TexInfo* t, const char* fn, u8* img, size_t img_size) static int png_encode(TexInfo* t, const char* fn, u8* img, size_t img_size)
@ -911,16 +915,15 @@ fail:
err = (int)hf; err = (int)hf;
goto fail; goto fail;
} }
png_set_write_fn(png_ptr, &hf, png_write, 0); png_set_write_fn(png_ptr, &hf, png_write, png_flush);
png_set_IHDR(png_ptr, info_ptr, w, h, 8, color_type, png_set_IHDR(png_ptr, info_ptr, w, h, 8, color_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
CHECK_ERR(alloc_rows(img, h, pitch, rows)); CHECK_ERR(alloc_rows(img, h, pitch, rows));
png_write_image(png_ptr, (png_bytepp)rows); png_set_rows(png_ptr, info_ptr, rows);
png_write_end(png_ptr, info_ptr); png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, 0);
err = 0; err = 0;
@ -928,11 +931,11 @@ fail:
// shared cleanup // shared cleanup
ret: ret:
png_destroy_write_struct(&png_ptr, &info_ptr);
free(rows); free(rows);
vfs_close(hf); vfs_close(hf);
png_destroy_write_struct(&png_ptr, &info_ptr);
return err; return err;
} }