4 //for f in picture.png scope.png; do
5 // pngtopam -alpha < $f > /tmp/a
6 // pngtopnm < $f | /tmp/a.out > /tmp/b
7 // pnmtopng -alpha=/tmp/a < /tmp/b > /tmp/data1/$f
9 int main(int ac, char **av)
14 fputs(fgets(line,sizeof(line),stdin),stdout);
15 } while( strcmp(line,"255\n") );
16 while( (r=getc(stdin)) >= 0 && (g=getc(stdin)) >= 0 && (b=getc(stdin)) >= 0 ) {
17 double rr = r/255., gg = g/255., bb = b/255.;
18 int y = (int)(( 0.29900*rr + 0.58700*gg + 0.11400*bb)*255. + 0.5);
19 int u = (int)((-0.16874*rr - 0.33126*gg + 0.50000*bb + 0.5) * 255. + 0.5);
20 int v = (int)(( 0.50000*rr - 0.41869*gg - 0.08131*bb + 0.5) * 255. + 0.5);
21 if( abs(u-0x80) < 2 && abs(v-0x80) < 2 && y <= 0x48 )
22 if( (y += 0x100-0x48) >= 0x100 ) y = 0x100-1;
23 double yy = y/255., uu = (u-128)/255., vv = (v-128)/255.;
24 r = (int)((yy + 1.40200*vv) * 255. + 0.5);
25 g = (int)((yy- 0.34414*uu - 0.71414*vv) * 255. + 0.5);
26 b = (int)((yy+ 1.77200*uu) * 255. + 0.5);
27 putc(r, stdout); putc(g, stdout); putc(b, stdout);