MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / ReadPNGData

Method ReadPNGData

src/lua/LuaTextures.cpp:165–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163
164 private:
165 bool ReadPNGData(const std::string& pngData) {
166 std::istringstream iss(pngData);
167 PNGImageFile image(&iss);
168 if (!image.isOpen()) {
169 return false;
170 }
171
172 type = GL_UNSIGNED_BYTE;
173 xsize = (GLint)image.getWidth();
174 ysize = (GLint)image.getHeight();
175
176 // set the data format based on the number of channels
177 const int channels = image.getNumChannels();
178 switch (channels) {
179 case 1: { format = GL_LUMINANCE; break; }
180 case 2: { format = GL_LUMINANCE_ALPHA; break; }
181 case 3: { format = GL_RGB; break; }
182 case 4: { format = GL_RGBA; break; }
183 default: {
184 return false;
185 }
186 }
187
188 const int bufSize = (xsize * ysize * channels);
189 data = new char[bufSize];
190 if (!image.read(data)) {
191 delete[] data;
192 data = NULL;
193 return false;
194 }
195
196 ownData = true;
197
198 return true;
199 }
200
201 public:
202 GLsizei xsize;

Callers

nothing calls this directly

Calls 5

isOpenMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
getNumChannelsMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected