enable decimation of input TIF

This commit is contained in:
Matthew Sheby 2021-10-20 15:29:04 -07:00
parent 714c63efee
commit 4735d941d9
4 changed files with 25 additions and 1 deletions

View File

@ -1507,6 +1507,10 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
scale_component(&(image->comps[j]), 12);
}
} else if ((parameters->target_bitdepth > 0) && (parameters->target_bitdepth != tiBps)) {
for (j = 0; j < numcomps; ++j) {
scale_component(&(image->comps[j]), parameters->target_bitdepth);
}
}
return image;

View File

@ -186,6 +186,10 @@ static void encode_help_display(void)
fprintf(stdout,
" It corresponds to the number of DWT decompositions +1. \n");
fprintf(stdout, " Default: 6.\n");
fprintf(stdout, "-X <target bitdepth>\n");
fprintf(stdout, " Target bitdepth.\n");
fprintf(stdout, " Number of bits per component to use from input image\n");
fprintf(stdout, " if all bits are unwanted. \n");
fprintf(stdout, "-b <cblk width>,<cblk height>\n");
fprintf(stdout,
" Code-block size. The dimension must respect the constraint \n");
@ -623,7 +627,7 @@ static int parse_cmdline_encoder(int argc, char **argv,
};
/* parse the command line */
const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:"
const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:X:"
#ifdef USE_JPWL
"W:"
#endif /* USE_JPWL */
@ -908,6 +912,19 @@ static int parse_cmdline_encoder(int argc, char **argv,
}
break;
/* ----------------------------------------------------- */
case 'X': { /* target bitdepth */
int target_bitdepth = 0;
char *s = opj_optarg;
sscanf(s, "%d", &target_bitdepth);
if (target_bitdepth <= 0) {
fprintf(stderr, "Target bitdepth must be at least 1 bit.\n");
return 1;
}
parameters->target_bitdepth = target_bitdepth;
}
break;
/* ----------------------------------------------------- */
case 'n': { /* resolution */

View File

@ -756,6 +756,7 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t
parameters->tp_on = 0;
parameters->decod_format = -1;
parameters->cod_format = -1;
parameters->target_bitdepth = -1;
parameters->tcp_rates[0] = 0;
parameters->tcp_numlayers = 0;
parameters->cp_disto_alloc = 0;

View File

@ -465,6 +465,8 @@ typedef struct opj_cparameters {
int decod_format;
/** output file format 0: J2K, 1: JP2, 2: JPT */
int cod_format;
/** desired bitdepth from input file */
int target_bitdepth;
/*@}*/
/* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */