1
/* Eye Of Gnome - Thumbnailing functions
3
* Copyright (C) 2000-2007 The Free Software Foundation
5
* Author: Lucas Rocha <lucasr@gnome.org>
7
* Based on eel code (eel/eel-graphic-effects.c) by:
8
* - Andy Hertzfeld <andy@eazel.com>
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.
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.
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.
25
/* NOTE this is a stripped version of eog-thumbnail which only contains the
26
* functions necessary for cheese
29
#include <cheese-config.h>
32
#include "eog-thumbnail.h"
35
static GdkPixbuf *frame = NULL;
39
draw_frame_row (GdkPixbuf *frame_image,
42
gint source_v_position,
44
GdkPixbuf *result_pixbuf,
48
gint remaining_width, h_offset, slab_width;
50
remaining_width = target_width;
53
while (remaining_width > 0)
55
slab_width = remaining_width > source_width ?
56
source_width : remaining_width;
58
gdk_pixbuf_copy_area (frame_image,
64
left_offset + h_offset,
67
remaining_width -= slab_width;
68
h_offset += slab_width;
73
draw_frame_column (GdkPixbuf *frame_image,
76
gint source_h_position,
78
GdkPixbuf *result_pixbuf,
82
gint remaining_height, v_offset, slab_height;
84
remaining_height = target_height;
87
while (remaining_height > 0)
89
slab_height = remaining_height > source_height ?
90
source_height : remaining_height;
92
gdk_pixbuf_copy_area (frame_image,
99
top_offset + v_offset);
101
remaining_height -= slab_height;
102
v_offset += slab_height;
106
/* copied from libart_lgpl/art_rgb.c */
109
art_rgb_run_alpha (guint8 *buf, guint8 r, guint8 g, guint8 b, int alpha, int n)
114
for (i = 0; i < n; i++)
117
*buf++ = v + (((r - v) * alpha + 0x80) >> 8);
119
*buf++ = v + (((g - v) * alpha + 0x80) >> 8);
121
*buf++ = v + (((b - v) * alpha + 0x80) >> 8);
126
eog_thumbnail_stretch_frame_image (GdkPixbuf *frame_image,
135
GdkPixbuf *result_pixbuf;
137
gint frame_width, frame_height;
139
gint target_width, target_frame_width;
140
gint target_height, target_frame_height;
142
frame_width = gdk_pixbuf_get_width (frame_image);
143
frame_height = gdk_pixbuf_get_height (frame_image);
147
result_pixbuf = gdk_pixbuf_scale_simple (frame_image,
154
result_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
161
row_stride = gdk_pixbuf_get_rowstride (result_pixbuf);
162
pixels_ptr = gdk_pixbuf_get_pixels (result_pixbuf);
166
for (y = 0; y < dest_height; y++)
168
art_rgb_run_alpha (pixels_ptr,
172
pixels_ptr += row_stride;
176
target_width = dest_width - left_offset - right_offset;
177
target_frame_width = frame_width - left_offset - right_offset;
179
target_height = dest_height - top_offset - bottom_offset;
180
target_frame_height = frame_height - top_offset - bottom_offset;
182
/* Draw the left top corner and top row */
183
gdk_pixbuf_copy_area (frame_image,
190
draw_frame_row (frame_image,
198
/* Draw the right top corner and left column */
199
gdk_pixbuf_copy_area (frame_image,
200
frame_width - right_offset,
205
dest_width - right_offset,
208
draw_frame_column (frame_image,
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,
223
dest_width - right_offset,
224
dest_height - bottom_offset);
226
draw_frame_row (frame_image,
229
frame_height - bottom_offset,
230
dest_height - bottom_offset,
232
left_offset, bottom_offset);
234
/* Draw the bottom left corner and the right column */
235
gdk_pixbuf_copy_area (frame_image,
237
frame_height - bottom_offset,
242
dest_height - bottom_offset);
244
draw_frame_column (frame_image,
247
frame_width - right_offset,
248
dest_width - right_offset,
249
result_pixbuf, top_offset,
252
return result_pixbuf;
256
eog_thumbnail_add_frame (GdkPixbuf **thumbnail)
258
GdkPixbuf *result_pixbuf;
259
gint source_width, source_height;
260
gint dest_width, dest_height;
262
source_width = gdk_pixbuf_get_width (*thumbnail);
263
source_height = gdk_pixbuf_get_height (*thumbnail);
265
dest_width = source_width + 9;
266
dest_height = source_height + 9;
268
result_pixbuf = eog_thumbnail_stretch_frame_image (frame,
274
gdk_pixbuf_copy_area (*thumbnail,
281
g_object_unref (*thumbnail);
283
*thumbnail = result_pixbuf;
287
eog_thumbnail_init (void)
291
frame = gdk_pixbuf_new_from_file (PACKAGE_DATADIR "/pixmaps/thumbnail-frame.png", NULL);