diff options
-rwxr-xr-x | dyecmd/src/dye.cpp | 29 | ||||
-rwxr-xr-x | testxml/testxml.py | 2 |
2 files changed, 29 insertions, 2 deletions
diff --git a/dyecmd/src/dye.cpp b/dyecmd/src/dye.cpp index 77da2eb..760ff23 100755 --- a/dyecmd/src/dye.cpp +++ b/dyecmd/src/dye.cpp @@ -22,6 +22,7 @@ #include <algorithm> #include <sstream> #include <iostream> +#include <stdio.h> #include "dye.h" @@ -80,29 +81,46 @@ Palette::Palette(const std::string &description) void Palette::getColor(int intensity, int color[3]) const { + printf ("---------------------------------------------\n"); + printf ("intensity=%x\n", intensity); + printf ("image color: %x, %x, %x\n", color[0], color[1], color[2]); + // Return implicit black if (intensity == 0) { color[0] = 0; color[1] = 0; color[2] = 0; + printf ("set color to zero\n"); return; } int last = mColors.size(); - if (last == 0) return; + printf ("last=%d\n", last); + if (last == 0) + return; int i = intensity * last / 255; int t = intensity * last % 255; + printf ("i = intensity * last / 255 = %d\n", i); + printf ("t = intensity * last %% 255 = %d\n", t); + int j = t != 0 ? i : i - 1; + printf ("j = t != 0 ? i : i - 1 = %d\n", j); // Get the exact color if any, the next color otherwise. int r2 = mColors[j].value[0], g2 = mColors[j].value[1], b2 = mColors[j].value[2]; + printf ("read from palate at j (%d)\n", j); + printf ("r2 = mColors[j].value[0]=%x\n", r2); + printf ("g2 = mColors[j].value[1]=%x\n", g2); + printf ("b2 = mColors[j].value[2]=%x\n", b2); + if (t == 0) { + printf ("t == 0, return rgb = %x, %x, %x\n", r2, g2, b2); // Exact color. color[0] = r2; color[1] = g2; @@ -112,17 +130,26 @@ void Palette::getColor(int intensity, int color[3]) const // Get the previous color. First color is implicitly black. int r1 = 0, g1 = 0, b1 = 0; + printf ("r1=g1=b1=0\n"); if (i > 0) { r1 = mColors[i - 1].value[0]; g1 = mColors[i - 1].value[1]; b1 = mColors[i - 1].value[2]; + printf ("read from palate at i-1 (%d)\n", i - 1); + printf ("r1 = mColors[i - 1].value[0] = %x\n", r1); + printf ("g1 = mColors[i - 1].value[1] = %x\n", g1); + printf ("b1 = mColors[i - 1].value[2] = %x\n", b1); } // Perform a linear interpolation. color[0] = ((255 - t) * r1 + t * r2) / 255; color[1] = ((255 - t) * g1 + t * g2) / 255; color[2] = ((255 - t) * b1 + t * b2) / 255; + printf ("result color:\n"); + printf ("color[0] = ((255 - t) * r1 + t * r2) / 255 = %d * %d + %d * %d = %x\n", 255 - t, r1, t, r2, color[0]); + printf ("color[1] = ((255 - t) * g1 + t * g2) / 255 = %d * %d + %d * %d = %x\n", 255 - t, g1, t, g2, color[1]); + printf ("color[2] = ((255 - t) * b1 + t * b2) / 255 = %d * %d + %d * %d = %x\n", 255 - t, b1, t, b2, color[2]); } Dye::Dye(const std::string &description) diff --git a/testxml/testxml.py b/testxml/testxml.py index 38326e8..9c64849 100755 --- a/testxml/testxml.py +++ b/testxml/testxml.py @@ -554,7 +554,7 @@ def testSpriteAction(file, name, action, numframes, iserr): if idx >= numframes or idx < 0: showMsgSprite(file, "incorrect frame index " + str(idx) + \ - " aciton: " + name + ", direction: "\ + " action: " + name + ", direction: "\ + direction, iserr) else: framesid.add(idx) |