libcaesium/caesium/utils.c

28 lines
447 B
C
Raw Normal View History

2016-11-04 11:00:04 +01:00
#include <stdlib.h>
#include <stdio.h>
#include "utils.h"
#include "error.h"
2016-11-13 14:43:54 +01:00
image_type detect_image_type(FILE *pFile)
2016-11-04 11:00:04 +01:00
{
2017-03-18 19:51:18 +01:00
unsigned char buffer[2];
2016-11-04 11:00:04 +01:00
if (pFile == NULL) {
libcaesium_display_error(WARNING, 101);
2016-11-04 11:00:04 +01:00
return UNKN;
}
2017-03-18 19:51:18 +01:00
if (fread(buffer, 1, 2, pFile) < 2) {
2016-11-04 11:00:04 +01:00
return UNKN;
}
2017-03-07 11:33:58 +01:00
if (buffer[0] == 0xFF && buffer[1] == 0xD8) {
2017-02-25 10:17:33 +01:00
return CS_JPEG;
2016-11-04 11:00:04 +01:00
} else if (buffer[0] == 0x89 && buffer[1] == 0x50) {
2017-02-25 10:17:33 +01:00
return CS_PNG;
2016-11-04 11:00:04 +01:00
}
return UNKN;
}