1 #ifndef _IMAGES_IO_MAIN_H
2 #define _IMAGES_IO_MAIN_H
4 int libjpeg_read_header(struct image_io *io);
5 int libjpeg_read_data(struct image_io *io);
6 int libjpeg_write(struct image_io *io);
8 int libpng_read_header(struct image_io *io);
9 int libpng_read_data(struct image_io *io);
10 int libpng_write(struct image_io *io);
12 int libungif_read_header(struct image_io *io);
13 int libungif_read_data(struct image_io *io);
15 int libmagick_read_header(struct image_io *io);
16 int libmagick_read_data(struct image_io *io);
17 int libmagick_write(struct image_io *io);
19 struct image_io_read_data_internals {
25 static inline struct image *
26 image_io_read_data_prepare(struct image_io_read_data_internals *rdi, struct image_io *io, uns cols, uns rows)
28 rdi->need_scale = io->cols != cols | io->rows != rows;
29 rdi->need_destroy = rdi->need_scale || !io->pool;
30 return rdi->image = rdi->need_scale ?
31 image_new(io->thread, cols, rows, io->flags & IMAGE_CHANNELS_FORMAT, NULL) :
32 image_new(io->thread, io->cols, io->rows, io->flags & IMAGE_IO_IMAGE_FLAGS, io->pool);
36 image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image_io *io)
40 struct image *img = image_new(io->thread, io->cols, io->rows, io->flags & IMAGE_IO_IMAGE_FLAGS, io->pool);
43 if (rdi->need_destroy)
44 image_destroy(rdi->image);
47 if (unlikely(!image_scale(io->thread, img, rdi->image)))
49 image_destroy(rdi->image);
55 io->image_destroy = !io->pool;
59 io->image = rdi->image;
60 io->image_destroy = rdi->need_destroy;
66 image_io_read_data_break(struct image_io_read_data_internals *rdi, struct image_io *io UNUSED)
68 if (rdi->need_destroy)
69 image_destroy(rdi->image);