farbfeld

suckless image format with conversion tools
git clone git://git.suckless.org/farbfeld
Log | Files | Refs | README | LICENSE

commit 9f7647d61eb07195fc46cd4d9ad73aab06f2f779
parent a18c512a46c9dfe6f24e3ff1ad07318cd3fd4667
Author: sin <sin@2f30.org>
Date:   Tue, 29 Jul 2014 17:25:22 +0100

Revert "Fix endianness in header"

The previous behaviour was correct.  A width of 1900 pixels which is
0x00000640 in hex was stored on disk as:

00 00 06 40

That's BE order which is what we want.

Reading this uint32_t on an LE machine we get:

width = 0x40060000 and converting from BE to LE

we get the correct 0x640 value.

Reading on a BE machine we get the correct value
and the swap is a no-op.

Diffstat:
Mif2png.c | 4++--
Mpng2if.c | 6++++--
2 files changed, 6 insertions(+), 4 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] << 24) | (hdr[10] << 16) | (hdr[11] << 8) | (hdr[12] << 0)); - height = ntohl((hdr[13] << 24) | (hdr[14] << 16) | (hdr[15] << 8) | (hdr[16] << 0)); + 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)); /* 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,8 +57,10 @@ main(int argc, char *argv[]) /* write header with big endian width and height-values */ fprintf(stdout, "imagefile"); - fwrite(&width, sizeof(uint32_t), 1, stdout); - fwrite(&height, sizeof(uint32_t), 1, stdout); + val_be = htonl(width); + fwrite(&val_be, sizeof(uint32_t), 1, stdout); + val_be = htonl(height); + fwrite(&val_be, sizeof(uint32_t), 1, stdout); /* write data */ for (i = 0; i < height; i++) {