1 /*
2 * xvdflt.c - load routine for 'default' XV image
3 *
4 * LoadDfltPic() - loads up 'pic' note: can't fail(!)
5 */
6
7 #include "copyright.h"
8
9 #include "xv.h"
10
11 #include "bits/logo_top"
12 #include "bits/logo_bot"
13 #include "bits/logo_out"
14 #include "bits/xv_jhb"
15 #include "bits/xv_cpyrt"
16 #include "bits/xv_rev"
17 #include "bits/xv_ver"
18 #include "bits/xf_left"
19 /* #include "bits/xf_right" not used */
20 #include "bits/font5x9.h"
21
22
23 #ifndef USEOLDPIC
24 # include "xvdflt.h"
25 #endif
26
27
28
29 #define DWIDE 480
30 #define DHIGH 270
31
32 static void loadOldDfltPic PARM((PICINFO *));
33 static void setcolor PARM((PICINFO *, int, int, int, int));
34 static void gen_bg PARM((byte *, PICINFO *));
35
36
37 /*******************************************/
LoadDfltPic(pinfo)38 void LoadDfltPic(pinfo)
39 PICINFO *pinfo;
40 {
41 char str[256];
42 byte *dfltpic;
43 int i, j, k, xdpline, nbytes;
44
45 #ifdef USEOLDPIC
46
47 loadOldDfltPic(pinfo);
48
49 #else /* !USEOLDPIC */
50
51 if (!ncols) {
52 loadOldDfltPic(pinfo);
53 return;
54 }
55
56 dfltpic = (byte *) calloc((size_t) XVDFLT_WIDE * XVDFLT_HIGH, (size_t) 1);
57 if (!dfltpic) FatalError("couldn't malloc 'dfltpic' in LoadDfltPic()");
58
59
60 /* copy image from xvdflt_pic[] array */
61 xdpline = 0;
62 for (i=0; i<XVDFLT_HIGH; i++) {
63 nbytes = 0;
64 while (nbytes < XVDFLT_WIDE) {
65 const char *sp;
66 byte *dp;
67
68 j = XVDFLT_WIDE - nbytes;
69 if (j > XVDFLT_PARTLEN) j = XVDFLT_PARTLEN;
70
71 sp = xvdflt_pic[xdpline];
72 dp = dfltpic + i*XVDFLT_WIDE + nbytes;
73 for (k=0; k<j; k++) {
74 int c1,c2;
75 c1 = *sp++; c2 = *sp++;
76 if (c1>='a') c1 = 10+(c1-'a');
77 else c1 = c1-'0';
78
79 if (c2>='a') c2 = 10+(c2-'a');
80 else c2 = c2-'0';
81
82 *dp++ = (byte) ((c1<<4) | c2);
83 }
84
85 nbytes += j;
86 xdpline++;
87 }
88 }
89
90 /* load up colormaps */
91 for (i=0; i<256; i++) {
92 pinfo->r[i] = xvdflt_r[i];
93 pinfo->g[i] = xvdflt_g[i];
94 pinfo->b[i] = xvdflt_b[i];
95 }
96
97
98 setcolor(pinfo, 250, 248,184,120); /* revdate */
99 setcolor(pinfo, 251, 255,255,255); /* regstr */
100 setcolor(pinfo, 252, 0, 0, 0); /* black background for text */
101
102
103 xbm2pic((byte *) xv_cpyrt_bits, xv_cpyrt_width, xv_cpyrt_height,
104 dfltpic, DWIDE, DHIGH, DWIDE/2+1, 203+1, 252);
105 xbm2pic((byte *) xv_cpyrt_bits, xv_cpyrt_width, xv_cpyrt_height,
106 dfltpic, DWIDE, DHIGH, DWIDE/2, 203, 250);
107
108 i = xv_ver_width + xv_rev_width + 30;
109
110 xbm2pic((byte *) xv_ver_bits, xv_ver_width, xv_ver_height,
111 dfltpic, DWIDE, DHIGH, DWIDE/2 - (i/2) + xv_ver_width/2+1, 220+1,252);
112 xbm2pic((byte *) xv_rev_bits, xv_rev_width, xv_rev_height,
113 dfltpic, DWIDE, DHIGH, DWIDE/2 + (i/2) - xv_rev_width/2+1, 220+1,252);
114
115 xbm2pic((byte *) xv_ver_bits, xv_ver_width, xv_ver_height,
116 dfltpic, DWIDE, DHIGH, DWIDE/2 - (i/2) + xv_ver_width/2, 220, 250);
117 xbm2pic((byte *) xv_rev_bits, xv_rev_width, xv_rev_height,
118 dfltpic, DWIDE, DHIGH, DWIDE/2 + (i/2) - xv_rev_width/2, 220, 250);
119
120 strcpy(str,"Press <right> mouse button for menu.");
121 DrawStr2Pic(str, DWIDE/2+1, 241+1, dfltpic, DWIDE, DHIGH, 252);
122 DrawStr2Pic(str, DWIDE/2, 241, dfltpic, DWIDE, DHIGH, 250);
123
124
125 #ifdef REGSTR
126 strcpy(str,REGSTR);
127 #else
128 strcpy(str,"UNREGISTERED COPY: See 'About XV' for registration info.");
129 #endif
130
131 DrawStr2Pic(str, DWIDE/2+1, 258+1, dfltpic, DWIDE, DHIGH, 252);
132 DrawStr2Pic(str, DWIDE/2, 258, dfltpic, DWIDE, DHIGH, 251);
133
134
135 pinfo->pic = dfltpic;
136 pinfo->w = XVDFLT_WIDE;
137 pinfo->h = XVDFLT_HIGH;
138 pinfo->type = PIC8;
139 #ifdef HAVE_PNG
140 pinfo->frmType = F_PNG;
141 #else
142 pinfo->frmType = F_GIF;
143 #endif
144 pinfo->colType = F_FULLCOLOR;
145
146 pinfo->normw = pinfo->w;
147 pinfo->normh = pinfo->h;
148
149 sprintf(pinfo->fullInfo, "<8-bit internal>");
150 sprintf(pinfo->shrtInfo, "%dx%d image.", XVDFLT_WIDE, XVDFLT_HIGH);
151 pinfo->comment = (char *) NULL;
152
153 #endif /* !USEOLDPIC */
154 }
155
156
157
158 /*******************************************/
loadOldDfltPic(pinfo)159 static void loadOldDfltPic(pinfo)
160 PICINFO *pinfo;
161 {
162 /* load up the stuff XV expects us to load up */
163
164 char str[256];
165 byte *dfltpic;
166 int i, j, k;
167
168 dfltpic = (byte *) calloc((size_t) DWIDE * DHIGH, (size_t) 1);
169 if (!dfltpic) FatalError("couldn't malloc 'dfltpic' in LoadDfltPic()");
170
171
172 if (ncols) { /* draw fish texture */
173 for (i=k=0; i<DHIGH; i+=xf_left_height) {
174 for (j=0; j<DWIDE; j+=xf_left_width) {
175 k++;
176 if (k&1)
177 xbm2pic((byte *) xf_left_bits, xf_left_width, xf_left_height,
178 dfltpic, DWIDE, DHIGH, j + xf_left_width/2,
179 i + xf_left_height/2, 1);
180 }
181 }
182 }
183
184
185
186 xbm2pic((byte *) xvpic_logo_out_bits, xvpic_logo_out_width,
187 xvpic_logo_out_height, dfltpic, DWIDE, DHIGH, DWIDE/2 + 10, 80, 103);
188
189 xbm2pic((byte *) xvpic_logo_top_bits, xvpic_logo_top_width,
190 xvpic_logo_top_height, dfltpic, DWIDE, DHIGH, DWIDE/2 + 10, 80, 100);
191
192 xbm2pic((byte *) xvpic_logo_bot_bits, xvpic_logo_bot_width,
193 xvpic_logo_bot_height, dfltpic, DWIDE, DHIGH, DWIDE/2 + 10, 80, 101);
194
195
196
197 xbm2pic((byte *) xv_jhb_bits, xv_jhb_width, xv_jhb_height,
198 dfltpic, DWIDE, DHIGH, DWIDE/2, 160, 102);
199
200 xbm2pic((byte *) xv_cpyrt_bits, xv_cpyrt_width, xv_cpyrt_height,
201 dfltpic, DWIDE, DHIGH, DWIDE/2, 203, 102);
202
203 i = xv_ver_width + xv_rev_width + 30;
204
205 xbm2pic((byte *) xv_ver_bits, xv_ver_width, xv_ver_height,
206 dfltpic, DWIDE, DHIGH, DWIDE/2 - (i/2) + xv_ver_width/2, 220, 102);
207
208 xbm2pic((byte *) xv_rev_bits, xv_rev_width, xv_rev_height,
209 dfltpic, DWIDE, DHIGH, DWIDE/2 + (i/2) - xv_rev_width/2, 220, 102);
210
211 strcpy(str,"Press <right> mouse button for menu.");
212 DrawStr2Pic(str, DWIDE/2, 241, dfltpic, DWIDE, DHIGH, 102);
213
214 strcpy(str,"UNREGISTERED COPY: See 'About XV' for registration info.");
215
216 #ifdef REGSTR
217 strcpy(str,REGSTR);
218 #endif
219
220 DrawStr2Pic(str, DWIDE/2, 258, dfltpic, DWIDE, DHIGH, 104);
221
222 setcolor(pinfo, 0, 225, 150, 255); /* top-left fish color */
223 setcolor(pinfo, 15, 55, 0, 77); /* bot-right fish color */
224 setcolor(pinfo, 16, 150, 150, 255); /* top-left background color */
225 setcolor(pinfo, 63, 0, 0, 77); /* bottom-right background color */
226
227 if (ncols) gen_bg(dfltpic, pinfo);
228
229 /* set up colormap */
230 setcolor(pinfo, 100, 255,213, 25); /* XV top half */
231 setcolor(pinfo, 101, 255,000,000); /* XV bottom half */
232 setcolor(pinfo, 102, 255,208,000); /* jhb + fish + revdate */
233 setcolor(pinfo, 103, 220,220,220); /* XV backlighting */
234 setcolor(pinfo, 104, 255,255,255); /* registration string */
235
236 if (ncols==0) {
237 setcolor(pinfo, 0, 0, 0, 0);
238 setcolor(pinfo, 102,255,255,255);
239 setcolor(pinfo, 103,255,255,255);
240 setcolor(pinfo, 104,255,255,255);
241 }
242
243 pinfo->pic = dfltpic;
244 pinfo->w = DWIDE;
245 pinfo->h = DHIGH;
246 pinfo->type = PIC8;
247 #ifdef HAVE_PNG
248 pinfo->frmType = F_PNG;
249 #else
250 pinfo->frmType = F_GIF;
251 #endif
252 pinfo->colType = F_FULLCOLOR;
253
254 sprintf(pinfo->fullInfo, "<8-bit internal>");
255 sprintf(pinfo->shrtInfo, "%dx%d image.",DWIDE, DHIGH);
256 pinfo->comment = (char *) NULL;
257 }
258
259
260
261 /*******************************************/
xbm2pic(bits,bwide,bhigh,pic,pwide,phigh,cx,cy,col)262 void xbm2pic(bits, bwide, bhigh, pic, pwide, phigh, cx, cy, col)
263 byte *bits;
264 byte *pic;
265 int bwide, bhigh, pwide, phigh, cx, cy, col;
266 /*******************************************/
267 {
268 /* draws an X bitmap into an 8-bit 'pic'. Only '1' bits from the bitmap
269 are drawn (in color 'col'). '0' bits are ignored */
270
271 int i, j, k, bit, x, y;
272 byte *pptr, *bptr;
273
274 y = cy - bhigh/2;
275
276 for (i=0; i<bhigh; i++,y++) {
277 if ( (y>=0) && (y<phigh) ) {
278 pptr = pic + y * pwide;
279 bptr = (byte *) bits + i * ((bwide+7)/8);
280 x = cx - bwide/2;
281
282 k = *bptr;
283 for (j=0,bit=0; j<bwide; j++, bit = (bit+1)&7, x++) {
284 if (!bit) k = *bptr++;
285 if ( (k&1) && (x>=0) && (x<pwide))
286 pptr[x] = col;
287
288 k = k >> 1;
289 }
290 }
291 }
292 }
293
294
295 /*******************************************/
setcolor(pinfo,i,rv,gv,bv)296 static void setcolor(pinfo, i, rv, gv, bv)
297 PICINFO *pinfo;
298 int i, rv, gv, bv;
299 {
300 pinfo->r[i] = rv;
301 pinfo->g[i] = gv;
302 pinfo->b[i] = bv;
303 }
304
305
306 /*******************************************/
gen_bg(dfltpic,pinfo)307 static void gen_bg(dfltpic, pinfo)
308 byte *dfltpic;
309 PICINFO *pinfo;
310 {
311 int i,j, dr, dg, db;
312 byte *pp;
313
314 pp = dfltpic;
315 for (i=0; i<DHIGH; i++)
316 for (j=0; j<DWIDE; j++, pp++) {
317 if (*pp == 0) {
318 *pp = 16 + ((i+j) * 48) / (DHIGH + DWIDE);
319 }
320 else if (*pp == 1) {
321 *pp = ((i+j) * 16) / (DHIGH + DWIDE);
322 }
323 }
324
325
326 /* color gradient in cells 0-15 */
327 for (i=1; i<15; i++) {
328 dr = (int) pinfo->r[15] - (int) pinfo->r[0];
329 dg = (int) pinfo->g[15] - (int) pinfo->g[0];
330 db = (int) pinfo->b[15] - (int) pinfo->b[0];
331
332 setcolor(pinfo, i, (int) pinfo->r[0] + (dr * i) / 15,
333 (int) pinfo->g[0] + (dg * i) / 15,
334 (int) pinfo->b[0] + (db * i) / 15);
335 }
336
337 /* color gradient in cells 16-63 */
338 for (i=17, j=1; i<63; i++,j++) {
339 dr = (int) pinfo->r[63] - (int) pinfo->r[16];
340 dg = (int) pinfo->g[63] - (int) pinfo->g[16];
341 db = (int) pinfo->b[63] - (int) pinfo->b[16];
342
343 setcolor(pinfo, i, (int) pinfo->r[16] + (dr * j)/47,
344 (int) pinfo->g[16] + (dg * j)/47,
345 (int) pinfo->b[16] + (db * j)/47);
346 }
347 }
348
349
350
351 /*******************************************/
DrawStr2Pic(str,cx,cy,pic,pw,ph,col)352 void DrawStr2Pic(str, cx, cy, pic, pw, ph, col)
353 char *str;
354 byte *pic;
355 int cx, cy, pw, ph, col;
356 {
357 /* draw string (in 5x9 font) centered around cx,cy, in color 'col' */
358
359 int i;
360
361 i = strlen(str);
362 if (!i) return;
363
364 cx -= ((i-1) * 3);
365
366 for ( ; *str; str++, cx+=6) {
367 i = (byte) *str;
368 if (i >= 32 && i < 128)
369 xbm2pic(font5x9[i - 32], 5, 9, pic, pw, ph, cx, cy, col);
370 }
371 }
372