From: Pavel Charvat Date: Wed, 26 Jul 2006 19:07:08 +0000 (+0200) Subject: cleaner image-walk interface X-Git-Tag: holmes-import~628 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=993d8284c9b643b7a0ddc27a67a3f324b3d77aaf;p=libucw.git cleaner image-walk interface --- diff --git a/images/image-walk.h b/images/image-walk.h index a276b08e..821712af 100644 --- a/images/image-walk.h +++ b/images/image-walk.h @@ -7,51 +7,59 @@ * 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 @@ -75,10 +83,10 @@ #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 @@ -86,56 +94,56 @@ static void IMAGE_WALK_STATIC ) #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 @@ -154,4 +162,5 @@ static void IMAGE_WALK_STATIC #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 diff --git a/images/image.c b/images/image.c index e04d839c..378b8922 100644 --- a/images/image.c +++ b/images/image.c @@ -125,12 +125,14 @@ image_clone(struct image_thread *it, struct image *src, uns flags, struct mempoo 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) diff --git a/images/io-libjpeg.c b/images/io-libjpeg.c index dddfd79f..b6c6552a 100644 --- a/images/io-libjpeg.c +++ b/images/io-libjpeg.c @@ -66,11 +66,11 @@ libjpeg_write_error_exit(j_common_ptr cinfo) 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); } @@ -241,8 +241,8 @@ libjpeg_read_data(struct image_io *io) 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: @@ -267,7 +267,7 @@ libjpeg_read_data(struct image_io *io) image_thread_err(io->thread, IMAGE_ERR_INVALID_PIXEL_FORMAT, "Unsupported color space."); return 0; } - + /* Setup fallback */ if (setjmp(i->err.setjmp_buf)) { @@ -298,11 +298,13 @@ libjpeg_read_data(struct image_io *io) 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; @@ -310,11 +312,13 @@ libjpeg_read_data(struct image_io *io) 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; @@ -322,7 +326,7 @@ libjpeg_read_data(struct image_io *io) ASSERT(0); } ASSERT(i->cinfo.output_scanline == i->cinfo.output_height); - + /* Destroy libjpeg object */ jpeg_finish_decompress(&i->cinfo); jpeg_destroy_decompress(&i->cinfo); @@ -375,7 +379,7 @@ libjpeg_write(struct image_io *io) return 0; } jpeg_create_compress(&i.cinfo); - + /* Initialize destination manager */ i.cinfo.dest = &i.dest; i.dest.init_destination = libjpeg_init_destination; @@ -425,11 +429,13 @@ libjpeg_write(struct image_io *io) 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; @@ -437,11 +443,13 @@ libjpeg_write(struct image_io *io) 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; diff --git a/images/io-libmagick.c b/images/io-libmagick.c index ee0480d1..db5d7398 100644 --- a/images/io-libmagick.c +++ b/images/io-libmagick.c @@ -162,47 +162,55 @@ libmagick_read_data(struct image_io *io) 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; @@ -305,53 +313,61 @@ libmagick_write(struct image_io *io) 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; diff --git a/images/io-libpng.c b/images/io-libpng.c index c2847a82..dbf33d51 100644 --- a/images/io-libpng.c +++ b/images/io-libpng.c @@ -95,7 +95,7 @@ int 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, @@ -120,7 +120,7 @@ libpng_read_header(struct image_io *io) png_destroy_read_struct(&rd->png_ptr, &rd->info_ptr, NULL); return 0; } - + /* Setup libpng longjump */ if (unlikely(setjmp(png_jmpbuf(rd->png_ptr)))) { @@ -128,7 +128,7 @@ libpng_read_header(struct image_io *io) 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); @@ -171,7 +171,7 @@ libpng_read_header(struct image_io *io) 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; @@ -198,7 +198,7 @@ libpng_read_data(struct image_io *io) } 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) @@ -296,7 +296,7 @@ libpng_read_data(struct image_io *io) else io->image = img; io->image_destroy = !io->pool; - + return 1; } @@ -321,7 +321,7 @@ libpng_write(struct image_io *io) png_destroy_write_struct(&png_ptr, NULL); return 0; } - + /* Setup libpng longjump */ if (unlikely(setjmp(png_jmpbuf(png_ptr)))) { @@ -332,7 +332,7 @@ libpng_write(struct image_io *io) /* 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) @@ -359,7 +359,7 @@ libpng_write(struct image_io *io) png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); break; default: - ASSERT(0); + ASSERT(0); } png_write_info(png_ptr, info_ptr); diff --git a/images/io-libungif.c b/images/io-libungif.c index c047fc53..7c9850e4 100644 --- a/images/io-libungif.c +++ b/images/io-libungif.c @@ -114,6 +114,7 @@ libungif_read_data(struct image_io *io) 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; @@ -127,30 +128,31 @@ libungif_read_data(struct image_io *io) { 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; @@ -159,24 +161,21 @@ libungif_read_data(struct image_io *io) 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; @@ -184,24 +183,21 @@ libungif_read_data(struct image_io *io) } 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; @@ -212,16 +208,14 @@ libungif_read_data(struct image_io *io) 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; }