[trunk] Create a new static *_impl function to avoid a warning triggered by the depre...
[openjpeg.git] / src / lib / openjp2 / openjpeg.c
index 0ed7e67a1709c98f95e212963f25e9cd2f15411f..31199b2433bebd576ce98133604b9da7d7c136b1 100644 (file)
@@ -30,7 +30,6 @@
 #include <windows.h>
 #endif /* _WIN32 */
 
-#include "opj_config.h"
 #include "opj_includes.h"
 
 /**
@@ -851,10 +850,9 @@ OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream)
                opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
 
                if (! l_codec->is_decompressor) {
-                       l_codec->m_codec_data.m_compression.opj_encode( l_codec->m_codec,
+                       return l_codec->m_codec_data.m_compression.opj_encode(  l_codec->m_codec,
                                                                                                                        l_stream,
                                                                                                                        &(l_codec->m_event_mgr));
-                       return OPJ_TRUE;
                }
        }
 
@@ -1032,12 +1030,7 @@ void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
 }
 
 /* ---------------------------------------------------------------------- */
-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(p_file,OPJ_J2K_STREAM_CHUNK_SIZE,p_is_read_stream);
-}
-
-opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (     FILE * p_file, 
+static opj_stream_t* opj_stream_create_file_stream_impl (      FILE * p_file, 
                                                                                                                        OPJ_SIZE_T p_size, 
                                                                                                                        OPJ_BOOL p_is_read_stream)
 {
@@ -1052,12 +1045,66 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (      FILE * p_file,
                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);
+    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_BOOL p_is_read_stream)
+{
+    opj_stream_t* l_stream = 00;
+    FILE *p_file;
+    const char *mode;
+
+    if (! fname) {
+        return NULL;
+    }
+    
+    if(p_is_read_stream) mode = "rb"; else mode = "wb";
+
+    p_file = fopen(fname, mode);
+
+    if (! p_file) {
+           return NULL;
+    }
+
+    l_stream = opj_stream_create(p_size,p_is_read_stream);
+    if (! l_stream) {
+        fclose(p_file);
+        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;
+    return l_stream;
 }