Fix various compiler warnings
This commit is contained in:
parent
7e4e09a7fb
commit
f0629cb1c4
|
@ -1384,7 +1384,7 @@ int imagetopgx(opj_image_t * image, const char *outfile)
|
||||||
goto fin;
|
goto fin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strncpy(name, outfile, dotpos);
|
memcpy(name, outfile, dotpos);
|
||||||
sprintf(name + dotpos, "_%u.pgx", compno);
|
sprintf(name + dotpos, "_%u.pgx", compno);
|
||||||
fdest = fopen(name, "wb");
|
fdest = fopen(name, "wb");
|
||||||
/* don't need name anymore */
|
/* don't need name anymore */
|
||||||
|
@ -2228,7 +2228,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split)
|
||||||
const size_t olen = strlen(outfile);
|
const size_t olen = strlen(outfile);
|
||||||
const size_t dotpos = olen - 4;
|
const size_t dotpos = olen - 4;
|
||||||
|
|
||||||
strncpy(destname, outfile, dotpos);
|
memcpy(destname, outfile, dotpos);
|
||||||
sprintf(destname + dotpos, "_%u.pgm", compno);
|
sprintf(destname + dotpos, "_%u.pgm", compno);
|
||||||
} else {
|
} else {
|
||||||
sprintf(destname, "%s", outfile);
|
sprintf(destname, "%s", outfile);
|
||||||
|
|
|
@ -65,49 +65,36 @@ static void convert_16u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
|
static opj_image_t * pngtoimage_internal(opj_cparameters_t * params,
|
||||||
|
FILE *reader,
|
||||||
|
png_structp png,
|
||||||
|
png_infop info,
|
||||||
|
png_uint_32* pheight,
|
||||||
|
OPJ_BYTE*** prows,
|
||||||
|
OPJ_INT32** prow32s)
|
||||||
{
|
{
|
||||||
png_structp png = NULL;
|
*pheight = 0;
|
||||||
png_infop info = NULL;
|
*prows = NULL;
|
||||||
|
*prow32s = NULL;
|
||||||
|
|
||||||
|
if (setjmp(png_jmpbuf(png))) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
opj_image_t *image = NULL;
|
||||||
|
opj_image_cmptparm_t cmptparm[4];
|
||||||
|
OPJ_UINT32 nr_comp;
|
||||||
|
convert_XXx32s_C1R cvtXXTo32s = NULL;
|
||||||
|
convert_32s_CXPX cvtCxToPx = NULL;
|
||||||
|
OPJ_INT32* planes[4];
|
||||||
double gamma;
|
double gamma;
|
||||||
int bit_depth, interlace_type, compression_type, filter_type;
|
int bit_depth, interlace_type, compression_type, filter_type;
|
||||||
OPJ_UINT32 i;
|
OPJ_UINT32 i;
|
||||||
png_uint_32 width, height = 0U;
|
png_uint_32 width, height = 0U;
|
||||||
int color_type;
|
int color_type;
|
||||||
FILE *reader = NULL;
|
|
||||||
OPJ_BYTE** rows = NULL;
|
OPJ_BYTE** rows = NULL;
|
||||||
OPJ_INT32* row32s = NULL;
|
OPJ_INT32* row32s = NULL;
|
||||||
/* j2k: */
|
|
||||||
opj_image_t *image = NULL;
|
|
||||||
opj_image_cmptparm_t cmptparm[4];
|
|
||||||
OPJ_UINT32 nr_comp;
|
|
||||||
OPJ_BYTE sigbuf[8];
|
|
||||||
convert_XXx32s_C1R cvtXXTo32s = NULL;
|
|
||||||
convert_32s_CXPX cvtCxToPx = NULL;
|
|
||||||
OPJ_INT32* planes[4];
|
|
||||||
|
|
||||||
if ((reader = fopen(read_idf, "rb")) == NULL) {
|
|
||||||
fprintf(stderr, "pngtoimage: can not open %s\n", read_idf);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|
|
||||||
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) {
|
|
||||||
fprintf(stderr, "pngtoimage: %s is no valid PNG file\n", read_idf);
|
|
||||||
goto fin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
|
||||||
NULL, NULL, NULL)) == NULL) {
|
|
||||||
goto fin;
|
|
||||||
}
|
|
||||||
if ((info = png_create_info_struct(png)) == NULL) {
|
|
||||||
goto fin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setjmp(png_jmpbuf(png))) {
|
|
||||||
goto fin;
|
|
||||||
}
|
|
||||||
|
|
||||||
png_init_io(png, reader);
|
png_init_io(png, reader);
|
||||||
png_set_sig_bytes(png, MAGIC_SIZE);
|
png_set_sig_bytes(png, MAGIC_SIZE);
|
||||||
|
@ -117,8 +104,9 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
|
||||||
if (png_get_IHDR(png, info, &width, &height,
|
if (png_get_IHDR(png, info, &width, &height,
|
||||||
&bit_depth, &color_type, &interlace_type,
|
&bit_depth, &color_type, &interlace_type,
|
||||||
&compression_type, &filter_type) == 0) {
|
&compression_type, &filter_type) == 0) {
|
||||||
goto fin;
|
return image;
|
||||||
}
|
}
|
||||||
|
*pheight = height;
|
||||||
|
|
||||||
/* png_set_expand():
|
/* png_set_expand():
|
||||||
* expand paletted images to RGB, expand grayscale images of
|
* expand paletted images to RGB, expand grayscale images of
|
||||||
|
@ -167,7 +155,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "pngtoimage: colortype %d is not supported\n", color_type);
|
fprintf(stderr, "pngtoimage: colortype %d is not supported\n", color_type);
|
||||||
goto fin;
|
return image;
|
||||||
}
|
}
|
||||||
cvtCxToPx = convert_32s_CXPX_LUT[nr_comp];
|
cvtCxToPx = convert_32s_CXPX_LUT[nr_comp];
|
||||||
bit_depth = png_get_bit_depth(png, info);
|
bit_depth = png_get_bit_depth(png, info);
|
||||||
|
@ -184,20 +172,20 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "pngtoimage: bit depth %d is not supported\n", bit_depth);
|
fprintf(stderr, "pngtoimage: bit depth %d is not supported\n", bit_depth);
|
||||||
goto fin;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rows = (OPJ_BYTE**)calloc(height + 1, sizeof(OPJ_BYTE*));
|
rows = (OPJ_BYTE**)calloc(height + 1, sizeof(OPJ_BYTE*));
|
||||||
if (rows == NULL) {
|
if (rows == NULL) {
|
||||||
fprintf(stderr, "pngtoimage: memory out\n");
|
fprintf(stderr, "pngtoimage: memory out\n");
|
||||||
goto fin;
|
return image;
|
||||||
}
|
}
|
||||||
|
*prows = rows;
|
||||||
for (i = 0; i < height; ++i) {
|
for (i = 0; i < height; ++i) {
|
||||||
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png, info));
|
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png, info));
|
||||||
if (rows[i] == NULL) {
|
if (rows[i] == NULL) {
|
||||||
fprintf(stderr, "pngtoimage: memory out\n");
|
fprintf(stderr, "pngtoimage: memory out\n");
|
||||||
goto fin;
|
return image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
png_read_image(png, rows);
|
png_read_image(png, rows);
|
||||||
|
@ -218,7 +206,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
|
||||||
image = opj_image_create(nr_comp, &cmptparm[0],
|
image = opj_image_create(nr_comp, &cmptparm[0],
|
||||||
(nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY);
|
(nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY);
|
||||||
if (image == NULL) {
|
if (image == NULL) {
|
||||||
goto fin;
|
return image;
|
||||||
}
|
}
|
||||||
image->x0 = (OPJ_UINT32)params->image_offset_x0;
|
image->x0 = (OPJ_UINT32)params->image_offset_x0;
|
||||||
image->y0 = (OPJ_UINT32)params->image_offset_y0;
|
image->y0 = (OPJ_UINT32)params->image_offset_y0;
|
||||||
|
@ -229,8 +217,9 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
|
||||||
|
|
||||||
row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32));
|
row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32));
|
||||||
if (row32s == NULL) {
|
if (row32s == NULL) {
|
||||||
goto fin;
|
return image;
|
||||||
}
|
}
|
||||||
|
*prow32s = row32s;
|
||||||
|
|
||||||
/* Set alpha channel */
|
/* Set alpha channel */
|
||||||
image->comps[nr_comp - 1U].alpha = 1U - (nr_comp & 1U);
|
image->comps[nr_comp - 1U].alpha = 1U - (nr_comp & 1U);
|
||||||
|
@ -247,6 +236,43 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
|
||||||
planes[2] += width;
|
planes[2] += width;
|
||||||
planes[3] += width;
|
planes[3] += width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
|
||||||
|
{
|
||||||
|
png_structp png = NULL;
|
||||||
|
png_infop info = NULL;
|
||||||
|
OPJ_UINT32 i;
|
||||||
|
png_uint_32 height = 0U;
|
||||||
|
FILE *reader = NULL;
|
||||||
|
OPJ_BYTE** rows = NULL;
|
||||||
|
OPJ_INT32* row32s = NULL;
|
||||||
|
OPJ_BYTE sigbuf[8];
|
||||||
|
opj_image_t *image = NULL;
|
||||||
|
|
||||||
|
if ((reader = fopen(read_idf, "rb")) == NULL) {
|
||||||
|
fprintf(stderr, "pngtoimage: can not open %s\n", read_idf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|
||||||
|
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) {
|
||||||
|
fprintf(stderr, "pngtoimage: %s is no valid PNG file\n", read_idf);
|
||||||
|
goto fin;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||||
|
NULL, NULL, NULL)) == NULL) {
|
||||||
|
goto fin;
|
||||||
|
}
|
||||||
|
if ((info = png_create_info_struct(png)) == NULL) {
|
||||||
|
goto fin;
|
||||||
|
}
|
||||||
|
|
||||||
|
image = pngtoimage_internal(params, reader, png, info, &height, &rows, &row32s);
|
||||||
fin:
|
fin:
|
||||||
if (rows) {
|
if (rows) {
|
||||||
for (i = 0; i < height; ++i)
|
for (i = 0; i < height; ++i)
|
||||||
|
|
|
@ -553,7 +553,13 @@ static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
|
||||||
if (parameters->decod_format == -1) {
|
if (parameters->decod_format == -1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
sprintf(infilename, "%s/%s", img_fol->imgdirpath, image_filename);
|
if (strlen(img_fol->imgdirpath) + 1 + strlen(image_filename) + 1 > sizeof(
|
||||||
|
infilename)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strcpy(infilename, img_fol->imgdirpath);
|
||||||
|
strcat(infilename, "/");
|
||||||
|
strcat(infilename, image_filename);
|
||||||
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile),
|
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile),
|
||||||
infilename) != 0) {
|
infilename) != 0) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -566,8 +572,15 @@ static char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
|
||||||
sprintf(temp1, ".%s", temp_p);
|
sprintf(temp1, ".%s", temp_p);
|
||||||
}
|
}
|
||||||
if (img_fol->set_out_format == 1) {
|
if (img_fol->set_out_format == 1) {
|
||||||
sprintf(outfilename, "%s/%s.%s", img_fol->imgdirpath, temp_ofname,
|
if (strlen(img_fol->imgdirpath) + 1 + strlen(temp_ofname) + 1 + strlen(
|
||||||
img_fol->out_format);
|
img_fol->out_format) + 1 > sizeof(outfilename)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strcpy(outfilename, img_fol->imgdirpath);
|
||||||
|
strcat(outfilename, "/");
|
||||||
|
strcat(outfilename, temp_ofname);
|
||||||
|
strcat(outfilename, ".");
|
||||||
|
strcat(outfilename, img_fol->out_format);
|
||||||
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile),
|
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile),
|
||||||
outfilename) != 0) {
|
outfilename) != 0) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -958,9 +971,10 @@ static int parse_cmdline_encoder(int argc, char **argv,
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
|
|
||||||
case 'p': { /* progression order */
|
case 'p': { /* progression order */
|
||||||
char progression[4];
|
char progression[5];
|
||||||
|
|
||||||
strncpy(progression, opj_optarg, 4);
|
strncpy(progression, opj_optarg, 4);
|
||||||
|
progression[4] = 0;
|
||||||
parameters->prog_order = give_progression(progression);
|
parameters->prog_order = give_progression(progression);
|
||||||
if (parameters->prog_order == -1) {
|
if (parameters->prog_order == -1) {
|
||||||
fprintf(stderr, "Unrecognized progression order "
|
fprintf(stderr, "Unrecognized progression order "
|
||||||
|
|
|
@ -461,8 +461,13 @@ char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
|
||||||
|
|
||||||
strcpy(image_filename, dirptr->filename[imageno]);
|
strcpy(image_filename, dirptr->filename[imageno]);
|
||||||
fprintf(stderr, "File Number %d \"%s\"\n", imageno, image_filename);
|
fprintf(stderr, "File Number %d \"%s\"\n", imageno, image_filename);
|
||||||
sprintf(infilename, "%s%s%s", img_fol->imgdirpath, path_separator,
|
if (strlen(img_fol->imgdirpath) + strlen(path_separator) + strlen(
|
||||||
image_filename);
|
image_filename) + 1 > sizeof(infilename)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strcpy(infilename, img_fol->imgdirpath);
|
||||||
|
strcat(infilename, path_separator);
|
||||||
|
strcat(infilename, image_filename);
|
||||||
parameters->decod_format = infile_format(infilename);
|
parameters->decod_format = infile_format(infilename);
|
||||||
if (parameters->decod_format == -1) {
|
if (parameters->decod_format == -1) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -479,8 +484,15 @@ char get_next_file(int imageno, dircnt_t *dirptr, img_fol_t *img_fol,
|
||||||
sprintf(temp1, ".%s", temp_p);
|
sprintf(temp1, ".%s", temp_p);
|
||||||
}
|
}
|
||||||
if (img_fol->set_out_format == 1) {
|
if (img_fol->set_out_format == 1) {
|
||||||
sprintf(outfilename, "%s/%s.%s", img_fol->imgdirpath, temp_ofname,
|
if (strlen(img_fol->imgdirpath) + 1 + strlen(temp_ofname) + 1 + strlen(
|
||||||
img_fol->out_format);
|
img_fol->out_format) + 1 > sizeof(outfilename)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strcpy(outfilename, img_fol->imgdirpath);
|
||||||
|
strcat(outfilename, "/");
|
||||||
|
strcat(outfilename, temp_ofname);
|
||||||
|
strcat(outfilename, ".");
|
||||||
|
strcat(outfilename, img_fol->out_format);
|
||||||
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile),
|
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile),
|
||||||
outfilename) != 0) {
|
outfilename) != 0) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -142,9 +142,9 @@ static char* createMultiComponentsFilename(const char* inFilename,
|
||||||
return outFilename;
|
return outFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
outFilename = (char*)malloc((posToken + 7) * sizeof(char)); /*6*/
|
outFilename = (char*)malloc(posToken + 32);
|
||||||
|
|
||||||
strncpy(outFilename, inFilename, posToken);
|
memcpy(outFilename, inFilename, posToken);
|
||||||
outFilename[posToken] = '\0';
|
outFilename[posToken] = '\0';
|
||||||
strcat(outFilename, separator);
|
strcat(outFilename, separator);
|
||||||
sprintf(s, "%i", indexF);
|
sprintf(s, "%i", indexF);
|
||||||
|
|
Loading…
Reference in New Issue