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

Contents of /eyes/clean_up_alpha.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sat Nov 12 21:32:04 2011 UTC (6 years, 10 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
added clean_up_alpha.c
1 /* When making a grey scale alpha rendition, for whatever reason, there are spots where color still
2 exists. It is consuming to fille these in by hand. So this program filles them in with a random walk.
3 */
4
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <math.h>
9
10 #include "util.h"
11
12
13
14
15
16 /* usage tilify xsize ysize seed basefile */
17 int main (int argc,char *argv[]) {
18 int xsize;
19 int ysize;
20 if (argc==4) {
21 xsize=atoi(argv[1]);
22 ysize=atoi(argv[2]);
23 srand(atoi(argv[3]));
24 }
25 else {
26 fprintf(stderr,"usage clean_up_alpha xsize ysize random_seed\n"
27 "Where file has x|y|r|g|b text format\n");
28 exit(-1);
29 }
30 FILE *base;
31 base = stdin;
32 char basebuf[10001];
33 char otherbuf[10001];
34 char alphabuf[10001];
35 char hologrambuf[10001];
36 unsigned char *a = (unsigned char *)malloc(sizeof(unsigned char)*3*xsize*ysize);
37
38
39
40
41 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
42 while (fgets(basebuf,10000,base)) {
43 char *q;
44 int xb,yb,rb,gb,bb;
45 int xo,yo,ro,go,bo;
46 int xa,ya,ra,ga,ba;
47 int hb;
48 xb = fieldi(basebuf,0);
49 yb = fieldi(basebuf,1);
50 rb = fieldi(basebuf,2);
51 gb = fieldi(basebuf,3);
52 bb = fieldi(basebuf,4);
53 int loc= (yb*xsize+xb);
54 loc = loc+loc+loc;
55 a[loc++] = rb;
56 a[loc++] = gb;
57 a[loc++] = bb;
58 }
59
60
61 int x,y;
62 for (y=0;y<ysize;y++) {
63 for (x=0;x<xsize;x++) {
64 int loc = (y*xsize +x)*3;
65 int r,g,b;
66 int x2,y2;
67 x2 = x;
68 y2 = y;
69 do {
70 int loc2 = (y2*xsize +x2)*3;
71 r=a[loc2];
72 g=a[loc2+1];
73 b=a[loc2+2];
74 if ((r != g)||(r != b)/*||((r==0)&&(g==0)&&(b==0))*/) {
75 int dir= (rand()>>2)%8;
76 /* 0 1 2
77 7 3
78 6 5 4 */
79 if ((dir<=2)&&(y2>0)) y2--; /* possible up */
80 if (((dir==4)||(dir==5)||(dir==6)) && (y2 <ysize-1)) y2++; /* or down */
81 if (((dir==0)||(dir==6)||(dir==7)) && (x2 >0)) x2--; /* or left */
82 if (((dir==2)||(dir==3)||(dir==4)) && (x2 <xsize-1)) x2++; /* or right */
83 continue;
84 }
85 /* were good here - the pixel is grey */
86 break;
87 } while (1);
88 int rf,gf,bf;
89 rf = r;
90 gf = g;
91 bf = b;
92 int total;
93 total = rf*65536+gf*256+bf;
94 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",
95 x,y,rf,gf,bf,total,rf,gf,bf);
96 } /* for x */
97 } /* for y */
98
99
100 exit(0);
101 }
102
103
104
105

  ViewVC Help
Powered by ViewVC 1.1.5