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

Contents of /eyes/randomify.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations)
Thu Mar 6 06:43:51 2014 UTC (4 years, 4 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +4 -0 lines
File MIME type: text/plain
Got qi working and released.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4
5 #include "util.h"
6 /* This version - made % from 256 to 255 - this way a white color will be strictly one
7 image, and black the other. This is for kristie
8 */
9 /* usage randomify xsize ysize seed basefile pixelfile alphafile [hologramfile] */
10 int main (int argc,char *argv[]) {
11 char *basefile; /* base.txt by convention */
12 char *pixelfile; /* p2.txt by convention */
13 char *alphafile; /* alpha.txt by convention */
14 char *hologramfile; /* l.txt conventionally */
15 int xsize;
16 int ysize;
17 if (argc==7) {
18 xsize=atoi(argv[1]);
19 ysize=atoi(argv[2]);
20 srand(atoi(argv[3]));
21 basefile=argv[4];
22 pixelfile=argv[5];
23 alphafile=argv[6];
24 hologramfile="fdshadisaohgyuhgurk";
25 }
26 else if (argc==8) {
27 xsize=atoi(argv[1]);
28 ysize=atoi(argv[2]);
29 srand(atoi(argv[3]));
30 basefile=argv[4];
31 pixelfile=argv[5];
32 alphafile=argv[6];
33 hologramfile=argv[7];
34 }
35 else {
36 fprintf(stderr,"usage randomify xsize ysize seed basefile pixelfile alphafile [hologramfile]\n"
37 "Where file has x|y|r|g|b text format\n");
38 exit(-1);
39 }
40 FILE *base,*other,*alpha,*hologram;
41 base = fopen(basefile,"r");
42 other = fopen(pixelfile,"r");
43 alpha = fopen(alphafile,"r");
44 hologram = fopen(hologramfile,"r"); /* optional */
45 if (hologram) {
46 fprintf(stderr,"hologram found and being used as a base\n");
47 }
48 char basebuf[10001];
49 char otherbuf[10001];
50 char alphabuf[10001];
51 char hologrambuf[10001];
52 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
53 while (fgets(basebuf,10000,base)) {
54 char *q;
55 // fprintf(stderr,"b %s\n",basebuf);
56 q=fgets(otherbuf,10000,other);
57 // fprintf(stderr,"o %s\n",otherbuf);
58 if (alpha) q=fgets(alphabuf,10000,alpha);
59 if (hologram) q=fgets(hologrambuf,10000,hologram);
60 int xb,yb,rb,gb,bb;
61 int xo,yo,ro,go,bo;
62 int xa,ya,ra,ga,ba;
63 int hb;
64 xb = fieldi(basebuf,0);
65 yb = fieldi(basebuf,1);
66 rb = fieldi(basebuf,2);
67 gb = fieldi(basebuf,3);
68 bb = fieldi(basebuf,4);
69 xo = fieldi(otherbuf,0);
70 yo = fieldi(otherbuf,1);
71 ro = fieldi(otherbuf,2);
72 go = fieldi(otherbuf,3);
73 bo = fieldi(otherbuf,4);
74 if (alpha) {
75 xa = fieldi(alphabuf,0);
76 ya = fieldi(alphabuf,1);
77 ra = fieldi(alphabuf,2);
78 ga = fieldi(alphabuf,3);
79 ba = fieldi(alphabuf,4);
80 }
81 else {
82 xa=xb;
83 ya=yb;
84 ra=128;
85 ga=128;
86 ba=128;
87 }
88 hb = fieldi(hologrambuf,2);
89 if ((xb != xo)||(yb != yo) ||
90 (xb != xa)||(yb != ya)) {
91 fprintf(stderr,"error %d,%d %d,%d %d,%d\n",
92 xb,yb,xo,yo,xa,ya);
93 continue;
94 }
95
96 /* This section is for full color pixel transfer */
97 int rf,gf,bf;
98 if (hologram||((ra == ga)&&(ra == ba))) {
99 int r;
100 if (hologram) {
101 r=hb;
102 /* heres the special rub. There are different brightnesses for r
103 if the O is darker than B then we do this in one direction
104 Otherwise we reverse the polarity. That way the hologram will work
105 with the lightness and darkness of the two pictures.
106 I think the result will be much better.
107 */
108 int lumao,lumab;
109 lumao = (ro*299) + (go * 587) + (bo* 114);
110 lumab = (rb*299) + (gb * 587) + (bb* 114);
111 if (lumab < lumao) {
112 r = 255 - r; /* other way biitch!*/
113 if (r<ra) {
114 rf = ro;
115 gf = go;
116 bf = bo;
117 }
118 else {
119 rf = rb;
120 gf = gb;
121 bf = bb;
122 }
123 }
124 else {
125 if (r<ra) {
126 rf = ro;
127 gf = go;
128 bf = bo;
129 }
130 else {
131 rf = rb;
132 gf = gb;
133 bf = bb;
134 }
135 }
136 }
137 else {
138 r= (random()>>2) % 255;
139 if (r<ra) {
140 rf = ro;
141 gf = go;
142 bf = bo;
143 }
144 else {
145 rf = rb;
146 gf = gb;
147 bf = bb;
148 }
149 }
150 }
151 else {
152 int r;
153 r = (random()>>2) % 255;
154 if (r<ra) rf = ro; else rf=rb;
155 r = (random()>>2) % 255;
156 if (r<ga) gf = go; else gf=gb;
157 r = (random()>>2) % 255;
158 if (r<ba) bf = bo; else bf=bb;
159 }
160
161 /*
162 int total;
163 total = rf*65536+gf*256+bf;
164 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",
165 xb,yb,rf,gf,bf,total,rf,gf,bf);
166 */
167 printf("%d,%d: (%d,%d,%d)\n",xb,yb,rf,gf,bf);
168
169 }
170 }

  ViewVC Help
Powered by ViewVC 1.1.5