Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
View
2  src/imagew-api.c
@@ -278,7 +278,7 @@ IW_IMPL(void) iw_destroy_context(struct iw_context *ctx)
IW_IMPL(void) iw_get_output_image(struct iw_context *ctx, struct iw_image *img)
{
- memset(img,0,sizeof(struct iw_image));
+ iw_zeromem(img,sizeof(struct iw_image));
img->width = ctx->optctx.width;
img->height = ctx->optctx.height;
img->imgtype = ctx->optctx.imgtype;
View
12 src/imagew-bmp.c
@@ -80,7 +80,7 @@ static void iwbmp_write_file_header(struct iwbmpwritecontext *bmpctx)
if(!bmpctx->include_file_header) return;
- memset(&fileheader,0,sizeof(fileheader));
+ iw_zeromem(fileheader,sizeof(fileheader));
fileheader[0] = 66; // 'B'
fileheader[1] = 77; // 'M'
iw_set_ui32le(&fileheader[ 2],14+40+(unsigned int)bmpctx->palsize+
@@ -94,7 +94,7 @@ static void iwbmp_write_bmp_header(struct iwbmpwritecontext *bmpctx)
unsigned int dens_x, dens_y;
iw_byte header[40];
- memset(&header,0,sizeof(header));
+ iw_zeromem(header,sizeof(header));
iw_set_ui32le(&header[ 0],40); // biSize
iw_set_ui32le(&header[ 4],bmpctx->img->width); // biWidth
@@ -133,7 +133,7 @@ static void iwbmp_write_palette(struct iwbmpwritecontext *bmpctx)
buf[3] = 0;
}
else {
- memset(buf,0,4);
+ iw_zeromem(buf,4);
}
iwbmp_write(bmpctx,buf,4);
}
@@ -214,9 +214,9 @@ IW_IMPL(int) iw_write_bmp_file(struct iw_context *ctx, struct iw_iodescr *iodesc
int retval=0;
struct iw_image img1;
- memset(&img1,0,sizeof(struct iw_image));
+ iw_zeromem(&img1,sizeof(struct iw_image));
- memset(&bmpctx,0,sizeof(struct iwbmpwritecontext));
+ iw_zeromem(&bmpctx,sizeof(struct iwbmpwritecontext));
bmpctx.ctx = ctx;
bmpctx.include_file_header = 1;
@@ -236,7 +236,5 @@ IW_IMPL(int) iw_write_bmp_file(struct iw_context *ctx, struct iw_iodescr *iodesc
retval=1;
done:
- if(bmpctx.iodescr->close_fn)
- (*bmpctx.iodescr->close_fn)(ctx,bmpctx.iodescr);
return retval;
}
View
9 src/imagew-gif.c
@@ -275,7 +275,7 @@ static void lzw_init(struct lzwdeccontext *d, unsigned int root_codesize)
{
unsigned int i;
- memset(d,0,sizeof(struct lzwdeccontext));
+ iw_zeromem(d,sizeof(struct lzwdeccontext));
d->root_codesize = root_codesize;
d->num_root_codes = 1<<d->root_codesize;
@@ -497,7 +497,7 @@ static int iwgif_init_screen(struct iwgifreadcontext *rctx)
if(!img->pixels) goto done;
// Start by clearing the screen to black, or transparent black.
- memset(img->pixels,0,img->bpr*img->height);
+ iw_zeromem(img->pixels,img->bpr*img->height);
retval=1;
done:
@@ -757,7 +757,7 @@ IW_IMPL(int) iw_read_gif_file(struct iw_context *ctx, struct iw_iodescr *iodescr
struct iwgifreadcontext *rctx = NULL;
int retval=0;
- memset(&img,0,sizeof(struct iw_image));
+ iw_zeromem(&img,sizeof(struct iw_image));
rctx = iw_mallocz(ctx,sizeof(struct iwgifreadcontext));
if(!rctx) goto done;
@@ -787,9 +787,6 @@ IW_IMPL(int) iw_read_gif_file(struct iw_context *ctx, struct iw_iodescr *iodescr
iw_set_error(ctx,"Failed to read GIF file");
}
- if(iodescr->close_fn)
- (*iodescr->close_fn)(ctx,iodescr);
-
if(rctx) {
if(rctx->row_pointers) iw_free(ctx,rctx->row_pointers);
iw_free(ctx,rctx);
View
1  src/imagew-internals.h
@@ -117,6 +117,7 @@ struct iw_opt_ctx {
struct iw_context {
int caller_api_version;
+ int use_count;
unsigned int output_profile;
iw_mallocfn_type mallocfn;
View
24 src/imagew-jpeg.c
@@ -150,9 +150,9 @@ static void convert_cmyk_to_rbg(struct iw_context *ctx, const JSAMPLE *src,
if(r<0.0) r=0.0; if(r>1.0) r=1.0;
if(g<0.0) g=0.0; if(g>1.0) g=1.0;
if(b<0.0) b=0.0; if(b>1.0) b=1.0;
- dst[3*i+0] = (iw_byte)(0.5+255.0*r);
- dst[3*i+1] = (iw_byte)(0.5+255.0*g);
- dst[3*i+2] = (iw_byte)(0.5+255.0*b);
+ dst[3*i+0] = (JSAMPLE)(0.5+255.0*r);
+ dst[3*i+1] = (JSAMPLE)(0.5+255.0*g);
+ dst[3*i+2] = (JSAMPLE)(0.5+255.0*b);
}
}
@@ -171,10 +171,10 @@ IW_IMPL(int) iw_read_jpeg_file(struct iw_context *ctx, struct iw_iodescr *iodesc
JSAMPLE *tmprow = NULL;
int cmyk_flag = 0;
- memset(&img,0,sizeof(struct iw_image));
- memset(&cinfo,0,sizeof(struct jpeg_decompress_struct));
- memset(&jerr,0,sizeof(struct my_error_mgr));
- memset(&jpegrctx,0,sizeof(struct iw_jpegrctx));
+ iw_zeromem(&img,sizeof(struct iw_image));
+ iw_zeromem(&cinfo,sizeof(struct jpeg_decompress_struct));
+ iw_zeromem(&jerr,sizeof(struct my_error_mgr));
+ iw_zeromem(&jpegrctx,sizeof(struct iw_jpegrctx));
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
@@ -279,8 +279,6 @@ IW_IMPL(int) iw_read_jpeg_file(struct iw_context *ctx, struct iw_iodescr *iodesc
done:
if(cinfo_valid) jpeg_destroy_decompress(&cinfo);
- if(iodescr->close_fn)
- (*iodescr->close_fn)(ctx,iodescr);
if(jpegrctx.buffer) iw_free(ctx,jpegrctx.buffer);
if(tmprow) iw_free(ctx,tmprow);
return retval;
@@ -376,9 +374,9 @@ IW_IMPL(int) iw_write_jpeg_file(struct iw_context *ctx, struct iw_iodescr *iode
int samp_factor_h, samp_factor_v;
struct iw_jpegwctx jpegwctx;
- memset(&cinfo,0,sizeof(struct jpeg_compress_struct));
- memset(&jerr,0,sizeof(struct my_error_mgr));
- memset(&jpegwctx,0,sizeof(struct iw_jpegwctx));
+ iw_zeromem(&cinfo,sizeof(struct jpeg_compress_struct));
+ iw_zeromem(&jerr,sizeof(struct my_error_mgr));
+ iw_zeromem(&jpegwctx,sizeof(struct iw_jpegwctx));
iw_get_output_image(ctx,&img);
@@ -487,8 +485,6 @@ IW_IMPL(int) iw_write_jpeg_file(struct iw_context *ctx, struct iw_iodescr *iode
if(compress_created)
jpeg_destroy_compress(&cinfo);
- if(iodescr->close_fn)
- (*iodescr->close_fn)(ctx,iodescr);
if(row_pointers) iw_free(ctx,row_pointers);
if(jpegwctx.buffer) iw_free(ctx,jpegwctx.buffer);
View
6 src/imagew-main.c
@@ -1979,6 +1979,12 @@ IW_IMPL(int) iw_process_image(struct iw_context *ctx)
int ret;
int retval = 0;
+ if(ctx->use_count>0) {
+ iw_set_error(ctx,"Internal: Incorrect attempt to reprocess image");
+ goto done;
+ }
+ ctx->use_count++;
+
ret = iw_prepare_processing(ctx,ctx->canvas_width,ctx->canvas_height);
if(!ret) goto done;
View
13 src/imagew-miff.c
@@ -448,8 +448,8 @@ IW_IMPL(int) iw_read_miff_file(struct iw_context *ctx, struct iw_iodescr *iodesc
struct iwmiffreadcontext rctx;
int retval=0;
- memset(&rctx,0,sizeof(struct iwmiffreadcontext));
- memset(&img,0,sizeof(struct iw_image));
+ iw_zeromem(&rctx,sizeof(struct iwmiffreadcontext));
+ iw_zeromem(&img,sizeof(struct iw_image));
rctx.ctx = ctx;
rctx.host_little_endian = iw_get_host_endianness();
@@ -496,9 +496,6 @@ IW_IMPL(int) iw_read_miff_file(struct iw_context *ctx, struct iw_iodescr *iodesc
if(!retval) {
iw_set_error(ctx,"Failed to read MIFF file");
}
-
- if(iodescr->close_fn)
- (*iodescr->close_fn)(ctx,iodescr);
return retval;
}
@@ -764,9 +761,9 @@ IW_IMPL(int) iw_write_miff_file(struct iw_context *ctx, struct iw_iodescr *iodes
int retval=0;
struct iw_image img1;
- memset(&img1,0,sizeof(struct iw_image));
+ iw_zeromem(&img1,sizeof(struct iw_image));
- memset(&wctx,0,sizeof(struct iwmiffwritecontext));
+ iw_zeromem(&wctx,sizeof(struct iwmiffwritecontext));
wctx.ctx = ctx;
@@ -782,7 +779,5 @@ IW_IMPL(int) iw_write_miff_file(struct iw_context *ctx, struct iw_iodescr *iodes
retval=1;
done:
- if(wctx.iodescr->close_fn)
- (*wctx.iodescr->close_fn)(ctx,wctx.iodescr);
return retval;
}
View
12 src/imagew-opt.c
@@ -427,7 +427,7 @@ static void iwopt_try_rgb8_binary_trns(struct iw_context *ctx, struct iw_opt_ctx
// Try to find a color that's not used in the image.
// Looking for all 2^24 possible colors is too much work.
// We will just look for 256 predefined colors: R={0-255},G=192,B=192
- memset(clr_used,0,256*sizeof(iw_byte));
+ iw_zeromem(clr_used,256);
// Hard to decide how to do this. I don't want the optimization phase
// to modify img2.pixels, though that would be the easiest method.
@@ -496,7 +496,7 @@ static void iwopt_try_rgb16_binary_trns(struct iw_context *ctx, struct iw_opt_ct
if(!(ctx->output_profile&IW_PROFILE_BINARYTRNS)) return;
if(!ctx->opt_binary_trns) return;
- memset(clr_used,0,256*sizeof(iw_byte));
+ iw_zeromem(clr_used,256);
trns_mask = iw_malloc_large(ctx, optctx->width, optctx->height);
if(!trns_mask) goto done;
@@ -564,7 +564,7 @@ static void iwopt_try_gray8_binary_trns(struct iw_context *ctx, struct iw_opt_ct
if(!(ctx->output_profile&IW_PROFILE_BINARYTRNS)) return;
if(!ctx->opt_binary_trns) return;
- memset(clr_used,0,256*sizeof(iw_byte));
+ iw_zeromem(clr_used,256);
trns_mask = iw_malloc_large(ctx, optctx->width, optctx->height);
if(!trns_mask) goto done;
@@ -624,7 +624,7 @@ static void iwopt_try_gray16_binary_trns(struct iw_context *ctx, struct iw_opt_c
if(!(ctx->output_profile&IW_PROFILE_BINARYTRNS)) return;
if(!ctx->opt_binary_trns) return;
- memset(clr_used,0,256*sizeof(iw_byte));
+ iw_zeromem(clr_used,256);
trns_mask = iw_malloc_large(ctx, optctx->width, optctx->height);
if(!trns_mask) goto done;
@@ -908,7 +908,7 @@ static int iwopt_palette_is_valid_gray(struct iw_context *ctx, struct iw_opt_ctx
if(optctx->palette->num_entries > max_entries)
return 0;
- memset(clr_used,0,256*sizeof(iw_byte));
+ iw_zeromem(clr_used,256);
for(i=0;i<optctx->palette->num_entries;i++) {
if(optctx->palette->entry[i].a>0) { // Look at all the nontransparent entries.
@@ -1115,7 +1115,7 @@ void iwpvt_optimize_image(struct iw_context *ctx)
optctx = &ctx->optctx;
- //memset(optctx,0,sizeof(struct iw_opt_ctx));
+ //iw_zeromem(optctx,sizeof(struct iw_opt_ctx));
optctx->width = ctx->img2.width;
optctx->height = ctx->img2.height;
optctx->imgtype = ctx->img2.imgtype;
View
12 src/imagew-png.c
@@ -234,8 +234,8 @@ IW_IMPL(int) iw_read_png_file(struct iw_context *ctx, struct iw_iodescr *iodescr
png_infop info_ptr = NULL;
struct iw_pngrctx pngrctx;
- memset(&pngrctx,0,sizeof(struct iw_pngrctx));
- memset(&img,0,sizeof(struct iw_image));
+ iw_zeromem(&pngrctx,sizeof(struct iw_pngrctx));
+ iw_zeromem(&img,sizeof(struct iw_image));
errinfo.jbufp = &jbuf;
errinfo.ctx = ctx;
@@ -365,8 +365,6 @@ IW_IMPL(int) iw_read_png_file(struct iw_context *ctx, struct iw_iodescr *iodescr
if(png_ptr) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
}
- if(iodescr->close_fn)
- (*iodescr->close_fn)(ctx,iodescr);
if(row_pointers) iw_free(ctx,row_pointers);
return retval;
}
@@ -400,7 +398,7 @@ static void iwpng_set_binary_trns(struct iw_context *ctx,
{
png_color_16 newtrns;
- memset(&newtrns,0,sizeof(png_color_16));
+ iw_zeromem(&newtrns,sizeof(png_color_16));
if(img->has_colorkey_trns) {
if(lpng_color_type==PNG_COLOR_TYPE_GRAY) {
@@ -476,7 +474,7 @@ IW_IMPL(int) iw_write_png_file(struct iw_context *ctx, struct iw_iodescr *iodesc
int cmprlevel;
struct iw_pngwctx pngwctx;
- memset(&pngwctx,0,sizeof(struct iw_pngwctx));
+ iw_zeromem(&pngwctx,sizeof(struct iw_pngwctx));
iw_get_output_image(ctx,&img);
iw_get_output_colorspace(ctx,&csdescr);
@@ -595,8 +593,6 @@ IW_IMPL(int) iw_write_png_file(struct iw_context *ctx, struct iw_iodescr *iodesc
if(png_ptr) {
png_destroy_write_struct(&png_ptr, &info_ptr);
}
- if(iodescr->close_fn)
- (*iodescr->close_fn)(ctx,iodescr);
if(row_pointers) iw_free(ctx,row_pointers);
return retval;
}
View
4 src/imagew-tiff.c
@@ -588,7 +588,7 @@ IW_IMPL(int) iw_write_tiff_file(struct iw_context *ctx, struct iw_iodescr *iodes
int retval=0;
struct iw_image img1;
- memset(&img1,0,sizeof(struct iw_image));
+ iw_zeromem(&img1,sizeof(struct iw_image));
tiffctx = iw_mallocz(ctx,sizeof(struct iwtiffwritecontext));
if(!tiffctx) goto done;
@@ -614,8 +614,6 @@ IW_IMPL(int) iw_write_tiff_file(struct iw_context *ctx, struct iw_iodescr *iodes
retval=1;
done:
- if(tiffctx->iodescr->close_fn)
- (*tiffctx->iodescr->close_fn)(ctx,tiffctx->iodescr);
if(tiffctx) iw_free(ctx,tiffctx);
return retval;
}
View
5 src/imagew-util.c
@@ -184,6 +184,11 @@ IW_IMPL(int) iw_stricmp(const char *s1, const char *s2)
#endif
}
+IW_IMPL(void) iw_zeromem(void *mem, size_t n)
+{
+ memset(mem,0,n);
+}
+
////////////////////////////////////////////
// A simple carry-with-multiply pseudorandom number generator (PRNG).
View
15 src/imagew-webp.c
@@ -530,8 +530,8 @@ IW_IMPL(int) iw_read_webp_file(struct iw_context *ctx, struct iw_iodescr *iodesc
struct iwwebpreadcontext rctx;
int retval=0;
- memset(&rctx,0,sizeof(struct iwwebpreadcontext));
- memset(&img,0,sizeof(struct iw_image));
+ iw_zeromem(&rctx,sizeof(struct iwwebpreadcontext));
+ iw_zeromem(&img,sizeof(struct iw_image));
rctx.ctx = ctx;
rctx.iodescr = iodescr;
@@ -553,9 +553,6 @@ IW_IMPL(int) iw_read_webp_file(struct iw_context *ctx, struct iw_iodescr *iodesc
if(!retval) {
iw_set_error(ctx,"Failed to read WebP file");
}
-
- if(iodescr->close_fn)
- (*iodescr->close_fn)(ctx,iodescr);
return retval;
}
@@ -661,8 +658,8 @@ IW_IMPL(int) iw_write_webp_file(struct iw_context *ctx, struct iw_iodescr *iodes
int retval=0;
struct iw_image img1;
- memset(&img1,0,sizeof(struct iw_image));
- memset(&wctx,0,sizeof(struct iwwebpwritecontext));
+ iw_zeromem(&img1,sizeof(struct iw_image));
+ iw_zeromem(&wctx,sizeof(struct iwwebpwritecontext));
wctx.ctx = ctx;
@@ -681,10 +678,6 @@ IW_IMPL(int) iw_write_webp_file(struct iw_context *ctx, struct iw_iodescr *iodes
if(!retval) {
iw_set_error(ctx,"Failed to write WebP file");
}
-
- if(wctx.iodescr->close_fn)
- (*wctx.iodescr->close_fn)(ctx,wctx.iodescr);
-
return retval;
}
View
5 src/imagew.h
@@ -356,7 +356,8 @@ struct iw_iodescr {
// Must write all bytes supplied.
iw_writefn_type write_fn;
- // Optional "close" function.
+ // Optional "close" function. IW will never call this, but the app can use
+ // it for convenience.
iw_closefn_type close_fn;
// Return the file size.
@@ -635,6 +636,8 @@ IW_EXPORT(void) iw_snprintf(char *buf, size_t buflen, const char *fmt, ...)
iw_gnuc_attribute ((format (printf, 3, 4)));
IW_EXPORT(int) iw_stricmp(const char *s1, const char *s2);
+IW_EXPORT(void) iw_zeromem(void *mem, size_t n);
+
IW_EXPORT(int) iw_imgtype_num_channels(int t);
IW_EXPORT(size_t) iw_calc_bytesperrow(int num_pixels, int bits_per_pixel);

No commit comments for this range

Something went wrong with that request. Please try again.