| 201 | #endif |
| 202 | |
| 203 | bool TextureTool::ExportTextureStb(ImageType type, const StringView& path, const TextureData& textureData) |
| 204 | { |
| 205 | if (textureData.GetArraySize() != 1) |
| 206 | { |
| 207 | LOG(Warning, "Exporting texture arrays and cubemaps is not supported."); |
| 208 | } |
| 209 | TextureData const* texture = &textureData; |
| 210 | |
| 211 | #if USE_EDITOR |
| 212 | // Handle compressed textures |
| 213 | TextureData decompressed; |
| 214 | texture = stbDecompress(textureData, decompressed); |
| 215 | if (!texture) |
| 216 | return true; |
| 217 | #endif |
| 218 | |
| 219 | // Convert into RGBA8 |
| 220 | const auto sampler = PixelFormatSampler::Get(texture->Format); |
| 221 | if (sampler == nullptr) |
| 222 | { |
| 223 | LOG(Warning, "Texture data format {0} is not supported.", (int32)textureData.Format); |
| 224 | return true; |
| 225 | } |
| 226 | const auto srcData = texture->GetData(0, 0); |
| 227 | const int comp = 4; |
| 228 | Array<byte> data; |
| 229 | bool sRGB = PixelFormatExtensions::IsSRGB(texture->Format); |
| 230 | if (type == ImageType::HDR) |
| 231 | { |
| 232 | data.Resize(sizeof(float) * comp * texture->Width * texture->Height); |
| 233 | |
| 234 | auto ptr = (Float4*)data.Get(); |
| 235 | for (int32 y = 0; y < texture->Height; y++) |
| 236 | { |
| 237 | for (int32 x = 0; x < texture->Width; x++) |
| 238 | { |
| 239 | Color color = sampler->SamplePoint(srcData->Data.Get(), x, y, srcData->RowPitch); |
| 240 | if (sRGB) |
| 241 | color = Color::SrgbToLinear(color); |
| 242 | *(ptr + x + y * texture->Width) = color.ToFloat4(); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | data.Resize(sizeof(Color32) * comp * texture->Width * texture->Height); |
| 249 | |
| 250 | auto ptr = (Color32*)data.Get(); |
| 251 | for (int32 y = 0; y < texture->Height; y++) |
| 252 | { |
| 253 | for (int32 x = 0; x < texture->Width; x++) |
| 254 | { |
| 255 | Color color = sampler->SamplePoint(srcData->Data.Get(), x, y, srcData->RowPitch); |
| 256 | if (sRGB) |
| 257 | color = Color::SrgbToLinear(color); |
| 258 | *(ptr + x + y * texture->Width) = Color32(color); |
| 259 | } |
| 260 | } |
nothing calls this directly
no test coverage detected