|
|
1.1 root 1: #include <stdio.h>
2: #include <signal.h>
3: #include "pico.h"
4:
5: #define lowbyte(A) (A)&0377
6: #define higbyte(A) ((A) >> 8) & 07
7:
8: extern short CURSCRATCH, CUROLD;
9: extern struct SRC src[MANY];
10: extern void onquit();
11: extern int DEF_LL, DEF_NL;
12:
13: metputitall(k)
14: { struct SRC *from = &src[k];
15: register unsigned char *pr, *pg, *pb, *w;
16: register int i, j;
17: int ex = from->sx + from->ex;
18: int offset, delta, sx = from->sx;
19: int sy = from->sy, ey = from->sy + from->ey;
20: unsigned char mcode[16];
21: unsigned char W[1024];
22: extern int om_fd;
23:
24: mcode[0] = 0x4F;
25: mcode[1] = 0377; /* WRMASK */
26: mcode[2] = 0x52; /* set P1 */
27: mcode[7] = 0x53; /* set P2 */
28: mcode[12] = 0;
29: mcode[13] = 'o';
30: mcode[3] = lowbyte(sx);
31: mcode[4] = higbyte(sx);
32: mcode[8] = lowbyte(ex);
33: mcode[9] = higbyte(ex);
34:
35: offset = sy*DEF_LL + sx;
36: delta = DEF_LL - ex + sx;
37:
38: pr = from->pixred+offset;
39: pg = from->pixgrn+offset;
40: pb = from->pixblu+offset;
41:
42: switch (from->nchan)
43: { case 1:
44: signal(SIGINT, SIG_IGN);
45: for (i = sy; i < ey; i++, pr += (ex-sx)+delta)
46: { mcode[5] = mcode[10] = lowbyte(i);
47: mcode[6] = mcode[11] = higbyte(i);
48: write(om_fd, mcode, 14);
49: write(om_fd, pr, ex-sx);
50: }
51: signal(SIGINT, onquit);
52: break;
53: case 3: for (i = sy; i < ey; i++, pr+=delta, pg+=delta, pb+=delta)
54: { mcode[5] = mcode[10] = lowbyte(i);
55: mcode[6] = mcode[11] = higbyte(i);
56: for (j = sx, w = W; j < ex; j++)
57: *w++ = ((*pr++ & 224))|
58: ((*pg++ & 224)>>3)|
59: ((*pb++ & 192)>>6);
60: signal(SIGINT, SIG_IGN);
61: write(om_fd, mcode, 14);
62: write(om_fd, W, ex-sx);
63: signal(SIGINT, onquit);
64: }
65: break;
66: default:
67: fprintf(stderr, "undefined number of channels\n");
68: break;
69: }
70: }
71:
72: metgetitall(from)
73: struct SRC *from;
74: {
75: register unsigned char *pr, *pg, *pb, *w;
76: register int j, ex = from->sx + from->ex;
77: unsigned char W[1024];
78: int i, offset, delta, sx = from->sx;
79: int sy = from->sy, ey = from->sy + from->ey;
80:
81: if (from == Old)
82: fprintf(stderr, "reading screen...");
83:
84: offset = sy*DEF_LL + sx;
85: delta = DEF_LL - ex + sx;
86:
87: pr = from->pixred+offset;
88: pg = from->pixgrn+offset;
89: pb = from->pixblu+offset;
90:
91: switch (from->nchan)
92: { case 1:
93: for (i = sy; i < ey; i++, pr+=delta, pg+=delta, pb+=delta)
94: { metri(pr, 0, i, DEF_LL);
95: for (j = sx; j < ex; j++)
96: { *pg++ = *pb++ = *pr++;
97: }
98: }
99: break;
100: case 3:
101: for (i = sy; i < ey; i++, pr+=delta, pg+=delta, pb+=delta)
102: { metri(W, 0, i, DEF_LL);
103: for (j = sx, w = W; j < ex; j++, w++)
104: { *pr++ = (*w&224);
105: *pg++ = (*w& 28)<<3;
106: *pb++ = (*w& 3)<<6;
107: } }
108: break;
109: default:
110: fprintf(stderr, "undefined number of channels\n");
111: break;
112: }
113: if (from == Old)
114: fprintf(stderr, "\n");
115: RESIDENT;
116: }
117:
118: metlyank(x, y)
119: { register int i;
120: register unsigned char *pr, *pg, *pb, *w;
121: unsigned char W[1024];
122: extern char faster;
123: int from=Old->sx, to=Old->ex;
124:
125: if (y < Old->sy || y >= Old->ey) return;
126:
127: if (!faster)
128: { metyank(x, y);
129: return;
130: } else
131: { if (x != 0)
132: return;
133: }
134: i = (y < 1 || y >= DEF_LL) ? 0 : DEF_LL*(y-1);
135: pr = scratchred+i;
136:
137: if (Old->nchan ==1)
138: w = pr;
139: else
140: { pg = scratchgrn+i;
141: pb = scratchblu+i;
142: for (i = from, w = W; i < to; i++)
143: *w++ = ((*pr++ & 224))|
144: ((*pg++ & 224)>>3)|
145: ((*pb++ & 192)>>6);
146: w = W;
147: }
148: metwi(w, to-from, from, y);
149:
150: return 1;
151: }
152:
153: metyank(x, y)
154: { register int i = DEF_LL*y+x;
155: unsigned char *pr = scratchred+i;
156: unsigned char *pg = scratchgrn+i;
157: unsigned char *pb = scratchblu+i;
158: unsigned char w;
159:
160: if (Old->nchan == 1)
161: w = *pr;
162: else
163: w = ((*pr & 224))| ((*pg & 224)>>3)| ((*pb & 192)>>6);
164:
165: metwi(&w, 1, x, y);
166:
167: return 1;
168: }
169:
170: extern unsigned char Rmap[256], Gmap[256], Bmap[256];
171:
172: metredcmap(i, z)
173: { int j = i%256;
174: int k = z%256;
175:
176: Rmap[j] = k;
177: if (j == 255) dometcmap();
178: return k;
179: }
180:
181: metgrncmap(i, z)
182: { int j = i%256;
183: int k = z%256;
184:
185: Gmap[j] = k;
186: if (j == 255) dometcmap();
187: return k;
188: }
189:
190: metblucmap(i, z)
191: { int j = i%256;
192: int k = z%256;
193:
194: Bmap[j] = k;
195: if (j == 255) dometcmap();
196: return k;
197: }
198:
199: dometcmap()
200: { struct scolor {
201: char tag, loc;
202: char red, grn, blu;
203: char zero;
204: } color[256];
205: char b[8];
206: register struct scolor *cp = color;
207: register int i;
208: extern int om_fd;
209:
210: if (Old->nchan == 1)
211: for (i = 0; i < 256; i++, cp++)
212: { cp->tag = 'Q';
213: cp->loc = i;
214: cp->red = Rmap[i];
215: cp->grn = Gmap[i];
216: cp->blu = Bmap[i];
217: cp->zero = 0;
218: }
219: else
220: for (i = 0; i < 256; i++, cp++)
221: { cp->tag = 'Q';
222: cp->loc = i;
223: cp->red = (Rmap[i]&224) ? (Rmap[i]&224) : 0;
224: cp->grn = (Gmap[i]& 28) ? (Gmap[i]& 28)<<3 : 0;
225: cp->blu = (Bmap[i]& 3) ? (Bmap[i]& 3)<<6 : 0;
226: cp->zero = 0;
227: }
228:
229: b[0] = 'O'; b[1] = 0377;
230: signal(SIGINT, SIG_IGN);
231: write(om_fd, b, 2);
232: write(om_fd, color, sizeof(color));
233: signal(SIGINT, onquit);
234: }
235:
236: metgetcmap(i, r,g,b)
237: { int h = 0, k = 0;
238:
239: if (r) { h++; k += Rmap[i]; }
240: if (g) { h++; k += Gmap[i]; }
241: if (b) { h++; k += Bmap[i]; }
242: if (h > 1) k /= h;
243:
244: return k;
245: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.