diff --git a/ChangeLog b/ChangeLog index 979f1c29..7cbd72cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ What's New for OpenJPEG ! : changed + : added +October 31, 2006 ++ [Antonin] added the ability to specify the rate as "float" (before : integer) + August 18, 2006 * [Antonin] fixed a bug in j2k_to_image.c, that prevented the -l option to work correctly. diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c index 911f3224..3c3f59ff 100644 --- a/codec/image_to_j2k.c +++ b/codec/image_to_j2k.c @@ -272,7 +272,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) case 'r': /* rates rates/distorsion */ { char *s = optarg; - while (sscanf(s, "%d", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) { + while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) { parameters->tcp_numlayers++; while (*s && *s != ',') { s++; diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c index 5c1d10d6..bbca537f 100644 --- a/libopenjpeg/j2k.c +++ b/libopenjpeg/j2k.c @@ -259,7 +259,7 @@ void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp) { fprintf(fd, " mct=%d\n", tcp->mct); fprintf(fd, " rates="); for (layno = 0; layno < tcp->numlayers; layno++) { - fprintf(fd, "%d ", tcp->rates[layno]); + fprintf(fd, "%.1f ", tcp->rates[layno]); } fprintf(fd, "\n"); for (compno = 0; compno < img->numcomps; compno++) { diff --git a/libopenjpeg/j2k.h b/libopenjpeg/j2k.h index 42e452a9..c5282465 100644 --- a/libopenjpeg/j2k.h +++ b/libopenjpeg/j2k.h @@ -151,7 +151,7 @@ typedef struct opj_tcp { /** multi-component transform identifier */ int mct; /** rates of layers */ - int rates[100]; + float rates[100]; /** number of progression order changes */ int numpocs; /** indicates if a POC marker has been used O:NO, 1:YES */ diff --git a/libopenjpeg/openjpeg.h b/libopenjpeg/openjpeg.h index 90d23639..5961dabf 100644 --- a/libopenjpeg/openjpeg.h +++ b/libopenjpeg/openjpeg.h @@ -216,7 +216,7 @@ typedef struct opj_cparameters { /** number of layers */ int tcp_numlayers; /** rates of layers */ - int tcp_rates[100]; + float tcp_rates[100]; /** different psnr for successive layers */ float tcp_distoratio[100]; /** number of resolutions */ diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c index 9222a4d8..bf0a81bf 100644 --- a/libopenjpeg/tcd.c +++ b/libopenjpeg/tcd.c @@ -149,11 +149,11 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c /* Modification of the RATE >> */ for (j = 0; j < tcp->numlayers; j++) { tcp->rates[j] = tcp->rates[j] ? - int_ceildiv(tile->numcomps + ((float) (tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) - * image->comps[0].prec, - (tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) + * image->comps[0].prec))/ + (tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy) + 34 : 0; if (tcp->rates[j]) { @@ -394,12 +394,12 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur /* 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) - * image->comps[0].prec, - (tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy)) - : 0; + ((float) (tile->numcomps + * (tile->x1 - tile->x0) + * (tile->y1 - tile->y0) + * image->comps[0].prec))/ + (tcp->rates[j] * 8 * image->comps[0].dx * image->comps[0].dy) + : 0; if (tcp->rates[j]) { if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { @@ -1020,7 +1020,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in double hi = max; int success = 0; /* TODO: remove maxlen */ - int maxlen = tcd_tcp->rates[layno] ? int_min(tcd_tcp->rates[layno], len) : len; + int maxlen = tcd_tcp->rates[layno] ? (tcd_tcp->rates[layno] < len ? tcd_tcp->rates[layno] : len) : len; double goodthresh = 0; int i; double distotarget; /* fixed_quality */