Skip to content

Commit

Permalink
Implement encoder configuration (stored in registry for JPEG XL, AVIF…
Browse files Browse the repository at this point in the history
… and PNG)
  • Loading branch information
Kaldaien committed Sep 4, 2024
1 parent e436068 commit d027ad6
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 37 deletions.
54 changes: 54 additions & 0 deletions include/utility/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,38 @@ struct SKIF_RegistrySettings {
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\)",
LR"(Diagnostics)" );

KeyValue <int> regKVAVIFQuality =
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\AVIF\)",
LR"(Quality)" );

KeyValue <int> regKVAVIFSpeed =
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\AVIF\)",
LR"(Speed)" );

KeyValue <int> regKVAVIFHDRBitDepth =
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\AVIF\)",
LR"(HDR BitDepth)" );

KeyValue <int> regKVJXLQuality =
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\JPEG XL\)",
LR"(Quality)" );

KeyValue <int> regKVJXLSpeed =
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\JPEG XL\)",
LR"(Speed)" );

KeyValue <int> regKVJXLHDRBitDepth =
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\JPEG XL\)",
LR"(HDR BitDepth)" );

KeyValue <int> regKVJXRQuality =
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\JPEG XR\)",
LR"(Quality)" );

KeyValue <int> regKVPNGHDRBitDepth =
SKIF_MakeRegKeyI ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\PNG\)",
LR"(HDR BitDepth)" );

// Wide Strings

