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