]> mj.ucw.cz Git - libucw.git/commitdiff
cleaning image flags manipulation
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Wed, 2 Aug 2006 10:14:22 +0000 (12:14 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Wed, 2 Aug 2006 10:14:22 +0000 (12:14 +0200)
images/image.c
images/images.h
images/io-libmagick.c
images/io-libpng.c
images/io-main.c

index 828313d53d8ec5099480582b5e8782b9ff9b19db..e030a94745d9426ae8f29e33bee87cac3a239f5b 100644 (file)
@@ -45,7 +45,7 @@ struct image *
 image_new(struct image_thread *it, uns cols, uns rows, uns flags, struct mempool *pool)
 {
   DBG("image_new(cols=%u rows=%u flags=0x%x pool=%p)", cols, rows, flags, pool);
-  flags &= IMAGE_PIXEL_FORMAT | IMAGE_SSE_ALIGNED;
+  flags &= IMAGE_NEW_FLAGS;
   if (unlikely(!image_dimensions_valid(cols, rows)))
     {
       image_thread_err_format(it, IMAGE_ERR_INVALID_DIMENSIONS, "Invalid image dimensions (%ux%u)", cols, rows);
@@ -121,7 +121,7 @@ image_clone(struct image_thread *it, struct image *src, uns flags, struct mempoo
 {
   DBG("image_clone(src=%p flags=0x%x pool=%p)", src, src->flags, pool);
   struct image *img;
-  flags &= ~IMAGE_CHANNELS_FORMAT;
+  flags &= IMAGE_NEW_FLAGS & ~IMAGE_CHANNELS_FORMAT;
   flags |= src->flags & IMAGE_CHANNELS_FORMAT;
   if (!(img = image_new(it, src->cols, src->rows, flags, pool)))
     return NULL;
@@ -185,7 +185,7 @@ image_init_matrix(struct image_thread *it, struct image *img, byte *pixels, uns
   img->rows = rows;
   img->row_size = row_size;
   img->image_size = rows * row_size;
-  img->flags = flags & (IMAGE_PIXEL_FORMAT | IMAGE_SSE_ALIGNED);
+  img->flags = flags & (IMAGE_NEW_FLAGS | IMAGE_GAPS_PROTECTED);
   return 1;
 }
 
@@ -199,7 +199,8 @@ image_init_subimage(struct image_thread *it UNUSED, struct image *img, struct im
   img->rows = rows;
   img->row_size = src->row_size;
   img->image_size = src->row_size * rows;
-  img->flags = src->flags & ~IMAGE_NEED_DESTROY; 
+  img->flags = src->flags & IMAGE_NEW_FLAGS;
+  img->flags |= IMAGE_GAPS_PROTECTED;
   return 1;
 }
 
index 12cada96de5a4190f063543f6f282a54d65e75e4..4ac9da6ee599c77a78b5f985727e4b1cc254b1c1 100644 (file)
@@ -70,9 +70,12 @@ enum image_flag {
   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 write to 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,
+  IMAGE_NEW_FLAGS = IMAGE_PIXEL_FORMAT | IMAGE_SSE_ALIGNED,
+  IMAGE_INTERNAL_FLAGS = IMAGE_NEED_DESTROY | IMAGE_GAPS_PROTECTED,
 };
 
 struct image {
@@ -82,13 +85,13 @@ struct image {
   u32 rows;                    /* number of rows */
   u32 pixel_size;              /* size of pixel (1, 2, 3 or 4) */
   u32 row_size;                        /* scanline size in bytes */
-  u32 image_size;              /* rows * rows_size */
+  u32 image_size;              /* rows * row_size */
   u32 flags;                   /* enum image_flag */
 };
 
 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 *img); /* only with NULL mempool */
+void image_destroy(struct image *img);
 void image_clear(struct image_thread *it, struct image *img);
 int image_init_matrix(struct image_thread *it, struct image *img, byte *pixels, uns cols, uns rows, uns row_size, uns flags);
 int image_init_subimage(struct image_thread *it, struct image *img, struct image *src, uns left, uns top, uns cols, uns rows);
index e4bca9c37e466bc69b34db369333aaf802e3f1c5..bd503e792a72b0dbb1fbfe906547e474dd73a144 100644 (file)
@@ -147,7 +147,7 @@ libmagick_read_data(struct image_io *io)
   struct image_io_read_data_internals rdi;
   uns read_flags = io->flags;
   if ((read_flags & IMAGE_IO_USE_BACKGROUND) && !(read_flags & IMAGE_ALPHA))
-    read_flags |= IMAGE_ALPHA;     
+    read_flags = (read_flags | IMAGE_ALPHA) & IMAGE_CHANNELS_FORMAT;
   if (unlikely(!image_io_read_data_prepare(&rdi, io, rd->image->columns, rd->image->rows, read_flags)))
     {
       libmagick_destroy_read_data(rd);
index a1705a376a467b044bad77a6f478cd8fec29d612..f15955a64cf83c045bd953cb1afa33fd96908b96 100644 (file)
@@ -229,7 +229,7 @@ libpng_read_data(struct image_io *io)
            if (io->flags & IMAGE_IO_USE_BACKGROUND)
              {
                 png_set_add_alpha(rd->png_ptr, 255, PNG_FILLER_AFTER);
-               read_flags |= IMAGE_ALPHA;
+               read_flags = (read_flags | IMAGE_ALPHA) & IMAGE_CHANNELS_FORMAT;
              }
            else if ((io->flags & IMAGE_PIXEL_FORMAT) == (COLOR_SPACE_RGB | IMAGE_PIXELS_ALIGNED))
               png_set_add_alpha(rd->png_ptr, 255, PNG_FILLER_AFTER);
@@ -251,7 +251,7 @@ libpng_read_data(struct image_io *io)
        if (!(io->flags & IMAGE_ALPHA))
          {
            if (io->flags & IMAGE_IO_USE_BACKGROUND)
-             read_flags |= IMAGE_ALPHA;
+             read_flags = (read_flags | IMAGE_ALPHA) & IMAGE_CHANNELS_FORMAT;
            else
               png_set_strip_alpha(rd->png_ptr);
          }  
@@ -267,7 +267,7 @@ libpng_read_data(struct image_io *io)
          png_set_rgb_to_gray_fixed(rd->png_ptr, 1, 21267, 71514);
        if (!(io->flags & IMAGE_ALPHA))
          if (io->flags & IMAGE_IO_USE_BACKGROUND)
-           read_flags |= IMAGE_ALPHA;
+           read_flags = (read_flags | IMAGE_ALPHA) & IMAGE_CHANNELS_FORMAT;
          else if ((io->flags & IMAGE_PIXEL_FORMAT) != (COLOR_SPACE_RGB | IMAGE_PIXELS_ALIGNED))
             png_set_strip_alpha(rd->png_ptr);
        break;
index f0902d3b5ad3c1ca1ee1650239e8546456bd2164..0ed20129d6db1ec9fdc4681a0fd9ceb9729617d4 100644 (file)
@@ -152,6 +152,8 @@ image_io_read_data(struct image_io *io, int ref)
     {
       if (!ref)
        io->flags |= IMAGE_IO_NEED_DESTROY;
+      else
+       io->flags &= ~IMAGE_IO_NEED_DESTROY;
       return io->image;
     }
   else
@@ -243,7 +245,7 @@ image_io_read_data_prepare(struct image_io_read_data_internals *rdi, struct imag
 {
   DBG("image_io_read_data_prepare()");
   if (rdi->need_transformations = io->cols != cols || io->rows != rows ||
-      ((io->flags ^ flags) & (IMAGE_IO_IMAGE_FLAGS & ~IMAGE_NEED_DESTROY)))
+      ((io->flags ^ flags) & IMAGE_NEW_FLAGS))
     return rdi->image = image_new(io->thread, cols, rows, flags & IMAGE_IO_IMAGE_FLAGS, NULL);
   else
     return rdi->image = image_new(io->thread, io->cols, io->rows, io->flags & IMAGE_IO_IMAGE_FLAGS, io->pool);
@@ -259,7 +261,7 @@ image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image
       if (io->cols != rdi->image->cols || io->rows != rdi->image->rows)
         {
          DBG("Scaling image");
-         rdi->need_transformations = ((io->flags ^ rdi->image->flags) & (IMAGE_IO_IMAGE_FLAGS & ~IMAGE_NEED_DESTROY));
+         rdi->need_transformations = ((io->flags ^ rdi->image->flags) & IMAGE_NEW_FLAGS);
          struct image *img = image_new(io->thread, io->cols, io->rows, rdi->image->flags, rdi->need_transformations ? NULL : io->pool);
          if (unlikely(!img))
            {
@@ -279,8 +281,9 @@ image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image
       if ((io->flags ^ rdi->image->flags) & IMAGE_ALPHA)
         {
          DBG("Aplying background");
-         rdi->need_transformations = 0;
-         struct image *img = image_new(io->thread, io->cols, io->rows, io->flags, rdi->need_transformations ? NULL : io->pool);
+         uns flags = rdi->image->flags & ~IMAGE_ALPHA; 
+         rdi->need_transformations = (flags & io->flags) & IMAGE_NEW_FLAGS;
+         struct image *img = image_new(io->thread, io->cols, io->rows, flags, rdi->need_transformations ? NULL : io->pool);
          if (unlikely(!img))
            {
              image_destroy(rdi->image);