[cairo-commit] cairo/src cairo_gl_surface.c, 1.5, 1.6 cairo_gstate.c, 1.47, 1.48 cairo_pattern.c, 1.5, 1.6 cairoint.h, 1.59, 1.60

David Reveman commit at pdx.freedesktop.org
Thu Apr 29 20:26:59 PDT 2004


Committed by: davidr

Update of /cvs/cairo/cairo/src
In directory pdx:/tmp/cvs-serv31835/src

Modified Files:
	cairo_gl_surface.c cairo_gstate.c cairo_pattern.c cairoint.h 
Log Message:
Updated linear and radial patterns

Index: cairo_gl_surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_gl_surface.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** a/cairo_gl_surface.c	28 Apr 2004 09:14:23 -0000	1.5
--- b/cairo_gl_surface.c	30 Apr 2004 03:26:56 -0000	1.6
***************
*** 591,595 ****
      unsigned int i, bytes = size * 4;
      cairo_shader_op_t op;
! 
      _cairo_pattern_shader_init (pattern, &op);
  
--- 591,595 ----
      unsigned int i, bytes = size * 4;
      cairo_shader_op_t op;
!     
      _cairo_pattern_shader_init (pattern, &op);
  
***************
*** 608,615 ****
      glitz_surface_t *programmatic = NULL;
      cairo_gl_surface_t *gl_surface;
-     double bbox_x = box->p1.x >> 16;
-     double bbox_y = box->p1.y >> 16;
-     double x = bbox_x + pattern->source_offset.x;
-     double y = bbox_y + pattern->source_offset.y;
  
      switch (pattern->type) {
--- 608,611 ----
***************
*** 623,628 ****
  
  	programmatic = glitz_surface_create_solid (&color);
!     }
! 	break;
      case CAIRO_PATTERN_LINEAR:
      case CAIRO_PATTERN_RADIAL: {
--- 619,623 ----
  
  	programmatic = glitz_surface_create_solid (&color);
!     } break;
      case CAIRO_PATTERN_LINEAR:
      case CAIRO_PATTERN_RADIAL: {
***************
*** 643,666 ****
  	    double dx, dy;
  
! 	    dx = (pattern->u.linear.point1.x - x) -
! 		(pattern->u.linear.point0.x - x);
! 	    dy = (pattern->u.linear.point1.y - y) -
! 		(pattern->u.linear.point0.y - y);
! 	    
  	    color_range_size = sqrt (dx * dx + dy * dy);
  	} else {
  	    /* glitz doesn't support inner circle yet. */
! 	    if (pattern->u.radial.center0.x !=
! 		pattern->u.radial.center1.x
! 		|| pattern->u.radial.center0.y !=
! 		pattern->u.radial.center1.y
! 		|| pattern->u.radial.radius0.dx
! 		|| pattern->u.radial.radius0.dy)
  		return CAIRO_INT_STATUS_UNSUPPORTED;
  
! 	    color_range_size = sqrt (pattern->u.radial.radius1.dx *
! 				     pattern->u.radial.radius1.dx +
! 				     pattern->u.radial.radius1.dy *
! 				     pattern->u.radial.radius1.dy);
  	}
  
--- 638,652 ----
  	    double dx, dy;
  
! 	    dx = pattern->u.linear.point1.x - pattern->u.linear.point0.x;
! 	    dy = pattern->u.linear.point1.y - pattern->u.linear.point0.y;
! 
  	    color_range_size = sqrt (dx * dx + dy * dy);
  	} else {
  	    /* glitz doesn't support inner circle yet. */
! 	    if (pattern->u.radial.center0.x != pattern->u.radial.center1.x ||
! 		pattern->u.radial.center0.y != pattern->u.radial.center1.y)
  		return CAIRO_INT_STATUS_UNSUPPORTED;
  
! 	    color_range_size = pattern->u.radial.radius1;
  	}
  
***************
*** 673,678 ****
  
  	_cairo_gl_create_color_range (pattern,
! 				      glitz_color_range_get_data
! 				      (color_range), color_range_size);
  
  	switch (pattern->extend) {
--- 659,664 ----
  
  	_cairo_gl_create_color_range (pattern,
! 				      glitz_color_range_get_data (color_range),
! 				      color_range_size);
  
  	switch (pattern->extend) {
***************
*** 688,701 ****
  	}
  
  	if (pattern->type == CAIRO_PATTERN_LINEAR) {
  	    glitz_point_fixed_t start;
  	    glitz_point_fixed_t stop;
  
! 	    start.x =
! 		_cairo_fixed_from_double (pattern->u.linear.point0.x - x);
! 	    start.y =
! 		_cairo_fixed_from_double (pattern->u.linear.point0.y - y);
! 	    stop.x = _cairo_fixed_from_double (pattern->u.linear.point1.x - x);
! 	    stop.y = _cairo_fixed_from_double (pattern->u.linear.point1.y - y);
  
  	    programmatic =
--- 674,687 ----
  	}
  
+ 	glitz_color_range_set_filter (color_range, GLITZ_FILTER_BILINEAR);
+ 
  	if (pattern->type == CAIRO_PATTERN_LINEAR) {
  	    glitz_point_fixed_t start;
  	    glitz_point_fixed_t stop;
  
! 	    start.x = _cairo_fixed_from_double (pattern->u.linear.point0.x);
! 	    start.y = _cairo_fixed_from_double (pattern->u.linear.point0.y);
! 	    stop.x = _cairo_fixed_from_double (pattern->u.linear.point1.x);
! 	    stop.y = _cairo_fixed_from_double (pattern->u.linear.point1.y);
  
  	    programmatic =
***************
*** 703,734 ****
  	} else {
  	    glitz_point_fixed_t center;
- 	    glitz_distance_fixed_t radius;
  	    
! 	    center.x =
! 		_cairo_fixed_from_double (pattern->u.radial.center1.x - x);
! 	    center.y =
! 		_cairo_fixed_from_double (pattern->u.radial.center1.y - y);
! 	    radius.dx =
! 		_cairo_fixed_from_double (pattern->u.radial.radius1.dx);
! 	    radius.dy =
! 		_cairo_fixed_from_double (pattern->u.radial.radius1.dy);
! 
! 	    programmatic =
! 		glitz_surface_create_radial (&center, &radius, color_range);
  	}
  
  	glitz_color_range_destroy (color_range);
!     }
! 	break;
!     default:
  	return CAIRO_INT_STATUS_UNSUPPORTED;
  	break;
      }
! 
      if (!programmatic)
  	return CAIRO_STATUS_NO_MEMORY;
  
      gl_surface = (cairo_gl_surface_t *)
!         _cairo_gl_surface_create (programmatic, 1);
      if (!gl_surface) {
  	glitz_surface_destroy (programmatic);
--- 689,715 ----
  	} else {
  	    glitz_point_fixed_t center;
  	    
! 	    center.x = _cairo_fixed_from_double (pattern->u.radial.center1.x);
! 	    center.y = _cairo_fixed_from_double (pattern->u.radial.center1.y);
! 	    
! 	    programmatic = glitz_surface_create_radial
! 		(&center,
! 		 _cairo_fixed_from_double (pattern->u.radial.radius0),
! 		 _cairo_fixed_from_double (pattern->u.radial.radius1),
! 		 color_range);
  	}
  
  	glitz_color_range_destroy (color_range);
!     } break;
!     case CAIRO_PATTERN_SURFACE:
  	return CAIRO_INT_STATUS_UNSUPPORTED;
  	break;
      }
!     
      if (!programmatic)
  	return CAIRO_STATUS_NO_MEMORY;
  
      gl_surface = (cairo_gl_surface_t *)
! 	_cairo_gl_surface_create (programmatic, 1);
      if (!gl_surface) {
  	glitz_surface_destroy (programmatic);
***************
*** 736,739 ****
--- 717,724 ----
  	return CAIRO_STATUS_NO_MEMORY;
      }
+     
+     if (pattern->type == CAIRO_PATTERN_LINEAR ||
+ 	pattern->type == CAIRO_PATTERN_RADIAL)
+ 	cairo_surface_set_matrix (gl_surface, &pattern->matrix);
  
      _cairo_pattern_init_copy (&gl_surface->pattern, pattern);
***************
*** 741,745 ****
  
      pattern->source = &gl_surface->base;
-     _cairo_pattern_set_source_offset (pattern, bbox_x, bbox_y);
  
      return CAIRO_STATUS_SUCCESS;
--- 726,729 ----

Index: cairo_gstate.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_gstate.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** a/cairo_gstate.c	23 Apr 2004 17:08:53 -0000	1.47
--- b/cairo_gstate.c	30 Apr 2004 03:26:56 -0000	1.48
***************
*** 1279,1283 ****
    
      _cairo_pattern_set_alpha (pattern, gstate->alpha);
!     _cairo_pattern_transform (pattern, &gstate->ctm, &gstate->ctm_inverse);
  
      _cairo_pattern_set_source_offset (pattern,
--- 1279,1283 ----
    
      _cairo_pattern_set_alpha (pattern, gstate->alpha);
!     _cairo_pattern_transform (pattern, &gstate->ctm_inverse);
  
      _cairo_pattern_set_source_offset (pattern,

Index: cairo_pattern.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_pattern.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** a/cairo_pattern.c	25 Apr 2004 11:02:38 -0000	1.5
--- b/cairo_pattern.c	30 Apr 2004 03:26:56 -0000	1.6
***************
*** 176,185 ****
      pattern->u.radial.center0.x = cx0;
      pattern->u.radial.center0.y = cy0;
!     pattern->u.radial.radius0.dx = fabs (radius0);
!     pattern->u.radial.radius0.dy = fabs (radius0);
      pattern->u.radial.center1.x = cx1;
      pattern->u.radial.center1.y = cy1;
!     pattern->u.radial.radius1.dx = fabs (radius1);
!     pattern->u.radial.radius1.dy = fabs (radius1);
  
      return pattern;
--- 176,183 ----
      pattern->u.radial.center0.x = cx0;
      pattern->u.radial.center0.y = cy0;
!     pattern->u.radial.radius0 = fabs (radius0);
      pattern->u.radial.center1.x = cx1;
      pattern->u.radial.center1.y = cy1;
!     pattern->u.radial.radius1 = fabs (radius1);
  
      return pattern;
***************
*** 354,396 ****
  void
  _cairo_pattern_transform (cairo_pattern_t *pattern,
- 			  cairo_matrix_t *ctm,
  			  cairo_matrix_t *ctm_inverse)
  {
!     cairo_matrix_t matrix;
!  
!     switch (pattern->type) {
!     case CAIRO_PATTERN_SURFACE:
! 	/* hmm, maybe we should instead multiply with the inverse of the
! 	   pattern matrix here? */
! 	cairo_matrix_multiply (&pattern->matrix, ctm_inverse,
! 			       &pattern->matrix);
! 	break;
!     case CAIRO_PATTERN_LINEAR:
! 	cairo_matrix_multiply (&matrix, &pattern->matrix, ctm);
! 	cairo_matrix_transform_point (&matrix,
! 				      &pattern->u.linear.point0.x,
! 				      &pattern->u.linear.point0.y);
! 	cairo_matrix_transform_point (&matrix,
! 				      &pattern->u.linear.point1.x,
! 				      &pattern->u.linear.point1.y);
! 	break;
!     case CAIRO_PATTERN_RADIAL:
! 	cairo_matrix_multiply (&matrix, &pattern->matrix, ctm);
! 	cairo_matrix_transform_point (&matrix,
! 				      &pattern->u.radial.center0.x,
! 				      &pattern->u.radial.center0.y);
! 	cairo_matrix_transform_distance (&matrix,
! 					 &pattern->u.radial.radius0.dx,
! 					 &pattern->u.radial.radius0.dy);
! 	cairo_matrix_transform_point (&matrix,
! 				      &pattern->u.radial.center1.x,
! 				      &pattern->u.radial.center1.y);
! 	cairo_matrix_transform_distance (&matrix,
! 					 &pattern->u.radial.radius1.dx,
! 					 &pattern->u.radial.radius1.dy);
! 	break;
!     case CAIRO_PATTERN_SOLID:
! 	break;
!     }
  }
  
--- 352,358 ----
  void
  _cairo_pattern_transform (cairo_pattern_t *pattern,
  			  cairo_matrix_t *ctm_inverse)
  {
!     cairo_matrix_multiply (&pattern->matrix, ctm_inverse, &pattern->matrix);
  }
  
***************
*** 519,528 ****
  	break;
      case CAIRO_EXTEND_REFLECT:
! 	if (factor < 0) {
! 	    if ((factor >> 16) % 2)
! 		factor -= factor & 0xffff0000;
! 	    else
! 		factor = 65536 - (factor - (factor & 0xffff0000));
! 	} else if (factor > 65536) {
  	    if ((factor >> 16) % 2)
  		factor = 65536 - (factor - (factor & 0xffff0000));
--- 481,485 ----
  	break;
      case CAIRO_EXTEND_REFLECT:
! 	if (factor < 0 || factor > 65536) {
  	    if ((factor >> 16) % 2)
  		factor = 65536 - (factor - (factor & 0xffff0000));
***************
*** 563,650 ****
  			      double offset_x,
  			      double offset_y,
! 			      char *data,
  			      int width,
  			      int height)
  {
      int x, y;
!     cairo_point_double_t point0, point1, angle;
!     double a, length, start;
      cairo_shader_op_t op;
-     double factor;
  
      _cairo_pattern_shader_init (pattern, &op);
  
!     point0.x = pattern->u.linear.point0.x - offset_x;
!     point0.y = pattern->u.linear.point0.y - offset_y;
!     point1.x = pattern->u.linear.point1.x - offset_x;
!     point1.y = pattern->u.linear.point1.y - offset_y;
  
      length = sqrt ((point1.x - point0.x) * (point1.x - point0.x) +
  		   (point1.y - point0.y) * (point1.y - point0.y));
      length = (length) ? 1.0 / length : CAIRO_MAXSHORT;
  
!     a = -atan2 (point1.y - point0.y, point1.x - point0.x);
!     angle.x = cos (a);
!     angle.y = -sin (a);
! 
!     start = angle.x * point0.x;
!     start += angle.y * point0.y;
  
      for (y = 0; y < height; y++) {
  	for (x = 0; x < width; x++) {
  	    
! 	    factor = ((angle.x * (double) x) +
! 		      (angle.y * (double) y) - start) * length;
  
! 	    _cairo_pattern_calc_color_at_pixel (&op,
! 						factor * 65536,
! 						(int *)
! 						&data[y * width * 4 + x * 4]);
  	}
      }
  }
  
- /* TODO: Inner circle is currently ignored. */
  static void
  _cairo_image_data_set_radial (cairo_pattern_t *pattern,
  			      double offset_x,
  			      double offset_y,
! 			      char *data,
  			      int width,
  			      int height)
  {
!     int x, y;
!     cairo_point_double_t center1, pos;
!     cairo_distance_double_t length;
!     double factor, min_length;
      cairo_shader_op_t op;
  
      _cairo_pattern_shader_init (pattern, &op);
  
!     center1.x = pattern->u.radial.center1.x - offset_x;
!     center1.y = pattern->u.radial.center1.y - offset_y;
  
!     min_length = (pattern->u.radial.radius1.dx < pattern->u.radial.radius1.dy)?
! 	pattern->u.radial.radius1.dx : pattern->u.radial.radius1.dy;
!     
!     length.dx = min_length / pattern->u.radial.radius1.dx;
!     length.dy = min_length / pattern->u.radial.radius1.dy;
!     
!     min_length = (min_length)? 1.0 / min_length: CAIRO_MAXSHORT;
  
      for (y = 0; y < height; y++) {
  	for (x = 0; x < width; x++) {
! 	    pos.x = x - center1.x;
! 	    pos.y = y - center1.y;
  
! 	    pos.x *= length.dx;
! 	    pos.y *= length.dy;
  
! 	    factor = sqrt (pos.x * pos.x + pos.y * pos.y) * min_length;
  
! 	    _cairo_pattern_calc_color_at_pixel (&op,
! 						factor * 65536,
! 						(int *)
! 						&data[y * width * 4 + x * 4]);
  	}
      }
--- 520,673 ----
  			      double offset_x,
  			      double offset_y,
! 			      int *pixels,
  			      int width,
  			      int height)
  {
      int x, y;
!     cairo_point_double_t point0, point1;
!     double px, py, ex, ey;
!     double a, b, c, d, tx, ty;
!     double length, start, angle, fx, fy, factor;
      cairo_shader_op_t op;
  
      _cairo_pattern_shader_init (pattern, &op);
  
!     point0.x = pattern->u.linear.point0.x;
!     point0.y = pattern->u.linear.point0.y;
!     point1.x = pattern->u.linear.point1.x;
!     point1.y = pattern->u.linear.point1.y;
  
+     cairo_matrix_get_affine (&pattern->matrix, &a, &b, &c, &d, &tx, &ty);
+     
      length = sqrt ((point1.x - point0.x) * (point1.x - point0.x) +
  		   (point1.y - point0.y) * (point1.y - point0.y));
      length = (length) ? 1.0 / length : CAIRO_MAXSHORT;
  
!     angle = -atan2 (point1.y - point0.y, point1.x - point0.x);
!     fx = cos (angle);
!     fy = -sin (angle);
!     
!     start = fx * point0.x;
!     start += fy * point0.y;
  
      for (y = 0; y < height; y++) {
  	for (x = 0; x < width; x++) {
+ 	    px = x + offset_x;
+ 	    py = y + offset_y;
+ 		
+ 	    /* transform fragment */
+ 	    ex = a * px + c * py + tx;
+ 	    ey = b * px + d * py + ty;
  	    
! 	    factor = ((fx * ex + fy * ey) - start) * length;
  
! 	    _cairo_pattern_calc_color_at_pixel (&op, factor * 65536, pixels++);
  	}
      }
  }
  
  static void
  _cairo_image_data_set_radial (cairo_pattern_t *pattern,
  			      double offset_x,
  			      double offset_y,
! 			      int *pixels,
  			      int width,
  			      int height)
  {
!     int x, y, aligned_circles;
!     cairo_point_double_t c0, c1;
!     double px, py, ex, ey;
!     double a, b, c, d, tx, ty;
!     double r0, r1, c0_e_x, c0_e_y, c0_e, c1_e_x, c1_e_y, c1_e,
! 	c0_c1_x, c0_c1_y, c0_c1, angle_c0, c1_y, y_x, c0_y, c0_x, r1_2,
! 	denumerator, fraction, factor;
      cairo_shader_op_t op;
  
      _cairo_pattern_shader_init (pattern, &op);
  
!     c0.x = pattern->u.radial.center0.x;
!     c0.y = pattern->u.radial.center0.y;
!     r0 = pattern->u.radial.radius0;
!     c1.x = pattern->u.radial.center1.x;
!     c1.y = pattern->u.radial.center1.y;
!     r1 =  pattern->u.radial.radius1;
  
!     if (c0.x != c1.x || c0.y != c1.y) {
! 	aligned_circles = 0;
! 	c0_c1_x = c1.x - c0.x;
! 	c0_c1_y = c1.y - c0.y;
! 	c0_c1 = sqrt (c0_c1_x * c0_c1_x + c0_c1_y * c0_c1_y);
! 	r1_2 = r1 * r1;
!     } else {
! 	aligned_circles = 1;
! 	r1 = 1.0 / (r1 - r0);
!     }
! 
!     cairo_matrix_get_affine (&pattern->matrix, &a, &b, &c, &d, &tx, &ty);
  
      for (y = 0; y < height; y++) {
  	for (x = 0; x < width; x++) {
! 	    px = x + offset_x;
! 	    py = y + offset_y;
! 		
! 	    /* transform fragment */
! 	    ex = a * px + c * py + tx;
! 	    ey = b * px + d * py + ty;
  
! 	    if (aligned_circles) {
! 		ex = ex - c1.x;
! 		ey = ey - c1.y;
  
! 		factor = (sqrt (ex * ex + ey * ey) - r0) * r1;
! 	    } else {
! 	    /* Here we need to calulate distance c0 -> x; the distance from
! 	       the inner circle center c0, through point (ex, ey) to
! 	       point x where it crosses the outer circle. The gradient offset
! 	       can then be calculated within the distance of the inner and
! 	       outer circles.
! 	       
!                         y    y_x  (ex, ey)        
!                c0 -------------------+---------- x
!                   \     |                  __--
!                    \    |              __--
!                  r0 \   | c1_y     __--
!                      \  |      __-- r1
!                       \ |  __--
!                       c1 --
! 	       */
  
! 		c0_e_x = ex - c0.x;
! 		c0_e_y = ey - c0.y;
! 		c0_e = sqrt (c0_e_x * c0_e_x + c0_e_y * c0_e_y);
! 
! 		c1_e_x = ex - c1.x;
! 		c1_e_y = ey - c1.y;
! 		c1_e = sqrt (c1_e_x * c1_e_x + c1_e_y * c1_e_y);
! 
! 		denumerator = -2.0 * c0_e * c0_c1;
! 		
! 		if (denumerator != 0.0) {
! 		    fraction = (c1_e * c1_e - c0_e * c0_e - c0_c1 * c0_c1) /
! 			denumerator;
! 
! 		    if (fraction > 1.0)
! 			fraction = 1.0;
! 		    else if (fraction < -1.0)
! 			fraction = -1.0;
! 		    
! 		    angle_c0 = acos (fraction);
! 		    
! 		    c0_y = cos (angle_c0) * c0_c1;
! 		    c1_y = sin (angle_c0) * c0_c1;
! 		    
! 		    y_x = sqrt (r1_2 - c1_y * c1_y);
! 		    c0_x = y_x + c0_y;
! 		    
! 		    factor = (c0_e - r0) / (c0_x - r0);
! 		} else
! 		    factor = -r0;
! 	    }
! 
! 	    _cairo_pattern_calc_color_at_pixel (&op, factor * 65536, pixels++);
  	}
      }
***************
*** 671,682 ****
  	if (pattern->type == CAIRO_PATTERN_RADIAL)
  	    _cairo_image_data_set_radial (pattern,
! 					  pattern->source_offset.x + x,
! 					  pattern->source_offset.y + y,
! 					  data, width, height);
  	else
  	    _cairo_image_data_set_linear (pattern,
! 					  pattern->source_offset.x + x,
! 					  pattern->source_offset.y + y,
! 					  data, width, height);
  
  	_cairo_pattern_set_source_offset (pattern, x, y);
--- 694,707 ----
  	if (pattern->type == CAIRO_PATTERN_RADIAL)
  	    _cairo_image_data_set_radial (pattern,
! 					  x - pattern->source_offset.x,
! 					  y - pattern->source_offset.y,
! 					  (int *) data,
! 					  width, height);
  	else
  	    _cairo_image_data_set_linear (pattern,
! 					  x - pattern->source_offset.x,
! 					  y - pattern->source_offset.y,
! 					  (int *) data,
! 					  width, height);
  
  	_cairo_pattern_set_source_offset (pattern, x, y);
***************
*** 716,717 ****
--- 741,743 ----
      return (cairo_image_surface_t *) surface;
  }
+  

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** a/cairoint.h	25 Apr 2004 11:02:38 -0000	1.59
--- b/cairoint.h	30 Apr 2004 03:26:56 -0000	1.60
***************
*** 509,514 ****
              cairo_point_double_t center0;
              cairo_point_double_t center1;
!             cairo_distance_double_t radius0;
!             cairo_distance_double_t radius1;
          } radial;
      } u;
--- 509,514 ----
              cairo_point_double_t center0;
              cairo_point_double_t center1;
!             double radius0;
!             double radius1;
          } radial;
      } u;
***************
*** 1356,1361 ****
  extern void __internal_linkage
  _cairo_pattern_transform (cairo_pattern_t *pattern,
! 			  cairo_matrix_t *matrix,
! 			  cairo_matrix_t *matrix_inverse);
  
  extern void __internal_linkage
--- 1356,1360 ----
  extern void __internal_linkage
  _cairo_pattern_transform (cairo_pattern_t *pattern,
! 			  cairo_matrix_t *ctm_inverse);
  
  extern void __internal_linkage





More information about the cairo-commit mailing list