Logo   Home Table of Contents    News  Dev Blogs  Gallery  Timeline  Legend  Tags  Sponsors 
Join us on... 
Banner

Current: Month Day, Year

9.1.6 Code of opengl/texture.py

opengl/texture provides all methods to deal with openGL textures. The file only contains 4 classes:

Class TextureRepo

This class is contains information about loaded textures. Key is the filename, values are: [ openGL texture, usage, filedate, mhtex, reference to object array ] if filedate is "0" it is a generated texture.

Variables

These variables are all preset by __init__.
namedescription
glob reference to global object.
textures Dictionary of textures.
systextures Dictionary of system textures (not to be accidentally deleted.

Methods:

nameparametersreturnsdescription
getTextures Nonedictionary of textures Getter of textures.
show NoneNone Command can be used for debugging (it is not used in normal mode).
add_sys path
texture (list)
None Adds a system texture defined by list
add_user path
texture
timestamp
mhtex
obj
None Adds a user texture with time stamp and for the object it is used for (if it does not yet exist.
exists pathopenGL texture
mhtex object
If texture path exists it returns openGL texture and texture object. Otherwise it returns None
inc path
obj
None Increments usage counter of texture and adds object to list.
delete texture
obj
success (bool) find texture path and check if obj is assigned. If so, delete it and decrement counter. If counter is zero texture is destroyed and elem deleted from self.textures.
refresh NoneNone refresh all textures (to load e.g. a skin under construction. No refresh for generated textures. Here the timestamp is checked.
cleanup textypeNone central location to delete textures (systextures only by demand).

Class ImageEdit

Class used for coloration. values are: [ openGL texture, usage, filedate, mhtex, reference to object array ] if filedate is "0" it is a generated texture.

Variables

These variables are all preset by __init__.
namedescription
glob reference to global object.

Methods:

nameparametersreturnsdescription
validMask image
mask
True if valid check if mask is valid (has same size and is not none)
modifyToConstantHue image
r
g
b
mask
None modify an image to a constant hue. The image is transformed to a numpy array. then the hue is calculated from r, g, b (in degrees). The values are converted to float. Then if hue is -1 (r, g, b are identical), hue is set to index 0 and p, q, t are identical to value. Otherwise hue p, q, t are calculated by hue formular in 6 different sections depending on index.

If a mask image is given only white areas are changed, black ones stay identical.

noColor image
mask
None desaturates image by using modifyToConstantHue and values 1.0, 1.0, 1.0, and mask.
multColor image
r
g
b
mask
None multiplies image with a certain color. If a mask image is given only white areas are changed, black ones stay identical.
greyToColor image
r
g
b
mask
None first desaturates image and then multiplies image with a certain color. A mask can be used.

Class MH_Texture

Class used for Textures. It uses the global repo.

Variables

These variables are all preset by __init__.
namedescription
glob reference to global object.
obj the object which uses the texture.
repo reference to global texture repo.
textype the texture type (user or system).
image the image (preset to None).
name the name (preset to None).

Methods:

nameparametersreturnsdescription
getImage Noneimage getter for image
getName Nonename getter for name
getTexture Nonetexture getter for texture
create imagetexture create an QOpenGLTexture with minmage filters and wrapmode, set data and return texture.
destroy NoneNone destroy the texture.
delete NoneNone delete the texture (only if type is user) by repo.delete function.
stdcolor Nonetexture object Creates a texture object of color [0.5, 0.5, 0.5].
unicolor rgb
name
texture object Creates a texture object of a certain rgb color. It returns an existing object in case it is already there and increases the counter for that texture and adds obj to list. Otherwise a new 1 pixel texture is created (either for system or for user) User texture will contain obj in list.
load path
textype
modify (bool)
texture object checks if a certain user texture already exists. If so, it increases the counter and add the object. Otherwise the timestamp of the texture is fetched and a new texture is created and added to the repo as system or user texture. The texture is returned (or None if texture cannot be loaded).
save_png rgbname save image changed by coloration color (in exportfolder with name hex-color name prefix) The name created is returned.
refresh_image Nonetexture Old image is destroyed and created again. Used when textures are modified.
refresh pathtexture Old image is destroyed and created again with new image path. Texture is returned.

Class MH_Thumb

Class used for Thumbnails.

Variables

These variables are all preset by __init__.
namedescription
maxsize the maximal size of the thumbnail (preset to 128).
img the image (preset to None).

Methods:

nameparametersreturnsdescription
rescale nameNone creates a thumbnail from image with Qt.KeepAspectRatio, Qt.SmoothTransformation and saves the image as name.