1 /*************************************************************************
\r
5 Demonstrates RLE encoding to file QUICK and DIRTY
\r
6 **************************************************************************/
\r
17 #include "xvbitmap.h"
\r
18 #include "xbmtools.h"
\r
21 #include "xrletool.h"
\r
22 #include "xfileio.h"
\r
23 /* Macro to make pointer parameters model independent */
\r
24 #define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))
\r
28 /* | . | . | . | . */
\r
29 8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
\r
30 8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
\r
31 8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
\r
32 8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
\r
33 8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
\r
34 8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
\r
35 0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
\r
36 0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
\r
37 0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
\r
38 0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
\r
39 0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 2, 2, 2, 2, 0, 0,
\r
40 0, 0, 0, 4, 4, 4, 0, 4, 4, 0, 4, 4, 0, 4,14, 2, 2, 2, 0, 0,
\r
41 0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 0, 2, 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 0, 0, 0, 0, 0, 0,
\r
58 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
\r
66 void error(char * string){
\r
68 printf("%s\n",string);
\r
72 void load_user_fonts(){
\r
75 f=fopen("var6x8.fnt","rb");
\r
76 newfnt = farmalloc(256*16+4);
\r
77 for (i=0;i<256*16+4;i++){
\r
83 x_register_userfont(newfnt);
\r
88 int i,j,handle,size,comp_size;
\r
89 char far * tempbuff,far * diskbuff;
\r
91 pbm = farmalloc(20 * 30 + 2);
\r
92 x_bm_to_pbm( MK_FP(FP_SEG(turtle),FP_OFF(turtle)), pbm);
\r
94 x_set_mode(X_MODE_360x240,360);
\r
97 x_bgprintf(0,0,0,14,0,
\r
98 "This is a demo of RLE compression of 360x240 video screen to ");
\r
99 x_bgprintf(0,8,0,14,0,
\r
100 "disk. Uncompressed, this screen requires a file of size ");
\r
101 x_bgprintf(0,16,0,14,0,"86400 (360x240) bytes.");
\r
102 x_bgprintf(0,48,0,14,0,
\r
103 "Press a key to draw the image and save it to screen:");
\r
106 x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
\r
108 for (j=0;j<(ScrnPhysicalHeight/30);j++)
\r
109 for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
\r
110 x_put_masked_pbm(i*20, j*30, 0, pbm);
\r
112 x_set_start_addr(0,240);
\r
114 x_bgprintf(0,0,240*90,14,0,
\r
115 "Now compressing and writing to file 'screen.dat'.");
\r
116 x_bgprintf(0,8,240*90,14,0,"Please wait... ");
\r
119 if((handle=f_open("screen.dat",F_WRONLY))==FILE_ERR)
\r
120 error("Unable to open 'screen.dat' for writing.");
\r
122 tempbuff=farmalloc(90*240);
\r
123 diskbuff=farmalloc(90*240);
\r
124 buffsize=(int far *)farmalloc(2);
\r
127 x_select_default_plane(i);
\r
128 if (!(j=x_buff_RLEncode(MK_FP(0xA000,0),tempbuff,90*240)))
\r
129 error("Error buff compressing");
\r
131 f_writefar(handle,(char far *)buffsize,2);
\r
132 f_writefar(handle,tempbuff,j);
\r
138 if((handle=f_open("screen.raw",F_WRONLY))==FILE_ERR)
\r
139 error("Unable to open 'screen.dat' for writing.");
\r
141 x_select_default_plane(i);
\r
142 f_writefar(handle,MK_FP(0xA000,0),90*240);
\r
146 x_bgprintf(0,8,240*90,14,0,"Done. Press a key to restore.");
\r
149 x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
\r
150 x_set_start_addr(0,0);
\r
152 if((handle=f_open("screen.dat",F_RDONLY))==FILE_ERR)
\r
153 error("Unable to open 'screen.dat' for reading.");
\r
157 x_select_default_plane(i);
\r
158 f_readfar(handle,(char far *)buffsize,2);
\r
159 f_readfar(handle,diskbuff,*buffsize);
\r
160 j=x_buff_RLDecode(diskbuff,MK_FP(0xA000,0));
\r
167 printf("screen size = 86400 compressed = %u",comp_size);
\r