diff --git a/Source/Engine/Tools/TextureTool/TextureTool.cpp b/Source/Engine/Tools/TextureTool/TextureTool.cpp index c59904192..b5e22c84c 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.cpp +++ b/Source/Engine/Tools/TextureTool/TextureTool.cpp @@ -250,6 +250,8 @@ bool TextureTool::ImportTexture(const StringView& path, TextureData& textureData bool hasAlpha = false; #if COMPILE_WITH_DIRECTXTEX const auto failed = ImportTextureDirectXTex(type, path, textureData, options, errorMsg, hasAlpha); +#elif COMPILE_WITH_STB + const auto failed = ImportTextureStb(type, path, textureData, options, errorMsg, hasAlpha); #else const auto failed = true; LOG(Warning, "Importing textures is not supported on this platform."); @@ -443,11 +445,12 @@ TextureTool::PixelFormatSampler PixelFormatSamplers[] = sizeof(Color32), [](const void* ptr) { - return Color(*(Color32*)ptr); + return Color::SrgbToLinear(Color(*(Color32*)ptr)); }, [](const void* ptr, const Color& color) { - *(Color32*)ptr = Color32(color); + Color srgb = Color::LinearToSrgb(color); + *(Color32*)ptr = Color32(srgb); }, }, { @@ -555,11 +558,12 @@ TextureTool::PixelFormatSampler PixelFormatSamplers[] = [](const void* ptr) { const Color32 bgra = *(Color32*)ptr; - return Color(Color32(bgra.B, bgra.G, bgra.R, bgra.A)); + return Color::SrgbToLinear(Color(Color32(bgra.B, bgra.G, bgra.R, bgra.A))); }, [](const void* ptr, const Color& color) { - *(Color32*)ptr = Color32(byte(color.B * MAX_uint8), byte(color.G * MAX_uint8), byte(color.R * MAX_uint8), byte(color.A * MAX_uint8)); + Color srgb = Color::LinearToSrgb(color); + *(Color32*)ptr = Color32(byte(srgb.B * MAX_uint8), byte(srgb.G * MAX_uint8), byte(srgb.R * MAX_uint8), byte(srgb.A * MAX_uint8)); }, }, { @@ -581,11 +585,12 @@ TextureTool::PixelFormatSampler PixelFormatSamplers[] = [](const void* ptr) { const Color32 bgra = *(Color32*)ptr; - return Color(Color32(bgra.B, bgra.G, bgra.R, MAX_uint8)); + return Color::SrgbToLinear(Color(Color32(bgra.B, bgra.G, bgra.R, MAX_uint8))); }, [](const void* ptr, const Color& color) { - *(Color32*)ptr = Color32(byte(color.B * MAX_uint8), byte(color.G * MAX_uint8), byte(color.R * MAX_uint8), MAX_uint8); + Color srgb = Color::LinearToSrgb(color); + *(Color32*)ptr = Color32(byte(srgb.B * MAX_uint8), byte(srgb.G * MAX_uint8), byte(srgb.R * MAX_uint8), MAX_uint8); }, }, { diff --git a/Source/Engine/Tools/TextureTool/TextureTool.h b/Source/Engine/Tools/TextureTool/TextureTool.h index 9b32f4e7c..6337406ae 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.h +++ b/Source/Engine/Tools/TextureTool/TextureTool.h @@ -218,7 +218,7 @@ public: /// The Y texture coordinates (normalized to range 0-height). /// The data pointer for the texture slice (1D or 2D image). /// The row pitch (in bytes). The offset between each image rows. - /// The color to store. + /// The color to store (linear). static void Store(const PixelFormatSampler* sampler, int32 x, int32 y, const void* data, int32 rowPitch, const Color& color); /// @@ -232,7 +232,7 @@ public: /// The data pointer for the texture slice (1D or 2D image). /// The size of the input texture (in pixels). /// The row pitch (in bytes). The offset between each image rows. - /// The sampled color. + /// The sampled color (linear). static Color SamplePoint(const PixelFormatSampler* sampler, const Vector2& uv, const void* data, const Int2& size, int32 rowPitch); /// @@ -246,7 +246,7 @@ public: /// The Y texture coordinates (normalized to range 0-height). /// The data pointer for the texture slice (1D or 2D image). /// The row pitch (in bytes). The offset between each image rows. - /// The sampled color. + /// The sampled color (linear). static Color SamplePoint(const PixelFormatSampler* sampler, int32 x, int32 y, const void* data, int32 rowPitch); /// @@ -260,7 +260,7 @@ public: /// The data pointer for the texture slice (1D or 2D image). /// The size of the input texture (in pixels). /// The row pitch (in bytes). The offset between each image rows. - /// The sampled color. + /// The sampled color (linear). static Color SampleLinear(const PixelFormatSampler* sampler, const Vector2& uv, const void* data, const Int2& size, int32 rowPitch); private: @@ -291,6 +291,7 @@ private: #if COMPILE_WITH_STB static bool ExportTextureStb(ImageType type, const StringView& path, const TextureData& textureData); static bool ImportTextureStb(ImageType type, const StringView& path, TextureData& textureData, bool& hasAlpha); + static bool ImportTextureStb(ImageType type, const StringView& path, TextureData& textureData, const Options& options, String& errorMsg, bool& hasAlpha); static bool ConvertStb(TextureData& dst, const TextureData& src, const PixelFormat dstFormat); static bool ResizeStb(PixelFormat format, TextureMipData& dstMip, const TextureMipData& srcMip, int32 dstMipWidth, int32 dstMipHeight); static bool ResizeStb(TextureData& dst, const TextureData& src, int32 dstWidth, int32 dstHeight);