Add support for PNG images in .spv files.
[pspp] / src / output / image-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2020 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #ifndef OUTPUT_IMAGE_ITEM_H
18 #define OUTPUT_IMAGE_ITEM_H 1
19
20 #ifdef HAVE_CAIRO
21 #include <cairo.h>
22 #endif
23 #include <stdbool.h>
24 #include "output/output-item.h"
25
26 struct image_item
27   {
28     struct output_item output_item; /* Superclass */
29 #ifdef HAVE_CAIRO
30     cairo_surface_t *image;
31 #endif
32   };
33
34 #ifdef HAVE_CAIRO
35 struct image_item *image_item_create (cairo_surface_t *);
36 #endif
37
38 struct image_item *image_item_unshare (struct image_item *);
39 \f
40 /* This boilerplate for image_item, a subclass of output_item, was
41    autogenerated by mk-class-boilerplate. */
42
43 #include <assert.h>
44 #include "libpspp/cast.h"
45
46 extern const struct output_item_class image_item_class;
47
48 /* Returns true if SUPER is a image_item, otherwise false. */
49 static inline bool
50 is_image_item (const struct output_item *super)
51 {
52   return super->class == &image_item_class;
53 }
54
55 /* Returns SUPER converted to image_item.  SUPER must be a image_item, as
56    reported by is_image_item. */
57 static inline struct image_item *
58 to_image_item (const struct output_item *super)
59 {
60   assert (is_image_item (super));
61   return UP_CAST (super, struct image_item, output_item);
62 }
63
64 /* Returns INSTANCE converted to output_item. */
65 static inline struct output_item *
66 image_item_super (const struct image_item *instance)
67 {
68   return CONST_CAST (struct output_item *, &instance->output_item);
69 }
70
71 /* Increments INSTANCE's reference count and returns INSTANCE. */
72 static inline struct image_item *
73 image_item_ref (const struct image_item *instance)
74 {
75   return to_image_item (output_item_ref (&instance->output_item));
76 }
77
78 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
79    the reference count is now zero. */
80 static inline void
81 image_item_unref (struct image_item *instance)
82 {
83   output_item_unref (&instance->output_item);
84 }
85
86 /* Returns true if INSTANCE's reference count is greater than 1,
87    false otherwise. */
88 static inline bool
89 image_item_is_shared (const struct image_item *instance)
90 {
91   return output_item_is_shared (&instance->output_item);
92 }
93
94 void image_item_submit (struct image_item *);
95 \f
96 #endif /* output/image-item.h */