Debian Codegraph @

src/gutenprintui2/print-image-thumbnail.c

raw symbols SCIP
1 /*
2 * Print plug-in for the GIMP.
3 *
4 * Copyright 1997-2000 Michael Sweet ([email protected]) and
5 * Robert Krawitz ([email protected])
6 * Copyright 2000 Charles Briscoe-Smith <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include <sys/types.h>
26 #include <string.h>
27
28 #include <gutenprintui2/gutenprintui.h>
29 #include "gutenprintui-internal.h"
30
31 /* Concrete type to represent image */
32 typedef struct
33 {
34 const guchar *data;
35 gint w, h, bpp;
36 gint32 real_bpp;
37 } thumbnail_image_t;
38
39 static const char *Thumbnail_get_appname(stp_image_t *image);
40 static void Thumbnail_conclude(stp_image_t *image);
41 static stp_image_status_t Thumbnail_get_row(stp_image_t *image,
42 unsigned char *data,
43 size_t byte_limit, int row);
44 static int Thumbnail_height(stp_image_t *image);
45 static int Thumbnail_width(stp_image_t *image);
46 static void Thumbnail_reset(stp_image_t *image);
47 static void Thumbnail_init(stp_image_t *image);
48
49 static stp_image_t theImage =
50 {
51 Thumbnail_init,
52 Thumbnail_reset,
53 Thumbnail_width,
54 Thumbnail_height,
55 Thumbnail_get_row,
56 Thumbnail_get_appname,
57 Thumbnail_conclude,
58 NULL
59 };
60
61 stp_image_t *
62 stpui_image_thumbnail_new(const guchar *data, gint w, gint h, gint bpp)
63 {
64 thumbnail_image_t *im;
65 if (! theImage.rep)
66 theImage.rep = stp_malloc(sizeof(thumbnail_image_t));
67 im = (thumbnail_image_t *) (theImage.rep);
68 memset(im, 0, sizeof(thumbnail_image_t));
69 im->data = data;
70 im->w = w;
71 im->h = h;
72 im->bpp = bpp;
73
74 theImage.reset(&theImage);
75 return &theImage;
76 }
77
78 static int
79 Thumbnail_width(stp_image_t *image)
80 {
81 thumbnail_image_t *im = (thumbnail_image_t *) (image->rep);
82 return im->w;
83 }
84
85 static int
86 Thumbnail_height(stp_image_t *image)
87 {
88 thumbnail_image_t *im = (thumbnail_image_t *) (image->rep);
89 return im->h;
90 }
91
92 static stp_image_status_t
93 Thumbnail_get_row(stp_image_t *image, unsigned char *data,
94 size_t byte_limit, int row)
95 {
96 thumbnail_image_t *im = (thumbnail_image_t *) (image->rep);
97 const guchar *where = im->data + (row * im->w * im->bpp);
98 memcpy(data, where, im->w * im->bpp);
99 (void)byte_limit;
100 return STP_IMAGE_STATUS_OK;
101 }
102
103 static void
104 Thumbnail_init(stp_image_t *image)
105 {
106 (void)image;
107 /* Nothing to do. */
108 }
109
110 static void
111 Thumbnail_reset(stp_image_t *image)
112 {
113 (void)image;
114 }
115
116 static void
117 Thumbnail_conclude(stp_image_t *image)
118 {
119 (void)image;
120 }
121
122 static const char *
123 Thumbnail_get_appname(stp_image_t *image)
124 {
125 static char pluginname[] = "Thumbnail V" VERSION " - " RELEASE_DATE;
126 (void)image;
127 return pluginname;
128 }