Reverted removal of 'const' from TagItem arrays/pointers in r50147
[AROS.git] / workbench / demos / images / datfilt.awk
blob1857d758a4c0e6f97b35bbde15721f99f760410b
1 BEGIN {
2 for (t=1; t<ARGC; t++)
4 fin=ARGV[t];
5 name=fin;
6 sub(/\..*$/,"",name);
7 fout=name ".h"
8 getline colors < fin;
10 depth=0;
11 bit=1;
13 while (bit < length(colors))
15 depth++;
16 bit*=2;
19 height=0;
20 width=0;
21 while ((getline line < fin) > 0)
23 pattern[height++] = line;
24 if (length(line)>width)
25 width=length(line);
28 printf ("Processing %s -> %s (%d x %d x %d)\n", fin, fout, width, height, depth);
30 for (y=0; y<height; y++)
32 line=pattern[y];
33 xoff=0;
35 while (line!="")
37 for (d=0; d<depth; d++)
38 out[y,xoff,d]=0;
40 left=substr(line,1,16);
41 line=substr(line,17);
42 bit=32768;
44 for (x=1; x<=16; x++)
46 cpen=substr(left,x,1);
48 if (cpen=="")
49 break;
51 pen=index(colors,cpen);
52 if (!pen)
54 printf ("Error: Unknown pen '%s' in file in line %d\n", cpen, y+2);
55 exit 10;
58 pen --;
60 for (d=0; d<depth; d++)
62 if (pen/2.0 != int(pen/2.0))
64 #printf ("Pos: %d/%d Plane:%d %04x\n", y, xoff, d, bit);
65 out[y,xoff,d]+=bit;
67 pen=int(pen/2);
70 bit=bit/2;
73 xoff ++;
77 printf ("") > fout;
79 NAME=toupper(name);
80 printf ("#define %s_WIDTH %d\n", NAME, width) >> fout;
81 printf ("#define %s_HEIGHT %d\n\n", NAME, height) >> fout;
83 # printf ("UWORD %sData[] =\n", name) >> fout;
84 printf ("UBYTE %sData[] =\n", name) >> fout;
86 printf ("{\n") >> fout;
87 xmax=int((width+15)/16);
88 pick=0;
89 bit=1;
90 for (d=0; d<depth; d++)
92 pick+=bit;
93 bit=bit*2;
94 for (y=0; y<height; y++)
96 printf (" ") >> fout;
98 for (x=0; x<xmax; x++)
100 # printf (" 0x%04X,", out[y,x,d]) >> fout;
101 printf (" 0x%02X,", out[y,x,d]/256) >> fout;
102 printf (" 0x%02X,", out[y,x,d]%256) >> fout;
105 printf ("\n") >> fout;
108 if (d+1!=depth)
109 printf ("\n") >> fout;
111 printf ("};\n\n") >> fout;
114 printf ("struct Image %sImage =\n{\n", name) >> fout;
115 printf (" 0, 0, /* Left, Top */\n") >> fout;
116 printf (" %s_WIDTH, %s_HEIGHT, /* Width, Height */\n", NAME, NAME) >> fout;
117 printf (" %d, /* Depth */\n", depth) >> fout;
118 printf (" (UWORD *)%sData, /* ImageData */\n", name) >> fout;
119 printf (" 0x%02X, /* PlanePick */\n", pick) >> fout;
120 printf (" 0x00, /* PlaneOnOff */\n") >> fout;
121 printf (" NULL /* NextImage */\n") >> fout;
122 printf ("};\n") >> fout;
124 close (fin);
125 close (fout);