* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "opj_config.h"
+#include "opj_apps_config.h"
#include <stdio.h>
#include <string.h>
#include "convert.h"
#include "index.h"
-#ifdef HAVE_LIBLCMS2
+#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#endif
-#ifdef HAVE_LIBLCMS1
+#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
#endif
#include "color.h"
const char *s, *magic_s;
int ext_format, magic_format;
unsigned char buf[12];
- unsigned int l_nb_read;
+ OPJ_SIZE_T l_nb_read;
reader = fopen(fname, "rb");
case 'r': /* reduce option */
{
- sscanf(opj_optarg, "%d", ¶meters->cp_reduce);
+ sscanf(opj_optarg, "%ud", ¶meters->cp_reduce);
}
break;
case 'l': /* layering option */
{
- sscanf(opj_optarg, "%d", ¶meters->cp_layer);
+ sscanf(opj_optarg, "%ud", ¶meters->cp_layer);
}
break;
case 'd': /* Input decode ROI */
{
int size_optarg = (int)strlen(opj_optarg) + 1;
- char *ROI_values = (char*) malloc(size_optarg);
+ char *ROI_values = (char*) malloc((size_t)size_optarg);
ROI_values[0] = '\0';
strncpy(ROI_values, opj_optarg, strlen(opj_optarg));
ROI_values[strlen(opj_optarg)] = '\0';
case 't': /* Input tile index */
{
- sscanf(opj_optarg, "%d", ¶meters->tile_index);
+ sscanf(opj_optarg, "%ud", ¶meters->tile_index);
parameters->nb_tile_to_decode = 1;
}
break;
return EXIT_FAILURE;
}
else{
- *DA_x0 = values[0]; *DA_y0 = values[1];
- *DA_x1 = values[2]; *DA_y1 = values[3];
+ *DA_x0 = (OPJ_UINT32)values[0]; *DA_y0 = (OPJ_UINT32)values[1];
+ *DA_x1 = (OPJ_UINT32)values[2]; *DA_y1 = (OPJ_UINT32)values[3];
return EXIT_SUCCESS;
}
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
- FILE *fsrc = NULL;
opj_dparameters_t parameters; /* decompression parameters */
opj_image_t* image = NULL;
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){
- dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
- dirptr->filename = (char**) malloc(num_images*sizeof(char*));
+ dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
+ dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename_buf){
return EXIT_FAILURE;
/* read the input file and put it in memory */
/* ---------------------------------------- */
- fsrc = fopen(parameters.infile, "rb");
- if (!fsrc) {
- fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
- return EXIT_FAILURE;
- }
- l_stream = opj_stream_create_default_file_stream(fsrc,1);
+ l_stream = opj_stream_create_default_file_stream_v3(parameters.infile,1);
if (!l_stream){
- fclose(fsrc);
- fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
+ fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile);
return EXIT_FAILURE;
}
if ( !opj_setup_decoder(l_codec, ¶meters) ){
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
opj_stream_destroy_v3(l_stream);
- fclose(fsrc);
opj_destroy_codec(l_codec);
return EXIT_FAILURE;
}
if(! opj_read_header(l_stream, l_codec, &image)){
fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
opj_stream_destroy_v3(l_stream);
- fclose(fsrc);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return EXIT_FAILURE;
if (!parameters.nb_tile_to_decode) {
/* Optional if you want decode the entire image */
- if (!opj_set_decode_area(l_codec, image, parameters.DA_x0,
- parameters.DA_y0, parameters.DA_x1, parameters.DA_y1)){
+ if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0,
+ (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)){
fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n");
opj_stream_destroy_v3(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
- fclose(fsrc);
return EXIT_FAILURE;
}
opj_destroy_codec(l_codec);
opj_stream_destroy_v3(l_stream);
opj_image_destroy(image);
- fclose(fsrc);
return EXIT_FAILURE;
}
}
opj_destroy_codec(l_codec);
opj_stream_destroy_v3(l_stream);
opj_image_destroy(image);
- fclose(fsrc);
return EXIT_FAILURE;
}*/
opj_destroy_codec(l_codec);
opj_stream_destroy_v3(l_stream);
opj_image_destroy(image);
- fclose(fsrc);
return EXIT_FAILURE;
}
fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index);
/* Close the byte stream */
opj_stream_destroy_v3(l_stream);
- fclose(fsrc);
if(image->color_space == OPJ_CLRSPC_SYCC){
color_sycc_to_rgb(image); /* FIXME */
}
+
+ if( image->color_space != OPJ_CLRSPC_SYCC
+ && image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy
+ && image->comps[1].dx != 1 )
+ image->color_space = OPJ_CLRSPC_SYCC;
+ else if (image->numcomps <= 2)
+ image->color_space = OPJ_CLRSPC_GRAY;
if(image->icc_profile_buf) {
-#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
+#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(image); /* FIXME */
#endif
free(image->icc_profile_buf);
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
-#ifdef HAVE_LIBTIFF
+#ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
-#endif /* HAVE_LIBTIFF */
+#endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)){
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
-#ifdef HAVE_LIBPNG
+#ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
-#endif /* HAVE_LIBPNG */
+#endif /* OPJ_HAVE_LIBPNG */
/* Can happen if output file is TIFF or PNG
- * and HAVE_LIBTIF or HAVE_LIBPNG is undefined
+ * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
default:
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);