commit a18c512a46c9dfe6f24e3ff1ad07318cd3fd4667
parent 2816c20ff8c70fa2151fe41eca371397cedbb3e3
Author: FRIGN <dev@frign.de>
Date: Tue, 29 Jul 2014 17:30:36 +0200
Fix endianness in header
Well, who would have thought fwrite already converts your integer to
NBO? It would've been bloody helpful to at least mention it in the
manual.
While at it, fix the wrong read-in-code and call it a day.
Diffstat:
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/if2png.c b/if2png.c
@@ -46,8 +46,8 @@ main(int argc, char *argv[])
fprintf(stderr, "invalid magic in header\n");
return EXIT_FAILURE;
}
- width = ntohl((hdr[9] << 0) | (hdr[10] << 8) | (hdr[11] << 16) | (hdr[12] << 24));
- height = ntohl((hdr[13] << 0) | (hdr[14] << 8) | (hdr[15] << 16) | (hdr[16] << 24));
+ width = ntohl((hdr[9] << 24) | (hdr[10] << 16) | (hdr[11] << 8) | (hdr[12] << 0));
+ height = ntohl((hdr[13] << 24) | (hdr[14] << 16) | (hdr[15] << 8) | (hdr[16] << 0));
/* load png */
png_struct_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
diff --git a/png2if.c b/png2if.c
@@ -57,10 +57,8 @@ main(int argc, char *argv[])
/* write header with big endian width and height-values */
fprintf(stdout, "imagefile");
- val_be = htonl(width);
- fwrite(&val_be, sizeof(uint32_t), 1, stdout);
- val_be = htonl(height);
- fwrite(&val_be, sizeof(uint32_t), 1, stdout);
+ fwrite(&width, sizeof(uint32_t), 1, stdout);
+ fwrite(&height, sizeof(uint32_t), 1, stdout);
/* write data */
for (i = 0; i < height; i++) {