Hi,
Attached patch fixes decoding of files where component precision > 8.
Possible test files are :
codestreams_profile1/p1_04.j2k
testfiles_jp2/file6.jp2
testfiles_jp2/file7.jp2
Posting here for comments.
--
Regards,
Jai
Index: j2kdec.c
===================================================================
--- j2kdec.c (revision 4434)
+++ j2kdec.c (working copy)
@@ -54,7 +54,7 @@
uint8_t cbps[4]; ///< bits per sample in particular components
uint8_t sgnd[4]; ///< if a component is signed
uint8_t properties[4];
-
+ int precision;
int ncomponents;
int tile_width, tile_height; ///< tile size
int numXtiles, numYtiles;
@@ -225,6 +225,8 @@
for (i = 0; i < s->ncomponents; i++){ // Ssiz_i XRsiz_i, YRsiz_i
uint8_t x = bytestream_get_byte(&s->buf);
s->cbps[i] = (x & 0x7f) + 1;
+ if (s->cbps[i] > s->precision)
+ s->precision = s->cbps[i];
s->sgnd[i] = (x & 0x80) == 1;
if (bytestream_get_byte(&s->buf) != 1)
return -1;
@@ -251,8 +253,14 @@
s->avctx->height = s->height - s->image_offset_y;
switch(s->ncomponents){
- case 1: s->avctx->pix_fmt = PIX_FMT_GRAY8; break;
- case 3: s->avctx->pix_fmt = PIX_FMT_RGB24; break;
+ case 1: if (s->precision > 8) {
+ s->avctx->pix_fmt = PIX_FMT_GRAY16;
+ } else s->avctx->pix_fmt = PIX_FMT_GRAY8;
+ break;
+ case 3: if (s->precision > 8) {
+ s->avctx->pix_fmt = PIX_FMT_RGB48;
+ } else s->avctx->pix_fmt = PIX_FMT_RGB24;
+ break;
case 4: s->avctx->pix_fmt = PIX_FMT_BGRA; break;
}
@@ -788,6 +796,7 @@
if (s->avctx->pix_fmt == PIX_FMT_BGRA) // RGBA -> BGRA
FFSWAP(int *, src[0], src[2]);
+ if (s->precision <= 8) {
for (; y < tile->comp[0].coord[1][1] - s->image_offset_y; y++){
uint8_t *dst;
@@ -806,6 +815,26 @@
line += s->picture.linesize[0];
}
+ } else {
+ for (; y < tile->comp[0].coord[1][1] - s->image_offset_y; y++) {
+ uint16_t *dst;
+ x = tile->comp[0].coord[0][0] - s->image_offset_x;
+ dst = line + x * s->ncomponents * 2;
+ for (; x < tile->comp[0].coord[0][1] - s->image_offset_x; x++) {
+ for (compno = 0; compno < s->ncomponents; compno++) {
+ *src[compno] = av_rescale(*src[compno], (1 << 16) - 1,
+ (1 << s->cbps[compno]) - 1);
+ *src[compno] += 1 << 15;
+ if (*src[compno] < 0)
+ *src[compno] = 0;
+ else if (*src[compno] >= (1 << 16))
+ *src[compno] = (1 << 16) - 1;
+ *dst++ = *src[compno]++;
+ }
+ }
+ line += s->picture.linesize[0];
+ }
+ }
return 0;
}
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc