~ubuntu-branches/debian/sid/cheese/sid

« back to all changes in this revision

Viewing changes to src/eog-thumbnail.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-07-17 21:04:16 UTC
  • mfrom: (15.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110717210416-nt5qi659qei7a2yy
Tags: 3.0.1-2
* debian/control.in:
  - Change gir1.2-cheese-3.0 Section to libs
  - Make library packages depend against cheese-common package
  - Make cheese package recommends against hicolor-icon-theme
  - Move gst Dependency to libcheese package
* debian/patches/0002-fix-linking.patch: Add missing library to fix linking
* debian/watch:
  - Switch to .bz2 tarballs.
  - Bump version to 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Eye Of Gnome - Thumbnailing functions
2
 
 *
3
 
 * Copyright (C) 2000-2007 The Free Software Foundation
4
 
 *
5
 
 * Author: Lucas Rocha <lucasr@gnome.org>
6
 
 *
7
 
 * Based on eel code (eel/eel-graphic-effects.c) by:
8
 
 *      - Andy Hertzfeld <andy@eazel.com>
9
 
 *
10
 
 * This program is free software; you can redistribute it and/or modify
11
 
 * it under the terms of the GNU General Public License as published by
12
 
 * the Free Software Foundation; either version 2 of the License, or
13
 
 * (at your option) any later version.
14
 
 *
15
 
 * This program is distributed in the hope that it will be useful,
16
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 * GNU General Public License for more details.
19
 
 *
20
 
 * You should have received a copy of the GNU General Public License
21
 
 * along with this program; if not, write to the Free Software
22
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
 
 */
24
 
 
25
 
/* NOTE this is a stripped version of eog-thumbnail which only contains the
26
 
 * functions necessary for cheese
27
 
 */
28
 
#ifdef HAVE_CONFIG_H
29
 
  #include <cheese-config.h>
30
 
#endif
31
 
 
32
 
#include "eog-thumbnail.h"
33
 
 
34
 
 
35
 
static GdkPixbuf *frame = NULL;
36
 
 
37
 
 
38
 
static void
39
 
draw_frame_row (GdkPixbuf *frame_image,
40
 
                gint       target_width,
41
 
                gint       source_width,
42
 
                gint       source_v_position,
43
 
                gint       dest_v_position,
44
 
                GdkPixbuf *result_pixbuf,
45
 
                gint       left_offset,
46
 
                gint       height)
47
 
{
48
 
  gint remaining_width, h_offset, slab_width;
49
 
 
50
 
  remaining_width = target_width;
51
 
  h_offset        = 0;
52
 
 
53
 
  while (remaining_width > 0)
54
 
  {
55
 
    slab_width = remaining_width > source_width ?
56
 
                 source_width : remaining_width;
57
 
 
58
 
    gdk_pixbuf_copy_area (frame_image,
59
 
                          left_offset,
60
 
                          source_v_position,
61
 
                          slab_width,
62
 
                          height,
63
 
                          result_pixbuf,
64
 
                          left_offset + h_offset,
65
 
                          dest_v_position);
66
 
 
67
 
    remaining_width -= slab_width;
68
 
    h_offset        += slab_width;
69
 
  }
70
 
}
71
 
 
72
 
static void
73
 
draw_frame_column (GdkPixbuf *frame_image,
74
 
                   gint       target_height,
75
 
                   gint       source_height,
76
 
                   gint       source_h_position,
77
 
                   gint       dest_h_position,
78
 
                   GdkPixbuf *result_pixbuf,
79
 
                   gint       top_offset,
80
 
                   gint       width)
81
 
{
82
 
  gint remaining_height, v_offset, slab_height;
83
 
 
84
 
  remaining_height = target_height;
85
 
  v_offset         = 0;
86
 
 
87
 
  while (remaining_height > 0)
88
 
  {
89
 
    slab_height = remaining_height > source_height ?
90
 
                  source_height : remaining_height;
91
 
 
92
 
    gdk_pixbuf_copy_area (frame_image,
93
 
                          source_h_position,
94
 
                          top_offset,
95
 
                          width,
96
 
                          slab_height,
97
 
                          result_pixbuf,
98
 
                          dest_h_position,
99
 
                          top_offset + v_offset);
100
 
 
101
 
    remaining_height -= slab_height;
102
 
    v_offset         += slab_height;
103
 
  }
104
 
}
105
 
 
106
 
/* copied from libart_lgpl/art_rgb.c */
107
 
 
108
 
static void
109
 
art_rgb_run_alpha (guint8 *buf, guint8 r, guint8 g, guint8 b, int alpha, int n)
110
 
{
111
 
  int i;
112
 
  int v;
113
 
 
114
 
  for (i = 0; i < n; i++)
115
 
  {
116
 
    v      = *buf;
117
 
    *buf++ = v + (((r - v) * alpha + 0x80) >> 8);
118
 
    v      = *buf;
119
 
    *buf++ = v + (((g - v) * alpha + 0x80) >> 8);
120
 
    v      = *buf;
121
 
    *buf++ = v + (((b - v) * alpha + 0x80) >> 8);
122
 
  }
123
 
}
124
 
 
125
 
static GdkPixbuf *
126
 
eog_thumbnail_stretch_frame_image (GdkPixbuf *frame_image,
127
 
                                   gint       left_offset,
128
 
                                   gint       top_offset,
129
 
                                   gint       right_offset,
130
 
                                   gint       bottom_offset,
131
 
                                   gint       dest_width,
132
 
                                   gint       dest_height,
133
 
                                   gboolean   fill_flag)
134
 
{
135
 
  GdkPixbuf *result_pixbuf;
136
 
  guchar    *pixels_ptr;
137
 
  gint       frame_width, frame_height;
138
 
  gint       y, row_stride;
139
 
  gint       target_width, target_frame_width;
140
 
  gint       target_height, target_frame_height;
141
 
 
142
 
  frame_width  = gdk_pixbuf_get_width (frame_image);
143
 
  frame_height = gdk_pixbuf_get_height (frame_image);
144
 
 
145
 
  if (fill_flag)
146
 
  {
147
 
    result_pixbuf = gdk_pixbuf_scale_simple (frame_image,
148
 
                                             dest_width,
149
 
                                             dest_height,
150
 
                                             GDK_INTERP_NEAREST);
151
 
  }
152
 
  else
153
 
  {
154
 
    result_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
155
 
                                    TRUE,
156
 
                                    8,
157
 
                                    dest_width,
158
 
                                    dest_height);
159
 
  }
160
 
 
161
 
  row_stride = gdk_pixbuf_get_rowstride (result_pixbuf);
162
 
  pixels_ptr = gdk_pixbuf_get_pixels (result_pixbuf);
163
 
 
164
 
  if (!fill_flag)
165
 
  {
166
 
    for (y = 0; y < dest_height; y++)
167
 
    {
168
 
      art_rgb_run_alpha (pixels_ptr,
169
 
                         255, 255,
170
 
                         255, 255,
171
 
                         dest_width);
172
 
      pixels_ptr += row_stride;
173
 
    }
174
 
  }
175
 
 
176
 
  target_width       = dest_width - left_offset - right_offset;
177
 
  target_frame_width = frame_width - left_offset - right_offset;
178
 
 
179
 
  target_height       = dest_height - top_offset - bottom_offset;
180
 
  target_frame_height = frame_height - top_offset - bottom_offset;
181
 
 
182
 
  /* Draw the left top corner  and top row */
183
 
  gdk_pixbuf_copy_area (frame_image,
184
 
                        0, 0,
185
 
                        left_offset,
186
 
                        top_offset,
187
 
                        result_pixbuf,
188
 
                        0, 0);
189
 
 
190
 
  draw_frame_row (frame_image,
191
 
                  target_width,
192
 
                  target_frame_width,
193
 
                  0, 0,
194
 
                  result_pixbuf,
195
 
                  left_offset,
196
 
                  top_offset);
197
 
 
198
 
  /* Draw the right top corner and left column */
199
 
  gdk_pixbuf_copy_area (frame_image,
200
 
                        frame_width - right_offset,
201
 
                        0,
202
 
                        right_offset,
203
 
                        top_offset,
204
 
                        result_pixbuf,
205
 
                        dest_width - right_offset,
206
 
                        0);
207
 
 
208
 
  draw_frame_column (frame_image,
209
 
                     target_height,
210
 
                     target_frame_height,
211
 
                     0, 0,
212
 
                     result_pixbuf,
213
 
                     top_offset,
214
 
                     left_offset);
215
 
 
216
 
  /* Draw the bottom right corner and bottom row */
217
 
  gdk_pixbuf_copy_area (frame_image,
218
 
                        frame_width - right_offset,
219
 
                        frame_height - bottom_offset,
220
 
                        right_offset,
221
 
                        bottom_offset,
222
 
                        result_pixbuf,
223
 
                        dest_width - right_offset,
224
 
                        dest_height - bottom_offset);
225
 
 
226
 
  draw_frame_row (frame_image,
227
 
                  target_width,
228
 
                  target_frame_width,
229
 
                  frame_height - bottom_offset,
230
 
                  dest_height - bottom_offset,
231
 
                  result_pixbuf,
232
 
                  left_offset, bottom_offset);
233
 
 
234
 
  /* Draw the bottom left corner and the right column */
235
 
  gdk_pixbuf_copy_area (frame_image,
236
 
                        0,
237
 
                        frame_height - bottom_offset,
238
 
                        left_offset,
239
 
                        bottom_offset,
240
 
                        result_pixbuf,
241
 
                        0,
242
 
                        dest_height - bottom_offset);
243
 
 
244
 
  draw_frame_column (frame_image,
245
 
                     target_height,
246
 
                     target_frame_height,
247
 
                     frame_width - right_offset,
248
 
                     dest_width - right_offset,
249
 
                     result_pixbuf, top_offset,
250
 
                     right_offset);
251
 
 
252
 
  return result_pixbuf;
253
 
}
254
 
 
255
 
