TDME2  1.9.200
PNGTextureWriter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ext/libpng/png.h>
4 
5 #include <string>
6 #include <vector>
7 
8 #include <tdme/tdme.h>
10 #include <tdme/engine/fwd-tdme.h>
12 
13 using std::string;
14 using std::vector;
15 
18 
19 /**
20  * PNG texture writer class
21  * @author Andreas Drewke
22  */
24 {
25  friend class Texture;
26 private:
27  /**
28  * PNG output stream
29  */
31  public:
32 
33  /**
34  * Public constructor
35  */
36  PNGOutputStream(vector<uint8_t>* data): data(data) {
37  }
38 
39  /**
40  * Destructor
41  */
43  }
44 
45  /**
46  * Read byte
47  * @param inBytes in bytes to write
48  * @param inBytesToRead in bytes to read
49  */
50  void writeBytes(int8_t* inBytes, int32_t inBytesToRead) {
51  for (int32_t i = 0; i < inBytesToRead; i++) {
52  data->push_back(inBytes[i]);
53  }
54  }
55 
56  private:
57  vector<uint8_t>* data;
58  };
59 
60  /**
61  * Write PNG data to memory
62  * @param png_ptr png structure
63  * @param inBytes in bytes
64  * @param inBytesToWrite in bytes to write
65  */
66  static void writePNGDataToMemory(png_structp png_ptr, png_bytep inBytes, png_size_t inBytesToWrite);
67 
68  /**
69  * Flush PNG data
70  * @param png_ptr png structure
71  */
72  static void flushPNGDataToMemory(png_structp png_ptr);
73 
74 public:
75 
76  /**
77  * Writes a texture to PNG file
78  * @param texture texture
79  * @param pathName path name
80  * @param fileName file name
81  * @param removeAlphaChannel remove alpha channel
82  * @param flipY flip Y
83  * @return success
84  */
85  static bool write(Texture* texture, const string& pathName, const string& fileName, bool removeAlphaChannel = true, bool flipY = true);
86 
87  /**
88  * Writes a texture to PNG using a data vector
89  * @param texture texture
90  * @param pngData PNG data
91  * @param removeAlphaChannel remove alpha channel
92  * @param flipY flip Y
93  * @return success
94  */
95  static bool write(Texture* texture, vector<uint8_t>& pngData, bool removeAlphaChannel = true, bool flipY = true);
96 
97  /**
98  * Writes a texture to PNG using a data vector
99  * @param width width
100  * @param height height
101  * @param bytesPerPixel bytes per pixel
102  * @param textureByteBuffer texture RGB byte buffer
103  * @param pngData PNG data
104  * @param removeAlphaChannel remove alpha channel
105  * @return success
106  */
107  static bool write(int width, int height, int bytesPerPixel, const ByteBuffer& textureByteBuffer, vector<uint8_t>& pngData, bool removeAlphaChannel = true, bool flipY = false);
108 
109 };
Texture entity.
Definition: Texture.h:24
void writeBytes(int8_t *inBytes, int32_t inBytesToRead)
Read byte.
PNGOutputStream(vector< uint8_t > *data)
Public constructor.
static bool write(Texture *texture, const string &pathName, const string &fileName, bool removeAlphaChannel=true, bool flipY=true)
Writes a texture to PNG file.
static void writePNGDataToMemory(png_structp png_ptr, png_bytep inBytes, png_size_t inBytesToWrite)
Write PNG data to memory.
static void flushPNGDataToMemory(png_structp png_ptr)
Flush PNG data.
Byte buffer class.
Definition: ByteBuffer.h:27