Finish fixing up bugs with png i/o

This commit is contained in:
Mathieu Malaterre 2010-06-22 19:27:35 +00:00
parent 3a44c91ea3
commit f71e6e7879
3 changed files with 27 additions and 5 deletions

View File

@ -81,7 +81,7 @@ foreach(filename ${OPENJPEG_DATA_IMAGES_GLOB})
#message( "found:${output_variable} for ${filename_temp}" )
endif()
ADD_TEST(dump-${filename_temp} ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename})
foreach(codec_type ppm pgx bmp tif raw tga)
foreach(codec_type ppm pgx bmp tif raw tga png)
ADD_TEST(j2i-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image -i ${filename} -o ${filename_temp}.${codec_type})
ADD_TEST(i2j-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/image_to_j2k -i ${filename_temp}.${codec_type} -o ${filename_temp}.${codec_type}${filename_ext})
#if(UNIX)

View File

@ -1713,6 +1713,14 @@ int main(int argc, char **argv) {
return 1;
}
break;
case PNG_DFMT:
image = pngtoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, "Unable to load png file\n");
return 1;
}
break;
}
/* Decide if MCT should be used */
parameters.tcp_mct = image->numcomps == 3 ? 1 : 0;

View File

@ -31,7 +31,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#define __USE_BSD
#include <string.h>
#include <stdlib.h>
#include <math.h>
@ -43,6 +42,7 @@
#include "index.h"
#ifndef WIN32
#include <strings.h>
#define _stricmp strcasecmp
#define _strnicmp strncasecmp
#endif
@ -60,7 +60,7 @@
#define TIF_DFMT 14
#define RAW_DFMT 15
#define TGA_DFMT 16
#define PNG_DFMT 17
/* ----------------------------------------------------------------------- */
typedef struct dircnt{
@ -190,8 +190,8 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
char * ext = strrchr(filename, '.');
if (ext == NULL)
return -1;
@ -288,6 +288,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
case TIF_DFMT:
case RAW_DFMT:
case TGA_DFMT:
case PNG_DFMT:
break;
default:
fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outfile);
@ -325,6 +326,9 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
case TGA_DFMT:
img_fol->out_format = "raw";
break;
case PNG_DFMT:
img_fol->out_format = "png";
break;
default:
fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outformat);
return 1;
@ -735,6 +739,16 @@ int main(int argc, char **argv)
ret = EXIT_SUCCESS;
}
break;
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
}
/* free remaining structures */