meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation
http://camanjs.com
BSD 3-Clause "New" or "Revised" License
3.56k stars 406 forks source link

Adjust Channels on both sides? #109

Closed confile closed 11 years ago

confile commented 11 years ago

In Photoshop you can adjust channels from both sides. I tested this with the Caman channels as well. When I set a channel like the following I get the same as if I do it in Photoshop on one side. You have to take care that the scale is different. For the positive side in Photoshop you have 1 to 255 and in Caman you have 1 to 100 so to adjust this you have to multiply the Photoshop value by (100/255). So 10 in Photoshop will be approximately 4 in Caman.

Is this correct?

So, to adjust the right hand side of the channel I do:

this.channels({
    red: 4
  });

and for the left hand side I do:

this.channels({
    red: -4
  });

How do I adjust both sides at the same time like it can be dome in Photoshop?

quick_tips__instagram_your_images_using_photoshop___abduzeedo_design_inspiration-2

meltingice commented 11 years ago

The channels method is a bit different from levels in Photoshop. It looks at the current pixel in the image and adjusts it's value up or down as a percentage towards 0 or 255, depending on the user input. This adds or removes intensity for that color channel.

# Where options.red is a percentage
if options.red?
  if options.red > 0
    rgba.r += (255 - rgba.r) * options.red
  else
    rgba.r -= rgba.r * Math.abs(options.red)

Adding a more Levels-like tool is something I've wanted to do for awhile.

confile commented 11 years ago

@meltingice I will look forward to test your extension.