diff --git a/2018/bellard/Makefile b/2018/bellard/Makefile index 725a85d8a..b2b493290 100644 --- a/2018/bellard/Makefile +++ b/2018/bellard/Makefile @@ -115,8 +115,8 @@ OBJ= ${PROG}.o DATA= fruits.bin lena512.bin vintage_cars.bin Lenna.png TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# @@ -139,6 +139,9 @@ ${PROG}: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + # data files # data: ${DATA} diff --git a/2018/bellard/README.md b/2018/bellard/README.md index c481b35bf..fda2b493e 100644 --- a/2018/bellard/README.md +++ b/2018/bellard/README.md @@ -4,6 +4,9 @@ make ``` +There is an alternate version that should work with Windows. See [Alternate +code](#alternate-code) below. + ## To use: @@ -18,9 +21,35 @@ make eog lena.ppm # On Linux open -a Preview lena.ppm # On macOS -pngtopnm < Lenna.png | pnmscale 0.25 | cjpeg -arithmetic -dct float -quality 14 > small.jpg +pngtopam < Lenna.png | pnmscale 0.25 | cjpeg -arithmetic -dct float -quality 14 > small.jpg ``` -### NOTE: Lenna.png is from https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png + +NOTE: `pngtopam(1)` (or `pngtopnm(1)` for older versions) and `pnmscale` come from +the netpbm project and `cjpeg(1)` comes from `libjpeg-turbo`. If you don't have +these tools already see [FAQ 3.15 - How do I compile and install netpbm for +entries that require it?](/faq.md#netpbm) and [FAQ 3.16 - How do I compile and +install libjpeg-turbo for entries that require it?](/faq.md#libjpeg). + +NOTE: [Lenna.png](Lenna.png) is from +. + + +## Alternate code: + +The [prog.alt.c](prog.alt.c) is based on the author's remarks and it should work +for Windows. + + +### Alternate build: + +```sh +make alt +``` + + +### Alternate use: + +Use `prog.alt` as you would `prog`. ## Judges' remarks: @@ -67,7 +96,7 @@ as the algorithms already have a significant complexity. Although the program was optimized to decompress its built-in image, it accepts to decompress image files from its standard input. Examples: -\ + ```sh ./prog d < lena512.bin > lena512.ppm ./prog d < fruits.bin > fruits.ppm diff --git a/2018/bellard/prog.alt.c b/2018/bellard/prog.alt.c new file mode 100644 index 000000000..a4253eb87 --- /dev/null +++ b/2018/bellard/prog.alt.c @@ -0,0 +1,137 @@ +#include +#include +#include +#define e(a, d) for(a=0;a; ?{ c; ; W; ; l; } h} p} i{ % } P} /{ *}  % L; ; !{  S{ n }  " +" x;  { 1  J; v{ U} ({ @ X{ k} H; 4; e J 6; ; v; G{ { ] &{ A d{ l M{ ; K ;; 4 -{ }} p h{ ; { r W; v{ ; f} } 1{ ^ &{ 9{ { ; ~; n; q{ 9  R 6{ { u; a; ; U; ; Y} +} } 2 s k; 8 { J K; ' i; ; $; W{ P !{ { { P } [; (; Q; U n; +}  g{ C; { { ; <{ v  S} b; 6 ` } ?{ + %; } n; q{ r} k; ; { c{ S} 2} ~{ 4; R W v}  R; k I} |;  d; [ O} 5; ; ; } Z d {  { &; h o{ V v ; _{ { /} F{ f{ r{ 4{ { ?{ 4; S} :; ] ; E} ; &} # e !{ >{ H; { O{ 0; } H; p ; w}  >{ 1} { -} 4 ; " +"S} } u L{ y} %; 2  |{ (} /; ,{  )} Y; g} G} v; T} }; } i {{ }; [{ E{ q} g; T{ ={ } R; k{ j; _; h} g P c; ({ F; 6} }} 3 ,} <; 0  P; { ' t} u} ; } U} s{ 8{ E}  >{ } E { G { H :{  Y o g} } F D{ R{ -; M ?; = q} _ U { ;  I  { |{ { }   1{ ,} { x{ { U{ s; J} }  6{ > 7 ; ,{ D{ {{ ; ]} ; M; &} { V}  n{ & T ~; ({ } [; r{ # u{ X 9; L; U f} )}  { T}  p{ N; >{ > }  } D} m { 1{ { } X ; o} w} $} ^ v} K  f ,} ^ 3; { @{ _} _{ o; 4} h} H; # .{ {} ; <{ { G{ $; { " +"z { a{ { D; ? |} { { ; `}  } Q} j; 4}  3{ Q} { * ; } r{ a} } R { p @;  N{ { f; A; 8} L $} { } } J{ } k{ r}  { [; -; p{ I{  { &} J; T} ?{ Z{ >; 5 >; ];  w z ^} u; ); H} ; L &; V E{ 1{ g; C}  V} ~; U; ^{ J; { /} {; (} y} a K  /} .} ; K; N{ w{ `{ }  T{ l `; #; N{ l X; ?; +} {  w{ ; q; z; _; y} 8}  &{ X} V{ W G}  ,; [} U{ v{ Q; w{  [  Y} N Y u i{ { ! A{ }{ b 0; X ~} ; -; 8{ E  } ; F{ y {} {  "; +int y[3][1<<20],i[2048],X[166],p,r=1,f,s,O,P; +Q(){ +int b; +r*=s; +p*=s; +if(s>>9){ +if(b=*x){ +p+=b-1-(b>10)-(b>13)-(b>34)-(b>92)<<4; +b=x[1]; +x+=2; +p+=b<33?(b^8)*2%5:(b^6)%3*4+(*x++^8)*2%5+4; +} +} +else{ +b=getchar(); +p+=b<0?0:b; +} +} +t(E){ +int u,k,F,*m; +if(r=u){ +p-=u; +r-=u; +} +else r=u; +m[k]++; +if(F>63){ +*m/=2; +m[1]/=2; +} +return k; +} +n(E){ +int a,b; +a=0; +while(!t(E+a))a++; +b=1; +while(a--)b=b<<1|t(4); +return b-1; +} +R(S,Y,T,Z,U,d,V)int*S,*T; +{ +int G,a,j,H; +e(H,d)e(a,d){ +G=0; +e(j,d)G+=T[j*Z+H*U]*lrint(cos(acos(-1)/d*(a+0.5)*j)*sqrt(2-!j)*1024); +S[a*Y+H*U]=G+(1<>V; +} +} +W(z,l,g){ +int v,a,j,I,d,k,A,*o,c,B,q,C,h,w,J; +if(g>5||g>2&&t(g-3)){ +c=1<<--g; +e(a,4)W(z+a%2*c,l+a/2*c,g); +} +else{ +c=1<0; +e(a,d)i[a]=0; +e(a,d){ +if(t(61+g*2+B))break; +a+=n(5+B*10); +k=1-2*t(3); +i[a]=k*(n(25+(B+(a>3)+j+I; +if(k=h<0)h=(h*8+w/2)/w-2; +h=h>3; +} +} +} +} +} +K(b){ +putchar(b<0?0:b>255?255:b); +} +main(D){ +int a,l,L,M,g,N; +_setmode(0, 32768); _setmode(1, 32768); +s=D>1?256:1968; +Q(); +g=n(5); +f=1<[2018/ciura](/2018/ciura/prog.c) ([README.md](/2018/ciura/README.md))