#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>
/* 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;
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");
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))
- 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{ \
- 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
# 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;
- 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;
# 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;
- 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;
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_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;
- 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;
# 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: