revert between 56095 -> 55830 in arch
[AROS.git] / workbench / demos / images / datfilt.awk
blob2b71f86f6663510c59cdc9c96130230fd785484c
1 BEGIN {
2 for (t=1; t<ARGC; t++)
4 fin=ARGV[t];
5 name=fin;
6 sub(/.*\//,"",name); # strip path
7 sub(/\..*$/,"",name);
8 fout=name ".h"
9 getline colors < fin;
11 depth=0;
12 bit=1;
14 while (bit < length(colors))
16 depth++;
17 bit*=2;
20 height=0;
21 width=0;
22 while ((getline line < fin) > 0)
24 pattern[height++] = line;
25 if (length(line)>width)
26 width=length(line);
29 printf ("Processing %s -> %s (%d x %d x %d)\n", fin, fout, width, height, depth);
31 for (y=0; y<height; y++)
33 line=pattern[y];
34 xoff=0;
36 while (line!="")
38 for (d=0; d<depth; d++)
39 out[y,xoff,d]=0;
41 left=substr(line,1,16);
42 line=substr(line,17);
43 bit=32768;
45 for (x=1; x<=16; x++)
47 cpen=substr(left,x,1);
49 if (cpen=="")
50 break;
52 pen=index(colors,cpen);
53 if (!pen)
55 printf ("Error: Unknown pen '%s' in file in line %d\n", cpen, y+2);
56 exit 10;
59 pen --;
61 for (d=0; d<depth; d++)
63 if (pen/2.0 != int(pen/2.0))
65 #printf ("Pos: %d/%d Plane:%d %04x\n", y, xoff, d, bit);
66 out[y,xoff,d]+=bit;
68 pen=int(pen/2);
71 bit=bit/2;
74 xoff ++;
78 printf ("") > fout;
80 NAME=toupper(name);
81 printf ("#define %s_WIDTH %d\n", NAME, width) >> fout;
82 printf ("#define %s_HEIGHT %d\n\n", NAME, height) >> fout;
84 # printf ("UWORD %sData[] =\n", name) >> fout;
85 printf ("UBYTE %sData[] =\n", name) >> fout;
87 printf ("{\n") >> fout;
88 xmax=int((width+15)/16);
89 pick=0;
90 bit=1;
91 for (d=0; d<depth; d++)
93 pick+=bit;
94 bit=bit*2;
95 for (y=0; y<height; y++)
97 printf (" ") >> fout;
99 for (x=0; x<xmax; x++)
101 # printf (" 0x%04X,", out[y,x,d]) >> fout;
102 printf (" 0x%02X,", out[y,x,d]/256) >> fout;
103 printf (" 0x%02X,", out[y,x,d]%256) >> fout;
106 printf ("\n") >> fout;
109 if (d+1!=depth)
110 printf ("\n") >> fout;
112 printf ("};\n\n") >> fout;
115 printf ("struct Image %sImage =\n{\n", name) >> fout;
116 printf (" 0, 0, /* Left, Top */\n") >> fout;
117 printf (" %s_WIDTH, %s_HEIGHT, /* Width, Height */\n", NAME, NAME) >> fout;
118 printf (" %d, /* Depth */\n", depth) >> fout;
119 printf (" (UWORD *)%sData, /* ImageData */\n", name) >> fout;
120 printf (" 0x%02X, /* PlanePick */\n", pick) >> fout;
121 printf (" 0x00, /* PlaneOnOff */\n") >> fout;
122 printf (" NULL /* NextImage */\n") >> fout;
123 printf ("};\n") >> fout;
125 close (fin);
126 close (fout);