I’m mapping several photoshop elements to CIFilter, the only one I’m having trouble with is this Levels Adjustment:


Which CI Filter (or combination of filters) would let me utilize the 16, 1.73, 239 & 39/245 above in the first example or the 31, 1.25, 255 30/255 in the second example. I believe this is a kind of shadow/black and white level adjustment.
Any help appreciated.
By adapting the formula from this page: http://http.developer.nvidia.com/GPUGems/gpugems_ch22.html, I believe you can do this using a combination of
CIColorMatrix,CIGammaAdjustand anotherCIColorMatrix.Let’s call the input levels
inBlack,inGammaandinWhiterespectively, and the output levelsoutBlackandoutWhite. Note that Photoshop color are between 0 and 255 while CI colors are between 0 and 1 so you need to divide the Photoshop values (exceptinGamma!) by 255 before putting them into the following formulas.The input mapping is
pixel = (inPixel-inBlack)/(inWhite-inBlack), which means your first matrix will beThen you apply gamma correction using
CIGammaAdjustand theinGammanumber (I had to use the inverse1/inGammawhen doing my calculations, try that too!).Finally the output mapping is pixel =
gammaCorrectedPixel * (outWhite - outBlack) + outBlack, giving you the final matrixI haven’t actually tried this using CoreImage, but the calculations work out nicely!