~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to karbon/render/art_render_pattern.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * art_render_pattern.c: 
 
3
 *
 
4
 * Libart_LGPL - library of basic graphic primitives
 
5
 * Copyright (C) 2000 Raph Levien
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Library General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Library General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Library General Public
 
18
 * License along with this library; if not, write to the
 
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 *
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
#include "art_render_pattern.h"
 
26
 
 
27
#include <math.h>
 
28
 
 
29
typedef struct _ArtImageSourcePattern ArtImageSourcePattern;
 
30
 
 
31
struct _ArtImageSourcePattern {
 
32
  ArtImageSource super;
 
33
  const ArtPattern *pattern;
 
34
};
 
35
 
 
36
static void
 
37
art_render_pattern_done (ArtRenderCallback *self, ArtRender *render)
 
38
{
 
39
  art_free (self);
 
40
}
 
41
 
 
42
static void
 
43
art_render_pattern_render (ArtRenderCallback *self, ArtRender *render,
 
44
                                   art_u8 *dest, int y)
 
45
{
 
46
  ArtImageSourcePattern *z = (ArtImageSourcePattern *)self;
 
47
  const ArtPattern *pattern = z->pattern;
 
48
  int pixstride = (render->n_chan + 1) * (render->depth >> 3);
 
49
  int n_ch = render->n_chan + 1;
 
50
  int x, j, index;
 
51
  int width = render->x1 - render->x0;
 
52
  int twidth = pattern->twidth;
 
53
  int theight = pattern->theight;
 
54
  art_u8 *bufp = render->image_buf;
 
55
 
 
56
  double angle = pattern->angle;
 
57
  double opacity = pattern->opacity;
 
58
  double cosangle = cos(angle);
 
59
  double sinangle = sin(angle);
 
60
 
 
61
  y = y - render->y0;
 
62
 
 
63
  for (x = 0; x < width; x++)
 
64
  {
 
65
          int x0 = sinangle * y + cosangle * x;
 
66
          int y0 = -sinangle * x + cosangle * y;
 
67
          x0 = (x0 % twidth);
 
68
          if(x0 < 0) x0 += twidth;
 
69
          y0 = (y0 % theight);
 
70
          if(y0 < 0) y0 += theight;
 
71
          index = (((y0 * twidth + x0) * pixstride) % (twidth * theight * 4));
 
72
          /*for (j = 0; j < n_ch - 1; j++)
 
73
                {*/
 
74
              /* bgra -> rgba */
 
75
          bufp[0] = pattern->buffer[index + 2];
 
76
          bufp[1] = pattern->buffer[index + 1];
 
77
          bufp[2] = pattern->buffer[index + 0];
 
78
          bufp[3] = opacity;
 
79
                /*}*/
 
80
      bufp += pixstride;
 
81
  }
 
82
}
 
83
 
 
84
static void
 
85
art_render_pattern_negotiate (ArtImageSource *self, ArtRender *render,
 
86
                                      ArtImageSourceFlags *p_flags,
 
87
                                      int *p_buf_depth, ArtAlphaType *p_alpha)
 
88
{
 
89
  self->super.render = art_render_pattern_render;
 
90
  *p_flags = 0;
 
91
  *p_buf_depth = render->depth;
 
92
  *p_alpha = ART_ALPHA_SEPARATE;
 
93
}
 
94
 
 
95
void
 
96
art_render_pattern (ArtRender *render,
 
97
                            const ArtPattern *pattern,
 
98
                            ArtFilterLevel level)
 
99
{
 
100
  ArtImageSourcePattern *image_source = art_new (ArtImageSourcePattern, 1);
 
101
 
 
102
  image_source->super.super.render = NULL;
 
103
  image_source->super.super.done = art_render_pattern_done;
 
104
  image_source->super.negotiate = art_render_pattern_negotiate;
 
105
 
 
106
  image_source->pattern = pattern;
 
107
 
 
108
  art_render_add_image_source (render, &image_source->super);
 
109
}