diff tools/libgfx.c @ 1616:36d073c45327

Refactor the format handling a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 15 May 2018 14:29:32 +0300
parents 2f8f2f7a42c8
children 4c96181c9c09
line wrap: on
line diff
--- a/tools/libgfx.c	Tue May 15 12:38:55 2018 +0300
+++ b/tools/libgfx.c	Tue May 15 14:29:32 2018 +0300
@@ -1988,59 +1988,64 @@
 //
 // List of formats
 //
-DMImageFormat dmImageFormatList[DM_IMGFMT_LAST] =
+const DMImageFormat dmImageFormatList[] =
 {
+#ifdef DM_USE_LIBPNG
     {
-        "PNG", "Portable Network Graphics",
+        "png", "Portable Network Graphics",
+        DM_IMGFMT_PNG, DM_FMT_RDWR,
         fmtProbePNG,
-#ifdef DM_USE_LIBPNG
         dmReadPNGImage, dmReadPNGImageFILE,
         dmWritePNGImage, dmWritePNGImageFILE,
-#else
-        NULL, NULL,
-        NULL, NULL,
+    },
 #endif
-    },
     {
-        "PPM", "Portable PixMap",
+        "ppm", "Portable PixMap",
+        DM_IMGFMT_PPM, DM_FMT_WR,
         NULL,
         NULL, NULL,
         dmWritePPMImage, dmWritePPMImageFILE,
     },
     {
-        "PCX", "Z-Soft Paintbrush",
+        "pcx", "Z-Soft Paintbrush",
+        DM_IMGFMT_PCX, DM_FMT_RDWR,
         fmtProbePCX,
         dmReadPCXImage, dmReadPCXImageFILE,
         dmWritePCXImage, dmWritePCXImageFILE,
     },
     {
-        "ILBM", "IFF ILBM",
+        "lbm", "IFF ILBM / PBM",
+        DM_IMGFMT_ILBM, DM_FMT_RD,
         fmtProbeILBM,
         dmReadILBMImage, dmReadILBMImageFILE,
         NULL, NULL,
     },
     {
-        "RAW", "Plain bitplaned (planar or non-planar) RAW",
+        "raw", "Plain bitplaned (planar or non-planar) RAW",
+        DM_IMGFMT_RAW, DM_FMT_WR,
         NULL,
         NULL, NULL,
         dmWriteRAWImage, dmWriteRAWImageFILE,
     },
     {
-        "ARAW", "IFFMaster Amiga RAW",
+        "araw", "IFFMaster Amiga RAW",
+        DM_IMGFMT_ARAW, DM_FMT_WR,
         NULL,
         NULL, NULL,
         dmWriteRAWImage, dmWriteRAWImageFILE,
     }
 };
 
+const int ndmImageFormatList = sizeof(dmImageFormatList) / sizeof(dmImageFormatList[0]);
 
-int dmImageProbeGeneric(const Uint8 *buf, const size_t len, DMImageFormat **pfmt, int *index)
+
+int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **pfmt, int *index)
 {
-    int i, scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1;
+    int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1;
 
-    for (i = 0; i < DM_IMGFMT_LAST; i++)
+    for (int i = 0; i < ndmImageFormatList; i++)
     {
-        DMImageFormat *fmt = &dmImageFormatList[i];
+        const DMImageFormat *fmt = &dmImageFormatList[i];
         if (fmt->probe != NULL)
         {
             int score = fmt->probe(buf, len);