[patch] Text renders in "random" colors #279

Closed
zebediah49 opened this Issue Nov 19, 2012 · 0 comments

Comments

Projects
None yet
2 participants

Text was rendering in really strange colors. I tracked it down to a bug in text.cpp, where a 0-1 float was being directly assigned from a 0-255 unit8:

uint8_t* buffer = bitmap->buffer;
.......
    for (pos_t y = 0; y < s_bitmap_rows && y < image->get_height() + pen_y; y++) {
      for (pos_t x = 0; x < s_bitmap_width && x < image->get_width() + pen_x; x++) {
        color c(base);
        c.a = buffer[x + y * bitmap->width]; //THIS LINE
        image->safe_blend_pixel(pen_x + x, pen_y + y, c);

Converting the value using the color_i_to_f array resolves the issue:

        c.a = color_i_to_f[buffer[x + y * bitmap->width]];

DIFF:

diff --git a/src/text.cpp b/src/text.cpp
index 77fbc7f..42f6773 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -60,7 +60,7 @@ namespace text {
     for (pos_t y = 0; y < s_bitmap_rows && y < image->get_height() + pen_y; y++) {
       for (pos_t x = 0; x < s_bitmap_width && x < image->get_width() + pen_x; x++) {
         color c(base);
-        c.a = buffer[x + y * bitmap->width];
+        c.a = color_i_to_f[buffer[x + y * bitmap->width]];
         image->safe_blend_pixel(pen_x + x, pen_y + y, c);
       }
     }

udoprog added a commit that referenced this issue Nov 30, 2012

@udoprog udoprog closed this Nov 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment