Skip to content

Commit 2b6f585

Browse files
authored
texconv: add --ignore-srgb, --wic-uncompressed and revisit --wic-lossless (#555)
1 parent 37a18e9 commit 2b6f585

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

Texconv/texconv.cpp

+51-8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ namespace
117117
OPT_TGAZEROALPHA,
118118
OPT_WIC_LOSSLESS,
119119
OPT_WIC_MULTIFRAME,
120+
OPT_WIC_UNCOMPRESSED,
120121
OPT_NOLOGO,
121122
OPT_TIMING,
122123
OPT_SEPALPHA,
@@ -140,6 +141,7 @@ namespace
140141
OPT_INVERT_Y,
141142
OPT_RECONSTRUCT_Z,
142143
OPT_BCNONMULT4FIX,
144+
OPT_IGNORE_SRGB_METADATA,
143145
#ifdef USE_XBOX_EXTS
144146
OPT_USE_XBOX,
145147
OPT_XGMODE,
@@ -282,6 +284,7 @@ namespace
282284
{ L"help", OPT_HELP },
283285
{ L"horizontal-flip", OPT_HFLIP },
284286
{ L"ignore-mips", OPT_DDS_IGNORE_MIPS },
287+
{ L"ignore-srgb", OPT_IGNORE_SRGB_METADATA },
285288
{ L"image-filter", OPT_FILTER },
286289
{ L"invert-y", OPT_INVERT_Y },
287290
{ L"keep-coverage", OPT_PRESERVE_ALPHA_COVERAGE },
@@ -311,6 +314,7 @@ namespace
311314
{ L"vertical-flip", OPT_VFLIP },
312315
{ L"wic-lossless", OPT_WIC_LOSSLESS },
313316
{ L"wic-multiframe", OPT_WIC_MULTIFRAME },
317+
{ L"wic-uncompressed", OPT_WIC_UNCOMPRESSED },
314318
{ L"wic-quality", OPT_WIC_QUALITY },
315319
{ L"width", OPT_WIDTH },
316320
{ L"x2-bias", OPT_X2_BIAS },
@@ -591,7 +595,6 @@ namespace
591595
#ifdef USE_OPENEXR
592596
{ L"exr", CODEC_EXR },
593597
#endif
594-
{ L"heic", WIC_CODEC_HEIF },
595598
{ L"heif", WIC_CODEC_HEIF },
596599
{ nullptr, CODEC_DDS }
597600
};
@@ -817,17 +820,21 @@ namespace
817820
L" -xgmode <mode>, --xbox-mode <mode>\n"\
818821
L" Tile/swizzle using provided memory layout mode\n"
819822
#endif
823+
L"\n"
824+
L" (PNG, JPG, TIF, TGA input only)\n"
825+
L" --ignore-srgb Ignores any gamma setting in the metadata\n"
820826
L"\n"
821827
L" (TGA input only)\n"
822828
L" --tga-zero-alpha Allow all zero alpha channel files to be loaded 'as is'\n"
823829
L"\n"
824830
L" (TGA output only)\n"
825831
L" -tga20 Write file including TGA 2.0 extension area\n"
826832
L"\n"
827-
L" (BMP, PNG, JPG, TIF, WDP output only)\n"
833+
L" (BMP, PNG, JPG, TIF, WDP, and HIEF output only)\n"
828834
L" -wicq <quality>, --wic-quality <quality>\n"
829835
L" When writing images with WIC use quality (0.0 to 1.0)\n"
830836
L" --wic-lossless When writing images with WIC use lossless mode\n"
837+
L" --wic-uncompressed When writing images with WIC use uncompressed mode\n"
831838
L" --wic-multiframe When writing images with WIC encode multiframe images\n"
832839
L"\n"
833840
L" -nologo suppress copyright message\n"
@@ -2088,6 +2095,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
20882095
else if (_wcsicmp(ext.c_str(), L".tga") == 0)
20892096
{
20902097
TGA_FLAGS tgaFlags = (IsBGR(format)) ? TGA_FLAGS_BGR : TGA_FLAGS_NONE;
2098+
if (dwOptions & (UINT64_C(1) << OPT_IGNORE_SRGB_METADATA))
2099+
{
2100+
tgaFlags |= TGA_FLAGS_IGNORE_SRGB;
2101+
}
20912102
if (dwOptions & (UINT64_C(1) << OPT_TGAZEROALPHA))
20922103
{
20932104
tgaFlags |= TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA;
@@ -2179,7 +2190,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
21792190

21802191
WIC_FLAGS wicFlags = WIC_FLAGS_NONE | dwFilter;
21812192
if (FileType == CODEC_DDS)
2193+
{
21822194
wicFlags |= WIC_FLAGS_ALL_FRAMES;
2195+
}
2196+
if (dwOptions & (UINT64_C(1) << OPT_IGNORE_SRGB_METADATA))
2197+
{
2198+
wicFlags |= WIC_FLAGS_IGNORE_SRGB;
2199+
}
21832200

21842201
hr = LoadFromWICFile(curpath.c_str(), wicFlags, &info, *image);
21852202
if (FAILED(hr))
@@ -2194,7 +2211,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
21942211
}
21952212
else if (_wcsicmp(ext.c_str(), L".webp") == 0)
21962213
{
2197-
wprintf(L"INFO: This format requires installing the WEBP Image Extensions - https://www.microsoft.com/p/webp-image-extensions/9pg2dk419drg\n");
2214+
wprintf(L"INFO: This format requires installing the WEBP Image Extensions - https://apps.microsoft.com/detail/9PG2DK419DRG\n");
21982215
}
21992216
}
22002217
continue;
@@ -3793,18 +3810,20 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
37933810
hr = SaveToWICFile(img, nimages, WIC_FLAGS_NONE, GetWICCodec(codec), destName.c_str(), nullptr,
37943811
[&](IPropertyBag2* props)
37953812
{
3796-
const bool wicLossless = (dwOptions & (UINT64_C(1) << OPT_WIC_LOSSLESS)) != 0;
3813+
const bool lossless = (dwOptions & (UINT64_C(1) << OPT_WIC_LOSSLESS)) != 0;
3814+
const bool uncompressed = (dwOptions & (UINT64_C(1) << OPT_WIC_UNCOMPRESSED)) != 0;
37973815

37983816
switch (FileType)
37993817
{
3818+
default:
38003819
case WIC_CODEC_JPEG:
3801-
if (wicLossless || wicQuality >= 0.f)
3820+
if (wicQuality >= 0.f)
38023821
{
38033822
PROPBAG2 options = {};
38043823
VARIANT varValues = {};
38053824
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
38063825
varValues.vt = VT_R4;
3807-
varValues.fltVal = (wicLossless) ? 1.f : wicQuality;
3826+
varValues.fltVal = wicQuality;
38083827
std::ignore = props->Write(1, &options, &varValues);
38093828
}
38103829
break;
@@ -3813,7 +3832,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
38133832
{
38143833
PROPBAG2 options = {};
38153834
VARIANT varValues = {};
3816-
if (wicLossless)
3835+
if (uncompressed)
38173836
{
38183837
options.pstrName = const_cast<wchar_t*>(L"TiffCompressionMethod");
38193838
varValues.vt = VT_UI1;
@@ -3829,13 +3848,37 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
38293848
}
38303849
break;
38313850

3851+
case WIC_CODEC_HEIF:
3852+
{
3853+
PROPBAG2 options = {};
3854+
VARIANT varValues = {};
3855+
if (uncompressed)
3856+
{
3857+
options.pstrName = const_cast<wchar_t*>(L"HeifCompressionMethod");
3858+
varValues.vt = VT_UI1;
3859+
#if defined(NTDDI_WIN10_CU)
3860+
varValues.bVal = WICHeifCompressionNone;
3861+
#else
3862+
varValues.bVal = 0x1 /* WICHeifCompressionNone */;
3863+
#endif
3864+
}
3865+
else if (wicQuality >= 0.f)
3866+
{
3867+
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
3868+
varValues.vt = VT_R4;
3869+
varValues.fltVal = wicQuality;
3870+
}
3871+
std::ignore = props->Write(1, &options, &varValues);
3872+
}
3873+
break;
3874+
38323875
case WIC_CODEC_WMP:
38333876
case CODEC_HDP:
38343877
case CODEC_JXR:
38353878
{
38363879
PROPBAG2 options = {};
38373880
VARIANT varValues = {};
3838-
if (wicLossless)
3881+
if (lossless)
38393882
{
38403883
options.pstrName = const_cast<wchar_t*>(L"Lossless");
38413884
varValues.vt = VT_BOOL;

0 commit comments

Comments
 (0)