summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Malaterre <mathieu.malaterre@gmail.com>2014-03-03 11:36:31 +0000
committerMathieu Malaterre <mathieu.malaterre@gmail.com>2014-03-03 11:36:31 +0000
commit25255c4ed1cb1974857189a2a5c67f878c923cc3 (patch)
treec174ee9190f9a9885ecf917c5c86639871d9c902
parent16febebd28aafe8a47472d669b399dded8f84c5e (diff)
[trunk] remove all api with invalid FILE* parameters which could leads to issues when applications are compiled with different flags from openjpeg.
Fixes issue 198
-rw-r--r--src/lib/openjp2/openjpeg.c38
-rw-r--r--src/lib/openjp2/openjpeg.h18
-rw-r--r--src/lib/openjpip/jp2k_decoder.c6
-rw-r--r--src/lib/openjpip/jp2k_decoder.h2
-rw-r--r--src/lib/openjpip/jpipstream_manager.c25
5 files changed, 23 insertions, 66 deletions
diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c
index 31199b24..957143f3 100644
--- a/src/lib/openjp2/openjpeg.c
+++ b/src/lib/openjp2/openjpeg.c
@@ -1029,49 +1029,11 @@ void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
}
}
-/* ---------------------------------------------------------------------- */
-static opj_stream_t* opj_stream_create_file_stream_impl ( FILE * p_file,
- OPJ_SIZE_T p_size,
- OPJ_BOOL p_is_read_stream)
-{
- opj_stream_t* l_stream = 00;
-
- if (! p_file) {
- return NULL;
- }
-
- l_stream = opj_stream_create(p_size,p_is_read_stream);
- if (! l_stream) {
- return NULL;
- }
-
- opj_stream_set_user_data(l_stream, p_file);
- opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
- opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
- opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
- opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
- opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
-
- return l_stream;
-}
-
-opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream)
-{
- return opj_stream_create_file_stream_impl(p_file,OPJ_J2K_STREAM_CHUNK_SIZE,p_is_read_stream);
-}
-
opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream)
{
return opj_stream_create_file_stream_v3(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream);
}
-opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream ( FILE * p_file,
- OPJ_SIZE_T p_size,
- OPJ_BOOL p_is_read_stream)
-{
- return opj_stream_create_file_stream_impl(p_file,p_size,p_is_read_stream);
-}
-
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (
const char *fname,
OPJ_SIZE_T p_size,
diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h
index 338a771d..8170f7a4 100644
--- a/src/lib/openjp2/openjpeg.h
+++ b/src/lib/openjp2/openjpeg.h
@@ -1061,30 +1061,12 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
/**
- * Helper function.
- * Sets the stream to be a file stream. The FILE must have been open previously.
- * @param p_file the file stream to operate on
- * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
-*/
-OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream));
-
-/**
* Create a stream from a file identified with its filename with default parameters (helper function)
* @param fname the filename of the file to stream
* @param p_is_read_stream whether the stream is a read stream (true) or not (false)
*/
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream);
-/**
- * FIXME DOC
- * @param p_file the file stream to operate on
- * @param p_buffer_size size of the chunk used to stream
- * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
-*/
-OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file,
- OPJ_SIZE_T p_buffer_size,
- OPJ_BOOL p_is_read_stream));
-
/** Create a stream from a file identified with its filename with a specific buffer size
* @param fname the filename of the file to stream
* @param p_buffer_size size of the chunk used to stream
diff --git a/src/lib/openjpip/jp2k_decoder.c b/src/lib/openjpip/jp2k_decoder.c
index 9bbfe00d..a1878adc 100644
--- a/src/lib/openjpip/jp2k_decoder.c
+++ b/src/lib/openjpip/jp2k_decoder.c
@@ -43,7 +43,7 @@ static void info_callback(const char *msg, void *client_data);
static Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox);
-Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox)
+Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox)
{
Byte_t *pnmstream = NULL;
opj_dparameters_t parameters; /* decompression parameters */
@@ -51,13 +51,11 @@ Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox)
opj_codec_t *l_codec = NULL; /* handle to a decompressor */
opj_stream_t *l_stream = NULL;
-
-
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* set a byte stream */
- l_stream = opj_stream_create_default_file_stream( fp, 1);
+ l_stream = opj_stream_create_default_file_stream_v3( fn, OPJ_TRUE);
if (!l_stream){
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
return NULL;
diff --git a/src/lib/openjpip/jp2k_decoder.h b/src/lib/openjpip/jp2k_decoder.h
index a53b1537..7fc8e961 100644
--- a/src/lib/openjpip/jp2k_decoder.h
+++ b/src/lib/openjpip/jp2k_decoder.h
@@ -34,6 +34,6 @@
#include "byte_manager.h"
#include "ihdrbox_manager.h"
-Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox);
+Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox);
#endif /* !JP2K_DECODER_H_ */
diff --git a/src/lib/openjpip/jpipstream_manager.c b/src/lib/openjpip/jpipstream_manager.c
index 3227af75..6649129c 100644
--- a/src/lib/openjpip/jpipstream_manager.c
+++ b/src/lib/openjpip/jpipstream_manager.c
@@ -76,19 +76,34 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
Byte_t *pnmstream;
Byte_t *j2kstream; /* j2k or jp2 codestream */
Byte8_t j2klen;
+ size_t retlen;
FILE *fp;
const char j2kfname[] = "tmp.j2k";
+ fp = fopen( j2kfname, "w+b");
+ if( !fp )
+ {
+ return NULL;
+ }
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
+ if( !j2kstream )
+ {
+ fclose(fp);
+ remove( j2kfname);
+ return NULL;
+ }
- fp = fopen( j2kfname, "w+b");
- fwrite( j2kstream, j2klen, 1, fp);
+ retlen = fwrite( j2kstream, 1, j2klen, fp);
opj_free( j2kstream);
- fseek( fp, 0, SEEK_SET);
+ fclose(fp);
+ if( retlen != j2klen )
+ {
+ remove( j2kfname);
+ return NULL;
+ }
- pnmstream = j2k_to_pnm( fp, ihdrbox);
+ pnmstream = j2k_to_pnm( j2kfname, ihdrbox);
- fclose( fp);
remove( j2kfname);
return pnmstream;