Mapping 31-bit grey-scale, to 8-bit grey-scale

edited March 2017 in Share Your Work

This is a very esoteric "issue" I think I'we resolved, and possibly could be solved easier with colorMode
Anyways I used the map function.
So as I said, its very abstract and esoteric thing, it has nothing to do with HDR so I should probably keep it to myself but I give it a chance and let mod be the judge.

Why 31 bit, why not 32-bit?
Well 31 bit is much easier to work with in signed values.

int black = 0x0;
int white = (0x1 << 31) - 1;
// stored outside of function for numbers not to reset
int darkest_color, previously_darkest_color, brightest_color, previously_brightest_color;

// map for every pixel drawn to screen, from the 0-2 billion to 0-255 adjusted for contrast
int greyscale (int color_to_draw) {
        if ( color_to_draw > brightest_color ) {
          brightest_color = color_to_draw;
        }
        if( color_to_draw < darkest_color ) {
        darkest_color = color_to_draw;
        }

        if(previously_brightest_color > previously_darkest_color) {
        color_to_draw = 
        floor(
             map( color_to_draw,
                  min( previously_darkest_color, darkest_color),
                  max( previously_brightest_color, brightest_color),
                  0,255
                )
             ) & 0xFF;
        } else { color_to_draw = 0; }
        return (color_to_draw << 16) + (color_to_draw << 8) + color_to_draw;  // + #000000 if you need opaque color
      }

//at the end of every frame
void swap() {
previously_brightest_color=brightest_color;
brightest_color = black;
previously_darkest_color = darkest_color;
darkest_color = white;
}
Tagged:

Comments

  • Where are these 31-bit images coming from, that you need to do color mapping on them? A special webcam / security cam?

Sign In or Register to comment.