}
}
-/* ---------------------------------------------------------------------- */
-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,
*/
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
*/
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
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 */
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(¶meters);
/* 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;
#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_ */
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;