# HG changeset patch # User Matti Hamalainen # Date 1526376629 -10800 # Node ID 70b04c16aa40ee04350b3ad518727a095cf7f9cc # Parent 749f8f808531398fdd2c130f1ce2a114a8bd95d2 Move format probe functions near to their other functions. diff -r 749f8f808531 -r 70b04c16aa40 tools/libgfx.c --- a/tools/libgfx.c Tue May 15 12:00:43 2018 +0300 +++ b/tools/libgfx.c Tue May 15 12:30:29 2018 +0300 @@ -411,6 +411,23 @@ #ifdef DM_USE_LIBPNG +static int fmtProbePNG(const Uint8 *buf, const size_t len) +{ + if (len > 64 && buf[0] == 0x89 && + buf[1] == 'P' && buf[2] == 'N' && buf[3] == 'G' && + buf[4] == 0x0d && buf[5] == 0x0a) + { + if (buf[12] == 'I' && buf[13] == 'H' && + buf[14] == 'D' && buf[15] == 'R') + return DM_PROBE_SCORE_MAX; + else + return DM_PROBE_SCORE_GOOD; + } + + return DM_PROBE_SCORE_FALSE; +} + + static int dmWritePNGRow(void *cbdata, const Uint8 *row, const size_t len) { png_structp png_ptr = cbdata; @@ -764,6 +781,9 @@ #endif +// +// Z-Soft PCX format +// #define DMPCX_PAL_COLORS 16 // Number of internal palette colors typedef struct @@ -805,6 +825,20 @@ } DMPCXData; +static int fmtProbePCX(const Uint8 *buf, const size_t len) +{ + if (len > 128 + 32 && + + (buf[1] == 5 || buf[1] == 2 || buf[1] == 3) && + buf[2] == 1 && + (buf[3] == 8 || buf[3] == 4 || buf[3] == 3 || buf[3] == 1) && + buf[65] >= 1 && buf[65] <= 4) + return DM_PROBE_SCORE_GOOD; + + return DM_PROBE_SCORE_FALSE; +} + + // Returns one byte from row buffer (of length len) at offset soffs, // OR zero if the offset is outside buffer. static inline Uint8 dmPCXGetByte(const Uint8 *row, const size_t len, const size_t soffs) @@ -1374,6 +1408,9 @@ } +// +// IFF ILBM / PBM format +// #define IFF_ID_FORM 0x464F524D // "FORM" #define IFF_ID_ILBM 0x494C424D // "ILBM" #define IFF_ID_PBM 0x50424D20 // "PBM " @@ -1428,6 +1465,26 @@ } DMIFF; +static int fmtProbeILBM(const Uint8 *buf, const size_t len) +{ + if (len > 32 && + buf[ 0] == 'F' && buf[ 1] == 'O' && + buf[ 2] == 'R' && buf[ 3] == 'M' && ( + (buf[ 8] == 'I' && buf[ 9] == 'L' && buf[10] == 'B' && buf[11] == 'M') || + (buf[ 8] == 'P' && buf[ 9] == 'B' && buf[10] == 'M' && buf[11] == 0x20) + )) + { + if (buf[12] == 'B' && buf[13] == 'M' && + buf[14] == 'H' && buf[15] == 'D') + return DM_PROBE_SCORE_MAX; + else + return DM_PROBE_SCORE_GOOD; + } + + return DM_PROBE_SCORE_FALSE; +} + + static BOOL dmReadIFFChunk(DMResource *fp, DMIFFChunk *chunk) { if (!dmf_read_be32(fp, &chunk->id) || @@ -1932,57 +1989,9 @@ } -static int fmtProbePNG(const Uint8 *buf, const size_t len) -{ - if (len > 64 && buf[0] == 0x89 && - buf[1] == 'P' && buf[2] == 'N' && buf[3] == 'G' && - buf[4] == 0x0d && buf[5] == 0x0a) - { - if (buf[12] == 'I' && buf[13] == 'H' && - buf[14] == 'D' && buf[15] == 'R') - return DM_PROBE_SCORE_MAX; - else - return DM_PROBE_SCORE_GOOD; - } - - return DM_PROBE_SCORE_FALSE; -} - - -static int fmtProbePCX(const Uint8 *buf, const size_t len) -{ - if (len > 128 + 32 && - - (buf[1] == 5 || buf[1] == 2 || buf[1] == 3) && - buf[2] == 1 && - (buf[3] == 8 || buf[3] == 4 || buf[3] == 3 || buf[3] == 1) && - buf[65] >= 1 && buf[65] <= 4) - return DM_PROBE_SCORE_GOOD; - - return DM_PROBE_SCORE_FALSE; -} - - -static int fmtProbeILBM(const Uint8 *buf, const size_t len) -{ - if (len > 32 && - buf[ 0] == 'F' && buf[ 1] == 'O' && - buf[ 2] == 'R' && buf[ 3] == 'M' && ( - (buf[ 8] == 'I' && buf[ 9] == 'L' && buf[10] == 'B' && buf[11] == 'M') || - (buf[ 8] == 'P' && buf[ 9] == 'B' && buf[10] == 'M' && buf[11] == 0x20) - )) - { - if (buf[12] == 'B' && buf[13] == 'M' && - buf[14] == 'H' && buf[15] == 'D') - return DM_PROBE_SCORE_MAX; - else - return DM_PROBE_SCORE_GOOD; - } - - return DM_PROBE_SCORE_FALSE; -} - - +// +// List of formats +// DMImageFormat dmImageFormatList[DM_IMGFMT_LAST] = { {