Cartoon Scanner

This is a tool I use for scanning cartoons I rip from magazines. It can cut and rotate .ppm images and save parts in .jpg format. In order to build it, just go to the build/ directory and run jj. Move the resulting binary cartoscan to somewhere permanent.

There is no configuration file, all settings are taken from environment variables. It's best to put these settings in a shell script and run the program from there. Here is an example script:

#!/bin/sh
CARTOSCAN_SCANCMD="/home/dodo/bin/scan.sh @"
CARTOSCAN_OUTPUTDIR=/home/dodo/ciz
CARTOSCAN_SCANDIR=/tmp/scan
CARTOSCAN_OUTPUTPFX=yeni

export CARTOSCAN_SCANCMD
export CARTOSCAN_OUTPUTDIR
export CARTOSCAN_SCANDIR
export CARTOSCAN_OUTPUTPFX

/home/dodo/bin/cartoscan
_SCANCMD contains the command line to scan a new image. The '@' character in the command line is replaced by the full output file name. scanimage outputs to stdout when scanning a single image and cartoscan can't handle redirections in the _SCANCMD variable. Therefore, it's best to put the actual scan command into yet another script. Here is what I use:
#!/bin/sh
echo scanning

scanimage --format=pnm --mode='Color - 16 Million Colors' \
     --page-format=A4 --doc-source=Flatbed --resolution=600 > $1

echo done
The scanned images must be in the PPM format.

_SCANDIR defines where the scanned images will be stored.

_OUTPUTDIR and _OUTPUTPFX define how the output images will be stored. Saved images will have the path:

  <OUTPUTDIR>/<OUTPUTPFX><major>-<minor>.jpg

Things to Do

Autocrop isn't implemented. It's not very useful for scanned images because borders are never single color. There's always variation. Maybe I should just forget about it.

The rotation procedure I use here turns out to be somewhat broken. For very small angles, it won't do anything at all. Also, if you rotate a completely white (#FFffFF) image, it will generate some very light gray pattern in the image. This is quite disturbing. For scanned images, the pattern isn't noticable because there is already a lot of 'noise' in the input image.

I blank out saved parts of the input image. However, this blank-out area isn't modified by rotations. This results in incorrect blank-outs. This can be harmful to your original scanned image if not handled correctly. I had written the polygon filling stuff for this purpose, but got carried away with the rest of the program. I should update this sometime.

The .PPM reading library isn't very robust. If it encounters a premature EOF, the program will exit. The correct action is to show as much as you have, and print a warning about it.