]> mj.ucw.cz Git - libucw.git/blobdiff - images/images.h
XML: Fixed reporting of characters via the PULL interface.
[libucw.git] / images / images.h
index 616c17b3cd8c6e1430ab76ba8bd02d18d498a41a..34ba1ad961823b1534f2fbb459e9ff1bbee18a1e 100644 (file)
@@ -55,12 +55,12 @@ extern uns image_max_bytes;         /* ImageLib.ImageMaxBytes */
 #define IMAGE_SSE_ALIGN_SIZE 16
 
 enum image_flag {
-  IMAGE_COLOR_SPACE = 0x7,             /* mask for enum color_space */
-  IMAGE_ALPHA = 0x8,                   /* alpha channel */
-  IMAGE_PIXELS_ALIGNED = 0x10,         /* align pixel size to the nearest power of two  */
-  IMAGE_SSE_ALIGNED = 0x20,            /* align scanlines to multiples of 16 bytes (both start and size) */
-  IMAGE_NEED_DESTROY = 0x40,           /* image is allocated with xmalloc */
-  IMAGE_GAPS_PROTECTED = 0x80,         /* cannot access gaps between rows */
+  IMAGE_COLOR_SPACE = 0xf,             /* mask for enum color_space */
+  IMAGE_ALPHA = 0x10,                  /* alpha channel */
+  IMAGE_PIXELS_ALIGNED = 0x20,         /* align pixel size to the nearest power of two  */
+  IMAGE_SSE_ALIGNED = 0x40,            /* align scanlines to multiples of 16 bytes (both start and size) */
+  IMAGE_NEED_DESTROY = 0x80,           /* image is allocated with xmalloc */
+  IMAGE_GAPS_PROTECTED = 0x100,                /* cannot access gaps between rows */
   IMAGE_CHANNELS_FORMAT = IMAGE_COLOR_SPACE | IMAGE_ALPHA,
   IMAGE_PIXEL_FORMAT = IMAGE_CHANNELS_FORMAT | IMAGE_PIXELS_ALIGNED,
   IMAGE_ALIGNED = IMAGE_PIXELS_ALIGNED | IMAGE_SSE_ALIGNED,
@@ -68,16 +68,27 @@ enum image_flag {
   IMAGE_INTERNAL_FLAGS = IMAGE_NEED_DESTROY | IMAGE_GAPS_PROTECTED,
 };
 
+#define IMAGE_MAX_CHANNELS 4
+#define IMAGE_CHANNELS_FORMAT_MAX_SIZE 128
+byte *image_channels_format_to_name(uns format, byte *buf);
+uns image_name_to_channels_format(byte *name);
+
+struct color {
+  byte c[IMAGE_MAX_CHANNELS];
+  byte color_space;
+};
+
 struct image {
   byte *pixels;                        /* aligned top left pixel, there are at least sizeof(uns)
                                   unused bytes after the buffer (possible optimizations) */
-  u32 cols;                    /* number of columns */
-  u32 rows;                    /* number of rows */
-  u32 pixel_size;              /* size of pixel in bytes (1, 2, 3 or 4) */
-  u32 row_size;                        /* scanline size in bytes */
-  u32 row_pixels_size;         /* scanline size in bytes excluding rows gaps */
-  u32 image_size;              /* rows * row_size */
-  u32 flags;                   /* enum image_flag */
+  uns cols;                    /* number of columns */
+  uns rows;                    /* number of rows */
+  uns channels;                        /* number of color channels including the alpha channel */
+  uns pixel_size;              /* size of pixel in bytes (1, 2, 3 or 4) */
+  uns row_size;                        /* scanline size in bytes */
+  uns row_pixels_size;         /* scanline size in bytes excluding rows gaps */
+  uns image_size;              /* rows * row_size */
+  uns flags;                   /* enum image_flag */
 };
 
 struct image *image_new(struct image_context *ctx, uns cols, uns rows, uns flags, struct mempool *pool);
@@ -92,24 +103,10 @@ image_dimensions_valid(uns cols, uns rows)
 {
   return cols && rows && cols <= image_max_dim && rows <= image_max_dim;
 }
-
-byte *color_space_to_name(uns 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_context *ctx, 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_context *ctx, struct image *dest, struct image *src, struct color *background);
+void image_dimensions_fit_to_box(uns *cols, uns *rows, uns max_cols, uns max_rows, uns upsample);
 
 /* image-io.c */
 
@@ -122,26 +119,24 @@ enum image_format {
 };
 
 struct image_io {
-                                       /*  R - read_header input */
-                                       /*   H - read_header output */
-                                       /*    I - read_data input */
-                                       /*     O - read_data output */
-                                       /*      W - write input */
+                                       /*  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 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 */
+  uns cols;                            /* [ HI  ] - number of columns, parameter to image_new */
+  uns rows;                            /* [ HI  ] - number of rows, parameter to image_new */
+  uns flags;                           /* [ HI  ] - see enum image_io_flags */
+  uns jpeg_quality;                    /* [    W] - JPEG compression quality (1..100) */
+  uns number_of_colors;                        /* [ H   ] - number of image colors */
   struct color background_color;       /* [ HI  ] - background color, zero if undefined */
-#ifdef CONFIG_IMAGES_EXIF
-  u32 exif_size;                       /* [ H  W] - EXIF size in bytes (zero if not present) */
+  uns exif_size;                       /* [ H  W] - EXIF size in bytes (zero if not present) */
   byte *exif_data;                     /* [ H  W] - EXIF data */
-#endif
 
   /* internals */
   struct image_context *context;
@@ -155,9 +150,7 @@ enum image_io_flags {
   IMAGE_IO_NEED_DESTROY = 0x10000,     /* [   O ] - enables automatic call of image_destroy */
   IMAGE_IO_HAS_PALETTE = 0x20000,      /* [ H   ] - true for image with indexed colors */
   IMAGE_IO_USE_BACKGROUND = 0x40000,   /* [  I  ] - merge transparent pixels with background_color */
-#ifdef CONFIG_IMAGES_EXIF
   IMAGE_IO_WANT_EXIF = 0x80000,                /* [R    ] - read EXIF data if present */
-#endif
 };
 
 int image_io_init(struct image_context *ctx, struct image_io *io);