DrawSkewY oddity in 6.5.4-0

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

DrawSkewY oddity in 6.5.4-0

Post by rmagick »

The following program tries to replicate the SVG "Skew" example here http://www.w3.org/TR/SVG11/coords.html# ... rixDefined, but the X axis in the skewY coordinate system is wrong. Here's the target image:
Image

Here's the output from my test:
Image

Here's the program I used to create the image. Please let me know if you need any more information.

Code: Select all

// gcc `MagickWand-config --cflags --cppflags` -o skew skew.c `MagickWand-config --ldflags --libs`
#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>

int main(int argc, char **argv)
{
    MagickWand *wand;
    DrawingWand *drawing;
    PixelWand *none, *white, *black, *red, *blue;

    MagickWandGenesis();

    none = NewPixelWand();
    PixelSetColor(none, "none");
    red = NewPixelWand();
    PixelSetColor(red, "red");
    black = NewPixelWand();
    PixelSetColor(black, "black");
    white = NewPixelWand();
    PixelSetColor(white, "white");
    blue = NewPixelWand();
    PixelSetColor(blue, "blue");

    drawing = NewDrawingWand();

    // Draw the axes of the original coordinate system.
    PushDrawingWand(drawing);
        DrawSetFillColor(drawing, none);
        DrawSetStrokeColor(drawing, black);
        DrawSetStrokeWidth(drawing, 3.0);
        DrawLine(drawing, 0.0, 1.5, 400.0, 1.5);
        DrawLine(drawing, 1.5, 0.0, 1.5, 120.0);
    PopDrawingWand(drawing);

    // Establish a new coordinate system whose origin is at (30,30) in the
    // initial coord. system and which is skewed in X by 30 degrees.
    PushDrawingWand(drawing);
        DrawTranslate(drawing, 30.0, 30.0);
        DrawSkewX(drawing, 30.0);
        PushDrawingWand(drawing);
            DrawSetFillColor(drawing, none);
            DrawSetStrokeColor(drawing, red);
            DrawSetStrokeWidth(drawing, 3.0);
            DrawLine(drawing, 0.0, 0.0, 50.0, 0.0);
            DrawLine(drawing, 0.0, 0.0, 0.0, 50.0);
        PopDrawingWand(drawing);
        PushDrawingWand(drawing);
            DrawSetFontFamily(drawing, "Verdana");
            DrawSetFontSize(drawing, 20.0);
            DrawSetFontWeight(drawing, 400ul);
            DrawSetFontStyle(drawing, NormalStyle);
            DrawSetFillColor(drawing, blue);
            DrawSetStrokeColor(drawing, none);
            DrawAnnotation(drawing, 0.0, 0.0, "ABC (skewX)");
        PopDrawingWand(drawing);
    PopDrawingWand(drawing);

    // Establish a new coordinate system whose origin is at (200, 30) in the
    // initial coord. system and which is skewed in Y by 30 degrees.
    PushDrawingWand(drawing);
        DrawTranslate(drawing, 200.0, 30.0);
        DrawSkewY(drawing, 30.0);
        PushDrawingWand(drawing);
            DrawSetFillColor(drawing, none);
            DrawSetStrokeColor(drawing, red);
            DrawSetStrokeWidth(drawing, 3.0);
            DrawLine(drawing, 0.0, 0.0, 50.0, 0.0);
            DrawLine(drawing, 0.0, 0.0, 0.0, 50.0);
        PopDrawingWand(drawing);
        PushDrawingWand(drawing);
            DrawSetFontFamily(drawing, "Verdana");
            DrawSetFontSize(drawing, 20.0);
            DrawSetFontWeight(drawing, 400ul);
            DrawSetFontStyle(drawing, NormalStyle);
            DrawSetFillColor(drawing, blue);
            DrawSetStrokeColor(drawing, none);
            DrawAnnotation(drawing, 0.0, 0.0, "ABC (skewY)");
        PopDrawingWand(drawing);
    PopDrawingWand(drawing);


    wand = NewMagickWand();
    MagickNewImage(wand, 400, 120, white);
    MagickDrawImage(wand, drawing);
    MagickWriteImage(wand, "Skew.gif");

    DestroyDrawingWand(drawing);
    DestroyMagickWand(wand);
    DestroyPixelWand(none);
    DestroyPixelWand(blue);
    DestroyPixelWand(white);
    DestroyPixelWand(black);
    DestroyPixelWand(red);

    MagickWandTerminus();
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: DrawSkewY oddity in 6.5.4-0

Post by magick »

Add
  • MagickWriteImage(wand, "Skew.mvg");
after your write to Skew.gif. Now type this command:
  • convert msvg:Skew.svg reference.mvg
Now compare Skew.mvg to reference.mvg. The key to success is to get your program to produce essentially the same output as reference.mvg. If you make an effort and can't get it to work, post your progress here and we'll take a closer look at the problem.
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: DrawSkewY oddity in 6.5.4-0

Post by rmagick »

I'll give that a try. Thanks for the tip.
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: DrawSkewY oddity in 6.5.4-0

Post by rmagick »

Here's a simplified version of the skew y problem. Notice that the Y-axis is skewed 60 degrees instead of 30.

Code: Select all

/*
 *  gcc `MagickWand-config --cflags --cppflags` -o skewybug skewybug.c `MagickWand-config --ldflags --libs`
 */
#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>

int main(int argc, char **argv)
{
    MagickWand *wand;
    DrawingWand *drawing;
    PixelWand *none, *white, *red;

    MagickWandGenesis();

    none = NewPixelWand();
    PixelSetColor(none, "none");
    red = NewPixelWand();
    PixelSetColor(red, "red");
    white = NewPixelWand();
    PixelSetColor(white, "white");

    drawing = NewDrawingWand();

    DrawTranslate(drawing, 200.0, 30.0);
    DrawSkewY(drawing, 30.0);
    DrawSetStrokeColor(drawing, red);
    DrawSetStrokeWidth(drawing, 3.0);
    DrawLine(drawing, 0.0, 0.0, 50.0, 0.0);
    DrawLine(drawing, 0.0, 0.0, 0.0, 50.0);

    wand = NewMagickWand();
    MagickNewImage(wand, 400, 120, white);
    MagickDrawImage(wand, drawing);
    MagickWriteImage(wand, "skewybug.png");
    MagickWriteImage(wand, "skewybug.mvg");

    DestroyDrawingWand(drawing);
    DestroyMagickWand(wand);
    DestroyPixelWand(none);
    DestroyPixelWand(white);
    DestroyPixelWand(red);

    MagickWandTerminus();
}
Here's the skewybug.mvg file:

Code: Select all

translate 200,30
affine 1,0.57735,0,1,0,0
skewY 30
stroke '#FFFF00000000'
stroke-width 3
line 0,0 50,0
line 0,0 0,50
I notice that manually removing the affine command that DrawSkewY adds fixes the problem.
Here's the skewybug.png file:
Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: DrawSkewY oddity in 6.5.4-0

Post by magick »

We can reproduce the problem you reported and have a patch in the Subversion trunk available sometime tomorrow. The patch will also be in the next point release of ImageMagick. Thanks.
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: DrawSkewY oddity in 6.5.4-0

Post by rmagick »

Thanks for both fixes!
Post Reply