[FFmpeg-soc] [soc]: r776 - in jpeg2000: j2k.c j2k.h j2kdec.c j2kenc.c
k.nowosad
subversion at mplayerhq.hu
Tue Aug 14 13:57:03 CEST 2007
Author: k.nowosad
Date: Tue Aug 14 13:57:03 2007
New Revision: 776
Log:
optimized tag tree allocation
Modified:
jpeg2000/j2k.c
jpeg2000/j2k.h
jpeg2000/j2kdec.c
jpeg2000/j2kenc.c
Modified: jpeg2000/j2k.c
==============================================================================
--- jpeg2000/j2k.c (original)
+++ jpeg2000/j2k.c Tue Aug 14 13:57:03 2007
@@ -57,24 +57,15 @@ int ff_j2k_ceildiv(int a, int b)
/* tag tree routines */
/** allocate the memory for tag tree */
-//TODO: optimize (too many mallocs)
-static J2kTgtNode *tag_tree_alloc(int w, int h)
-{
- int i;
- J2kTgtNode *t = av_malloc(w*h*sizeof(J2kTgtNode));
- if (t == NULL)
- return NULL;
- for (i = 0; i < w*h; i++){
- t[i].val = 0;
- t[i].vis = 0;
- }
- return t;
-}
-
J2kTgtNode *ff_j2k_tag_tree_init(int w, int h)
{
- J2kTgtNode *res = tag_tree_alloc(w, h),
- *t = res;
+ int size = 2 << av_log2(w*h);
+ J2kTgtNode *res, *t, *t2;
+
+ if (size < w*h)
+ size *= 4;
+
+ t = res = av_mallocz(size*sizeof(J2kTgtNode));
if (res == NULL)
return NULL;
@@ -82,13 +73,10 @@ J2kTgtNode *ff_j2k_tag_tree_init(int w,
while (w > 1 || h > 1){
int pw = w, ph = h;
int i, j;
- J2kTgtNode *t2;
w = (w+1) >> 1;
h = (h+1) >> 1;
- t2 = tag_tree_alloc(w, h);
- if (t2 == NULL)
- return NULL;
+ t2 = t + pw*ph;
for (i = 0; i < ph; i++)
for (j = 0; j < pw; j++){
@@ -100,15 +88,6 @@ J2kTgtNode *ff_j2k_tag_tree_init(int w,
return res;
}
-void ff_j2k_tag_tree_destroy(J2kTgtNode *tree)
-{
- while (tree != NULL){
- J2kTgtNode *parent = tree[0].parent;
- av_free(tree);
- tree = parent;
- }
-}
-
int ff_j2k_getnbctxno(int flag, int bandno)
{
int h, v, d;
Modified: jpeg2000/j2k.h
==============================================================================
--- jpeg2000/j2k.h (original)
+++ jpeg2000/j2k.h Tue Aug 14 13:57:03 2007
@@ -105,7 +105,6 @@ int ff_j2k_ceildiv(int a, int b);
/** tag tree routines */
J2kTgtNode *ff_j2k_tag_tree_init(int w, int h);
-void ff_j2k_tag_tree_destroy(J2kTgtNode *tree);
/** TIER-1 routines */
int ff_j2k_getnbctxno(int flag, int bandno);
Modified: jpeg2000/j2kdec.c
==============================================================================
--- jpeg2000/j2kdec.c (original)
+++ jpeg2000/j2kdec.c Tue Aug 14 13:57:03 2007
@@ -984,8 +984,8 @@ static void cleanup(J2kDecoderContext *s
for (precno = 0; precno < reslevel->nprecw * reslevel->nprech; precno++){
J2kPrec *prec = band->prec + precno;
- ff_j2k_tag_tree_destroy(prec->zerobits);
- ff_j2k_tag_tree_destroy(prec->cblkincl);
+ av_free(prec->zerobits);
+ av_free(prec->cblkincl);
}
av_free(band->cblk);
av_free(band->prec);
Modified: jpeg2000/j2kenc.c
==============================================================================
--- jpeg2000/j2kenc.c (original)
+++ jpeg2000/j2kenc.c Tue Aug 14 13:57:03 2007
@@ -869,8 +869,8 @@ static void encode_packet(J2kEncoderCont
}
}
- ff_j2k_tag_tree_destroy(cblkincl);
- ff_j2k_tag_tree_destroy(zerobits);
+ av_free(cblkincl);
+ av_free(zerobits);
}
j2k_flush(s);
for (bandno = 0; bandno < rlevel->nbands; bandno++){
More information about the FFmpeg-soc
mailing list