void
256
 
eog_thumbnail_add_frame (GdkPixbuf **thumbnail)
257
 
{
258
 
  GdkPixbuf *result_pixbuf;
259
 
  gint       source_width, source_height;
260
 
  gint       dest_width, dest_height;
261
 
 
262
 
  source_width  = gdk_pixbuf_get_width (*thumbnail);
263
 
  source_height = gdk_pixbuf_get_height (*thumbnail);
264
 
 
265
 
  dest_width  = source_width + 9;
266
 
  dest_height = source_height + 9;
267
 
 
268
 
  result_pixbuf = eog_thumbnail_stretch_frame_image (frame,
269
 
                                                     3, 3, 6, 6,
270
 
                                                     dest_width,
271
 
                                                     dest_height,
272
 
                                                     FALSE);
273
 
 
274
 
  gdk_pixbuf_copy_area (*thumbnail,
275
 
                        0, 0,
276
 
                        source_width,
277
 
                        source_height,
278
 
                        result_pixbuf,
279
 
                        3, 3);
280
 
 
281
 
  g_object_unref (*thumbnail);
282
 
 
283
 
  *thumbnail = result_pixbuf;
284
 
}
285
 
 
286
 
void
287
 
eog_thumbnail_init (void)
288
 
{
289
 
  if (frame == NULL)
290
 
  {
291
 
    frame = gdk_pixbuf_new_from_file (PACKAGE_DATADIR "/pixmaps/thumbnail-frame.png", NULL);
292
 
  }
293
 
}