[cups-devel] distortions in imagetoraster
Toomas Rosin
toomas at toomas.lan
Sun Apr 19 05:46:14 PDT 2015
Hello!
Recently I tried to print a 89x99 image that had, on the white
background, only a row of black pixels at the top and another at the
bottom. To my surprise, it did not print correctly: the upper row was
missing in the printout. In my experiments with different images with
one pixel row and/or column at the edges of the image, and with
different CUPS options, imagetoraster always cut off the top row and, in
most cases, also distorted the lower row and the right column. The left
column always printed correctly.
The results varied slightly depending on whether I passed the name of
the PPD file to imagetoraster via its environment.
On my system (cups 2.0.2, cups-filters 1.0.66, HP DeskJet 1280)
imagetoraster sets `zoom_type' to CUPS_IZOOM_FAST; changing it
manually (under gdb) to CUPS_IZOOM_NORMAL before continuing with
_cupsImageZoomNew() did not change anything.
I tried to examine the code after the comment "Then write image
data..." near line 1294 in cups-filters/filter/imagetoraster.c, but
could not quite figure out what exactly was being done there.
I am appending a Bash script that demonstrates the issue. It uses
"composite" from ImageMagick for creating test images, and RasterView
for viewing the resulting rasters. Ideally, the rasters should show
white squares with 1-pixel black borders, but the real results were
different, at least on my system.
What's going on?
Cheers,
T.
---------------- 8< ---------------- 8< ----------------
#! /bin/bash
cd /tmp
trap 'rm -f $$.png $$.ras' EXIT
PPD=/etc/cups/ppd/HP_Deskjet_1280.ppd
IMAGETORASTER=/usr/lib/cups/filter/imagetoraster
if [ ! -e $PPD ]; then
echo Edit "$0", setting PPD on line 6 to an existing PPD file
exit 1
fi
if [ ! -x $IMAGETORASTER ]; then
echo Edit "$0", setting IMAGETORASTER on line 7 to the location of the imagetoraster binary
exit 1
fi
# Create a quadratic white square with a 1-pixel black border, create
# a CUPS raster file from the image, and show it with RasterView.
# Arguments: $1 --- side of the square and the black frame in pixels;
# all the following arguments are passed to imagetoraster as CUPS
# options.
doraster () {
local side=$1; shift
local options=$*
rm -f $$.png $$.ras
local white=$((side-2))
composite \
-size ${white}x${white} xc:white \
-size ${side}x${side} xc:black \
-geometry +1+1 $$.png
$IMAGETORASTER x x x 1 "$options" $$.png > $$.ras 2> /dev/null
rasterview $$.ras
}
# Same as above, but with PPD set in the environment.
doraster-p () {
PPD=$PPD doraster "$@"
}
experiment () {
local command=$1; shift
local result=$1; shift
echo $command
echo expecting result: $result
read
$command
}
# Results.
experiment \
"doraster 4" \
"upper side missing, lower side too thick"
experiment \
"doraster 4 natural-scaling=100" \
"only left and lower sides present"
experiment \
"doraster-p 4 natural-scaling=100" \
"upper side missing, lower side too thick, right side too thin"
# imagetoraster sets img->xppi and img->yppi to 128; this means that
# with side == 32 and natural-scaling == 25, the cups_izoom_t
# structure it generates is of "natural size", i.e. has as many pixels
# as the image itself.
experiment \
"doraster 32 natural-scaling=25" \
"only left side present"
experiment \
"doraster-p 32 natural-scaling=25" \
"only left and lower sides present"
More information about the cups
mailing list