Add 2018/bellard/try.sh
This commit is contained in:
1 parent
35ca2f8d1f
commit
485b24beab
3 files changed
+68
-14
No files matched your search
+11
-9
@@ -17,18 +17,20 @@ code](#alternate-code) below.
|
|||||||
|
|
||||||
## Try:
|
## Try:
|
||||||
|
|
||||||
```sh
|
First open [Lenna.png](Lenna.png) in your graphics viewer of choice. Next, after
|
||||||
eog lena.ppm # On Linux
|
running the above command (`./prog > lena.ppm`), open `lena.ppm` in your
|
||||||
open -a Preview lena.ppm # On macOS
|
graphics viewer of choice. After that try:
|
||||||
|
|
||||||
pngtopam < Lenna.png | pnmscale 0.25 | cjpeg -arithmetic -dct float -quality 14 > small.jpg
|
```sh
|
||||||
|
./try.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
NOTE: `pngtopam(1)` (or `pngtopnm(1)` for older versions) and `pnmscale` come from
|
NOTE: the script uses the tools `pngtopam(1)` (or `pngtopnm(1)` for older
|
||||||
the netpbm project and `cjpeg(1)` comes from `libjpeg-turbo`. If you don't have
|
versions) and `pnmscale` come from the netpbm project and `cjpeg(1)` comes from
|
||||||
these tools already see [FAQ 3.15 - How do I compile and install netpbm for
|
`libjpeg-turbo`. If you don't have these tools already see [FAQ 3.15 - How do I
|
||||||
entries that require it?](/faq.md#netpbm) and [FAQ 3.16 - How do I compile and
|
compile and install netpbm for entries that require it?](/faq.md#netpbm) and
|
||||||
install libjpeg-turbo for entries that require it?](/faq.md#libjpeg).
|
[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
|
NOTE: [Lenna.png](Lenna.png) is from
|
||||||
<https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png>.
|
<https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png>.
|
||||||
|
|||||||
Executable
+50
@@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# try.sh - demonstrate IOCCC winner 2018/bellard
|
||||||
|
#
|
||||||
|
|
||||||
|
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
|
||||||
|
# this way allows us to have the user specify a different compiler in an easy
|
||||||
|
# way.
|
||||||
|
[[ -z "$CC" ]] && CC="cc"
|
||||||
|
|
||||||
|
make CC="$CC" all >/dev/null || exit 1
|
||||||
|
|
||||||
|
# clear screen after compilation so that only the entry is shown
|
||||||
|
clear
|
||||||
|
|
||||||
|
# find out if we have necessary tools
|
||||||
|
PNGTOPAM="$(type -P pngtopam)"
|
||||||
|
PNMSCALE="$(type -P pnmscale)"
|
||||||
|
PNGTOPNM="$(type -P pngtopnm)"
|
||||||
|
CJPEG="$(type -P cjpeg)"
|
||||||
|
|
||||||
|
rm -f small.jpg
|
||||||
|
|
||||||
|
if [[ -n "$PNGTOPAM" && -n "$PNMSCALE" && -n "$CJPEG" ]]; then
|
||||||
|
echo "$ $PNGTOPAM < Lenna.png | $PNMSCALE 0.25 | $CJPEG -arithmetic -dct float -quality 14 > small.jpg" 1>&2
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo 1>&2
|
||||||
|
"$PNGTOPAM" < Lenna.png | "$PNMSCALE" 0.25 | "$CJPEG" -arithmetic -dct float -quality 14 > small.jpg
|
||||||
|
if [[ -f small.jpg ]]; then
|
||||||
|
echo "Now open small.jpg in your graphics viewer of choice." 1>&2
|
||||||
|
fi
|
||||||
|
elif [[ -n "$PNGTOPNM" && -n "$PNMSCALE" && -n "$CJPEG" ]]; then
|
||||||
|
echo "$ $PNGTOPNM < Lenna.png | $PNMSCALE 0.25 | $CJPEG -arithmetic -dct float -quality 14 > small.jpg" 1>&2
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo 1>&2
|
||||||
|
"$PNGTOPNM" < Lenna.png | "$PNMSCALE" 0.25 | "$CJPEG" -arithmetic -dct float -quality 14 > small.jpg
|
||||||
|
if [[ -f small.jpg ]]; then
|
||||||
|
echo "Now open small.jpg in your graphics viewer of choice." 1>&2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ -z "$PNGTOPAM" || -z "$PNGTOPNM" || "$PNMSCALE" ]]; then
|
||||||
|
echo "Cannot find pngtopam(1) or pnmscale(1). Try installing netpbm first." 1>&2
|
||||||
|
echo "See https://github.com/ioccc-src/temp-test-ioccc/blob/master/faq.md#netpbm" 1>&2
|
||||||
|
echo 1>&2
|
||||||
|
fi
|
||||||
|
if [[ -z "$CJPEG" ]]; then
|
||||||
|
echo "Cannot find cjpeg. Try installing libjpeg-turbo." 1>&2
|
||||||
|
echo "See https://github.com/ioccc-src/temp-test-ioccc/blob/master/faq.md#libjpeg." 1>&2
|
||||||
|
echo 1>&2
|
||||||
|
fi
|
||||||
+7
-5
@@ -4364,11 +4364,13 @@ He also added the [try.sh](/2015/yang/try.sh) script.
|
|||||||
|
|
||||||
## <a name="2018_bellard"></a>[2018/bellard](/2018/bellard/prog.c) ([README.md](/2018/bellard/README.md))
|
## <a name="2018_bellard"></a>[2018/bellard](/2018/bellard/prog.c) ([README.md](/2018/bellard/README.md))
|
||||||
|
|
||||||
[Cody](#cody), out of abundance of caution, added a second arg to `main()`
|
[Cody](#cody) added the [try.sh](/2018/bellard/try.sh) script.
|
||||||
because some versions of clang object to the number of args of `main()`, saying
|
|
||||||
that it must be 0, 2 or 3. The version this has been observed in does not
|
Cody also, out of abundance of caution, added a second arg to `main()` because
|
||||||
actually object to 1 arg but it is entirely possible that this changes so a
|
some versions of clang object to the number of args of `main()`, saying that it
|
||||||
second arg (that's not needed and is unused) has been added just in case.
|
must be 0, 2 or 3. The version this has been observed in does not actually
|
||||||
|
object to 1 arg but it is entirely possible that this changes so a second arg
|
||||||
|
(that's not needed and is unused) has been added just in case.
|
||||||
|
|
||||||
Cody also added explicit linking of libm (`-lm`) for systems that do not do this
|
Cody also added explicit linking of libm (`-lm`) for systems that do not do this
|
||||||
(Linux doesn't seem to but macOS does).
|
(Linux doesn't seem to but macOS does).
|
||||||
|
|||||||
Reference in new issue
Block a user