HTML5 Canvas image contrast

前端 未结 7 1350
情书的邮戳
情书的邮戳 2020-12-13 04:51

I\'ve been writing an image processing program which applies effects through HTML5 canvas pixel processing. I\'ve achieved Thresholding, Vintaging, and ColorGradient pixel m

7条回答
  •  既然无缘
    2020-12-13 05:08

    This javascript implementation complies with the SVG/CSS3 definition of "contrast" (and the following code will render your canvas image identically):

    /*contrast filter function*/
    //See definition at https://drafts.fxtf.org/filters/#contrastEquivalent
    //pixels come from your getImageData() function call on your canvas image
    contrast = function(pixels, value){
        var d = pixels.data;
        var intercept = 255*(-value/2 + 0.5);
        for(var i=0;i 255) d[i] = 255;
            if(d[i+1] > 255) d[i+1] = 255;
            if(d[i+2] > 255) d[i+2] = 255;
            if(d[i] < 0) d[i] = 0;
            if(d[i+1] < 0) d[i+1] = 0;
            if(d[i+2] < 0) d[i+2] = 0;
        }
        return pixels;
    }
    

提交回复
热议问题