MCPcopy Create free account
hub / github.com/DaedalusX64/daedalus / FlattenTexture

Function FlattenTexture

Source/Graphics/PngUtil.cpp:195–223  ·  view source on GitHub ↗

Utility function to flatten a native texture into an array of NativePf8888 values. Should live elsewhere, but need to share WritePngRow.

Source from the content-addressed store, hash-verified

193// Utility function to flatten a native texture into an array of NativePf8888 values.
194// Should live elsewhere, but need to share WritePngRow.
195void FlattenTexture(const CNativeTexture * texture, void * dst, size_t len)
196{
197 const u8 * p = reinterpret_cast< const u8 * >( texture->GetData() );
198 const NativePf8888 * pal8888 = reinterpret_cast< const NativePf8888 * >( texture->GetPalette() );
199
200 u32 width = texture->GetWidth();
201 u32 height = texture->GetHeight();
202 u32 pitch = texture->GetStride();
203
204#ifdef DAEDALUS_ENABLE_ASSERTS
205 DAEDALUS_ASSERT(len == width * sizeof(NativePf8888) * height, "Unexpected number of bytes.");
206#endif
207 u8 * line = static_cast<u8 *>( dst );
208 for ( u32 y = 0; y < height; y++ )
209 {
210 switch (texture->GetFormat())
211 {
212 case TexFmt_5650: WritePngRow< NativePf5650 >( line, p, width ); break;
213 case TexFmt_5551: WritePngRow< NativePf5551 >( line, p, width ); break;
214 case TexFmt_4444: WritePngRow< NativePf4444 >( line, p, width ); break;
215 case TexFmt_8888: WritePngRow< NativePf8888 >( line, p, width ); break;
216 case TexFmt_CI4_8888: WritePngRowPal4( line, p, width, pal8888 ); break;
217 case TexFmt_CI8_8888: WritePngRowPal8( line, p, width, pal8888 ); break;
218 }
219
220 p += pitch;
221 line += width * sizeof(NativePf8888);
222 }
223}

Callers 1

EncodeTextureFunction · 0.85

Calls 8

WritePngRowPal4Function · 0.85
WritePngRowPal8Function · 0.85
GetDataMethod · 0.80
GetPaletteMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45
GetStrideMethod · 0.45
GetFormatMethod · 0.45

Tested by

no test coverage detected