1 #ifndef _IMAGES_IMAGES_H
2 #define _IMAGES_IMAGES_H
4 #include "lib/mempool.h"
12 IMAGE_ERR_UNSPECIFIED,
13 IMAGE_ERR_NOT_IMPLEMENTED,
14 IMAGE_ERR_INVALID_DIMENSIONS,
15 IMAGE_ERR_INVALID_FILE_FORMAT,
16 IMAGE_ERR_INVALID_PIXEL_FORMAT,
17 IMAGE_ERR_READ_FAILED,
18 IMAGE_ERR_WRITE_FAILED,
24 enum image_error err_code;
28 void image_thread_init(struct image_thread *thread);
29 void image_thread_cleanup(struct image_thread *thread);
32 image_thread_flush(struct image_thread *thread)
35 thread->err_msg = NULL;
36 mp_flush(thread->pool);
40 image_thread_err(struct image_thread *thread, uns code, char *msg)
42 thread->err_code = code;
43 thread->err_msg = (byte *)msg;
46 void image_thread_err_format(struct image_thread *thread, uns code, char *msg, ...);
48 /* basic image manupulation */
50 #define IMAGE_MAX_SIZE 0xffffU /* maximum number of cols/rows, must be <(1<<16) */
51 #define IMAGE_SSE_ALIGN_SIZE (MAX(16, sizeof(uns)))
55 COLOR_SPACE_GRAYSCALE,
61 IMAGE_COLOR_SPACE = 0x7, /* mask for enum color_space */
62 IMAGE_ALPHA = 0x8, /* alpha channel */
63 IMAGE_PIXELS_ALIGNED = 0x10, /* align pixel size to the nearest power of two */
64 IMAGE_SSE_ALIGNED = 0x20, /* align scanlines to multiples of 16 bytes (both start and size) */
65 IMAGE_CHANNELS_FORMAT = IMAGE_COLOR_SPACE | IMAGE_ALPHA,
66 IMAGE_PIXEL_FORMAT = IMAGE_CHANNELS_FORMAT | IMAGE_PIXELS_ALIGNED,
67 IMAGE_ALIGNED = IMAGE_PIXELS_ALIGNED | IMAGE_SSE_ALIGNED,
71 byte *pixels; /* left top pixel, there are at least sizeof(uns)
72 unsed bytes after the buffer (possible optimizations) */
73 u32 cols; /* number of columns */
74 u32 rows; /* number of rows */
75 u32 pixel_size; /* size of pixel (1, 2, 3 or 4) */
76 u32 row_size; /* scanline size in bytes */
77 u32 image_size; /* size of pixels buffer (rows * rows_size) */
78 u32 flags; /* enum image_flag */
81 struct image *image_new(struct image_thread *it, uns cols, uns rows, uns flags, struct mempool *pool);
82 struct image *image_clone(struct image_thread *it, struct image *src, uns flags, struct mempool *pool);
83 void image_destroy(struct image_thread *it, struct image *img); /* only with NULL mempool */
84 void image_clear(struct image_thread *it, struct image *img);
86 byte *color_space_to_name(enum color_space cs);
87 byte *image_channels_format_to_name(uns format);
88 uns image_name_to_channels_format(byte *name);
92 int image_scale(struct image_thread *thread, struct image *dest, struct image *src);
93 void image_dimensions_fit_to_box(u32 *cols, u32 *rows, u32 max_cols, u32 max_rows, uns upsample);
98 IMAGE_FORMAT_UNDEFINED,
107 struct fastbuf *fastbuf;
108 enum image_format format;
109 struct mempool *pool;
114 struct image_thread *thread;
115 struct mempool *internal_pool;
118 void (*read_cancel)(struct image_io *io);
129 void image_io_init(struct image_thread *it, struct image_io *io);
130 void image_io_cleanup(struct image_io *io);
131 void image_io_reset(struct image_io *io);
133 int image_io_read_header(struct image_io *io);
134 struct image *image_io_read_data(struct image_io *io, int ref);
135 struct image *image_io_read(struct image_io *io, int ref);
137 int image_io_write(struct image_io *io);
139 byte *image_format_to_extension(enum image_format format);
140 enum image_format image_extension_to_format(byte *extension);
141 enum image_format image_file_name_to_format(byte *file_name);
145 #ifdef CONFIG_LIBJPEG
146 int libjpeg_read_header(struct image_io *io);
147 int libjpeg_read_data(struct image_io *io);
148 int libjpeg_write(struct image_io *io);
152 int libpng_read_header(struct image_io *io);
153 int libpng_read_data(struct image_io *io);
154 int libpng_write(struct image_io *io);
157 #ifdef CONFIG_LIBUNGIF
158 int libungif_read_header(struct image_io *io);
159 int libungif_read_data(struct image_io *io);
162 #ifdef CONFIG_LIBMAGICK
163 int libmagick_read_header(struct image_io *io);
164 int libmagick_read_data(struct image_io *io);
165 int libmagick_write(struct image_io *io);