Home » Archimedes archive » Acorn User » AU 1998-05 A.adf » Regulars » StarInfo/Johns/c/JScrnSave
StarInfo/Johns/c/JScrnSave
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1998-05 A.adf » Regulars |
Filename: | StarInfo/Johns/c/JScrnSave |
Read OK: | ✔ |
File size: | 1969 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* ** JScrnSave ** --------- ** Saves the screen as a JPEG. For 4-32bpp modes only. ** (c) 1997 Chris Johns ** ** JScreenSave is FREEWARE */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "kernel.h" #include "swis.h" #include "screen.h" #include "cjpeg.h" #define JPEGSIZE 512*1024 int hdpi(void); int vdpi(void); void hourglass_percentage(int percentage); void grab_32bpp(char *addr,char *buff,int tag,int xsize,int ysize); void grab_16bpp(char *addr,char *buff,int tag,int xsize,int ysize); void grab_8bpp (char *addr,char *buff,int *palette,int tag,int xsize,int ysize); void grab_4bpp (char *addr,char *buff,int *palette,int tag,int xsize,int ysize); _kernel_oserror nobuff = {0,"Failed to allocate buffer."}; int main(int ac,char *av[]) { char *filename; int quality; int xsize,ysize; char *linebuff; void *screen = screenaddr(); char *jpeg = malloc(JPEGSIZE); int *palette= NULL; CJPEG_params params; int tag,size; if (jpeg==NULL) _kernel_raise_error(&nobuff); // Check that we have the CompressJPEG module { _kernel_swi_regs r; _kernel_oserror *e; r.r[0] = 18; r.r[1] = (int) "CompressJPEG"; e = _kernel_swi(OS_Module,&r,&r); if (e!=NULL) { r.r[0] = 1; r.r[1] = (int) "System:Modules.JCompMod"; e = _kernel_swi(OS_Module,&r,&r); if (e!=NULL) _kernel_raise_error(e); } } // Check argc if (ac<2 || ac>3) { _kernel_oserror e = {0,"Syntax: *JScrnSave <filename> [quality]"}; _kernel_raise_error(&e); } // read the filename filename = malloc(strlen(av[1])+1); if (filename==NULL) _kernel_raise_error(&nobuff); strcpy(filename,av[1]); // read the quality if (ac==3) { sscanf(av[2],"%d",&quality); if (quality<1 || quality>100) { _kernel_oserror e = {0,"Quality must be between 1 and 100"}; _kernel_raise_error(&e); } } else quality=75; // check the bpp if (screenbpp()<4) { _kernel_oserror e = {0,"Sorry, I cannot handle <4 bpp screens"}; _kernel_raise_error(&e); } // Start the hourglas _swi(Hourglass_On,0); _swi(Hourglass_LEDs,_IN(0)|_IN(1),1,1); // Get the screen size screensize(&xsize,&ysize); // if we need read the palette then do so if (screenbpp()<=8) { _kernel_swi_regs r; r.r[0] = -1; r.r[1] = -1; r.r[2] = 0; r.r[3] = 0; r.r[4] = 0; _kernel_swi(ColourTrans_ReadPalette,&r,&r); palette = malloc(r.r[3]); if (palette==NULL) _kernel_raise_error(&nobuff); r.r[2] = (int) palette; _kernel_swi(ColourTrans_ReadPalette,&r,&r); } // setup the CJPEG paramaters params.width = xsize; params.height = ysize; params.quality = quality; params.no8bc = 3; params.hdpi = hdpi(); params.vdpi = vdpi(); // Start to create the JPEG tag = CJPEG_Start(jpeg,JPEGSIZE,¶ms); // allocate memory to linebuff linebuff = malloc(xsize*3); if (linebuff==NULL) _kernel_raise_error(&nobuff); _swi(Hourglass_LEDs,_IN(0)|_IN(1),0,0); // Add each line switch (screenbpp()) { case 32 : grab_32bpp(screen,linebuff,tag,xsize,ysize); break; case 16 : grab_16bpp(screen,linebuff,tag,xsize,ysize); break; case 8 : grab_8bpp(screen,linebuff,palette,tag,xsize,ysize); break; case 4 : grab_4bpp(screen,linebuff,palette,tag,xsize,ysize); break; } // free the buffer _swi(Hourglass_Percentage,_IN(0),-1); _swi(Hourglass_LEDs,_IN(0)|_IN(1),2,2); free(linebuff); // Tidy up and get size size = CJPEG_Finish(tag); { // Save the file _kernel_osfile_block block; block.load = 0xc85; block.exec = 0; block.start = (int) jpeg; block.end = (int) jpeg+size; if (_kernel_osfile(10,filename,&block)<0) { _kernel_oserror e={0,"Failed to save screen\n"}; _kernel_raise_error(&e); } } // Stop the hourglass _swi(Hourglass_Off,0); // free memory if (palette!=NULL) free(palette); free(filename); free(jpeg); } // Functions to get DPI of the mode #define EIG_TO_DPI { switch (eig) { \ case 2:dpi=45; break; \ case 1:dpi=90; break; \ case 0:dpi=180; break; } } int hdpi(void) { int eig,junk,dpi; screeneig(&eig,&junk); EIG_TO_DPI; return dpi; } int vdpi(void) { int eig,junk,dpi; screeneig(&junk,&eig); EIG_TO_DPI; return dpi; } // grab the screen in 32bpp void grab_32bpp(char *saddr,char *buff,int tag,int xsize,int ysize) { int line; for (line=0;line<ysize;line++) { char *adr = saddr+(line*xsize*4); int pix; hourglass_percentage((line*100)/ysize); for (pix=0;pix<xsize;pix++) { buff[(pix*3)+0] = adr[(pix*4)+0]; buff[(pix*3)+1] = adr[(pix*4)+1]; buff[(pix*3)+2] = adr[(pix*4)+2]; } CJPEG_WriteLine(tag,buff); } } // grab the screen in 16bpp void grab_16bpp(char *saddr,char *buff,int tag,int xsize,int ysize) { int line; for (line=0;line<ysize;line++) { char *adr = saddr+(line*xsize*2); int pix; hourglass_percentage((line*100)/ysize); for (pix=0;pix<xsize;pix++) { unsigned word = adr[(pix*2)] | (adr[(pix*2)+1] << 8); word = word & 0xffff; buff[(pix*3)+2] = (word & 0x7c00) >> 7; buff[(pix*3)+1] = (word & 0x3e0) >> 2; buff[(pix*3)+0] = (word & 0x1f) << 3; } CJPEG_WriteLine(tag,buff); } } // grab the screen in 8pp void grab_8bpp (char *saddr,char *buff,int *palette,int tag,int xsize,int ysize) { int line; for (line=0;line<ysize;line++) { char *adr = saddr+(line*xsize); int pix; hourglass_percentage((line*100)/ysize); for (pix=0;pix<xsize;pix++) { char p = adr[pix]; buff[(pix*3)+0] = ((char *)palette)[(p*4)+1]; buff[(pix*3)+1] = ((char *)palette)[(p*4)+2]; buff[(pix*3)+2] = ((char *)palette)[(p*4)+3]; } CJPEG_WriteLine(tag,buff); } } // grab the screen in 4pp void grab_4bpp (char *saddr,char *buff,int *palette,int tag,int xsize,int ysize) { int line; for (line=0;line<ysize;line++) { char *adr = saddr+(line*(xsize/2)); int pix; hourglass_percentage((line*100)/ysize); for (pix=0;pix<xsize;pix++) { char p; if ((pix % 2) == 0) p = adr[pix/2] & 0xf; if ((pix % 2) == 1) p = (adr[(pix-1)/2] & 0xf0) >> 4; buff[(pix*3)+0] = ((char *)palette)[(p*4)+1]; buff[(pix*3)+1] = ((char *)palette)[(p*4)+2]; buff[(pix*3)+2] = ((char *)palette)[(p*4)+3]; } CJPEG_WriteLine(tag,buff); } }
00000000 2f 2a 0a 2a 2a 20 4a 53 63 72 6e 53 61 76 65 0a |/*.** JScrnSave.| 00000010 2a 2a 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 2a 2a 20 |** ---------.** | 00000020 53 61 76 65 73 20 74 68 65 20 73 63 72 65 65 6e |Saves the screen| 00000030 20 61 73 20 61 20 4a 50 45 47 2e 20 46 6f 72 20 | as a JPEG. For | 00000040 34 2d 33 32 62 70 70 20 6d 6f 64 65 73 20 6f 6e |4-32bpp modes on| 00000050 6c 79 2e 0a 2a 2a 20 28 63 29 20 31 39 39 37 20 |ly..** (c) 1997 | 00000060 43 68 72 69 73 20 4a 6f 68 6e 73 0a 2a 2a 0a 2a |Chris Johns.**.*| 00000070 2a 20 4a 53 63 72 65 65 6e 53 61 76 65 20 69 73 |* JScreenSave is| 00000080 20 46 52 45 45 57 41 52 45 0a 2a 2f 0a 23 69 6e | FREEWARE.*/.#in| 00000090 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a |clude <stdio.h>.| 000000a0 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 6c 69 62 |#include <stdlib| 000000b0 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 |.h>.#include <st| 000000c0 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 |ring.h>.#include| 000000d0 20 22 6b 65 72 6e 65 6c 2e 68 22 0a 23 69 6e 63 | "kernel.h".#inc| 000000e0 6c 75 64 65 20 22 73 77 69 73 2e 68 22 0a 0a 23 |lude "swis.h"..#| 000000f0 69 6e 63 6c 75 64 65 20 22 73 63 72 65 65 6e 2e |include "screen.| 00000100 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 63 6a 70 |h".#include "cjp| 00000110 65 67 2e 68 22 0a 0a 23 64 65 66 69 6e 65 20 4a |eg.h"..#define J| 00000120 50 45 47 53 49 5a 45 20 35 31 32 2a 31 30 32 34 |PEGSIZE 512*1024| 00000130 0a 0a 69 6e 74 20 68 64 70 69 28 76 6f 69 64 29 |..int hdpi(void)| 00000140 3b 0a 69 6e 74 20 76 64 70 69 28 76 6f 69 64 29 |;.int vdpi(void)| 00000150 3b 0a 0a 76 6f 69 64 20 68 6f 75 72 67 6c 61 73 |;..void hourglas| 00000160 73 5f 70 65 72 63 65 6e 74 61 67 65 28 69 6e 74 |s_percentage(int| 00000170 20 70 65 72 63 65 6e 74 61 67 65 29 3b 0a 0a 76 | percentage);..v| 00000180 6f 69 64 20 67 72 61 62 5f 33 32 62 70 70 28 63 |oid grab_32bpp(c| 00000190 68 61 72 20 2a 61 64 64 72 2c 63 68 61 72 20 2a |har *addr,char *| 000001a0 62 75 66 66 2c 69 6e 74 20 74 61 67 2c 69 6e 74 |buff,int tag,int| 000001b0 20 78 73 69 7a 65 2c 69 6e 74 20 79 73 69 7a 65 | xsize,int ysize| 000001c0 29 3b 0a 76 6f 69 64 20 67 72 61 62 5f 31 36 62 |);.void grab_16b| 000001d0 70 70 28 63 68 61 72 20 2a 61 64 64 72 2c 63 68 |pp(char *addr,ch| 000001e0 61 72 20 2a 62 75 66 66 2c 69 6e 74 20 74 61 67 |ar *buff,int tag| 000001f0 2c 69 6e 74 20 78 73 69 7a 65 2c 69 6e 74 20 79 |,int xsize,int y| 00000200 73 69 7a 65 29 3b 0a 76 6f 69 64 20 67 72 61 62 |size);.void grab| 00000210 5f 38 62 70 70 0a 20 20 20 20 20 20 20 20 20 20 |_8bpp. | 00000220 20 28 63 68 61 72 20 2a 61 64 64 72 2c 63 68 61 | (char *addr,cha| 00000230 72 20 2a 62 75 66 66 2c 69 6e 74 20 2a 70 61 6c |r *buff,int *pal| 00000240 65 74 74 65 2c 69 6e 74 20 74 61 67 2c 69 6e 74 |ette,int tag,int| 00000250 20 78 73 69 7a 65 2c 69 6e 74 20 79 73 69 7a 65 | xsize,int ysize| 00000260 29 3b 0a 76 6f 69 64 20 67 72 61 62 5f 34 62 70 |);.void grab_4bp| 00000270 70 0a 20 20 20 20 20 20 20 20 20 20 20 28 63 68 |p. (ch| 00000280 61 72 20 2a 61 64 64 72 2c 63 68 61 72 20 2a 62 |ar *addr,char *b| 00000290 75 66 66 2c 69 6e 74 20 2a 70 61 6c 65 74 74 65 |uff,int *palette| 000002a0 2c 69 6e 74 20 74 61 67 2c 69 6e 74 20 78 73 69 |,int tag,int xsi| 000002b0 7a 65 2c 69 6e 74 20 79 73 69 7a 65 29 3b 0a 0a |ze,int ysize);..| 000002c0 5f 6b 65 72 6e 65 6c 5f 6f 73 65 72 72 6f 72 20 |_kernel_oserror | 000002d0 6e 6f 62 75 66 66 20 3d 20 7b 30 2c 22 46 61 69 |nobuff = {0,"Fai| 000002e0 6c 65 64 20 74 6f 20 61 6c 6c 6f 63 61 74 65 20 |led to allocate | 000002f0 62 75 66 66 65 72 2e 22 7d 3b 0a 0a 69 6e 74 20 |buffer."};..int | 00000300 6d 61 69 6e 28 69 6e 74 20 61 63 2c 63 68 61 72 |main(int ac,char| 00000310 20 2a 61 76 5b 5d 29 0a 7b 0a 20 20 63 68 61 72 | *av[]).{. char| 00000320 20 2a 66 69 6c 65 6e 61 6d 65 3b 0a 20 20 69 6e | *filename;. in| 00000330 74 20 20 20 71 75 61 6c 69 74 79 3b 0a 20 20 69 |t quality;. i| 00000340 6e 74 20 20 20 78 73 69 7a 65 2c 79 73 69 7a 65 |nt xsize,ysize| 00000350 3b 0a 20 20 63 68 61 72 20 2a 6c 69 6e 65 62 75 |;. char *linebu| 00000360 66 66 3b 0a 20 20 76 6f 69 64 20 2a 73 63 72 65 |ff;. void *scre| 00000370 65 6e 20 3d 20 73 63 72 65 65 6e 61 64 64 72 28 |en = screenaddr(| 00000380 29 3b 0a 20 20 63 68 61 72 20 2a 6a 70 65 67 20 |);. char *jpeg | 00000390 20 20 3d 20 6d 61 6c 6c 6f 63 28 4a 50 45 47 53 | = malloc(JPEGS| 000003a0 49 5a 45 29 3b 0a 20 20 69 6e 74 20 20 2a 70 61 |IZE);. int *pa| 000003b0 6c 65 74 74 65 3d 20 4e 55 4c 4c 3b 0a 20 20 43 |lette= NULL;. C| 000003c0 4a 50 45 47 5f 70 61 72 61 6d 73 20 70 61 72 61 |JPEG_params para| 000003d0 6d 73 3b 0a 20 20 69 6e 74 20 20 20 74 61 67 2c |ms;. int tag,| 000003e0 73 69 7a 65 3b 0a 0a 20 20 69 66 20 28 6a 70 65 |size;.. if (jpe| 000003f0 67 3d 3d 4e 55 4c 4c 29 20 5f 6b 65 72 6e 65 6c |g==NULL) _kernel| 00000400 5f 72 61 69 73 65 5f 65 72 72 6f 72 28 26 6e 6f |_raise_error(&no| 00000410 62 75 66 66 29 3b 0a 0a 20 20 2f 2f 20 43 68 65 |buff);.. // Che| 00000420 63 6b 20 74 68 61 74 20 77 65 20 68 61 76 65 20 |ck that we have | 00000430 74 68 65 20 43 6f 6d 70 72 65 73 73 4a 50 45 47 |the CompressJPEG| 00000440 20 6d 6f 64 75 6c 65 0a 20 20 7b 0a 20 20 20 20 | module. {. | 00000450 5f 6b 65 72 6e 65 6c 5f 73 77 69 5f 72 65 67 73 |_kernel_swi_regs| 00000460 20 72 3b 0a 20 20 20 20 5f 6b 65 72 6e 65 6c 5f | r;. _kernel_| 00000470 6f 73 65 72 72 6f 72 20 2a 65 3b 0a 20 20 20 20 |oserror *e;. | 00000480 72 2e 72 5b 30 5d 20 3d 20 31 38 3b 0a 20 20 20 |r.r[0] = 18;. | 00000490 20 72 2e 72 5b 31 5d 20 3d 20 28 69 6e 74 29 20 | r.r[1] = (int) | 000004a0 22 43 6f 6d 70 72 65 73 73 4a 50 45 47 22 3b 0a |"CompressJPEG";.| 000004b0 20 20 20 20 65 20 3d 20 5f 6b 65 72 6e 65 6c 5f | e = _kernel_| 000004c0 73 77 69 28 4f 53 5f 4d 6f 64 75 6c 65 2c 26 72 |swi(OS_Module,&r| 000004d0 2c 26 72 29 3b 0a 20 20 20 20 69 66 20 28 65 21 |,&r);. if (e!| 000004e0 3d 4e 55 4c 4c 29 20 7b 0a 20 20 20 20 20 20 72 |=NULL) {. r| 000004f0 2e 72 5b 30 5d 20 3d 20 31 3b 0a 20 20 20 20 20 |.r[0] = 1;. | 00000500 20 72 2e 72 5b 31 5d 20 3d 20 28 69 6e 74 29 20 | r.r[1] = (int) | 00000510 22 53 79 73 74 65 6d 3a 4d 6f 64 75 6c 65 73 2e |"System:Modules.| 00000520 4a 43 6f 6d 70 4d 6f 64 22 3b 0a 20 20 20 20 20 |JCompMod";. | 00000530 20 65 20 3d 20 5f 6b 65 72 6e 65 6c 5f 73 77 69 | e = _kernel_swi| 00000540 28 4f 53 5f 4d 6f 64 75 6c 65 2c 26 72 2c 26 72 |(OS_Module,&r,&r| 00000550 29 3b 0a 20 20 20 20 20 20 69 66 20 28 65 21 3d |);. if (e!=| 00000560 4e 55 4c 4c 29 20 5f 6b 65 72 6e 65 6c 5f 72 61 |NULL) _kernel_ra| 00000570 69 73 65 5f 65 72 72 6f 72 28 65 29 3b 0a 20 20 |ise_error(e);. | 00000580 20 20 7d 0a 20 20 7d 0a 0a 20 20 2f 2f 20 43 68 | }. }.. // Ch| 00000590 65 63 6b 20 61 72 67 63 0a 20 20 69 66 20 28 61 |eck argc. if (a| 000005a0 63 3c 32 20 7c 7c 20 61 63 3e 33 29 20 7b 0a 20 |c<2 || ac>3) {. | 000005b0 20 20 20 5f 6b 65 72 6e 65 6c 5f 6f 73 65 72 72 | _kernel_oserr| 000005c0 6f 72 20 65 20 3d 20 7b 30 2c 22 53 79 6e 74 61 |or e = {0,"Synta| 000005d0 78 3a 20 2a 4a 53 63 72 6e 53 61 76 65 20 3c 66 |x: *JScrnSave <f| 000005e0 69 6c 65 6e 61 6d 65 3e 20 5b 71 75 61 6c 69 74 |ilename> [qualit| 000005f0 79 5d 22 7d 3b 0a 20 20 20 20 5f 6b 65 72 6e 65 |y]"};. _kerne| 00000600 6c 5f 72 61 69 73 65 5f 65 72 72 6f 72 28 26 65 |l_raise_error(&e| 00000610 29 3b 0a 20 20 7d 0a 0a 20 20 2f 2f 20 72 65 61 |);. }.. // rea| 00000620 64 20 74 68 65 20 66 69 6c 65 6e 61 6d 65 0a 20 |d the filename. | 00000630 20 66 69 6c 65 6e 61 6d 65 20 3d 20 6d 61 6c 6c | filename = mall| 00000640 6f 63 28 73 74 72 6c 65 6e 28 61 76 5b 31 5d 29 |oc(strlen(av[1])| 00000650 2b 31 29 3b 0a 20 20 69 66 20 28 66 69 6c 65 6e |+1);. if (filen| 00000660 61 6d 65 3d 3d 4e 55 4c 4c 29 20 5f 6b 65 72 6e |ame==NULL) _kern| 00000670 65 6c 5f 72 61 69 73 65 5f 65 72 72 6f 72 28 26 |el_raise_error(&| 00000680 6e 6f 62 75 66 66 29 3b 0a 20 20 73 74 72 63 70 |nobuff);. strcp| 00000690 79 28 66 69 6c 65 6e 61 6d 65 2c 61 76 5b 31 5d |y(filename,av[1]| 000006a0 29 3b 0a 0a 20 20 2f 2f 20 72 65 61 64 20 74 68 |);.. // read th| 000006b0 65 20 71 75 61 6c 69 74 79 0a 20 20 69 66 20 28 |e quality. if (| 000006c0 61 63 3d 3d 33 29 20 7b 0a 20 20 20 20 73 73 63 |ac==3) {. ssc| 000006d0 61 6e 66 28 61 76 5b 32 5d 2c 22 25 64 22 2c 26 |anf(av[2],"%d",&| 000006e0 71 75 61 6c 69 74 79 29 3b 0a 20 20 20 20 69 66 |quality);. if| 000006f0 20 28 71 75 61 6c 69 74 79 3c 31 20 7c 7c 20 71 | (quality<1 || q| 00000700 75 61 6c 69 74 79 3e 31 30 30 29 20 7b 0a 20 20 |uality>100) {. | 00000710 20 20 20 20 5f 6b 65 72 6e 65 6c 5f 6f 73 65 72 | _kernel_oser| 00000720 72 6f 72 20 65 20 3d 20 7b 30 2c 22 51 75 61 6c |ror e = {0,"Qual| 00000730 69 74 79 20 6d 75 73 74 20 62 65 20 62 65 74 77 |ity must be betw| 00000740 65 65 6e 20 31 20 61 6e 64 20 31 30 30 22 7d 3b |een 1 and 100"};| 00000750 0a 20 20 20 20 20 20 5f 6b 65 72 6e 65 6c 5f 72 |. _kernel_r| 00000760 61 69 73 65 5f 65 72 72 6f 72 28 26 65 29 3b 0a |aise_error(&e);.| 00000770 20 20 20 20 7d 0a 20 20 7d 20 65 6c 73 65 20 71 | }. } else q| 00000780 75 61 6c 69 74 79 3d 37 35 3b 0a 0a 20 20 2f 2f |uality=75;.. //| 00000790 20 63 68 65 63 6b 20 74 68 65 20 62 70 70 0a 20 | check the bpp. | 000007a0 20 69 66 20 28 73 63 72 65 65 6e 62 70 70 28 29 | if (screenbpp()| 000007b0 3c 34 29 20 7b 0a 20 20 20 20 5f 6b 65 72 6e 65 |<4) {. _kerne| 000007c0 6c 5f 6f 73 65 72 72 6f 72 20 65 20 3d 20 7b 30 |l_oserror e = {0| 000007d0 2c 22 53 6f 72 72 79 2c 20 49 20 63 61 6e 6e 6f |,"Sorry, I canno| 000007e0 74 20 68 61 6e 64 6c 65 20 3c 34 20 62 70 70 20 |t handle <4 bpp | 000007f0 73 63 72 65 65 6e 73 22 7d 3b 0a 20 20 20 20 5f |screens"};. _| 00000800 6b 65 72 6e 65 6c 5f 72 61 69 73 65 5f 65 72 72 |kernel_raise_err| 00000810 6f 72 28 26 65 29 3b 0a 20 20 7d 0a 0a 20 20 2f |or(&e);. }.. /| 00000820 2f 20 53 74 61 72 74 20 74 68 65 20 68 6f 75 72 |/ Start the hour| 00000830 67 6c 61 73 0a 20 20 5f 73 77 69 28 48 6f 75 72 |glas. _swi(Hour| 00000840 67 6c 61 73 73 5f 4f 6e 2c 30 29 3b 0a 20 20 5f |glass_On,0);. _| 00000850 73 77 69 28 48 6f 75 72 67 6c 61 73 73 5f 4c 45 |swi(Hourglass_LE| 00000860 44 73 2c 5f 49 4e 28 30 29 7c 5f 49 4e 28 31 29 |Ds,_IN(0)|_IN(1)| 00000870 2c 31 2c 31 29 3b 0a 0a 20 20 2f 2f 20 47 65 74 |,1,1);.. // Get| 00000880 20 74 68 65 20 73 63 72 65 65 6e 20 73 69 7a 65 | the screen size| 00000890 0a 20 20 73 63 72 65 65 6e 73 69 7a 65 28 26 78 |. screensize(&x| 000008a0 73 69 7a 65 2c 26 79 73 69 7a 65 29 3b 0a 0a 20 |size,&ysize);.. | 000008b0 20 2f 2f 20 69 66 20 77 65 20 6e 65 65 64 20 72 | // if we need r| 000008c0 65 61 64 20 74 68 65 20 70 61 6c 65 74 74 65 20 |ead the palette | 000008d0 74 68 65 6e 20 64 6f 20 73 6f 0a 20 20 69 66 20 |then do so. if | 000008e0 28 73 63 72 65 65 6e 62 70 70 28 29 3c 3d 38 29 |(screenbpp()<=8)| 000008f0 20 7b 0a 20 20 20 20 5f 6b 65 72 6e 65 6c 5f 73 | {. _kernel_s| 00000900 77 69 5f 72 65 67 73 20 72 3b 0a 20 20 20 20 72 |wi_regs r;. r| 00000910 2e 72 5b 30 5d 20 3d 20 2d 31 3b 20 72 2e 72 5b |.r[0] = -1; r.r[| 00000920 31 5d 20 3d 20 2d 31 3b 20 72 2e 72 5b 32 5d 20 |1] = -1; r.r[2] | 00000930 3d 20 30 3b 20 72 2e 72 5b 33 5d 20 3d 20 30 3b |= 0; r.r[3] = 0;| 00000940 20 72 2e 72 5b 34 5d 20 3d 20 30 3b 0a 20 20 20 | r.r[4] = 0;. | 00000950 20 5f 6b 65 72 6e 65 6c 5f 73 77 69 28 43 6f 6c | _kernel_swi(Col| 00000960 6f 75 72 54 72 61 6e 73 5f 52 65 61 64 50 61 6c |ourTrans_ReadPal| 00000970 65 74 74 65 2c 26 72 2c 26 72 29 3b 0a 20 20 20 |ette,&r,&r);. | 00000980 20 70 61 6c 65 74 74 65 20 3d 20 6d 61 6c 6c 6f | palette = mallo| 00000990 63 28 72 2e 72 5b 33 5d 29 3b 0a 20 20 20 20 69 |c(r.r[3]);. i| 000009a0 66 20 28 70 61 6c 65 74 74 65 3d 3d 4e 55 4c 4c |f (palette==NULL| 000009b0 29 20 5f 6b 65 72 6e 65 6c 5f 72 61 69 73 65 5f |) _kernel_raise_| 000009c0 65 72 72 6f 72 28 26 6e 6f 62 75 66 66 29 3b 0a |error(&nobuff);.| 000009d0 20 20 20 20 72 2e 72 5b 32 5d 20 3d 20 28 69 6e | r.r[2] = (in| 000009e0 74 29 20 70 61 6c 65 74 74 65 3b 0a 20 20 20 20 |t) palette;. | 000009f0 5f 6b 65 72 6e 65 6c 5f 73 77 69 28 43 6f 6c 6f |_kernel_swi(Colo| 00000a00 75 72 54 72 61 6e 73 5f 52 65 61 64 50 61 6c 65 |urTrans_ReadPale| 00000a10 74 74 65 2c 26 72 2c 26 72 29 3b 0a 20 20 7d 0a |tte,&r,&r);. }.| 00000a20 0a 20 20 2f 2f 20 73 65 74 75 70 20 74 68 65 20 |. // setup the | 00000a30 43 4a 50 45 47 20 70 61 72 61 6d 61 74 65 72 73 |CJPEG paramaters| 00000a40 0a 20 20 70 61 72 61 6d 73 2e 77 69 64 74 68 20 |. params.width | 00000a50 20 20 3d 20 78 73 69 7a 65 3b 0a 20 20 70 61 72 | = xsize;. par| 00000a60 61 6d 73 2e 68 65 69 67 68 74 20 20 3d 20 79 73 |ams.height = ys| 00000a70 69 7a 65 3b 0a 20 20 70 61 72 61 6d 73 2e 71 75 |ize;. params.qu| 00000a80 61 6c 69 74 79 20 3d 20 71 75 61 6c 69 74 79 3b |ality = quality;| 00000a90 0a 20 20 70 61 72 61 6d 73 2e 6e 6f 38 62 63 20 |. params.no8bc | 00000aa0 20 20 3d 20 33 3b 0a 20 20 70 61 72 61 6d 73 2e | = 3;. params.| 00000ab0 68 64 70 69 20 20 20 20 3d 20 68 64 70 69 28 29 |hdpi = hdpi()| 00000ac0 3b 0a 20 20 70 61 72 61 6d 73 2e 76 64 70 69 20 |;. params.vdpi | 00000ad0 20 20 20 3d 20 76 64 70 69 28 29 3b 0a 0a 20 20 | = vdpi();.. | 00000ae0 2f 2f 20 53 74 61 72 74 20 74 6f 20 63 72 65 61 |// Start to crea| 00000af0 74 65 20 74 68 65 20 4a 50 45 47 0a 20 20 74 61 |te the JPEG. ta| 00000b00 67 20 3d 20 43 4a 50 45 47 5f 53 74 61 72 74 28 |g = CJPEG_Start(| 00000b10 6a 70 65 67 2c 4a 50 45 47 53 49 5a 45 2c 26 70 |jpeg,JPEGSIZE,&p| 00000b20 61 72 61 6d 73 29 3b 0a 0a 20 20 2f 2f 20 61 6c |arams);.. // al| 00000b30 6c 6f 63 61 74 65 20 6d 65 6d 6f 72 79 20 74 6f |locate memory to| 00000b40 20 6c 69 6e 65 62 75 66 66 0a 20 20 6c 69 6e 65 | linebuff. line| 00000b50 62 75 66 66 20 3d 20 6d 61 6c 6c 6f 63 28 78 73 |buff = malloc(xs| 00000b60 69 7a 65 2a 33 29 3b 0a 20 20 69 66 20 28 6c 69 |ize*3);. if (li| 00000b70 6e 65 62 75 66 66 3d 3d 4e 55 4c 4c 29 20 5f 6b |nebuff==NULL) _k| 00000b80 65 72 6e 65 6c 5f 72 61 69 73 65 5f 65 72 72 6f |ernel_raise_erro| 00000b90 72 28 26 6e 6f 62 75 66 66 29 3b 0a 0a 20 20 5f |r(&nobuff);.. _| 00000ba0 73 77 69 28 48 6f 75 72 67 6c 61 73 73 5f 4c 45 |swi(Hourglass_LE| 00000bb0 44 73 2c 5f 49 4e 28 30 29 7c 5f 49 4e 28 31 29 |Ds,_IN(0)|_IN(1)| 00000bc0 2c 30 2c 30 29 3b 0a 20 20 2f 2f 20 41 64 64 20 |,0,0);. // Add | 00000bd0 65 61 63 68 20 6c 69 6e 65 0a 20 20 73 77 69 74 |each line. swit| 00000be0 63 68 20 28 73 63 72 65 65 6e 62 70 70 28 29 29 |ch (screenbpp())| 00000bf0 20 7b 0a 20 20 20 20 63 61 73 65 20 33 32 20 3a | {. case 32 :| 00000c00 20 67 72 61 62 5f 33 32 62 70 70 28 73 63 72 65 | grab_32bpp(scre| 00000c10 65 6e 2c 6c 69 6e 65 62 75 66 66 2c 74 61 67 2c |en,linebuff,tag,| 00000c20 78 73 69 7a 65 2c 79 73 69 7a 65 29 3b 20 62 72 |xsize,ysize); br| 00000c30 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 31 36 |eak;. case 16| 00000c40 20 3a 20 67 72 61 62 5f 31 36 62 70 70 28 73 63 | : grab_16bpp(sc| 00000c50 72 65 65 6e 2c 6c 69 6e 65 62 75 66 66 2c 74 61 |reen,linebuff,ta| 00000c60 67 2c 78 73 69 7a 65 2c 79 73 69 7a 65 29 3b 20 |g,xsize,ysize); | 00000c70 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 |break;. case | 00000c80 38 20 20 3a 20 67 72 61 62 5f 38 62 70 70 28 73 |8 : grab_8bpp(s| 00000c90 63 72 65 65 6e 2c 6c 69 6e 65 62 75 66 66 2c 70 |creen,linebuff,p| 00000ca0 61 6c 65 74 74 65 2c 74 61 67 2c 78 73 69 7a 65 |alette,tag,xsize| 00000cb0 2c 79 73 69 7a 65 29 3b 20 20 62 72 65 61 6b 3b |,ysize); break;| 00000cc0 0a 20 20 20 20 63 61 73 65 20 34 20 20 3a 20 67 |. case 4 : g| 00000cd0 72 61 62 5f 34 62 70 70 28 73 63 72 65 65 6e 2c |rab_4bpp(screen,| 00000ce0 6c 69 6e 65 62 75 66 66 2c 70 61 6c 65 74 74 65 |linebuff,palette| 00000cf0 2c 74 61 67 2c 78 73 69 7a 65 2c 79 73 69 7a 65 |,tag,xsize,ysize| 00000d00 29 3b 20 20 62 72 65 61 6b 3b 0a 20 20 7d 0a 0a |); break;. }..| 00000d10 20 20 2f 2f 20 66 72 65 65 20 74 68 65 20 62 75 | // free the bu| 00000d20 66 66 65 72 0a 20 20 5f 73 77 69 28 48 6f 75 72 |ffer. _swi(Hour| 00000d30 67 6c 61 73 73 5f 50 65 72 63 65 6e 74 61 67 65 |glass_Percentage| 00000d40 2c 5f 49 4e 28 30 29 2c 2d 31 29 3b 0a 20 20 5f |,_IN(0),-1);. _| 00000d50 73 77 69 28 48 6f 75 72 67 6c 61 73 73 5f 4c 45 |swi(Hourglass_LE| 00000d60 44 73 2c 5f 49 4e 28 30 29 7c 5f 49 4e 28 31 29 |Ds,_IN(0)|_IN(1)| 00000d70 2c 32 2c 32 29 3b 0a 20 20 66 72 65 65 28 6c 69 |,2,2);. free(li| 00000d80 6e 65 62 75 66 66 29 3b 0a 0a 20 20 2f 2f 20 54 |nebuff);.. // T| 00000d90 69 64 79 20 75 70 20 61 6e 64 20 67 65 74 20 73 |idy up and get s| 00000da0 69 7a 65 0a 20 20 73 69 7a 65 20 3d 20 43 4a 50 |ize. size = CJP| 00000db0 45 47 5f 46 69 6e 69 73 68 28 74 61 67 29 3b 0a |EG_Finish(tag);.| 00000dc0 0a 20 20 7b 20 2f 2f 20 53 61 76 65 20 74 68 65 |. { // Save the| 00000dd0 20 66 69 6c 65 0a 20 20 20 20 5f 6b 65 72 6e 65 | file. _kerne| 00000de0 6c 5f 6f 73 66 69 6c 65 5f 62 6c 6f 63 6b 20 62 |l_osfile_block b| 00000df0 6c 6f 63 6b 3b 0a 20 20 20 20 62 6c 6f 63 6b 2e |lock;. block.| 00000e00 6c 6f 61 64 20 20 3d 20 30 78 63 38 35 3b 0a 20 |load = 0xc85;. | 00000e10 20 20 20 62 6c 6f 63 6b 2e 65 78 65 63 20 20 3d | block.exec =| 00000e20 20 30 3b 0a 20 20 20 20 62 6c 6f 63 6b 2e 73 74 | 0;. block.st| 00000e30 61 72 74 20 3d 20 28 69 6e 74 29 20 6a 70 65 67 |art = (int) jpeg| 00000e40 3b 0a 20 20 20 20 62 6c 6f 63 6b 2e 65 6e 64 20 |;. block.end | 00000e50 20 20 3d 20 28 69 6e 74 29 20 6a 70 65 67 2b 73 | = (int) jpeg+s| 00000e60 69 7a 65 3b 0a 0a 20 20 20 20 69 66 20 28 5f 6b |ize;.. if (_k| 00000e70 65 72 6e 65 6c 5f 6f 73 66 69 6c 65 28 31 30 2c |ernel_osfile(10,| 00000e80 66 69 6c 65 6e 61 6d 65 2c 26 62 6c 6f 63 6b 29 |filename,&block)| 00000e90 3c 30 29 20 7b 0a 20 20 20 20 20 20 5f 6b 65 72 |<0) {. _ker| 00000ea0 6e 65 6c 5f 6f 73 65 72 72 6f 72 20 65 3d 7b 30 |nel_oserror e={0| 00000eb0 2c 22 46 61 69 6c 65 64 20 74 6f 20 73 61 76 65 |,"Failed to save| 00000ec0 20 73 63 72 65 65 6e 5c 6e 22 7d 3b 0a 20 20 20 | screen\n"};. | 00000ed0 20 20 20 5f 6b 65 72 6e 65 6c 5f 72 61 69 73 65 | _kernel_raise| 00000ee0 5f 65 72 72 6f 72 28 26 65 29 3b 0a 20 20 20 20 |_error(&e);. | 00000ef0 7d 0a 20 20 7d 0a 0a 20 20 2f 2f 20 53 74 6f 70 |}. }.. // Stop| 00000f00 20 74 68 65 20 68 6f 75 72 67 6c 61 73 73 0a 20 | the hourglass. | 00000f10 20 5f 73 77 69 28 48 6f 75 72 67 6c 61 73 73 5f | _swi(Hourglass_| 00000f20 4f 66 66 2c 30 29 3b 0a 0a 20 20 2f 2f 20 66 72 |Off,0);.. // fr| 00000f30 65 65 20 6d 65 6d 6f 72 79 0a 20 20 69 66 20 28 |ee memory. if (| 00000f40 70 61 6c 65 74 74 65 21 3d 4e 55 4c 4c 29 20 66 |palette!=NULL) f| 00000f50 72 65 65 28 70 61 6c 65 74 74 65 29 3b 0a 20 20 |ree(palette);. | 00000f60 66 72 65 65 28 66 69 6c 65 6e 61 6d 65 29 3b 0a |free(filename);.| 00000f70 20 20 66 72 65 65 28 6a 70 65 67 29 3b 0a 7d 0a | free(jpeg);.}.| 00000f80 0a 2f 2f 20 46 75 6e 63 74 69 6f 6e 73 20 74 6f |.// Functions to| 00000f90 20 67 65 74 20 44 50 49 20 6f 66 20 74 68 65 20 | get DPI of the | 00000fa0 6d 6f 64 65 0a 23 64 65 66 69 6e 65 20 45 49 47 |mode.#define EIG| 00000fb0 5f 54 4f 5f 44 50 49 20 7b 20 73 77 69 74 63 68 |_TO_DPI { switch| 00000fc0 20 28 65 69 67 29 20 7b 20 5c 0a 20 20 20 20 20 | (eig) { \. | 00000fd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000fe0 20 20 20 63 61 73 65 20 32 3a 64 70 69 3d 34 35 | case 2:dpi=45| 00000ff0 3b 20 20 62 72 65 61 6b 3b 20 5c 0a 20 20 20 20 |; break; \. | 00001000 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00001010 20 20 20 20 63 61 73 65 20 31 3a 64 70 69 3d 39 | case 1:dpi=9| 00001020 30 3b 20 20 62 72 65 61 6b 3b 20 5c 0a 20 20 20 |0; break; \. | 00001030 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00001040 20 20 20 20 20 63 61 73 65 20 30 3a 64 70 69 3d | case 0:dpi=| 00001050 31 38 30 3b 20 62 72 65 61 6b 3b 20 7d 20 7d 0a |180; break; } }.| 00001060 69 6e 74 20 68 64 70 69 28 76 6f 69 64 29 0a 7b |int hdpi(void).{| 00001070 0a 20 20 69 6e 74 20 65 69 67 2c 6a 75 6e 6b 2c |. int eig,junk,| 00001080 64 70 69 3b 0a 20 20 73 63 72 65 65 6e 65 69 67 |dpi;. screeneig| 00001090 28 26 65 69 67 2c 26 6a 75 6e 6b 29 3b 0a 20 20 |(&eig,&junk);. | 000010a0 45 49 47 5f 54 4f 5f 44 50 49 3b 0a 20 20 72 65 |EIG_TO_DPI;. re| 000010b0 74 75 72 6e 20 64 70 69 3b 0a 7d 0a 0a 69 6e 74 |turn dpi;.}..int| 000010c0 20 76 64 70 69 28 76 6f 69 64 29 0a 7b 0a 20 20 | vdpi(void).{. | 000010d0 69 6e 74 20 65 69 67 2c 6a 75 6e 6b 2c 64 70 69 |int eig,junk,dpi| 000010e0 3b 0a 20 20 73 63 72 65 65 6e 65 69 67 28 26 6a |;. screeneig(&j| 000010f0 75 6e 6b 2c 26 65 69 67 29 3b 0a 20 20 45 49 47 |unk,&eig);. EIG| 00001100 5f 54 4f 5f 44 50 49 3b 0a 20 20 72 65 74 75 72 |_TO_DPI;. retur| 00001110 6e 20 64 70 69 3b 0a 7d 0a 0a 2f 2f 20 67 72 61 |n dpi;.}..// gra| 00001120 62 20 74 68 65 20 73 63 72 65 65 6e 20 69 6e 20 |b the screen in | 00001130 33 32 62 70 70 0a 76 6f 69 64 20 67 72 61 62 5f |32bpp.void grab_| 00001140 33 32 62 70 70 28 63 68 61 72 20 2a 73 61 64 64 |32bpp(char *sadd| 00001150 72 2c 63 68 61 72 20 2a 62 75 66 66 2c 69 6e 74 |r,char *buff,int| 00001160 20 74 61 67 2c 69 6e 74 20 78 73 69 7a 65 2c 69 | tag,int xsize,i| 00001170 6e 74 20 79 73 69 7a 65 29 0a 7b 0a 20 20 69 6e |nt ysize).{. in| 00001180 74 20 6c 69 6e 65 3b 0a 20 20 66 6f 72 20 28 6c |t line;. for (l| 00001190 69 6e 65 3d 30 3b 6c 69 6e 65 3c 79 73 69 7a 65 |ine=0;line<ysize| 000011a0 3b 6c 69 6e 65 2b 2b 29 20 7b 0a 20 20 20 20 63 |;line++) {. c| 000011b0 68 61 72 20 2a 61 64 72 20 3d 20 73 61 64 64 72 |har *adr = saddr| 000011c0 2b 28 6c 69 6e 65 2a 78 73 69 7a 65 2a 34 29 3b |+(line*xsize*4);| 000011d0 0a 20 20 20 20 69 6e 74 20 20 70 69 78 3b 0a 20 |. int pix;. | 000011e0 20 20 20 68 6f 75 72 67 6c 61 73 73 5f 70 65 72 | hourglass_per| 000011f0 63 65 6e 74 61 67 65 28 28 6c 69 6e 65 2a 31 30 |centage((line*10| 00001200 30 29 2f 79 73 69 7a 65 29 3b 0a 0a 20 20 20 20 |0)/ysize);.. | 00001210 66 6f 72 20 28 70 69 78 3d 30 3b 70 69 78 3c 78 |for (pix=0;pix<x| 00001220 73 69 7a 65 3b 70 69 78 2b 2b 29 20 7b 0a 0a 20 |size;pix++) {.. | 00001230 20 20 20 20 20 62 75 66 66 5b 28 70 69 78 2a 33 | buff[(pix*3| 00001240 29 2b 30 5d 20 3d 20 61 64 72 5b 28 70 69 78 2a |)+0] = adr[(pix*| 00001250 34 29 2b 30 5d 3b 0a 20 20 20 20 20 20 62 75 66 |4)+0];. buf| 00001260 66 5b 28 70 69 78 2a 33 29 2b 31 5d 20 3d 20 61 |f[(pix*3)+1] = a| 00001270 64 72 5b 28 70 69 78 2a 34 29 2b 31 5d 3b 0a 20 |dr[(pix*4)+1];. | 00001280 20 20 20 20 20 62 75 66 66 5b 28 70 69 78 2a 33 | buff[(pix*3| 00001290 29 2b 32 5d 20 3d 20 61 64 72 5b 28 70 69 78 2a |)+2] = adr[(pix*| 000012a0 34 29 2b 32 5d 3b 0a 20 20 20 20 7d 0a 20 20 20 |4)+2];. }. | 000012b0 20 43 4a 50 45 47 5f 57 72 69 74 65 4c 69 6e 65 | CJPEG_WriteLine| 000012c0 28 74 61 67 2c 62 75 66 66 29 3b 0a 20 20 7d 0a |(tag,buff);. }.| 000012d0 7d 0a 0a 2f 2f 20 67 72 61 62 20 74 68 65 20 73 |}..// grab the s| 000012e0 63 72 65 65 6e 20 69 6e 20 31 36 62 70 70 0a 76 |creen in 16bpp.v| 000012f0 6f 69 64 20 67 72 61 62 5f 31 36 62 70 70 28 63 |oid grab_16bpp(c| 00001300 68 61 72 20 2a 73 61 64 64 72 2c 63 68 61 72 20 |har *saddr,char | 00001310 2a 62 75 66 66 2c 69 6e 74 20 74 61 67 2c 69 6e |*buff,int tag,in| 00001320 74 20 78 73 69 7a 65 2c 69 6e 74 20 79 73 69 7a |t xsize,int ysiz| 00001330 65 29 0a 7b 0a 20 20 69 6e 74 20 6c 69 6e 65 3b |e).{. int line;| 00001340 0a 20 20 66 6f 72 20 28 6c 69 6e 65 3d 30 3b 6c |. for (line=0;l| 00001350 69 6e 65 3c 79 73 69 7a 65 3b 6c 69 6e 65 2b 2b |ine<ysize;line++| 00001360 29 20 7b 0a 20 20 20 20 63 68 61 72 20 2a 61 64 |) {. char *ad| 00001370 72 20 3d 20 73 61 64 64 72 2b 28 6c 69 6e 65 2a |r = saddr+(line*| 00001380 78 73 69 7a 65 2a 32 29 3b 0a 20 20 20 20 69 6e |xsize*2);. in| 00001390 74 20 70 69 78 3b 0a 20 20 20 20 68 6f 75 72 67 |t pix;. hourg| 000013a0 6c 61 73 73 5f 70 65 72 63 65 6e 74 61 67 65 28 |lass_percentage(| 000013b0 28 6c 69 6e 65 2a 31 30 30 29 2f 79 73 69 7a 65 |(line*100)/ysize| 000013c0 29 3b 0a 0a 20 20 20 20 66 6f 72 20 28 70 69 78 |);.. for (pix| 000013d0 3d 30 3b 70 69 78 3c 78 73 69 7a 65 3b 70 69 78 |=0;pix<xsize;pix| 000013e0 2b 2b 29 20 7b 0a 20 20 20 20 20 20 75 6e 73 69 |++) {. unsi| 000013f0 67 6e 65 64 20 77 6f 72 64 20 3d 20 61 64 72 5b |gned word = adr[| 00001400 28 70 69 78 2a 32 29 5d 20 7c 20 28 61 64 72 5b |(pix*2)] | (adr[| 00001410 28 70 69 78 2a 32 29 2b 31 5d 20 3c 3c 20 38 29 |(pix*2)+1] << 8)| 00001420 3b 0a 20 20 20 20 20 20 77 6f 72 64 20 3d 20 77 |;. word = w| 00001430 6f 72 64 20 26 20 30 78 66 66 66 66 3b 0a 20 20 |ord & 0xffff;. | 00001440 20 20 20 20 62 75 66 66 5b 28 70 69 78 2a 33 29 | buff[(pix*3)| 00001450 2b 32 5d 20 3d 20 28 77 6f 72 64 20 26 20 30 78 |+2] = (word & 0x| 00001460 37 63 30 30 29 20 3e 3e 20 37 3b 0a 20 20 20 20 |7c00) >> 7;. | 00001470 20 20 62 75 66 66 5b 28 70 69 78 2a 33 29 2b 31 | buff[(pix*3)+1| 00001480 5d 20 3d 20 28 77 6f 72 64 20 26 20 30 78 33 65 |] = (word & 0x3e| 00001490 30 29 20 3e 3e 20 32 3b 0a 20 20 20 20 20 20 62 |0) >> 2;. b| 000014a0 75 66 66 5b 28 70 69 78 2a 33 29 2b 30 5d 20 3d |uff[(pix*3)+0] =| 000014b0 20 28 77 6f 72 64 20 26 20 30 78 31 66 29 20 3c | (word & 0x1f) <| 000014c0 3c 20 33 3b 0a 20 20 20 20 7d 0a 20 20 20 20 43 |< 3;. }. C| 000014d0 4a 50 45 47 5f 57 72 69 74 65 4c 69 6e 65 28 74 |JPEG_WriteLine(t| 000014e0 61 67 2c 62 75 66 66 29 3b 0a 20 20 7d 0a 7d 0a |ag,buff);. }.}.| 000014f0 0a 2f 2f 20 67 72 61 62 20 74 68 65 20 73 63 72 |.// grab the scr| 00001500 65 65 6e 20 69 6e 20 38 70 70 0a 76 6f 69 64 20 |een in 8pp.void | 00001510 67 72 61 62 5f 38 62 70 70 0a 20 20 20 20 20 20 |grab_8bpp. | 00001520 20 20 20 20 28 63 68 61 72 20 2a 73 61 64 64 72 | (char *saddr| 00001530 2c 63 68 61 72 20 2a 62 75 66 66 2c 69 6e 74 20 |,char *buff,int | 00001540 2a 70 61 6c 65 74 74 65 2c 69 6e 74 20 74 61 67 |*palette,int tag| 00001550 2c 69 6e 74 20 78 73 69 7a 65 2c 69 6e 74 20 79 |,int xsize,int y| 00001560 73 69 7a 65 29 0a 7b 0a 20 20 69 6e 74 20 6c 69 |size).{. int li| 00001570 6e 65 3b 0a 20 20 66 6f 72 20 28 6c 69 6e 65 3d |ne;. for (line=| 00001580 30 3b 6c 69 6e 65 3c 79 73 69 7a 65 3b 6c 69 6e |0;line<ysize;lin| 00001590 65 2b 2b 29 20 7b 0a 20 20 20 20 63 68 61 72 20 |e++) {. char | 000015a0 2a 61 64 72 20 3d 20 73 61 64 64 72 2b 28 6c 69 |*adr = saddr+(li| 000015b0 6e 65 2a 78 73 69 7a 65 29 3b 0a 20 20 20 20 69 |ne*xsize);. i| 000015c0 6e 74 20 70 69 78 3b 0a 20 20 20 20 68 6f 75 72 |nt pix;. hour| 000015d0 67 6c 61 73 73 5f 70 65 72 63 65 6e 74 61 67 65 |glass_percentage| 000015e0 28 28 6c 69 6e 65 2a 31 30 30 29 2f 79 73 69 7a |((line*100)/ysiz| 000015f0 65 29 3b 0a 0a 20 20 20 20 66 6f 72 20 28 70 69 |e);.. for (pi| 00001600 78 3d 30 3b 70 69 78 3c 78 73 69 7a 65 3b 70 69 |x=0;pix<xsize;pi| 00001610 78 2b 2b 29 20 7b 0a 20 20 20 20 20 20 63 68 61 |x++) {. cha| 00001620 72 20 70 20 3d 20 61 64 72 5b 70 69 78 5d 3b 0a |r p = adr[pix];.| 00001630 20 20 20 20 20 20 62 75 66 66 5b 28 70 69 78 2a | buff[(pix*| 00001640 33 29 2b 30 5d 20 3d 20 28 28 63 68 61 72 20 2a |3)+0] = ((char *| 00001650 29 70 61 6c 65 74 74 65 29 5b 28 70 2a 34 29 2b |)palette)[(p*4)+| 00001660 31 5d 3b 0a 20 20 20 20 20 20 62 75 66 66 5b 28 |1];. buff[(| 00001670 70 69 78 2a 33 29 2b 31 5d 20 3d 20 28 28 63 68 |pix*3)+1] = ((ch| 00001680 61 72 20 2a 29 70 61 6c 65 74 74 65 29 5b 28 70 |ar *)palette)[(p| 00001690 2a 34 29 2b 32 5d 3b 0a 20 20 20 20 20 20 62 75 |*4)+2];. bu| 000016a0 66 66 5b 28 70 69 78 2a 33 29 2b 32 5d 20 3d 20 |ff[(pix*3)+2] = | 000016b0 28 28 63 68 61 72 20 2a 29 70 61 6c 65 74 74 65 |((char *)palette| 000016c0 29 5b 28 70 2a 34 29 2b 33 5d 3b 0a 20 20 20 20 |)[(p*4)+3];. | 000016d0 7d 0a 20 20 20 20 43 4a 50 45 47 5f 57 72 69 74 |}. CJPEG_Writ| 000016e0 65 4c 69 6e 65 28 74 61 67 2c 62 75 66 66 29 3b |eLine(tag,buff);| 000016f0 0a 20 20 7d 0a 7d 0a 0a 2f 2f 20 67 72 61 62 20 |. }.}..// grab | 00001700 74 68 65 20 73 63 72 65 65 6e 20 69 6e 20 34 70 |the screen in 4p| 00001710 70 0a 76 6f 69 64 20 67 72 61 62 5f 34 62 70 70 |p.void grab_4bpp| 00001720 0a 20 20 20 20 20 20 20 20 20 20 28 63 68 61 72 |. (char| 00001730 20 2a 73 61 64 64 72 2c 63 68 61 72 20 2a 62 75 | *saddr,char *bu| 00001740 66 66 2c 69 6e 74 20 2a 70 61 6c 65 74 74 65 2c |ff,int *palette,| 00001750 69 6e 74 20 74 61 67 2c 69 6e 74 20 78 73 69 7a |int tag,int xsiz| 00001760 65 2c 69 6e 74 20 79 73 69 7a 65 29 0a 7b 0a 20 |e,int ysize).{. | 00001770 20 69 6e 74 20 6c 69 6e 65 3b 0a 20 20 66 6f 72 | int line;. for| 00001780 20 28 6c 69 6e 65 3d 30 3b 6c 69 6e 65 3c 79 73 | (line=0;line<ys| 00001790 69 7a 65 3b 6c 69 6e 65 2b 2b 29 20 7b 0a 20 20 |ize;line++) {. | 000017a0 20 20 63 68 61 72 20 2a 61 64 72 20 3d 20 73 61 | char *adr = sa| 000017b0 64 64 72 2b 28 6c 69 6e 65 2a 28 78 73 69 7a 65 |ddr+(line*(xsize| 000017c0 2f 32 29 29 3b 0a 20 20 20 20 69 6e 74 20 70 69 |/2));. int pi| 000017d0 78 3b 0a 20 20 20 20 68 6f 75 72 67 6c 61 73 73 |x;. hourglass| 000017e0 5f 70 65 72 63 65 6e 74 61 67 65 28 28 6c 69 6e |_percentage((lin| 000017f0 65 2a 31 30 30 29 2f 79 73 69 7a 65 29 3b 0a 0a |e*100)/ysize);..| 00001800 20 20 20 20 66 6f 72 20 28 70 69 78 3d 30 3b 70 | for (pix=0;p| 00001810 69 78 3c 78 73 69 7a 65 3b 70 69 78 2b 2b 29 20 |ix<xsize;pix++) | 00001820 7b 0a 20 20 20 20 20 20 63 68 61 72 20 70 3b 0a |{. char p;.| 00001830 20 20 20 20 20 20 69 66 20 28 28 70 69 78 20 25 | if ((pix %| 00001840 20 32 29 20 3d 3d 20 30 29 20 70 20 3d 20 20 61 | 2) == 0) p = a| 00001850 64 72 5b 70 69 78 2f 32 5d 20 20 20 20 20 26 20 |dr[pix/2] & | 00001860 30 78 66 3b 0a 20 20 20 20 20 20 69 66 20 28 28 |0xf;. if ((| 00001870 70 69 78 20 25 20 32 29 20 3d 3d 20 31 29 20 70 |pix % 2) == 1) p| 00001880 20 3d 20 28 61 64 72 5b 28 70 69 78 2d 31 29 2f | = (adr[(pix-1)/| 00001890 32 5d 20 26 20 30 78 66 30 29 20 3e 3e 20 34 3b |2] & 0xf0) >> 4;| 000018a0 0a 0a 20 20 20 20 20 20 62 75 66 66 5b 28 70 69 |.. buff[(pi| 000018b0 78 2a 33 29 2b 30 5d 20 3d 20 28 28 63 68 61 72 |x*3)+0] = ((char| 000018c0 20 2a 29 70 61 6c 65 74 74 65 29 5b 28 70 2a 34 | *)palette)[(p*4| 000018d0 29 2b 31 5d 3b 0a 20 20 20 20 20 20 62 75 66 66 |)+1];. buff| 000018e0 5b 28 70 69 78 2a 33 29 2b 31 5d 20 3d 20 28 28 |[(pix*3)+1] = ((| 000018f0 63 68 61 72 20 2a 29 70 61 6c 65 74 74 65 29 5b |char *)palette)[| 00001900 28 70 2a 34 29 2b 32 5d 3b 0a 20 20 20 20 20 20 |(p*4)+2];. | 00001910 62 75 66 66 5b 28 70 69 78 2a 33 29 2b 32 5d 20 |buff[(pix*3)+2] | 00001920 3d 20 28 28 63 68 61 72 20 2a 29 70 61 6c 65 74 |= ((char *)palet| 00001930 74 65 29 5b 28 70 2a 34 29 2b 33 5d 3b 0a 20 20 |te)[(p*4)+3];. | 00001940 20 20 7d 0a 20 20 20 20 43 4a 50 45 47 5f 57 72 | }. CJPEG_Wr| 00001950 69 74 65 4c 69 6e 65 28 74 61 67 2c 62 75 66 66 |iteLine(tag,buff| 00001960 29 3b 0a 20 20 7d 0a 7d 0a |);. }.}.| 00001969