summaryrefslogtreecommitdiff
path: root/libopenjpeg/t1.c
diff options
context:
space:
mode:
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>2007-11-14 10:52:02 +0000
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>2007-11-14 10:52:02 +0000
commit010ae27471655e3fe05912bd9965245a4f2cd7f3 (patch)
tree5799bb0c4d6b0a1c26e842a7f0c6ece5276724b9 /libopenjpeg/t1.c
parent24e189e4d8a231e7273d788b2bd77e2484cec761 (diff)
Patch by Callum Lerwick. The opj_tcd_cblk array is one of the largest allocations, because it contains a bunch of static buffers. This also makes it a major source of cache thrashing. This patch allocates the buffers from the heap, and dynamically sizes them in the decoder. I have not yet managed to dynamically size them in the encoder, getting the decoder to do it was tricky enough... I also split opj_tcd_cblk_t into separate encode and decode versions. A lot of fields were not used by both, so this cuts its size even further.
Diffstat (limited to 'libopenjpeg/t1.c')
-rw-r--r--libopenjpeg/t1.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/libopenjpeg/t1.c b/libopenjpeg/t1.c
index 63d42fa1..ad1c6a83 100644
--- a/libopenjpeg/t1.c
+++ b/libopenjpeg/t1.c
@@ -194,7 +194,7 @@ Encode 1 code-block
*/
static void t1_encode_cblk(
opj_t1_t *t1,
- opj_tcd_cblk_t * cblk,
+ opj_tcd_cblk_enc_t* cblk,
int orient,
int compno,
int level,
@@ -213,7 +213,7 @@ Decode 1 code-block
*/
static void t1_decode_cblk(
opj_t1_t *t1,
- opj_tcd_cblk_t * cblk,
+ opj_tcd_cblk_dec_t* cblk,
int orient,
int roishift,
int cblksty);
@@ -792,7 +792,7 @@ static bool allocate_buffers(
/** mod fixed_quality */
static void t1_encode_cblk(
opj_t1_t *t1,
- opj_tcd_cblk_t * cblk,
+ opj_tcd_cblk_enc_t* cblk,
int orient,
int compno,
int level,
@@ -925,7 +925,7 @@ static void t1_encode_cblk(
static void t1_decode_cblk(
opj_t1_t *t1,
- opj_tcd_cblk_t * cblk,
+ opj_tcd_cblk_dec_t* cblk,
int orient,
int roishift,
int cblksty)
@@ -958,10 +958,14 @@ static void t1_decode_cblk(
/* BYPASS mode */
type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
+ /* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */
+ if(seg->data == NULL){
+ continue;
+ }
if (type == T1_TYPE_RAW) {
- raw_init_dec(raw, seg->data, seg->len);
+ raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
} else {
- mqc_init_dec(mqc, seg->data, seg->len);
+ mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len);
}
for (passno = 0; passno < seg->numpasses; ++passno) {
@@ -1046,7 +1050,7 @@ void t1_encode_cblks(
opj_tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; ++cblkno) {
- opj_tcd_cblk_t *cblk = &prc->cblks[cblkno];
+ opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
int* restrict datap;
int* restrict tiledp;
int cblk_w;
@@ -1134,7 +1138,7 @@ void t1_decode_cblks(
opj_tcd_precinct_t* precinct = &band->precincts[precno];
for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) {
- opj_tcd_cblk_t* cblk = &precinct->cblks[cblkno];
+ opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno];
int* restrict datap;
void* restrict tiledp;
int cblk_w, cblk_h;
@@ -1193,8 +1197,10 @@ void t1_decode_cblks(
}
}
}
+ opj_free(cblk->data);
+ opj_free(cblk->segs);
} /* cblkno */
- opj_free(precinct->cblks);
+ opj_free(precinct->cblks.dec);
} /* precno */
} /* bandno */
} /* resno */