Finding color matrix for Brightness and contrast for iOS Application

418 Views Asked by At

I checked out the color matrix for brightness and contrast and I got

 {contrast,     0,      0,      0,   brightness
 0,         contrast,   0,      0,   brightness
 0,             0,    contrast, 0,   brightness
 0,             0,      0,      1,     0
 0,             0,      0,      0,     1 }

which is a 5*5 matrix.

But in iOS we have only 4*4 matrix for colorMatrix

CIFilter *colorMatrixFilter = [CIFilter filterWithName:@"CIColorMatrix"]; // 2
[colorMatrixFilter setDefaults]; // 3
[colorMatrixFilter setValue:rawImage forKey:kCIInputImageKey]; // 4
[colorMatrixFilter setValue:[CIVector vectorWithX:contrast Y:0 Z:0 W:brightness] forKey:@"inputRVector"]; // 5
[colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:contrast Z:0 W:brightness] forKey:@"inputGVector"]; // 6
[colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:contrast W:brightness] forKey:@"inputBVector"]; // 7
[colorMatrixFilter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:1] forKey:@"inputAVector"]; // 8

But this doesn't give the desired results, pictures having negative brightness are black. And same goes for contrast. Suggest the right matrix for the brightness and contrast for iOS apps

0

There are 0 best solutions below