Bug #1219

Bad color when rgba.cpp is compiled with GCC 4.2.4

Added by kervala about 8 years ago. Updated about 8 years ago.

Status:Closed Start date:12/21/2010
Priority:High Due date:
Assignee:kervala % Done:

100%

Category:OS: GNU/Linux
Target version:Version 0.8.0 Estimated time:5.00 hours

Description

We are currently using a workaround because when we compile rgba.cpp with optimizations on, a bug occurs and characters become blue.

History

#1 Updated by kervala about 8 years ago

  • Status changed from Validated to Assigned

#2 Updated by kervala about 8 years ago

  • Status changed from Assigned to Resolved
  • % Done changed from 0 to 100

Applied in changeset r1264.

#3 Updated by kervala about 8 years ago

  • Target version set to Version 0.8.0

In CRGBA::convertToHLS when R, G and B have same values, GCC 4.2.4 considers maxV is neither R neither G.

I have a test case to reproduce the bug (I'll post it tomorrow) and I think we could optimize this method using an array of floats and storing the index of the max value, so we'll not need to compare floats (which isn't accurate depending on round mode).

#4 Updated by kervala about 8 years ago

 1#include <stdio.h>
 2#include <stdint.h>
 3#include <algorithm>
 4
 5template<class T>    inline T maxof(const T& a,  const T& b,  const T& c)
 6    {return std::max(std::max(a,b),c);}
 7
 8uint8_t R = 127;
 9uint8_t G = 127;
10uint8_t B = 127;
11
12int main()
13{
14    float r = R / 255.f;
15    float g = G / 255.f;
16    float b = B / 255.f;
17
18    float maxV = maxof(r, g, b);
19
20    // Get hue
21    if (maxV == r)
22    {
23        printf("r = %f\n", r);
24    }
25    else if (maxV == g)
26    {
27        printf("g = %f\n", g);
28    }
29    else
30    {
31        printf("b = %f\n", b);
32    }
33
34    return 0;
35}
36

Will give :

b = 0.498039

When compiled with : g++ -O2 test.cpp -o test

and

r = 0.498039

When compiled with : g++ -O0 test.cpp -o test

#5 Updated by kervala about 8 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF