[Closed] Image Viewer with Gamma Adjustment?
I’ve made a nice simple render pass browser that’s working really nicely for just checking renders.
The only thing is I need to apply a 2.2 correction to the image ideally… in the mxscript help there’s gamma for new bitmaps, and renders but doesn’t work if you openbitmap an image and copy it into the new bitmap, it’s still in 1.0 linear.
Is there a dotnet control that can deal with gamma?
you can specify gamma on the constructor of a new bitmap:
bitmap 800 600 gamma:2.2
alternatively, you can specifiy gamma of loaded images:
local gam = fileInGamma
fileInGamma = 2.2
openBitmap thebitmapfile
fileInGamma = gam
I’ve found that Gamma information… but it doesn’t do what I need it to.
I’ve found this which seems like it’ll be a good place to start… but it’s not working in max9 for me…
Fairly complex, using GDI+ with dotnet to apply a color matrix transformation.
At worst case I could possibly use GetPixel/SetPixel to do the adjustment but that’ll be far far too slow for what I need it for…
pcolor = 128
gamma = 2.2
ncolor = 255 * (pcolor / 255 as float) ^ (1 / gamma as float)
print ncolor
Actually Get/SetPixels wasn’t as slow as I thought it’d be, is there any way to make this any quicker than I’ve written it?
--adjust gamma
gamma = 2.2
thebmp = bmp_Preview.bitmap
w = thebmp.width
h = thebmp.height
newbmp = bitmap w h
for i = 1 to h do
(
thepixels = Getpixels thebmp [0,i] (w - 1)
for o in thepixels do
(
o.r = 255 * (o.r / 255 as float) ^ (1 / gamma as float)
o.g = 255 * (o.g / 255 as float) ^ (1 / gamma as float)
o.b = 255 * (o.b / 255 as float) ^ (1 / gamma as float)
)
setPixels newbmp [0,i] thepixels
)
bmp_Preview.bitmap = newbmp
wouldn’t it be quicker to generate a colorcorrect map, do the gamma adjustment there, and use the rendermap method on it?
edit: sorry, you mentioned you’re on max9. I don’t think you have colorcorrect.
This should be just a bit faster than your function, no need to calculate 1/gamma every time:
--adjust gamma
gamma = 2.2
thebmp = bmp_Preview.bitmap
w = thebmp.width
h = thebmp.height
gammaMult = (1/gamma as float)
newbmp = bitmap w h
for i = 1 to h do
(
thepixels = Getpixels thebmp [0,i] (w - 1)
for o in thepixels do
(
o.r = 255 * (o.r / 255.0) ^ gammaMult
o.g = 255 * (o.g / 255.0) ^ gammaMult
o.b = 255 * (o.b / 255.0) ^ gammaMult
)
setPixels newbmp [0,i] thepixels
)
bmp_Preview.bitmap = newbmp