I'm looking for more efficient solution of converting .exr to 8bit JPEG with gamma encoding. Currently, I make use of OpenEXR module and numpy. Here is the code snippets:
File = OpenEXR.InputFile(exrfile)
PixType = Imath.PixelType(Imath.PixelType.FLOAT)
DW = File.header()['dataWindow']
Size = (DW.max.x - DW.min.x + 1, DW.max.y - DW.min.y + 1)
rgb = [numpy.fromstring(File.channel(c, PixType), dtype=numpy.float32) for c in 'RGB']
for i in range(3):
rgb[i] = numpy.where(rgb[i]<=0.0031308,
(rgb[i]*12.92)*255.0,
(1.055*(rgb[i]**(1.0/2.4))-0.055) * 255.0)
rgb8 = [Image.fromstring("F", Size, c.tostring()).convert("L") for c in rgb]
#rgb8 = [Image.fromarray(c.astype(int)) for c in rgb]
Image.merge("RGB", rgb8).save(jpgfile, "JPEG", quality=95)
I'm wondering if there is even efficient solution for that?