/[opencvs]/eyes/randomify4.c
ViewVC logotype

Contents of /eyes/randomify4.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sat Oct 8 22:06:17 2011 UTC (7 years, 2 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
working on tilify.c - this will be pretty neat
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 /* randomify4 gets 3 pixel files and their green screen equivilants
5 and it randomifys equally between the three.
6 */
7
8 #include "util.h"
9 /* usage randomify xsize ysize seed basefile pixelfilea pixelfilea_gs \
10 pixelfile_b pixelfileb_gs \
11 pixelfile_c pixelfilec_gs alphafile [hologramfile] */
12 int main (int argc,char *argv[]) {
13 char *basefile; /* base.txt by convention */
14 char *pixelfilea; /* p2.txt by convention */
15 char *pixelfilea_gs; /* p2.txt by convention */
16 char *pixelfileb; /* p2.txt by convention */
17 char *pixelfileb_gs; /* p2.txt by convention */
18 char *pixelfilec; /* p2.txt by convention */
19 char *pixelfilec_gs; /* p2.txt by convention */
20 char *alphafile; /* alpha.txt by convention */
21 char *hologramfile; /* l.txt conventionally */
22 int xsize;
23 int ysize;
24 if (argc==12) {
25 xsize=atoi(argv[1]);
26 ysize=atoi(argv[2]);
27 srand(atoi(argv[3]));
28 basefile=argv[4];
29 pixelfilea=argv[5];
30 pixelfilea_gs=argv[6];
31 pixelfileb=argv[7];
32 pixelfileb_gs=argv[8];
33 pixelfilec=argv[9];
34 pixelfilec_gs=argv[10];
35 alphafile=argv[11];
36 hologramfile="fdshadisaohgyuhgurk";
37 }
38 else if (argc==13) {
39 xsize=atoi(argv[1]);
40 ysize=atoi(argv[2]);
41 srand(atoi(argv[3]));
42 basefile=argv[4];
43 pixelfilea=argv[5];
44 pixelfilea_gs=argv[6];
45 pixelfileb=argv[7];
46 pixelfileb_gs=argv[8];
47 pixelfilec=argv[9];
48 pixelfilec_gs=argv[10];
49 alphafile=argv[11];
50 hologramfile=argv[12];
51 }
52 else {
53 fprintf(stderr,"usage randomify4 xsize ysize seed basefile pixelfilea pfa_gs pfb pfb_gs pfc pfc_gs alphafile [hologramfile]\n"
54 "Where file has x|y|r|g|b text format\n");
55 exit(-1);
56 }
57 FILE *base,*othera,*othera_gs,*otherb,*otherb_gs,*otherc,*otherc_gs,*alpha,*hologram;
58 base = fopen(basefile,"r");
59 othera = fopen(pixelfilea,"r");
60 othera_gs = fopen(pixelfilea_gs,"r");
61 otherb = fopen(pixelfileb,"r");
62 otherb_gs = fopen(pixelfileb_gs,"r");
63 otherc = fopen(pixelfilec,"r");
64 otherc_gs = fopen(pixelfilec_gs,"r");
65 alpha = fopen(alphafile,"r");
66 hologram = fopen(hologramfile,"r"); /* optional */
67 if (hologram) {
68 fprintf(stderr,"hologram found and being used as a base\n");
69 }
70 char basebuf[10001];
71 char otherbufa[10001];
72 char otherbufa_gs[10001];
73 char otherbufb[10001];
74 char otherbufb_gs[10001];
75 char otherbufc[10001];
76 char otherbufc_gs[10001];
77 char alphabuf[10001];
78 char hologrambuf[10001];
79 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
80 while (fgets(basebuf,10000,base)) {
81 char *q;
82 // fprintf(stderr,"b %s\n",basebuf);
83 q=fgets(otherbufa,10000,othera);
84 q=fgets(otherbufa_gs,10000,othera_gs);
85 q=fgets(otherbufb,10000,otherb);
86 q=fgets(otherbufb_gs,10000,otherb_gs);
87 q=fgets(otherbufc,10000,otherc);
88 q=fgets(otherbufc_gs,10000,otherc_gs);
89 // fprintf(stderr,"o %s\n",otherbuf);
90 if (alpha) q=fgets(alphabuf,10000,alpha);
91 if (hologram) q=fgets(hologrambuf,10000,hologram);
92 int xb,yb,rb,gb,bb;
93 int xoa,yoa,roa,goa,boa;
94 int xoa_gs,yoa_gs,roa_gs,goa_gs,boa_gs;
95 int xob,yob,rob,gob,bob;
96 int xob_gs,yob_gs,rob_gs,gob_gs,bob_gs;
97 int xoc,yoc,roc,goc,boc;
98 int xoc_gs,yoc_gs,roc_gs,goc_gs,boc_gs;
99 int xa,ya,ra,ga,ba;
100 int hb;
101 xb = fieldi(basebuf,0);
102 yb = fieldi(basebuf,1);
103 rb = fieldi(basebuf,2);
104 gb = fieldi(basebuf,3);
105 bb = fieldi(basebuf,4);
106 xoa = fieldi(otherbufa,0);
107 yoa = fieldi(otherbufa,1);
108 roa = fieldi(otherbufa,2);
109 goa = fieldi(otherbufa,3);
110 boa = fieldi(otherbufa,4);
111 xoa_gs = fieldi(otherbufa_gs,0);
112 yoa_gs = fieldi(otherbufa_gs,1);
113 roa_gs = fieldi(otherbufa_gs,2);
114 goa_gs = fieldi(otherbufa_gs,3);
115 boa_gs = fieldi(otherbufa_gs,4);
116 xob = fieldi(otherbufb,0);
117 yob = fieldi(otherbufb,1);
118 rob = fieldi(otherbufb,2);
119 gob = fieldi(otherbufb,3);
120 bob = fieldi(otherbufb,4);
121 xob_gs = fieldi(otherbufb_gs,0);
122 yob_gs = fieldi(otherbufb_gs,1);
123 rob_gs = fieldi(otherbufb_gs,2);
124 gob_gs = fieldi(otherbufa_gs,3);
125 bob_gs = fieldi(otherbufa_gs,4);
126 xoc = fieldi(otherbufc,0);
127 yoc = fieldi(otherbufc,1);
128 roc = fieldi(otherbufc,2);
129 goc = fieldi(otherbufc,3);
130 boc = fieldi(otherbufc,4);
131 xoc_gs = fieldi(otherbufc_gs,0);
132 yoc_gs = fieldi(otherbufc_gs,1);
133 roc_gs = fieldi(otherbufc_gs,2);
134 goc_gs = fieldi(otherbufa_gs,3);
135 boc_gs = fieldi(otherbufa_gs,4);
136 if (alpha) {
137 xa = fieldi(alphabuf,0);
138 ya = fieldi(alphabuf,1);
139 ra = fieldi(alphabuf,2);
140 ga = fieldi(alphabuf,3);
141 ba = fieldi(alphabuf,4);
142 }
143 else {
144 xa=xb;
145 ya=yb;
146 ra=128;
147 ga=128;
148 ba=128;
149 }
150 hb = fieldi(hologrambuf,2);
151 if ((xb != xoa)||(yb != yoa) ||
152 (xb != xa)||(yb != ya)) {
153 fprintf(stderr,"error %d,%d %d,%d %d,%d\n",
154 xb,yb,xoa,yoa,xa,ya);
155 continue;
156 }
157
158
159
160 int r;
161 int ro,go,bo;
162 r = -1;
163 if ((roa_gs == 3 )&&(goa_gs == 255) && (boa_gs = 2)) { /* no channel a */
164 if ((rob_gs == 3 )&&(gob_gs == 255) && (bob_gs = 2)) { /* no channel b */
165 if ((roc_gs == 3 )&&(goc_gs == 255) && (boc_gs = 2)) { /* no channel c */
166 r = (random()>>2) % 3; /* pick randomly from the blank */
167 }
168 else {
169 r=2; /* only channel c easy */
170 }
171 } /* if no channel b */
172 else { /* no a, yes b */
173 if ((roc_gs == 3 )&&(goc_gs == 255) && (boc_gs = 2)) { /* no channel c */
174 r=1; /* only channel b */
175 }
176 else { /* b and c */
177 r = ((random()>>2)%2)+1; /* choose b or c */
178 }
179 }
180 } /* if no a */
181 else { /* have a */
182 if ((rob_gs == 3 )&&(gob_gs == 255) && (bob_gs = 2)) { /* no channel b */
183 if ((roc_gs == 3 )&&(goc_gs == 255) && (boc_gs = 2)) { /* no channel c */
184 r = 0; /* only a */
185 }
186 else { /* a and c */
187 r = ((random()>>2)%2)*2; /* choose a or c */
188 }
189 } /* if a and no b */
190 else { /* a and b */
191 if ((roc_gs == 3 )&&(goc_gs == 255) && (boc_gs = 2)) { /* no channel c */
192 r = ((random()>>2)%2); /* choose a or b */
193 }
194 else { /* a b and c all there - the usual case */
195 r = (random()>>2) % 3; /* pick one randomly from the set */
196 }
197 } /* a and b */
198 } /* a */
199
200
201 if (r==0) {
202 ro = roa; go = goa; bo = boa;
203 }
204 else if (r==1) {
205 ro = rob; go = gob; bo = bob;
206 }
207 else if (r==2) {
208 ro = roc; go = goc; bo = boc;
209 }
210 else {
211 fprintf(stderr,"error computing which file to read x %d y %d\n",xa,ya);
212 exit(-1);
213 }
214
215 /* This section is for full color pixel transfer */
216 int rf,gf,bf;
217 if (hologram||((ra == ga)&&(ra == ba))) {
218 int r;
219 if (hologram) {
220 r=hb;
221 }
222 else r= (random()>>2) % 256;
223 if (r<ra) {
224 rf = ro;
225 gf = go;
226 bf = bo;
227 }
228 else {
229 rf = rb;
230 gf = gb;
231 bf = bb;
232 }
233 }
234 else {
235 int r;
236 r = (random()>>2) % 256;
237 if (r<ra) rf = ro; else rf=rb;
238 r = (random()>>2) % 256;
239 if (r<ga) gf = go; else gf=gb;
240 r = (random()>>2) % 256;
241 if (r<ba) bf = bo; else bf=bb;
242 }
243
244 int total;
245 total = rf*65536+gf*256+bf;
246 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",
247 xb,yb,rf,gf,bf,total,rf,gf,bf);
248 }
249 }

  ViewVC Help
Powered by ViewVC 1.1.5