04-18-2012, 04:37 PM | #16 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
|
04-18-2012, 04:55 PM | #17 |
Connoisseur
Posts: 59
Karma: 57554
Join Date: Jan 2012
Location: Romania
Device: Kindle Touch
|
Dithermatron 1.1 was very fast but from one point it appeared that it was a bit too fast for the screen to keep up.
The cosmegg one was trippy. |
Advert | |
|
04-18-2012, 05:06 PM | #18 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
For the K4 and K5, they eink update calls return immediately, and we have to be careful to not touch the framebuffer until ready, so we wait in a spin-loop. Using a timer to signal an event would save battery in that case, but this is not a long-running background process and that would complicate the code, so a simple spinloop does the job quite nice here.
|
04-18-2012, 05:10 PM | #19 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
You can slow it down by using a different K4DLY selection and recompiling. Cosmegg accepts a command line parameter for msec between display updates. You can change it to 250 for 4 updates/second (./cosmeg 250). EXPERIMENT: Run multiple "dithermatron &" in the background to see MORE objects. Last edited by geekmaster; 04-20-2012 at 03:07 PM. |
|
04-18-2012, 05:22 PM | #20 | |
curly᷂͓̫̙᷊̥̮̾ͯͤͭͬͦͨ ʎʌɹnɔ
Posts: 3,002
Karma: 50506927
Join Date: Dec 2010
Location: ♁ ᴺ₄₅°₃₀' ᵂ₇₃°₃₇' ±₆₀"
Device: K3₃.₄.₃ PW3&4₅.₁₃.₃
|
Quote:
... and you need to be sure 4 times. Last edited by PoP; 04-20-2012 at 03:07 PM. Reason: add quote |
|
Advert | |
|
04-19-2012, 05:07 AM | #21 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
palpump - geekmaster palette pump demo
Spoiler:
This started as a test stub to verify the "color palette" dither table values. I now subtracted one from all values so it can get a pure black. Remember that dithering with an 8x8 table gives 65 shades, not 64 as 6-bit colors would give. Anyway, this is an animated "color" palette demo. Not as flashy as the others, but it shows how to use a new function (scaleable palette display). I animate the scaling factor here. Using this new color palette in some existing programs can make the WHITE value go away, requiring adjustment to the color scale factors in the program. Remember to clear the screen (eips -c) before running this each time. The moving palette "wall" appears to be semi-transparent, but that "transparency" is just eink ghosting, which you would not see in a screenshot, but that ghosting looks interesting and contributes to the effect in this demo. Last edited by geekmaster; 04-19-2012 at 05:23 AM. |
04-20-2012, 01:17 PM | #22 |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
paldemo - kindle 0-255 dithered palette display
UPDATE: The new paldemo version (not yet published) contains a second dither table with gamma 2.2 dither threshold values for LCD and CRT desktop displays. This gives a color palette screenshot that appears correctly balanced (average 50% gray) on desktop displays. See the gamma tutorial below.
This "paldemo" program demonstrates the new "geekmaster formula 42" dithering function adapted for a 0-255 color palette. It can be used to convert a framebuffer containing a grayscale image or antialiased text directly to dithered black and white, so that it can be animated or resized smoothly. A new dither table is used that spreads the 65 shades of gray evenly through the 0-255 color value range, and a "-1" adjustment was made to a strategic location in the formula to balance the number of pure blacks and pure whites on the ends of the color table for 4-bit pixel displays. Because 65 is not a power of 2, the threshold columns do not line up in the displayed 16x16 color palette, but this is to be expected for non-integral range conversion. The display palette onscreen size is adjustable. This demo program calls palette(550) to display a 550x550 pixel palette, but you can change that value to resize the palette. The screenshot gamma tutorial: Spoiler:
The source: Spoiler:
The download:
Last edited by geekmaster; 04-21-2012 at 11:44 AM. |
04-21-2012, 05:28 AM | #23 |
Member
Posts: 16
Karma: 25544
Join Date: Feb 2012
Device: Kindle 3
|
Firs of all, thanks for your awesome code, Geekmaster.
I'm a beginner, and I played a bit with your sources. This is a little demo I came up with. |
04-21-2012, 08:31 AM | #24 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
I ran it. It looks like a random walk with pixel timeout and erase. Now I need to go look at the code. This looks interesting. You should add things like a Hilbert Curve to this. It looks like you pumped the source code through AStyle to reformat it. Unfortunately, AStyle does not have a profile for my condensed coding style that I like (max code per line, max lines per page). White-space lovers probably hate my code anyway. You should change the program name in the comments at the top, and add a revision history that includes your name. This was worth the "2600 karma" badge of honor. Oops... wrong karma field (I gave you too many points). WARNING: One thing about the MIT license: This is a derivative of my code, so the copyright FOR THIS SOURCE FILE is still mine. The purpose of the copyright is to support the MIT license so that others can freely use my code, so it does not need multiple copyrights. You removed MY copyright -- you should put that back. It is better to add a revision history to my file to show your name and your changes or additions. If you NEED your own copyright for your function, you should put your function code in a separate .c source file, and put your copyright (and the MIT license or other compatible license such as BSD) in that file. Then link it to mine by putting both files on the compiler command line. I added my original copyright back to the source code (and you should too, and you should edit your post above, to replace the download with a replacement zip file containing properly attributed code. ) Here is the updated code with my copyright line restored (and new title, and additional models tested): PHP Code:
Last edited by geekmaster; 04-21-2012 at 09:24 AM. |
|
04-21-2012, 09:41 AM | #25 |
Member
Posts: 16
Karma: 25544
Join Date: Feb 2012
Device: Kindle 3
|
Sorry about the license thing. I updated the source file, but I can't manage to edit my post. I attached the updated file to this post.
edit: It seems that the Edit button appears on this post I just wrote... Anyways, thanks for the karma. Last edited by kiri87; 04-21-2012 at 09:43 AM. |
04-21-2012, 09:45 AM | #26 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
Hmm... In your download, somehow my "geekmaster formula 42" got MORE whitespace pollution (it is indented much too far when viewed in Windows Notepad). Last edited by geekmaster; 04-21-2012 at 09:49 AM. |
|
04-21-2012, 09:53 AM | #27 |
Member
Posts: 16
Karma: 25544
Join Date: Feb 2012
Device: Kindle 3
|
It's very odd. I can still see the Edit button on my previous post, but there's none on the initial post. I think it's automatically hidden after some time, I don't know...
|
04-21-2012, 12:08 PM | #28 |
Zealot
Posts: 130
Karma: 10000
Join Date: Mar 2012
Device: Kindle 3G, Kindle Touch 3G, iRiver Story HD, Sony Reader
|
Hi kiri87,
I ran the demo and is is very good! My son loves it. However, I don't think you need to use the dither algorithm because it is all black and white. Maybe you can modify the demo so it shows dithering... Thanks, James |
04-21-2012, 12:40 PM | #29 |
Zealot
Posts: 130
Karma: 10000
Join Date: Mar 2012
Device: Kindle 3G, Kindle Touch 3G, iRiver Story HD, Sony Reader
|
Hi,
Here is one that uses dithering. I incremented the color every segment, and made every pixel width 2 to see the dithering. EDIT: Fixed bug in color. Code:
//==================================================== // simplePixelDemo 1.0 - random walk demo // Copyright (C) 2012 by geekmaster, with MIT license: // Copyright (C) 2012 by kiri, with MIT license: // http://www.opensource.org/licenses/mit-license.php //---------------------------------------------------- // The speed is limited by the eink device drivers. // Newer kindle models are faster, but need delays. // This was tested on DX, DXG, K3, K5(touch). //---------------------------------------------------- #include <stdio.h> // printf #include <stdlib.h> // malloc, free, atoi #include <string.h> // memset, memcpy #include <unistd.h> // usleep #include <fcntl.h> // open, close, write #include <time.h> // time #include <sys/ioctl.h> // ioctl #include <sys/time.h> // gettime #include <sys/mman.h> // mmap, munmap #include <linux/fb.h> // screeninfo #define FPS 5 // max frames/sec #define LENGTH 25000 #define STEP 1250 enum eupd_op { EUPD_OPEN,EUPD_CLOSE,EUPD_UPDATE }; typedef unsigned char u8; typedef unsigned int u32; // function prototypes inline void setpx(int,int,int); void setbx(int,int,int); int eupdate(int); int getmsec(void); // global var7 u32 mpu=200; // msec/update u8 *fb0=NULL; // framebuffer pointer int fdFB=0; // fb0 file descriptor u32 fs=0; // fb0 stride u32 MX=0; // xres (visible) u32 MY=0; // yres (visible) u8 blk=0; // black u8 wht=0; // white u8 pb=0; // pixel bits #define bwidth 2 // width of block void simplePixelDemo(void) { int x,y,tn; int c=0; struct fb_var_screeninfo screeninfo; fdFB=open("/dev/fb0",O_RDWR); // eink framebuffer // calculate model-specific vars ioctl(fdFB,FBIOGET_VSCREENINFO,&screeninfo); MX=screeninfo.xres/bwidth; // max X+1 MY=screeninfo.yres; // max Y+1 pb=screeninfo.bits_per_pixel; // pixel bits fs=screeninfo.xres_virtual*pb/8; // fb0 stride blk=pb/8-1; // black wht=~blk; // white fb0=(u8 *)mmap(0,MY*fs,PROT_READ|PROT_WRITE,MAP_SHARED,fdFB,0); // map fb0 eupdate(EUPD_OPEN); // open fb0 update proc MY=MY/bwidth; system("eips -c"); //clear screen int currentX = MX/2, currentY =MY/2; //initial point is the center of the screen int choice; int direction = 0; //the direction: 0 = right, 1 = up, 2 = left, 3 = down long int i; int cu; int pixels[3][LENGTH]; for (i=0; i<LENGTH; i++) {//fill with central pixels pixels[0][i] = currentX; pixels[1][i] = currentY; pixels[2][i] = c++; c&=0x3F; } srand ( time(NULL) ); for (cu=0; cu<100; cu++) { tn=mpu+getmsec(); for (i=0; i<LENGTH - STEP; i++) { if (i<STEP) setbx(pixels[0][i], pixels[1][i], 64); //clear some pixels // move pixels array to the left pixels[0][i] = pixels[0][i + STEP]; pixels[1][i] = pixels[1][i + STEP]; pixels[2][i] = pixels[2][i + STEP]; } for (i=0; i<STEP; i++) { //create some new pixels choice = rand()%5; if (choice == 0) { direction += 1; direction %= 4; } else if (choice == 1) { direction -= 1; direction += 4; direction %= 4; } else { switch(direction) { case 0: if (currentX>=MX) break; currentX++; break; case 1: if (currentY>=MY) break; currentY++; break; case 2: if (currentX<=0) break; currentX--; break; case 3: if (currentY<=0) break; currentY--; break; } } pixels[0][LENGTH - STEP + i] = currentX; pixels[1][LENGTH - STEP + i] = currentY; pixels[2][LENGTH - STEP + i] = c++; c&=0x3F; } for (i=0; i<LENGTH; i++) { //display pixels setbx(pixels[0][i], pixels[1][i], pixels[2][i]); } eupdate(EUPD_UPDATE); // update display while (tn>getmsec()); // wait until next update time } // cleanup - close and free resources eupdate(EUPD_UPDATE); // update display eupdate(EUPD_CLOSE); // close fb0 update proc port munmap(fb0,fs*(MY+1)); // unmap fb0 close(fdFB); // close fb0 } //=============================== // eupdate - eink update display // op (open, close, update) //------------------------------- int eupdate(int op) { static int fdUpdate=-1; if (EUPD_OPEN==op) { fdUpdate=open("/proc/eink_fb/update_display",O_WRONLY); } else if (EUPD_CLOSE==op) { close(fdUpdate); } else if (EUPD_UPDATE==op) { if (-1==fdUpdate) { system("eips ''"); } else { write(fdUpdate,"1\n",2); } } else { return -1; // bad op code } return fdUpdate; } void setbx(int x, int y, int c) { int i,j,xx,yy; xx=x*bwidth; yy=y*bwidth; for (i=0; i < bwidth; i++) for (j=0; j < bwidth; j++) setpx (xx+i,yy+j,c); } //======================================== // setpx - draw pixel using ordered dither // x,y: screen coordinates, c: color(0-64). // (This works on all eink kindle models.) //---------------------------------------- inline void setpx(int x,int y,int c) { static int dt[64] = { 1, 33, 9, 41, 3, 35, 11, 43, 49, 17, 57, 25, 51, 19, 59, 27, 13, 45, 5, 37, 15, 47, 7, 39, 61, 29, 53, 21, 63, 31, 55, 23, 4, 36, 12, 44, 2, 34, 10, 42, 52, 20, 60, 28, 50, 18, 58, 26, 16, 48, 8, 40, 14, 46, 6, 38, 64, 32, 56, 24, 62, 30, 54, 22 }; // dither table fb0[pb*x/8+fs*y] = ((128&(c-dt[(7&x)+8*(7&y)]))/128*(blk&(240*(1&~x)| 15*(1&x)|fb0[pb*x/8+fs*y])))|((128&(dt[(7&x)+8*(7&y)]-c))/128*wht| (blk&((240*(1&x)|15*(1&~x))&fb0[pb*x/8+fs*y]))); // geekmaster formula 42 } //==================================== // getmsec - get msec since first call // (tick counter wraps every 12 days) //------------------------------------ int getmsec(void) { int tc; static int ts=0; struct timeval tv; gettimeofday(&tv,NULL); tc=tv.tv_usec/1000+1000*(0xFFFFF&tv.tv_sec); if (0==tc) { ts=tc; } return tc-ts; } //================== // main - start here //------------------ int main(int argc,char **argv) { if (argc>1) { mpu=atoi(argv[1]); } simplePixelDemo(); return 0; } Last edited by jmseight; 04-21-2012 at 12:54 PM. |
04-21-2012, 04:46 PM | #30 | |
Carpe diem, c'est la vie.
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
Quote:
I have a new modified formula 42 that takes color values 0-255 instead of 0-65, so it can be used directly with 8-bit images with no need to pre-scale the color values. It was published as part of "paldemo". It also works with non-linear dither tables, including a LCD 2.2-gamma table (screenshot provided in paldemo post). I just ran your version. The dithered grays do look interesting on this demo. I like seeing my code grow in unexpected directions that are not on MY "to do" list. P.S. I am getting an occasional "sementation fault" error on this, which probably means that it tried to write past the end of the framebuffer (y > 799). Although there is no harm in this for a demo, it SHOULD be fixed in the next version (so this error does not end up in other code that borrowed from this, perhaps causing real damage in some other scenario -- better to just do it right). Last edited by geekmaster; 11-25-2012 at 11:01 PM. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Troubleshooting Kindle and math formula | DrShakalu | Amazon Kindle | 12 | 12-11-2011 07:25 AM |
Formula Plots | PuxyYunm | General Discussions | 9 | 05-15-2011 04:19 AM |
Demo: Jetbook mini official demo | bookwarm | Ectaco jetBook | 36 | 09-21-2010 12:18 PM |