Created
May 30, 2016 10:48
-
-
Save nicelifeBS/3fc3175f9838be619d5bb9ddfe14a490 to your computer and use it in GitHub Desktop.
Modo python API: Create a custom preview render and write its image to disk as png in sRGB color space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lx | |
import modo | |
ImgSrv = lx.service.Image() | |
colorService = lx.service.ColorMapping() | |
TosRGB = lx.object.ColorMapping(colorService.MakeColorMapping("nuke-default:sRGB", 0)) | |
width = 1000 | |
height = 800 | |
# Create preview and render | |
Preview = lx.service.Preview().CreatePreview() | |
Preview.SetRes(width, height) | |
Preview.SetRenderTime(15.0) | |
Preview.IsComplete() | |
# Get the preview buffer | |
previewImage = Preview.GetBuffer() | |
w, h = previewImage.Size() | |
ch = previewImage.Components() | |
# create a new storage object for our pixels | |
Pixel = lx.object.storage() | |
Pixel.setType('f') | |
Pixel.setSize(w * h * ch) | |
# Create a new image for export | |
exportImage = ImgSrv.Create(w, h, lx.symbol.iIMP_RGBAFP, 0) | |
imWrite = lx.object.ImageWrite(exportImage) | |
for ih in range(h): | |
for iw in range(w): | |
previewImage.GetPixel(iw, ih, lx.symbol.iIMP_RGBAFP, Pixel) | |
iR = Pixel[0] | |
iG = Pixel[1] | |
iB = Pixel[2] | |
# convert to sRGB | |
R, G, B = TosRGB.FromLinear((iR, iG, iB), 3) | |
# set the RGBA pixels | |
Pixel.set((R, G, B, Pixel[3])) | |
imWrite.SetPixel(iw, ih, lx.symbol.iIMP_RGBAFP, Pixel) | |
# Write image to disk | |
ImgSrv.Save(imWrite, '/tmp/test1.png', 'PNG', 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment