summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFRIGN <dev@frign.de>2015-11-10 18:35:22 +0100
committerFRIGN <dev@frign.de>2015-11-10 18:35:22 +0100
commitbc58a701d118e074c935bf29af095d72b95f8a31 (patch)
tree85c0ee68b37f2c702137be2aeef20ea53eed385c
parent372aec2290b9215335a7fbc3c3f42da629b0aa5f (diff)
Fix 16-bit RGB-expands and header-endianness properly
-rw-r--r--ff2png.c7
-rw-r--r--png2ff.c3
2 files changed, 6 insertions, 4 deletions
diff --git a/ff2png.c b/ff2png.c
index 4cbbf22..abf2f09 100644
--- a/ff2png.c
+++ b/ff2png.c
@@ -46,8 +46,8 @@ main(int argc, char *argv[])
fprintf(stderr, "invalid magic in header\n");
return 1;
}
- width = be32toh((hdr[9] << 0) | (hdr[10] << 8) | (hdr[11] << 16) | (hdr[12] << 24));
- height = be32toh((hdr[13] << 0) | (hdr[14] << 8) | (hdr[15] << 16) | (hdr[16] << 24));
+ width = be32toh(*((uint32_t *)(hdr + 8)));
+ height = be32toh(*((uint32_t *)(hdr + 12)));
/* load png */
png_struct_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@@ -76,7 +76,8 @@ main(int argc, char *argv[])
fprintf(stderr, "unexpected EOF or row-skew\n");
return 1;
}
- png_row[j] = be16toh(tmp16) / (1 << 8);
+ /* ((2^16-1) / 255) == 257 */
+ png_row[j] = (uint8_t)(be16toh(tmp16) / 257);
}
png_write_row(png_struct_p, png_row);
}
diff --git a/png2ff.c b/png2ff.c
index 52f1781..3d5e35f 100644
--- a/png2ff.c
+++ b/png2ff.c
@@ -64,7 +64,8 @@ main(int argc, char *argv[])
/* TODO: allow 16 bit PNGs to be converted losslessly */
for (r = 0; r < height; ++r) {
for (i = 0; i < png_row_len; i++) {
- tmp16 = htobe16((uint16_t)png_row_p[r][i]);
+ /* ((2^16-1) / 255) == 257 */
+ tmp16 = htobe16(257 * png_row_p[r][i]);
fwrite(&tmp16, sizeof(uint16_t), 1, stdout);
}
}