1 /* $Header: /home/yav/xpx/RCS/hold.c,v 1.4 1996/04/26 17:22:47 yav Exp $
2  * xpx image hold space control
3  * written by yav (UHD98984@pcvan.or.jp)
4  */
5 
6 #include <X11/Xlib.h>
7 
8 #include "headers.h"
9 #include "xpx.h"
10 #include "work.h"
11 #define PUBLIC_HOLD_C
12 #include "extern.h"
13 
14 char rcsid_hold[] = "$Id: hold.c,v 1.4 1996/04/26 17:22:47 yav Exp $";
15 
16 AREA hold = {0, 0, 0, 0};
17 static unsigned char *holdspace = NULL;
18 
19 /*
20  * Edit buffer -> Hold space
21  */
save_holdspace(src)22 int save_holdspace(src)
23      AREA *src;			/* source imgdata area */
24 {
25   int i;
26   int y;
27 
28   if (debug_mode)
29     fprintf(stderr, "save_holdspace %d %d %d %d\n",
30 	    src->x, src->y, src->w, src->h);
31 
32   /* reset hold space */
33   if (holdspace != NULL)
34     free(holdspace);
35   hold.w = hold.h = 0;
36 
37   /* alloc hold space */
38   i = src->w * src->h;
39   holdspace = malloc(i);
40   if (holdspace == NULL)
41     return 1;			/* more core! */
42   hold.w = src->w;
43   hold.h = src->h;
44 
45   /* store */
46   for (y = 0; y < src->h; y++)
47     memcpy(holdspace+hold.w*y, imgdata+(src->y+y)*imgmaxw+src->x, hold.w);
48   if (debug_mode)
49     fprintf(stderr, "save done.\n");
50   return 0;			/* success */
51 }
52 
53 /*
54  * Edit buffer <- Hold space
55  */
load_holdspace(dst)56 int load_holdspace(dst)
57      AREA *dst;			/* destimation imgdata area */
58 				/* update dst.w dst.h */
59 {
60   int x, y;
61   int lastnocopypixel;
62   unsigned char *srcp, *dstp;
63   char *mp;
64 
65   if (debug_mode)
66     fprintf(stderr, "load_holdspace %d %d %d %d\n",
67 	    dst->x, dst->y, dst->w, dst->h);
68   if (holdspace == NULL) {
69     message("!Hold space empty.\n");
70     return 1;			/* hold space empty */
71   }
72   if (dst->w > hold.w)
73     dst->w = hold.w;
74   if (dst->h > hold.h)
75     dst->h = hold.h;
76   lastnocopypixel = nocopypixel;
77   if (!nocopypixel_mode)
78     nocopypixel = -1;
79   mp = colmask+current_pal*MAXPALSET;
80   for (y = 0; y < dst->h; y++) {
81     dstp = imgdata + (dst->y+y)*imgmaxw + dst->x;
82     srcp = holdspace + y*hold.w;
83     for (x = 0; x < dst->w; x++) {
84       if (!*(mp+*(dstp+x)) && *(srcp+x) != nocopypixel)
85 	*(dstp+x) = *(srcp+x);
86     }
87   }
88   update_area(dst->x, dst->y, dst->w, dst->h); /* XImage update */
89   nocopypixel = lastnocopypixel;
90   if (debug_mode)
91     fprintf(stderr, "load done.\n");
92   return 0;			/* success */
93 }
94 
95 /* End of file */
96