Ignore:
Timestamp:
Mar 11, 2015 3:11:07 AM (9 years ago)
Author:
ldelgass
Message:

Add legend option for blending against a background color

File:
1 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/ColorMap.cpp

    r5118 r5119  
    3434            float x = (float)i/(height-1);
    3535            float val = min + (max - min) * x;
    36             osg::Vec4f rgb = map->getColor(val);
     36            osg::Vec4f rgba = map->getColor(val);
     37            float opacity = rgba[3];
    3738            unsigned char color[3];
    3839            if (opaque) {
    39                 color[0] = (unsigned char)(255. * (bgr ? rgb[2] : rgb[0]));
    40                 color[1] = (unsigned char)(255. * rgb[1]);
    41                 color[2] = (unsigned char)(255. * (bgr ? rgb[0] : rgb[2]));
     40                color[0] = (unsigned char)(255. * (bgr ? rgba[2] : rgba[0]));
     41                color[1] = (unsigned char)(255. * rgba[1]);
     42                color[2] = (unsigned char)(255. * (bgr ? rgba[0] : rgba[2]));
    4243            } else {
    43                 float opacity = rgb[3];
    44                 color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgb[2] : rgb[0]) * opacity));
    45                 color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgb[1] * opacity));
    46                 color[2] = (unsigned char)(255. * (bgColor[2] * (1.0 - opacity) + (bgr ? rgb[0] : rgb[2]) * opacity));
     44                color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgba[2] : rgba[0]) * opacity));
     45                color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgba[1] * opacity));
     46                color[2] = (unsigned char)(255. * (bgColor[2] * (1.0 - opacity) + (bgr ? rgba[0] : rgba[2]) * opacity));
    4747            }
    4848            for (int j = 0; j < width; j++) {
     
    5050                dst += 3;
    5151                if (bytesPerPixel == 4) {
    52                     *(dst++) = (unsigned char)255.;
     52                    *(dst++) = (unsigned char)(255. * (opaque ? 1.0 : opacity));
    5353                }
    5454            }
     
    6060                float val = min + (max - min) * x;
    6161                osg::Vec4f rgb = map->getColor(val);
     62                double opacity = rgb[3];
    6263                unsigned char color[3];
    6364                if (opaque) {
     
    6667                    color[2] = (unsigned char)(255. * (bgr ? rgb[0] : rgb[2]));
    6768                } else {
    68                     double opacity = rgb[3];
    6969                    color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgb[2] : rgb[0]) * opacity));
    7070                    color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgb[1] * opacity));
     
    7474                dst += 3;
    7575                if (bytesPerPixel == 4) {
    76                     *(dst++) = (unsigned char)255.;
     76                    *(dst++) = (unsigned char)(255. * (opaque ? 1.0 : opacity));
    7777                }
    7878            }
Note: See TracChangeset for help on using the changeset viewer.