MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / SaveToPNG

Method SaveToPNG

GTE/Applications/GLX/WICFileIO.cpp:253–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253bool WICFileIO::SaveToPNG(std::string const& filename, std::shared_ptr<Texture2> const& texture)
254{
255 if (!texture)
256 {
257 return false;
258 }
259
260 int32_t bit_depth = 0;
261 int32_t color_type = 0;
262 png_uint_32 bytes_per_pixel = 0;
263 switch (texture->GetFormat())
264 {
265 case DF_R8G8B8A8_UNORM:
266 {
267 bit_depth = 8;
268 color_type = PNG_COLOR_TYPE_RGBA;
269 bytes_per_pixel = 4;
270 break;
271 }
272 case DF_R8G8_UNORM:
273 bit_depth = 8;
274 color_type = PNG_COLOR_TYPE_GA;
275 bytes_per_pixel = 2;
276 break;
277 case DF_R8_UNORM:
278 bit_depth = 8;
279 color_type = PNG_COLOR_TYPE_GRAY;
280 bytes_per_pixel = 1;
281 break;
282 case DF_R16G16B16A16_UNORM:
283 bit_depth = 16;
284 color_type = PNG_COLOR_TYPE_RGBA;
285 bytes_per_pixel = 8;
286 break;
287 case DF_R16G16_UNORM:
288 bit_depth = 16;
289 color_type = PNG_COLOR_TYPE_GA;
290 bytes_per_pixel = 4;
291 break;
292 case DF_R16_UNORM:
293 bit_depth = 16;
294 color_type = PNG_COLOR_TYPE_GRAY;
295 bytes_per_pixel = 2;
296 break;
297 default: // unsupported format
298 return false;
299 }
300
301 // The destructor for the helper will be called on any return from
302 // this function after the constructor call.
303 WICFileIOPrivateHelper helper(filename.c_str(), false);
304 if (!helper.fp)
305 {
306 return false;
307 }
308
309 helper.png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
310 if (!helper.png_ptr)

Callers

nothing calls this directly

Calls 3

GetFormatMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45

Tested by

no test coverage detected