[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
This commit is contained in:
Mathieu Malaterre 2014-03-03 11:36:31 +00:00
parent 16febebd28
commit 25255c4ed1
5 changed files with 24 additions and 67 deletions

View File

@ -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) 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); 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 ( opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (
const char *fname, const char *fname,
OPJ_SIZE_T p_size, OPJ_SIZE_T p_size,

View File

@ -1060,14 +1060,6 @@ 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); 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) * 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 fname the filename of the file to stream
@ -1075,16 +1067,6 @@ OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file
*/ */
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream); 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 /** 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 fname the filename of the file to stream
* @param p_buffer_size size of the chunk used to stream * @param p_buffer_size size of the chunk used to stream

View File

@ -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); 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; Byte_t *pnmstream = NULL;
opj_dparameters_t parameters; /* decompression parameters */ 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_codec_t *l_codec = NULL; /* handle to a decompressor */
opj_stream_t *l_stream = NULL; opj_stream_t *l_stream = NULL;
/* set decoding parameters to default values */ /* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters); opj_set_default_decoder_parameters(&parameters);
/* set a byte stream */ /* 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){ if (!l_stream){
fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
return NULL; return NULL;

View File

@ -34,6 +34,6 @@
#include "byte_manager.h" #include "byte_manager.h"
#include "ihdrbox_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_ */ #endif /* !JP2K_DECODER_H_ */

View File

@ -76,19 +76,34 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
Byte_t *pnmstream; Byte_t *pnmstream;
Byte_t *j2kstream; /* j2k or jp2 codestream */ Byte_t *j2kstream; /* j2k or jp2 codestream */
Byte8_t j2klen; Byte8_t j2klen;
size_t retlen;
FILE *fp; FILE *fp;
const char j2kfname[] = "tmp.j2k"; const char j2kfname[] = "tmp.j2k";
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
fp = fopen( j2kfname, "w+b"); fp = fopen( j2kfname, "w+b");
fwrite( j2kstream, j2klen, 1, fp); if( !fp )
{
return NULL;
}
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
if( !j2kstream )
{
fclose(fp);
remove( j2kfname);
return NULL;
}
retlen = fwrite( j2kstream, 1, j2klen, fp);
opj_free( j2kstream); 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); remove( j2kfname);
return pnmstream; return pnmstream;