refactor to not use opj_cparameters_t

This commit is contained in:
Matthew Sheby 2021-10-21 13:31:38 -07:00
parent 4a1e327415
commit ae566ad713
5 changed files with 17 additions and 16 deletions

View File

@ -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

View File

@ -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;

View File

@ -189,7 +189,8 @@ static void encode_help_display(void)
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, " if all bits are unwanted.\n");
fprintf(stdout, " (Currently only implemented for TIF.)\n");
fprintf(stdout, "-b <cblk width>,<cblk height>\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(&parameters);
@ -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, &parameters, &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, &parameters);
image = tiftoimage(parameters.infile, &parameters, target_bitdepth);
if (!image) {
fprintf(stderr, "Unable to load tif(f) file\n");
ret = 1;

View File

@ -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;

View File

@ -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 */