--------------------------------------------------------------------------
| 437 | |
| 438 | //-------------------------------------------------------------------------- |
| 439 | static bool sWritePNG(GBitmap *bitmap, Stream &stream, U32 compressionLevel) |
| 440 | { |
| 441 | U32 waterMark = FrameAllocator::getWaterMark(); |
| 442 | |
| 443 | if ( compressionLevel < 10 ) |
| 444 | { |
| 445 | bool retVal = _writePNG(bitmap, stream, compressionLevel, 0, PNG_ALL_FILTERS); |
| 446 | FrameAllocator::setWaterMark(waterMark); |
| 447 | return retVal; |
| 448 | } |
| 449 | |
| 450 | // check all our methods of compression to find the best one and use it |
| 451 | U8* buffer = new U8[1 << 22]; // 4 Megs. Should be enough... |
| 452 | MemStream* pMemStream = new MemStream(1 << 22, buffer, false, true); |
| 453 | |
| 454 | const U32 zStrategies[] = { Z_DEFAULT_STRATEGY, |
| 455 | Z_FILTERED }; |
| 456 | const U32 pngFilters[] = { PNG_FILTER_NONE, |
| 457 | PNG_FILTER_SUB, |
| 458 | PNG_FILTER_UP, |
| 459 | PNG_FILTER_AVG, |
| 460 | PNG_FILTER_PAETH, |
| 461 | PNG_ALL_FILTERS }; |
| 462 | |
| 463 | U32 minSize = 0xFFFFFFFF; |
| 464 | U32 bestStrategy = 0xFFFFFFFF; |
| 465 | U32 bestFilter = 0xFFFFFFFF; |
| 466 | U32 bestCLevel = 0xFFFFFFFF; |
| 467 | |
| 468 | for (U32 cl = 0; cl <=9; cl++) |
| 469 | { |
| 470 | for (U32 zs = 0; zs < 2; zs++) |
| 471 | { |
| 472 | for (U32 pf = 0; pf < 6; pf++) |
| 473 | { |
| 474 | pMemStream->setPosition(0); |
| 475 | |
| 476 | U32 waterMarkInner = FrameAllocator::getWaterMark(); |
| 477 | |
| 478 | if (_writePNG(bitmap, *pMemStream, cl, zStrategies[zs], pngFilters[pf]) == false) |
| 479 | AssertFatal(false, "Handle this error!"); |
| 480 | |
| 481 | FrameAllocator::setWaterMark(waterMarkInner); |
| 482 | |
| 483 | if (pMemStream->getPosition() < minSize) |
| 484 | { |
| 485 | minSize = pMemStream->getPosition(); |
| 486 | bestStrategy = zs; |
| 487 | bestFilter = pf; |
| 488 | bestCLevel = cl; |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | AssertFatal(minSize != 0xFFFFFFFF, "Error, no best found?"); |
| 494 | |
| 495 | delete pMemStream; |
| 496 | delete [] buffer; |
nothing calls this directly
no test coverage detected