KeyValue <std::wstring> regKVIgnoreUpdate =
Expand Down Expand Up @@ -429,6 +461,28 @@ struct SKIF_RegistrySettings {
std::wstring wsDefaultHDRExt = L".png";
std::wstring wsDefaultSDRExt = L".png";

// Encoder config
struct {
int hdr_bitdepth = 12;
int quality = 100;
int speed = 10;
int yuv_sampling = 444;
} avif;

struct {
int quality = 100;
} jxr;

struct {
int quality = 100;
int speed = 10;
int hdr_bitdepth = 16;
} jxl;

struct {
int hdr_bitdepth = 16;
} png;

// Windows stuff
std::wstring wsAppRegistration;
int iNotificationsDuration = 5; // Defaults to 5 seconds in case Windows is not set to something else
Expand Down
60 changes: 31 additions & 29 deletions src/tabs/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3736,52 +3736,54 @@ SKIF_UI_Tab_DrawViewer (void)
if (ImGui::BeginTabItem ("AVIF", nullptr, ImGuiTabItemFlags_NoTooltip))
{
selection = 0;
//ImGui::TextUnformatted ("AVIF");

static int avif_bit_depth = 12;
static int avif_compression_speed = AVIF_SPEED_FASTEST;
static int avif_compression_quality = AVIF_QUALITY_LOSSLESS;
ImGui::SliderInt ("Compression Speed", &avif_compression_speed, AVIF_SPEED_SLOWEST, AVIF_SPEED_FASTEST);
ImGui::SliderInt ("Compression Quality", &avif_compression_quality, 80, 100);

if (ImGui::SliderInt ("Compression Speed", &_registry.avif.speed, AVIF_SPEED_SLOWEST, AVIF_SPEED_FASTEST))
_registry.regKVAVIFSpeed.putData (_registry.avif.speed);

if (ImGui::SliderInt ("Compression Quality", &_registry.avif.quality, 80, 100))
_registry.regKVAVIFQuality.putData (_registry.avif.quality);

int avif_bit_select =
avif_bit_depth == 8 ? 0 :
avif_bit_depth == 10 ? 1 :
avif_bit_depth == 12 ? 2 : 2;
_registry.avif.hdr_bitdepth == 8 ? 0 :
_registry.avif.hdr_bitdepth == 10 ? 1 :
_registry.avif.hdr_bitdepth == 12 ? 2 : 2;

bool changed_depth =
ImGui::Combo ("Compression Bit Depth", &avif_bit_select, " 8-bpc\0 10-bpc\0 12-bpc\0\0");

avif_bit_depth = avif_bit_select == 0 ? 8 :
avif_bit_select == 1 ? 10 :
avif_bit_select == 2 ? 12 : 12;
_registry.avif.hdr_bitdepth = avif_bit_select == 0 ? 8 :
avif_bit_select == 1 ? 10 :
avif_bit_select == 2 ? 12 : 12;

if (changed_depth)
_registry.regKVAVIFHDRBitDepth.putData (_registry.avif.hdr_bitdepth);

ImGui::EndTabItem ();
}
if (ImGui::BeginTabItem ("JPEG XL", nullptr, ImGuiTabItemFlags_NoTooltip))
{
selection = 1;
//ImGui::TextUnformatted ("XL");

static int jxl_compression_speed = 10;
static int jxl_compression_quality = 100;
ImGui::SliderInt ("Compression Speed", &jxl_compression_speed, AVIF_SPEED_SLOWEST, AVIF_SPEED_FASTEST);
ImGui::SliderInt ("Compression Quality", &jxl_compression_quality, 80, 100);
ImGui::EndTabItem ();
}
if (ImGui::BeginTabItem ("JPEG XR", nullptr, ImGuiTabItemFlags_NoTooltip))
{
selection = 2;
//ImGui::TextUnformatted ("XR");
static int jxr_compression_quality = 100;
ImGui::SliderInt ("Compression Quality", &jxr_compression_quality, 80, 100);
if (ImGui::SliderInt ("Compression Speed", &_registry.jxl.speed, AVIF_SPEED_SLOWEST, AVIF_SPEED_FASTEST))
_registry.regKVJXLSpeed.putData (_registry.jxl.speed);

if (ImGui::SliderInt ("Compression Quality", &_registry.jxl.quality, 80, 100))
_registry.regKVJXLQuality.putData (_registry.jxl.quality);
ImGui::EndTabItem ();
}
///if (ImGui::BeginTabItem ("JPEG XR", nullptr, ImGuiTabItemFlags_NoTooltip))
///{
/// selection = 2;
/// //ImGui::TextUnformatted ("XR");
/// static int jxr_compression_quality = 100;
/// ImGui::SliderInt ("Compression Quality", &jxr_compression_quality, 80, 100);
/// ImGui::EndTabItem ();
///}
if (ImGui::BeginTabItem ("PNG", nullptr, ImGuiTabItemFlags_NoTooltip))
{
selection = 3;
//ImGui::TextUnformatted ("PNG");
static int png_bit_depth = 16;
ImGui::SliderInt ("Bit Depth", &png_bit_depth, 10, 16);
if (ImGui::SliderInt ("HDR Bit Depth", &_registry.png.hdr_bitdepth, 10, 16))
_registry.regKVJXLQuality.putData (_registry.png.hdr_bitdepth);
ImGui::EndTabItem ();
}
//if (ImGui::BeginTabItem ("Ultra HDR", nullptr, ImGuiTabItemFlags_NoTooltip))
Expand Down
18 changes: 10 additions & 8 deletions src/utility/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,9 @@ SKIV_Image_LoadUltraHDR (DirectX::ScratchImage& image, void* data, int size)
HRESULT
SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileName)
{
SKIF_RegistrySettings& _registry =
SKIF_RegistrySettings::GetInstance ();

using namespace DirectX;

const Image* pOutputImage = &image;
Expand Down Expand Up @@ -2606,7 +2609,7 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa
JxlBasicInfo basic_info = { };
jxlEncoderInitBasicInfo (&basic_info);

const bool bLossless = false;
const bool bLossless = (_registry.jxl.quality == 100);

basic_info.xsize = static_cast <uint32_t> (image.width);
basic_info.ysize = static_cast <uint32_t> (image.height);
Expand Down Expand Up @@ -2640,8 +2643,8 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa
jxlEncoderFrameSettingsCreate (jxl_encoder, nullptr);

jxlEncoderSetFrameLossless (frame_settings, bLossless ? JXL_TRUE : JXL_FALSE);
jxlEncoderSetFrameDistance (frame_settings, 0.05f);//jxlEncoderDistanceFromQuality (100.0f));
jxlEncoderFrameSettingsSetOption (frame_settings, JXL_ENC_FRAME_SETTING_EFFORT, 7);
jxlEncoderSetFrameDistance (frame_settings, jxlEncoderDistanceFromQuality ((float)_registry.jxl.quality));
jxlEncoderFrameSettingsSetOption (frame_settings, JXL_ENC_FRAME_SETTING_EFFORT, _registry.jxl.speed);

if ( JXL_ENC_SUCCESS !=
jxlEncoderAddImageFrame ( frame_settings, &pixel_format,
Expand Down Expand Up @@ -2748,7 +2751,7 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa

if (image.format == DXGI_FORMAT_R16G16B16A16_FLOAT)
{
bit_depth = 12;
bit_depth = _registry.avif.hdr_bitdepth;
//std::clamp (config.screenshots.avif.scrgb_bit_depth, 8, 12);

// 8, 10, 12... nothing else.
Expand Down Expand Up @@ -2989,16 +2992,15 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa
SYSTEM_INFO si = { };
GetSystemInfo (&si);

encoder->quality = 100;//config.screenshots.compression_quality;
encoder->qualityAlpha = 100;//config.screenshots.compression_quality; // N/A?
encoder->quality = _registry.avif.quality;
encoder->qualityAlpha = _registry.avif.quality; // N/A?
encoder->timescale = 1;
encoder->repetitionCount = AVIF_REPETITION_COUNT_INFINITE;
encoder->maxThreads = std::min (64U, std::min ((UINT)si.dwNumberOfProcessors, (UINT)__popcnt64 (si.dwActiveProcessorMask)));

Check failure on line 2999 in src/utility/image.cpp

View workflow job for this annotation

GitHub Actions / Build

encoder->maxThreads = std::min (64U, std::min ((UINT)si.dwNumberOfProcessors, (UINT)__popcnt64 (si.dwActiveProcessorMask))); [D:\a\SKIV\SKIV\SKIV.vcxproj]

Check failure on line 2999 in src/utility/image.cpp

View workflow job for this annotation

GitHub Actions / Build

^ [D:\a\SKIV\SKIV\SKIV.vcxproj]

Check failure on line 2999 in src/utility/image.cpp

View workflow job for this annotation

GitHub Actions / Build

encoder->maxThreads = std::min (64U, std::min ((UINT)si.dwNumberOfProcessors, (UINT)__popcnt64 (si.dwActiveProcessorMask))); [D:\a\SKIV\SKIV\SKIV.vcxproj]

Check failure on line 2999 in src/utility/image.cpp

View workflow job for this annotation

GitHub Actions / Build

^ [D:\a\SKIV\SKIV\SKIV.vcxproj]
encoder->speed = 7;//config.screenshots.avif.compression_speed;
encoder->minQuantizer = AVIF_QUANTIZER_BEST_QUALITY;
encoder->maxQuantizer = AVIF_QUANTIZER_BEST_QUALITY;
encoder->codecChoice = AVIF_CODEC_CHOICE_AUTO;
encoder->speed = AVIF_SPEED_FASTEST;
encoder->speed = _registry.avif.speed;

addResult = SK_avifEncoderAddImage (encoder, avif_image, 1, AVIF_ADD_IMAGE_FLAG_SINGLE);
encodeResult = SK_avifEncoderFinish (encoder, &avifOutput);
Expand Down
21 changes: 21 additions & 0 deletions src/utility/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,27 @@ SKIF_RegistrySettings::SKIF_RegistrySettings (void)
if (regKVDiagnostics.hasData(&hKey))
iDiagnostics = regKVDiagnostics .getData (&hKey);


if (regKVAVIFHDRBitDepth.hasData (&hKey))
avif.hdr_bitdepth = regKVAVIFHDRBitDepth .getData (&hKey);
if (regKVAVIFQuality.hasData (&hKey))
avif.quality = regKVAVIFQuality .getData (&hKey);
if (regKVAVIFSpeed.hasData (&hKey))
avif.speed = regKVAVIFSpeed .getData (&hKey);

if (regKVJXLHDRBitDepth.hasData (&hKey))
jxl.hdr_bitdepth = regKVJXLHDRBitDepth .getData (&hKey);
if (regKVJXLQuality.hasData (&hKey))
jxl.quality = regKVJXLQuality .getData (&hKey);
if (regKVJXLSpeed.hasData (&hKey))
jxl.speed = regKVJXLSpeed .getData (&hKey);

if (regKVJXRQuality.hasData (&hKey))
jxr.quality = regKVJXRQuality .getData (&hKey);

if (regKVPNGHDRBitDepth.hasData (&hKey))
png.hdr_bitdepth = regKVPNGHDRBitDepth .getData (&hKey);

#if 0
if (! SKIF_Util_GetDragFromMaximized ( ))
bMaximizeOnDoubleClick = false; // Force disabled IF the OS prerequisites are not enabled
Expand Down

0 comments on commit d027ad6

Please sign in to comment.