[gs-cvs] rev 8818 - trunk/gs/src
giles at ghostscript.com
giles at ghostscript.com
Thu Jul 3 11:25:55 PDT 2008
Author: giles
Date: 2008-07-03 11:25:55 -0700 (Thu, 03 Jul 2008)
New Revision: 8818
Modified:
trunk/gs/src/sjpx.c
trunk/gs/src/sjpx.h
Log:
Clean up the state machine in s_jpxd_process.
DETAILS:
The state machine didn't always respect the calling conventions for
filter process routines, and could return '0' (more input needed) when
'last' was true (no more input exists).
Also, the jas_stream member of the filter state isn't currently
necessary and has been moved to s_jpxd_decode_image(). Originally
it was envisioned that the jas_stream could seek on the filter's
source ghostscript stream and so would need a longer lifetime than
we're currently using. This has now been simplified to a local variable.
EXPECTED DIFFERENCES:
None.
Modified: trunk/gs/src/sjpx.c
===================================================================
--- trunk/gs/src/sjpx.c 2008-07-03 18:25:54 UTC (rev 8817)
+++ trunk/gs/src/sjpx.c 2008-07-03 18:25:55 UTC (rev 8818)
@@ -289,7 +289,7 @@
static int
s_jpxd_decode_image(stream_jpxd_state * state)
{
- jas_stream_t *stream = state->stream;
+ jas_stream_t *stream = NULL;
jas_image_t *image = NULL;
char *optstr = NULL;
@@ -299,13 +299,18 @@
if_debug0('w', "[w] got indexed colorspace in s_jpxd_decode_image\n");
optstr = (char *)"raw";
}
- /* see if an image is available */
- if (stream != NULL) {
- image = jas_image_decode(stream, -1, optstr);
- if (image == NULL) {
- dprintf("unable to decode JPX image data.\n");
- return ERRC;
- }
+ /* wrap our buffer in a jas_stream */
+ stream = jas_stream_memopen((char*)state->buffer, state->buffill);
+ if (stream == NULL) {
+ dprintf("unable to create stream for JPX image data.\n");
+ return ERRC;
+ }
+ /* decode an image */
+ image = jas_image_decode(stream, -1, optstr);
+ if (image == NULL) {
+ dprintf("unable to decode JPX image data.\n");
+ return ERRC;
+ }
#ifdef JPX_USE_JASPER_CM
/* convert non-rgb multicomponent colorspaces to sRGB */
if (jas_image_numcmpts(image) > 1 &&
@@ -321,17 +326,14 @@
}
}
#endif
- state->image = image;
- state->offset = 0;
- jas_stream_close(stream);
- state->stream = NULL;
+ state->image = image;
+ state->offset = 0;
+ jas_stream_close(stream);
#ifdef DEBUG
dump_jas_image(image);
#endif
- }
-
return 0;
}
@@ -343,7 +345,6 @@
stream_cursor_write * pw, bool last)
{
stream_jpxd_state *const state = (stream_jpxd_state *) ss;
- jas_stream_t *stream = state->stream;
long in_size = pr->limit - pr->ptr;
long out_size = pw->limit - pw->ptr;
int status = 0;
@@ -361,39 +362,35 @@
if (in_size > 0) {
s_jpxd_buffer_input(state, pr, in_size);
}
- if ((last == 1) && (stream == NULL) && (state->image == NULL)) {
- /* turn our buffer into a stream */
- stream = jas_stream_memopen((char*)state->buffer, state->bufsize);
- state->stream = stream;
- }
- if (out_size > 0) {
- if (state->image == NULL) {
- status = s_jpxd_decode_image(state);
- }
- if (state->image != NULL) {
- jas_image_t *image = state->image;
- int numcmpts = jas_image_numcmpts(image);
- int stride = numcmpts*jas_image_width(image);
- long image_size = stride*jas_image_height(image);
- int clrspc = jas_image_clrspc(image);
- int x, y;
- long usable, done;
- y = state->offset / stride;
- x = state->offset - y*stride; /* bytes, not samples */
- usable = min(out_size, stride - x);
- /* Make sure we can return a full pixel.
- This can fail if we get the colorspace wrong. */
- if (usable < numcmpts) return ERRC;
- x = x/numcmpts; /* now samples */
- /* copy data out of the decoded image data */
- /* be lazy and only write the rest of the current row */
- if (state->colorspace == gs_jpx_cs_indexed) {
- /* we've passed 'raw' but the palette is the same pixel
- format as a grayscale image. The PDF interpreter will
- know to handle it differently. */
- done = copy_row_gray(pw->ptr, image, x, y, usable);
- } else /* use the stream's colorspace */
- switch (jas_clrspc_fam(clrspc)) {
+ if (last) {
+ if (state->image == NULL) {
+ status = s_jpxd_decode_image(state);
+ }
+ if (state->image != NULL) {
+ jas_image_t *image = state->image;
+ int numcmpts = jas_image_numcmpts(image);
+ int stride = numcmpts*jas_image_width(image);
+ long image_size = stride*jas_image_height(image);
+ int clrspc = jas_image_clrspc(image);
+ int x, y;
+ long usable, done;
+
+ y = state->offset / stride;
+ x = state->offset - y*stride; /* bytes, not samples */
+ usable = min(out_size, stride - x);
+ /* Make sure we can return a full pixel.
+ This can fail if we get the colorspace wrong. */
+ if (usable < numcmpts) return ERRC;
+ x = x/numcmpts; /* now samples */
+ /* copy data out of the decoded image data */
+ /* be lazy and only write the rest of the current row */
+ if (state->colorspace == gs_jpx_cs_indexed) {
+ /* we've passed 'raw' but the palette is the same pixel
+ format as a grayscale image. The PDF interpreter will
+ know to handle it differently. */
+ done = copy_row_gray(pw->ptr, image, x, y, usable);
+ } else /* use the stream's colorspace */
+ switch (jas_clrspc_fam(clrspc)) {
case JAS_CLRSPC_FAM_GRAY:
done = copy_row_gray(pw->ptr, image, x, y, usable);
break;
@@ -409,11 +406,11 @@
default:
done = copy_row_default(pw->ptr, image, x, y, usable);
break;
- }
- pw->ptr += done;
- state->offset += done;
- status = (state->offset < image_size) ? 1 : 0;
- }
+ }
+ pw->ptr += done;
+ state->offset += done;
+ status = (state->offset < image_size) ? 1 : EOFC;
+ }
}
return status;
@@ -429,7 +426,6 @@
if (state) {
if (state->image) jas_image_destroy(state->image);
- if (state->stream) jas_stream_close(state->stream);
if (state->buffer) gs_free(state->jpx_memory, state->buffer, state->bufsize, 1,
"JPXDecode temp buffer");
}
@@ -445,7 +441,6 @@
{
stream_jpxd_state *const state = (stream_jpxd_state *) ss;
- state->stream = NULL;
state->image = NULL;
state->offset = 0;
state->buffer = NULL;
Modified: trunk/gs/src/sjpx.h
===================================================================
--- trunk/gs/src/sjpx.h 2008-07-03 18:25:54 UTC (rev 8817)
+++ trunk/gs/src/sjpx.h 2008-07-03 18:25:55 UTC (rev 8818)
@@ -44,7 +44,6 @@
{
stream_state_common; /* a define from scommon.h */
jas_image_t *image;
- jas_stream_t *stream;
long offset; /* offset into the image bitmap of the next
byte to be returned */
const gs_memory_t *jpx_memory;
More information about the gs-cvs
mailing list