Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Classes | Defines | Typedefs | Functions
art_render_misc.c File Reference
#include "scconfig.h"
#include "art_render_misc.h"
#include <math.h>

Go to the source code of this file.

Classes

struct  _ArtImageSourceGradLin
struct  _ArtImageSourceGradRad
struct  _ArtImageSourceGradCon

Defines

#define EPSILON   1e-6

Typedefs

typedef struct _ArtImageSourceGradLin
typedef struct _ArtImageSourceGradRad
typedef struct _ArtImageSourceGradCon

Functions

static void art_karbon_render_gradient_setpix (ArtRender *render, art_u8 *dst, int n_stops, ArtGradientStop *stops, double offset)
 art_karbon_render_gradient_setpix: Set a gradient pixel.
static void art_karbon_render_gradient_linear_done (ArtRenderCallback *self, ArtRender *render)
static void art_karbon_render_gradient_linear_render (ArtRenderCallback *self, ArtRender *render, art_u8 *dest, int y)
static void art_karbon_render_gradient_linear_negotiate (ArtImageSource *self, ArtRender *render, ArtImageSourceFlags *p_flags, int *p_buf_depth, ArtAlphaType *p_alpha)
void art_karbon_render_gradient_linear (ArtRender *render, const ArtGradientLinear *gradient, ArtFilterLevel level)
 art_karbon_render_gradient_linear: Add a linear gradient image source.
static void art_karbon_render_gradient_radial_done (ArtRenderCallback *self, ArtRender *render)
static void art_karbon_render_gradient_radial_render (ArtRenderCallback *self, ArtRender *render, art_u8 *dest, int y)
static void art_karbon_render_gradient_radial_negotiate (ArtImageSource *self, ArtRender *render, ArtImageSourceFlags *p_flags, int *p_buf_depth, ArtAlphaType *p_alpha)
void art_karbon_render_gradient_radial (ArtRender *render, const ArtGradientRadial *gradient, ArtFilterLevel level)
 art_karbon_render_gradient_radial: Add a radial gradient image source.
static void art_render_gradient_conical_done (ArtRenderCallback *self, ArtRender *render)
static void art_render_gradient_conical_render (ArtRenderCallback *self, ArtRender *render, art_u8 *dest, int y)
static void art_render_gradient_conical_negotiate (ArtImageSource *self, ArtRender *render, ArtImageSourceFlags *p_flags, int *p_buf_depth, ArtAlphaType *p_alpha)
void art_karbon_render_gradient_conical (ArtRender *render, const ArtGradientConical *gradient, ArtFilterLevel level)
 art_render_gradient_radial: Add a radial gradient image source.

Class Documentation

struct _ArtImageSourceGradLin

Definition at line 42 of file art_render_misc.c.

Class Members
const ArtGradientLinear * gradient
ArtImageSource super
struct _ArtImageSourceGradRad

Definition at line 47 of file art_render_misc.c.

Class Members
double a
const ArtGradientRadial * gradient
ArtImageSource super
struct _ArtImageSourceGradCon

Definition at line 53 of file art_render_misc.c.

Class Members
const ArtGradientConical * gradient
ArtImageSource super

Define Documentation

#define EPSILON   1e-6

Definition at line 59 of file art_render_misc.c.


Typedef Documentation

typedef struct _ArtImageSourceGradCon

Definition at line 40 of file art_render_misc.c.

typedef struct _ArtImageSourceGradLin

Definition at line 38 of file art_render_misc.c.

typedef struct _ArtImageSourceGradRad

Definition at line 39 of file art_render_misc.c.


Function Documentation

void art_karbon_render_gradient_conical ( ArtRender *  render,
const ArtGradientConical *  gradient,
ArtFilterLevel  level 
)

art_render_gradient_radial: Add a radial gradient image source.

: The render object. : The radial gradient.

Adds the radial gradient as the image source for rendering in the render object .

