See what happens if we switch to Indexed8...

This commit is contained in:
NiLuJe 2019-05-24 03:12:38 +02:00
parent 96a98bbc29
commit 38ad6a5b2d
2 changed files with 17 additions and 3 deletions

View File

@ -25,6 +25,8 @@ typedef unsigned __int32 uint32_t;
#include <cstdint>
#endif
#include <QVector>
// 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<uint8_t> palette(16);
QVector<QRgb> 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;

View File

@ -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)