#include <string.h>
+#include <stdint.h>
#include "kds_s2000w_image_type_check.h"
+#define TIFF_SIG_LEN 4
+#define PNM_SIG_LEN 2
+#define JPEG_SIG_LEN 2
+
bool kds_s2000w_image_type_check_is_tiff(const blobdata_t* image)
{
- if (image->size < 4)
+ if (image->size < TIFF_SIG_LEN)
return false;
- const char* image_data = (const char*) image->data;
- bool result = image_data[0] == (char)0x49;
- result = result && image_data[1] == (char)0x49;
- result = result && image_data[2] == (char)0x2A;
- return result && image_data[3] == (char)0x00;
+ const uint8_t tiff_sig[] = {0x49, 0x49, 0x2a, 0x00};
+ return memcmp(image->data, tiff_sig, TIFF_SIG_LEN) == 0;
}
bool kds_s2000w_image_type_check_is_pnm(const blobdata_t* image)
{
- if (image->size < 2)
+ if (image->size < PNM_SIG_LEN)
return false;
- const char* image_data = (const char*) image->data;
- return strncmp(image_data, "P4", 2) == 0
- || (strncmp(image_data, "P6", 2) == 0);
+ return memcmp(image->data, "P4", PNM_SIG_LEN) == 0
+ || memcmp(image->data, "P6", PNM_SIG_LEN) == 0;
}
bool kds_s2000w_image_type_check_is_jpeg(const blobdata_t* image)
{
- if (image->size < 2)
+ if (image->size < JPEG_SIG_LEN)
return false;
- const char* image_data = (const char*) image->data;
- bool result = image_data[0] == (char)0xff;
- return result && image_data[1] == (char)0xd8;
+ const uint8_t jpeg_sig[] = {0xff, 0xd8};
+ return memcmp(image->data, jpeg_sig, JPEG_SIG_LEN) == 0;
}
\ No newline at end of file