Simplify vflist_get_formatted()
[geeqie.git] / src / pixbuf-util.h
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef PIXBUF_UTIL_H
23 #define PIXBUF_UTIL_H
24
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26 #include <glib.h>
27 #include <gtk/gtk.h>
28 #include <pango/pango.h>
29
30 struct FileData;
31
32 gboolean pixbuf_to_file_as_png (GdkPixbuf *pixbuf, const gchar *filename);
33
34 void pixbuf_inline_register_stock_icons();
35 gboolean register_theme_icon_as_stock(const gchar *key, const gchar *icon);
36
37 GdkPixbuf *pixbuf_inline(const gchar *key);
38 GdkPixbuf *pixbuf_fallback(FileData *fd, gint requested_width, gint requested_height);
39
40 gboolean pixbuf_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h, gint *new_w, gint *new_h);
41
42 #define PIXBUF_INLINE_ARCHIVE               "gq-icon-archive-file"
43 #define PIXBUF_INLINE_BROKEN                "gq-icon-broken"
44 #define PIXBUF_INLINE_COLLECTION            "gq-icon-collection"
45 #define PIXBUF_INLINE_ICON_180              "gq-icon-rotate-180"
46 #define PIXBUF_INLINE_ICON_BOOK             "gq-icon-book"
47 #define PIXBUF_INLINE_ICON_CONFIG           "gq-icon-config"
48 #define PIXBUF_INLINE_ICON_DRAW_RECTANGLE   "gq-icon-draw-rectangle"
49 #define PIXBUF_INLINE_ICON_EXIF             "gq-icon-exif"
50 #define PIXBUF_INLINE_ICON_EXPOSURE         "gq-icon-exposure"
51 #define PIXBUF_INLINE_ICON_FLOAT            "gq-icon-float"
52 #define PIXBUF_INLINE_ICON                  "gqview-icon"
53 #define PIXBUF_INLINE_ICON_GRAYSCALE        "gq-icon-grayscale"
54 #define PIXBUF_INLINE_ICON_HEIF             "gq-icon-heic"
55 #define PIXBUF_INLINE_ICON_HIDETOOLS        "gq-icon-hidetools"
56 #define PIXBUF_INLINE_ICON_MAINTENANCE      "gq-icon-maintenance"
57 #define PIXBUF_INLINE_ICON_MARKS            "gq-icon-marks"
58 #define PIXBUF_INLINE_ICON_MOVE             "gq-icon-move"
59 #define PIXBUF_INLINE_ICON_ORIGINAL         "gq-icon-original"
60 #define PIXBUF_INLINE_ICON_PANORAMA         "gq-icon-panorama"
61 #define PIXBUF_INLINE_ICON_PDF              "gq-icon-pdf"
62 #define PIXBUF_INLINE_ICON_PROPERTIES       "gq-icon-properties"
63 #define PIXBUF_INLINE_ICON_RENAME           "gq-icon-rename"
64 #define PIXBUF_INLINE_ICON_SELECT_ALL       "gq-icon-select-all"
65 #define PIXBUF_INLINE_ICON_SELECT_INVERT    "gq-icon-select-invert"
66 #define PIXBUF_INLINE_ICON_SELECT_NONE      "gq-icon-select-none"
67 #define PIXBUF_INLINE_ICON_SELECT_RECTANGLE "gq-icon-select-rectangle"
68 #define PIXBUF_INLINE_ICON_SORT             "gq-icon-sort"
69 #define PIXBUF_INLINE_ICON_THUMB            "gq-icon-thumb"
70 #define PIXBUF_INLINE_ICON_TOOLS            "gq-icon-tools"
71 #define PIXBUF_INLINE_ICON_VIEW             "gq-icon-view"
72 #define PIXBUF_INLINE_ICON_ZOOMFILLHOR      "gq-icon-zoomfillhor"
73 #define PIXBUF_INLINE_ICON_ZOOMFILLVERT     "gq-icon-zoomfillvert"
74 #define PIXBUF_INLINE_LOGO                  "geeqie-logo"
75 #define PIXBUF_INLINE_METADATA              "gq-icon-metadata"
76 #define PIXBUF_INLINE_SCROLLER              "gq-scroller"
77 #define PIXBUF_INLINE_SPLIT_PANE_SYNC       "gq-icon-split-pane-sync"
78 #define PIXBUF_INLINE_UNKNOWN               "gq-icon-unknown"
79 #define PIXBUF_INLINE_VIDEO                 "gq-icon-video"
80
81 GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gboolean counter_clockwise);
82 GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gboolean mirror, gboolean flip);
83 GdkPixbuf* pixbuf_apply_orientation(GdkPixbuf *pixbuf, gint orientation);
84
85 /**
86  * @brief Composites the fill color with the existing contents of the pixbuf,
87  *        within the specified region, with a proportion set by the alpha (`a`)
88  *        parameter.
89  * @param pb The `GdkPixbuf` to paint into.
90  * @param x,y Coordinates of the top-left corner of the first region.
91  * @param w,h Extent of the first region.
92  * @param r,g,b Fill color.
93  * @param a The alpha to use for compositing. a=255 is solid (fully the new
94  *          color).  a=0 is tranparent (fully the original contents).
95  */
96 void pixbuf_draw_rect_fill(GdkPixbuf *pb,
97                            gint x, gint y, gint w, gint h,
98                            gint r, gint g, gint b, gint a);
99
100 /**
101  * @brief Fills the specified region of the pixbuf with the specified color.
102  * @param pb The `GdkPixbuf` to paint into.
103  * @param x,y Coordinates of the top-left corner of the first region.
104  * @param w,h Extent of the first region.
105  * @param r,g,b,a Fill color and alpha.
106  */
107 void pixbuf_set_rect_fill(GdkPixbuf *pb,
108                           gint x, gint y, gint w, gint h,
109                           gint r, gint g, gint b, gint a);
110
111 /**
112  * @brief Draws a rectangular stroke of the specified stroke width and color
113  *        around the specified region of the pixbuf.
114  * @param pb The `GdkPixbuf` to paint into.
115  * @param x,y Coordinates of the top-left corner of the region.
116  * @param w,h Extent of the region.
117  * @param r,g,b,a Line color and alpha.
118  * @param left_width Stroke width of the left edge of the rectangle.
119  * @param right_width Stroke width of the right edge of the rectangle.
120  * @param top_width Stroke width of the top edge of the rectangle.
121  * @param bottom_width Stroke width of the bottom edge of the rectangle.
122  */
123 void pixbuf_set_rect(GdkPixbuf *pb,
124                      gint x, gint y, gint w, gint h,
125                      gint r, gint g, gint b, gint a,
126                      gint left_width, gint right_width, gint top_width, gint bottom_width);
127
128 /**
129  * @brief Sets the specified pixel of the pixbuf to the specified color.
130  * @param pb The `GdkPixbuf` to paint into.
131  * @param x,y Coordinates of the pixel to set.
132  * @param r,g,b,a Color and alpha.
133  */
134 void pixbuf_pixel_set(GdkPixbuf *pb, gint x, gint y, gint r, gint g, gint b, gint a);
135
136
137 void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *widget,
138                         gint x, gint y,
139                         guint8 r, guint8 g, guint8 b, guint8 a);
140
141
142 /**
143  * @brief Draws a filled triangle of the specified color into the pixbuf, constrained
144  *        to the specified clip region.
145  * @param pb The `GdkPixbuf` to paint into.
146  * @param x1,y1 Coordinates of the first corner of the triangle.
147  * @param x2,y2 Coordinates of the second corner of the triangle.
148  * @param x3,y3 Coordinates of the third corner of the triangle.
149  * @param clip_x,clip_y Coordinates of the top-left corner of the clipping region.
150  * @param clip_w,clip_h Extent of the clipping region.
151  * @param r,g,b,a Color and alpha.
152  */
153 void pixbuf_draw_triangle(GdkPixbuf *pb,
154                           gint clip_x, gint clip_y, gint clip_w, gint clip_h,
155                           gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
156                           guint8 r, guint8 g, guint8 b, guint8 a);
157
158 /**
159  * @brief Draws the sub-segment of the specified line segment that lies within the
160  *        clip region into the pixbuf.
161  * @param pb The `GdkPixbuf` to paint into.
162  * @param clip_x,clip_y Coordinates of the top-left corner of the clipping region.
163  * @param clip_w,clip_h Extent of the clipping region.
164  * @param x1,y1 Coordinates of the first point of the line segment.
165  * @param x2,y2 Coordinates of the second point of the line segment.
166  * @param r,g,b,a Color and alpha.
167  */
168 void pixbuf_draw_line(GdkPixbuf *pb,
169                       gint clip_x, gint clip_y, gint clip_w, gint clip_h,
170                       gint x1, gint y1, gint x2, gint y2,
171                       guint8 r, guint8 g, guint8 b, guint8 a);
172
173 /**
174  * @brief Composites a "shaded" region of the specified color and with the
175  *        specified size and border gradient width into the clip region of the
176  *        specified pixbuf.
177  * @param pb The `GdkPixbuf` to paint into.
178  * @param clip_x,clip_y Coordinates of the top-left corner of the clipping region.
179  * @param clip_w,clip_h Extent of the clipping region.
180  * @param x,y Coordinates of the top-left corner of the shaded region.
181  * @param w,h Extent of the shaded region.
182  * @param border The thickness, in pixels, of the gradient border around the
183  *        fully-shaded region.
184  * @param r,g,b Shadow base color.
185  * @param a The max shadow composition fraction.  Note that any alpha value of the
186  *          original pixel will remain untouched.
187  */
188 void pixbuf_draw_shadow(GdkPixbuf *pb,
189                         gint clip_x, gint clip_y, gint clip_w, gint clip_h,
190                         gint x, gint y, gint w, gint h, gint border,
191                         guint8 r, guint8 g, guint8 b, guint8 a);
192
193 /**
194  * @brief Sets the r, g, and b values for each pixel within the specified region
195  *        of the pixbuf the average of the original values for that pixel.
196  * @param pb The `GdkPixbuf` to paint into.
197  * @param x,y Coordinates of the top-left corner of the region.
198  * @param w,h Extent of the region.
199  */
200 void pixbuf_desaturate_rect(GdkPixbuf *pb,
201                             gint x, gint y, gint w, gint h);
202 /**
203  * @brief Sets each full-black `(0, 0, 0)` or full-white `(255, 255, 255)` pixel in the
204  *        specified pixbuf region to full-red `(255, 0, 0)`.  Does not change alpha.
205  * @param pb The `GdkPixbuf` to paint into.
206  * @param x,y Coordinates of the top-left corner of the first region.
207  * @param w,h Extent of the first region.
208  */
209 void pixbuf_highlight_overunderexposed(GdkPixbuf *pb,
210                                        gint x, gint y, gint w, gint h);
211 /**
212  * @brief Sets the alpha channel to 255 (fully opaque) for every pixel in the specified
213  *        pixbuf region.
214  * @param pb The `GdkPixbuf` to paint into.
215  * @param x,y Coordinates of the top-left corner of the first region.
216  * @param w,h Extent of the first region.
217  */
218 void pixbuf_ignore_alpha_rect(GdkPixbuf *pb,
219                               gint x, gint y, gint w, gint h);
220
221 /* clipping utils */
222
223 // TODO(xsdg): Rename this function to util_intersect_regions.
224 /**
225  * @brief Performs an intersection of the two specified regions.
226  * @param[in] x,y Coordinates of the top-left corner of the first region.
227  * @param[in] w,h Extent of the first region.
228  * @param[in] clip_x,clip_y Coordinates of the top-left corner of the second region.
229  * @param[in] clip_w,clip_h Extent of the second region.
230  * @param[out] rx,ry Computed coordinates of the top-left corner of the intersection.
231  * @param[out] rw,rh Computed extent of the intersection.
232  * @retval FALSE The specified regions are non-overlapping.
233  * @retval TRUE The intersection operation was performed, and the output params were set.
234  */
235 gboolean util_clip_region(gint x, gint y, gint w, gint h,
236                           gint clip_x, gint clip_y, gint clip_w, gint clip_h,
237                           gint *rx, gint *ry, gint *rw, gint *rh);
238
239 // TODO(xsdg): Rename this function to util_triangle_bounding_box.
240 /**
241  * @brief Computes the bounding box for the specified triangle.
242  * @param[in] x1,y1 Coordinates of the first corner of the triangle.
243  * @param[in] x2,y2 Coordinates of the second corner of the triangle.
244  * @param[in] x3,y3 Coordinates of the third corner of the triangle.
245  * @param[out] rx,ry Computed coordinates of the top-left corner of the bounding box.
246  * @param[out] rw,rh Computed extent of the bounding box.
247  */
248 void util_clip_triangle(gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
249                         gint &rx, gint &ry, gint &rw, gint &rh);
250
251
252 #endif
253 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */