ref: 995e4a01171a87bd2453fb05b13612e76720cd26
parent: 8f2d8d661e4230e61e095e336f1b14c739b62ba0
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Sun Nov 9 08:59:03 EST 2003
Add reference counting to the image structure to permit sharing of the glyph images between symbol dictionaries. git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@286 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/jbig2.h
+++ b/jbig2.h
@@ -1,7 +1,7 @@
/*
jbig2dec
- Copyright (c) 2002 artofcode LLC.
+ Copyright (c) 2002-2003 artofcode LLC.
This software is distributed under license and may not
be copied, modified or distributed except as expressly
@@ -13,7 +13,7 @@
Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
- $Id: jbig2.h,v 1.17 2003/03/05 14:29:35 giles Exp $
+ $Id$
*/
#ifdef __cplusplus
@@ -56,9 +56,12 @@
struct _Jbig2Image {
int width, height, stride;
uint8_t *data;
+ int refcount;
};
Jbig2Image* jbig2_image_new(Jbig2Ctx *ctx, int width, int height);
+Jbig2Image* jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image);
+void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image);
void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image);
--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -16,7 +16,7 @@
Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
- $Id: jbig2_generic.c,v 1.13 2002/07/20 17:23:15 giles Exp $
+ $Id$
*/
/**
@@ -455,7 +455,7 @@
jbig2_image_compose(ctx, ctx->pages[ctx->current_page].image, image,
rsi.x, rsi.y, JBIG2_COMPOSE_OR);
- jbig2_image_free(ctx, image);
+ jbig2_image_release(ctx, image);
jbig2_free(ctx->allocator, GB_stats);
--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -1,7 +1,7 @@
/*
jbig2dec
- Copyright (c) 2001-2002 artofcode LLC.
+ Copyright (c) 2001-2003 artofcode LLC.
This software is distributed under license and may not
be copied, modified or distributed except as expressly
@@ -55,10 +55,24 @@
image->width = width;
image->height = height;
image->stride = stride;
+ image->refcount = 1;
return image;
}
+/* clone an image pointer by bumping its reference count */
+Jbig2Image* jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image)
+{
+ image->refcount++;
+ return image;
+}
+
+/* release an image pointer, freeing it it appropriate */
+void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image)
+{
+ image->refcount--;
+ if (!image->refcount) jbig2_image_free(image);
+}
/* free a Jbig2Image structure and its associated memory */
void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image)
--- a/jbig2_image_pbm.c
+++ b/jbig2_image_pbm.c
@@ -13,7 +13,7 @@
Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
- $Id: jbig2_image_pbm.c,v 1.12 2002/08/15 14:54:45 giles Exp $
+ $Id$
*/
#ifdef HAVE_CONFIG_H
@@ -134,7 +134,7 @@
fread(image->data, 1, image->height*image->stride, in);
if (feof(in)) {
fprintf(stderr, "unexpected end of pbm file.\n");
- jbig2_image_free(ctx, image);
+ jbig2_image_release(ctx, image);
return NULL;
}
/* success */
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -1,7 +1,7 @@
/*
jbig2dec
- Copyright (C) 2002 artofcode LLC.
+ Copyright (C) 2002-2003 artofcode LLC.
This software is distributed under license and may not
be copied, modified or distributed except as expressly
@@ -472,7 +472,7 @@
region_info.width, region_info.height, region_info.x, region_info.y);
jbig2_image_compose(ctx, page_image, image, region_info.x, region_info.y, JBIG2_COMPOSE_OR);
if (image != page_image)
- jbig2_image_free(ctx, image);
+ jbig2_image_release(ctx, image);
}
/* success */