List Info

Thread: matrix on gradients




matrix on gradients
user name
2006-07-05 22:12:28
Hi,
I've seen that the svg gradients are affected by the matrix
transformations:
(enhttp://www.w3.org/TR/SVG/coords.html#EstablishingA
NewUserSpace
(frhttp://www.yoyodesign.org/doc/w3c/sv
g1/coords.html#EstablishingANewUserSpace

Well in fact I guess that for some of the transformations,
it could be 
possible to apply the matrix to the coordinates and use the
code I've made, 
but for sometimes it is not possible. For exemple if the
transformation 
contains a shear and/or a scale that doesn't scales with
the same value in 
the X and Y directions, in this case the radial gradient
will have an elipse 
shape (just like when a circle is drawn).
For the linear gradients I guess (not sure) that it should
be possible to 
modify the vector that defines the linear gradient, in stead
of applying the 
matrix on all the pixels of the gradient bounding-box.

So the proto .h should have some extra parameters, as you
can see below.

And also you said to me to put the magick gradients in a
blackbox with a 
command line interface to test it. But as you know, as I am
not a C 
programmer I am not very comfortable in C and I haven't
made yet the code to 
parse the command line requests as you have specified:

  gradient -width=200 -height=300 -type=linear \
          -point-a='0.4, 0'   -point-b='0.6, 1' \
          -stop-offset=10%  -stop-color='#EE1122' \
          -stop-offset=60%  -stop-color='#DDAA44' \
          -stop-offset=95%  -stop-color='#4488FF' \
          -filename=gradient.rgba
  display -size 200x300 -depth 8 rgba:gradient.rgba

which stands for this SVG gradient:

    <linearGradient id="MyGradient"
            x1="0.4"  y1="0"
            x2="0.6"  y2="1">
        <stop offset="10%" 
stop-color="#EE1122" />
        <stop offset="60%" 
stop-color="#DDAA44" />
        <stop offset="95%" 
stop-color="#4488FF" />
    </linearGradient>

Well, I understand the need to make a high level interface
to test the 
gradients, but while the command line C code is not done
yet, the OCaml 
binding can be used temporarily as this high level
interface.
And indeed I've found a bug with those values:

let () =
  let width, height = 400, 300
  and x0, y0 = 120,  70
  and x1, y1 = 240, 140 in
  let img = get_canvas ~width ~height
~color:"#888" in
  linear_gradient img
        ~width ~height
        ~a:{x=x0; y=y0}
        ~b:{x=x1; y=y1}
        ~spread_method:Reflect_spread
        ~stop:[
              (0.1,  "#1D5");
              (0.3,  "#00F");
              (0.8,  "#F00");
              (0.9,  "#F91") ]
        ~matrix:(
              ( 1.0, 0.0, 0.0 ),
              ( 0.0, 1.0, 0.0 ),
              ( 0.0, 0.0, 1.0 ) )
        ~bounding_box:{
              pos = {x=20; y=30};
              dims = {width=379; height=180} }
          ()
  ;
  draw_line img ~x0 ~y0 ~x1 ~y1 ();
  display img;
  write_image img "gradient.rgba";
;;

the bug above can be seen here:
  wget  http://tux.linux-nantes.fr.eu.org/~fmonnier/tmp/gra
dient.rgba
  display -size 400x300 -depth 16  rgba:gradient.rgba

I have resolve it in the OCaml implementation.
In fact it was just a < that had to be changed to a <=
I haven't spend time yet to find where it is located in the
C implementation, 
while this bug was exactly the same in the OCaml version and
the C one.
(And a funny thing: I did the same error for the radial
gradient)

Before the task of making the blackbox command line parsing
would be done, if 
you (or someone else) is willing to have an OCaml command
line version (in 
stead of a C one) just ask me. Indeed to write the code to
parse the command 
line in C would probably take me about two evening, while it
would only take 
10 minutes in OCaml to get the same result 

Or maybe there is a volunteer around who could make the C
command line parsing 
code ?

Another idea could be that you could put an empty function
(which I could fill 
with the current code), which could be placed inside a
MagickFuture area?

___________

// header with additional parameters for matrix
transformations:

typedef enum
{
  Gradient_UserSpaceOnUse,
  /* If gradientUnits="userSpaceOnUse", x1, y1,
x2, y2 represent values
   * in the coordinate system that results from taking the
current user
   * coordinate system in place at the time when the
gradient element is
   * referenced (i.e., the user coordinate system for the
element
   * referencing the gradient element via a 'fill' or
'stroke' property)
   * and then applying the transform specified by attribute
gradientTransform.
   */

  Gradient_ObjectBoundingBox
  /*   gradientUnits="objectBoundingBox"
   * Indicates that the attributes which specify the
gradient vector
   * (x1, y1, x2, y2) represent fractions or percentages of
the bounding box
   * of the element to which the gradient is applied.
   */
} Gradient_Units;


typedef struct _BoundingBox
{
  unsigned long
    x, y,
    width, height;
} BoundingBox;


void
linearGradientMagick(
  Image *image,
  /* the image on which the gradient fills the bounding box
*/

  unsigned long width,  /* size of the image */
  unsigned long height,

  BoundingBox bounding_box,

  char *colors_strings[], /* colors */
  long double stop[],     /* positions of colors (0.0 <
percentage < 1.0) */
  int stop_nb,            /* number of colors */

  Gradient_SpreadMethod spreadMethod,

  /*
  en: http://www.w3.org/TR/SVG/coords.html#TransformAttribute
  fr: http://www.yoyodesign.org/doc/w3c/svg1/coor
ds.html#TransformAttribute
  */
  long double matrix[3][3],
  Gradient_Units gradientUnits;

  /*  Percentages are allowed for x1, y1, x2, y2.
  For gradientUnits="userSpaceOnUse",
percentages represent values relative
  to the current viewport.
  For gradientUnits="objectBoundingBox",
percentages represent values
  relative to the bounding box for the object.  */
  unsigned long a_x,    /* point A */
  unsigned long a_y,

  unsigned long b_x,    /* point B */
  unsigned long b_y );


-- 
PS: Thanks a lot for the new documentation of the page
architecture
ht
tp://www.imagemagick.org/script/architecture.php
_______________________________________________
Magick-developers mailing list
Magick-developersimagemagick.org
http://studio.imagemagick.org/mailman/listinfo/m
agick-developers
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )