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)

This commit is contained in:
Kovid Goyal 2021-08-20 07:14:49 +05:30
parent 9ac68112b1
commit 30c411acd1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -9,6 +9,7 @@
#include <stdexcept> #include <stdexcept>
#include <QVector> #include <QVector>
#include <cmath> #include <cmath>
#include <set>
// Macros {{{ // Macros {{{
#define SQUARE(x) (x)*(x) #define SQUARE(x) (x)*(x)
@ -646,6 +647,7 @@ QImage normalize(const QImage &image) { // {{{
QRgb pixel, *dest; QRgb pixel, *dest;
unsigned char r, g, b; unsigned char r, g, b;
QImage img(image); QImage img(image);
std::set<QRgb> all_colors;
ENSURE32(img); ENSURE32(img);
@ -656,11 +658,13 @@ QImage normalize(const QImage &image) { // {{{
for(i=0; i < count; ++i){ for(i=0; i < count; ++i){
pixel = *dest++; pixel = *dest++;
all_colors.insert(pixel);
histogram[qRed(pixel)].red++; histogram[qRed(pixel)].red++;
histogram[qGreen(pixel)].green++; histogram[qGreen(pixel)].green++;
histogram[qBlue(pixel)].blue++; histogram[qBlue(pixel)].blue++;
histogram[qAlpha(pixel)].alpha++; histogram[qAlpha(pixel)].alpha++;
} }
if (all_colors.size() < 2) return img;
// find the histogram boundaries by locating the .01 percent levels. // find the histogram boundaries by locating the .01 percent levels.
threshold_intensity = count/1000; threshold_intensity = count/1000;