| 927 | } |
| 928 | |
| 929 | bool TextureTool::ResizeStb(PixelFormat format, TextureMipData& dstMip, const TextureMipData& srcMip, int32 dstMipWidth, int32 dstMipHeight) |
| 930 | { |
| 931 | // Setup |
| 932 | auto formatSize = PixelFormatExtensions::SizeInBytes(format); |
| 933 | auto components = PixelFormatExtensions::ComputeComponentsCount(format); |
| 934 | auto srcMipWidth = srcMip.RowPitch / formatSize; |
| 935 | auto srcMipHeight = srcMip.DepthPitch / srcMip.RowPitch; |
| 936 | auto sampler = PixelFormatSampler::Get(format); |
| 937 | |
| 938 | // Allocate memory |
| 939 | dstMip.RowPitch = dstMipWidth * formatSize; |
| 940 | dstMip.DepthPitch = dstMip.RowPitch * dstMipHeight; |
| 941 | dstMip.Lines = dstMipHeight; |
| 942 | dstMip.Data.Allocate(dstMip.DepthPitch); |
| 943 | |
| 944 | // Resize texture |
| 945 | switch (format) |
| 946 | { |
| 947 | case PixelFormat::R8_Typeless: |
| 948 | case PixelFormat::R8_SInt: |
| 949 | case PixelFormat::R8_SNorm: |
| 950 | case PixelFormat::R8G8_Typeless: |
| 951 | case PixelFormat::R8G8_SInt: |
| 952 | case PixelFormat::R8G8_SNorm: |
| 953 | case PixelFormat::R8G8B8A8_Typeless: |
| 954 | case PixelFormat::R8G8B8A8_UNorm: |
| 955 | case PixelFormat::R8G8B8A8_UInt: |
| 956 | case PixelFormat::R8G8B8A8_SNorm: |
| 957 | case PixelFormat::R8G8B8A8_SInt: |
| 958 | case PixelFormat::B8G8R8A8_UNorm: |
| 959 | case PixelFormat::B8G8R8X8_Typeless: |
| 960 | case PixelFormat::B8G8R8X8_UNorm: |
| 961 | { |
| 962 | if (!stbir_resize_uint8((const uint8*)srcMip.Data.Get(), srcMipWidth, srcMipHeight, srcMip.RowPitch, (uint8*)dstMip.Data.Get(), dstMipWidth, dstMipHeight, dstMip.RowPitch, components)) |
| 963 | { |
| 964 | LOG(Warning, "Cannot resize image."); |
| 965 | return true; |
| 966 | } |
| 967 | break; |
| 968 | } |
| 969 | case PixelFormat::R8G8B8A8_UNorm_sRGB: |
| 970 | case PixelFormat::B8G8R8A8_UNorm_sRGB: |
| 971 | case PixelFormat::B8G8R8X8_UNorm_sRGB: |
| 972 | { |
| 973 | auto alphaChannel = format == PixelFormat::B8G8R8X8_UNorm_sRGB ? STBIR_ALPHA_CHANNEL_NONE : 3; |
| 974 | if (!stbir_resize_uint8_srgb((const uint8*)srcMip.Data.Get(), srcMipWidth, srcMipHeight, srcMip.RowPitch, (uint8*)dstMip.Data.Get(), dstMipWidth, dstMipHeight, dstMip.RowPitch, components, alphaChannel, 0)) |
| 975 | { |
| 976 | LOG(Warning, "Cannot resize image."); |
| 977 | return true; |
| 978 | } |
| 979 | break; |
| 980 | } |
| 981 | case PixelFormat::R32_Typeless: |
| 982 | case PixelFormat::R32_Float: |
| 983 | case PixelFormat::R32G32_Float: |
| 984 | case PixelFormat::R32G32B32_Float: |
| 985 | case PixelFormat::R32G32B32A32_Float: |
| 986 | { |
nothing calls this directly
no test coverage detected