| 66 | } |
| 67 | |
| 68 | bool TextureMipData::GetPixels(Array<Color32>& pixels, int32 width, int32 height, PixelFormat format) const |
| 69 | { |
| 70 | const int32 size = width * height; |
| 71 | if (Data.IsInvalid() || size < 1) |
| 72 | return true; |
| 73 | pixels.Resize(size); |
| 74 | byte* dst = (byte*)pixels.Get(); |
| 75 | const int32 dstRowSize = width * sizeof(Color32); |
| 76 | const byte* src = Data.Get(); |
| 77 | const int32 srcRowSize = RowPitch; |
| 78 | switch (format) |
| 79 | { |
| 80 | case PixelFormat::R8G8B8A8_SInt: |
| 81 | case PixelFormat::R8G8B8A8_Typeless: |
| 82 | case PixelFormat::R8G8B8A8_SNorm: |
| 83 | case PixelFormat::R8G8B8A8_UInt: |
| 84 | case PixelFormat::R8G8B8A8_UNorm: |
| 85 | case PixelFormat::R8G8B8A8_UNorm_sRGB: |
| 86 | case PixelFormat::R8G8_B8G8_UNorm: |
| 87 | case PixelFormat::B8G8R8A8_Typeless: |
| 88 | case PixelFormat::B8G8R8A8_UNorm: |
| 89 | case PixelFormat::B8G8R8A8_UNorm_sRGB: |
| 90 | case PixelFormat::B8G8R8X8_Typeless: |
| 91 | case PixelFormat::B8G8R8X8_UNorm: |
| 92 | case PixelFormat::B8G8R8X8_UNorm_sRGB: |
| 93 | if (srcRowSize == dstRowSize) |
| 94 | Platform::MemoryCopy(dst, src, RowPitch * Lines); |
| 95 | else |
| 96 | { |
| 97 | for (uint32 row = 0; row < Lines; row++) |
| 98 | { |
| 99 | Platform::MemoryCopy(dst, src, dstRowSize); |
| 100 | dst += dstRowSize; |
| 101 | src += srcRowSize; |
| 102 | } |
| 103 | } |
| 104 | break; |
| 105 | default: |
| 106 | { |
| 107 | // Try to use texture sampler utility |
| 108 | auto sampler = PixelFormatSampler::Get(format); |
| 109 | if (sampler) |
| 110 | { |
| 111 | for (int32 y = 0; y < height; y++) |
| 112 | { |
| 113 | for (int32 x = 0; x < width; x++) |
| 114 | { |
| 115 | Color c = sampler->SamplePoint(src, x, y, RowPitch); |
| 116 | *(Color32*)(dst + dstRowSize * y + x * sizeof(Color32)) = Color32(c); |
| 117 | } |
| 118 | } |
| 119 | return false; |
| 120 | } |
| 121 | LOG(Error, "Unsupported texture data format {0}.", ScriptingEnum::ToString(format)); |
| 122 | return true; |
| 123 | } |
| 124 | } |
| 125 | return false; |