#include #include "console.h" #include "dirlist.h" #include "screen.h" #include "image.h" #include "browse.h" #include "tools.h" #include "charmap.h" #include "touchpad.h" #define SCR16_DELAY 35 #define CONTRAST_DELAY 100 #define ESC_DELAY 200 #define MEM1 0x900B0000 #define MEM2 0x900B000C int getMem(int addr) { return *(volatile unsigned*) addr; } void setMem(int addr, int val) { *(volatile unsigned*) addr = val; } int main(int argc, char* argv[]) { switchScrOffOn(0); // prevents displaying garbage when the screen mode will be changed int orig = getMem(MEM1); setMem(MEM1,4098); // overclock 300/150/75MHz setMem(MEM2,4); unsigned int contrast=getContrast(); unsigned int ocontrast=contrast; unsigned char* screen = (unsigned char*) malloc(SCREEN_WIDTH*SCREEN_HEIGHT*2); unsigned char* offscreen = (unsigned char*) malloc(SCREEN_WIDTH*SCREEN_HEIGHT*2); unsigned char* t; fileheader fheader; dataheader dheader; char* image; char* rawdatabuf=NULL; char path[PATH_SIZE]; int ximg, yimg; float ratio, zoom = 1.0, zmax; if(argc<1) return 0; strcpy(path, argv[0]); FILE* img; int selected=1; setScreen(screen); startScrMode16(); clrBuf(screen); switchScrOffOn(1); while(selected) { selected=chooseFile(path,path," mViewer 3.0: Select image file"); if(selected) // choix du fichier non annulé { clrScr(); resetConsole(); img = fopen(path, "rb"); if(readFileHeader(&fheader,img)) { if(fheader.type==1) // support BMP { if(readDataHeader(&dheader,img,&fheader)) { if(fheader.type==1 && (dheader.compression==0 || dheader.compression==1 || dheader.compression==3) ) // formats gérés { dispHeader(&fheader, &dheader); displn("[+]Contrast+ [x]ZoomIn [ ]Scrolling",0); disp("[-]Contrast- [ö]ZoomOut [ esc ]Return",0); int* palette=0; if(dheader.indexedcolors) { palette=(int*)malloc(dheader.indexedcolors*sizeof(int)); readPalette(palette, &dheader, img, &fheader); } image = (char*) malloc(dheader.width*dheader.height); initImgProgress(MAX_COL-4,0,0); if(readImage(image, &dheader, palette, img, &fheader)) { endImgProgress(); ximg=0; yimg=0; ratio = (dheader.width/320.0 > dheader.height/240.0) ? dheader.width/320.0 : dheader.height/240.0; zmax = (ratio > 1.0) ? ratio : 1.0; zoom=zmax; clrBuf(offscreen); unsigned int e=1; // Binary-Events e: // * -> refresh // 2 -> scroll up // 4 -> scroll down // 8 -> scroll left // 16 -> scroll right // 32 -> zoom // 64 -> dezoom int rstep=0, lstep=0, ustep=0, dstep=0; float istep=0.0,ostep=0.0; // for progressive zoom & scrolling int mode=2; //mode: bit0 = 16/32 colors | bit1 = Screen Off/On // int delay=35; // let's not refresh faster than the screen int torelease=0; // forbids action repeat before key is released: bit1=keyCTRL | bit2=keyC int zwidth=(int)(dheader.width/zoom), zheight=(int)(dheader.height)/zoom; // actual (zoomed) image dimensions int zwidthold=zwidth, zheightold=zheight; // keeps previous (zoomed) image dimensions clrBuf(screen); initTP(); while(!isKeyPressed(KEY_NSPIRE_ESC)) { if(!(e&2)) ustep=0; else ustep++; if(!(e&4)) dstep=0; else dstep++; if(!(e&8)) lstep=0; else lstep++; if(!(e&16)) rstep=0; else rstep++; if(!(e&32)) istep=0.0; else istep+=0.01; if(!(e&64)) ostep=0.0; else ostep+=0.01; if(isTouchpad()) { if(!(mode&1)) wait(TOUCHPAD_DELAY); readTP(); } if (isTPTouched() && !isTPPressed()) e|=128; if(e) { if(e&128) { ximg-=getX_Velocity()*10; yimg+=getY_Velocity()*10; if(yimg>0) yimg=0; if(ximg>0) ximg=0; if(ximg+zwidthzmax) ostep=zmax-zoom; zoom+=ostep; zwidthold=zwidth; zheightold=zheight; zwidth=(int)(dheader.width/zoom); zheight=(int)(dheader.height/zoom); ximg = (ximg-SCREEN_WIDTH/2)*zwidth/zwidthold+SCREEN_WIDTH/2; yimg = (yimg-SCREEN_HEIGHT/2)*zheight/zheightold+SCREEN_HEIGHT/2; if(zwidth0) yimg=0; if(ximg>0) ximg=0; dispBufIMG(offscreen,ximg, yimg, image, dheader.width, dheader.height, zoom); setScreen(offscreen); // offscreen buffer becomes onscreen buffer t=offscreen;offscreen=screen;screen=t; // switch offscreen & onscreen pointers if(e&64) { if(zwidth SCREEN_HEIGHT ) e|=2 ; if((isKeyPressed(KEY_NSPIRE_LEFT) || isKeyPressed(KEY_NSPIRE_DOWNLEFT) || isKeyPressed(KEY_NSPIRE_LEFTUP) || isKeyPressed(KEY_NSPIRE_1) || isKeyPressed(KEY_NSPIRE_4) || isKeyPressed(KEY_NSPIRE_7)) && !isKeyPressed(KEY_NSPIRE_5) && !isKeyPressed(KEY_NSPIRE_CLICK) && ximg<0 ) e|=16; if((isKeyPressed(KEY_NSPIRE_RIGHT) || isKeyPressed(KEY_NSPIRE_RIGHTDOWN) || isKeyPressed(KEY_NSPIRE_UPRIGHT) || isKeyPressed(KEY_NSPIRE_3) || isKeyPressed(KEY_NSPIRE_6) || isKeyPressed(KEY_NSPIRE_9)) && !isKeyPressed(KEY_NSPIRE_5) && !isKeyPressed(KEY_NSPIRE_CLICK) && ximg+zwidth > SCREEN_WIDTH ) e|=8 ; if(isKeyPressed(KEY_NSPIRE_MULTIPLY) && zoom>1.0) e|=32; if(isKeyPressed(KEY_NSPIRE_DIVIDE) && zoomCONTRAST_MIN) { setContrast(--contrast); if(!(mode&1)) { if(isTouchpad()) wait(CONTRAST_DELAY-TOUCHPAD_DELAY); else wait(CONTRAST_DELAY); } } if(isKeyPressed(KEY_NSPIRE_5) || isKeyPressed(KEY_NSPIRE_CLICK)) { if(!(torelease&4) && (isKeyPressed(KEY_NSPIRE_2) || isKeyPressed(KEY_NSPIRE_1) || isKeyPressed(KEY_NSPIRE_3) || isKeyPressed(KEY_NSPIRE_DOWN) || isKeyPressed(KEY_NSPIRE_RIGHTDOWN) || isKeyPressed(KEY_NSPIRE_DOWNLEFT))) { yimg-=(int)(SCREEN_HEIGHT*zoom); torelease|=4; e|=1; } if(!(torelease&8) && (isKeyPressed(KEY_NSPIRE_8) || isKeyPressed(KEY_NSPIRE_7) || isKeyPressed(KEY_NSPIRE_9) || isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_UPRIGHT) || isKeyPressed(KEY_NSPIRE_LEFTUP))) { yimg+=(int)(SCREEN_HEIGHT*zoom); torelease|=8; e|=1; } if(!(torelease&16) && (isKeyPressed(KEY_NSPIRE_4) || isKeyPressed(KEY_NSPIRE_7) || isKeyPressed(KEY_NSPIRE_1) || isKeyPressed(KEY_NSPIRE_LEFT) || isKeyPressed(KEY_NSPIRE_LEFTUP) || isKeyPressed(KEY_NSPIRE_DOWNLEFT))) { ximg+=(int)(SCREEN_WIDTH*zoom); torelease|=16; e|=1; } if(!(torelease&32) && (isKeyPressed(KEY_NSPIRE_6) || isKeyPressed(KEY_NSPIRE_3) || isKeyPressed(KEY_NSPIRE_9) || isKeyPressed(KEY_NSPIRE_RIGHT) || isKeyPressed(KEY_NSPIRE_UPRIGHT) || isKeyPressed(KEY_NSPIRE_RIGHTDOWN))) { ximg-=(int)(SCREEN_WIDTH*zoom); torelease|=32; e|=1; } } if(!(torelease&1) && isKeyPressed(KEY_NSPIRE_CTRL)) { if(mode&2) mode&=~2; else mode|=2; switchScrOffOn(mode&2); torelease|=1; } if(!(torelease&2) && isKeyPressed(KEY_NSPIRE_C)) { resetConsole(); if(mode&1) { mode&=~1; if(!(mode&4)) { switchRGB(1); mode|=4; } } else mode|=1; torelease|=2; } if(mode&1 ) { wait(SCR16_DELAY); if(mode&4) mode&=~4; else mode|=4; switchRGB(mode&4); } if(torelease) // no-repeat actions { if(!isKeyPressed(KEY_NSPIRE_CTRL)) torelease &= ~1; if(!isKeyPressed(KEY_NSPIRE_C)) torelease &= ~2; if((!isKeyPressed(KEY_NSPIRE_5) && !isKeyPressed(KEY_NSPIRE_CLICK)) || (!isKeyPressed(KEY_NSPIRE_2) && !isKeyPressed(KEY_NSPIRE_1) && !isKeyPressed(KEY_NSPIRE_3) && !isKeyPressed(KEY_NSPIRE_DOWN))) torelease &= ~4; if((!isKeyPressed(KEY_NSPIRE_5) && !isKeyPressed(KEY_NSPIRE_CLICK)) || (!isKeyPressed(KEY_NSPIRE_8) && !isKeyPressed(KEY_NSPIRE_7) && !isKeyPressed(KEY_NSPIRE_9) && !isKeyPressed(KEY_NSPIRE_UP))) torelease &= ~8; if(!isKeyPressed(KEY_NSPIRE_5) && !isKeyPressed(KEY_NSPIRE_CLICK) || !isKeyPressed(KEY_NSPIRE_4) && !isKeyPressed(KEY_NSPIRE_1) && !isKeyPressed(KEY_NSPIRE_7) && !isKeyPressed(KEY_NSPIRE_LEFT)) torelease &= ~16; if(!isKeyPressed(KEY_NSPIRE_5) && !isKeyPressed(KEY_NSPIRE_CLICK) || !isKeyPressed(KEY_NSPIRE_6) && !isKeyPressed(KEY_NSPIRE_3) && !isKeyPressed(KEY_NSPIRE_9) && !isKeyPressed(KEY_NSPIRE_RIGHT)) torelease &= ~32; } if( !(mode&1) && !isTouchpad()) wait(TOUCHPAD_DELAY); } endTP(); if(!(mode&2)) switchScrOffOn(1); if(mode&4) switchRGB(1); setContrast(ocontrast); contrast=ocontrast; } else { displn("",0); pause("Error reading image data...",0, 1); } free(image); free(palette); } else { displn("Unsupported image data...",0); dispHeader(&fheader,&dheader); pause(NULL,0,1); } } else { displn("Unrecognized image data...",0); dispHeader(&fheader,&dheader); pause(NULL,0,1); } } else { displn("Unsupported image type...",0); dispHeader(&fheader,&dheader); pause(NULL,0,1); } } else pause("Unrecognized image type...",0, 1); fclose(img); if(selected) wait(ESC_DELAY); } } switchScrOffOn(0); // prevents displaying garbage when the screen mode will be changed endScrMode16(); free(offscreen); free(screen); setMem(MEM1,orig); // reset overclock setMem(MEM2,4); switchScrOffOn(1); return 0; }