GrayscaleType and scaling colors
Posted: 2014-12-11T07:27:47-07:00
I'm trying to write a PNG with very specific grayscale values.
In particular, I want certain pixels to have value, say, 80 (out of 255).
The following code writes a PNG that, when inspecting in GIMP, gives the pixels value 20 where I wanted 80.
When looking at the bottom part of the image, 80 seems to be more than halfway across, so something clearly isn't linear.
Could someone explain what's going on here?
Is there a way to make it so that the pixel values are linear, so that 128 is halfway across the strip at the bottom, etc.?
Thanks so much!
In particular, I want certain pixels to have value, say, 80 (out of 255).
The following code writes a PNG that, when inspecting in GIMP, gives the pixels value 20 where I wanted 80.
When looking at the bottom part of the image, 80 seems to be more than halfway across, so something clearly isn't linear.
Code: Select all
Magick::Image m(Magick::Geometry(256, 256), "white");
for (size_t r = 0; r < 128; ++r)
for (size_t c = 0; c < 256; ++c) {
double val = 80/255.0;
m.pixelColor((ssize_t) c, (ssize_t) r, Magick::ColorGray(val));
}
for (size_t r = 128; r < 256; ++r)
for (size_t c = 0; c < 256; ++c) {
double val = c / 255.0;
m.pixelColor((ssize_t) c, (ssize_t) r, Magick::ColorGray(val));
}
m.type(Magick::GrayscaleType);
m.write("foo.png");
Is there a way to make it so that the pixel values are linear, so that 128 is halfway across the strip at the bottom, etc.?
Thanks so much!