]> mj.ucw.cz Git - libucw.git/blobdiff - images/io-libungif.c
XTypes: Added support to configuration and option parser.
[libucw.git] / images / io-libungif.c
index c46484311cbe980a86b6a5032a57972ee56d4e1a..bf97f743e11b5f009b1608090fa0bdcd98c8b467 100644 (file)
@@ -9,13 +9,13 @@
 
 #undef LOCAL_DEBUG
 
 
 #undef LOCAL_DEBUG
 
-#include "lib/lib.h"
-#include "lib/mempool.h"
-#include "lib/fastbuf.h"
-#include "images/images.h"
-#include "images/error.h"
-#include "images/color.h"
-#include "images/io-main.h"
+#include <ucw/lib.h>
+#include <ucw/mempool.h>
+#include <ucw/fastbuf.h>
+#include <images/images.h>
+#include <images/error.h>
+#include <images/color.h>
+#include <images/io-main.h>
 
 #include <gif_lib.h>
 
 
 #include <gif_lib.h>
 
@@ -147,7 +147,11 @@ libungif_read_data(struct image_io *io)
 
   /* Prepare image */
   struct image_io_read_data_internals rdi;
 
   /* Prepare image */
   struct image_io_read_data_internals rdi;
-  if (unlikely(!image_io_read_data_prepare(&rdi, io, image->ImageDesc.Width, image->ImageDesc.Height, io->flags)))
+  uint read_flags = io->flags;
+  uint cs = read_flags & IMAGE_COLOR_SPACE;
+  if (cs != COLOR_SPACE_GRAYSCALE && cs != COLOR_SPACE_RGB)
+    read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_RGB;
+  if (unlikely(!image_io_read_data_prepare(&rdi, io, image->ImageDesc.Width, image->ImageDesc.Height, read_flags)))
     {
       DGifCloseFile(gif);
       return 0;
     {
       DGifCloseFile(gif);
       return 0;
@@ -160,7 +164,7 @@ libungif_read_data(struct image_io *io)
   byte *img_end = rdi.image->pixels + rdi.image->image_size;
 
   /* Handle deinterlacing */
   byte *img_end = rdi.image->pixels + rdi.image->image_size;
 
   /* Handle deinterlacing */
-  uns dein_step, dein_next;
+  uint dein_step, dein_next;
   if (image->ImageDesc.Interlace)
     {
       DBG("Deinterlaced image");
   if (image->ImageDesc.Interlace)
     {
       DBG("Deinterlaced image");
@@ -175,16 +179,20 @@ libungif_read_data(struct image_io *io)
       case 1:
        {
          byte pal[256], *pal_pos = pal, *pal_end = pal + 256;
       case 1:
        {
          byte pal[256], *pal_pos = pal, *pal_end = pal + 256;
-         for (uns i = 0; i < (uns)color_map->ColorCount; i++, pal_pos++, palette++)
+         for (uint i = 0; i < (uint)color_map->ColorCount; i++, pal_pos++, palette++)
            *pal_pos = rgb_to_gray_func(palette->Red, palette->Green, palette->Blue);
          if (pal_pos != pal_end)
            bzero(pal_pos, pal_end - pal_pos);
          if (rd->transparent_index >= 0 && (io->flags & IMAGE_IO_USE_BACKGROUND))
            *pal_pos = rgb_to_gray_func(palette->Red, palette->Green, palette->Blue);
          if (pal_pos != pal_end)
            bzero(pal_pos, pal_end - pal_pos);
          if (rd->transparent_index >= 0 && (io->flags & IMAGE_IO_USE_BACKGROUND))
-           color_put_grayscale(pal + rd->transparent_index, &io->background_color);
+           if (!color_put(io->context, &io->background_color, pal + rd->transparent_index, COLOR_SPACE_GRAYSCALE))
+             {
+               DGifCloseFile(gif);
+               return 0;
+             }
 #        define DO_ROW_END do{ \
 #        define DO_ROW_END do{ \
-             walk_row_start += dein_step; \
-             if (walk_row_start >= img_end) \
-               { uns n = dein_next >> 1; walk_row_start = rdi.image->pixels + n, dein_step = dein_next; dein_next = n; } \
+             walk_row_start += dein_step; \
+             while (walk_row_start >= img_end) \
+               { uint n = dein_next >> 1; walk_row_start = rdi.image->pixels + n, dein_step = dein_next; dein_next = n; } \
            }while(0)
 #        define IMAGE_WALK_PREFIX(x) walk_##x
 #        define IMAGE_WALK_INLINE
            }while(0)
 #        define IMAGE_WALK_PREFIX(x) walk_##x
 #        define IMAGE_WALK_INLINE
@@ -194,13 +202,13 @@ libungif_read_data(struct image_io *io)
 #        define IMAGE_WALK_ROW_STEP 0
 #        define IMAGE_WALK_DO_STEP do{ *walk_pos = pal[*pixels++]; }while(0)
 #        define IMAGE_WALK_DO_ROW_END DO_ROW_END
 #        define IMAGE_WALK_ROW_STEP 0
 #        define IMAGE_WALK_DO_STEP do{ *walk_pos = pal[*pixels++]; }while(0)
 #        define IMAGE_WALK_DO_ROW_END DO_ROW_END
-#        include "images/image-walk.h"
+#        include <images/image-walk.h>
          break;
        }
       case 2:
        {
          byte pal[256 * 2], *pal_pos = pal, *pal_end = pal + 256 * 2;
          break;
        }
       case 2:
        {
          byte pal[256 * 2], *pal_pos = pal, *pal_end = pal + 256 * 2;
-         for (uns i = 0; i < (uns)color_map->ColorCount; i++, pal_pos += 2, palette++)
+         for (uint i = 0; i < (uint)color_map->ColorCount; i++, pal_pos += 2, palette++)
            {
              pal_pos[0] = rgb_to_gray_func(palette->Red, palette->Green, palette->Blue);
              pal_pos[1] = 255;
            {
              pal_pos[0] = rgb_to_gray_func(palette->Red, palette->Green, palette->Blue);
              pal_pos[1] = 255;
@@ -217,13 +225,13 @@ libungif_read_data(struct image_io *io)
 #        define IMAGE_WALK_ROW_STEP 0
 #        define IMAGE_WALK_DO_STEP do{ *(u16 *)walk_pos = ((u16 *)pal)[*pixels++]; }while(0)
 #        define IMAGE_WALK_DO_ROW_END DO_ROW_END
 #        define IMAGE_WALK_ROW_STEP 0
 #        define IMAGE_WALK_DO_STEP do{ *(u16 *)walk_pos = ((u16 *)pal)[*pixels++]; }while(0)
 #        define IMAGE_WALK_DO_ROW_END DO_ROW_END
-#        include "images/image-walk.h"
+#        include <images/image-walk.h>
          break;
        }
       case 3:
        {
          byte pal[256 * 4], *pal_pos = pal, *pal_end = pal + 256 * 4;
          break;
        }
       case 3:
        {
          byte pal[256 * 4], *pal_pos = pal, *pal_end = pal + 256 * 4;
-         for (uns i = 0; i < (uns)color_map->ColorCount; i++, pal_pos += 4, palette++)
+         for (uint i = 0; i < (uint)color_map->ColorCount; i++, pal_pos += 4, palette++)
            {
              pal_pos[0] = palette->Red;
              pal_pos[1] = palette->Green;
            {
              pal_pos[0] = palette->Red;
              pal_pos[1] = palette->Green;
@@ -232,7 +240,11 @@ libungif_read_data(struct image_io *io)
          if (pal_pos != pal_end)
            bzero(pal_pos, pal_end - pal_pos);
          if (rd->transparent_index >= 0 && (io->flags & IMAGE_IO_USE_BACKGROUND))
          if (pal_pos != pal_end)
            bzero(pal_pos, pal_end - pal_pos);
          if (rd->transparent_index >= 0 && (io->flags & IMAGE_IO_USE_BACKGROUND))
-           color_put_rgb(pal + 4 * rd->transparent_index, &io->background_color);
+           if (!color_put(io->context, &io->background_color, pal + 4 * rd->transparent_index, COLOR_SPACE_RGB))
+             {
+               DGifCloseFile(gif);
+               return 0;
+             }
 #        define IMAGE_WALK_PREFIX(x) walk_##x
 #        define IMAGE_WALK_INLINE
 #        define IMAGE_WALK_IMAGE (rdi.image)
 #        define IMAGE_WALK_PREFIX(x) walk_##x
 #        define IMAGE_WALK_INLINE
 #        define IMAGE_WALK_IMAGE (rdi.image)
@@ -241,13 +253,13 @@ libungif_read_data(struct image_io *io)
 #        define IMAGE_WALK_ROW_STEP 0
 #        define IMAGE_WALK_DO_STEP do{ byte *p = pal + 4 * (*pixels++); walk_pos[0] = p[0]; walk_pos[1] = p[1]; walk_pos[2] = p[2]; }while(0)
 #        define IMAGE_WALK_DO_ROW_END DO_ROW_END
 #        define IMAGE_WALK_ROW_STEP 0
 #        define IMAGE_WALK_DO_STEP do{ byte *p = pal + 4 * (*pixels++); walk_pos[0] = p[0]; walk_pos[1] = p[1]; walk_pos[2] = p[2]; }while(0)
 #        define IMAGE_WALK_DO_ROW_END DO_ROW_END
-#        include "images/image-walk.h"
+#        include <images/image-walk.h>
          break;
        }
       case 4:
        {
          byte pal[256 * 4], *pal_pos = pal, *pal_end = pal + 256 * 4;
          break;
        }
       case 4:
        {
          byte pal[256 * 4], *pal_pos = pal, *pal_end = pal + 256 * 4;
-         for (uns i = 0; i < (uns)color_map->ColorCount; i++, pal_pos += 4, palette++)
+         for (uint i = 0; i < (uint)color_map->ColorCount; i++, pal_pos += 4, palette++)
            {
              pal_pos[0] = palette->Red;
              pal_pos[1] = palette->Green;
            {
              pal_pos[0] = palette->Red;
              pal_pos[1] = palette->Green;
@@ -266,7 +278,7 @@ libungif_read_data(struct image_io *io)
 #        define IMAGE_WALK_ROW_STEP 0
 #        define IMAGE_WALK_DO_STEP do{ *(u32 *)walk_pos = ((u32 *)pal)[*pixels++]; }while(0)
 #        define IMAGE_WALK_DO_ROW_END DO_ROW_END
 #        define IMAGE_WALK_ROW_STEP 0
 #        define IMAGE_WALK_DO_STEP do{ *(u32 *)walk_pos = ((u32 *)pal)[*pixels++]; }while(0)
 #        define IMAGE_WALK_DO_ROW_END DO_ROW_END
-#        include "images/image-walk.h"
+#        include <images/image-walk.h>
          break;
        }
       default:
          break;
        }
       default: