diff --git a/src/bin/jp2/convert.h b/src/bin/jp2/convert.h index 61439d49..b9b009ce 100644 --- a/src/bin/jp2/convert.h +++ b/src/bin/jp2/convert.h @@ -95,7 +95,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters); int imagetobmp(opj_image_t *image, const char *outfile); /* TIFF conversion*/ -opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters); +opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters, + const unsigned int target_bitdepth); int imagetotif(opj_image_t *image, const char *outfile); /** Load a single image component encoded in PGX file format diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index f657d2d4..5c6295ce 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -1247,7 +1247,8 @@ static void tif_16uto32s(const OPJ_UINT16* pSrc, OPJ_INT32* pDst, * libtiff/tif_getimage.c : 1,2,4,8,16 bitspersample accepted * CINEMA : 12 bit precision */ -opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) +opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters, + const unsigned int target_bitdepth) { int subsampling_dx = parameters->subsampling_dx; int subsampling_dy = parameters->subsampling_dy; @@ -1506,10 +1507,9 @@ 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)) { + } else if ((target_bitdepth > 0) && (target_bitdepth != tiBps)) { for (j = 0; j < numcomps; ++j) { - scale_component(&(image->comps[j]), parameters->target_bitdepth); + scale_component(&(image->comps[j]), target_bitdepth); } } return image; diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 61fd9ed7..aa130024 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -189,7 +189,8 @@ static void encode_help_display(void) fprintf(stdout, "-X \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, " if all bits are unwanted.\n"); + fprintf(stdout, " (Currently only implemented for TIF.)\n"); fprintf(stdout, "-b ,\n"); fprintf(stdout, " Code-block size. The dimension must respect the constraint \n"); @@ -604,7 +605,8 @@ static int parse_cmdline_encoder(int argc, char **argv, int* pOutFramerate, OPJ_BOOL* pOutPLT, OPJ_BOOL* pOutTLM, - int* pOutNumThreads) + int* pOutNumThreads, + unsigned int* pTarget_bitdepth) { OPJ_UINT32 i, j; int totlen, c; @@ -914,14 +916,12 @@ static int parse_cmdline_encoder(int argc, char **argv, /* ----------------------------------------------------- */ case 'X': { /* target bitdepth */ - unsigned int target_bitdepth = 0; char *s = opj_optarg; - sscanf(s, "%u", &target_bitdepth); - if (target_bitdepth == 0) { + sscanf(s, "%u", pTarget_bitdepth); + if (*pTarget_bitdepth == 0) { fprintf(stderr, "Target bitdepth must be at least 1 bit.\n"); return 1; } - parameters->target_bitdepth = target_bitdepth; } break; @@ -1925,6 +1925,9 @@ int main(int argc, char **argv) OPJ_BOOL TLM = OPJ_FALSE; int num_threads = 0; + /** desired bitdepth from input file */ + unsigned int target_bitdepth = 0; + /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); @@ -1945,7 +1948,7 @@ int main(int argc, char **argv) 255; /* This will be set later according to the input image or the provided option */ if (parse_cmdline_encoder(argc, argv, ¶meters, &img_fol, &raw_cp, indexfilename, sizeof(indexfilename), &framerate, &PLT, &TLM, - &num_threads) == 1) { + &num_threads, &target_bitdepth) == 1) { ret = 1; goto fin; } @@ -2038,7 +2041,7 @@ int main(int argc, char **argv) #ifdef OPJ_HAVE_LIBTIFF case TIF_DFMT: - image = tiftoimage(parameters.infile, ¶meters); + image = tiftoimage(parameters.infile, ¶meters, target_bitdepth); if (!image) { fprintf(stderr, "Unable to load tif(f) file\n"); ret = 1; diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 477d3310..0c5f2d5f 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -756,7 +756,6 @@ 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 = 0; parameters->tcp_rates[0] = 0; parameters->tcp_numlayers = 0; parameters->cp_disto_alloc = 0; diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 67819c70..68e4e7e1 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -471,8 +471,6 @@ typedef struct opj_cparameters { int decod_format; /** output file format 0: J2K, 1: JP2, 2: JPT */ int cod_format; - /** desired bitdepth from input file */ - unsigned int target_bitdepth; /*@}*/ /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */