Hi Michael,
On Tue, May 24, 2011 at 1:10 AM, rukhsana afroz <[email protected]>wrote:
> Hi Michael,
>
> On Fri, May 20, 2011 at 10:49 PM, rukhsana afroz <[email protected]
> > wrote:
>
>> Hi Michael,
>>
>>
>> On Thu, May 19, 2011 at 3:38 PM, rukhsana afroz <[email protected]
>> > wrote:
>>
>>>
>>>
>>> On Thu, May 19, 2011 at 3:32 PM, rukhsana afroz <
>>> [email protected]> wrote:
>>>
>>>> Hi Michael,
>>>>
>>>>
>>>> On Sun, May 15, 2011 at 5:00 PM, Michael Niedermayer
>>>> <[email protected]>wrote:
>>>>
>>>>>
>>>>> We will have to implement multiple codeword segments.
>>>>>
>>>>> Also sofar, good work!
>>>>>
>>>>>
>>>> Sorry for the late reply. If I implement codeblock segment, its going to
>>>> affect from packet decoding process to the subsequent deoding process till
>>>> the last. Therefore, I have to be properly planned in order to accomplish
>>>> these changes. Here, I have put patch for incorporating multiple codeblock
>>>> segment. I had to create two more structures and modify J2KCblk sturucture
>>>> as well. This patch is just for the modification/creation on the
>>>> structures.
>>>> I am also writing some miscellaneous function and I will post those in my
>>>> subsequent emails.
>>>>
>>>
>> I have modified the decode_packet function incorporating multiple codeword
>> segment. Here, I have attached the patch for the required changes. I have
>> taken the help from jasper code while writing this code, because only the
>> document is not sufficient to incorporate these changes. I have not tested
>> this code yet. Once, I test it, I also let you know. If you have any
>> suggestion on this patch, please let me know.
>>
>>
>>
>
> While doing arithmetic coding operation in decode_cblk function one
> term/variable is "bpno". Coding operation (decode_sigpass, decode_refpass,
> decode_clpass) uses this variable to determine the data of each codeblock in
> different contexts. This variable has been set in our decoder:
>
>
> bpno = cblk->nonzerobits - 1
>
> And, jasper has set this variable as follows:
>
> bpno = band->roishift + band->numbps - 1 - (cblk->numimsbs + (seg->passno +
> i - cblk->firstpassno + 2) / 3);
>
> band->roishift is the value got from processing the RGN marker and
> band->numbps is also the value got from some other marker. Our decoder has
> not processed this marker. cblk->numimsbs is similar to our decoder's
> cblk->nonzerobits. Other part of this variable is segment specific and that
> makes sense. I need you suggestion on how to set this variable. I will
> explain more tomorrow on IRC chat.
>
>
>
Here, I have attached two patches which cove all changes due to multiple
codeblock segment. I have tested decode_packet function, but not decode_cblk
yet.
Thanks
--
Rukhsana Ruby
Phd Student
Department of Electrical & Computer Engineering
The University of British Columbia
============================
diff --git a/libavcodec/j2k.h b/libavcodec/j2k.h
index 76ef03a..a8e5221 100644
--- a/libavcodec/j2k.h
+++ b/libavcodec/j2k.h
@@ -100,12 +100,6 @@ enum J2kQuantsty{ ///< quantization style
#define J2K_CSTY_SOP 0x02 // SOP marker present
#define J2K_CSTY_EPH 0x04 // EPH marker present
-/* Tier-1 coding pass types. */
-#define J2K_SIGPASS 0 /* significance */
-#define J2K_REFPASS 1 /* refinement */
-#define J2K_CLNPASS 2 /* cleanup */
-
-
typedef struct {
int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH];
int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2];
@@ -144,14 +138,6 @@ typedef struct {
} J2kPass;
typedef struct {
- unint16_t index;
- uint8_t npasses;
- uint8_t maxpasses;
- uint8_t firstpassno;
- uint8_t passno;
-} J2kCblkSeg;
-
-typedef struct {
uint8_t npasses;
uint8_t ninclpasses; ///< number coding of passes included in codestream
uint8_t nonzerobits;
@@ -160,8 +146,7 @@ typedef struct {
uint8_t lblock;
uint8_t zero;
uint8_t data[8192];
- J2kCblkSeg segs[50];
- //J2kPass passes[100];
+ J2kPass passes[100];
} J2kCblk; ///< code block
typedef struct {
diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
index d729d45..b8d69df 100644
--- a/libavcodec/j2kdec.c
+++ b/libavcodec/j2kdec.c
@@ -322,9 +322,7 @@ static int get_cod(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
get_cox(s, &tmp);
for (compno = 0; compno < s->ncomponents; compno++){
if (!(properties[compno] & HAD_COC))
- {
- memcpy(c + compno, &tmp, sizeof(J2kCodingStyle));
- }
+ memcpy(c + compno, &tmp, sizeof(J2kCodingStyle));
}
return 0;
}
@@ -332,7 +330,7 @@ static int get_cod(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
/** get coding parameters for a component in the whole image on a particular tile */
static int get_coc(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
{
- int compno, csty;
+ int compno;
if (s->buf_end - s->buf < 2)
return AVERROR(EINVAL);
@@ -340,9 +338,7 @@ static int get_coc(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties)
compno = bytestream_get_byte(&s->buf);
c += compno;
- csty = bytestream_get_byte(&s->buf);
- c->csty = c->csty | (csty & 0xFE);
-
+ c->csty = bytestream_get_byte(&s->buf);
get_cox(s, c);
properties[compno] |= HAD_COC;
diff --git a/libavcodec/j2k.h b/libavcodec/j2k.h
index 76ef03a..ce5fdb9 100644
--- a/libavcodec/j2k.h
+++ b/libavcodec/j2k.h
@@ -158,7 +158,6 @@ typedef struct {
uint16_t length;
uint16_t lengthinc;
uint8_t lblock;
- uint8_t zero;
uint8_t data[8192];
J2kCblkSeg segs[50];
//J2kPass passes[100];
diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
index d729d45..037a710 100644
--- a/libavcodec/j2kdec.c
+++ b/libavcodec/j2kdec.c
@@ -468,6 +468,63 @@ static int init_tile(J2kDecoderContext *s, int tileno)
return 0;
}
+int getpasstype(int passno)
+{
+ int passtype;
+ switch (passno % 3) {
+ case 0:
+ passtype = J2K_CLNPASS;
+ break;
+ case 1:
+ passtype = J2K_SIGPASS;
+ break;
+ case 2:
+ passtype = J2K_REFPASS;
+ break;
+ default:
+ passtype = -1;
+ assert(0);
+ break;
+ }
+ return passtype;
+}
+
+int getsegpasscnt(int passno, int firstpassno, int numpasses, int bypass, int termall)
+{
+ int ret;
+ int passtype;
+
+ if (termall) {
+ ret = 1;
+ } else if (bypass) {
+ if (passno < firstpassno + 10) {
+ ret = 10 - (passno - firstpassno);
+ } else {
+ passtype = JPC_PASSTYPE(passno);
+ switch (passtype) {
+ case J2K_SIGPASS:
+ ret = 2;
+ break;
+ case J2K_REFPASS:
+ ret = 1;
+ break;
+ case J2K_CLNPASS:
+ ret = 1;
+ break;
+ default:
+ ret = -1;
+ assert(0);
+ break;
+ }
+ }
+ } else {
+ ret = 32 * 3 - 2;
+ }
+ ret = FFMIN(ret, numpasses - passno);
+ return ret;
+}
+
+
/** read the number of coding passes */
static int getnpasses(J2kDecoderContext *s)
{
@@ -534,7 +591,7 @@ static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLev
for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++)
for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){
J2kCblk *cblk = band->cblk + cblkno;
- int incl, newpasses, llen;
+ int incl, newpasses, llen, n, savenewpasses, mycounter, maxpasses, num_segs, index;
if (cblk->npasses)
incl = get_bits(s, 1);
@@ -547,19 +604,46 @@ static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLev
return incl;
if (!cblk->npasses)
+ {
cblk->nonzerobits = expn[bandno] + numgbits - 1 - tag_tree_decode(s, prec->zerobits + pos, 100);
+ cblk->firstpassno = cblk->nonzerobits * 3;
+ }
if ((newpasses = getnpasses(s)) < 0)
- return newpasses;
+ return newpasses;
av_log(s->avctx, AV_LOG_INFO, "newpasses = %d\n", newpasses);
- if ((llen = getlblockinc(s)) < 0)
- return llen;
- av_log(s->avctx, AV_LOG_INFO, "increment = %d\n", llen);
- cblk->lblock += llen;
- if ((ret = get_bits(s, av_log2(newpasses) + cblk->lblock)) < 0)
- return ret;
- av_log(s->avctx, AV_LOG_INFO, "len = %d\n", ret);
- cblk->lengthinc = ret;
- cblk->npasses += newpasses;
+
+ savenewpasses = newpasses;
+ mycounter = 0;
+ if (newpasses > 0){
+ if ((llen = getlblockinc(s)) < 0)
+ return llen;
+ av_log(s->avctx, AV_LOG_INFO, "increment = %d\n", llen);
+ cblk->lblock += llen;
+ num_segs = 0;
+ index = 0;
+ while (newpasses > 0){
+ passno = cblk->firstpassno + cblk->npasses + mycounter;
+ /* XXX - the maxpasses is not set precisely but this doesn't matter... */
+ maxpasses = getsegpasscnt(passno, cblk->firstpassno, 10000, (codsty->cblk_style & J2K_CBLK_BYPASS)
+ != 0, (ccp->cblkctx & J2K_CBLK_TERMALL) != 0);
+ cblk->segs[num_segs].passno = passno;
+ cblk->segs[num_segs].maxpasses = maxpasses;
+ n = FFMIN(newpasses, maxpasses);
+ mycounter += n;
+ newpasses -= n;
+ if ((len = get_bits(s, cblk->lblock + av_log2(n))) < 0) {
+ return let;
+ }
+ cblk->segs[num_segs].npasses += n;
+ cblk->segs[num_segs].index = index;
+ index += len;
+ num_segs = num_segs + 1;
+ av_log(s->avctx, AV_LOG_INFO, "len = %d\n", ret);
+ }
+ }
+ cblk->length = index;
+ cblk->num_segs = num_segs;
+ cblk->npasses += savenewpasses;
}
}
j2k_flush(s);
@@ -578,14 +662,15 @@ static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLev
J2kBand *band = rlevel->band + bandno;
int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0;
for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){
- int xi;
+ int xi, i, cnt;
for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){
J2kCblk *cblk = band->cblk + yi * cblknw + xi;
- if (s->buf_end - s->buf < cblk->lengthinc)
- return AVERROR(EINVAL);
- bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);
- cblk->length += cblk->lengthinc;
- cblk->lengthinc = 0;
+ for (i = 0; i < cblk->num_segs; i++){
+ cnt = (i + 1 == cblk->num_segs? cblk->length: cblk->segs[i+1].index) - cblk->segs[i].index;
+ if (s->buf_end - s->buf < cnt)
+ return AVERROR(EINVAL);
+ bytestream_get_buffer(&s->buf, &cblk->data[cblk->segs[i].index], cnt);
+ }
}
}
}
@@ -727,7 +812,6 @@ static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Contex
for (y = 0; y < height; y++)
memset(t1->data[y], 0, width*sizeof(int));
- ff_mqc_initdec(&t1->mqc, cblk->data);
cblk->data[cblk->length] = 0xff;
cblk->data[cblk->length+1] = 0xff;
@@ -742,28 +826,34 @@ static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Contex
int bpass_csty_symbol = J2K_CBLK_BYPASS & codsty->cblk_style;
int vert_causal_ctx_csty_symbol = J2K_CBLK_VSC & codsty->cblk_style;
- while(passno--){
- switch(pass_t){
- case 0: decode_sigpass(t1, width, height, bpno+1, bandpos,
- bpass_csty_symbol && (clnpass_cnt >= 4), vert_causal_ctx_csty_symbol);
- break;
- case 1: decode_refpass(t1, width, height, bpno+1);
- if (bpass_csty_symbol && clnpass_cnt >= 4)
- ff_mqc_initdec(&t1->mqc, cblk->data);
- break;
- case 2: decode_clnpass(s, t1, width, height, bpno+1, bandpos,
- codsty->cblk_style & J2K_CBLK_SEGSYM);
- clnpass_cnt = clnpass_cnt + 1;
- if (bpass_csty_symbol && clnpass_cnt >= 4)
- ff_mqc_initdec(&t1->mqc, cblk->data);
- break;
- }
-
- pass_t++;
- if (pass_t == 3){
- bpno--;
- pass_t = 0;
- }
+ for (x = 0; cblk->num_segs; x++)
+
+ ff_mqc_initdec(&t1->mqc, cblk->data[cblk->segs[x].index]);
+
+ for (y = 0; y < cblk->segs[x].npasses; y++){
+
+ pass_t = (cblk->segs[x].passno + y + 2) % 3;
+
+ switch(pass_t){
+ case 0: decode_sigpass(t1, width, height, bpno+1, bandpos,
+ bpass_csty_symbol && (clnpass_cnt >= 4), vert_causal_ctx_csty_symbol);
+ break;
+ case 1: decode_refpass(t1, width, height, bpno+1);
+ if (bpass_csty_symbol && clnpass_cnt >= 4)
+ ff_mqc_initdec(&t1->mqc, cblk->data);
+ break;
+ case 2: decode_clnpass(s, t1, width, height, bpno+1, bandpos,
+ codsty->cblk_style & J2K_CBLK_SEGSYM);
+ clnpass_cnt = clnpass_cnt + 1;
+ if (bpass_csty_symbol && clnpass_cnt >= 4)
+ ff_mqc_initdec(&t1->mqc, cblk->data);
+ break;
+ }
+
+ if (pass_t == 3){
+ bpno--;
+ }
+ }
}
return 0;
}
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel