~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/widgets/gimprender.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program 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
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <string.h>
 
22
 
 
23
#include <gtk/gtk.h>
 
24
 
 
25
#include "libgimpbase/gimpbase.h"
 
26
 
 
27
#include "widgets-types.h"
 
28
 
 
29
#include "core/gimp.h"
 
30
#include "core/gimpviewable.h"
 
31
 
 
32
#include "gimprender.h"
 
33
 
 
34
 
 
35
static void   gimp_render_setup_notify (gpointer    config,
 
36
                                        GParamSpec *param_spec,
 
37
                                        Gimp       *gimp);
 
38
 
 
39
 
 
40
/*  accelerate transparency of image scaling  */
 
41
guchar *gimp_render_check_buf         = NULL;
 
42
guchar *gimp_render_empty_buf         = NULL;
 
43
guchar *gimp_render_white_buf         = NULL;
 
44
guchar *gimp_render_temp_buf          = NULL;
 
45
 
 
46
guchar *gimp_render_blend_dark_check  = NULL;
 
47
guchar *gimp_render_blend_light_check = NULL;
 
48
guchar *gimp_render_blend_white       = NULL;
 
49
 
 
50
 
 
51
void
 
52
gimp_render_init (Gimp *gimp)
 
53
{
 
54
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
55
 
 
56
  g_signal_connect (gimp->config, "notify::transparency-type",
 
57
                    G_CALLBACK (gimp_render_setup_notify),
 
58
                    gimp);
 
59
 
 
60
  gimp_render_setup_notify (gimp->config, NULL, gimp);
 
61
}
 
62
 
 
63
void
 
64
gimp_render_exit (Gimp *gimp)
 
65
{
 
66
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
67
 
 
68
  g_signal_handlers_disconnect_by_func (gimp->config,
 
69
                                        gimp_render_setup_notify,
 
70
                                        gimp);
 
71
 
 
72
  if (gimp_render_blend_dark_check)
 
73
    {
 
74
      g_free (gimp_render_blend_dark_check);
 
75
      gimp_render_blend_dark_check = NULL;
 
76
    }
 
77
 
 
78
  if (gimp_render_blend_light_check)
 
79
    {
 
80
      g_free (gimp_render_blend_light_check);
 
81
      gimp_render_blend_light_check = NULL;
 
82
    }
 
83
 
 
84
  if (gimp_render_blend_white)
 
85
    {
 
86
      g_free (gimp_render_blend_white);
 
87
      gimp_render_blend_white = NULL;
 
88
    }
 
89
 
 
90
  if (gimp_render_check_buf)
 
91
    {
 
92
      g_free (gimp_render_check_buf);
 
93
      gimp_render_check_buf = NULL;
 
94
    }
 
95
 
 
96
  if (gimp_render_empty_buf)
 
97
    {
 
98
      g_free (gimp_render_empty_buf);
 
99
      gimp_render_empty_buf = NULL;
 
100
    }
 
101
 
 
102
  if (gimp_render_white_buf)
 
103
    {
 
104
      g_free (gimp_render_white_buf);
 
105
      gimp_render_white_buf = NULL;
 
106
    }
 
107
 
 
108
  if (gimp_render_temp_buf)
 
109
    {
 
110
      g_free (gimp_render_temp_buf);
 
111
      gimp_render_temp_buf = NULL;
 
112
    }
 
113
}
 
114
 
 
115
 
 
116
static void
 
117
gimp_render_setup_notify (gpointer    config,
 
118
                          GParamSpec *param_spec,
 
119
                          Gimp       *gimp)
 
120
{
 
121
  GimpCheckType check_type;
 
122
  guchar        light, dark;
 
123
  gint          i, j;
 
124
 
 
125
  g_object_get (config,
 
126
                "transparency-type", &check_type,
 
127
                NULL);
 
128
 
 
129
  if (! gimp_render_blend_dark_check)
 
130
    gimp_render_blend_dark_check = g_new (guchar, 65536);
 
131
  if (! gimp_render_blend_light_check)
 
132
    gimp_render_blend_light_check = g_new (guchar, 65536);
 
133
  if (! gimp_render_blend_white)
 
134
    gimp_render_blend_white = g_new (guchar, 65536);
 
135
 
 
136
  gimp_checks_get_shades (check_type, &light, &dark);
 
137
 
 
138
  for (i = 0; i < 256; i++)
 
139
    for (j = 0; j < 256; j++)
 
140
      {
 
141
        gimp_render_blend_dark_check [(i << 8) + j] =
 
142
          (guchar) ((j * i + dark * (255 - i)) / 255);
 
143
        gimp_render_blend_light_check [(i << 8) + j] =
 
144
          (guchar) ((j * i + light * (255 - i)) / 255);
 
145
        gimp_render_blend_white [(i << 8) + j] =
 
146
          (guchar) ((j * i + 255 * (255 - i)) / 255);
 
147
      }
 
148
 
 
149
  g_free (gimp_render_check_buf);
 
150
  g_free (gimp_render_empty_buf);
 
151
  g_free (gimp_render_white_buf);
 
152
  g_free (gimp_render_temp_buf);
 
153
 
 
154
#define BUF_SIZE (MAX (GIMP_RENDER_BUF_WIDTH, \
 
155
                       GIMP_VIEWABLE_MAX_PREVIEW_SIZE) + 4)
 
156
 
 
157
  gimp_render_check_buf = g_new  (guchar, BUF_SIZE * 3);
 
158
  gimp_render_empty_buf = g_new0 (guchar, BUF_SIZE * 3);
 
159
  gimp_render_white_buf = g_new  (guchar, BUF_SIZE * 3);
 
160
  gimp_render_temp_buf  = g_new  (guchar, BUF_SIZE * 3);
 
161
 
 
162
  /*  calculate check buffer for previews  */
 
163
 
 
164
  memset (gimp_render_white_buf, 255, BUF_SIZE * 3);
 
165
 
 
166
  for (i = 0; i < BUF_SIZE; i++)
 
167
    {
 
168
      if (i & 0x4)
 
169
        {
 
170
          gimp_render_check_buf[i * 3 + 0] = gimp_render_blend_dark_check[0];
 
171
          gimp_render_check_buf[i * 3 + 1] = gimp_render_blend_dark_check[0];
 
172
          gimp_render_check_buf[i * 3 + 2] = gimp_render_blend_dark_check[0];
 
173
        }
 
174
      else
 
175
        {
 
176
          gimp_render_check_buf[i * 3 + 0] = gimp_render_blend_light_check[0];
 
177
          gimp_render_check_buf[i * 3 + 1] = gimp_render_blend_light_check[0];
 
178
          gimp_render_check_buf[i * 3 + 2] = gimp_render_blend_light_check[0];
 
179
        }
 
180
    }
 
181
 
 
182
#undef BUF_SIZE
 
183
}