summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Reckase <e.reckase@gmail.com>2010-11-21 13:50:22 +0000
committerScott Draves <spot@draves.org>2015-02-15 12:20:14 -0500
commitba1a8451bf2054193a8215995e1edb1d4661e0e2 (patch)
treefe05c20fe585274cf00e271787e9722565d9133a
parenta327e855a963a29d85a54a468abaaf40c2b0480e (diff)
downloadpucket-ba1a8451bf2054193a8215995e1edb1d4661e0e2.tar.gz
pucket-ba1a8451bf2054193a8215995e1edb1d4661e0e2.tar.bz2
pucket-ba1a8451bf2054193a8215995e1edb1d4661e0e2.zip
png_set_swap must be called after the png_write_info call, otherwise it doesn't work. Would have been nice if this was documented a bit better. No more brute force byte swapping!
git-svn-id: https://flam3.googlecode.com/svn/trunk@90 77852712-ef1d-11de-8684-7d64432d61a3
-rwxr-xr-xsrc/png.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/png.c b/src/png.c
index 8eee7c7..23ff489 100755
--- a/src/png.c
+++ b/src/png.c
@@ -99,31 +99,21 @@ void write_png(FILE *file, void *image, int width, int height, flam3_img_comment
PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
- /* Swap the bytes if we're doing 16bpc and on little-endian platform */
- if (2==bpc && testbe != htons(testbe)) {
- unsigned short *im = (unsigned short *)image;
- for (i=0; i<height*width*4; i++) {
- im[i] = htons(im[i]);
- }
- }
-
if (pngcom_enable==1)
png_set_text(png_ptr, info_ptr, text, FLAM3_PNG_COM);
png_write_info(png_ptr, info_ptr);
+
+ /* Must set this after the write_info */
+ if (2==bpc && testbe != htons(testbe)) {
+ png_set_swap(png_ptr);
+ }
+
png_write_image(png_ptr, (png_bytepp) rows);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
free(rows);
- /* Swap back the bytes in case we're doing strips */
- if (2==bpc && testbe != htons(testbe)) {
- unsigned short *im = (unsigned short *)image;
- for (i=0; i<height*width*4; i++) {
- im[i] = htons(im[i]);
- }
- }
-
}
#define SIG_CHECK_SIZE 8