예제 #1
0
void SkTMaskGamma_build_correcting_lut(uint8_t table[256], U8CPU srcI, SkScalar contrast,
                                       const SkColorSpaceLuminance& srcConvert, SkScalar srcGamma,
                                       const SkColorSpaceLuminance& dstConvert, SkScalar dstGamma) {
    const float src = (float)srcI / 255.0f;
    const float linSrc = srcConvert.toLuma(srcGamma, src);
    //Guess at the dst. The perceptual inverse provides smaller visual
    //discontinuities when slight changes to desaturated colors cause a channel
    //to map to a different correcting lut with neighboring srcI.
    //See https://code.google.com/p/chromium/issues/detail?id=141425#c59 .
    const float dst = 1.0f - src;
    const float linDst = dstConvert.toLuma(dstGamma, dst);

    //Contrast value tapers off to 0 as the src luminance becomes white
    const float adjustedContrast = SkScalarToFloat(contrast) * linDst;

    //Remove discontinuity and instability when src is close to dst.
    //The value 1/256 is arbitrary and appears to contain the instability.
    if (fabs(src - dst) < (1.0f / 256.0f)) {
        float ii = 0.0f;
        for (int i = 0; i < 256; ++i, ii += 1.0f) {
            float rawSrca = ii / 255.0f;
            float srca = apply_contrast(rawSrca, adjustedContrast);
            table[i] = SkToU8(sk_float_round2int(255.0f * srca));
        }
    } else {
        // Avoid slow int to float conversion.
        float ii = 0.0f;
        for (int i = 0; i < 256; ++i, ii += 1.0f) {
            // 'rawSrca += 1.0f / 255.0f' and even
            // 'rawSrca = i * (1.0f / 255.0f)' can add up to more than 1.0f.
            // When this happens the table[255] == 0x0 instead of 0xff.
            // See http://code.google.com/p/chromium/issues/detail?id=146466
            float rawSrca = ii / 255.0f;
            float srca = apply_contrast(rawSrca, adjustedContrast);
            SkASSERT(srca <= 1.0f);
            float dsta = 1.0f - srca;

            //Calculate the output we want.
            float linOut = (linSrc * srca + dsta * linDst);
            SkASSERT(linOut <= 1.0f);
            float out = dstConvert.fromLuma(dstGamma, linOut);

            //Undo what the blit blend will do.
            float result = (out - dst) / (src - dst);
            SkASSERT(sk_float_round2int(255.0f * result) <= 255);

            table[i] = SkToU8(sk_float_round2int(255.0f * result));
        }
    }
}
예제 #2
0
파일: filter.c 프로젝트: Tastyep/rt
unsigned int	filter_color(unsigned int color, t_opt *opt)
{
  if (opt->filter == 1)
    color = filter_sepia(color);
  if (opt->filter == 2)
    color = filter_grey(color);
  if (opt->gamma != -1)
    color = gamma_filter(color, opt->gamma);
  if (opt->filter == 3)
    color = revers_filter(color, opt);
  if (opt->contrast != 1.0)
    color = apply_contrast(color, opt);
  if (opt->saturation != 1.0)
    color = saturation(color, opt->saturation);
  return (color);
}
예제 #3
0
파일: test.c 프로젝트: nulldatamap/VoidEye
int main( int argc , char ** argv )
{
  printf( "Starting up VoidEye test.\n" );
  init_test( "" );
  update_texture();
  remove_colours();
  update_texture();
  int b , d , a;
  b = find_brightest();
  d = find_darkest();
  a = find_avarage();
  printf( "b: %d d: %d a: %d\n", b , d , a );
  apply_contrast( 256 );
  update_texture();
  create_groups();
  return 0;
}