--------------------------------------------------------------------------
| 321 | |
| 322 | //-------------------------------------------------------------------------- |
| 323 | static bool _writePNG(GBitmap *bitmap, Stream &stream, U32 compressionLevel, U32 strategy, U32 filter) |
| 324 | { |
| 325 | GFXFormat format = bitmap->getFormat(); |
| 326 | |
| 327 | // ONLY RGB bitmap writing supported at this time! |
| 328 | AssertFatal( format == GFXFormatR8G8B8 || |
| 329 | format == GFXFormatR8G8B8A8 || |
| 330 | format == GFXFormatR8G8B8X8 || |
| 331 | format == GFXFormatA8 || |
| 332 | format == GFXFormatR5G6B5 || |
| 333 | format == GFXFormatR8G8B8A8_LINEAR_FORCE, "_writePNG: ONLY RGB bitmap writing supported at this time."); |
| 334 | |
| 335 | if ( format != GFXFormatR8G8B8 && |
| 336 | format != GFXFormatR8G8B8A8 && |
| 337 | format != GFXFormatR8G8B8X8 && |
| 338 | format != GFXFormatA8 && |
| 339 | format != GFXFormatR5G6B5 && format != GFXFormatR8G8B8A8_LINEAR_FORCE) |
| 340 | return false; |
| 341 | |
| 342 | png_structp png_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, |
| 343 | NULL, |
| 344 | pngFatalErrorFn, |
| 345 | pngWarningFn, |
| 346 | NULL, |
| 347 | pngMallocFn, |
| 348 | pngFreeFn); |
| 349 | if (png_ptr == NULL) |
| 350 | return (false); |
| 351 | |
| 352 | png_infop info_ptr = png_create_info_struct(png_ptr); |
| 353 | if (info_ptr == NULL) |
| 354 | { |
| 355 | png_destroy_write_struct(&png_ptr, (png_infopp)NULL); |
| 356 | return false; |
| 357 | } |
| 358 | |
| 359 | png_set_write_fn(png_ptr, &stream, pngWriteDataFn, pngFlushDataFn); |
| 360 | |
| 361 | // Set the compression level and image filters |
| 362 | png_set_compression_window_bits(png_ptr, 15); |
| 363 | png_set_compression_level(png_ptr, compressionLevel); |
| 364 | png_set_filter(png_ptr, 0, filter); |
| 365 | |
| 366 | // Set the image information here. Width and height are up to 2^31, |
| 367 | // bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on |
| 368 | // the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, |
| 369 | // PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, |
| 370 | // or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or |
| 371 | // PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST |
| 372 | // currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED |
| 373 | |
| 374 | U32 width = bitmap->getWidth(); |
| 375 | U32 height = bitmap->getHeight(); |
| 376 | |
| 377 | if (format == GFXFormatR8G8B8) |
| 378 | { |
| 379 | png_set_IHDR(png_ptr, info_ptr, |
| 380 | width, height, // the width & height |
no test coverage detected