Skip to content

Commit 86463df

Browse files
committed
texconv: add -ignore-srgb and fix -wic-lossless for JPG
1 parent 2d87c06 commit 86463df

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

Texconv/texconv.cpp

+41-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ namespace
140140
OPT_INVERT_Y,
141141
OPT_RECONSTRUCT_Z,
142142
OPT_BCNONMULT4FIX,
143+
OPT_IGNORE_SRGB_METADATA,
143144
#ifdef USE_XBOX_EXTS
144145
OPT_USE_XBOX,
145146
OPT_XGMODE,
@@ -282,6 +283,7 @@ namespace
282283
{ L"help", OPT_HELP },
283284
{ L"horizontal-flip", OPT_HFLIP },
284285
{ L"ignore-mips", OPT_DDS_IGNORE_MIPS },
286+
{ L"ignore-srgb", OPT_IGNORE_SRGB_METADATA },
285287
{ L"image-filter", OPT_FILTER },
286288
{ L"invert-y", OPT_INVERT_Y },
287289
{ L"keep-coverage", OPT_PRESERVE_ALPHA_COVERAGE },
@@ -817,6 +819,9 @@ namespace
817819
L" -xgmode <mode>, --xbox-mode <mode>\n"\
818820
L" Tile/swizzle using provided memory layout mode\n"
819821
#endif
822+
L"\n"
823+
L" (PNG, JPG, TIF, TGA input only)\n"
824+
L" --ignore-srgb Ignores any gamma setting in the metadata\n"
820825
L"\n"
821826
L" (TGA input only)\n"
822827
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[])
20882093
else if (_wcsicmp(ext.c_str(), L".tga") == 0)
20892094
{
20902095
TGA_FLAGS tgaFlags = (IsBGR(format)) ? TGA_FLAGS_BGR : TGA_FLAGS_NONE;
2096+
if (dwOptions & (UINT64_C(1) << OPT_IGNORE_SRGB_METADATA))
2097+
{
2098+
tgaFlags |= TGA_FLAGS_IGNORE_SRGB;
2099+
}
20912100
if (dwOptions & (UINT64_C(1) << OPT_TGAZEROALPHA))
20922101
{
20932102
tgaFlags |= TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA;
@@ -2179,7 +2188,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
21792188

21802189
WIC_FLAGS wicFlags = WIC_FLAGS_NONE | dwFilter;
21812190
if (FileType == CODEC_DDS)
2191+
{
21822192
wicFlags |= WIC_FLAGS_ALL_FRAMES;
2193+
}
2194+
if (dwOptions & (UINT64_C(1) << OPT_IGNORE_SRGB_METADATA))
2195+
{
2196+
wicFlags |= WIC_FLAGS_IGNORE_SRGB;
2197+
}
21832198

21842199
hr = LoadFromWICFile(curpath.c_str(), wicFlags, &info, *image);
21852200
if (FAILED(hr))
@@ -3798,13 +3813,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
37983813
switch (FileType)
37993814
{
38003815
case WIC_CODEC_JPEG:
3801-
if (wicLossless || wicQuality >= 0.f)
3816+
if (wicQuality >= 0.f)
38023817
{
38033818
PROPBAG2 options = {};
38043819
VARIANT varValues = {};
38053820
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
38063821
varValues.vt = VT_R4;
3807-
varValues.fltVal = (wicLossless) ? 1.f : wicQuality;
3822+
varValues.fltVal = wicQuality;
38083823
std::ignore = props->Write(1, &options, &varValues);
38093824
}
38103825
break;
@@ -3829,6 +3844,30 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
38293844
}
38303845
break;
38313846

3847+
case WIC_CODEC_HEIF:
3848+
{
3849+
PROPBAG2 options = {};
3850+
VARIANT varValues = {};
3851+
if (wicLossless)
3852+
{
3853+
options.pstrName = const_cast<wchar_t*>(L"HeifCompressionMethod");
3854+
varValues.vt = VT_UI1;
3855+
#if defined(NTDDI_WIN10_CU)
3856+
varValues.bVal = WICHeifCompressionNone;
3857+
#else
3858+
varValues.bVal = 0x1 /* WICHeifCompressionNone */;
3859+
#endif
3860+
}
3861+
else if (wicQuality >= 0.f)
3862+
{
3863+
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
3864+
varValues.vt = VT_R4;
3865+
varValues.fltVal = wicQuality;
3866+
}
3867+
std::ignore = props->Write(1, &options, &varValues);
3868+
}
3869+
break;
3870+
38323871
case WIC_CODEC_WMP:
38333872
case CODEC_HDP:
38343873
case CODEC_JXR:

0 commit comments

Comments
 (0)