-
Notifications
You must be signed in to change notification settings - Fork 111
/
asc-image.h
170 lines (150 loc) · 5.42 KB
/
asc-image.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2016-2024 Matthias Klumpp <matthias@tenstral.net>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the license, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined(__APPSTREAM_COMPOSE_H) && !defined(ASC_COMPILATION)
#error "Only <appstream-compose.h> can be included directly."
#endif
#pragma once
#include <glib-object.h>
#include <appstream.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
G_BEGIN_DECLS
#define ASC_TYPE_IMAGE (asc_image_get_type ())
G_DECLARE_FINAL_TYPE (AscImage, asc_image, ASC, IMAGE, GObject)
/**
* AscImageSaveFlags:
* @ASC_IMAGE_SAVE_FLAG_NONE: No special flags set
* @ASC_IMAGE_SAVE_FLAG_OPTIMIZE: Optimize generated PNG for size
* @ASC_IMAGE_SAVE_FLAG_PAD_16_9: Pad with alpha to 16:9 aspect
* @ASC_IMAGE_SAVE_FLAG_SHARPEN: Sharpen the image to clarify detail
* @ASC_IMAGE_SAVE_FLAG_BLUR: Blur the image to clear detail
*
* The flags used for saving images.
**/
typedef enum {
ASC_IMAGE_SAVE_FLAG_NONE = 0,
ASC_IMAGE_SAVE_FLAG_OPTIMIZE = 1 << 0,
ASC_IMAGE_SAVE_FLAG_PAD_16_9 = 1 << 1,
ASC_IMAGE_SAVE_FLAG_SHARPEN = 1 << 2,
ASC_IMAGE_SAVE_FLAG_BLUR = 1 << 3,
/*< private >*/
ASC_IMAGE_SAVE_FLAG_LAST
} AscImageSaveFlags;
/**
* AscImageLoadFlags:
* @ASC_IMAGE_LOAD_FLAG_NONE: No special flags set
* @ASC_IMAGE_LOAD_FLAG_SHARPEN: Sharpen the resulting image
* @ASC_IMAGE_LOAD_FLAG_ALLOW_UNSUPPORTED: Allow loading of unsupported image types.
* @ASC_IMAGE_LOAD_FLAG_ALWAYS_RESIZE: Always resize the source image to the perfect size
*
* The flags used for loading images.
**/
typedef enum {
ASC_IMAGE_LOAD_FLAG_NONE = 0,
ASC_IMAGE_LOAD_FLAG_SHARPEN = 1 << 0,
ASC_IMAGE_LOAD_FLAG_ALLOW_UNSUPPORTED = 1 << 1,
ASC_IMAGE_LOAD_FLAG_ALWAYS_RESIZE = 1 << 2,
/*< private >*/
ASC_IMAGE_LOAD_FLAG_LAST
} AscImageLoadFlags;
/**
* AscImageFormat:
* @ASC_IMAGE_FORMAT_UNKNOWN: Unknown image format.
* @ASC_IMAGE_FORMAT_PNG: PNG format
* @ASC_IMAGE_FORMAT_JPEG: JPEG format
* @ASC_IMAGE_FORMAT_GIF: GIF format
* @ASC_IMAGE_FORMAT_SVG: SVG format
* @ASC_IMAGE_FORMAT_SVGZ: Compressed SVG format
* @ASC_IMAGE_FORMAT_WEBP: WebP format
* @ASC_IMAGE_FORMAT_AVIF: AVIF format
* @ASC_IMAGE_FORMAT_XPM: XPM format
*
* File format of an image.
**/
typedef enum {
ASC_IMAGE_FORMAT_UNKNOWN,
ASC_IMAGE_FORMAT_PNG,
ASC_IMAGE_FORMAT_JPEG,
ASC_IMAGE_FORMAT_GIF,
ASC_IMAGE_FORMAT_SVG,
ASC_IMAGE_FORMAT_SVGZ,
ASC_IMAGE_FORMAT_WEBP,
ASC_IMAGE_FORMAT_AVIF,
ASC_IMAGE_FORMAT_XPM,
/*< private >*/
ASC_IMAGE_FORMAT_LAST
} AscImageFormat;
/**
* AscImageError:
* @ASC_IMAGE_ERROR_FAILED: Generic failure.
* @ASC_IMAGE_ERROR_UNSUPPORTED: The graphic type is not supported.
*
* An image processing error.
**/
typedef enum {
ASC_IMAGE_ERROR_FAILED,
ASC_IMAGE_ERROR_UNSUPPORTED,
/*< private >*/
ASC_IMAGE_ERROR_LAST
} AscImageError;
#define ASC_IMAGE_ERROR asc_image_error_quark ()
GQuark asc_image_error_quark (void);
const gchar *asc_image_format_to_string (AscImageFormat format);
AscImageFormat asc_image_format_from_string (const gchar *str);
AscImageFormat asc_image_format_from_filename (const gchar *fname);
gboolean asc_optimize_png (const gchar *fname, GError **error);
GHashTable *asc_image_supported_format_names (void);
AscImage *asc_image_new (void);
AscImage *asc_image_new_from_file (const gchar *fname,
guint dest_size,
AscImageLoadFlags flags,
GError **error);
AscImage *asc_image_new_from_data (const void *data,
gssize len,
guint dest_size,
gboolean compressed,
AscImageLoadFlags flags,
GError **error);
gboolean asc_image_load_filename (AscImage *image,
const gchar *filename,
guint dest_size,
guint src_size_min,
AscImageLoadFlags flags,
GError **error);
GdkPixbuf *asc_image_save_pixbuf (AscImage *image,
guint width,
guint height,
AscImageSaveFlags flags);
gboolean asc_image_save_filename (AscImage *image,
const gchar *filename,
guint width,
guint height,
AscImageSaveFlags flags,
GError **error);
GdkPixbuf *asc_image_get_pixbuf (AscImage *image);
void asc_image_set_pixbuf (AscImage *image, GdkPixbuf *pixbuf);
guint asc_image_get_width (AscImage *image);
guint asc_image_get_height (AscImage *image);
void asc_image_scale (AscImage *image, guint new_width, guint new_height);
void asc_image_scale_to_width (AscImage *image, guint new_width);
void asc_image_scale_to_height (AscImage *image, guint new_height);
void asc_image_scale_to_fit (AscImage *image, guint size);
void asc_pixbuf_blur (GdkPixbuf *src, gint radius, gint iterations);
void asc_pixbuf_sharpen (GdkPixbuf *src, gint radius, gdouble amount);
G_END_DECLS