Hi.
I often work with grayscale (RGB actually) images that's not "real" grayscale.
Let's say "white" isn't 255,255,255 but something like 254,255,253 and "black" isn't 0,0,0 but something like 1,3,0 etc. (you got idea I hope).
These images isn't friendly for optimizing because optipng works with them in RGB mode. Can you add option like "-forcegray" (or whatever you call it) so optipng will convert images into "real" grayscale before optimization?
Best regards.
Some very basic ideas
add option "-forcegray"
add option "-graytreshold <value>", define default value 5-10.
If "forcegray" defined in command line then check image:
if (BrokenGrayscale) ConvertToGrayscale;
function BrokenGrayscale {
// here we will check if it's "broken" grayscale image or normal RGB image.
// check difference in R/G/B channels
for every pixel {
if (MAX(ABS(R-G),ABS(R-B),ABS(G-B)) > graytreshold) return false; // nope, difference in channels too big => normal RGB image
}
return true; // yes, difference is just few points => broken grayscale image, requires conversion to "proper" grayscale
}
function ConvertToGrayscale {
for every pixel {
// with usual very small difference in R/G/B channels there's no reason to use BT.709 or BT.601 methods, simple average is good enough
Gray = (R+G+B)/3
R = Gray
G = Gray
B = Gray
}
}
Optimize(); // usual optimization
Last edit: Eugene 2015-10-26