Skip to content

Commit

Permalink
image.c: Modify the code as reviewer suggested and remove FIXME comme…
Browse files Browse the repository at this point in the history
…nt description
  • Loading branch information
Damien-Chen committed Aug 22, 2024
1 parent aeab1e2 commit cbbf7ff
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit cbbf7ff

Please sign in to comment.