add lossless webp encoding

This commit is contained in:
Green Sky
2025-04-07 16:18:32 +02:00
parent 923dbed53d
commit 4ca3048988
2 changed files with 29 additions and 12 deletions

View File

@ -473,17 +473,17 @@ void SendImagePopup::render(float time_delta) {
if (compress) {
ImGui::SameLine();
ImGui::Combo("##compression_type", &current_compressor, "webp\0jpeg\0png\0qoi\0");
ImGui::Combo("##compression_type", &current_compressor, "webp\0webp lossless\0jpeg\0png\0qoi\0");
ImGui::Indent();
// combo "webp""webp-lossless""png""jpg?"
// if lossy quality slider (1-100) default 80
if (current_compressor == 0 || current_compressor == 1) {
if (current_compressor == 0 || current_compressor == 2) {
const uint32_t qmin = 1;
const uint32_t qmax = 100;
recalc_size |= ImGui::SliderScalar("quality", ImGuiDataType_U32, &quality, &qmin, &qmax);
}
if (current_compressor == 2) {
if (current_compressor == 1 || current_compressor == 3) {
const uint32_t qmin = 0;
const uint32_t qmax = 9;
recalc_size |= ImGui::SliderScalar("compression_level", ImGuiDataType_U32, &compression_level, &qmin, &qmax);
@ -529,16 +529,21 @@ void SendImagePopup::render(float time_delta) {
_on_send(new_data, ".webp");
}
} else if (current_compressor == 1) {
new_data = ImageEncoderWebP{}.encodeToMemoryRGBA(tmp_img, {{"compression_level", compression_level}});
if (!new_data.empty()) {
_on_send(new_data, ".webp");
}
} else if (current_compressor == 2) {
new_data = ImageEncoderSTBJpeg{}.encodeToMemoryRGBA(tmp_img, {{"quality", quality}});;
if (!new_data.empty()) {
_on_send(new_data, ".jpg");
}
} else if (current_compressor == 2) {
} else if (current_compressor == 3) {
new_data = ImageEncoderSTBPNG{}.encodeToMemoryRGBA(tmp_img, {{"png_compression_level", compression_level}});;
if (!new_data.empty()) {
_on_send(new_data, ".png");
}
} else if (current_compressor == 3) {
} else if (current_compressor == 4) {
new_data = ImageEncoderQOI{}.encodeToMemoryRGBA(tmp_img, {});;
if (!new_data.empty()) {
_on_send(new_data, ".qoi");