diff --git a/src/image.c b/src/image.c index 117a510..f393d3c 100644 --- a/src/image.c +++ b/src/image.c @@ -31,9 +31,7 @@ typedef enum { #undef _ } twin_image_format_t; -/* FIXME: Check the header of the given images to determine the supported image - * formats instead of parsing the filename without checking its content. - */ + static twin_image_format_t image_type_from_name(const char *path) { twin_image_format_t type = IMAGE_TYPE_unknown; @@ -55,20 +53,18 @@ static twin_image_format_t image_type_from_name(const char *path) #if LOADER_HAS(PNG) #if __BYTE_ORDER == __BIG_ENDIAN uint8_t png_header[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; - if (memcmp(header, png_header, sizeof(png_header)) == 0) { - type = IMAGE_TYPE_png; - } #else uint8_t png_header[8] = {0x0A, 0x1A, 0x0A, 0x0D, 0x47, 0x4E, 0x50, 0x89}; - if (memcmp(header, png_header, sizeof(png_header)) == 0) { +#endif + + if (!memcmp(header, png_header, sizeof(png_header))) { type = IMAGE_TYPE_png; } #endif -#endif #if LOADER_HAS(JPEG) uint8_t jpg_header[3] = {0xFF, 0xD8, 0xFF}; - if (memcmp(header, jpg_header, sizeof(jpg_header)) == 0) { + if (!memcmp(header, jpg_header, sizeof(jpg_header))) { type = IMAGE_TYPE_jpeg; } #endif