TDME2  1.9.200
TextureReader.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_map>
4 #include <string>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
9 #include <tdme/engine/fwd-tdme.h>
14 
15 using std::string;
16 using std::unordered_map;
17 using std::vector;
18 
23 
24 /**
25  * Texture reader class
26  * @author Andreas Drewke
27  */
29 {
30  friend class tdme::engine::Texture;
31  friend class PNGTextureReader;
32 
33 public:
34  /**
35  * @return texture extensions
36  */
37  static const vector<string>& getTextureExtensions();
38 
39  /**
40  * Reads a texture
41  * @param pathName path name
42  * @param fileName file name
43  * @param useCache use cache
44  * @param powerOfTwo scale image to fit power of two dimensions
45  * @param idPrefix id prefix
46  * @return texture data instance or null
47  */
48  static Texture* read(const string& pathName, const string& fileName, bool useCache = true, bool powerOfTwo = true, const string& idPrefix = string());
49 
50  /**
51  * Reads a texture with additional transparency texture
52  * @param texturePathName texture path name
53  * @param textureFileName texture file name
54  * @param transparencyTexturePathName transparency texture path name
55  * @param transparencyTextureFileName transparency texture file name
56  * @param useCache use cache
57  * @param powerOfTwo scale image to fit power of two dimensions
58  * @param idPrefix id prefix
59  * @return texture data instance or null
60  */
61  static Texture* read2(const string& texturePathName, const string& textureFileName, const string& transparencyTexturePathName, const string& transparencyTextureFileName, bool useCache = true, bool powerOfTwo = true, const string& idPrefix = string());
62 
63  /**
64  * Rotate texture around center
65  * @param texture texture
66  * @param rotation rotation in degree
67  * @param idSuffix id suffix for generated texture
68  * @return rotation rotation
69  */
70  static Texture* rotate(Texture* texture, float rotation, const string& idSuffix = ":rotated");
71 
72  /**
73  * Scale texture
74  * @param texture texture
75  * @param width width
76  * @param height height
77  * @param idSuffix id suffix for generated texture
78  * @return texture
79  */
80  static Texture* scale(Texture* texture, int width, int height, const string& idSuffix = ":scaled");
81 
82  /**
83  * Smooth texture
84  * @param texture texture
85  * @param idSuffix id suffix for generated texture
86  * @param adjacentSampleWeight adjacent sample weight
87  * @return texture
88  */
89  static Texture* smooth(Texture* texture, const string& idSuffix = ":smoothed", float adjacentSampleWeight = 0.05f);
90 
91 private:
92 
93  /**
94  * Remove texture from cache
95  * @param texture texture
96  */
97  static void removeFromCache(Texture* texture);
98 
99  /**
100  * Scales a texture line
101  * @param pixelByteBuffer pixel byte buffer aka original texture
102  * @param pixelByteBufferScaled pixel byte buffer scaled aka new texture, its offset should point to start of line you want to write
103  * @param width orginal width
104  * @param textureWidth new texture width
105  * @param bytesPerPixel bytes per pixel
106  * @param y y position in original image
107  */
108  static void scaleTextureLine(const ByteBuffer& pixelByteBuffer, ByteBuffer& pixelByteBufferScaled, int width, int textureWidth, int bytesPerPixel, int y);
109 
110  //
111  STATIC_DLL_IMPEXT static vector<string> extensions;
112 
113  // maybe have a read write lock here for texture cache, but currently I have no multithreaded access to it
114  STATIC_DLL_IMPEXT static unordered_map<string, Texture*> textureCache;
116 };
Texture entity.
Definition: Texture.h:24
static Texture * scale(Texture *texture, int width, int height, const string &idSuffix=":scaled")
Scale texture.
static STATIC_DLL_IMPEXT Mutex textureCacheMutex
static void removeFromCache(Texture *texture)
Remove texture from cache.
static STATIC_DLL_IMPEXT unordered_map< string, Texture * > textureCache
static const vector< string > & getTextureExtensions()
static Texture * read(const string &pathName, const string &fileName, bool useCache=true, bool powerOfTwo=true, const string &idPrefix=string())
Reads a texture.
static void scaleTextureLine(const ByteBuffer &pixelByteBuffer, ByteBuffer &pixelByteBufferScaled, int width, int textureWidth, int bytesPerPixel, int y)
Scales a texture line.
static Texture * read2(const string &texturePathName, const string &textureFileName, const string &transparencyTexturePathName, const string &transparencyTextureFileName, bool useCache=true, bool powerOfTwo=true, const string &idPrefix=string())
Reads a texture with additional transparency texture.
static Texture * smooth(Texture *texture, const string &idSuffix=":smoothed", float adjacentSampleWeight=0.05f)
Smooth texture.
static Texture * rotate(Texture *texture, float rotation, const string &idSuffix=":rotated")
Rotate texture around center.
static STATIC_DLL_IMPEXT vector< string > extensions
Mutex implementation.
Definition: Mutex.h:19
Byte buffer class.
Definition: ByteBuffer.h:27
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15