61 lines
2.1 KiB
C
61 lines
2.1 KiB
C
/* ************************************************************************** */
|
|
/* _____ _ */
|
|
/* parse/picture_cg.c |_ _|__ _ _| |__ ___ _ _ */
|
|
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
|
|
/* | | (_) | |_| | | | | __/ |_| | */
|
|
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
|
/* Last updated: 2016/11/02 14:47:49 |___/ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#include <libg1m/internals.h>
|
|
|
|
/**
|
|
* g1m_parse_g3p:
|
|
* Parse a G3P file.
|
|
*
|
|
* @arg handle the handle.
|
|
* @arg stream the stream to parse from.
|
|
* @arg std the standard header.
|
|
* @return the error code (0 if ok).
|
|
*/
|
|
|
|
int g1m_parse_g3p(g1m_t *handle, FILE *stream,
|
|
struct standard_header *std)
|
|
{
|
|
/* get the header and footer */
|
|
DREAD(hd, g3p_subheader)
|
|
|
|
/* correct endianess */
|
|
hd.control = be32toh(hd.control);
|
|
hd.width = be16toh(hd.width);
|
|
hd.height = be16toh(hd.height);
|
|
hd.color_depth = be16toh(hd.color_depth);
|
|
hd.dimage_length = be32toh(hd.dimage_length);
|
|
|
|
/* check control */
|
|
if (memcmp(hd.magic, "CP", 2)) {
|
|
log_info("could not read CP.");
|
|
return (g1m_error_magic);
|
|
} else if (memcmp(hd.magic, "0100", 4)) {
|
|
log_info("could not read header 0100");
|
|
return (g1m_error_magic);
|
|
}
|
|
|
|
/* TODO: what about "length of packed data + 4" control? */
|
|
/* TODO: get footer, check control 0100 */
|
|
|
|
/* check if image is encrypted */
|
|
int is_encrypted = (((std->filesize & 0xff) +
|
|
((std->filesize & 0xff00) >> 8) + g1m_type_g3p) & 0xff) ^ 0x1c;
|
|
|
|
/* log info */
|
|
log_info("Width: %dpx, height: %dpx", hd.width, hd.height);
|
|
log_info("Pixel depth: %s",
|
|
(hd.color_depth == g3p_color_4bit) ? "4-bit" : "16-bit");
|
|
log_info("Deflated image length: %uo", hd.dimage_length);
|
|
log_info("Is encrypted: %s", is_encrypted ? "yes" : "no");
|
|
|
|
/* no error */
|
|
return (0);
|
|
}
|