diff options
author | FRIGN <dev@frign.de> | 2015-11-10 18:35:22 +0100 |
---|---|---|
committer | FRIGN <dev@frign.de> | 2015-11-10 18:35:22 +0100 |
commit | bc58a701d118e074c935bf29af095d72b95f8a31 (patch) | |
tree | 85c0ee68b37f2c702137be2aeef20ea53eed385c | |
parent | 372aec2290b9215335a7fbc3c3f42da629b0aa5f (diff) |
Fix 16-bit RGB-expands and header-endianness properly
-rw-r--r-- | ff2png.c | 7 | ||||
-rw-r--r-- | png2ff.c | 3 |
2 files changed, 6 insertions, 4 deletions
@@ -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); } @@ -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); } } |