MSL/conjure - Testing composite

Max <[email protected]> Mon, 6 Oct 2008 17:33:49 +0200
Newsgroups gmane.comp.video.graphicsmagick.bugs
Message-ID <20081006153349.GA14841@studiernix>
Here is a proposal for a script testing MSL/conjure.
It compares an image created with MSL to another image created with
composite.
If you see any red pixels in the result the test failed.
It's a quick hack but it might be all that is needed.

Any suggestions/comments?

Best regards
Max

On Mon, 29 Sep 2008, Bob Friesenhahn wrote:
> On Mon, 29 Sep 2008, Max wrote:
>
>> You mean for regression testing?
>> I'm just wondering how such a test looks like for an image processing
>> library?
>> You would have to compare the resulting image with an image that is
>> known to be correct, right?
>> Can you give me an easy example?
>
> I am not sure how to compare images using MSL.  The PerlMagick test  
> suite uses two means of comparison.  In some cases the computed image  
> signature string is used.  In other cases the output image is compared  
> against a reference image and some small error is allowed.
>
> For the utility tests, there is no comparison at all.  The test passes  
> if it runs through to completion without reporting an error.  Visual  
> inspection of the results is necessary.
>
> Since we already have the gruelling PerlMagick tests, the MSL tests  
> could be of the type where someone has to inspect the result to see that 
> they are correct.  In this situation, the MSL "tests" also act as a demo 
> and an example.  The person doing the inspection needs to know what the 
> results should be.
>
> Bob
>
>>
>> On Mon, 22 Sep 2008, Bob Friesenhahn wrote:
>>
>>> A way that you can help improve conjure quite a lot is to contribute
>>> some formal tests for it.  At the moment there are no MSL test scripts
>>> included at all, which means that MSL is not getting tested.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
Graphicsmagick-bugs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-bugs
composite_test.sh (application/x-sh, 4.4 KB)
#!/bin/bash

#Author: Max Hohenegger
#Last change: 2008-10-01
#Module: conjure, MSL
#Description: Test wether compositing images over a background image using
#             gravity delivers the same result using conjure (MSL) and convert

COMPOSITE_CMD="gm composite"
CONJURE_CMD="gm conjure"
#CONVERT_CMD="gm convert"
CONVERT_CMD="convert"
COMPARE_CMD="compare"
DISPLAY_CMD="gm display"

TEMP_DIR="/tmp"

FORMAT=".png"

BLANK="$TEMP_DIR/blank$FORMAT"
CENTER="$TEMP_DIR/Center$FORMAT"
NORTH="$TEMP_DIR/North$FORMAT"
NORTHEAST="$TEMP_DIR/NorthEast$FORMAT"
EAST="$TEMP_DIR/East$FORMAT"
SOUTHEAST="$TEMP_DIR/SouthEast$FORMAT"
SOUTH="$TEMP_DIR/South$FORMAT"
SOUTHWEST="$TEMP_DIR/SouthWest$FORMAT"
WEST="$TEMP_DIR/West$FORMAT"
NORTHWEST="$TEMP_DIR/NorthWest$FORMAT"

RESULT="$TEMP_DIR/result$FORMAT"
CONJURE_RESULT="$TEMP_DIR/conjure_result$FORMAT"
COMPARED="$TEMP_DIR/compared$FORMAT"


function draw_text ()
{
    TEMPFILE=$(tempfile)$FORMAT
    TEXT=$1
    TARGET=$2

    cat <<EOF >$TEMPFILE
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
    <style type="text/css"><![CDATA[ text {font-size:20px; text-anchor:middle;} ]]></style>
    <text x="50" y="50">$TEXT</text>
</svg>
EOF

    $CONVERT_CMD $TEMPFILE $TARGET || exit 1
    rm -f $TEMPFILE
}

function draw_blank ()
{
    TEMPFILE=$(tempfile)$FORMAT
    TARGET=$1

    cat <<EOF >$TEMPFILE
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="500" height="500"
 xmlns="http://www.w3.org/2000/svg">
</svg>
EOF

    $CONVERT_CMD $TEMPFILE $TARGET || exit 2
    rm -f $TEMPFILE
}

########################## PREPARE TEST OBJECTS ###########################
draw_blank $BLANK
draw_text "Center" $CENTER
draw_text "North" $NORTH
draw_text "NorthEast" $NORTHEAST
draw_text "East" $EAST
draw_text "SouthEast" $SOUTHEAST
draw_text "South" $SOUTH
draw_text "SouthWest" $SOUTHWEST
draw_text "West" $WEST
draw_text "NorthWest" $NORTHWEST

########################## CREATE TEST BASE ###########################
cp $BLANK $RESULT
$COMPOSITE_CMD $CENTER    $RESULT -gravity Center    $RESULT || exit 3
$COMPOSITE_CMD $NORTH     $RESULT -gravity North     $RESULT || exit 3
$COMPOSITE_CMD $NORTHEAST $RESULT -gravity NorthEast $RESULT || exit 3
$COMPOSITE_CMD $EAST      $RESULT -gravity East      $RESULT || exit 3
$COMPOSITE_CMD $SOUTHEAST $RESULT -gravity SouthEast $RESULT || exit 3
$COMPOSITE_CMD $SOUTH     $RESULT -gravity South     $RESULT || exit 3
$COMPOSITE_CMD $SOUTHWEST $RESULT -gravity SouthWest $RESULT || exit 3
$COMPOSITE_CMD $WEST      $RESULT -gravity West      $RESULT || exit 3
$COMPOSITE_CMD $NORTHWEST $RESULT -gravity NorthWest $RESULT || exit 3

########################## CREATE TEST OBJECT ###########################
TEMPFILE=$(tempfile).msl
cat <<EOF >$TEMPFILE
<?xml version="1.0" encoding="utf-8" ?>
<group>
    <image id="1"><read filename="$CENTER"/></image>
    <image id="2"><read filename="$NORTH"/></image>
    <image id="3"><read filename="$NORTHEAST"/></image>
    <image id="4"><read filename="$EAST"/></image>
    <image id="5"><read filename="$SOUTHEAST"/></image>
    <image id="6"><read filename="$SOUTH"/></image>
    <image id="7"><read filename="$SOUTHWEST"/></image>
    <image id="8"><read filename="$WEST"/></image>
    <image id="9"><read filename="$NORTHWEST"/></image>
    <image>
        <read filename="$BLANK"/>
        <composite image="1" gravity="Center"/>
        <composite image="2" gravity="North"/>
        <composite image="3" gravity="NorthEast"/>
        <composite image="4" gravity="East"/>
        <composite image="5" gravity="SouthEast"/>
        <composite image="6" gravity="South"/>
        <composite image="7" gravity="SouthWest"/>
        <composite image="8" gravity="West"/>
        <composite image="9" gravity="NorthWest"/>
    </image>
    <write filename="$CONJURE_RESULT"/>
</group>
EOF
#TODO: For some reason conjure keeps returning exit code 1
$CONJURE_CMD $TEMPFILE #|| exit 4
rm -f $TEMPFILE

################### COMPARE TEST OBJECT TO TESTBASE #########################

#gm display $RESULT
#gm display $CONJURE_RESULT

#diff --report-identical-files $RESULT $CONJURE_RESULT
$COMPARE_CMD $RESULT $CONJURE_RESULT $COMPARED || exit 5
$DISPLAY_CMD $COMPARED || exit 6

exit 0