Commits

Lars Viklund committed 7481fc5

Add -dt flag for tinting sprites with debug colour

Comments (0)

Files changed (1)

 void Usage();
 void RenderTilemap(TilemapDesc desc);
 
-int main()
+bool debugTint = false;
+
+int main(int argc, char* argv[])
 {
     json_t* p;
     json_error_t error;
 
+    for (int i = 1; i < argc; ++i)
+    {
+        if (argv[i] == std::string("-dt"))
+            debugTint = true;
+    }
+
     p = json_loadf(stdin, 0, &error);
 
     if (! p || ! json_is_object(p))
 
 void BlitImage(unsigned char const* src, int srcWidth, int srcHeight, unsigned char* dst, int dstX, int dstY, int dstPitch, int channels)
 {
+    unsigned char r = rand(), g = rand(), b = rand(), a = 255;
     int srcPitch = srcWidth*channels;
     for (int row = 0; row < srcHeight; ++row)
     {
         unsigned char const* p = src + row*srcPitch;
         unsigned char* q = dst + channels*dstX + (row+dstY)*dstPitch;
         std::copy(p, p + srcPitch, q);
+        if (debugTint)
+        {
+            for (int c = 0; c < srcPitch;)
+            {
+                q[c] = (r+q[c])/2; ++c;
+                q[c] = (g+q[c])/2; ++c;
+                q[c] = (b+q[c])/2; ++c;
+                if (channels > 3)
+                {
+                    q[c] = a; ++c;
+                }
+            }
+        }
     }
 }