diff options
author | Laslo Hunhold <dev@frign.de> | 2017-03-30 09:49:48 +0200 |
---|---|---|
committer | Laslo Hunhold <dev@frign.de> | 2017-03-30 09:49:48 +0200 |
commit | d25f3c73afa5beb83121c9b033bc0146c755ca3a (patch) | |
tree | 2d2407a2d07cb87f3da44e98cdd6131b3c9e5bd3 /ff2ppm.c | |
parent | d0ce307972fbc95073666e92043fc7012ffbefdf (diff) |
Add util.{c|h} to deduplicate code
Diffstat (limited to 'ff2ppm.c')
-rw-r--r-- | ff2ppm.c | 16 |
1 files changed, 3 insertions, 13 deletions
@@ -9,8 +9,7 @@ #include <string.h> #include "arg.h" - -char *argv0; +#include "util.h" static void usage(void) @@ -24,7 +23,7 @@ main(int argc, char *argv[]) { size_t rowlen; uint64_t a; - uint32_t hdr[4], width, height, i, j, k, l; + uint32_t width, height, i, j, k, l; uint16_t *row, mask[3] = { 0xffff, 0xffff, 0xffff }; uint8_t *rowout; char *color, colfmt[] = "%#x%#x%#x"; @@ -58,16 +57,7 @@ main(int argc, char *argv[]) if (argc) usage(); - /* header */ - if (fread(hdr, sizeof(*hdr), 4, stdin) != 4) { - goto readerr; - } - if (memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) { - fprintf(stderr, "%s: invalid magic value\n", argv0); - return 1; - } - width = ntohl(hdr[2]); - height = ntohl(hdr[3]); + read_ff_header(&width, &height); if (width > SIZE_MAX / ((sizeof("RGBA") - 1) * sizeof(uint16_t))) { fprintf(stderr, "%s: row length integer overflow\n", argv0); |