1 /* frames.c --
2
3 This file is part of the lzop file compressor.
4
5 Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
6 All Rights Reserved.
7
8 lzop and the LZO library are free software; you can redistribute them
9 and/or modify them under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzop/
26 */
27
28
29 #include "conf.h"
30
31 #if defined(USE_FRAMES)
32
33 #include "screen.h"
34
35
36 /*************************************************************************
37 //
38 **************************************************************************/
39
recolor_line(screen_t * screen,int frame,int line,lzo_bytep f,int len,int cy,int col)40 static void recolor_line(screen_t *screen, int frame, int line,
41 lzo_bytep f, int len, int cy, int col)
42 {
43 unsigned char colmap[4];
44 int k;
45
46 UNUSED(screen);
47 UNUSED(frame);
48 UNUSED(line);
49 UNUSED(f);
50 UNUSED(len);
51 UNUSED(cy);
52
53 colmap[0] = 0; /* black background */
54 if (col <= 0x333)
55 {
56 /* palette */
57 static const unsigned char pal[4] = { 0x2, 0x3, 0x5, 0x5 };
58 colmap[1] = pal[ (col >> 8) & 3 ];
59 colmap[2] = pal[ (col >> 4) & 3 ];
60 colmap[3] = pal[ (col >> 0) & 3 ];
61 }
62 else
63 {
64 /* direct colors */
65 colmap[1] = (col >> 16) & 0x07;
66 colmap[2] = (col >> 8) & 0x07;
67 colmap[3] = (col >> 0) & 0x07;
68 }
69
70 #if 0
71 for (k = 0; k < len; k += 2)
72 if (f[k+1] != 0)
73 {
74 if (f[k] != ' ')
75 f[k] = '.';
76 f[k+1] = 0x10;
77 }
78 else
79 assert(f[k] == ' ');
80 #endif
81
82 #if 1
83 for (k = 0; k < len; k += 2)
84 {
85 lzo_bytep p = &f[k+1];
86 if (*p != 0)
87 *p = (colmap[ (*p >> 4) & 3 ] << 4) | colmap[ *p & 3 ];
88 }
89 #endif
90
91 #if 0
92 f[0*2+0] = f[77*2+0] = line / 10 + '0';
93 f[0*2+1] = f[77*2+1] = 0x07;
94 f[1*2+0] = f[78*2+0] = line % 10 + '0';
95 f[1*2+1] = f[78*2+1] = 0x07;
96 #if 1
97 if (line == 18 - 1)
98 {
99 char s[2*80+1];
100 int y = cy - 4;
101
102 sprintf(s," %2d: %2d %2d ", frame, 0, 0);
103 screen->putStringAttr(screen,s,0x70,33,y+1);
104 for (k = 0; k < 79; k++)
105 {
106 screen->putCharAttr(screen,k%10+'0',k%10==0?0x06:0x07,k,y+3);
107 screen->putCharAttr(screen,k%10+'0',k%10==0?0x06:0x07,k,y+3+18+1);
108 }
109 #if 1
110 usleep(200*1000);
111 #else
112 while (!screen->kbhit(screen))
113 ;
114 while (screen->kbhit(screen))
115 if (getch() == 27)
116 exit(0);
117 #endif
118 }
119 #endif
120 #endif
121 }
122
123
random_color(void)124 static int random_color(void)
125 {
126 static const short c[6] = { 0x012, 0x021, 0x102, 0x120, 0x201, 0x210 };
127 int t;
128 lzo_uint32 seed;
129
130 seed = time(NULL);
131 #if 0
132 seed = seed * 69069L + 5;
133 t = (int)(seed >> 16) % 50;
134 #else
135 seed = seed * 0x015a4e35L + 1;
136 t = (int)(seed >> 16) % 50;
137 #endif
138 return (t < 6 ? c[t] : 0x333);
139 }
140
141
142 /*************************************************************************
143 //
144 **************************************************************************/
145
146 #include "frames.h"
147
screen_show_frames(screen_t * screen)148 void screen_show_frames(screen_t *screen)
149 {
150 int i, j, k;
151 lzo_uint out_len = UNCOMPRESSED_SIZE;
152 lzo_bytep frames = NULL;
153 lzo_bytep frames_mem = NULL;
154 int c_cx, c_cy;
155 const int len = 79 * 2; /* size of one line */
156 const int nframes = 19; /* number of frames */
157 const int lines = 18; /* intro */
158 const int total_lines = 24; /* head + help */
159 lzo_bool hit = 0;
160 int col;
161 lzo_uint32 c;
162
163 assert(acc_isatty(STDIN_FILENO));
164 assert(out_len == (lzo_uint) (lines * len * nframes));
165
166 #if 0
167 c = lzo_adler32(ADLER32_INIT_VALUE,compressed_frames,COMPRESSED_SIZE);
168 if (c != COMPRESSED_ADLER32)
169 exit(EXIT_ERROR);
170 #endif
171
172 frames = frames_mem = (lzo_bytep) malloc(UNCOMPRESSED_SIZE + 3);
173 if (frames == NULL)
174 return;
175
176 if ((lzo1x_decompress_safe(compressed_frames,COMPRESSED_SIZE,
177 frames,&out_len,NULL) != LZO_E_OK)
178 || (out_len != UNCOMPRESSED_SIZE))
179 exit(EXIT_ERROR);
180 #if 0
181 c = lzo_adler32(ADLER32_INIT_VALUE,frames,UNCOMPRESSED_SIZE);
182 if (c != UNCOMPRESSED_ADLER32)
183 exit(EXIT_ERROR);
184 #endif
185
186 screen->getCursor(screen,&c_cx,&c_cy);
187 c_cy += total_lines;
188 if (c_cy >= screen->getRows(screen))
189 c_cy -= screen->scrollUp(screen,c_cy-screen->getRows(screen)+1);
190 c_cy -= total_lines;
191 if (c_cy < 0)
192 c_cy = 0;
193 c_cx = 0;
194 screen->setCursor(screen,c_cx,c_cy);
195 #if 1
196 for (k = 0; k < 4; k++)
197 screen->clearLine(screen,c_cy+k);
198 #endif
199 head();
200 screen->getCursor(screen,&c_cx,&c_cy);
201 #if 1
202 for (k = 0; k < lines; k++)
203 screen->clearLine(screen,c_cy+k);
204 #endif
205 screen->refresh(screen);
206
207 col = random_color();
208 for (i = 0; i < nframes && !hit; i++)
209 {
210 for (j = 0; j < lines; j++)
211 {
212 recolor_line(screen,i,j,frames,len,c_cy,col);
213 screen->updateLineN(screen,frames,c_cy+j,len);
214 frames += len;
215 }
216 screen->refresh(screen);
217
218 if (i == 0)
219 {
220 for (j = 0; !(hit = screen->kbhit(screen)) && j < 10; j++)
221 usleep(120*1000);
222 }
223 else
224 {
225 if (!(hit = screen->kbhit(screen)))
226 usleep(60*1000);
227 }
228 }
229
230 free(frames_mem);
231
232 for (k = 0; k < lines; k++)
233 screen->clearLine(screen,c_cy+k);
234 screen->refresh(screen);
235 help();
236
237 UNUSED(c);
238 }
239
240
241 #endif /* USE_FRAMES */
242
243
244 /* vim:set ts=4 sw=4 et: */
245