]> mj.ucw.cz Git - libucw.git/blob - images/io-main.h
missing file
[libucw.git] / images / io-main.h
1 #ifndef _IMAGES_IO_MAIN_H
2 #define _IMAGES_IO_MAIN_H
3
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);
7
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);
11
12 int libungif_read_header(struct image_io *io);
13 int libungif_read_data(struct image_io *io);
14
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);
18
19 struct image_io_read_data_internals {
20   struct image *image;
21   int need_scale;
22   int need_destroy;
23 };
24
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)
27 {
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);
33 }
34
35 static inline int
36 image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image_io *io)
37 {
38   if (rdi->need_scale)
39     {
40       struct image *img = image_new(io->thread, io->cols, io->rows, io->flags & IMAGE_IO_IMAGE_FLAGS, io->pool);
41       if (unlikely(!img))
42         {
43           if (rdi->need_destroy)
44             image_destroy(rdi->image);
45           return 0;
46         }
47       if (unlikely(!image_scale(io->thread, img, rdi->image)))
48         {
49           image_destroy(rdi->image);
50           if (!io->pool)
51             image_destroy(img);
52           return 0;
53         }
54       io->image = img;
55       io->image_destroy = !io->pool;
56     }
57   else
58     {
59       io->image = rdi->image;
60       io->image_destroy = rdi->need_destroy;
61     }
62   return 1;
63 }
64
65 static inline void
66 image_io_read_data_break(struct image_io_read_data_internals *rdi, struct image_io *io UNUSED)
67 {
68   if (rdi->need_destroy)
69     image_destroy(rdi->image);
70 }
71
72 #endif