changeset 2098:e38705223ce4

Support grayscale output.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Mar 2019 12:14:31 +0200
parents f43011ea9b9f
children dac89484f143
files tools/libgfx.c
diffstat 1 files changed, 66 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tools/libgfx.c	Tue Mar 05 10:54:47 2019 +0200
+++ b/tools/libgfx.c	Tue Mar 05 12:14:31 2019 +0200
@@ -336,8 +336,72 @@
                 *ptr3 = ptr2 + rowWidth,
                 *ptr4 = ptr3 + rowWidth;
 
-        if (img->format == DM_COLFMT_PALETTE ||
-            img->format == DM_COLFMT_GRAYSCALE)
+        if (img->format == DM_COLFMT_GRAYSCALE)
+        {
+            for (x = 0; x < img->width; x++)
+            {
+                Uint8 c = img->data[(y * img->pitch) + (x * img->bpp) / 8];
+
+                switch (spec->format)
+                {
+                    case DM_COLFMT_PALETTE:
+                    case DM_COLFMT_GRAYSCALE:
+                        for (xscale = 0; xscale < spec->scaleX; xscale++)
+                            *ptr1++ = c;
+                        break;
+
+                    case DM_COLFMT_RGBA:
+                        if (spec->planar)
+                        {
+                            for (xscale = 0; xscale < spec->scaleX; xscale++)
+                            {
+                                *ptr1++ = c;
+                                *ptr2++ = c;
+                                *ptr3++ = c;
+                                *ptr4++ = 0xff;
+                            }
+                        }
+                        else
+                        {
+                            for (xscale = 0; xscale < spec->scaleX; xscale++)
+                            {
+                                *ptr1++ = c;
+                                *ptr1++ = c;
+                                *ptr1++ = c;
+                                *ptr1++ = 0xff;
+                            }
+                        }
+                        break;
+
+                    case DM_COLFMT_RGB:
+                        if (spec->planar)
+                        {
+                            for (xscale = 0; xscale < spec->scaleX; xscale++)
+                            {
+                                *ptr1++ = c;
+                                *ptr2++ = c;
+                                *ptr3++ = c;
+                            }
+                        }
+                        else
+                        {
+                            for (xscale = 0; xscale < spec->scaleX; xscale++)
+                            {
+                                *ptr1++ = c;
+                                *ptr1++ = c;
+                                *ptr1++ = c;
+                            }
+                        }
+                        break;
+
+                    default:
+                        res = DMERR_NOT_SUPPORTED;
+                        goto done;
+                }
+            }
+        }
+        else
+        if (img->format == DM_COLFMT_PALETTE)
         {
             for (x = 0; x < img->width; x++)
             {