From 30c411acd1719c5c91b2e6e2bb42f82c0f7cb325 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 20 Aug 2021 07:14:49 +0530 Subject: [PATCH] Comic input: Fix single color images having their colors changed by normalization. Fixes #1939908 [Normalize on CBZ conversion changes white pages to black pages](https://bugs.launchpad.net/calibre/+bug/1939908) --- src/calibre/utils/imageops/imageops.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calibre/utils/imageops/imageops.cpp b/src/calibre/utils/imageops/imageops.cpp index 982edb5526..2330fb4196 100644 --- a/src/calibre/utils/imageops/imageops.cpp +++ b/src/calibre/utils/imageops/imageops.cpp @@ -9,6 +9,7 @@ #include #include #include +#include // Macros {{{ #define SQUARE(x) (x)*(x) @@ -646,6 +647,7 @@ QImage normalize(const QImage &image) { // {{{ QRgb pixel, *dest; unsigned char r, g, b; QImage img(image); + std::set all_colors; ENSURE32(img); @@ -656,11 +658,13 @@ QImage normalize(const QImage &image) { // {{{ for(i=0; i < count; ++i){ pixel = *dest++; + all_colors.insert(pixel); histogram[qRed(pixel)].red++; histogram[qGreen(pixel)].green++; histogram[qBlue(pixel)].blue++; histogram[qAlpha(pixel)].alpha++; } + if (all_colors.size() < 2) return img; // find the histogram boundaries by locating the .01 percent levels. threshold_intensity = count/1000;