[trunk] fix compilation on windows where getopt is not available
This commit is contained in:
parent
de33ba029b
commit
b2bebcf5ce
|
@ -8,6 +8,7 @@ SET(common_SRCS
|
|||
|
||||
# Headers file are located here:
|
||||
include_directories(
|
||||
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
|
||||
${OPENJPEG_SOURCE_DIR}/src/lib/openjp3d
|
||||
${LCMS_INCLUDE_DIRNAME}
|
||||
${OPENJPEG_SOURCE_DIR}/src/bin/common
|
||||
|
|
|
@ -32,8 +32,9 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "opj_config.h"
|
||||
#include "openjp3d.h"
|
||||
#include "getopt.h"
|
||||
#include "opj_getopt.h"
|
||||
#include "convert.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -238,13 +239,13 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
/* parse the command line */
|
||||
|
||||
while (1) {
|
||||
int c = getopt(argc, argv, "i:m:o:r:q:f:t:n:c:b:x:p:s:d:hP:S:E:M:D:R:l:T:C:A:I");
|
||||
int c = opj_getopt(argc, argv, "i:m:o:r:q:f:t:n:c:b:x:p:s:d:hP:S:E:M:D:R:l:T:C:A:I");
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'i': /* input file */
|
||||
{
|
||||
char *infile = optarg;
|
||||
char *infile = opj_optarg;
|
||||
parameters->decod_format = get_file_format(infile);
|
||||
switch(parameters->decod_format) {
|
||||
case PGX_DFMT:
|
||||
|
@ -265,7 +266,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
/* ----------------------------------------------------- */
|
||||
case 'm': /* input IMG file */
|
||||
{
|
||||
char *imgfile = optarg;
|
||||
char *imgfile = opj_optarg;
|
||||
int imgformat = get_file_format(imgfile);
|
||||
switch(imgformat) {
|
||||
case IMG_DFMT:
|
||||
|
@ -283,7 +284,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
/* ----------------------------------------------------- */
|
||||
case 'o': /* output file */
|
||||
{
|
||||
char *outfile = optarg;
|
||||
char *outfile = opj_optarg;
|
||||
parameters->cod_format = get_file_format(outfile);
|
||||
switch(parameters->cod_format) {
|
||||
case J3D_CFMT:
|
||||
|
@ -304,7 +305,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 'r': /* define compression rates for each layer */
|
||||
{
|
||||
char *s = optarg;
|
||||
char *s = opj_optarg;
|
||||
while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) {
|
||||
parameters->tcp_numlayers++;
|
||||
while (*s && *s != ',') {
|
||||
|
@ -322,7 +323,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 'q': /* define distorsion (PSNR) for each layer */
|
||||
{
|
||||
char *s = optarg;
|
||||
char *s = opj_optarg;
|
||||
while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
|
||||
parameters->tcp_numlayers++;
|
||||
while (*s && *s != ',') {
|
||||
|
@ -346,7 +347,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
/*int *row = NULL, *col = NULL;
|
||||
int numlayers = 0, matrix_width = 0;
|
||||
|
||||
char *s = optarg;
|
||||
char *s = opj_optarg;
|
||||
sscanf(s, "%d", &numlayers);
|
||||
s++;
|
||||
if (numlayers > 9)
|
||||
|
@ -389,7 +390,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 't': /* tiles */
|
||||
{
|
||||
if (sscanf(optarg, "%d,%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy, ¶meters->cp_tdz) !=3) {
|
||||
if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy, ¶meters->cp_tdz) !=3) {
|
||||
fprintf(stdout, "[ERROR] '-t' 'dimensions of tiles' argument error ! [-t tdx,tdy,tdz]\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -402,7 +403,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
case 'n': /* resolution */
|
||||
{
|
||||
int aux;
|
||||
aux = sscanf(optarg, "%d,%d,%d", ¶meters->numresolution[0], ¶meters->numresolution[1], ¶meters->numresolution[2]);
|
||||
aux = sscanf(opj_optarg, "%d,%d,%d", ¶meters->numresolution[0], ¶meters->numresolution[1], ¶meters->numresolution[2]);
|
||||
if (aux == 2)
|
||||
parameters->numresolution[2] = 1;
|
||||
else if (aux == 1) {
|
||||
|
@ -422,7 +423,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
char sep;
|
||||
int res_spec = 0;
|
||||
int aux;
|
||||
char *s = optarg;
|
||||
char *s = opj_optarg;
|
||||
do {
|
||||
sep = 0;
|
||||
aux = sscanf(s, "[%d,%d,%d]%c", ¶meters->prct_init[0][res_spec], ¶meters->prct_init[1][res_spec], ¶meters->prct_init[2][res_spec], &sep);
|
||||
|
@ -444,7 +445,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
case 'b': /* code-block dimension */
|
||||
{
|
||||
int cblockw_init = 0, cblockh_init = 0, cblockl_init = 0;
|
||||
if (sscanf(optarg, "%d,%d,%d", &cblockw_init, &cblockh_init, &cblockl_init) != 3) {
|
||||
if (sscanf(opj_optarg, "%d,%d,%d", &cblockw_init, &cblockh_init, &cblockl_init) != 3) {
|
||||
fprintf(stdout, "[ERROR] '-b' 'dimensions of codeblocks' argument error ! [-b cblkx,cblky,cblkz]\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -462,7 +463,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 'x': /* creation of index file */
|
||||
{
|
||||
char *index = optarg;
|
||||
char *index = opj_optarg;
|
||||
strncpy(parameters->index, index, MAX_PATH);
|
||||
parameters->index_on = 1;
|
||||
}
|
||||
|
@ -474,7 +475,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
{
|
||||
char progression[4];
|
||||
|
||||
strncpy(progression, optarg, 4);
|
||||
strncpy(progression, opj_optarg, 4);
|
||||
parameters->prog_order = give_progression(progression);
|
||||
if (parameters->prog_order == -1) {
|
||||
fprintf(stdout, "[ERROR] Unrecognized progression order [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
|
||||
|
@ -487,7 +488,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 's': /* subsampling factor */
|
||||
{
|
||||
if (sscanf(optarg, "%d,%d,%d", ¶meters->subsampling_dx, ¶meters->subsampling_dy, ¶meters->subsampling_dz) != 2) {
|
||||
if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->subsampling_dx, ¶meters->subsampling_dy, ¶meters->subsampling_dz) != 2) {
|
||||
fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -498,7 +499,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 'd': /* coordonnate of the reference grid */
|
||||
{
|
||||
if (sscanf(optarg, "%d,%d,%d", ¶meters->volume_offset_x0, ¶meters->volume_offset_y0, ¶meters->volume_offset_z0) != 3) {
|
||||
if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->volume_offset_x0, ¶meters->volume_offset_y0, ¶meters->volume_offset_z0) != 3) {
|
||||
fprintf(stdout, "[ERROR] -d 'coordonnate of the reference grid' argument error !! [-d x0,y0,z0]\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -521,7 +522,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
int numpocs = 0; /* number of progression order change (POC) default 0 */
|
||||
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
|
||||
|
||||
char *s = optarg;
|
||||
char *s = opj_optarg;
|
||||
POC = parameters->POC;
|
||||
|
||||
fprintf(stdout, "/----------------------------------\\\n");
|
||||
|
@ -569,7 +570,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
{
|
||||
fprintf(stdout, "[INFO] Mode switch option not fully tested !!\n");
|
||||
value = 0;
|
||||
if (sscanf(optarg, "%d", &value) == 1) {
|
||||
if (sscanf(opj_optarg, "%d", &value) == 1) {
|
||||
for (i = 0; i <= 6; i++) {
|
||||
int cache = value & (1 << i);
|
||||
if (cache)
|
||||
|
@ -583,7 +584,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 'D': /* DCO */
|
||||
{
|
||||
if (sscanf(optarg, "%d", ¶meters->dcoffset) != 1) {
|
||||
if (sscanf(opj_optarg, "%d", ¶meters->dcoffset) != 1) {
|
||||
fprintf(stdout, "[ERROR] DC offset error !! [-D %d]\n",parameters->dcoffset);
|
||||
return 1;
|
||||
}
|
||||
|
@ -594,7 +595,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 'R': /* ROI */
|
||||
{
|
||||
if (sscanf(optarg, "OI:c=%d,U=%d", ¶meters->roi_compno, ¶meters->roi_shift) != 2) {
|
||||
if (sscanf(opj_optarg, "OI:c=%d,U=%d", ¶meters->roi_compno, ¶meters->roi_shift) != 2) {
|
||||
fprintf(stdout, "[ERROR] ROI error !! [-ROI:c='compno',U='shift']\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -605,7 +606,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
|
||||
case 'l': /* Tile offset */
|
||||
{
|
||||
if (sscanf(optarg, "%d,%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0, ¶meters->cp_tz0) != 3) {
|
||||
if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0, ¶meters->cp_tz0) != 3) {
|
||||
fprintf(stdout, "[ERROR] -l 'tile offset' argument error !! [-l X0,Y0,Z0]");
|
||||
return 1;
|
||||
}
|
||||
|
@ -618,7 +619,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
{
|
||||
char transform[4];
|
||||
|
||||
strncpy(transform, optarg, 4);
|
||||
strncpy(transform, opj_optarg, 4);
|
||||
parameters->transform_format = give_transform(transform);
|
||||
if (parameters->transform_format == -1) {
|
||||
fprintf(stdout, "[ERROR] -T 'Transform domain' argument error !! [-T 2DWT, 3DWT, 3RLS or 3LSE only]");
|
||||
|
@ -633,7 +634,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
{
|
||||
char coding[3];
|
||||
|
||||
strncpy(coding, optarg, 3);
|
||||
strncpy(coding, opj_optarg, 3);
|
||||
parameters->encoding_format = give_coding(coding);
|
||||
if (parameters->encoding_format == -1) {
|
||||
fprintf(stdout, "[ERROR] -C 'Coding algorithm' argument error !! [-C 2EB, 3EB, 2GR, 3GR or GRI only]");
|
||||
|
@ -651,7 +652,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
|
|||
break;
|
||||
|
||||
default:
|
||||
fprintf(stdout, "[ERROR] This option is not valid \"-%c %s\"\n", c, optarg);
|
||||
fprintf(stdout, "[ERROR] This option is not valid \"-%c %s\"\n", c, opj_optarg);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "opj_config.h"
|
||||
#include "openjp3d.h"
|
||||
#include "getopt.h"
|
||||
#include "opj_getopt.h"
|
||||
#include "convert.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -87,7 +88,7 @@ static double calc_PSNR(opj_volume_t *original, opj_volume_t *decoded)
|
|||
return -1.0;
|
||||
|
||||
return total;
|
||||
//return 20 * log10((max - 1) / sqrt(sum));
|
||||
/*return 20 * log10((max - 1) / sqrt(sum));*/
|
||||
}
|
||||
|
||||
static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
|
||||
|
@ -95,29 +96,29 @@ static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
|
|||
int max, i, compno = 0, size, sizeM;
|
||||
double sum;
|
||||
double mux = 0.0, muy = 0.0, sigmax = 0.0, sigmay = 0.0,
|
||||
sigmaxy = 0.0, structx = 0.0, structy = 0.0;
|
||||
sigmaxy = 0.0/*, structx = 0.0, structy = 0.0*/;
|
||||
double lcomp,ccomp,scomp;
|
||||
double C1,C2,C3;
|
||||
|
||||
max = (original->comps[compno].prec <= 8) ? 255 : (1 << original->comps[compno].prec) - 1;
|
||||
size = (original->x1 - original->x0) * (original->y1 - original->y0) * (original->z1 - original->z0);
|
||||
|
||||
//MSSIM
|
||||
/*MSSIM*/
|
||||
|
||||
// sizeM = size / (original->z1 - original->z0);
|
||||
/* sizeM = size / (original->z1 - original->z0);*/
|
||||
|
||||
sizeM = size;
|
||||
for(sum = 0, i = 0; i < sizeM; ++i) {
|
||||
// First, the luminance of each signal is compared.
|
||||
/* First, the luminance of each signal is compared.*/
|
||||
mux += original->comps[compno].data[i];
|
||||
muy += decoded->comps[compno].data[i];
|
||||
}
|
||||
mux /= sizeM;
|
||||
muy /= sizeM;
|
||||
|
||||
//We use the standard deviation (the square root of variance) as an estimate of the signal contrast.
|
||||
/*We use the standard deviation (the square root of variance) as an estimate of the signal contrast.*/
|
||||
for(sum = 0, i = 0; i < sizeM; ++i) {
|
||||
// First, the luminance of each signal is compared.
|
||||
/* First, the luminance of each signal is compared.*/
|
||||
sigmax += (original->comps[compno].data[i] - mux) * (original->comps[compno].data[i] - mux);
|
||||
sigmay += (decoded->comps[compno].data[i] - muy) * (decoded->comps[compno].data[i] - muy);
|
||||
sigmaxy += (original->comps[compno].data[i] - mux) * (decoded->comps[compno].data[i] - muy);
|
||||
|
@ -130,19 +131,19 @@ static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
|
|||
sigmay = sqrt(sigmay);
|
||||
sigmaxy = sqrt(sigmaxy);
|
||||
|
||||
//Third, the signal is normalized (divided) by its own standard deviation,
|
||||
//so that the two signals being compared have unit standard deviation.
|
||||
/*Third, the signal is normalized (divided) by its own standard deviation, */
|
||||
/*so that the two signals being compared have unit standard deviation.*/
|
||||
|
||||
//Luminance comparison
|
||||
/*Luminance comparison*/
|
||||
C1 = (0.01 * max) * (0.01 * max);
|
||||
lcomp = ((2 * mux * muy) + C1)/((mux*mux) + (muy*mux) + C1);
|
||||
//Constrast comparison
|
||||
/*Constrast comparison*/
|
||||
C2 = (0.03 * max) * (0.03 * max);
|
||||
ccomp = ((2 * sigmax * sigmay) + C2)/((sigmax*sigmax) + (sigmay*sigmay) + C2);
|
||||
//Structure comparison
|
||||
/*Structure comparison*/
|
||||
C3 = C2 / 2;
|
||||
scomp = (sigmaxy + C3) / (sigmax * sigmay + C3);
|
||||
//Similarity measure
|
||||
/*Similarity measure*/
|
||||
|
||||
sum = lcomp * ccomp * scomp;
|
||||
return sum;
|
||||
|
@ -217,13 +218,13 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
|
|||
/* parse the command line */
|
||||
|
||||
while (1) {
|
||||
int c = getopt(argc, argv, "i:o:O:r:l:B:m:h");
|
||||
int c = opj_getopt(argc, argv, "i:o:O:r:l:B:m:h");
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'i': /* input file */
|
||||
{
|
||||
char *infile = optarg;
|
||||
char *infile = opj_optarg;
|
||||
parameters->decod_format = get_file_format(infile);
|
||||
switch(parameters->decod_format) {
|
||||
case J3D_CFMT:
|
||||
|
@ -242,7 +243,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
|
|||
|
||||
case 'm': /* img file */
|
||||
{
|
||||
char *imgfile = optarg;
|
||||
char *imgfile = opj_optarg;
|
||||
int imgformat = get_file_format(imgfile);
|
||||
switch(imgformat) {
|
||||
case IMG_DFMT:
|
||||
|
@ -261,7 +262,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
|
|||
|
||||
case 'o': /* output file */
|
||||
{
|
||||
char *outfile = optarg;
|
||||
char *outfile = opj_optarg;
|
||||
parameters->cod_format = get_file_format(outfile);
|
||||
switch(parameters->cod_format) {
|
||||
case PGX_DFMT:
|
||||
|
@ -282,7 +283,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
|
|||
|
||||
case 'O': /* Original image for PSNR computing */
|
||||
{
|
||||
char *original = optarg;
|
||||
char *original = opj_optarg;
|
||||
parameters->orig_format = get_file_format(original);
|
||||
switch(parameters->orig_format) {
|
||||
case PGX_DFMT:
|
||||
|
@ -302,9 +303,9 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
|
|||
|
||||
case 'r': /* reduce option */
|
||||
{
|
||||
//sscanf(optarg, "%d, %d, %d", ¶meters->cp_reduce[0], ¶meters->cp_reduce[1], ¶meters->cp_reduce[2]);
|
||||
/*sscanf(opj_optarg, "%d, %d, %d", ¶meters->cp_reduce[0], ¶meters->cp_reduce[1], ¶meters->cp_reduce[2]);*/
|
||||
int aux;
|
||||
aux = sscanf(optarg, "%d,%d,%d", ¶meters->cp_reduce[0], ¶meters->cp_reduce[1], ¶meters->cp_reduce[2]);
|
||||
aux = sscanf(opj_optarg, "%d,%d,%d", ¶meters->cp_reduce[0], ¶meters->cp_reduce[1], ¶meters->cp_reduce[2]);
|
||||
if (aux == 2)
|
||||
parameters->cp_reduce[2] = 0;
|
||||
else if (aux == 1) {
|
||||
|
@ -322,7 +323,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
|
|||
|
||||
case 'l': /* layering option */
|
||||
{
|
||||
sscanf(optarg, "%d", ¶meters->cp_layer);
|
||||
sscanf(opj_optarg, "%d", ¶meters->cp_layer);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -354,7 +355,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
|
|||
/* ----------------------------------------------------- */
|
||||
|
||||
default:
|
||||
fprintf(stdout,"[WARNING] This option is not valid \"-%c %s\"\n",c, optarg);
|
||||
fprintf(stdout,"[WARNING] This option is not valid \"-%c %s\"\n",c, opj_optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue