thread->err_msg = (byte *)msg;
}
+static inline void
+image_thread_err_dup(struct image_thread *thread, uns code, char *msg)
+{
+ thread->err_code = code;
+ thread->err_msg = mp_strdup(thread->pool, msg);
+}
+
void image_thread_err_format(struct image_thread *thread, uns code, char *msg, ...);
/* basic image manupulation */
struct image *image_new(struct image_thread *it, uns cols, uns rows, uns flags, struct mempool *pool);
struct image *image_clone(struct image_thread *it, struct image *src, uns flags, struct mempool *pool);
-void image_destroy(struct image_thread *it, struct image *img); /* only with NULL mempool */
+void image_destroy(struct image *img); /* only with NULL mempool */
void image_clear(struct image_thread *it, struct image *img);
byte *color_space_to_name(enum color_space cs);
byte *image_channels_format_to_name(uns format);
uns image_name_to_channels_format(byte *name);
+struct color {
+ byte c[3];
+ byte color_space;
+} PACKED;
+
/* scale.c */
int image_scale(struct image_thread *thread, struct image *dest, struct image *src);
void image_dimensions_fit_to_box(u32 *cols, u32 *rows, u32 max_cols, u32 max_rows, uns upsample);
+/* alpha.c */
+
+int image_apply_background(struct image_thread *thread, struct image *dest, struct image *src, struct color *background);
+
/* image-io.c */
enum image_format {
};
struct image_io {
- struct image *image;
- struct fastbuf *fastbuf;
- enum image_format format;
- struct mempool *pool;
- u32 cols;
- u32 rows;
- u32 flags;
+ /* R - read_header input */
+ /* H - read_header output */
+ /* I - read_data input */
+ /* O - read_data output */
+ /* W - write input */
+
+ struct image *image; /* [ OW] - image data */
+ enum image_format format; /* [R W] - file format (IMAGE_FORMAT_x) */
+ struct fastbuf *fastbuf; /* [R W] - source/destination stream */
+ struct mempool *pool; /* [ I ] - parameter to image_new */
+ u32 cols; /* [ HI ] - number of columns, parameter to image_new */
+ u32 rows; /* [ HI ] - number of rows, parameter to image_new */
+ u32 flags; /* [ HI ] - see enum image_io_flags */
+ u32 jpeg_quality; /* [ W] - JPEG compression quality (1..100) */
+ u32 number_of_colors; /* [ H ] - number of image colors */
+ struct color background_color; /* [ HI ] - background color, zero if undefined */
+
/* internals */
struct image_thread *thread;
struct mempool *internal_pool;
int image_destroy;
void *read_data;
void (*read_cancel)(struct image_io *io);
- union {
- struct {
- } jpeg;
- struct {
- } png;
- struct {
- } gif;
- };
+};
+
+enum image_io_flags {
+ IMAGE_IO_IMAGE_FLAGS = 0xffff, /* [ HI ] - mask of parameters to image new, read_header fills IMAGE_CHANNELS_FORMAT */
+ IMAGE_IO_HAS_PALETTE = 0x10000, /* [ H ] - true for image with indexed colors */
+ IMAGE_IO_USE_BACKGROUND = 0x20000, /* [ I ] - merge transparent pixels with background_color */
};
void image_io_init(struct image_thread *it, struct image_io *io);
enum image_format image_extension_to_format(byte *extension);
enum image_format image_file_name_to_format(byte *file_name);
-/* internals */
-
-#ifdef CONFIG_LIBJPEG
-int libjpeg_read_header(struct image_io *io);
-int libjpeg_read_data(struct image_io *io);
-int libjpeg_write(struct image_io *io);
-#endif
-
-#ifdef CONFIG_LIBPNG
-int libpng_read_header(struct image_io *io);
-int libpng_read_data(struct image_io *io);
-int libpng_write(struct image_io *io);
-#endif
-
-#ifdef CONFIG_LIBUNGIF
-int libungif_read_header(struct image_io *io);
-int libungif_read_data(struct image_io *io);
-#endif
-
-#ifdef CONFIG_LIBMAGICK
-int libmagick_read_header(struct image_io *io);
-int libmagick_read_data(struct image_io *io);
-int libmagick_write(struct image_io *io);
-#endif
-
#endif