mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
See what happens if we switch to Indexed8...
This commit is contained in:
parent
96a98bbc29
commit
38ad6a5b2d
@ -25,6 +25,8 @@ typedef unsigned __int32 uint32_t;
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
// NOTE: *May* not behave any better than a simple / 0xFF on modern x86_64 CPUs...
|
// 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.
|
// This was, however, tested on ARM, where it is noticeably faster.
|
||||||
static uint32_t DIV255(uint32_t v) {
|
static uint32_t DIV255(uint32_t v) {
|
||||||
@ -79,7 +81,19 @@ QImage ordered_dither(const QImage &image) { // {{{
|
|||||||
QImage img = image;
|
QImage img = image;
|
||||||
int y = 0, x = 0, width = img.width(), height = img.height();
|
int y = 0, x = 0, width = img.width(), height = img.height();
|
||||||
uint8_t gray = 0, dithered = 0;
|
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...
|
// We're running behind blend_image, so, we should only ever be fed RGB32 as input...
|
||||||
if (img.format() != QImage::Format_RGB32) {
|
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
|
// We're running behind grayscale_image, so R = G = B
|
||||||
gray = qRed(pixel);
|
gray = qRed(pixel);
|
||||||
dithered = dither_o8x8(x, y, gray);
|
dithered = dither_o8x8(x, y, gray);
|
||||||
*(dst_row + x) = dithered;
|
*(dst_row + x) = palette.indexOf(dithered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dst;
|
return dst;
|
||||||
|
@ -468,7 +468,7 @@ def eink_dither_image(img):
|
|||||||
Running blend_image if the image has an alpha channel,
|
Running blend_image if the image has an alpha channel,
|
||||||
or grayscale_image if it's not already grayscaled is the caller's responsibility.
|
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)
|
img = image_from_data(img)
|
||||||
return imageops.ordered_dither(img)
|
return imageops.ordered_dither(img)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user