diff --git a/src/calibre/utils/imageops/quantize.cpp b/src/calibre/utils/imageops/quantize.cpp index 5643fc50ee..6787fc9fee 100644 --- a/src/calibre/utils/imageops/quantize.cpp +++ b/src/calibre/utils/imageops/quantize.cpp @@ -419,7 +419,7 @@ QImage quantize(const QImage &image, unsigned int maximum_colors, bool dither, c if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_Indexed8 && fmt != 24) { // 24 = QImage::Format_Grayscale8 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) {