Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,11 @@
function setrgb {
_.r=$1
_.g=$2
_.b=$3
}
function grayscale {
integer x=$(( round( 0.2126*_.r + 0.7152*_.g + 0.0722*_.b ) ))
_.r=$x
_.g=$x
_.b=$x
}

View file

@ -0,0 +1,39 @@
function grayscale {
RGBColor_t c
for ((y=0; y<_.height; y++)); do
for ((x=0; x<_.width; x++)); do
c.setrgb ${_.data[y][x]}
c.grayscale
_.data[y][x]=$(c.to_s)
done
done
}
function read {
exec 4<"$1"
typeset filetype
read -u4 filetype
if [[ $filetype != "P3" ]]; then
print -u2 "error: I can only read P3 type PPM files"
else
read -u4 _.width _.height
integer maxval
read -u4 maxval
integer x y r g b
typeset -a bytes
for ((y=0; y<_.height; y++)); do
read -u4 -A bytes
for ((x=0; x<_.width; x++)); do
r=${bytes[3*x+0]}
g=${bytes[3*x+1]}
b=${bytes[3*x+2]}
if (( r > maxval || g > maxval || b > maxval )); then
print -u2 "error: invalid color ($r $g $b), max=$maxval"
return 1
fi
_.data[y][x]="$r $g $b"
done
done
fi
exec 4<&-
}

View file

@ -0,0 +1,13 @@
Bitmap_t c
c.read "$HOME/tmp/bitmap.ppm"
c.to_s
if [[ $(c.to_s) == $(cat "$HOME/tmp/bitmap.ppm") ]]; then
echo looks OK
else
echo something is wrong
fi
c.grayscale
c.to_s
c.write "$HOME/tmp/bitmap_g.ppm"