Image/texture implementation code
This module provides the Pan-OpenGL operations required to support OpenGL image handling. Most of this code is simply boilerplate code that sets OpenGL parameters such that normal Pythonic assumptions about data-ordering are met to allow easier interaction with other projects (such as PIL or Numpy).
Generally speaking, there are 3 pieces of information which control how an image is processed in the system:
OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING -- if this global value is set, then read of unsigned byte images using glReadPixels and glGetTexImage produces a string instead of the default array format.
Attributes of Note:
New image formats and types will need to be registered here to be supported, this means that extension modules which add image types/formats need to alter the tables described above!
XXX Should be an API to handle that instead of direct modification.
Functions createTargetArray(
format , dims , type)
Create storage array for given parameters
If storage type requires > 1 unit per format pixel, then dims will be extended by 1, so in the common case of RGB and GL_UNSIGNED_BYTE you will wind up with an array of dims + (3,) dimensions. See COMPONENT_COUNTS for table which controls which formats produce larger dimensions. The secondary table TIGHT_PACK_FORMATS overrides this case, so that image formats registered as TIGHT_PACK_FORMATS only ever return a dims-shaped value. TIGHT_PACK_FORMATS will raise ValueErrors if they are used with a format that does not have the same number of components as they define.
Note that the base storage type must provide a zeros method. The zeros method relies on their being a registered default array-implementation for the storage type. The default installation of OpenGL-ctypes will use Numpy arrays for returning the result.
formatToComponentCount(
format)
Given an OpenGL image format specification, get components/pixel
rankPacking(
rank)
Set the pixel-transfer modes for a given image "rank" (# of dims)
Uses RANK_PACKINGS table to issue calls to glPixelStorei
returnFormat(
data , type)
Perform compatibility conversion for PyOpenGL 2.x image-as string results
Uses OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING to control whether to perform the conversions.
setupDefaultTransferMode(
)
Set pixel transfer mode to assumed internal structure of arrays
Basically OpenGL-ctypes (and PyOpenGL) assume that your image data is in non-byte-swapped order, with big-endian ordering of bytes (though that seldom matters in image data). These assumptions are normally correct when dealing with Python libraries which expose byte-arrays.
SetupPixelRead(
format , dims , type)
Setup transfer mode for a read into a numpy array return the array
Calls setupDefaultTransferMode, sets rankPacking and then returns a createTargetArray for the parameters.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4