| 712 | } |
| 713 | |
| 714 | bool TextureTool::Transform(TextureData& texture, const Function<void(Color&)>& transformation) |
| 715 | { |
| 716 | PROFILE_CPU(); |
| 717 | PROFILE_MEM(GraphicsTextures); |
| 718 | auto sampler = PixelFormatSampler::Get(texture.Format); |
| 719 | if (!sampler) |
| 720 | return true; |
| 721 | for (auto& slice : texture.Items) |
| 722 | { |
| 723 | for (int32 mipIndex = 0; mipIndex < slice.Mips.Count(); mipIndex++) |
| 724 | { |
| 725 | auto& mip = slice.Mips[mipIndex]; |
| 726 | auto mipWidth = Math::Max(texture.Width >> mipIndex, 1); |
| 727 | auto mipHeight = Math::Max(texture.Height >> mipIndex, 1); |
| 728 | for (int32 y = 0; y < mipHeight; y++) |
| 729 | { |
| 730 | for (int32 x = 0; x < mipWidth; x++) |
| 731 | { |
| 732 | Color color = sampler->SamplePoint(mip.Data.Get(), x, y, mip.RowPitch); |
| 733 | transformation(color); |
| 734 | sampler->Store(mip.Data.Get(), x, y, mip.RowPitch, color); |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | return false; |
| 740 | } |
| 741 | |
| 742 | #endif |