]> www.fi.muni.cz Git - evince.git/blob - backend/ev-document-misc.c
ca818b7fdeecfa0182af22bde2844e903478e361
[evince.git] / backend / ev-document-misc.c
1
2 #include "ev-document-misc.h"
3
4 /* Returns a new GdkPixbuf that is suitable for placing in the thumbnail view.
5  * It is four pixels wider and taller than the source.  If source_pixbuf is not
6  * NULL, then it will fill the return pixbuf with the contents of
7  * source_pixbuf. */
8 GdkPixbuf *
9 ev_document_misc_get_thumbnail_frame (int        width,
10                                       int        height,
11                                       GdkPixbuf *source_pixbuf)
12 {
13         GdkPixbuf *retval;
14         guchar *data;
15         gint rowstride;
16
17         if (source_pixbuf)
18                 g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
19
20         if (source_pixbuf) {
21                 width = gdk_pixbuf_get_width (source_pixbuf);
22                 height = gdk_pixbuf_get_height (source_pixbuf);
23         }
24
25         /* make sure no one is passing us garbage */
26         g_assert (width > 0 && height > 0);
27
28         retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
29                                  TRUE, 8,
30                                  width + 4,
31                                  height + 4);
32         gdk_pixbuf_fill (retval, 0x000000ff);
33         if (source_pixbuf)
34                 gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
35                                       width,
36                                       height,
37                                       retval,
38                                       1, 1);
39         /* Add the corner */
40         data = gdk_pixbuf_get_pixels (retval);
41         rowstride = gdk_pixbuf_get_rowstride (retval);
42         data [(width + 2) * 4 + 3] = 0;
43         data [(width + 3) * 4 + 3] = 0;
44         data [(width + 2) * 4 + (rowstride * 1) + 3] = 0;
45         data [(width + 3) * 4 + (rowstride * 1) + 3] = 0;
46
47         data [(height + 2) * rowstride + 3] = 0;
48         data [(height + 3) * rowstride + 3] = 0;
49         data [(height + 2) * rowstride + 4 + 3] = 0;
50         data [(height + 3) * rowstride + 4 + 3] = 0;
51
52         return retval;
53 }