dreamos82 / Dreamos64

My experiments with osdev... again
160 stars 8 forks source link

[FRAMEBUFFER] Colors not rendered correctly #164

Closed dreamos82 closed 4 months ago

dreamos82 commented 1 year ago

Apparently there is an issue in rendering colors.

image

The above screenshot should have contained rainbow colors. But it is definetely wrong! :)

dreamos82 commented 4 months ago

There were different issues:

  1. Something has changed in the output of Gimp C Header at some point in the past, because same file, output is different. I don't know why
  2. The other problem was that the pixel variable was a char instead of unsigned char, and while doing shifting and bit manipulation casting it to uint32_t the result was wrong, because char is signed.
  3. The order of the pixels i composing was wrong, it was not:
            uint32_t num = (uint32_t) pixel[0] << 24 |
              (uint32_t)pixel[1] << 16 |
              (uint32_t)pixel[2] << 8  |
              (uint32_t)pixel[3];

    but:

    uint32_t num =  ((uint32_t)pixel[3] << 24) |
              ((uint32_t)pixel[0] << 16) |
              ((uint32_t)pixel[1] << 8)  |
              (uint32_t)pixel[2];

    and pixel is now unsigned char

Btw the original version was working with a different byte order. I don't know why XD