kwo pushed a commit to branch master. http://git.enlightenment.org/legacy/imlib2.git/commit/?id=c4e4741cc8451e98c94974e588fd150f4f0e1c7d
commit c4e4741cc8451e98c94974e588fd150f4f0e1c7d Author: Kim Woelders <[email protected]> Date: Tue Sep 14 18:13:22 2021 +0200 FF loader: Cosmetics --- src/modules/loaders/loader_ff.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/modules/loaders/loader_ff.c b/src/modules/loaders/loader_ff.c index 18a3a78..f0e8f78 100644 --- a/src/modules/loaders/loader_ff.c +++ b/src/modules/loaders/loader_ff.c @@ -1,17 +1,20 @@ /* Farbfeld (http://tools.suckless.org/farbfeld) */ -#include <arpa/inet.h> -#include <stdint.h> - #include "loader_common.h" +#include <stdint.h> +#include <arpa/inet.h> -#define LEN(x) (sizeof((x)) / sizeof(*(x))) +typedef struct { + unsigned char magic[8]; + uint32_t w, h; +} ff_hdr_t; int load2(ImlibImage * im, int load_data) { int rc; - size_t rowlen, i, j; - uint32_t hdr[2 + 1 + 1], w, h; + int rowlen, i, j; + ff_hdr_t hdr_; + const ff_hdr_t *hdr; uint16_t *row; uint8_t *dat; @@ -19,12 +22,15 @@ load2(ImlibImage * im, int load_data) row = NULL; /* read and check the header */ - if (fread(hdr, sizeof(uint32_t), LEN(hdr), im->fp) != LEN(hdr) || - memcmp("farbfeld", hdr, sizeof("farbfeld") - 1)) + hdr = &hdr_; + if (fread(&hdr_, 1, sizeof(ff_hdr_t), im->fp) != sizeof(ff_hdr_t)) + goto quit; + + if (memcmp("farbfeld", hdr->magic, sizeof(hdr->magic))) goto quit; - im->w = ntohl(hdr[2]); - im->h = ntohl(hdr[3]); + im->w = ntohl(hdr->w); + im->h = ntohl(hdr->h); if (!IMAGE_DIMENSIONS_OK(im->w, im->h)) goto quit; @@ -38,19 +44,17 @@ load2(ImlibImage * im, int load_data) /* Load data */ - w = im->w; - h = im->h; - rowlen = w * (sizeof("RGBA") - 1); - if (!__imlib_AllocateData(im)) goto quit; + rowlen = 4 * im->w; /* RGBA */ + row = malloc(rowlen * sizeof(uint16_t)); if (!row) goto quit; dat = (uint8_t *) im->data; - for (i = 0; i < h; i++, dat += rowlen) + for (i = 0; i < im->h; i++, dat += rowlen) { if (fread(row, sizeof(uint16_t), rowlen, im->fp) != (size_t)rowlen) goto quit; --
