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

« back to all changes in this revision

Viewing changes to karbon/render/art_rgb.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
/* Libart_LGPL - library of basic graphic primitives
 
2
 * Copyright (C) 1998 Raph Levien
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
#include "art_rgb.h"
 
22
 
 
23
#include <string.h>     /* for memset */
 
24
 
 
25
/* Basic operators for manipulating 24-bit packed RGB buffers. */
 
26
 
 
27
#define COLOR_RUN_SIMPLE
 
28
 
 
29
#ifdef COLOR_RUN_SIMPLE
 
30
/* This is really slow. Is there any way we might speed it up?
 
31
   Two ideas:
 
32
 
 
33
   First, maybe we should be working at 32-bit alignment. Then,
 
34
   this can be a simple loop over word stores.
 
35
 
 
36
   Second, we can keep working at 24-bit alignment, but have some
 
37
   intelligence about storing. For example, we can iterate over
 
38
   4-pixel chunks (aligned at 4 pixels), with an inner loop
 
39
   something like:
 
40
 
 
41
   *buf++ = v1;
 
42
   *buf++ = v2;
 
43
   *buf++ = v3;
 
44
 
 
45
   One source of extra complexity is the need to make sure linebuf is
 
46
   aligned to a 32-bit boundary.
 
47
 
 
48
   This second alternative has some complexity to it, but is
 
49
   appealing because it really minimizes the memory bandwidth. */
 
50
void
 
51
art_rgb_fill_run_ (art_u8 *buf, art_u32 rgb, int n)
 
52
{
 
53
  int i;
 
54
  art_u32 *b = (art_u32 *)buf;
 
55
  for (i = 0; i < n; i++)
 
56
  {
 
57
    *b = rgb;
 
58
    b++;
 
59
  }
 
60
}
 
61
#endif
 
62
 
 
63
#ifdef COLOR_RUN_COMPLEX
 
64
/* This implements the second of the two ideas above. The test results
 
65
   are _very_ encouraging - it seems the speed is within 10% of
 
66
   memset, which is quite good! */
 
67
/**
 
68
 * art_rgb_fill_run: fill a buffer a solid RGB color.
 
69
 * @buf: Buffer to fill.
 
70
 * @r: Red, range 0..255.
 
71
 * @g: Green, range 0..255.
 
72
 * @b: Blue, range 0..255.
 
73
 * @n: Number of RGB triples to fill.
 
74
 *
 
75
 * Fills a buffer with @n copies of the (@r, @g, @b) triple. Thus,
 
76
 * locations @buf (inclusive) through @buf + 3 * @n (exclusive) are
 
77
 * written.
 
78
 *
 
79
 * The implementation of this routine is very highly optimized.
 
80
 **/
 
81
void
 
82
art_rgb_fill_run_ (art_u8 *buf, art_u32 rgb, int n)
 
83
{
 
84
  int i;
 
85
  unsigned int v1, v2, v3;
 
86
 
 
87
  if (r == g && g == b)
 
88
    {
 
89
        memset (buf, g, 4*n);
 
90
    }
 
91
  else
 
92
    {
 
93
      if (n < 8)
 
94
        {
 
95
          for (i = 0; i < n; i++)
 
96
            {
 
97
              buf++;
 
98
              *buf++ = r;
 
99
              *buf++ = g;
 
100
              *buf++ = b;
 
101
            }
 
102
        } else {
 
103
          /* handle prefix up to byte alignment */
 
104
          /* I'm worried about this cast on sizeof(long) != sizeof(uchar *)
 
105
             architectures, but it _should_ work. */
 
106
          for (i = 0; ((unsigned long)buf) & 3; i++)
 
107
            {
 
108
          buf++;
 
109
              *buf++ = r;
 
110
              *buf++ = g;
 
111
              *buf++ = b;
 
112
            }
 
113
#ifndef WORDS_BIGENDIAN
 
114
          v1 = r | (g << 8) | (b << 16) | (r << 24);
 
115
          v3 = (v1 << 8) | b;
 
116
          v2 = (v3 << 8) | g;
 
117
#else
 
118
          v1 = (r << 24) | (g << 16) | (b << 8) | r;
 
119
          v2 = (v1 << 8) | g;
 
120
          v3 = (v2 << 8) | b;
 
121
#endif
 
122
          for (; i < n - 3; i += 4)
 
123
            {/*
 
124
              ((art_u32 *)buf)[0] = v1;
 
125
              ((art_u32 *)buf)[1] = v2;
 
126
              ((art_u32 *)buf)[2] = v3;
 
127
              buf += 12;*/
 
128
              ((art_u32 *)buf)[1] = v1;
 
129
              ((art_u32 *)buf)[2] = v2;
 
130
              ((art_u32 *)buf)[3] = v3;
 
131
              buf += 16;
 
132
            }
 
133
          /* handle postfix */
 
134
          for (; i < n; i++)
 
135
            {
 
136
              buf++;
 
137
              *buf++ = r;
 
138
              *buf++ = g;
 
139
              *buf++ = b;
 
140
            }
 
141
        }
 
142
    }
 
143
}
 
144
#endif
 
145
 
 
146
/**
 
147
 * art_rgb_run_alpha: Render semitransparent color over RGB buffer.
 
148
 * @buf: Buffer for rendering.
 
149
 * @r: Red, range 0..255.
 
150
 * @g: Green, range 0..255.
 
151
 * @b: Blue, range 0..255.
 
152
 * @alpha: Alpha, range 0..256.
 
153
 * @n: Number of RGB triples to render.
 
154
 *
 
155
 * Renders a sequential run of solid (@r, @g, @b) color over @buf with
 
156
 * opacity @alpha.
 
157
 **/
 
158
void
 
159
art_rgb_run_alpha_ (art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int alpha, int n)
 
160
{
 
161
  int i;
 
162
  int v;
 
163
  for (i = 0; i < n; i++)
 
164
  {
 
165
    v = *buf;
 
166
    *buf++ = v + (((b - v) * alpha + 0x80) >> 8);
 
167
    v = *buf;
 
168
    *buf++ = v + (((g - v) * alpha + 0x80) >> 8);
 
169
    v = *buf;
 
170
    *buf++ = v + (((r - v) * alpha + 0x80) >> 8);
 
171
    buf++;
 
172
  }
 
173
}
 
174