Question

I'm using Caman JS to modify an image. I want to modify only the alpha channel of a subset of pixels. but when i apply the filter it modifies all the pixels in the image. Any suggestions on how to just modify the subset of pixels. Do i need to create a plugin instead of a filter?

window.doWhatever=->
   offset={x:170,y:150}
   #for i in [0..10]
   #  for j in [0..10]
   #    x=j+offset.x
   #    y=i+offset.y
   #    image.maskAlpha(x,y,0)
   x=50
   y=50
   image.maskAlpha(x,y,255)
   image.render()
 Caman.Filter.register 'maskAlpha',(x,y,alphain)  ->
   this.process 'maskAlpha', ->
   pixel=this.getPixel(x,y)
   this.putPixel(x,y,{
   r:pixel.r,
   g:pixel.g,
   b:pixel.b,
   a:alphain})

or in javascript
window.doWhatever = function() { var offset, x, y; offset = { x: 170, y: 150 }; x = 50; y = 50; image.maskAlpha(x, y, 255); return image.render(); };

 Caman.Filter.register('maskAlpha', function(x, y, alphain) {
   return this.process('maskAlpha', function() {
     var pixel;
     pixel = this.getPixel(x, y);
     return this.putPixel(x, y, {
       r: pixel.r,
       g: pixel.g,
       b: pixel.b,
       a: alphain
      });
   });
 });
Was it helpful?

Solution

There isn't a clean way to do this due to the defect in webkit and other browser implementation of canvas where it overwrites the RGB values with zero if alpha is set to 0.

alpha is over written question

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top