| 510 | } |
| 511 | |
| 512 | bool Tr2HostBitmap::Compress( unsigned compressionFormat, unsigned qualityLevel, TriTextureRes* output ) |
| 513 | { |
| 514 | if( !output || !IsValid() || GetType() != TEX_TYPE_2D || compressionFormat >= TR2DXT_COMPRESS_COUNT ) |
| 515 | { |
| 516 | return false; |
| 517 | } |
| 518 | |
| 519 | static const PixelFormat format[TR2DXT_COMPRESS_COUNT] = { |
| 520 | PIXEL_FORMAT_BC1_UNORM, // TR2DXT_COMPRESS_RT_DXT1 = 0, |
| 521 | PIXEL_FORMAT_BC3_UNORM, // TR2DXT_COMPRESS_RT_DXT5 = 1, |
| 522 | PIXEL_FORMAT_BC3_UNORM, // TR2DXT_COMPRESS_RT_DXT5N = 2, |
| 523 | PIXEL_FORMAT_BC3_UNORM, // TR2DXT_COMPRESS_RT_YCOCGDXT5 = 3, |
| 524 | PIXEL_FORMAT_BC3_UNORM, // TR2DXT_COMPRESS_RT_3DC = 4, |
| 525 | PIXEL_FORMAT_BC1_UNORM, // TR2DXT_COMPRESS_SQUISH_DXT1 = 5, |
| 526 | PIXEL_FORMAT_BC1_UNORM, // TR2DXT_COMPRESS_SQUISH_DXT3 = 6, |
| 527 | PIXEL_FORMAT_BC3_UNORM, // TR2DXT_COMPRESS_SQUISH_DXT5 = 7, |
| 528 | PIXEL_FORMAT_BC4_UNORM, // TR2DXT_COMPRESS_SQUISH_KBC4 = 8, |
| 529 | PIXEL_FORMAT_BC5_UNORM, // TR2DXT_COMPRESS_SQUISH_KBC5 = 9, |
| 530 | }; |
| 531 | |
| 532 | { |
| 533 | unsigned pitch = ( m_width + 3 ) / 4 * Tr2RenderContextEnum::GetBlockByteSize( format[compressionFormat] ); |
| 534 | CcpMallocBuffer destination( "Tr2HostBitmap::Compress", pitch * ( m_height + 3 ) / 4 ); |
| 535 | |
| 536 | Tr2DxtCompressControl* control = CCP_NEW( "TriDevice::CompressSurface/control" ) Tr2DxtCompressControl; |
| 537 | ON_BLOCK_EXIT( [&] { CCP_DELETE( control ); } ); |
| 538 | |
| 539 | if( !Tr2DxtCompressSurfaceAsync( (Tr2DxtCompressionFormat)compressionFormat, |
| 540 | (uint8_t*)GetRawData(), |
| 541 | m_width, |
| 542 | m_height, |
| 543 | (uint8_t*)destination.get(), |
| 544 | pitch, |
| 545 | control, |
| 546 | qualityLevel ) ) |
| 547 | { |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | Tr2HostBitmapPtr bitmap; |
| 552 | bitmap.CreateInstance(); |
| 553 | bitmap->Create( m_width, m_height, 1, format[compressionFormat] ); |
| 554 | memcpy( bitmap->GetRawData(), destination.get(), bitmap->GetRawDataSize() ); |
| 555 | output->CreateFromHostBitmap( bitmap ); |
| 556 | } |
| 557 | return true; |
| 558 | } |
| 559 | |
| 560 | |
| 561 | bool chan_selected( const std::string& channels, char channel ) |
nothing calls this directly
no test coverage detected