summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-gdk-pixbuf-extensions.h
blob: 8106c74bce7ed796dd80912e6591937d15967e32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* nautilus-gdk-pixbuf-extensions.h: Routines to augment what's in gdk-pixbuf.

   Copyright (C) 2000 Eazel, Inc.

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Authors: Darin Adler <darin@eazel.com>
            Ramiro Estrugo <ramiro@eazel.com>
*/

#ifndef NAUTILUS_GDK_PIXBUF_EXTENSIONS_H
#define NAUTILUS_GDK_PIXBUF_EXTENSIONS_H

#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libgnomevfs/gnome-vfs-types.h>
#include <libnautilus-extensions/nautilus-art-extensions.h>

#define NAUTILUS_STANDARD_ALPHA_THRESHHOLD 128
#define NAUTILUS_OPACITY_FULLY_TRANSPARENT 0
#define NAUTILUS_OPACITY_FULLY_OPAQUE	   255

typedef struct NautilusPixbufLoadHandle NautilusPixbufLoadHandle;
typedef void (* NautilusPixbufLoadCallback) (GnomeVFSResult  error,
					     GdkPixbuf      *pixbuf,
					     gpointer        callback_data);

/* Convenience functions for lists of GdkPixbuf objects. */
void                      nautilus_gdk_pixbuf_list_ref                  (GList                      *pixbuf_list);
void                      nautilus_gdk_pixbuf_list_unref                (GList                      *pixbuf_list);
void                      nautilus_gdk_pixbuf_list_free                 (GList                      *pixbuf_list);


/* Loading a GdkPixbuf with a URI. */
GdkPixbuf *               nautilus_gdk_pixbuf_load                      (const char                 *uri);


/* Same thing async. */
NautilusPixbufLoadHandle *nautilus_gdk_pixbuf_load_async                (const char                 *uri,
									 NautilusPixbufLoadCallback  callback,
									 gpointer                    callback_data);
void                      nautilus_cancel_gdk_pixbuf_load               (NautilusPixbufLoadHandle   *handle);
GdkPixbuf *               nautilus_gdk_pixbuf_scale_down_to_fit         (GdkPixbuf                  *pixbuf,
									 int                         max_width,
									 int                         max_height);
GdkPixbuf *               nautilus_gdk_pixbuf_scale_to_fit              (GdkPixbuf                  *pixbuf,
									 int                         max_width,
									 int                         max_height);
double                    nautilus_gdk_scale_to_fit_factor              (int                         width,
									 int                         height,
									 int                         max_width,
									 int                         max_height,
									 int                        *scaled_width,
									 int                        *scaled_height);


/* return average color values for each component */
void                      nautilus_gdk_pixbuf_average_value             (GdkPixbuf                  *pixbuf,
									 GdkColor                   *result_color);
void                      nautilus_gdk_pixbuf_fill_rectangle_with_color (GdkPixbuf                  *pixbuf,
									 const ArtIRect             *area,
									 guint32                     color);


/* Save a pixbuf to a png file.  Return value indicates succss/TRUE or failure/FALSE */
gboolean                  nautilus_gdk_pixbuf_save_to_file              (const GdkPixbuf            *pixbuf,
									 const char                 *file_name);
void                      nautilus_gdk_pixbuf_ref_if_not_null           (GdkPixbuf                  *pixbuf_or_null);
void                      nautilus_gdk_pixbuf_unref_if_not_null         (GdkPixbuf                  *pixbuf_or_null);


/* Copy a pixbuf to an area of a GdkDrawable */
void                      nautilus_gdk_pixbuf_draw_to_drawable          (const GdkPixbuf            *pixbuf,
									 GdkDrawable                *drawable,
									 GdkGC                      *gc,
									 int                         source_x,
									 int                         source_y,
									 const ArtIRect             *destination_area,
									 GdkRgbDither                dither,
									 GdkPixbufAlphaMode          alpha_compositing_mode,
									 int                         alpha_threshold);

/* Copy a pixbuf to an area of another pixbuf */
void                      nautilus_gdk_pixbuf_draw_to_pixbuf            (const GdkPixbuf            *pixbuf,
									 GdkPixbuf                  *destination_pixbuf,
									 int                         source_x,
									 int                         source_y,
									 const ArtIRect             *destination_area);


/* Composite one pixbuf over another with the given opacity */
void                      nautilus_gdk_pixbuf_draw_to_pixbuf_alpha      (const GdkPixbuf            *pixbuf,
									 GdkPixbuf                  *destination_pixbuf,
									 int                         source_x,
									 int                         source_y,
									 const ArtIRect             *destination_area,
									 int                         opacity,
									 GdkInterpType               interpolation_mode);


/* Fill an area of a pixbuf with a tile. */
void                      nautilus_gdk_pixbuf_draw_to_pixbuf_tiled      (const GdkPixbuf            *pixbuf,
									 GdkPixbuf                  *destination_pixbuf,
									 const ArtIRect             *destination_area,
									 int                         tile_width,
									 int                         tile_height,
									 int                         tile_origin_x,
									 int                         tile_origin_y,
									 int                         opacity,
									 GdkInterpType               interpolation_mode);

/* Fill an area of a drawable with a tile. */
void                      nautilus_gdk_pixbuf_draw_to_drawable_tiled    (const GdkPixbuf            *pixbuf,
									 GdkDrawable                *drawable,
									 GdkGC                      *gc,
									 const ArtIRect             *destination_area,
									 int                         tile_width,
									 int                         tile_height,
									 int                         tile_origin_x,
									 int                         tile_origin_y,
									 GdkRgbDither                dither,
									 GdkPixbufAlphaMode          alpha_compositing_mode,
									 int                         alpha_threshold);

/* Create a pixbuf from a sub area of another pixbuf */
GdkPixbuf *               nautilus_gdk_pixbuf_new_from_pixbuf_sub_area  (GdkPixbuf                  *pixbuf,
									 const ArtIRect             *area);
/* Create a pixbuf from an existing buffer. */
GdkPixbuf *               nautilus_gdk_pixbuf_new_from_existing_buffer  (guchar                     *buffer,
									 int                         buffer_rowstride,
									 gboolean                    buffer_has_alpha,
									 const ArtIRect             *area);

/* Access a global buffer for temporary GdkPixbuf operations.  
 * The returned buffer will be at least as big as the passed in 
 * dimensions.  The contents are not guaranteed to be anything at
 * anytime.  Also, it is not thread safe at all.
 */
GdkPixbuf *               nautilus_gdk_pixbuf_get_global_buffer         (int                         minimum_width,
									 int                         minimum_height);

/* Same as gdk_pixbuf_get_from_drawable() except it deals with 
 * race conditions and other evil things that can happen */
GdkPixbuf *               nautilus_gdk_pixbuf_get_from_window_safe      (GdkWindow                  *window,
									 int                         x,
									 int                         y,
									 int                         width,
									 int                         height);
/* Determine whether a pixbuf is valid or not */
gboolean                  nautilus_gdk_pixbuf_is_valid                  (const GdkPixbuf            *pixbuf);

/* Access the dimensions of a pixbuf. */
NautilusDimensions        nautilus_gdk_pixbuf_get_dimensions            (const GdkPixbuf            *pixbuf);

/* Return the intersection of the pixbuf with the given rectangle. */
ArtIRect                  nautilus_gdk_pixbuf_intersect                 (const GdkPixbuf            *pixbuf,
									 int                         pixbuf_x,
									 int                         pixbuf_y,
									 const ArtIRect             *rectangle);

#endif /* NAUTILUS_GDK_PIXBUF_EXTENSIONS_H */