diff --git a/src/calibre/utils/imageops/ordered_dither.cpp b/src/calibre/utils/imageops/ordered_dither.cpp index bf85727b0c..55293ddf04 100644 --- a/src/calibre/utils/imageops/ordered_dither.cpp +++ b/src/calibre/utils/imageops/ordered_dither.cpp @@ -25,6 +25,8 @@ typedef unsigned __int32 uint32_t; #include #endif +#include + // NOTE: *May* not behave any better than a simple / 0xFF on modern x86_64 CPUs... // This was, however, tested on ARM, where it is noticeably faster. static uint32_t DIV255(uint32_t v) { @@ -79,7 +81,19 @@ QImage ordered_dither(const QImage &image) { // {{{ QImage img = image; int y = 0, x = 0, width = img.width(), height = img.height(); uint8_t gray = 0, dithered = 0; - QImage dst(width, height, QImage::Format_Grayscale8); + QImage dst(width, height, QImage::Format_Indexed8); + + // Set up the eInk palette + // FIXME: Make it const and switch to C++11 list init if MSVC is amenable... + QVector palette(16); + QVector color_table(16); + int i = 0; + for (i = 0; i < 16; i++) { + uint8_t color = i * 17; + palette << color; + color_table << qRgb(color, color, color); + } + dst.setColorTable(color_table); // We're running behind blend_image, so, we should only ever be fed RGB32 as input... if (img.format() != QImage::Format_RGB32) { @@ -95,7 +109,7 @@ QImage ordered_dither(const QImage &image) { // {{{ // We're running behind grayscale_image, so R = G = B gray = qRed(pixel); dithered = dither_o8x8(x, y, gray); - *(dst_row + x) = dithered; + *(dst_row + x) = palette.indexOf(dithered); } } return dst; diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index f333755d54..d66cf20753 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -468,7 +468,7 @@ def eink_dither_image(img): Running blend_image if the image has an alpha channel, or grayscale_image if it's not already grayscaled is the caller's responsibility. - Returns a QImage in Grayscale8 pixel format. + Returns a QImage in Indexed8 pixel format. ''' img = image_from_data(img) return imageops.ordered_dither(img)