summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Cherepanov <alex.cherepanov@artifex.com>2012-03-12 21:57:09 -0400
committerChris Liddell <chris.liddell@artifex.com>2012-03-15 11:54:24 +0000
commit75ef35c843a99bc9d7022a0bc27e7cd4ffc37abd (patch)
treec00888ab927a51f08b2c081ec93bd5fd785b0844
parent29f3dc276c16c77c9bc506d70646ccf7fbe29998 (diff)
Bug 692851: Implement the case of bps < 8 for Luratech JPX decoder
Implement a missing case of Luratech JPX with components > 1, and bps < 8. Also fix incorrect bit shift calculation in OpenJpeg part.
-rw-r--r--gs/base/sjpx_luratech.c59
-rw-r--r--gs/base/sjpx_openjpeg.c4
2 files changed, 58 insertions, 5 deletions
diff --git a/gs/base/sjpx_luratech.c b/gs/base/sjpx_luratech.c
index 294594d73..632c94bb4 100644
--- a/gs/base/sjpx_luratech.c
+++ b/gs/base/sjpx_luratech.c
@@ -177,7 +177,31 @@ s_jpxd_write_data(unsigned char * pucData,
if (ulNum & 1)
*dst++ = pucData[ulNum - 1] << 4;
} else
- return cJP2_Error_Not_Yet_Supported;
+ {
+ unsigned int bt=0; unsigned long i;
+ int bit_pos = state->bpc * ulStart; /* starting bit position to fill for this component */
+ int bit_cnt; /* bit count for current byte */
+ unsigned char *p = &state->image[state->stride * ulRow + bit_pos/8]; /* starting byte to fill */;
+ bit_cnt = bit_pos % 8;
+ for (i = 0; i < ulNum; i++)
+ {
+ bt <<= state->bpc;
+ bt |= pucData[i];
+ bit_cnt += state->bpc;
+ if (bit_cnt >= 8)
+ {
+ *(p++) |= bt >> (bit_cnt-8);
+ bit_cnt -= 8;
+ bt &= (1<<bit_cnt)-1;
+ }
+ }
+ /* end of row */
+ if (bit_cnt > 0)
+ {
+ *p |= bt<<(8-bit_cnt);
+ bt = 0;
+ }
+ }
}
else if (comp >= 0) {
unsigned long cw, ch, i, hstep, vstep, x, y;
@@ -217,8 +241,37 @@ s_jpxd_write_data(unsigned char * pucData,
}
row += state->stride;
}
- } else
- return cJP2_Error_Not_Yet_Supported;
+ } else {
+ unsigned int bt=0;
+ int bit_pos = state->bpc * state->ncomp * ulStart * hstep + state->bpc * comp; /* starting bit position to fill for this component */
+ int bit_cnt; /* bit count for current byte */
+
+ row = &state->image[state->stride * ulRow * vstep + bit_pos/8]; /* starting byte to fill */
+ for (y = 0; y < vstep; y++) {
+ unsigned char *p = row;
+ bit_cnt = bit_pos % 8;
+ for (i = 0; i < ulNum; i++) {
+ for (x = 0; x < hstep; x++) {
+ bt <<= state->bpc * state->ncomp;
+ bt |= pucData[i];
+ bit_cnt += state->bpc;
+ while (bit_cnt >= 8) {
+ *(p++) |= bt >> (bit_cnt-8);
+ bit_cnt -= 8;
+ bt &= (1<<bit_cnt)-1;
+ }
+ bit_cnt += state->bpc * (state->ncomp - 1); /* skip other components */
+ }
+ }
+ /* end of row */
+ bit_cnt -= state->bpc * (state->ncomp - 1); /* return the last extra count */
+ if (bit_cnt > 0) {
+ *p |= bt<<(8-bit_cnt);
+ bt = 0;
+ }
+ row += state->stride;
+ }
+ }
}
return cJP2_Error_OK;
}
diff --git a/gs/base/sjpx_openjpeg.c b/gs/base/sjpx_openjpeg.c
index 4e5fd619a..058906310 100644
--- a/gs/base/sjpx_openjpeg.c
+++ b/gs/base/sjpx_openjpeg.c
@@ -356,7 +356,7 @@ static int process_one_trunk(stream_jpxd_state * const state, stream_cursor_writ
{
*(pw->ptr++) = bt >> (bit_pos-8);
bit_pos -= 8;
- bt &= (1<<(bit_pos-8))-1;
+ bt &= (1<<bit_pos)-1;
}
}
}
@@ -374,7 +374,7 @@ static int process_one_trunk(stream_jpxd_state * const state, stream_cursor_writ
{
*(pw->ptr++) = bt >> (bit_pos-8);
bit_pos -= 8;
- bt &= (1<<(bit_pos-8))-1;
+ bt &= (1<<bit_pos)-1;
}
}
state->img_offset++;