* of the GNU Lesser General Public License.
*/
-#if !defined(IMAGE_WALK_INLINE) && !defined(IMAGE_WALK_STATIC)
-# error Missing IMAGE_WALK_INLINE or IMAGE_WALK_STATIC
+#ifndef IMAGE_WALK_PREFIX
+# error Undefined IMAGE_WALK_PREFIX
#endif
+#define P(x) IMAGE_WALK_PREFIX(x)
+
#if !defined(IMAGE_WALK_UNROLL)
# define IMAGE_WALK_UNROLL 1
#elif IMAGE_WALK_UNROLL != 1 && IMAGE_WALK_UNROLL != 2 && IMAGE_WALK_UNROLL != 4
# error IMAGE_WALK_UNROLL must be 1, 2 or 4
#endif
+#ifndef IMAGE_WALK_IMAGE
+# define IMAGE_WALK_IMAGE P(img)
+#endif
#ifndef IMAGE_WALK_PIXELS
-# define IMAGE_WALK_PIXELS (img->pixels)
+# define IMAGE_WALK_PIXELS (IMAGE_WALK_IMAGE->pixels)
#endif
#ifndef IMAGE_WALK_COLS
-# define IMAGE_WALK_COLS (img->cols)
+# define IMAGE_WALK_COLS (IMAGE_WALK_IMAGE->cols)
#endif
#ifndef IMAGE_WALK_ROWS
-# define IMAGE_WALK_ROWS (img->rows)
+# define IMAGE_WALK_ROWS (IMAGE_WALK_IMAGE->rows)
#endif
#ifndef IMAGE_WALK_COL_STEP
-# define IMAGE_WALK_COL_STEP (img->pixel_size)
+# define IMAGE_WALK_COL_STEP (IMAGE_WALK_IMAGE->pixel_size)
#endif
#ifndef IMAGE_WALK_ROW_STEP
-# define IMAGE_WALK_ROW_STEP (img->row_size)
+# define IMAGE_WALK_ROW_STEP (IMAGE_WALK_IMAGE->row_size)
#endif
#ifdef IMAGE_WALK_DOUBLE
+# ifndef IMAGE_WALK_SEC_IMAGE
+# define IMAGE_WALK_SEC_IMAGE P(sec_img)
+# endif
# ifndef IMAGE_WALK_SEC_PIXELS
-# define IMAGE_WALK_SEC_PIXELS (sec_img->pixels)
+# define IMAGE_WALK_SEC_PIXELS (IMAGE_WALK_SEC_IMAGE->pixels)
# endif
# ifndef IMAGE_WALK_SEC_COLS
-# define IMAGE_WALK_SEC_COLS (sec_img->cols)
+# define IMAGE_WALK_SEC_COLS (IMAGE_WALK_SEC_IMAGE->cols)
# endif
# ifndef IMAGE_WALK_SEC_ROWS
-# define IMAGE_WALK_SEC_ROWS (sec_img->rows)
+# define IMAGE_WALK_SEC_ROWS (IMAGE_WALK_SEC_IMAGE->rows)
# endif
# ifndef IMAGE_WALK_SEC_COL_STEP
-# define IMAGE_WALK_SEC_COL_STEP (sec_img->pixel_size)
+# define IMAGE_WALK_SEC_COL_STEP (IMAGE_WALK_SEC_IMAGE->pixel_size)
# endif
# ifndef IMAGE_WALK_SEC_ROW_STEP
-# define IMAGE_WALK_SEC_ROW_STEP (sec_img->row_size)
+# define IMAGE_WALK_SEC_ROW_STEP (IMAGE_WALK_SEC_IMAGE->row_size)
# endif
-# define STEP IMAGE_WALK_DO_STEP; pos += col_step; sec_pos += sec_col_step
+# define IMAGE_WALK__STEP IMAGE_WALK_DO_STEP; P(pos) += P(col_step); P(sec_pos) += P(sec_col_step)
#else
-# define STEP IMAGE_WALK_DO_STEP; pos += col_step
+# define IMAGE_WALK__STEP IMAGE_WALK_DO_STEP; P(pos) += P(col_step)
#endif
#ifndef IMAGE_WALK_DO_START
#endif
#ifndef IMAGE_WALK_INLINE
-static void IMAGE_WALK_STATIC
- (struct image *img
+static void P(walk)
+ (struct image *P(img)
# ifdef IMAGE_WALK_DOUBLE
- , struct image *sec_img
+ , struct image *P(sec_img)
# endif
# ifdef IMAGE_WALK_EXTRA_ARGS
, IMAGE_WALK_EXTRA_ARGS
)
#endif
{
- uns cols = IMAGE_WALK_COLS;
- uns rows = IMAGE_WALK_ROWS;
+ uns P(cols) = IMAGE_WALK_COLS;
+ uns P(rows) = IMAGE_WALK_ROWS;
# if IMAGE_WALK_UNROLL > 1
- uns cols_unroll_block_count = cols / IMAGE_WALK_UNROLL;
- uns cols_unroll_end_count = cols % IMAGE_WALK_UNROLL;
+ uns P(cols_unroll_block_count) = P(cols) / IMAGE_WALK_UNROLL;
+ uns P(cols_unroll_end_count) = P(cols) % IMAGE_WALK_UNROLL;
# endif
- byte *pos = IMAGE_WALK_PIXELS, *row_start = pos;
- int col_step = IMAGE_WALK_COL_STEP;
- int row_step = IMAGE_WALK_ROW_STEP;
+ byte *P(pos) = IMAGE_WALK_PIXELS, *P(row_start) = P(pos);
+ int P(col_step) = IMAGE_WALK_COL_STEP;
+ int P(row_step) = IMAGE_WALK_ROW_STEP;
# ifdef IMAGE_WALK_DOUBLE
- byte *sec_pos = IMAGE_WALK_SEC_PIXELS, *sec_row_start = sec_pos;
- int sec_col_step = IMAGE_WALK_SEC_COL_STEP;
- int sec_row_step = IMAGE_WALK_SEC_ROW_STEP;
+ byte *P(sec_pos) = IMAGE_WALK_SEC_PIXELS, *P(sec_row_start) = P(sec_pos);
+ int P(sec_col_step) = IMAGE_WALK_SEC_COL_STEP;
+ int P(sec_row_step) = IMAGE_WALK_SEC_ROW_STEP;
# endif
IMAGE_WALK_DO_START;
- while (rows--)
+ while (P(rows)--)
{
IMAGE_WALK_DO_ROW_START;
# if IMAGE_WALK_UNROLL == 1
- for (uns i = cols; i--; )
+ for (uns P(_i) = P(cols); P(_i)--; )
# else
- for (uns i = cols_unroll_block_count; i--; )
+ for (uns P(_i) = P(cols_unroll_block_count); P(_i)--; )
# endif
{
# if IMAGE_WALK_UNROLL >= 4
- STEP;
- STEP;
+ IMAGE_WALK__STEP;
+ IMAGE_WALK__STEP;
# endif
# if IMAGE_WALK_UNROLL >= 2
- STEP;
+ IMAGE_WALK__STEP;
# endif
- STEP;
+ IMAGE_WALK__STEP;
}
# if IMAGE_WALK_UNROLL > 1
- for (uns i = cols_unroll_end_count; i--; )
+ for (uns P(_i) = P(cols_unroll_end_count); P(_i)--; )
{
- STEP;
+ IMAGE_WALK__STEP;
}
# endif
IMAGE_WALK_DO_ROW_END;
- pos = (row_start += row_step);
+ P(pos) = (P(row_start) += P(row_step));
# ifdef IMAGE_WALK_DOUBLE
- sec_pos = (sec_row_start += sec_row_step);
+ P(sec_pos) = (P(sec_row_start) += P(sec_row_step));
# endif
}
IMAGE_WALK_DO_END;
}
+#undef IMAGE_WALK_PREFIX
#undef IMAGE_WALK_INLINE
-#undef IMAGE_WALK_STATIC
#undef IMAGE_WALK_UNROLL
#undef IMAGE_WALK_DOUBLE
#undef IMAGE_WALK_EXTRA_ARGS
#undef IMAGE_WALK_DO_ROW_START
#undef IMAGE_WALK_DO_ROW_END
#undef IMAGE_WALK_DO_STEP
-#undef STEP
+#undef IMAGE_WALK__STEP
+#undef P
return NULL;
if (img->image_size)
{
- if (src->pixel_size != img->pixel_size)
+ if (src->pixel_size != img->pixel_size) /* conversion between aligned and unaligned RGB */
{
- struct image *sec_img = src;
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
+# define IMAGE_WALK_SEC_IMAGE src
# define IMAGE_WALK_DOUBLE
-# define IMAGE_WALK_DO_STEP do{ *(u32 *)pos = *(u32 *)sec_pos; }while(0)
+# define IMAGE_WALK_DO_STEP do{ walk_pos[0] = walk_sec_pos[0]; walk_pos[1] = walk_sec_pos[1]; walk_pos[2] = walk_sec_pos[2]; }while(0)
# include "images/image-walk.h"
}
else if (src->row_size != img->row_size)
static void
libjpeg_emit_message(j_common_ptr cinfo UNUSED, int msg_level UNUSED)
{
-#ifdef LOCAL_DEBUG
+#ifdef LOCAL_DEBUG
byte buf[JMSG_LENGTH_MAX];
cinfo->err->format_message(cinfo, buf);
DBG("libjpeg_emit_message(): [%d] %s", msg_level, buf);
-#endif
+#endif
if (unlikely(msg_level == -1))
longjmp(((struct libjpeg_err *)(cinfo)->err)->setjmp_buf, 1);
}
DBG("libjpeg_read_data()");
struct libjpeg_read_internals *i = io->read_data;
-
- /* Select color space */
+
+ /* Select color space */
switch (io->flags & IMAGE_COLOR_SPACE)
{
case COLOR_SPACE_GRAYSCALE:
image_thread_err(io->thread, IMAGE_ERR_INVALID_PIXEL_FORMAT, "Unsupported color space.");
return 0;
}
-
+
/* Setup fallback */
if (setjmp(i->err.setjmp_buf))
{
case 2:
{
byte buf[img->cols], *src;
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 2
# define IMAGE_WALK_DO_ROW_START do{ src = buf; jpeg_read_scanlines(&i->cinfo, (JSAMPLE **)&src, 1); }while(0)
-# define IMAGE_WALK_DO_STEP do{ pos[0] = *src++; pos[1] = 255; }while(0)
+# define IMAGE_WALK_DO_STEP do{ walk_pos[0] = *src++; walk_pos[1] = 255; }while(0)
# include "images/image-walk.h"
}
break;
case 4:
{
byte buf[img->cols * 3], *src;
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 4
# define IMAGE_WALK_DO_ROW_START do{ src = buf; jpeg_read_scanlines(&i->cinfo, (JSAMPLE **)&src, 1); }while(0)
-# define IMAGE_WALK_DO_STEP do{ *(u32 *)pos = *(u32 *)src; pos[3] = 255; src += 3; }while(0)
+# define IMAGE_WALK_DO_STEP do{ *(u32 *)walk_pos = *(u32 *)src; walk_pos[3] = 255; src += 3; }while(0)
# include "images/image-walk.h"
}
break;
ASSERT(0);
}
ASSERT(i->cinfo.output_scanline == i->cinfo.output_height);
-
+
/* Destroy libjpeg object */
jpeg_finish_decompress(&i->cinfo);
jpeg_destroy_decompress(&i->cinfo);
return 0;
}
jpeg_create_compress(&i.cinfo);
-
+
/* Initialize destination manager */
i.cinfo.dest = &i.dest;
i.dest.init_destination = libjpeg_init_destination;
case 2:
{
byte buf[img->cols], *dest = buf;
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 2
# define IMAGE_WALK_DO_ROW_END do{ dest = buf; jpeg_write_scanlines(&i.cinfo, (JSAMPLE **)&dest, 1); }while(0)
-# define IMAGE_WALK_DO_STEP do{ *dest++ = pos[0]; }while(0)
+# define IMAGE_WALK_DO_STEP do{ *dest++ = walk_pos[0]; }while(0)
# include "images/image-walk.h"
}
break;
case 4:
{
byte buf[img->cols * 3], *dest = buf;
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 4
# define IMAGE_WALK_DO_ROW_END do{ dest = buf; jpeg_write_scanlines(&i.cinfo, (JSAMPLE **)&dest, 1); }while(0)
-# define IMAGE_WALK_DO_STEP do{ *dest++ = pos[0]; *dest++ = pos[1]; *dest++ = pos[2]; }while(0)
+# define IMAGE_WALK_DO_STEP do{ *dest++ = walk_pos[0]; *dest++ = walk_pos[1]; *dest++ = walk_pos[2]; }while(0)
# include "images/image-walk.h"
}
break;
switch (img->pixel_size)
{
case 1:
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 1
# define IMAGE_WALK_DO_STEP do{ \
- pos[0] = libmagick_pixel_to_gray(src); \
+ walk_pos[0] = libmagick_pixel_to_gray(src); \
src++; }while(0)
# include "images/image-walk.h"
break;
case 2:
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 2
# define IMAGE_WALK_DO_STEP do{ \
- pos[0] = libmagick_pixel_to_gray(src); \
- pos[1] = QUANTUM_TO_BYTE(src->opacity); \
+ walk_pos[0] = libmagick_pixel_to_gray(src); \
+ walk_pos[1] = QUANTUM_TO_BYTE(src->opacity); \
src++; }while(0)
# include "images/image-walk.h"
break;
case 3:
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 3
# define IMAGE_WALK_DO_STEP do{ \
- pos[0] = QUANTUM_TO_BYTE(src->red); \
- pos[1] = QUANTUM_TO_BYTE(src->green); \
- pos[2] = QUANTUM_TO_BYTE(src->blue); \
+ walk_pos[0] = QUANTUM_TO_BYTE(src->red); \
+ walk_pos[1] = QUANTUM_TO_BYTE(src->green); \
+ walk_pos[2] = QUANTUM_TO_BYTE(src->blue); \
src++; }while(0)
# include "images/image-walk.h"
break;
case 4:
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 4
# define IMAGE_WALK_DO_STEP do{ \
- pos[0] = QUANTUM_TO_BYTE(src->red); \
- pos[1] = QUANTUM_TO_BYTE(src->green); \
- pos[2] = QUANTUM_TO_BYTE(src->blue); \
- pos[3] = QUANTUM_TO_BYTE(src->opacity); \
+ walk_pos[0] = QUANTUM_TO_BYTE(src->red); \
+ walk_pos[1] = QUANTUM_TO_BYTE(src->green); \
+ walk_pos[2] = QUANTUM_TO_BYTE(src->blue); \
+ walk_pos[3] = QUANTUM_TO_BYTE(src->opacity); \
src++; }while(0)
# include "images/image-walk.h"
break;
switch (img->pixel_size)
{
case 1:
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 1
# define IMAGE_WALK_DO_STEP do{ \
- dest->red = BYTE_TO_QUANTUM(pos[0]); \
- dest->green = BYTE_TO_QUANTUM(pos[0]); \
- dest->blue = BYTE_TO_QUANTUM(pos[0]); \
+ dest->red = BYTE_TO_QUANTUM(walk_pos[0]); \
+ dest->green = BYTE_TO_QUANTUM(walk_pos[0]); \
+ dest->blue = BYTE_TO_QUANTUM(walk_pos[0]); \
dest->opacity = OPACITY_MAX; \
dest++; }while(0)
# include "images/image-walk.h"
break;
case 2:
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 2
# define IMAGE_WALK_DO_STEP do{ \
- dest->red = BYTE_TO_QUANTUM(pos[0]); \
- dest->green = BYTE_TO_QUANTUM(pos[0]); \
- dest->blue = BYTE_TO_QUANTUM(pos[0]); \
- dest->opacity = BYTE_TO_QUANTUM(pos[1]); \
+ dest->red = BYTE_TO_QUANTUM(walk_pos[0]); \
+ dest->green = BYTE_TO_QUANTUM(walk_pos[0]); \
+ dest->blue = BYTE_TO_QUANTUM(walk_pos[0]); \
+ dest->opacity = BYTE_TO_QUANTUM(walk_pos[1]); \
dest++; }while(0)
# include "images/image-walk.h"
break;
case 3:
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 3
# define IMAGE_WALK_DO_STEP do{ \
- dest->red = BYTE_TO_QUANTUM(pos[0]); \
- dest->green = BYTE_TO_QUANTUM(pos[1]); \
- dest->blue = BYTE_TO_QUANTUM(pos[2]); \
+ dest->red = BYTE_TO_QUANTUM(walk_pos[0]); \
+ dest->green = BYTE_TO_QUANTUM(walk_pos[1]); \
+ dest->blue = BYTE_TO_QUANTUM(walk_pos[2]); \
dest->opacity = OPACITY_MAX; \
dest++; }while(0)
# include "images/image-walk.h"
break;
case 4:
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 4
# define IMAGE_WALK_DO_STEP do{ \
- dest->red = BYTE_TO_QUANTUM(pos[0]); \
- dest->green = BYTE_TO_QUANTUM(pos[1]); \
- dest->blue = BYTE_TO_QUANTUM(pos[2]); \
- dest->opacity = BYTE_TO_QUANTUM(pos[3]); \
+ dest->red = BYTE_TO_QUANTUM(walk_pos[0]); \
+ dest->green = BYTE_TO_QUANTUM(walk_pos[1]); \
+ dest->blue = BYTE_TO_QUANTUM(walk_pos[2]); \
+ dest->opacity = BYTE_TO_QUANTUM(walk_pos[3]); \
dest++; }while(0)
# include "images/image-walk.h"
break;
libpng_read_header(struct image_io *io)
{
DBG("libpng_read_header()");
-
+
/* Create libpng structures */
struct libpng_read_data *rd = io->read_data = mp_alloc(io->internal_pool, sizeof(*rd));
rd->png_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING,
png_destroy_read_struct(&rd->png_ptr, &rd->info_ptr, NULL);
return 0;
}
-
+
/* Setup libpng longjump */
if (unlikely(setjmp(png_jmpbuf(rd->png_ptr))))
{
png_destroy_read_struct(&rd->png_ptr, &rd->info_ptr, &rd->end_ptr);
return 0;
}
-
+
/* Setup libpng IO */
png_set_read_fn(rd->png_ptr, io->fastbuf, libpng_read_fn);
png_set_user_limits(rd->png_ptr, IMAGE_MAX_SIZE, IMAGE_MAX_SIZE);
png_destroy_read_struct(&rd->png_ptr, &rd->info_ptr, &rd->end_ptr);
image_thread_err(io->thread, IMAGE_ERR_READ_FAILED, "Unknown color type");
break;
- }
+ }
/* Success */
io->read_cancel = libpng_read_cancel;
}
volatile int need_scale = io->cols != rd->cols || io->rows != rd->rows;
- struct image * volatile img = need_scale ?
+ struct image * volatile img = need_scale ?
image_new(io->thread, rd->cols, rd->rows, io->flags & IMAGE_PIXEL_FORMAT, NULL) :
image_new(io->thread, rd->cols, rd->rows, io->flags, io->pool);
if (!img)
else
io->image = img;
io->image_destroy = !io->pool;
-
+
return 1;
}
png_destroy_write_struct(&png_ptr, NULL);
return 0;
}
-
+
/* Setup libpng longjump */
if (unlikely(setjmp(png_jmpbuf(png_ptr))))
{
/* Setup libpng IO */
png_set_write_fn(png_ptr, io->fastbuf, libpng_write_fn, libpng_flush_fn);
-
+
/* Setup PNG parameters */
struct image *img = io->image;
switch (img->flags & IMAGE_PIXEL_FORMAT)
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
break;
default:
- ASSERT(0);
+ ASSERT(0);
}
png_write_info(png_ptr, info_ptr);
ColorMapObject *color_map = image->ImageDesc.ColorMap ? : gif->SColorMap;
GifColorType *palette = color_map->Colors;
uns background = gif->SBackGroundColor;
+ byte *img_end = img->pixels + img->image_size;
/* Handle deinterlacing */
uns dein_step, dein_next;
{
case 1:
{
- uns i;
byte pal[256], *pal_pos = pal, *pal_end = pal + 256;
- for (i = 0; i < (uns)color_map->ColorCount; i++, pal_pos++, palette++)
+ for (uns i = 0; i < (uns)color_map->ColorCount; i++, pal_pos++, palette++)
*pal_pos = libungif_pixel_to_gray(palette);
if (pal_pos != pal_end)
bzero(pal_pos, pal_end - pal_pos);
+# define DO_ROW_END do{ \
+ walk_row_start += dein_step; \
+ if (walk_row_start > img_end) \
+ { uns n = dein_next >> 1; walk_row_start = img->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_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 1
# define IMAGE_WALK_ROW_STEP 0
-# define IMAGE_WALK_DO_STEP do{ *pos = pal[*pixels++]; }while(0)
-# define IMAGE_WALK_DO_ROW_END do{ \
- row_start += dein_step; \
- if (row_start > img->pixels + img->image_size) \
- row_start = img->pixels + (dein_next >>= 1), dein_step = dein_next << 1; \
- }while(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"
break;
}
case 2:
{
- uns i;
byte pal[256 * 2], *pal_pos = pal, *pal_end = pal + 256 * 2;
- for (i = 0; i < (uns)color_map->ColorCount; i++, pal_pos += 2, palette++)
+ for (uns i = 0; i < (uns)color_map->ColorCount; i++, pal_pos += 2, palette++)
{
pal_pos[0] = libungif_pixel_to_gray(palette);
pal_pos[1] = 255;
bzero(pal_pos, pal_end - pal_pos);
if (background < 256)
pal[background * 2 + 1] = 0;
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 2
# define IMAGE_WALK_ROW_STEP 0
-# define IMAGE_WALK_DO_STEP do{ *(u16 *)pos = ((u16 *)pal)[*pixels++]; }while(0)
-# define IMAGE_WALK_DO_ROW_END do{ \
- row_start += dein_step; \
- if (row_start > img->pixels + img->image_size) \
- row_start = img->pixels + (dein_next >>= 1), dein_step = dein_next << 1; \
- }while(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"
break;
}
case 3:
{
- uns i;
byte pal[256 * 4], *pal_pos = pal, *pal_end = pal + 256 * 4;
- for (i = 0; i < (uns)color_map->ColorCount; i++, pal_pos += 4, palette++)
+ for (uns i = 0; i < (uns)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);
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 3
# define IMAGE_WALK_ROW_STEP 0
-# define IMAGE_WALK_DO_STEP do{ byte *p = pal + 4 * (*pixels++); pos[0] = p[0]; pos[1] = p[1]; pos[2] = p[2]; }while(0)
-# define IMAGE_WALK_DO_ROW_END do{ \
- row_start += dein_step; \
- if (row_start > img->pixels + img->image_size) \
- row_start = img->pixels + (dein_next >>= 1), dein_step = dein_next << 1; \
- }while(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"
break;
}
case 4:
{
- uns i;
byte pal[256 * 4], *pal_pos = pal, *pal_end = pal + 256 * 4;
- for (i = 0; i < (uns)color_map->ColorCount; i++, pal_pos += 4, palette++)
+ for (uns i = 0; i < (uns)color_map->ColorCount; i++, pal_pos += 4, palette++)
{
pal_pos[0] = palette->Red;
pal_pos[1] = palette->Green;
bzero(pal_pos, pal_end - pal_pos);
if (background < 256)
pal[background * 4 + 3] = 0;
+# define IMAGE_WALK_PREFIX(x) walk_##x
# define IMAGE_WALK_INLINE
+# define IMAGE_WALK_IMAGE img
# define IMAGE_WALK_UNROLL 4
# define IMAGE_WALK_COL_STEP 4
# define IMAGE_WALK_ROW_STEP 0
-# define IMAGE_WALK_DO_STEP do{ *(u32 *)pos = ((u32 *)pal)[*pixels++]; }while(0)
-# define IMAGE_WALK_DO_ROW_END do{ \
- row_start += dein_step; \
- if (row_start > img->pixels + img->image_size) \
- row_start = img->pixels + (dein_next >>= 1), dein_step = dein_next << 1; \
- }while(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"
break;
}