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.
Thanks
--
Rukhsana Ruby
Phd Student
Department of Electrical & Computer Engineering
The University of British Columbia
============================
--- libavcodec/j2k.h 2011-05-02 06:02:46.949613000 -0700
+++ ../jpeg2000/j2k.h 2011-05-20 22:08:52.401936000 -0700
@@ -100,6 +100,11 @@
#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];
@@ -137,16 +142,62 @@
int64_t disto;
} J2kPass;
+
+
+typedef struct {
+ /* The next segment in the list. */
+ struct J2KCblkSeg *next;
+
+ /* The previous segment in the list. */
+ struct J2KCblkSeg *prev;
+
+ /* The starting pass number for this segment. */
+ uint8_t passno;
+
+ /* The number of passes in this segment. */
+ uint8_t numpasses;
+
+ /* The maximum number of passes in this segment. */
+ uint8_t maxpasses;
+
+ /* Data for this segment. */
+ uint8_t data[8192];
+
+ /* The number of bytes destined for this segment from the packet
+ currently being decoded. */
+ uint8_t cnt;
+
+ /* A flag indicating if this segment has been terminated. */
+ uint8_t complete;
+
+ /* The layer number to which this segment belongs. */
+ /* If the segment spans multiple layers, then the largest layer number
+ spanned by the segment is used. */
+ uint8_t lyrno;
+} J2KCblkSeg;
+
typedef struct {
+ /* The first entry in the list. */
+ J2KCblkSeg *head;
+
+ /* The last entry in the list. */
+ J2KCblkSeg *tail;
+} J2KCblkSegList;
+
+typedef struct {
+ /* A list of segments that still need to be decoded. */
+ J2KCblkSegList segs;
+
+ /* The first incomplete/partial segment. */
+ J2KCblkSeg *curseg;
+
+ /* The first pass number containing data for this code block. */
+ uint8_t firstpassno;
uint8_t npasses;
- uint8_t ninclpasses; ///< number coding of passes included in codestream
uint8_t nonzerobits;
uint16_t length;
uint16_t lengthinc;
uint8_t lblock;
- uint8_t zero;
- uint8_t data[8192];
- J2kPass passes[100];
} J2kCblk; ///< code block
typedef struct {
--- libavcodec/j2kdec.c 2011-05-20 21:00:31.358179000 -0700
+++ ../jpeg2000/j2kdec.c 2011-05-20 22:41:28.270844000 -0700
@@ -502,33 +490,83 @@
return res;
}
-static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLevel *rlevel, int precno,
- int layno, uint8_t *expn, int numgbits)
+int getpasstype(int passno)
{
- int bandno, cblkny, cblknx, cblkno, ret, marker, len;
+ 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;
+}
- av_log(s->avctx, AV_LOG_INFO, "start decode_packet %d\n", s->buf - s->buf_start);
+static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLevel *rlevel, int precno,
+ int layno, uint8_t *expn, int numgbits)
+{
+ int bandno, cblkny, cblknx, cblkno, len, marker;
+ J2KCblkSeg *seg;
- /*av_log(s->avctx, AV_LOG_INFO, "csty = %x\n", codsty->csty);
- if (codsty->csty & 0)
- {
- av_log(s->avctx, AV_LOG_INFO, "inside marker\n");
- marker = bytestream_get_be16(&s->buf);
- if (marker != J2K_SOP)
- return -1;
- len = bytestream_get_be16(&s->buf);
- s->buf += len -2;
- }*/
+ if (codsty->csty & J2K_CSTY_SOP) {
+ marker = bytestream_get_be16(&s->buf);
+ if (marker != J2K_SOP)
+ return -1;
+ len = bytestream_get_be16(&s->buf);
+ s->buf += len -2;
+ }
- if (!(ret = get_bits(s, 1))){
+ if (!(ret = get_bits(s, 1))){
j2k_flush(s);
return 0;
} else if (ret < 0)
return ret;
-
-
for (bandno = 0; bandno < rlevel->nbands; bandno++){
J2kBand *band = rlevel->band + bandno;
J2kPrec *prec = band->prec + precno;
@@ -541,38 +579,65 @@
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;
if (cblk->npasses)
incl = get_bits(s, 1);
else
incl = tag_tree_decode(s, prec->cblkincl + pos, layno+1) == layno;
- av_log(s->avctx, AV_LOG_INFO, "included = %d\n", incl);
if (!incl)
continue;
else if (incl < 0)
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;
- 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;
+ seg = cblk->curseg;
+ savenewpasses = newpasses;
+ mycounter = 0;
+ if (newpasses > 0) {
+ if ((llen = getlblockinc(s)) < 0)
+ return llen;
+ cblk->lblock += llen;
+
+ 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);
+ if (!seg) {
+ if (!(seg = alloc_cblk_seg())) {
+ return -1;
+ }
+ insert_seg_in_seglist(&cblk->segs, cblk->segs.tail, seg);
+ if (!cblk->curseg) {
+ cblk->curseg = seg;
+ }
+ seg->passno = passno;
+ seg->maxpasses = maxpasses;
+ }
+ n = FFMIN(newpasses, maxpasses);
+ mycounter += n;
+ numpasses -= n;
+ if ((len = get_bits(s, cblk->lblock + av_log2(n))) < 0) {
+ return let;
+ }
+ seg->lyrno = lyrno;
+ seg->npasses += n;
+ seg->cnt = len;
+ seg = seg->next;
+ }
+ }
+ cblk->npasses += savenewpasses;
+ }
}
}
j2k_flush(s);
- av_log(s->avctx, AV_LOG_INFO, "before end of packet header %d\n", s->buf - s->buf_start);
-
if (codsty->csty & J2K_CSTY_EPH) {
if (AV_RB16(s->buf) == J2K_EPH) {
s->buf += 2;
@@ -588,11 +653,18 @@
int xi;
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;
+ seg = cblk->curseg;
+ while (seg) {
+ if (s->buf_end - s->buf < seg->cnt)
+ return AVERROR(EINVAL);
+ bytestream_get_buffer(&s->buf, seg->data, seg->cnt);
+ cblk->length += seg->cnt;
+ seg->cnt = 0;
+ if (seg->numpasses >= seg->maxpasses) {
+ cblk->curseg = seg->next;
+ }
+ seg = seg->next;
+ }
}
}
}
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel