Separated validator and pixeldata finder

This commit is contained in:
Pünkösd Marcell 2020-11-05 19:56:00 +01:00
parent 987a708303
commit 8c64bbfc26
2 changed files with 20 additions and 10 deletions

View File

@ -5,19 +5,14 @@
#include "ciff_tools.h"
#include "utils.h"
uint8_t parse_ciff_from_mem(const uint8_t* data, uint64_t data_len, uint64_t* width, uint64_t* height, uint64_t* pixel_data_starts) {
/**
* Igazából, ezek többnyire csak változatos ellenőrzések
* A függvény validálja a CIFF fájl tartalmát, majd ha ez sikeres volt, akkor megmondja
* - A kép dimenzióit
* - Hogy hol kezdődik a pixel információ a képben
* Az, hogy a kép információt kimásolja-e, az a programozóra van bízva.
*/
uint8_t validate_ciff(const uint8_t* data, uint64_t data_len) {
// Read out the static part of the header (If we have at least header bytes)
if (data_len < sizeof(ciff_static_header_t)) {
return CIFF_PARSE_HEADER_TOO_SHORT;
}
// This is just a pointer with different type information
ciff_static_header_t* header_info = (struct ciff_static_header_t*)data;
// Do some preflight checks
@ -64,6 +59,21 @@ uint8_t parse_ciff_from_mem(const uint8_t* data, uint64_t data_len, uint64_t* wi
return CIFF_PARSE_UNKNOWN_ERROR;
}
return CIFF_PARSE_SUCCESS;
}
uint8_t get_pixel_data_from_ciff(const uint8_t* data, uint64_t data_len, uint64_t* width, uint64_t* height, uint64_t* pixel_data_starts) {
/**
* Ez csak visszad egy pointert, hogy honnan kezdődik a pixel data, miután validálta a képet
*/
uint8_t validate_result = validate_ciff(data, data_len);
if (validate_result != CIFF_PARSE_SUCCESS) {
return validate_result;
}
ciff_static_header_t* header_info = (struct ciff_static_header_t*)data; // This is just a pointer with different type information
// Set return data
*width = header_info->width;
*height = header_info->height;

View File

@ -22,7 +22,7 @@ typedef struct __attribute__ ((packed)) ciff_static_header_t {
uint64_t height;
} ciff_static_header_t;
uint8_t parse_ciff_from_mem(const uint8_t* data, uint64_t data_len, uint64_t* width, uint64_t* height, uint64_t* pixel_data_starts);
uint8_t validate_ciff(const uint8_t* data, uint64_t data_len);
uint8_t get_pixel_data_from_ciff(const uint8_t* data, uint64_t data_len, uint64_t* width, uint64_t* height, uint64_t* pixel_data_starts);
#endif //CAFF_PREVIEWER_CIFF_TOOLS_H