Skip to content

Commit

Permalink
texconv: add --ignore-srgb, --wic-uncompressed and revisit --wic-loss…
Browse files Browse the repository at this point in the history
…less (#555)
  • Loading branch information
walbourn authored Nov 13, 2024
1 parent 37a18e9 commit 2b6f585
Showing 1 changed file with 51 additions and 8 deletions.
59 changes: 51 additions & 8 deletions Texconv/texconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace
OPT_TGAZEROALPHA,
OPT_WIC_LOSSLESS,
OPT_WIC_MULTIFRAME,
OPT_WIC_UNCOMPRESSED,
OPT_NOLOGO,
OPT_TIMING,
OPT_SEPALPHA,
Expand All @@ -140,6 +141,7 @@ namespace
OPT_INVERT_Y,
OPT_RECONSTRUCT_Z,
OPT_BCNONMULT4FIX,
OPT_IGNORE_SRGB_METADATA,
#ifdef USE_XBOX_EXTS
OPT_USE_XBOX,
OPT_XGMODE,
Expand Down Expand Up @@ -282,6 +284,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 },
Expand Down Expand Up @@ -311,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 },
Expand Down Expand Up @@ -591,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 }
};
Expand Down Expand Up @@ -817,17 +820,21 @@ namespace
L" -xgmode <mode>, --xbox-mode <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"
L"\n"
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 <quality>, --wic-quality <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"
Expand Down Expand Up @@ -2088,6 +2095,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;
Expand Down Expand Up @@ -2179,7 +2190,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))
Expand All @@ -2194,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;
Expand Down Expand Up @@ -3793,18 +3810,20 @@ 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)
{
default:
case WIC_CODEC_JPEG:
if (wicLossless || wicQuality >= 0.f)
if (wicQuality >= 0.f)
{
PROPBAG2 options = {};
VARIANT varValues = {};
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
varValues.vt = VT_R4;
varValues.fltVal = (wicLossless) ? 1.f : wicQuality;
varValues.fltVal = wicQuality;
std::ignore = props->Write(1, &options, &varValues);
}
break;
Expand All @@ -3813,7 +3832,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<wchar_t*>(L"TiffCompressionMethod");
varValues.vt = VT_UI1;
Expand All @@ -3829,13 +3848,37 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
break;

case WIC_CODEC_HEIF:
{
PROPBAG2 options = {};
VARIANT varValues = {};
if (uncompressed)
{
options.pstrName = const_cast<wchar_t*>(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<wchar_t*>(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:
{
PROPBAG2 options = {};
VARIANT varValues = {};
if (wicLossless)
if (lossless)
{
options.pstrName = const_cast<wchar_t*>(L"Lossless");
varValues.vt = VT_BOOL;
Expand Down

0 comments on commit 2b6f585

Please sign in to comment.