From 73a872b237d8ebf7b7a03700f8b810aabb4df250 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 May 2016 17:44:13 +0530 Subject: [PATCH] Dont use Format_Grayscale8 It's unnecessary work to support it --- src/calibre/utils/imageops/quantize.cpp | 4 ++-- src/calibre/utils/img.py | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/calibre/utils/imageops/quantize.cpp b/src/calibre/utils/imageops/quantize.cpp index f22c1c7238..6e4e62f2ca 100644 --- a/src/calibre/utils/imageops/quantize.cpp +++ b/src/calibre/utils/imageops/quantize.cpp @@ -416,10 +416,10 @@ QImage quantize(const QImage &image, unsigned int maximum_colors, bool dither, c maximum_colors = MAX(2, MIN(MAX_COLORS, maximum_colors)); if (img.colorCount() > 0 && (size_t)img.colorCount() <= maximum_colors) return img; // Image is already quantized if (img.hasAlphaChannel()) throw std::out_of_range("Cannot quantize image with transparency"); - if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_Indexed8 && fmt != 24) { // 24 = QImage::Format_Grayscale8 + if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_Indexed8) { img = img.convertToFormat(QImage::Format_RGB32); if (img.isNull()) throw std::bad_alloc(); - } else if (fmt == 24) img = img.convertToFormat(QImage::Format_Indexed8); + } // There can be no more than MAX_LEAVES * 8 nodes. Add 1 in case there is an off by 1 error somewhere. Pool node_pool((MAX_LEAVES + 1) * 8); if (palette.size() > 0) { diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index d138d8c359..747a9ac8d0 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -156,8 +156,6 @@ def add_borders_to_image(img_data, left=0, top=0, right=0, bottom=0, return image_to_data(img, fmt=fmt) def to_grayscale(img): - if hasattr(QImage, 'Format_Grayscale8'): - return img.convertToFormat(QImage.Format_Grayscale8) if imageops is not None: return imageops.grayscale(img) return img