From 86463dfcb588b0f08afa482d576be1f463351c79 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Mon, 11 Nov 2024 20:46:07 -0800 Subject: [PATCH 1/3] texconv: add -ignore-srgb and fix -wic-lossless for JPG --- Texconv/texconv.cpp | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 24dcf3de..67c0867d 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -140,6 +140,7 @@ namespace OPT_INVERT_Y, OPT_RECONSTRUCT_Z, OPT_BCNONMULT4FIX, + OPT_IGNORE_SRGB_METADATA, #ifdef USE_XBOX_EXTS OPT_USE_XBOX, OPT_XGMODE, @@ -282,6 +283,7 @@ namespace { L"help", OPT_HELP }, { L"horizontal-flip", OPT_HFLIP }, { L"ignore-mips", OPT_DDS_IGNORE_MIPS }, + { L"ignore-srgb", OPT_IGNORE_SRGB_METADATA }, { L"image-filter", OPT_FILTER }, { L"invert-y", OPT_INVERT_Y }, { L"keep-coverage", OPT_PRESERVE_ALPHA_COVERAGE }, @@ -817,6 +819,9 @@ namespace L" -xgmode , --xbox-mode \n"\ L" Tile/swizzle using provided memory layout mode\n" #endif + L"\n" + L" (PNG, JPG, TIF, TGA input only)\n" + L" --ignore-srgb Ignores any gamma setting in the metadata\n" L"\n" L" (TGA input only)\n" L" --tga-zero-alpha Allow all zero alpha channel files to be loaded 'as is'\n" @@ -2088,6 +2093,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) else if (_wcsicmp(ext.c_str(), L".tga") == 0) { TGA_FLAGS tgaFlags = (IsBGR(format)) ? TGA_FLAGS_BGR : TGA_FLAGS_NONE; + if (dwOptions & (UINT64_C(1) << OPT_IGNORE_SRGB_METADATA)) + { + tgaFlags |= TGA_FLAGS_IGNORE_SRGB; + } if (dwOptions & (UINT64_C(1) << OPT_TGAZEROALPHA)) { tgaFlags |= TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA; @@ -2179,7 +2188,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) WIC_FLAGS wicFlags = WIC_FLAGS_NONE | dwFilter; if (FileType == CODEC_DDS) + { wicFlags |= WIC_FLAGS_ALL_FRAMES; + } + if (dwOptions & (UINT64_C(1) << OPT_IGNORE_SRGB_METADATA)) + { + wicFlags |= WIC_FLAGS_IGNORE_SRGB; + } hr = LoadFromWICFile(curpath.c_str(), wicFlags, &info, *image); if (FAILED(hr)) @@ -3798,13 +3813,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) switch (FileType) { case WIC_CODEC_JPEG: - if (wicLossless || wicQuality >= 0.f) + if (wicQuality >= 0.f) { PROPBAG2 options = {}; VARIANT varValues = {}; options.pstrName = const_cast(L"ImageQuality"); varValues.vt = VT_R4; - varValues.fltVal = (wicLossless) ? 1.f : wicQuality; + varValues.fltVal = wicQuality; std::ignore = props->Write(1, &options, &varValues); } break; @@ -3829,6 +3844,30 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } break; + case WIC_CODEC_HEIF: + { + PROPBAG2 options = {}; + VARIANT varValues = {}; + if (wicLossless) + { + options.pstrName = const_cast(L"HeifCompressionMethod"); + varValues.vt = VT_UI1; + #if defined(NTDDI_WIN10_CU) + varValues.bVal = WICHeifCompressionNone; + #else + varValues.bVal = 0x1 /* WICHeifCompressionNone */; + #endif + } + else if (wicQuality >= 0.f) + { + options.pstrName = const_cast(L"ImageQuality"); + varValues.vt = VT_R4; + varValues.fltVal = wicQuality; + } + std::ignore = props->Write(1, &options, &varValues); + } + break; + case WIC_CODEC_WMP: case CODEC_HDP: case CODEC_JXR: From 3c982367972584bd3481d53495531fd93da8fe7f Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 12 Nov 2024 13:23:52 -0800 Subject: [PATCH 2/3] More code review --- Texconv/texconv.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 67c0867d..404f2fc2 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -117,6 +117,7 @@ namespace OPT_TGAZEROALPHA, OPT_WIC_LOSSLESS, OPT_WIC_MULTIFRAME, + OPT_WIC_UNCOMPRESSED, OPT_NOLOGO, OPT_TIMING, OPT_SEPALPHA, @@ -313,6 +314,7 @@ namespace { L"vertical-flip", OPT_VFLIP }, { L"wic-lossless", OPT_WIC_LOSSLESS }, { L"wic-multiframe", OPT_WIC_MULTIFRAME }, + { L"wic-uncompressed", OPT_WIC_UNCOMPRESSED }, { L"wic-quality", OPT_WIC_QUALITY }, { L"width", OPT_WIDTH }, { L"x2-bias", OPT_X2_BIAS }, @@ -593,7 +595,6 @@ namespace #ifdef USE_OPENEXR { L"exr", CODEC_EXR }, #endif - { L"heic", WIC_CODEC_HEIF }, { L"heif", WIC_CODEC_HEIF }, { nullptr, CODEC_DDS } }; @@ -829,10 +830,11 @@ namespace L" (TGA output only)\n" L" -tga20 Write file including TGA 2.0 extension area\n" L"\n" - L" (BMP, PNG, JPG, TIF, WDP output only)\n" + L" (BMP, PNG, JPG, TIF, WDP, and HIEF output only)\n" L" -wicq , --wic-quality \n" L" When writing images with WIC use quality (0.0 to 1.0)\n" L" --wic-lossless When writing images with WIC use lossless mode\n" + L" --wic-uncompressed When writing images with WIC use uncompressed mode\n" L" --wic-multiframe When writing images with WIC encode multiframe images\n" L"\n" L" -nologo suppress copyright message\n" @@ -2209,7 +2211,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) } else if (_wcsicmp(ext.c_str(), L".webp") == 0) { - wprintf(L"INFO: This format requires installing the WEBP Image Extensions - https://www.microsoft.com/p/webp-image-extensions/9pg2dk419drg\n"); + wprintf(L"INFO: This format requires installing the WEBP Image Extensions - https://apps.microsoft.com/detail/9PG2DK419DRG\n"); } } continue; @@ -3808,7 +3810,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) hr = SaveToWICFile(img, nimages, WIC_FLAGS_NONE, GetWICCodec(codec), destName.c_str(), nullptr, [&](IPropertyBag2* props) { - const bool wicLossless = (dwOptions & (UINT64_C(1) << OPT_WIC_LOSSLESS)) != 0; + const bool lossless = (dwOptions & (UINT64_C(1) << OPT_WIC_LOSSLESS)) != 0; + const bool uncompressed = (dwOptions & (UINT64_C(1) << OPT_WIC_UNCOMPRESSED)) != 0; switch (FileType) { @@ -3828,7 +3831,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { PROPBAG2 options = {}; VARIANT varValues = {}; - if (wicLossless) + if (uncompressed) { options.pstrName = const_cast(L"TiffCompressionMethod"); varValues.vt = VT_UI1; @@ -3848,7 +3851,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { PROPBAG2 options = {}; VARIANT varValues = {}; - if (wicLossless) + if (uncompressed) { options.pstrName = const_cast(L"HeifCompressionMethod"); varValues.vt = VT_UI1; @@ -3874,7 +3877,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) { PROPBAG2 options = {}; VARIANT varValues = {}; - if (wicLossless) + if (lossless) { options.pstrName = const_cast(L"Lossless"); varValues.vt = VT_BOOL; From 66727f5e8bb3d962e3485c9706f04b2f80ab539c Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 12 Nov 2024 13:51:31 -0800 Subject: [PATCH 3/3] Minor code review --- Texconv/texconv.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 404f2fc2..561b77a4 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -3815,6 +3815,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) switch (FileType) { + default: case WIC_CODEC_JPEG: if (wicQuality >= 0.f) {