1 /* SCCS Id: @(#)jtp_gra.c 3.0 2000/11/12 */
2 /* Copyright (c) Jaakko Peltonen, 2000 */
3 /* NetHack may be freely redistributed. See license for details. */
4
5 #ifndef _jtp_gra_c_
6 #define _jtp_gra_c_
7
8 #include "jtp_def.h"
9 #include <stdlib.h>
10 #include <string.h>
11 #include <time.h>
12 #ifdef USE_DIRECTX_SYSCALLS
13 #include "jtp_dirx.h"
14 #endif
15 #ifdef USE_DOS_SYSCALLS
16 #include "jtp_dos.h"
17 #endif
18 #include "jtp_gen.h"
19 #include "jtp_gra.h"
20
21 unsigned char jtp_colors[256][3];
22 jtp_screen_t jtp_screen;
23 double jtp_gamma_correction = 1.0;
24
25 /*-----------------------------------------
26 Interface to system dependent functions
27 -----------------------------------------*/
jtp_enter_graphics_mode()28 void jtp_enter_graphics_mode()
29 {
30 #ifdef USE_DIRECTX_SYSCALLS
31 jtp_DXEnterGraphicsMode(&jtp_screen);
32 #endif
33 #ifdef USE_DOS_SYSCALLS
34 jtp_DOSEnterGraphicsMode(&jtp_screen);
35 #endif
36 #ifdef USE_SDL_SYSCALLS
37 jtp_SDLEnterGraphicsMode(&jtp_screen);
38 #endif
39 }
40
jtp_exit_graphics_mode()41 void jtp_exit_graphics_mode()
42 {
43 #ifdef USE_DIRECTX_SYSCALLS
44 jtp_DXExitGraphicsMode(&jtp_screen);
45 #endif
46 #ifdef USE_DOS_SYSCALLS
47 jtp_DOSExitGraphicsMode(&jtp_screen);
48 #endif
49 #ifdef USE_SDL_SYSCALLS
50 jtp_SDLExitGraphicsMode(&jtp_screen);
51 #endif
52 }
53
jtp_palch(unsigned char cindex,unsigned char r,unsigned char g,unsigned char b)54 void jtp_palch
55 (
56 unsigned char cindex,
57 unsigned char r,
58 unsigned char g,
59 unsigned char b
60 )
61 {
62 #ifdef USE_DIRECTX_SYSCALLS
63 jtp_DXRecordColor(cindex, r, g, b);
64 jtp_DXSetPalette();
65 #endif
66 #ifdef USE_DOS_SYSCALLS
67 jtp_DOSSetColor(cindex, r, g, b);
68 #endif
69 #ifdef USE_SDL_SYSCALLS
70 jtp_SDLRecordColor(cindex, r, g, b);
71 jtp_SDLSetPalette();
72 #endif
73 }
74
jtp_refresh()75 void jtp_refresh()
76 {
77 #ifdef USE_DIRECTX_SYSCALLS
78 jtp_DXRefresh(&jtp_screen);
79 #endif
80 #ifdef USE_DOS_SYSCALLS
81 jtp_DOSRefresh(&jtp_screen);
82 #endif
83 #ifdef USE_SDL_SYSCALLS
84 jtp_SDLRefresh(&jtp_screen);
85 #endif
86 }
87
jtp_refresh_region(int x1,int y1,int x2,int y2)88 void jtp_refresh_region(int x1, int y1, int x2, int y2)
89 {
90 #ifdef USE_DIRECTX_SYSCALLS
91 jtp_DXRefreshRegion(x1, y1, x2, y2, &jtp_screen);
92 #endif
93 #ifdef USE_DOS_SYSCALLS
94 jtp_DOSRefreshRegion(x1, y1, x2, y2, &jtp_screen);
95 #endif
96 #ifdef USE_SDL_SYSCALLS
97 jtp_SDLRefreshRegion(x1, y1, x2, y2, &jtp_screen);
98 #endif
99 }
100
101 /*-----------------------------------------
102 Graphics initialization
103 ------------------------------------------*/
jtp_fill_ifcolors(unsigned char * ifcolors)104 void jtp_fill_ifcolors
105 (
106 unsigned char *ifcolors
107 )
108 {
109 int i;
110 for (i = 0; i < 256; i++) ifcolors[i] = i;
111 }
112
113
jtp_init_screen(int screen_width,int screen_height,int screen_bit_depth)114 void jtp_init_screen
115 (
116 int screen_width,
117 int screen_height,
118 int screen_bit_depth
119 )
120 {
121 jtp_screen.width = screen_width;
122 jtp_screen.height = screen_height;
123 jtp_screen.vpage = (unsigned char *)calloc(jtp_screen.width*jtp_screen.height,sizeof(unsigned char));
124 jtp_screen.drx1 = 0;
125 jtp_screen.dry1 = 0;
126 jtp_screen.drx2 = jtp_screen.width-1;
127 jtp_screen.dry2 = jtp_screen.height-1;
128 }
129
130
jtp_free_screen()131 void jtp_free_screen()
132 {
133 free(jtp_screen.vpage);
134 }
135
136
137 /*--------------------------------------------------------------------------
138 Palette handling
139 --------------------------------------------------------------------------*/
140
jtp_correct_gamma(unsigned char * r,unsigned char * g,unsigned char * b,double alpha)141 void jtp_correct_gamma
142 (
143 unsigned char *r, /* Pointers to the color components to be corrected */
144 unsigned char *g,
145 unsigned char *b,
146 double alpha /* Gamma value, alpha > 0. Values below 1 darken. */
147 )
148 {
149 double l; /* Original color luminosity */
150 double m; /* Gamma correction multiplier */
151
152 /*
153 * A simple "L1" or "city-block" norm is used here
154 * to calculate luminosity. Other norms could also
155 * be used, for example the "L2" norm, or some
156 * weighted version of these. Also the relative
157 * importance of the red/green/blue components
158 * could be weighted.
159 */
160 l = ((double)*r + (double)*g + (double)*b) / (3.0*63.0);
161 if (l == 0) return;
162
163 /* Gamma correct luminosity value */
164 if (alpha <= 0) return;
165 if (alpha > 0) alpha = 1.0/alpha;
166
167 m = 1/((1-alpha*alpha)*l+alpha*alpha);
168
169 /* Correct the red, green and blue values */
170 l = *r * m; if (l > 63) l = 63; *r = l;
171 l = *g * m; if (l > 63) l = 63; *g = l;
172 l = *b * m; if (l > 63) l = 63; *b = l;
173
174 return;
175 }
176
jtp_updatepal(unsigned char index1,unsigned char index2)177 void jtp_updatepal
178 (
179 unsigned char index1,
180 unsigned char index2
181 )
182 {
183 int i;
184 #ifdef USE_DIRECTX_SYSCALLS
185 for (i = index1; i <= index2; i++)
186 jtp_DXRecordColor(i, jtp_colors[i][0], jtp_colors[i][1], jtp_colors[i][2]);
187 jtp_DXSetPalette();
188 jtp_DXProcessEvents();
189 #endif
190 #ifdef USE_DOS_SYSCALLS
191 for (i = index1; i <= index2; i++)
192 jtp_DOSSetColor(i, jtp_colors[i][0], jtp_colors[i][1], jtp_colors[i][2]);
193 #endif
194 #ifdef USE_SDL_SYSCALLS
195 for (i = index1; i <= index2; i++)
196 jtp_SDLRecordColor(i, jtp_colors[i][0], jtp_colors[i][1], jtp_colors[i][2]);
197 jtp_SDLSetPalette();
198 jtp_SDLProcessEvents();
199 #endif
200 }
201
jtp_blankpal(unsigned char index1,unsigned char index2)202 void jtp_blankpal
203 (
204 unsigned char index1,
205 unsigned char index2
206 )
207 {
208 int i;
209 #ifdef USE_DIRECTX_SYSCALLS
210 for (i = index1; i <= index2; i++)
211 jtp_DXRecordColor(i, 0, 0, 0);
212 jtp_DXSetPalette();
213 jtp_DXProcessEvents();
214 #endif
215 #ifdef USE_DOS_SYSCALLS
216 for (i = index1; i <= index2; i++)
217 jtp_DOSSetColor(i, 0, 0, 0);
218 #endif
219 #ifdef USE_SDL_SYSCALLS
220 for (i = index1; i <= index2; i++)
221 jtp_SDLRecordColor(i, 0, 0, 0);
222 jtp_SDLSetPalette();
223 jtp_SDLProcessEvents();
224 #endif
225 }
226
jtp_fade_out(double n_secs)227 void jtp_fade_out(double n_secs)
228 {
229 clock_t start_clock, cur_clock, old_clock, n_clocks;
230 int i;
231
232 n_clocks = CLOCKS_PER_SEC*n_secs;
233 start_clock = clock();
234 cur_clock = start_clock;
235 old_clock = cur_clock;
236
237 while (cur_clock < n_clocks + start_clock)
238 {
239 if (cur_clock != old_clock)
240 {
241 #ifdef USE_DIRECTX_SYSCALLS
242 for (i = 0; i < 256; i++)
243 jtp_DXRecordColor(i, (jtp_colors[i][0]*(n_clocks+start_clock-cur_clock))/n_clocks,
244 (jtp_colors[i][1]*(n_clocks+start_clock-cur_clock))/n_clocks,
245 (jtp_colors[i][2]*(n_clocks+start_clock-cur_clock))/n_clocks);
246 jtp_DXSetPalette();
247 jtp_DXProcessEvents();
248 #endif
249 #ifdef USE_DOS_SYSCALLS
250 for (i = 0; i < 256; i++)
251 jtp_DOSSetColor(i, (jtp_colors[i][0]*(n_clocks+start_clock-cur_clock))/n_clocks,
252 (jtp_colors[i][1]*(n_clocks+start_clock-cur_clock))/n_clocks,
253 (jtp_colors[i][2]*(n_clocks+start_clock-cur_clock))/n_clocks);
254 #endif
255 #ifdef USE_SDL_SYSCALLS
256 for (i = 0; i < 256; i++)
257 jtp_SDLRecordColor(i, (jtp_colors[i][0]*(n_clocks+start_clock-cur_clock))/n_clocks,
258 (jtp_colors[i][1]*(n_clocks+start_clock-cur_clock))/n_clocks,
259 (jtp_colors[i][2]*(n_clocks+start_clock-cur_clock))/n_clocks);
260 jtp_SDLSetPalette();
261 jtp_SDLProcessEvents();
262 #endif
263 }
264 old_clock = cur_clock;
265 cur_clock = clock();
266 }
267 jtp_blankpal(0,255);
268 }
269
jtp_fade_in(double n_secs)270 void jtp_fade_in(double n_secs)
271 {
272 clock_t start_clock, cur_clock, old_clock, n_clocks;
273 int i;
274
275 n_clocks = CLOCKS_PER_SEC*n_secs;
276 start_clock = clock();
277 cur_clock = start_clock;
278 old_clock = cur_clock;
279
280 while (cur_clock < n_clocks + start_clock)
281 {
282 if (cur_clock != old_clock)
283 {
284 #ifdef USE_DIRECTX_SYSCALLS
285 for (i = 0; i < 256; i++)
286 jtp_DXRecordColor(i, (jtp_colors[i][0]*(cur_clock-start_clock))/n_clocks,
287 (jtp_colors[i][1]*(cur_clock-start_clock))/n_clocks,
288 (jtp_colors[i][2]*(cur_clock-start_clock))/n_clocks);
289 jtp_DXSetPalette();
290 jtp_DXProcessEvents();
291 #endif
292 #ifdef USE_DOS_SYSCALLS
293 for (i = 0; i < 256; i++)
294 jtp_DOSSetColor(i, (jtp_colors[i][0]*(cur_clock-start_clock))/n_clocks,
295 (jtp_colors[i][1]*(cur_clock-start_clock))/n_clocks,
296 (jtp_colors[i][2]*(cur_clock-start_clock))/n_clocks);
297 #endif
298 #ifdef USE_SDL_SYSCALLS
299 for (i = 0; i < 256; i++)
300 jtp_SDLRecordColor(i, (jtp_colors[i][0]*(cur_clock-start_clock))/n_clocks,
301 (jtp_colors[i][1]*(cur_clock-start_clock))/n_clocks,
302 (jtp_colors[i][2]*(cur_clock-start_clock))/n_clocks);
303 jtp_SDLSetPalette();
304 jtp_SDLProcessEvents();
305 #endif
306 }
307 old_clock = cur_clock;
308 cur_clock = clock();
309 }
310 jtp_updatepal(0,255);
311 }
312
313
314 /*--------------------------------------------------------------------------
315 Basic graphics plotting
316 --------------------------------------------------------------------------*/
jtp_set_draw_region(int _drx1,int _dry1,int _drx2,int _dry2)317 void jtp_set_draw_region
318 (
319 int _drx1, int _dry1,
320 int _drx2, int _dry2
321 )
322 {
323 if (_drx1 >= 0) jtp_screen.drx1=_drx1; else jtp_screen.drx1 = 0;
324 if (_dry1 >= 0) jtp_screen.dry1=_dry1; else jtp_screen.dry1 = 0;
325 if (_drx2 < jtp_screen.width) jtp_screen.drx2=_drx2; else jtp_screen.drx2 = jtp_screen.width-1;
326 if (_dry2 < jtp_screen.height) jtp_screen.dry2=_dry2; else jtp_screen.dry2 = jtp_screen.height-1;
327 }
328
329
jtp_pixelput(int x,int y,unsigned char vari)330 void jtp_pixelput
331 (
332 int x, int y,
333 unsigned char vari
334 )
335 {
336 jtp_screen.vpage[y*jtp_screen.width+x]=vari;
337 }
338
jtp_pixelget(int x,int y)339 unsigned char jtp_pixelget(int x, int y)
340 {
341 return(jtp_screen.vpage[y*jtp_screen.width+x]);
342 }
343
jtp_rect(int x1,int y1,int x2,int y2,unsigned char cindex)344 void jtp_rect
345 (
346 int x1, int y1,
347 int x2, int y2,
348 unsigned char cindex
349 )
350 {
351 int i,j;
352 for (i = x1; i <= x2; i++)
353 {
354 jtp_screen.vpage[y1*jtp_screen.width+i] = cindex;
355 jtp_screen.vpage[y2*jtp_screen.width+i] = cindex;
356 }
357 for (j = y1; j <= y2; j++)
358 {
359 jtp_screen.vpage[j*jtp_screen.width+x1] = cindex;
360 jtp_screen.vpage[j*jtp_screen.width+x2] = cindex;
361 }
362 }
363
jtp_fill_rect(int x1,int y1,int x2,int y2,unsigned char cindex)364 void jtp_fill_rect
365 (
366 int x1, int y1,
367 int x2, int y2,
368 unsigned char cindex
369 )
370 {
371 int i,j;
372
373 if (x1 < jtp_screen.drx1) x1 = jtp_screen.drx1;
374 if (y1 < jtp_screen.dry1) y1 = jtp_screen.dry1;
375 if (x2 > jtp_screen.drx2) x2 = jtp_screen.drx2;
376 if (y2 > jtp_screen.dry2) y2 = jtp_screen.dry2;
377
378 for (i = x1; i <= x2; i++)
379 for (j = y1; j <= y2; j++)
380 jtp_screen.vpage[j*jtp_screen.width+i] = cindex;
381 }
382
383
jtp_bres_line(int x1,int y1,int x2,int y2,unsigned char cindex)384 void jtp_bres_line
385 (
386 int x1, int y1,
387 int x2, int y2,
388 unsigned char cindex
389 )
390 {
391 int dx, dy, x, y, tmpplus, endx, endy, p, const1, const2;
392
393 dx = abs(x1-x2); dy = abs(y1-y2);
394
395 if (dx > dy)
396 {
397 p = 2*dy-dx; const1 = 2*dy; const2 = 2*(dy-dx);
398
399 if (x1 > x2) { x = x2; y = y2; endx = x1; if (y1 > y2) tmpplus = 1; else tmpplus = -1; }
400 else { x = x1; y = y1; endx = x2; if (y2 > y1) tmpplus = 1; else tmpplus = -1; }
401 jtp_screen.vpage[jtp_screen.width*y+x] = cindex;
402
403 while (x < endx)
404 {
405 if (p < 0) p += const1; else { y += tmpplus; p += const2; }
406 x++; jtp_screen.vpage[jtp_screen.width*y+x] = cindex;
407 }
408 }
409 else
410 {
411 p = 2*dx-dy; const1 = 2*dx; const2 = 2*(dx-dy);
412
413 if (y1 > y2) { y = y2; x = x2; endy = y1; if (x1 > x2) tmpplus = 1; else tmpplus = -1; }
414 else { y = y1; x = x1; endy = y2; if (x2 > x1) tmpplus = 1; else tmpplus = -1; }
415 jtp_screen.vpage[jtp_screen.width*y+x] = cindex;
416
417 while (y < endy)
418 {
419 if (p < 0) p += const1; else { x += tmpplus; p += const2; }
420 y++; jtp_screen.vpage[jtp_screen.width*y+x] = cindex;
421 }
422 }
423 }
424
425
jtp_bres_circle_points(int xc,int yc,int dx,int dy,unsigned char cindex)426 void jtp_bres_circle_points
427 (
428 int xc, int yc,
429 int dx, int dy,
430 unsigned char cindex
431 )
432 {
433 int tempofs;
434 tempofs = jtp_screen.width*(yc+dy)+xc; jtp_screen.vpage[tempofs-dx] = cindex; jtp_screen.vpage[tempofs+dx] = cindex;
435 tempofs = jtp_screen.width*(yc-dy)+xc; jtp_screen.vpage[tempofs-dx] = cindex; jtp_screen.vpage[tempofs+dx] = cindex;
436 tempofs = jtp_screen.width*(yc+dx)+xc; jtp_screen.vpage[tempofs-dy] = cindex; jtp_screen.vpage[tempofs+dy] = cindex;
437 tempofs = jtp_screen.width*(yc-dx)+xc; jtp_screen.vpage[tempofs-dy] = cindex; jtp_screen.vpage[tempofs+dy] = cindex;
438 }
439
jtp_bres_circle(int xc,int yc,int radius,unsigned char cindex)440 void jtp_bres_circle
441 (
442 int xc, int yc,
443 int radius,
444 unsigned char cindex
445 )
446 {
447 int x, y, p;
448 x = 0; y = radius; p = 3 - 2*radius;
449 while (x < y)
450 {
451 jtp_bres_circle_points(xc, yc, x, y, cindex);
452 if (p < 0) p += x*4 + 6;
453 else { p += (x-y)*4 + 10; y--; }
454 x++;
455 }
456 if (x==y) jtp_bres_circle_points(xc, yc, x, y, cindex);
457 }
458
jtp_bres_circle_lines(int xc,int yc,int dx,int dy,unsigned char cindex)459 void jtp_bres_circle_lines
460 (
461 int xc, int yc,
462 int dx, int dy,
463 unsigned char cindex
464 )
465 {
466 int tempofs,i;
467 tempofs = jtp_screen.width*(yc+dy)+xc; for (i=-dx; i <= dx; i++) jtp_screen.vpage[tempofs+i] = cindex;
468 tempofs = jtp_screen.width*(yc-dy)+xc; for (i=-dx; i <= dx; i++) jtp_screen.vpage[tempofs+i] = cindex;
469 tempofs = jtp_screen.width*(yc+dx)+xc; for (i=-dy; i <= dy; i++) jtp_screen.vpage[tempofs+i] = cindex;
470 tempofs = jtp_screen.width*(yc-dx)+xc; for (i=-dy; i <= dy; i++) jtp_screen.vpage[tempofs+i] = cindex;
471 }
472
jtp_bres_fill_circle(int xc,int yc,int radius,unsigned char cindex)473 void jtp_bres_fill_circle
474 (
475 int xc, int yc,
476 int radius,
477 unsigned char cindex
478 )
479 {
480 int x, y, p, i;
481 x = 0; y = radius; p = 3 - 2*radius;
482 /*
483 for (i=-y; i <= y; i++)
484 { jtp_screen.vpage[jtp_screen.width*yc+xc+i]++; }
485 */
486 while (x < y)
487 {
488 if (p < 0) p += x*4 + 6;
489 else
490 {
491 p += (x-y)*4 + 10; y--;
492 for (i=-x; i <= x; i++)
493 { jtp_screen.vpage[jtp_screen.width*(yc+y)+xc+i]++;/* = cindex;*/
494 jtp_screen.vpage[jtp_screen.width*(yc-y)+xc+i]++;/* = cindex;*/ }
495 }
496 if (x!=y) for (i=-y; i <= y; i++)
497 { jtp_screen.vpage[jtp_screen.width*(yc+x)+xc+i]++;/* = cindex;*/
498 jtp_screen.vpage[jtp_screen.width*(yc-x)+xc+i]++;/* = cindex;*/ }
499 x++;
500 }
501 /* if (x==y) bres_circle_lines(xc,yc,x,y,cindex); */
502 }
503
504
505
506 /*--------------------------------------------------------------------------
507 Bitmap handling
508 --------------------------------------------------------------------------*/
jtp_get_img(int x1,int y1,int x2,int y2)509 unsigned char *jtp_get_img
510 (
511 int x1, int y1,
512 int x2, int y2
513 )
514 {
515 int Xsize,Ysize,i;
516 int Xbegin, Ybegin;
517 unsigned char *a;
518
519 if (x1>jtp_screen.width-1) return(NULL);
520 if (y1>jtp_screen.height-1) return(NULL);
521
522 if (x2<0) return(NULL);
523 if (y2<0) return(NULL);
524
525 if (x1<0) Xbegin = -x1; else Xbegin = 0;
526 if (y1<0) Ybegin = -y1; else Ybegin = 0;
527 if (x2>jtp_screen.width-1) x2=jtp_screen.width-1;
528 if (y2>jtp_screen.height-1) y2=jtp_screen.height-1;
529
530 Ysize=y2-y1+1;
531 Xsize=x2-x1+1;
532 a=(unsigned char *)malloc((Ysize*Xsize+4)*sizeof(unsigned char));
533 if (a==NULL) return(NULL);
534
535 a[0]=Ysize >> 8;
536 a[1]=Ysize & 255;
537 a[2]=Xsize >> 8;
538 a[3]=Xsize & 255;
539 for (i=Ybegin;i<=Ysize-1;i++)
540 memcpy(&(a[i*Xsize+4+Xbegin]),&(jtp_screen.vpage[(y1+i)*jtp_screen.width+x1+Xbegin]),Xsize-Xbegin);
541 return(a);
542 }
543
jtp_get_img_src(int x1,int y1,int x2,int y2,unsigned char * img_source)544 unsigned char *jtp_get_img_src
545 (
546 int x1, int y1,
547 int x2, int y2,
548 unsigned char *img_source
549 )
550 {
551 int Xsize,Ysize,i;
552 int imgXsize,imgYsize;
553 unsigned char *a;
554
555 if (!img_source) return(NULL);
556 imgYsize=img_source[0]*256+img_source[1];
557 imgXsize=img_source[2]*256+img_source[3];
558
559 if (x1>imgXsize-1) return(NULL);
560 if (y1>imgYsize-1) return(NULL);
561
562 if (x2<0) return(NULL);
563 if (y2<0) return(NULL);
564
565 if (x1<0) x1=0;
566 if (y1<0) y1=0;
567 if (x2>imgXsize-1) x2=imgXsize-1;
568 if (y2>imgYsize-1) y2=imgYsize-1;
569
570 Ysize=y2-y1+1;
571 Xsize=x2-x1+1;
572 a=(unsigned char *)malloc((Ysize*Xsize+4)*sizeof(unsigned char));
573 if (a==NULL) return(NULL);
574
575 a[0]=Ysize >> 8;
576 a[1]=Ysize & 255;
577 a[2]=Xsize >> 8;
578 a[3]=Xsize & 255;
579
580 img_source+=y1*imgXsize + x1 + 4;
581 for (i=0;i<=Ysize-1;i++)
582 {
583 memcpy(&(a[i*Xsize+4]),img_source,Xsize);
584 img_source+=imgXsize;
585 }
586 return(a);
587 }
588
589
590
jtp_put_img(int x,int y,unsigned char * a)591 void jtp_put_img
592 (
593 int x, int y,
594 unsigned char *a
595 )
596 {
597 int srcXsize,cutXsize,srcYsize,i,y1,y2,x1;
598 unsigned char *destin;
599
600 if ((a==NULL) || (x>jtp_screen.drx2) || (y>jtp_screen.dry2)) return;
601
602 srcYsize=a[0]*256+a[1];
603 srcXsize=a[2]*256+a[3];
604
605 if ((x+srcXsize<=jtp_screen.drx1) || (y+srcYsize<=jtp_screen.dry1)) return;
606 if (y<jtp_screen.dry1) y1=jtp_screen.dry1-y; else y1=0;
607 if (y+srcYsize-1>jtp_screen.dry2) y2=jtp_screen.dry2-y; else y2=srcYsize-1;
608 if (x+srcXsize-1>jtp_screen.drx2) cutXsize=jtp_screen.drx2-x+1; else cutXsize=srcXsize;
609 if (x<jtp_screen.drx1)
610 {
611 x1=jtp_screen.drx1-x;
612 cutXsize-=x1;
613 }
614 else x1=0;
615
616 a += x1 + 4 + y1*srcXsize;
617 destin = jtp_screen.vpage+(y+y1)*jtp_screen.width+x+x1;
618
619 for (i = y1; i <= y2; i++)
620 {
621 memcpy(destin,a,cutXsize);
622 a+=srcXsize;
623 destin+=jtp_screen.width;
624 }
625 }
626
627
jtp_put_stencil(int x,int y,unsigned char * a)628 void jtp_put_stencil
629 (
630 int x, int y,
631 unsigned char *a
632 )
633 {
634 int srcXsize,srcYsize,j,y1,y2,x1,x2;
635 int dplus;
636 unsigned char vari;
637 unsigned char *destin, *a_end;
638
639 if ((a==NULL) || (x>jtp_screen.drx2) || (y>jtp_screen.dry2)) return;
640
641 srcYsize=a[0]*256+a[1];
642 srcXsize=a[2]*256+a[3];
643
644 if ((x+srcXsize<=jtp_screen.drx1) || (y+srcYsize<=jtp_screen.dry1)) return;
645 if (y<jtp_screen.dry1) y1=jtp_screen.dry1-y; else y1=0;
646 if (y+srcYsize-1>jtp_screen.dry2) y2=jtp_screen.dry2-y; else y2=srcYsize-1;
647 if (x<jtp_screen.drx1) x1=jtp_screen.drx1-x; else x1=0;
648 if (x+srcXsize-1>jtp_screen.drx2) x2=jtp_screen.drx2-x; else x2=srcXsize-1;
649
650 a+=y1*srcXsize+4;
651 a_end = a + (y2-y1+1)*srcXsize;
652 destin=jtp_screen.vpage+(y1+y)*jtp_screen.width+x;
653 dplus = jtp_screen.width;
654
655 a += x1;
656 a_end += x1;
657 destin += x1;
658 x2 -= x1;
659 x1 = jtp_screen.width;
660
661 while (a < a_end)
662 {
663 for (j = x2; j >= 0; j--)
664 {
665 /*
666 vari=a[j];
667 if (vari!=0) destin[j]=vari;
668 */
669 if (a[j]) destin[j] = a[j];
670 }
671 a += srcXsize;
672 destin += dplus;
673 }
674 }
675
676
677
678 #endif
679