void main(void) { vec4 color = texture2D(texture, fragmentTextureCoordinate.xy); vec4 maskColor = texture2D(mask, fragmentTextureCoordinate.xy); float maskAmount = maskColor.a * rgbToHsl(maskColor.rgb).z; color.rgb *= maskAmount; color.a = maskAmount; gl_FragColor = color; }
void main(void) { // http://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast vec4 pixelColor = texture2D(image, fragmentTextureCoordinate.xy); pixelColor.rgb /= pixelColor.a; // compensate for channels that are completely void - this allows a fully exposed pixel // to always be white, regardless of starting value. .001 is the minimum resolution that // enables this. if( exposure > 0.) pixelColor.rgb += vec3(.001); // Apply Exposure pixelColor.rgb = clamp(pixelColor.rgb * pow(2., exposure), 0., 1.); vec3 hsl = rgbToHsl(pixelColor.rgb); // Apply hue shift hsl.x = mod(hsl.x + hueShift, 1.); // // Apply saturation hsl.y *= saturation; pixelColor.rgb = hslToRgb(hsl); // Apply contrast. pixelColor.rgb = ((pixelColor.rgb - 0.5f) * max(contrast, 0.)) + 0.5f; // Apply brightness. pixelColor.rgb += brightness; pixelColor.rgb = clamp(pixelColor.rgb, 0., 1.); // // Apply gamma. pixelColor.r = pow(pixelColor.r, gamma); pixelColor.g = pow(pixelColor.g, gamma); pixelColor.b = pow(pixelColor.b, gamma); // Return final pixel color. pixelColor.rgb *= pixelColor.a; gl_FragColor = pixelColor; }
void ImageView::colorize() { int y, x; unsigned char hr, hg, hb; int r, g, b; QRgb *line; unsigned char h, s, l; static unsigned char contrastTransform[256]; static unsigned char brightTransform[256]; if (displayImage.format() == QImage::Format_Indexed8) { displayImage = displayImage.convertToFormat(QImage::Format_RGB32); } int i; float contrast = ((float)GData::contrastVal / 100.0); float brightness = ((float)GData::brightVal / 100.0); for(i = 0; i < 256; ++i) { if (i < (int)(128.0f + 128.0f * tan(contrast)) && i > (int)(128.0f - 128.0f * tan(contrast))) contrastTransform[i] = (i - 128) / tan(contrast) + 128; else if (i >= (int)(128.0f + 128.0f * tan(contrast))) contrastTransform[i] = 255; else contrastTransform[i] = 0; } for (i = 0; i < 256; ++i) { brightTransform[i] = MIN(255,(int)((255.0 * pow(i / 255.0, 1.0 / brightness)) + 0.5)); } for(y = 0; y < displayImage.height(); ++y) { line = (QRgb *)displayImage.scanLine(y); for(x = 0; x < displayImage.width(); ++x) { r = qRed(line[x]); g = qGreen(line[x]); b = qBlue(line[x]); r = bound0To255((r * (GData::redVal + 100)) / 100); g = bound0To255((g * (GData::greenVal + 100)) / 100); b = bound0To255((b * (GData::blueVal + 100)) / 100); r = bound0To255(contrastTransform[r]); g = bound0To255(contrastTransform[g]); b = bound0To255(contrastTransform[b]); r = bound0To255(brightTransform[r]); g = bound0To255(brightTransform[g]); b = bound0To255(brightTransform[b]); rgbToHsl(r, g, b, &h, &s, &l); if (GData::colorizeEnabled) h = GData::hueVal; else h += GData::hueVal; s = bound0To255(((s * GData::saturationVal) / 100)); l = bound0To255(((l * GData::lightnessVal) / 100)); hslToRgb(h, s, l, &hr, &hg, &hb); r = GData::hueRedChannel? hr : qRed(line[x]); g = GData::hueGreenChannel? hg : qGreen(line[x]); b = GData::hueBlueChannel? hb: qBlue(line[x]); line[x] = qRgb(r, g, b); } } }
void qtcShade(const Options *opts, const color *ca, color *cb, double k) #endif { if(qtcEqual(k, 1.0)) { #ifdef __cplusplus *cb=ca; #else cb->red = ca->red; cb->green = ca->green; cb->blue = ca->blue; #endif } else switch(opts->shading) { case SHADING_SIMPLE: { #ifdef __cplusplus int v=(int)(255.0*(k-1.0)); cb->setRgb(qtcLimit(ca.red()+v), qtcLimit(ca.green()+v), qtcLimit(ca.blue()+v)); #else double v=65535.0*(k-1.0); cb->red = qtcLimit(ca->red+v); cb->green = qtcLimit(ca->green+v); cb->blue = qtcLimit(ca->blue+v); #endif break; } case SHADING_HSL: { #ifdef __cplusplus double r(ca.red()/255.0), g(ca.green()/255.0), b(ca.blue()/255.0); #else double r=ca->red/65535.0, g=ca->green/65535.0, b=ca->blue/65535.0; #endif double h, s, l; rgbToHsl(r, g, b, &h, &s, &l); l=normalize(l*k); s=normalize(s*k); hslToRgb(h, s, l, &r, &g, &b); #ifdef __cplusplus cb->setRgb(qtcLimit(r*255.0), qtcLimit(g*255.0), qtcLimit(b*255.0)); #else cb->red=qtcLimit(r*65535.0); cb->green=qtcLimit(g*65535.0); cb->blue=qtcLimit(b*65535.0); #endif break; } case SHADING_HSV: { #ifdef __cplusplus double r(ca.red()/255.0), g(ca.green()/255.0), b(ca.blue()/255.0); #else double r=ca->red/65535.0, g=ca->green/65535.0, b=ca->blue/65535.0; #endif double h, s, v; qtcRgbToHsv(r, g, b, &h, &s, &v); v*=k; if (v > 1.0) { s -= v - 1.0; if (s < 0) s = 0; v = 1.0; } qtcHsvToRgb(&r, &g, &b, h, s, v); #ifdef __cplusplus cb->setRgb(qtcLimit(r*255.0), qtcLimit(g*255.0), qtcLimit(b*255.0)); #else cb->red=qtcLimit(r*65535.0); cb->green=qtcLimit(g*65535.0); cb->blue=qtcLimit(b*65535.0); #endif break; } case SHADING_HCY: { #define HCY_FACTOR 0.15 #if defined QT_VERSION && (QT_VERSION >= 0x040000) && defined QTC_QT4_ENABLE_KDE if(k>1.0) *cb=KColorUtils::lighten(ca, (k*(1+HCY_FACTOR))-1.0, 1.0); else *cb=KColorUtils::darken(ca, 1.0-(k*(1-HCY_FACTOR)), 1.0); #elif defined __cplusplus if(k>1.0) *cb=ColorUtils_lighten(&ca, (k*(1+HCY_FACTOR))-1.0, 1.0); else *cb=ColorUtils_darken(&ca, 1.0-(k*(1-HCY_FACTOR)), 1.0); #else if(k>1.0) *cb=ColorUtils_lighten(ca, (k*(1+HCY_FACTOR))-1.0, 1.0); else *cb=ColorUtils_darken(ca, 1.0-(k*(1-HCY_FACTOR)), 1.0); #endif } } #if defined __cplusplus && defined QT_VERSION && (QT_VERSION >= 0x040000) cb->setAlpha(ca.alpha()); #endif #ifndef __cplusplus cb->pixel = ca->pixel; #endif }