Changes proposed by Mathieu Malaterre from the GDCM project... Thanks a lot Mathieu
- '//' replaced by '/* */' - inclusion of int.h in int.c - inclusion of j2k.h in int.h in order to export symbols - adding (void) var when a variable is declared but not used - some explicit cast - CLOCKS_PER_SEC is declared as float in bcc55, so there is a need to cast it to int for the modulo operation - some variables changed from float -> double
This commit is contained in:
@@ -61,6 +61,7 @@ extern jmp_buf j2k_error;
|
||||
void tcd_dump(tcd_image_t * img, int curtileno)
|
||||
{
|
||||
int tileno, compno, resno, bandno, precno, cblkno;
|
||||
(void)curtileno;
|
||||
fprintf(stdout, "image {\n");
|
||||
fprintf(stdout, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", img->tw,
|
||||
img->th, tcd_img->x0, tcd_img->x1, tcd_img->y0, tcd_img->y1);
|
||||
@@ -144,7 +145,7 @@ void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||
/* tile->PPT=img->PPT; */
|
||||
/* Modification of the RATE >> */
|
||||
for (j = 0; j < tcp->numlayers; j++) {
|
||||
tcp->rates[j] = tcp->rates[j] ? int_ceildiv(tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * img->comps[0].prec, (tcp->rates[j] * 8 * img->comps[0].dx * img->comps[0].dy)) : 0; //Mod antonin losslessbug
|
||||
tcp->rates[j] = tcp->rates[j] ? int_ceildiv(tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * img->comps[0].prec, (tcp->rates[j] * 8 * img->comps[0].dx * img->comps[0].dy)) : 0; /*Mod antonin losslessbug*/
|
||||
if (tcp->rates[j]) {
|
||||
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
|
||||
tcp->rates[j] = tcp->rates[j - 1] + 20;
|
||||
@@ -270,7 +271,7 @@ void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||
tccp->qmfbid ==
|
||||
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
||||
numbps = img->comps[compno].prec + gain;
|
||||
band->stepsize = (1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn);
|
||||
band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
|
||||
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
||||
|
||||
band->precincts =
|
||||
@@ -341,6 +342,7 @@ void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||
void tcd_free_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||
{
|
||||
int tileno, compno, resno, bandno, precno;
|
||||
(void)curtileno;
|
||||
tcd_img = img;
|
||||
tcd_cp = cp;
|
||||
tcd_image.tw = cp->tw;
|
||||
@@ -380,7 +382,7 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||
for (tileno = 0; tileno < 1; tileno++) {
|
||||
j2k_tcp_t *tcp = &cp->tcps[curtileno];
|
||||
int j;
|
||||
// int previous_x0, previous_x1, previous_y0, previous_y1;
|
||||
/* int previous_x0, previous_x1, previous_y0, previous_y1;*/
|
||||
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
|
||||
int p = curtileno % cp->tw;
|
||||
int q = curtileno / cp->tw;
|
||||
@@ -396,7 +398,7 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||
/* tile->PPT=img->PPT; */
|
||||
/* Modification of the RATE >> */
|
||||
for (j = 0; j < tcp->numlayers; j++) {
|
||||
tcp->rates[j] = tcp->rates[j] ? int_ceildiv(tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * img->comps[0].prec, (tcp->rates[j] * 8 * img->comps[0].dx * img->comps[0].dy)) : 0; //Mod antonin losslessbug
|
||||
tcp->rates[j] = tcp->rates[j] ? int_ceildiv(tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * img->comps[0].prec, (tcp->rates[j] * 8 * img->comps[0].dx * img->comps[0].dy)) : 0; /*Mod antonin losslessbug*/
|
||||
if (tcp->rates[j]) {
|
||||
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
|
||||
tcp->rates[j] = tcp->rates[j - 1] + 20;
|
||||
@@ -512,7 +514,7 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||
tccp->qmfbid ==
|
||||
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
||||
numbps = img->comps[compno].prec + gain;
|
||||
band->stepsize = (1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn);
|
||||
band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
|
||||
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
||||
|
||||
for (precno = 0; precno < res->pw * res->ph; precno++) {
|
||||
@@ -600,7 +602,7 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
||||
tileno = cp->tileno[i];
|
||||
|
||||
|
||||
// int previous_x0, previous_x1, previous_y0, previous_y1;
|
||||
/* int previous_x0, previous_x1, previous_y0, previous_y1;*/
|
||||
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
|
||||
p = tileno % cp->tw; /* si numerotation matricielle .. */
|
||||
q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */
|
||||
@@ -659,8 +661,8 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
||||
tlprcystart = int_floordivpow2(res->y0, pdy) << pdy;
|
||||
brprcxend = int_ceildivpow2(res->x1, pdx) << pdx;
|
||||
brprcyend = int_ceildivpow2(res->y1, pdy) << pdy;
|
||||
res->pw = (res->x0 == res->x1) ? 0 : ((brprcxend - tlprcxstart) >> pdx); // Mod Antonin : sizebug1
|
||||
res->ph = (res->y0 == res->y1) ? 0 : ((brprcyend - tlprcystart) >> pdy); // Mod Antonin : sizebug1
|
||||
res->pw = (res->x0 == res->x1) ? 0 : ((brprcxend - tlprcxstart) >> pdx); /* Mod Antonin : sizebug1*/
|
||||
res->ph = (res->y0 == res->y1) ? 0 : ((brprcyend - tlprcystart) >> pdy); /* Mod Antonin : sizebug1*/
|
||||
|
||||
if (resno == 0) {
|
||||
tlcbgxstart = tlprcxstart;
|
||||
@@ -718,7 +720,7 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
||||
tccp->qmfbid ==
|
||||
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
||||
numbps = img->comps[compno].prec + gain;
|
||||
band->stepsize = (1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn);
|
||||
band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
|
||||
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
||||
|
||||
band->precincts =
|
||||
@@ -777,7 +779,7 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
||||
}
|
||||
}
|
||||
}
|
||||
//tcd_dump(&tcd_image,0);
|
||||
/*tcd_dump(&tcd_image,0);*/
|
||||
|
||||
|
||||
/* Allocate place to store the data decoded = final image */
|
||||
@@ -834,7 +836,7 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
||||
void tcd_makelayer_fixed(int layno, int final)
|
||||
{
|
||||
int compno, resno, bandno, precno, cblkno;
|
||||
int value; //, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3];
|
||||
int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3];*/
|
||||
int matrice[10][10][3];
|
||||
int i, j, k;
|
||||
|
||||
@@ -933,7 +935,7 @@ void tcd_makelayer(int layno, double thresh, int final)
|
||||
{
|
||||
int compno, resno, bandno, precno, cblkno, passno;
|
||||
|
||||
tcd_tile->distolayer[layno] = 0; //add fixed_quality
|
||||
tcd_tile->distolayer[layno] = 0; /*add fixed_quality*/
|
||||
|
||||
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
|
||||
tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
|
||||
@@ -996,7 +998,7 @@ void tcd_makelayer(int layno, double thresh, int final)
|
||||
cblk->passes[cblk->numpassesinlayers - 1].distortiondec;
|
||||
}
|
||||
|
||||
tcd_tile->distolayer[layno] += layer->disto; //add fixed_quality
|
||||
tcd_tile->distolayer[layno] += layer->disto; /*add fixed_quality*/
|
||||
|
||||
if (final)
|
||||
cblk->numpassesinlayers = n;
|
||||
@@ -1011,14 +1013,14 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
||||
{
|
||||
int compno, resno, bandno, precno, cblkno, passno, layno;
|
||||
double min, max;
|
||||
double cumdisto[100]; //add fixed_quality
|
||||
const double K = 1; // 1.1; //add fixed_quality
|
||||
double cumdisto[100]; /*add fixed_quality*/
|
||||
const double K = 1; /* 1.1; //add fixed_quality*/
|
||||
|
||||
double maxSE = 0;
|
||||
min = DBL_MAX;
|
||||
max = 0;
|
||||
|
||||
tcd_tile->nbpix = 0; //add fixed_quality
|
||||
tcd_tile->nbpix = 0; /*add fixed_quality*/
|
||||
|
||||
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
|
||||
tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
|
||||
@@ -1058,9 +1060,9 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
||||
}
|
||||
} /* passno */
|
||||
|
||||
tcd_tile->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); //add fixed_quality
|
||||
tcd_tile->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); /*add fixed_quality*/
|
||||
|
||||
tilec->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); //add fixed_quality
|
||||
tilec->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); /*add fixed_quality*/
|
||||
|
||||
} /* cbklno */
|
||||
} /* precno */
|
||||
@@ -1083,22 +1085,22 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
||||
volatile double lo = min;
|
||||
volatile double hi = max;
|
||||
volatile int success = 0;
|
||||
volatile int maxlen = tcd_tcp->rates[layno] ? int_min(tcd_tcp->rates[layno], len) : len; //Mod antonin losslessbug
|
||||
volatile int maxlen = tcd_tcp->rates[layno] ? int_min(tcd_tcp->rates[layno], len) : len; /*Mod antonin losslessbug*/
|
||||
volatile double goodthresh;
|
||||
volatile int i;
|
||||
double distotarget; //add fixed_quality
|
||||
double distotarget; /*add fixed_quality*/
|
||||
|
||||
distotarget = tcd_tile->distotile - ((K * maxSE) / pow(10, tcd_tcp->distoratio[layno] / 10)); // add fixed_quality
|
||||
distotarget = tcd_tile->distotile - ((K * maxSE) / pow(10, tcd_tcp->distoratio[layno] / 10)); /* add fixed_quality*/
|
||||
|
||||
if ((tcd_tcp->rates[layno]) || (tcd_cp->disto_alloc==0)) {
|
||||
for (i = 0; i < 32; i++) {
|
||||
volatile double thresh = (lo + hi) / 2;
|
||||
int l = 0;
|
||||
double distoachieved = 0; // add fixed_quality
|
||||
double distoachieved = 0; /* add fixed_quality*/
|
||||
|
||||
tcd_makelayer(layno, thresh, 0);
|
||||
|
||||
if (tcd_cp->fixed_quality) { // add fixed_quality
|
||||
if (tcd_cp->fixed_quality) { /* add fixed_quality*/
|
||||
distoachieved =
|
||||
layno ==
|
||||
0 ? tcd_tile->distolayer[0] : cumdisto[layno - 1] +
|
||||
@@ -1137,7 +1139,7 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
||||
}
|
||||
tcd_makelayer(layno, goodthresh, 1);
|
||||
|
||||
cumdisto[layno] = layno == 0 ? tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; // add fixed_quality
|
||||
cumdisto[layno] = layno == 0 ? tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; /* add fixed_quality*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1158,7 +1160,7 @@ tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
|
||||
tile = tcd_tile;
|
||||
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
|
||||
if (info_IM->index_on) {
|
||||
tcd_tilecomp_t *tilec_idx = &tile->comps[0]; //Based on Component 0
|
||||
tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /*Based on Component 0*/
|
||||
|
||||
for (i = 0; i < tilec_idx->numresolutions; i++) {
|
||||
|
||||
@@ -1251,7 +1253,7 @@ tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
|
||||
}
|
||||
/*----------------DWT---------------------*/
|
||||
|
||||
// mod Ive
|
||||
/* mod Ive*/
|
||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||
@@ -1260,7 +1262,7 @@ for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
dwt_encode_real(tilec);
|
||||
}
|
||||
}
|
||||
// /mod Ive
|
||||
/* /mod Ive*/
|
||||
/*------------------TIER1-----------------*/
|
||||
|
||||
t1_init_luts();
|
||||
@@ -1269,7 +1271,7 @@ for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
/*-----------RATE-ALLOCATE------------------*/
|
||||
info_IM->index_write = 0; /* INDEX */
|
||||
|
||||
if (tcd_cp->disto_alloc || tcd_cp->fixed_quality) // mod fixed_quality
|
||||
if (tcd_cp->disto_alloc || tcd_cp->fixed_quality) /* mod fixed_quality*/
|
||||
/* Normal Rate/distortion allocation */
|
||||
tcd_rateallocate(dest, len, info_IM);
|
||||
else
|
||||
@@ -1284,7 +1286,7 @@ for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
|
||||
time7 = clock() - time7;
|
||||
fprintf(stdout,"total: %ld.%.3ld s\n", time7 / CLOCKS_PER_SEC,
|
||||
(time7 % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
(time7 % (int)CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
|
||||
/* cleaning memory */
|
||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
@@ -1312,7 +1314,7 @@ tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
|
||||
tile = tcd_tile;
|
||||
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
|
||||
if (info_IM->index_on) {
|
||||
tcd_tilecomp_t *tilec_idx = &tile->comps[0]; //Based on Component 0
|
||||
tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /*Based on Component 0*/
|
||||
|
||||
for (i = 0; i < tilec_idx->numresolutions; i++) {
|
||||
|
||||
@@ -1403,7 +1405,7 @@ tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
|
||||
|
||||
/*----------------DWT---------------------*/
|
||||
|
||||
// mod Ive
|
||||
/* mod Ive*/
|
||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||
@@ -1412,7 +1414,7 @@ for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
dwt_encode_real(tilec);
|
||||
}
|
||||
}
|
||||
// /mod Ive
|
||||
/* /mod Ive*/
|
||||
|
||||
/*------------------TIER1-----------------*/
|
||||
|
||||
@@ -1423,7 +1425,7 @@ for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
|
||||
info_IM->index_write = 0; /* INDEX */
|
||||
|
||||
if (tcd_cp->disto_alloc || tcd_cp->fixed_quality) // mod fixed_quality
|
||||
if (tcd_cp->disto_alloc || tcd_cp->fixed_quality) /* mod fixed_quality*/
|
||||
|
||||
/* Normal Rate/distortion allocation */
|
||||
|
||||
@@ -1443,7 +1445,7 @@ for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
/*---------------CLEAN-------------------*/
|
||||
time = clock() - time;
|
||||
fprintf(stdout,"total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
|
||||
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
(time % (int)CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
|
||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
tilec = &tile->comps[compno];
|
||||
@@ -1495,7 +1497,7 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
||||
}
|
||||
|
||||
|
||||
// mod Ive
|
||||
/* mod Ive */
|
||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||
dwt_decode(tilec,
|
||||
tilec->numresolutions - 1 -
|
||||
@@ -1505,7 +1507,7 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
||||
tilec->numresolutions - 1 -
|
||||
tcd_img->comps[compno].resno_decoded);
|
||||
}
|
||||
// /mod Ive
|
||||
/* /mod Ive*/
|
||||
|
||||
if (tile->comps[compno].numresolutions > 0)
|
||||
tcd_img->comps[compno].factor =
|
||||
@@ -1561,7 +1563,7 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
||||
for (i = res->x0; i < res->x1; i++) {
|
||||
|
||||
int v;
|
||||
float tmp = (tilec->data[i - res->x0 + (j - res->y0) * tw])/8192.0;
|
||||
double tmp = (tilec->data[i - res->x0 + (j - res->y0) * tw])/8192.0;
|
||||
int tmp2;
|
||||
|
||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||
@@ -1582,7 +1584,7 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
||||
|
||||
time = clock() - time;
|
||||
fprintf(stdout, "%ld.%.3ld s\n", time / CLOCKS_PER_SEC,
|
||||
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
(time % (int)CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user