Definition at line 390 of file art_render_misc.c.

{
  ArtImageSourceGradCon *image_source = art_new (ArtImageSourceGradCon, 1);

  image_source->super.super.render = NULL;
  image_source->super.super.done = art_render_gradient_conical_done;
  image_source->super.negotiate = art_render_gradient_conical_negotiate;

  image_source->gradient = gradient;

  art_render_add_image_source (render, &image_source->super);
}

Here is the call graph for this function:

void art_karbon_render_gradient_linear ( ArtRender *  render,
const ArtGradientLinear *  gradient,
ArtFilterLevel  level 
)

art_karbon_render_gradient_linear: Add a linear gradient image source.

: The render object. : The linear gradient.

Adds the linear gradient as the image source for rendering in the render object .

Definition at line 190 of file art_render_misc.c.

{
  ArtImageSourceGradLin *image_source = art_new (ArtImageSourceGradLin, 1);

  image_source->super.super.render = NULL;
  image_source->super.super.done = art_karbon_render_gradient_linear_done;
  image_source->super.negotiate = art_karbon_render_gradient_linear_negotiate;

  image_source->gradient = gradient;

  art_render_add_image_source (render, &image_source->super);
}

Here is the call graph for this function:

static void art_karbon_render_gradient_linear_done ( ArtRenderCallback *  self,
ArtRender *  render 
) [static]

Definition at line 127 of file art_render_misc.c.

{
  art_free (self);
}

Here is the caller graph for this function:

static void art_karbon_render_gradient_linear_negotiate ( ArtImageSource *  self,
ArtRender *  render,
ArtImageSourceFlags *  p_flags,
int p_buf_depth,
ArtAlphaType *  p_alpha 
) [static]

Definition at line 171 of file art_render_misc.c.

