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

Contents of /eyes/combinify.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Wed Apr 9 03:45:44 2014 UTC (4 years, 6 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +6 -2 lines
File MIME type: text/plain
als is complete
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
10
11
12
13
14 inline void outit(int x,int y,int *arrays,int arraycount,int xsize,int ysize) {
15 /* figure out weight and place weights in order */
16 if (arraycount==0) return;
17 if (x>=xsize) return;
18 if (y>=ysize) return;
19 int sum;
20 int i;
21 sum=arrays[0+3];
22 for (i=1;i<arraycount;i++) {
23 int q=arrays[i*4+3];
24 sum+= q;
25 arrays[i*4+3]=sum;
26 }
27 if (sum==0) return;
28 int r;
29 r = rand() % sum;
30 for (i=0;i<arraycount;i++) {
31 if (r<=arrays[i*4+3]) {
32 int rf,gf,bf;
33 // int total;
34 rf = arrays[i*4];
35 gf = arrays[i*4+1];
36 bf = arrays[i*4+2];
37 /* total = rf*65536+gf*256+bf;
38 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",
39 x,y,rf,gf,bf,total,rf,gf,bf);
40 It is a little quicker to not add the comments. In fact it is alot quicker.
41 */
42 printf("%d,%d: (%d,%d,%d)\n",
43 x,y,rf,gf,bf);
44 return;
45 } /* if we found it */
46 } /* for each record */
47 /* should NEVAR get here */
48 }
49
50
51
52
53
54 /* usage randomify xsize ysize seed basefile pixelfile alphafile [hologramfile] */
55 int main (int argc,char *argv[]) {
56 int xsize;
57 int ysize;
58 int arrays[100000];
59 int arraycount=0;
60 int oldxb=-1;
61 int oldyb=-1;
62 char basebuf[200000];
63 if (argc==4) {
64 xsize=atoi(argv[1]);
65 ysize=atoi(argv[2]);
66 srand(atoi(argv[3]));
67 }
68 else {
69 fprintf(stderr,"usage cabonify xsize ysize seed\n"
70 "Where file has Y|X|col|row|r|g|b|freq text format\n");
71 exit(-1);
72 }
73 printf("# ImageMagick pixel enumeration: %d,%d,65535,rgb\n",xsize,ysize);
74 while (gets(basebuf)) {
75 char *q;
76 int xb,yb,rb,gb,bb;
77 int xo,yo,ro,go,bo;
78 int xa,ya,ra,ga,ba;
79 int hb;
80 int weight;
81 yb = fieldi(basebuf,0);
82 xb = fieldi(basebuf,1);
83 rb = fieldi(basebuf,4);
84 gb = fieldi(basebuf,5);
85 bb = fieldi(basebuf,6);
86 weight = fieldi(basebuf,7);
87 if ((xb != oldxb)||(yb != oldyb)) {
88 outit(oldxb,oldyb,arrays,arraycount,xsize,ysize);
89 arraycount=0;
90 oldxb=xb;
91 oldyb=yb;
92 }
93 int ac;
94 int sum;
95 ac = arraycount*4;
96 arrays[ac++]=rb;
97 arrays[ac++]=gb;
98 arrays[ac++]=bb;
99 arrays[ac++]=weight;
100 arraycount++;
101 }
102 outit(oldxb,oldyb,arrays,arraycount,xsize,ysize);
103 }

  ViewVC Help
Powered by ViewVC 1.1.5