changeset 2091:3b3acb6b4ba0

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 28 Feb 2019 12:18:27 +0200
parents 0d7c73f42a0b
children 614b161c0aa5
files tools/libgfx.c
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/tools/libgfx.c	Mon Feb 25 12:43:08 2019 +0200
+++ b/tools/libgfx.c	Thu Feb 28 12:18:27 2019 +0200
@@ -114,6 +114,12 @@
 }
 
 
+int dmImageGetBitsPerPixel(const int format)
+{
+    return dmImageGetBytesPerPixel(format) * 8;
+}
+
+
 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp)
 {
     DMImage *img = dmMalloc0(sizeof(DMImage));
@@ -204,7 +210,9 @@
 }
 
 
-int dmWriteImageData(const DMImage *img, void *cbdata, int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageConvSpec *spec)
+int dmWriteImageData(const DMImage *img, void *cbdata,
+    int (*writeRowCB)(void *, const Uint8 *, const size_t),
+    const DMImageConvSpec *spec)
 {
     int x, y, yscale, xscale, res = 0, rowSize, rowWidth;
     Uint8 *row = NULL;
@@ -625,7 +633,7 @@
     png_set_IHDR(png_ptr, info_ptr,
         img->width * spec->scaleX,
         img->height * spec->scaleY,
-        8,                    /* bits per component */
+        8, // bits per component: TODO: FIXME: calculate and use
         fmt,
         PNG_INTERLACE_NONE,
         PNG_COMPRESSION_TYPE_DEFAULT,
@@ -849,6 +857,7 @@
         png_get_tRNS(png_ptr, info_ptr, &trans, &ntrans, NULL);
         if (trans != NULL && ntrans > 0)
         {
+            dmMsg(2, "PNG: %d transparent colors.\n", ntrans);
             for (i = 0; i < img->ncolors && i < ntrans; i++)
             {
                 img->pal[i].a = trans[i];
@@ -880,15 +889,16 @@
 
 typedef struct
 {
-    Uint8 manufacturer,     // always 0x0a
-            version,        // Z-Soft PC Paintbrush version:
+    Uint8
+        manufacturer,       // always 0x0a
+        version,            // Z-Soft PC Paintbrush version:
                             // 0 = v2.5
                             // 2 = v2.8 with palette,
                             // 3 = v2.8 without palette
                             // 4 = PC Paintbrush for Windows
                             // 5 = v3.0 or better
-            encoding,       // usually 0x01 = RLE, 0x00 = uncompressed
-            bitsPerPlane;   // bits per pixel per plane
+        encoding,           // usually 0x01 = RLE, 0x00 = uncompressed
+        bitsPerPlane;       // bits per pixel per plane
 
     Uint16 xmin, ymin, xmax, ymax;
     Uint16 hres, vres;      // resolution in DPI, can be image dimensions as well.
@@ -914,7 +924,6 @@
 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) &&