{
  self->super.render = art_karbon_render_gradient_linear_render;
  *p_flags = 0;
  *p_buf_depth = render->depth;
  *p_alpha = ART_ALPHA_PREMUL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void art_karbon_render_gradient_linear_render ( ArtRenderCallback *  self,
ArtRender *  render,
art_u8 *  dest,
int  y 
) [static]

Definition at line 133 of file art_render_misc.c.

{
  ArtImageSourceGradLin *z = (ArtImageSourceGradLin *)self;
  const ArtGradientLinear *gradient = z->gradient;
  int pixstride = (render->n_chan + 1) * (render->depth >> 3);
  int x;
  int width = render->x1 - render->x0;
  double offset, d_offset;
  double actual_offset;
  int n_stops = gradient->n_stops;
  ArtGradientStop *stops = gradient->stops;
  art_u8 *bufp = render->image_buf;
  ArtGradientSpread spread = gradient->spread;

  offset = render->x0 * gradient->a + y * gradient->b + gradient->c;
  d_offset = gradient->a;

  for (x = 0; x < width; x++)
    {
      if (spread == ART_GRADIENT_PAD)
       actual_offset = offset;
      else if (spread == ART_GRADIENT_REPEAT)
       actual_offset = offset - floor (offset);
      else /* (spread == ART_GRADIENT_REFLECT) */
       {
         double tmp;

         tmp = offset - 2 * floor (0.5 * offset);
         actual_offset = tmp > 1 ? 2 - tmp : tmp;
       }
      art_karbon_render_gradient_setpix (render, bufp, n_stops, stops, actual_offset);
      offset += d_offset;
      bufp += pixstride;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void art_karbon_render_gradient_radial ( ArtRender *  render,
const ArtGradientRadial *  gradient,
ArtFilterLevel  level 
)

art_karbon_render_gradient_radial: Add a radial gradient image source.

: The render object. : The radial gradient.

Adds the radial gradient as the image source for rendering in the render object .

Definition at line 300 of file art_render_misc.c.

{
  ArtImageSourceGradRad *image_source = art_new (ArtImageSourceGradRad, 1);
  double fx = gradient->fx;
  double fy = gradient->fy;

  image_source->super.super.render = NULL;
  image_source->super.super.done = art_karbon_render_gradient_radial_done;
  image_source->super.negotiate = art_karbon_render_gradient_radial_negotiate;

  image_source->gradient = gradient;
  /* todo: sanitycheck fx, fy? */
  image_source->a = 1 - fx * fx - fy * fy;

  art_render_add_image_source (render, &image_source->super);
}

Here is the call graph for this function:

static void art_karbon_render_gradient_radial_done ( ArtRenderCallback *  self,
ArtRender *  render 
) [static]

Definition at line 206 of file art_render_misc.c.

{
  art_free (self);
}

Here is the caller graph for this function:

static void art_karbon_render_gradient_radial_negotiate ( ArtImageSource *  self,
ArtRender *  render,
ArtImageSourceFlags *  p_flags,
int p_buf_depth,
ArtAlphaType *  p_alpha 
) [static]

Definition at line 281 of file art_render_misc.c.

{
  self->super.render = art_karbon_render_gradient_radial_render;
  *p_flags = 0;
  *p_buf_depth = render->depth;
  *p_alpha = ART_ALPHA_PREMUL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void art_karbon_render_gradient_radial_render ( ArtRenderCallback *  self,
ArtRender *  render,
art_u8 *  dest,
int  y 
) [static]

Definition at line 212 of file art_render_misc.c.

{
  ArtImageSourceGradRad *z = (ArtImageSourceGradRad *)self;
  const ArtGradientRadial *gradient = z->gradient;
  int pixstride = (render->n_chan + 1) * (render->depth >> 3);
  int x;
  int x0 = render->x0;
  int width = render->x1 - x0;
  int n_stops = gradient->n_stops;
  ArtGradientStop *stops = gradient->stops;
  art_u8 *bufp = render->image_buf;
  double fx = gradient->fx;
  double fy = gradient->fy;
  double dx, dy;
  const double *affine = gradient->affine;
  double aff0 = affine[0];
  double aff1 = affine[1];
  const double a = z->a;
  const double arecip = 1.0 / a;
  double b, db;
  double c, dc, ddc;
  double b_a, db_a;
  double rad, drad, ddrad;
  ArtGradientSpread spread = gradient->spread;

  dx = x0 * aff0 + y * affine[2] + affine[4] - fx;
  dy = x0 * aff1 + y * affine[3] + affine[5] - fy;
  b = dx * fx + dy * fy;
  db = aff0 * fx + aff1 * fy;
  c = dx * dx + dy * dy;
  dc = 2 * aff0 * dx + aff0 * aff0 + 2 * aff1 * dy + aff1 * aff1;
  ddc = 2 * aff0 * aff0 + 2 * aff1 * aff1;

  b_a = b * arecip;
  db_a = db * arecip;

  rad = b_a * b_a + c * arecip;
  drad = 2 * b_a * db_a + db_a * db_a + dc * arecip;
  ddrad = 2 * db_a * db_a + ddc * arecip;

  for (x = 0; x < width; x++)
    {
      double z;

      if (rad > 0)
       z = b_a + sqrt (rad);
      else
       z = b_a;

    if (spread == ART_GRADIENT_REPEAT)
         z = z - floor (z);
    else if (spread == ART_GRADIENT_REFLECT)
    {
         double tmp;

         tmp = z - 2 * floor (0.5 * z);
         z = tmp > 1 ? 2 - tmp : tmp;
    }

      art_karbon_render_gradient_setpix (render, bufp, n_stops, stops, z);
      bufp += pixstride;
      b_a += db_a;
      rad += drad;
      drad += ddrad;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void art_karbon_render_gradient_setpix ( ArtRender *  render,
art_u8 *  dst,
int  n_stops,
ArtGradientStop *  stops,
double  offset 
) [static]

art_karbon_render_gradient_setpix: Set a gradient pixel.

: The render object. : Pointer to destination (where to store pixel). : Number of stops in . : The stops for the gradient. : The offset.

must be > 0.

Sets a gradient pixel, storing it at .

Definition at line 74 of file art_render_misc.c.

{
  int ix;
  int j;
  double off0, off1;
  int n_ch = render->n_chan + 1;

  for (ix = 0; ix < n_stops; ix++)
    if (stops[ix].offset > offset)
      break;
  /* stops[ix - 1].offset < offset < stops[ix].offset */
  if (ix > 0 && ix < n_stops)
    {
      off0 = stops[ix - 1].offset;
      off1 = stops[ix].offset;
      if (fabs (off1 - off0) > EPSILON)
       {
         double interp;

         interp = (offset - off0) / (off1 - off0);
         for (j = 0; j < n_ch; j++)
           {
             int z0, z1;
             int z;
             z0 = stops[ix - 1].color[j];
             z1 = stops[ix].color[j];
             z = floor (z0 + (z1 - z0) * interp + 0.5);
             if (render->buf_depth == 8)
              dst[j] = ART_PIX_8_FROM_MAX (z);
             else /* (render->buf_depth == 16) */
              ((art_u16 *)dst)[j] = z;
           }
         return;
       }
    }
  else if (ix == n_stops)
    ix--;

  for (j = 0; j < n_ch; j++)
    {
      int z;
      z = stops[ix].color[j];
      if (render->buf_depth == 8)
       dst[j] = ART_PIX_8_FROM_MAX (z);
      else /* (render->buf_depth == 16) */
       ((art_u16 *)dst)[j] = z;
    }
}

Here is the caller graph for this function:

static void art_render_gradient_conical_done ( ArtRenderCallback *  self,
ArtRender *  render 
) [static]

Definition at line 322 of file art_render_misc.c.

{
  art_free (self);
}

Here is the caller graph for this function:

static void art_render_gradient_conical_negotiate ( ArtImageSource *  self,
ArtRender *  render,
ArtImageSourceFlags *  p_flags,
int p_buf_depth,
ArtAlphaType *  p_alpha 
) [static]

Definition at line 371 of file art_render_misc.c.

{
  self->super.render = art_render_gradient_conical_render;
  *p_flags = 0;
  *p_buf_depth = render->depth;
  *p_alpha = ART_ALPHA_PREMUL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void art_render_gradient_conical_render ( ArtRenderCallback *  self,
ArtRender *  render,
art_u8 *  dest,
int  y 
) [static]

Definition at line 328 of file art_render_misc.c.

{
  ArtImageSourceGradCon *z = (ArtImageSourceGradCon *)self;
  const ArtGradientConical *gradient = z->gradient;
  int pixstride = (render->n_chan + 1) * (render->depth >> 3);
  int x;
  int x0 = render->x0;
  int width = render->x1 - x0;
  int n_stops = gradient->n_stops;
  ArtGradientStop *stops = gradient->stops;
  art_u8 *bufp = render->image_buf;
  double cx = gradient->cx;
  double cy = gradient->cy;
  double r = gradient->r;
  double dx, dy;
  ArtGradientSpread spread = gradient->spread;

  dy = fabs(y) - fabs(cy);

  for (x = 0; x < width; x++)
    {
      double z;
       dx = fabs(x0 + x) - fabs(cx);

       z = (fabs(dx) + fabs(dy)) / (r);

    if (spread == ART_GRADIENT_REPEAT)
         z = z - floor (z);
    else if (spread == ART_GRADIENT_REFLECT)
    {
         double tmp;

         tmp = z - 2 * floor (0.5 * z);
         z = tmp > 1 ? 2 - tmp : tmp;
    }

      art_karbon_render_gradient_setpix (render, bufp, n_stops, stops, z);
      bufp += pixstride;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function: