Custom RGB colors


Re: Custom RGB colors
#7
Travis Cobbs Wrote:Combining two 12-bit colors together in a 50/50 checkerboard does not give you a 24 bits of color space.

Totally unrelated question. Do any math types out there know how to calculate the actual size of the color space for a 50/50 average of two 12-bit colors, where the results are 24-bit colors? I was curious and wrote a real quick program to come up with the number empirically (by calcuating all 16m+ combinations of 12-bit values and counting all the unique results), but the answer I got seemed very strange: 29,791 (which, for what it's worth, is 0x745F in hexadecimal). I can't decide if I messed up my (very simple) program or not. I would have expected some simple equation to give the count, but I also would have expected the result to have some kind of visible pattern in hexadecimal notation, and I don't see one.

For reference (for the programmers out there), here is the program. Store the below in a .cpp file and compile it and it should work on just about any semi-modern C++ environment. (Having said that, I've only run it as a Win32 C++ Console Application, build with Visual C++ 2010.)

Code:
#include <stdio.h>
#include <set>

int main(int argc, char* argv[])
{
    std::set<int> colors;
    for (int left = 0; left < 4096; ++left)
    {
        for (int right = 0; right < 4096; ++right)
        {
            int r = (((left & 0xF00) >> 8) * 17 + ((right & 0xF00) >> 8) * 17) / 2;
            int g = (((left & 0xF0)  >> 4) * 17 + ((right & 0xF0)  >> 4) * 17) / 2;
            int b =  ((left & 0xF)         * 17 +  (right & 0xF)         * 17) / 2;
            colors.insert((r << 16) | (g << 8) | b);
        }
    }
    int count = (int)colors.size();
    printf("Total: %d (0x%X)\n", count, count);
    return 0;
}
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Custom RGB colors - by Stephen - 2014-02-20, 13:06
Re: Custom RGB colors - by Philippe Hurbain - 2014-02-20, 13:39
Re: Custom RGB colors - by Stephen - 2014-02-20, 13:53
Re: Custom RGB colors - by Travis Cobbs - 2014-02-20, 19:02
Re: Custom RGB colors - by Stephen - 2014-02-20, 20:11
Re: Custom RGB colors - by Michael Heidemann - 2014-02-20, 21:10
Re: Custom RGB colors - by Travis Cobbs - 2014-02-20, 22:05
Re: Custom RGB colors - by Michael Heidemann - 2014-02-21, 16:55
Re: Custom RGB colors - by Travis Cobbs - 2014-02-21, 21:41
Re: Custom RGB colors - by Tim Gould - 2014-02-21, 22:43
Re: Custom RGB colors - by Travis Cobbs - 2014-02-22, 0:01
Re: Custom RGB colors - by Travis Cobbs - 2014-05-02, 16:44
Re: Custom RGB colors - by Michael Heidemann - 2014-05-02, 17:02
Re: Custom RGB colors - by Michael Heidemann - 2014-05-02, 11:10

Forum Jump:


Users browsing this thread: 10 Guest(s)