View Single Post
Old 04-20-2012, 03:30 AM   #110
geekmaster
Всё гениальное просто.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 5,069
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
UPDATE: A "-1" was added to the formula so that the pure blacks and whites are now balanced in a color table display for the K3 also. The previous version had less blacks and more whites on 4-bit displays. All better now.

Here is a nice 8x8 dithered set pixel function for color values 0-255:
PHP Code:
//========================================
// setpx - draw pixel using ordered dither
// x,y:screen coordinates, c:color(0-255).
// (This works on all eink kindle models.)
//----------------------------------------
inline void setpx(int x,int y,int c) {
    static 
int dt[64] = {
    
3,129,34,160,10,136,42,168,192,66,223,97,200,73,231,105,50,
    
176,18,144,58,184,26,152,239,113,207,81,247,121,215,89,14,
    
140,46,180,7,133,38,164,203,77,235,109,196,70,227,101,62,188,
    
30,156,54,180,22,148,251,125,219,93,243,117,211,85 }; // 0-255 dither table
    
fb0[pb*x/8+fs*y]=((256&(c-dt[(7&x)+8*(7&y)]-1))/256*(blk&(240*(1&~x)|
        
15*(1&x)|fb0[pb*x/8+fs*y])))|((256&(dt[(7&x)+8*(7&y)]-c))/256*wht|
        (
blk&((240*(1&x)|15*(1&~x))&fb0[pb*x/8+fs*y]))); // geekmaster formula 42

This has a balanced number of pure blacks and pure whites at each end of the table. This is all we need because the human eye cannot distinguish more than 64 shades of gray, and this table spreads 65 shades of gray evenly over a 0-255 range of color values. I plan to use this to support live video.

EDIT: I just wrote a program that uses the code above to convert all the pixels already in the framebuffer to dithered black and white. In an SSH session I run the program after turning the kindle on and off to get a fresh screensaver image, then run my framebuffer ditherer program, then use dd to snapshot the framebuffer. Other than a quick flash while it rewrites over gray pixels, I have to look close to see that it acually IS dithered. For most of these images, at arms length they look the same. Nice.

I did screenshots of converted images, but LCD displays are normally adjusted for about 2.2 gamma, while the kindles to 1.0 gamma. I need to gamma-correct the 256-color values BEFORE dithering to make them look good on the display. You cannot gamma-correct a 2-color image. So showing gamma 1.0 screenshots does not do these gamma 1.0 images justice -- you REALLY need to view them on the kindle. But anyway, here are a couple of the converted images:

Spoiler:
Spoiler:

And here is one that I downloaded, then displayed with "eips", dithered with the dither table shown above, and saved with "dd" (the original was rather washed-out, and small, so I stretched it and reduced the gamma a little before copying it to the kindle):

Spoiler:

Remember, these dithered images look MUCH better on the kindle (at arm length away) because it has the 1.0 gamma that these images were dithered for. Also, for MOVING images, your eye follows the movement and averages out the dither patterns, so it is much less annoying than in static images like these.

Enjoy!



Last edited by geekmaster; 04-20-2012 at 12:38 PM.
geekmaster is offline   Reply With Quote