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
|
|
|
{
|
|
|
|
unsigned char buffer[2];
|
|
|
|
|
|
|
|
if (pFile == NULL) {
|
2017-02-21 23:15:31 +01:00
|
|
|
display_error(WARNING, 101);
|
2016-11-04 11:00:04 +01:00
|
|
|
return UNKN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fread(buffer, 1, 2, pFile) < 2) {
|
|
|
|
return UNKN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer[0] == 0xFF && buffer[1] == 0xD8) {
|
|
|
|
return JPEG;
|
|
|
|
} else if (buffer[0] == 0x89 && buffer[1] == 0x50) {
|
|
|
|
return PNG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNKN;
|
|
|
|
}
|