.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_srgb.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_validation_validate_srgb.py: srgb texture colorspace ======================= Show images with physical colorspace, and srgb colorspace via three methods. * The top image shows physical colorspace, very non-linear. * The 2nd shows srgb colorspace, interpolated in srgb (srgb-to-linear happens in shader). * The 3d shows srgb texture, interpolated in linear space (srgb-to-linear is automatic). * The 4th is the same, using an explicit texture format. .. GENERATED FROM PYTHON SOURCE LINES 12-69 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_srgb_001.webp :alt: validate srgb :srcset: /_gallery/validation/images/sphx_glr_validate_srgb_001.webp :class: sphx-glr-single-img .. code-block:: Python import numpy as np from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx renderer = gfx.renderers.WgpuRenderer(RenderCanvas(size=(600, 600))) rgba = np.repeat(np.linspace(0, 255, 6).reshape(1, -1), 2, 0).astype(np.uint8) rgba.shape = (*rgba.shape, 1) rgba = np.repeat(rgba, 4, 2) rgba[:, :, 3] = 255 rgb = rgba[:, :, :3].copy() material = gfx.ImageBasicMaterial(clim=(0, 255), interpolation="linear") image1 = gfx.Image( gfx.Geometry(grid=gfx.Texture(rgb, dim=2, colorspace="physical")), material, ) image2 = gfx.Image( gfx.Geometry(grid=gfx.Texture(rgb, dim=2, colorspace="srgb")), material, ) image2.local.y = 2.1 image3 = gfx.Image( gfx.Geometry(grid=gfx.Texture(rgb, dim=2, colorspace="tex-srgb")), material, ) image3.local.y = 4.2 # Use explicit format. We still need to set the colorspace, otherwise it converts twice. # Pygfx will catch and warn for this case. image4 = gfx.Image( gfx.Geometry( grid=gfx.Texture(rgba, dim=2, colorspace="tex-srgb", format="rgba8unorm-srgb") ), material, ) image4.local.y = 6.3 scene = gfx.Scene() scene.add(image1, image2, image3, image4) camera = gfx.OrthographicCamera() camera.local.scale_y = -1 camera.show_object(scene, match_aspect=True, scale=1.05) renderer.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.260 seconds) .. _sphx_glr_download__gallery_validation_validate_srgb.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_srgb.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_srgb.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_srgb.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html