Skip to content

Instantly share code, notes, and snippets.

@sobotka
Last active May 10, 2020 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sobotka/68b430eabbf6998d11de6ccb04c7b5d5 to your computer and use it in GitHub Desktop.
Save sobotka/68b430eabbf6998d11de6ccb04c7b5d5 to your computer and use it in GitHub Desktop.
Minimal pyglet with OpenImageIO
#!/usr/bin/env python
import OpenImageIO
import pyglet
import glooey
if __name__ == "__main__":
window = pyglet.window.Window()
batch = pyglet.graphics.Batch()
ui = pyglet.graphics.OrderedGroup(100)
background = pyglet.graphics.OrderedGroup(0)
gui = glooey.Gui(window, batch=batch, group=ui)
widget = glooey.Placeholder()
gui.add(widget)
label = glooey.Label('Hello world!')
gui.add(label)
image_input = OpenImageIO.ImageBuf(
"A009C002_190210_R0EI_Alexa_LogCWideGamut.tif"
)
if image_input is not None:
print(image_input.spec())
else:
print("Image load failed")
horizontal_resolution = 640
scale = horizontal_resolution / image_input.spec().width
image_resized = OpenImageIO.ImageBufAlgo.resize (
OpenImageIO.ImageBufAlgo.flip(image_input),
roi=OpenImageIO.ROI(
0,
int(image_input.spec().width * scale),
0,
int(image_input.spec().height * scale),
0,
1,
0,
3))
if image_resized is not None:
print(image_input.spec())
else:
print("Image load failed")
image_pixels = image_resized.get_pixels(OpenImageIO.UINT8).flatten()
rawData = (pyglet.gl.GLubyte * len(image_pixels))(*image_pixels)
pyglet_image = pyglet.image.ImageData(
image_resized.spec().width,
image_resized.spec().height,
"RGB",
rawData
)
background = pyglet.sprite.Sprite(
pyglet_image, batch=batch,group=background)
print(pyglet_image.format)
print(pyglet_image.pitch)
@window.event
def on_draw():
window.clear()
# pyglet_image.blit(0, 0)
batch.draw()
pyglet.app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment