1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "output/image-item.h"
24 #include "libpspp/cast.h"
25 #include "libpspp/compiler.h"
26 #include "output/driver.h"
27 #include "output/output-item-provider.h"
29 #include "gl/xalloc.h"
30 #include "gl/xvasprintf.h"
32 /* Creates and returns a new image item containing IMAGE. Takes ownership of
35 image_item_create (cairo_surface_t *image)
37 struct image_item *item = xmalloc (sizeof *item);
38 *item = (struct image_item) {
39 .output_item = OUTPUT_ITEM_INITIALIZER (&image_item_class),
45 /* Submits ITEM to the configured output drivers, and transfers ownership to
46 the output subsystem. */
48 image_item_submit (struct image_item *item)
50 output_submit (&item->output_item);
54 image_item_unshare (struct image_item *old)
56 assert (old->output_item.ref_cnt > 0);
57 if (!image_item_is_shared (old))
59 image_item_unref (old);
61 struct image_item *new = xmalloc (sizeof *new);
62 *new = (struct image_item) {
63 .output_item = OUTPUT_ITEM_CLONE_INITIALIZER (&old->output_item),
64 .image = cairo_surface_reference (old->image),
70 image_item_get_label (const struct output_item *output_item UNUSED)
76 image_item_destroy (struct output_item *output_item)
78 struct image_item *item = to_image_item (output_item);
79 cairo_surface_destroy (item->image);
83 const struct output_item_class image_item_class =