[trunk] Create a new static *_impl function to avoid a warning triggered by the depre...
[openjpeg.git] / src / lib / openjp2 / openjpeg.c
index 20f3ca0e36a084ff8e7a57cb10803f69770fb840..31199b2433bebd576ce98133604b9da7d7c136b1 100644 (file)
@@ -1,5 +1,7 @@
 /*
  * Copyright (c) 2005, Herve Drolon, FreeImage Team
+ * Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France 
+ * Copyright (c) 2012, CS Systemes d'Information, France
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,7 +30,6 @@
 #include <windows.h>
 #endif /* _WIN32 */
 
-#include "opj_config.h"
 #include "opj_includes.h"
 
 /**
@@ -665,7 +666,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
                case OPJ_CODEC_J2K:
                        l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL (*) (void *,
                                                                                                                                                        struct opj_stream_private *,
-                                                                                                                                                       struct opj_event_mgr * )) opj_j2k_encode_v2;
+                                                                                                                                                       struct opj_event_mgr * )) opj_j2k_encode;
 
                        l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL (*) (  void *,
                                                                                                                                                                        struct opj_stream_private *,
@@ -849,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;
                }
        }
 
@@ -905,7 +905,7 @@ OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,
        OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size;
 
        /* add MCT capability */
-       int rsiz = (int)parameters->cp_rsiz | (int)OPJ_MCT;
+       OPJ_INT32 rsiz = (OPJ_INT32)parameters->cp_rsiz | (OPJ_INT32)OPJ_MCT;
        parameters->cp_rsiz = (OPJ_RSIZ_CAPABILITIES)rsiz;
        parameters->irreversible = 1;
 
@@ -1030,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)
 {
@@ -1050,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;
 }