comparison tools/lib64fmts.c @ 2080:7e4087e2740d

Define macros DM_MEMCMP_SIZE() and DM_MEMCMP_LEN() as helpers.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Dec 2018 19:36:48 +0200
parents c27ed6465022
children 9dc2976e9fa3
comparison
equal deleted inserted replaced
2079:9b6027d51f76 2080:7e4087e2740d
6 * 6 *
7 * Please read file 'COPYING' for information on license and distribution. 7 * Please read file 'COPYING' for information on license and distribution.
8 */ 8 */
9 #include "lib64gfx.h" 9 #include "lib64gfx.h"
10 10
11 #define DM_MEMCMP_SIZE(mptr, mcmp) memcmp((mptr), (mcmp), sizeof(mcmp))
12 #define DM_MEMCMP_LEN(mptr, mcmp) memcmp((mptr), (mcmp), strlen(mcmp))
11 13
12 static int fmtProbeGigapaintHires(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 14 static int fmtProbeGigapaintHires(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
13 { 15 {
14 if (buf->len == fmt->size && 16 if (buf->len == fmt->size &&
15 dmCompareAddr16(buf, 0, fmt->addr)) 17 dmCompareAddr16(buf, 0, fmt->addr))
33 }; 35 };
34 36
35 static int fmtProbeMicroIllustrator(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 37 static int fmtProbeMicroIllustrator(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
36 { 38 {
37 if (buf->len == fmt->size && 39 if (buf->len == fmt->size &&
38 memcmp(buf->data + 2, fmtMicroIllustratorMagicID_1, sizeof(fmtMicroIllustratorMagicID_1)) == 0 40 DM_MEMCMP_SIZE(buf->data + 2, fmtMicroIllustratorMagicID_1) == 0
39 && 41 &&
40 memcmp(buf->data + 9, fmtMicroIllustratorMagicID_2, sizeof(fmtMicroIllustratorMagicID_2)) == 0 42 DM_MEMCMP_SIZE(buf->data + 9, fmtMicroIllustratorMagicID_2) == 0
41 ) 43 )
42 return DM_PROBE_SCORE_MAX; 44 return DM_PROBE_SCORE_MAX;
43 45
44 return DM_PROBE_SCORE_FALSE; 46 return DM_PROBE_SCORE_FALSE;
45 } 47 }
156 static int fmtProbeDrazPaint20Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 158 static int fmtProbeDrazPaint20Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
157 { 159 {
158 const Uint8 *ident = buf->data + 2; 160 const Uint8 *ident = buf->data + 2;
159 if (buf->len > 22 && 161 if (buf->len > 22 &&
160 dmCompareAddr16(buf, 0, fmt->addr) && 162 dmCompareAddr16(buf, 0, fmt->addr) &&
161 memcmp(ident, "DRAZPAINT ", 10) == 0 && 163 DM_MEMCMP_LEN(ident, "DRAZPAINT ") == 0 &&
162 ident[11] == '.' && ( 164 ident[11] == '.' && (
163 (ident[10] == '1' && ident[12] == '4') || 165 (ident[10] == '1' && ident[12] == '4') ||
164 (ident[10] == '2' && ident[12] == '0') 166 (ident[10] == '2' && ident[12] == '0')
165 )) 167 ))
166 return DM_PROBE_SCORE_MAX; 168 return DM_PROBE_SCORE_MAX;
231 233
232 static int fmtProbeDrazLace10Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 234 static int fmtProbeDrazLace10Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
233 { 235 {
234 if (buf->len > 22 && 236 if (buf->len > 22 &&
235 dmCompareAddr16(buf, 0, fmt->addr) && 237 dmCompareAddr16(buf, 0, fmt->addr) &&
236 memcmp(buf->data + 2, "DRAZLACE! 1.0", 13) == 0) 238 DM_MEMCMP_LEN(buf->data + 2, "DRAZLACE! 1.0") == 0)
237 return DM_PROBE_SCORE_MAX; 239 return DM_PROBE_SCORE_MAX;
238 240
239 return DM_PROBE_SCORE_FALSE; 241 return DM_PROBE_SCORE_FALSE;
240 } 242 }
241 243
267 269
268 static int fmtProbeBDP5Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 270 static int fmtProbeBDP5Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
269 { 271 {
270 if (buf->len > 20 && 272 if (buf->len > 20 &&
271 dmCompareAddr16(buf, 0, fmt->addr) && 273 dmCompareAddr16(buf, 0, fmt->addr) &&
272 memcmp(buf->data + 2, fmtBDP5MagicID, strlen(fmtBDP5MagicID)) == 0) 274 DM_MEMCMP_LEN(buf->data + 2, fmtBDP5MagicID) == 0)
273 return DM_PROBE_SCORE_MAX; 275 return DM_PROBE_SCORE_MAX;
274 276
275 return DM_PROBE_SCORE_FALSE; 277 return DM_PROBE_SCORE_FALSE;
276 } 278 }
277 279
608 0xff, 0xc6, 0xfe 610 0xff, 0xc6, 0xfe
609 }; 611 };
610 612
611 if (buf->len >= 320 && 613 if (buf->len >= 320 &&
612 dmCompareAddr16(buf, 0, fmt->addr) && 614 dmCompareAddr16(buf, 0, fmt->addr) &&
613 memcmp(buf->data + 2, magicID, sizeof(magicID)) == 0) 615 DM_MEMCMP_SIZE(buf->data + 2, magicID) == 0)
614 return DM_PROBE_SCORE_MAX; 616 return DM_PROBE_SCORE_MAX;
615 617
616 return DM_PROBE_SCORE_FALSE; 618 return DM_PROBE_SCORE_FALSE;
617 } 619 }
618 620
786 788
787 789
788 static int fmtProbeFunPaint2(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) 790 static int fmtProbeFunPaint2(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
789 { 791 {
790 if (buf->len > 30 && 792 if (buf->len > 30 &&
791 dmCompareAddr16(buf, 0, fmt->addr) && 793 DM_MEMCMP_LEN(buf->data + 2, fmtFunPaint2MagicID) == 0)
792 memcmp(buf->data + 2, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) == 0)
793 { 794 {
794 // Unpacked variant 795 // Unpacked variant
795 if (fmt->size != 0 && buf->data[14 + 2] == 0) 796 if (fmt->size != 0 && buf->data[14 + 2] == 0)
796 return DM_PROBE_SCORE_MAX; 797 return DM_PROBE_SCORE_MAX;
797 798