summaryrefslogtreecommitdiff
path: root/libopenjpeg/openjpeg.c
blob: df058630d605e7351a8be6a310d723b276f369e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
/*
 * Copyright (c) 2005, Herve Drolon, FreeImage Team
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef _WIN32
#include <windows.h>
#endif /* _WIN32 */

#include "opj_config.h"
#include "opj_includes.h"


/**
 * Decompression handler.
 */
typedef struct opj_decompression
{
	/** Main header reading function handler*/
	opj_bool (*opj_read_header) (	struct opj_stream_private * cio,
									void * p_codec,
									opj_image_t **p_image,
									struct opj_event_mgr * p_manager);
	/** Decoding function */
	opj_bool (*opj_decode) (	void * p_codec,
								struct opj_stream_private *p_cio,
								opj_image_t *p_image,
								struct opj_event_mgr * p_manager);
	/** FIXME DOC */
	opj_bool (*opj_read_tile_header)(	void * p_codec,
										OPJ_UINT32 * p_tile_index,
										OPJ_UINT32* p_data_size,
										OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
										OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
										OPJ_UINT32 * p_nb_comps,
										opj_bool * p_should_go_on,
										struct opj_stream_private *p_cio,
										struct opj_event_mgr * p_manager);
	/** FIXME DOC */
	opj_bool (*opj_decode_tile_data)(	void * p_codec,
										OPJ_UINT32 p_tile_index,
										OPJ_BYTE * p_data,
										OPJ_UINT32 p_data_size,
										struct opj_stream_private *p_cio,
										struct opj_event_mgr * p_manager);
	/** Reading function used after codestream if necessary */
	opj_bool (* opj_end_decompress) (	void *p_codec,
										struct opj_stream_private *cio,
										struct opj_event_mgr * p_manager);
	/** Codec destroy function handler*/
	void (*opj_destroy) (void * p_codec);
	/** Setup decoder function handler */
	void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
	/** Set decode area function handler */
	opj_bool (*opj_set_decode_area) (	void * p_codec,
										opj_image_t* p_image,
										OPJ_INT32 p_start_x, OPJ_INT32 p_end_x,
										OPJ_INT32 p_start_y, OPJ_INT32 p_end_y,
										struct opj_event_mgr * p_manager);

	/** Get tile function */
	opj_bool (*opj_get_decoded_tile) (	void *p_codec,
										opj_stream_private_t *p_cio,
										opj_image_t *p_image,
										struct opj_event_mgr * p_manager,
										OPJ_UINT32 tile_index);

	/** Set the decoded resolution factor */
	opj_bool (*opj_set_decoded_resolution_factor) ( void * p_codec, 
                                                    OPJ_UINT32 res_factor, 
                                                    opj_event_mgr_t * p_manager);

}opj_decompression_t;

/**
 * Compression handler. FIXME DOC
 */
typedef struct opj_compression
{
	opj_bool (* opj_start_compress) (	void *p_codec,
										struct opj_stream_private *cio,
										struct opj_image * p_image,
										struct opj_event_mgr * p_manager);

	opj_bool (* opj_encode) (	void * p_codec,
								struct opj_stream_private *p_cio,
								struct opj_event_mgr * p_manager);

	opj_bool (* opj_write_tile) (	void * p_codec,
									OPJ_UINT32 p_tile_index,
									OPJ_BYTE * p_data,
									OPJ_UINT32 p_data_size,
									struct opj_stream_private * p_cio,
									struct opj_event_mgr * p_manager);

	opj_bool (* opj_end_compress) (	void * p_codec,
									struct opj_stream_private *p_cio,
									struct opj_event_mgr * p_manager);

	void (* opj_destroy) (void * p_codec);

	void (*opj_setup_encoder) (	void * p_codec,
								opj_cparameters_t * p_param,
								struct opj_image * p_image,
								struct opj_event_mgr * p_manager);

}opj_compression_t;

/**
 * Main codec handler used for compression or decompression.
 */
typedef struct opj_codec_private
{
	/** FIXME DOC */
	union 
    {
        opj_decompression_t m_decompression;
        opj_compression_t m_compression;
    } m_codec_data;
    /** FIXME DOC*/
	void * m_codec;
	/** Event handler */
	opj_event_mgr_t m_event_mgr;
	/** Flag to indicate if the codec is used to decode or encode*/
	opj_bool is_decompressor;
	void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
	opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
	opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
}
opj_codec_private_t;

/* ---------------------------------------------------------------------- */
/* Functions to set info_handler */

opj_bool OPJ_CALLCONV opj_set_info_handler(	opj_codec_t * p_codec, 
											opj_msg_callback p_callback,
											void * p_user_data)
{
	opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
	if(! l_codec){
		return OPJ_FALSE;
	}
	
	l_codec->m_event_mgr.info_handler = p_callback;
	l_codec->m_event_mgr.m_info_data = p_user_data;
	
	return OPJ_TRUE;
}

opj_bool OPJ_CALLCONV opj_set_warning_handler(	opj_codec_t * p_codec, 
												opj_msg_callback p_callback,
												void * p_user_data)
{
	opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
	if (! l_codec) {
		return OPJ_FALSE;
	}
	
	l_codec->m_event_mgr.warning_handler = p_callback;
	l_codec->m_event_mgr.m_warning_data = p_user_data;
	
	return OPJ_TRUE;
}

opj_bool OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, 
											opj_msg_callback p_callback,
											void * p_user_data)
{
	opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
	if (! l_codec) {
		return OPJ_FALSE;
	}
	
	l_codec->m_event_mgr.error_handler = p_callback;
	l_codec->m_event_mgr.m_error_data = p_user_data;
	
	return OPJ_TRUE;
}

/* ---------------------------------------------------------------------- */


OPJ_SIZE_T opj_read_from_file (void * p_buffer, OPJ_SIZE_T p_nb_bytes, FILE * p_file)
{
	OPJ_SIZE_T l_nb_read = fread(p_buffer,1,p_nb_bytes,p_file);
	return l_nb_read ? l_nb_read : -1;
}

OPJ_UINT64 opj_get_data_length_from_file (FILE * p_file)
{
	OPJ_OFF_T file_length = 0;

	OPJ_FSEEK(p_file, 0, SEEK_END);
	file_length = (OPJ_UINT64)OPJ_FTELL(p_file);
	OPJ_FSEEK(p_file, 0, SEEK_SET);

	return file_length;
}

OPJ_SIZE_T opj_write_from_file (void * p_buffer, OPJ_SIZE_T p_nb_bytes, FILE * p_file)
{
	return fwrite(p_buffer,1,p_nb_bytes,p_file);
}

OPJ_OFF_T opj_skip_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
{
	if (OPJ_FSEEK(p_user_data,p_nb_bytes,SEEK_CUR)) {
		return -1;
	}

	return p_nb_bytes;
}

opj_bool opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
{
	if (OPJ_FSEEK(p_user_data,p_nb_bytes,SEEK_SET)) {
		return OPJ_FALSE;
	}

	return OPJ_TRUE;
}

/* ---------------------------------------------------------------------- */
#ifdef _WIN32
#ifndef OPJ_STATIC
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {

	OPJ_ARG_NOT_USED(lpReserved);
	OPJ_ARG_NOT_USED(hModule);

	switch (ul_reason_for_call) {
		case DLL_PROCESS_ATTACH :
			break;
		case DLL_PROCESS_DETACH :
			break;
		case DLL_THREAD_ATTACH :
		case DLL_THREAD_DETACH :
			break;
    }

    return TRUE;
}
#endif /* OPJ_STATIC */
#endif /* _WIN32 */

/* ---------------------------------------------------------------------- */


const char* OPJ_CALLCONV opj_version(void) {
    return PACKAGE_VERSION;
}

/* ---------------------------------------------------------------------- */
/* DECOMPRESSION FUNCTIONS*/

opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
{
	opj_codec_private_t *l_codec = 00;

	l_codec = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
	if (!l_codec){
		return 00;
	}
	memset(l_codec, 0, sizeof(opj_codec_private_t));

	l_codec->is_decompressor = 1;

	switch (p_format) {
		case CODEC_J2K:
			l_codec->opj_dump_codec = (void (*) (void*, OPJ_INT32, FILE*)) j2k_dump;

			l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) j2k_get_cstr_info;

			l_codec->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) j2k_get_cstr_index;

			l_codec->m_codec_data.m_decompression.opj_decode =
					(opj_bool (*) (	void *,
									struct opj_stream_private *,
									opj_image_t*, struct opj_event_mgr * )) opj_j2k_decode;

			l_codec->m_codec_data.m_decompression.opj_end_decompress =
					(opj_bool (*) (	void *,
									struct opj_stream_private *,
									struct opj_event_mgr *)) opj_j2k_end_decompress;

			l_codec->m_codec_data.m_decompression.opj_read_header =
					(opj_bool (*) (	struct opj_stream_private *,
									void *,
									opj_image_t **,
									struct opj_event_mgr * )) opj_j2k_read_header;

			l_codec->m_codec_data.m_decompression.opj_destroy =
					(void (*) (void *))opj_j2k_destroy;

			l_codec->m_codec_data.m_decompression.opj_setup_decoder =
					(void (*) (void * , opj_dparameters_t * )) opj_j2k_setup_decoder;

			l_codec->m_codec_data.m_decompression.opj_read_tile_header =
					(opj_bool (*) (	void *,
									OPJ_UINT32*,
									OPJ_UINT32*,
									OPJ_INT32*, OPJ_INT32*,
									OPJ_INT32*, OPJ_INT32*,
									OPJ_UINT32*,
									opj_bool*,
									struct opj_stream_private *,
									struct opj_event_mgr * )) opj_j2k_read_tile_header;

			l_codec->m_codec_data.m_decompression.opj_decode_tile_data =
					(opj_bool (*) ( void *, 
                                    OPJ_UINT32, 
                                    OPJ_BYTE*, 
                                    OPJ_UINT32, 
                                    struct opj_stream_private *,
                                    struct opj_event_mgr *)) opj_j2k_decode_tile;

			l_codec->m_codec_data.m_decompression.opj_set_decode_area =
					(opj_bool (*) ( void *, 
                                    opj_image_t*, 
                                    OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, 
                                    struct opj_event_mgr *)) opj_j2k_set_decode_area;

			l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = 
                    (opj_bool (*) ( void *p_codec,
								    opj_stream_private_t *p_cio,
								    opj_image_t *p_image,
								    struct opj_event_mgr * p_manager,
								    OPJ_UINT32 tile_index)) opj_j2k_get_tile;

			l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = 
                    (opj_bool (*) ( void * p_codec,
									OPJ_UINT32 res_factor,
									struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_resolution_factor;

			l_codec->m_codec = opj_j2k_create_decompress();

			if (! l_codec->m_codec) {
				opj_free(l_codec);
				return NULL;
			}

			break;

		case CODEC_JP2:
			/* get a JP2 decoder handle */
			l_codec->opj_dump_codec = (void (*) (void*, OPJ_INT32, FILE*)) jp2_dump;

			l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) jp2_get_cstr_info;

			l_codec->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) jp2_get_cstr_index;

			l_codec->m_codec_data.m_decompression.opj_decode =
					(opj_bool (*) (	void *,
									struct opj_stream_private *,
									opj_image_t*,
									struct opj_event_mgr * )) opj_jp2_decode;

			l_codec->m_codec_data.m_decompression.opj_end_decompress =  
                    (opj_bool (*) ( void *,
                                    struct opj_stream_private *,
                                    struct opj_event_mgr *)) opj_jp2_end_decompress;

			l_codec->m_codec_data.m_decompression.opj_read_header =  
                    (opj_bool (*) ( struct opj_stream_private *,
					                void *,
					                opj_image_t **,
					                struct opj_event_mgr * )) opj_jp2_read_header;

			l_codec->m_codec_data.m_decompression.opj_read_tile_header = 
                    (opj_bool (*) ( void *,
					                OPJ_UINT32*,
					                OPJ_UINT32*,
					                OPJ_INT32*,
					                OPJ_INT32*,
					                OPJ_INT32 * ,
					                OPJ_INT32 * ,
					                OPJ_UINT32 * ,
					                opj_bool *,
					                struct opj_stream_private *,
					                struct opj_event_mgr * )) opj_jp2_read_tile_header;

			l_codec->m_codec_data.m_decompression.opj_decode_tile_data = 
                    (opj_bool (*) ( void *,
                                    OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,
                                    struct opj_stream_private *,
                                    struct opj_event_mgr * )) opj_jp2_decode_tile;

			l_codec->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))opj_jp2_destroy;

			l_codec->m_codec_data.m_decompression.opj_setup_decoder = 
                    (void (*) (void * ,opj_dparameters_t * )) opj_jp2_setup_decoder;

			l_codec->m_codec_data.m_decompression.opj_set_decode_area = 
                    (opj_bool (*) ( void *,
                                    opj_image_t*, 
                                    OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32,
                                    struct opj_event_mgr * )) opj_jp2_set_decode_area;

			l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = 
                    (opj_bool (*) ( void *p_codec,
									opj_stream_private_t *p_cio,
									opj_image_t *p_image,
									struct opj_event_mgr * p_manager,
									OPJ_UINT32 tile_index)) opj_jp2_get_tile;

			l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = 
                    (opj_bool (*) ( void * p_codec,
						    		OPJ_UINT32 res_factor,
							    	opj_event_mgr_t * p_manager)) opj_jp2_set_decoded_resolution_factor;

			l_codec->m_codec = opj_jp2_create(OPJ_TRUE);

			if (! l_codec->m_codec) {
				opj_free(l_codec);
				return 00;
			}

			break;
		case CODEC_UNKNOWN:
		case CODEC_JPT:
		default:
			opj_free(l_codec);
			return 00;
	}

	opj_set_default_event_handler(&(l_codec->m_event_mgr));
	return (opj_codec_t*) l_codec;
}

void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
	if(parameters) {
		memset(parameters, 0, sizeof(opj_dparameters_t));
		/* default decoding parameters */
		parameters->cp_layer = 0;
		parameters->cp_reduce = 0;
		parameters->cp_limit_decoding = NO_LIMITATION;

		parameters->decod_format = -1;
		parameters->cod_format = -1;
		parameters->flags = 0;		
/* UniPG>> */
#ifdef USE_JPWL
		parameters->jpwl_correct = OPJ_FALSE;
		parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
		parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
#endif /* USE_JPWL */
/* <<UniPG */
	}
}

opj_bool OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
                                        opj_dparameters_t *parameters 
										)
{
	if (p_codec && parameters) { 
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;

		if (! l_codec->is_decompressor) {
			opj_event_msg_v2(&(l_codec->m_event_mgr), EVT_ERROR, 
                "Codec provided to the opj_setup_decoder function is not a decompressor handler.\n");
			return OPJ_FALSE;
		}

		l_codec->m_codec_data.m_decompression.opj_setup_decoder(l_codec->m_codec,
																parameters);
		return OPJ_TRUE;
	}
	return OPJ_FALSE;
}

opj_bool OPJ_CALLCONV opj_read_header (	opj_stream_t *p_stream,
										opj_codec_t *p_codec,
										opj_image_t **p_image )
{
	if (p_codec && p_stream) {
		opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
		opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;

		if(! l_codec->is_decompressor) {
			opj_event_msg_v2(&(l_codec->m_event_mgr), EVT_ERROR, 
                "Codec provided to the opj_read_header function is not a decompressor handler.\n");
			return OPJ_FALSE;
		}

		return l_codec->m_codec_data.m_decompression.opj_read_header(	l_stream,
																		l_codec->m_codec,
																		p_image,
																		&(l_codec->m_event_mgr) );
	}

	return OPJ_FALSE;
}

/*
 *
 *
 */
opj_bool OPJ_CALLCONV opj_decode(   opj_codec_t *p_codec,
                                    opj_stream_t *p_stream,
                                    opj_image_t* p_image)
{
	if (p_codec && p_stream) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;

		if (! l_codec->is_decompressor) {
			return OPJ_FALSE;
		}

		return l_codec->m_codec_data.m_decompression.opj_decode(l_codec->m_codec,
																l_stream,
																p_image,
																&(l_codec->m_event_mgr) );
	}

	return OPJ_FALSE;
}


/**
 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
 *
 * @param	p_codec			the jpeg2000 codec.
 * @param	p_start_x		the left position of the rectangle to decode (in image coordinates).
 * @param	p_end_x			the right position of the rectangle to decode (in image coordinates).
 * @param	p_start_y		the up position of the rectangle to decode (in image coordinates).
 * @param	p_end_y			the bottom position of the rectangle to decode (in image coordinates).
 *
 * @return	true			if the area could be set.
 */
opj_bool OPJ_CALLCONV opj_set_decode_area(	opj_codec_t *p_codec,
											opj_image_t* p_image,
											OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
											OPJ_INT32 p_end_x, OPJ_INT32 p_end_y
											)
{
	if (p_codec) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		
		if (! l_codec->is_decompressor) {
			return OPJ_FALSE;
		}

		return  l_codec->m_codec_data.m_decompression.opj_set_decode_area(	l_codec->m_codec,
																			p_image,
																			p_start_x, p_start_y,
																			p_end_x, p_end_y,
																			&(l_codec->m_event_mgr) );
	}
	return OPJ_FALSE;
}

/**
 * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
 *
 * @param	p_codec			the jpeg2000 codec.
 * @param	p_tile_index	pointer to a value that will hold the index of the tile being decoded, in case of success.
 * @param	p_data_size		pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
 *							of truncated codestreams, the actual number of bytes decoded may be lower. 
 *                          The computation of the size is the same as depicted in opj_write_tile.
 * @param	p_tile_x0		pointer to a value that will hold the x0 pos of the tile (in the image).
 * @param	p_tile_y0		pointer to a value that will hold the y0 pos of the tile (in the image).
 * @param	p_tile_x1		pointer to a value that will hold the x1 pos of the tile (in the image).
 * @param	p_tile_y1		pointer to a value that will hold the y1 pos of the tile (in the image).
 * @param	p_nb_comps		pointer to a value that will hold the number of components in the tile.
 * @param	p_should_go_on	pointer to a boolean that will hold the fact that the decoding should go on. In case the
 *							codestream is over at the time of the call, the value will be set to false. The user should then stop
 *							the decoding.
 * @param	p_stream		the stream to decode.
 * @return	true			if the tile header could be decoded. In case the decoding should end, the returned value is still true.
 *							returning false may be the result of a shortage of memory or an internal error.
 */
opj_bool OPJ_CALLCONV opj_read_tile_header(	opj_codec_t *p_codec,
											opj_stream_t * p_stream,
											OPJ_UINT32 * p_tile_index,
											OPJ_UINT32 * p_data_size,
											OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
											OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
											OPJ_UINT32 * p_nb_comps,
											opj_bool * p_should_go_on)
{
	if (p_codec && p_stream && p_data_size && p_tile_index) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;

		if (! l_codec->is_decompressor) {
			return OPJ_FALSE;
		}

		return l_codec->m_codec_data.m_decompression.opj_read_tile_header(	l_codec->m_codec,
																			p_tile_index,
																			p_data_size,
																			p_tile_x0, p_tile_y0,
																			p_tile_x1, p_tile_y1,
																			p_nb_comps,
																			p_should_go_on,
																			l_stream,
																			&(l_codec->m_event_mgr));
	}
	return OPJ_FALSE;
}

/**
 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
 *
 * @param	p_codec			the jpeg2000 codec.
 * @param	p_tile_index	the index of the tile being decoded, this should be the value set by opj_read_tile_header.
 * @param	p_data			pointer to a memory block that will hold the decoded data.
 * @param	p_data_size		size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
 * @param	p_stream		the stream to decode.
 *
 * @return	true			if the data could be decoded.
 */
opj_bool OPJ_CALLCONV opj_decode_tile_data(	opj_codec_t *p_codec,
											OPJ_UINT32 p_tile_index,
											OPJ_BYTE * p_data,
											OPJ_UINT32 p_data_size,
											opj_stream_t *p_stream
											)
{
	if (p_codec && p_data && p_stream) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;

		if (! l_codec->is_decompressor) {
			return OPJ_FALSE;
		}

		return l_codec->m_codec_data.m_decompression.opj_decode_tile_data(	l_codec->m_codec,
																			p_tile_index,
																			p_data,
																			p_data_size,
																			l_stream,
																			&(l_codec->m_event_mgr) );
	}
	return OPJ_FALSE;
}

/*
 *
 *
 */
opj_bool OPJ_CALLCONV opj_get_decoded_tile(	opj_codec_t *p_codec,
											opj_stream_t *p_stream,
											opj_image_t *p_image,
											OPJ_UINT32 tile_index)
{
	if (p_codec && p_stream) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;

		if (! l_codec->is_decompressor) {
			return OPJ_FALSE;
		}
		
		return l_codec->m_codec_data.m_decompression.opj_get_decoded_tile(	l_codec->m_codec,
																			l_stream,
																			p_image,
																			&(l_codec->m_event_mgr),
																			tile_index);
	}

	return OPJ_FALSE;
}

/*
 *
 *
 */
opj_bool OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, 
														OPJ_UINT32 res_factor )
{
	opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;

	if ( !l_codec ){
		fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n");
		return OPJ_FALSE;
	}

	l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor(l_codec->m_codec, 
																			res_factor,
																			&(l_codec->m_event_mgr) );
	return OPJ_TRUE;
}

/* ---------------------------------------------------------------------- */
/* COMPRESSION FUNCTIONS*/

opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
{
	opj_codec_private_t *l_codec = 00;

	l_codec = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t));
	if (!l_codec) {
		return 00;
	}
	memset(l_codec, 0, sizeof(opj_codec_private_t));
	
	l_codec->is_decompressor = 0;

	switch(p_format) {
		case 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;

			l_codec->m_codec_data.m_compression.opj_end_compress = (opj_bool (*) (	void *,
																					struct opj_stream_private *,
																					struct opj_event_mgr *)) opj_j2k_end_compress;

			l_codec->m_codec_data.m_compression.opj_start_compress = (opj_bool (*) (void *,
																					struct opj_stream_private *,
																					struct opj_image * ,
																					struct opj_event_mgr *)) opj_j2k_start_compress;

			l_codec->m_codec_data.m_compression.opj_write_tile = (opj_bool (*) (void *,
																				OPJ_UINT32,
																				OPJ_BYTE*,
																				OPJ_UINT32,
																				struct opj_stream_private *,
																				struct opj_event_mgr *) ) opj_j2k_write_tile;

			l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_j2k_destroy;

			l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) (	void *,
																				opj_cparameters_t *,
																				struct opj_image *,
																				struct opj_event_mgr * )) opj_j2k_setup_encoder_v2;

			l_codec->m_codec = opj_j2k_create_compress_v2();
			if (! l_codec->m_codec) {
				opj_free(l_codec);
				return 00;
			}

			break;

		case CODEC_JP2:
			/* get a JP2 decoder handle */
			l_codec->m_codec_data.m_compression.opj_encode = (opj_bool (*) (void *,
																			struct opj_stream_private *,
																			struct opj_event_mgr * )) opj_jp2_encode;

			l_codec->m_codec_data.m_compression.opj_end_compress = (opj_bool (*) (	void *,
																					struct opj_stream_private *,
																					struct opj_event_mgr *)) opj_jp2_end_compress;

			l_codec->m_codec_data.m_compression.opj_start_compress = (opj_bool (*) (void *,
																					struct opj_stream_private *,
																					struct opj_image * ,
																					struct opj_event_mgr *))  opj_jp2_start_compress;

			l_codec->m_codec_data.m_compression.opj_write_tile = (opj_bool (*) (void *,
																				OPJ_UINT32,
																				OPJ_BYTE*,
																				OPJ_UINT32,
																				struct opj_stream_private *,
																				struct opj_event_mgr *)) opj_jp2_write_tile;

			l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy;

			l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) (	void *,
																				opj_cparameters_t *,
																				struct opj_image *,
																				struct opj_event_mgr * )) opj_jp2_setup_encoder;

			l_codec->m_codec = opj_jp2_create(OPJ_FALSE);
			if (! l_codec->m_codec) {
				opj_free(l_codec);
				return 00;
			}

			break;

		case CODEC_UNKNOWN:
		case CODEC_JPT:
		default:
			opj_free(l_codec);
			return 00;
	}

	opj_set_default_event_handler(&(l_codec->m_event_mgr));
	return (opj_codec_t*) l_codec;
}

void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
	if(parameters) {
		memset(parameters, 0, sizeof(opj_cparameters_t));
		/* default coding parameters */
		parameters->cp_cinema = OFF; 
		parameters->max_comp_size = 0;
		parameters->numresolution = 6;
		parameters->cp_rsiz = STD_RSIZ;
		parameters->cblockw_init = 64;
		parameters->cblockh_init = 64;
		parameters->prog_order = LRCP;
		parameters->roi_compno = -1;		/* no ROI */
		parameters->subsampling_dx = 1;
		parameters->subsampling_dy = 1;
		parameters->tp_on = 0;
		parameters->decod_format = -1;
		parameters->cod_format = -1;
		parameters->tcp_rates[0] = 0;   
		parameters->tcp_numlayers = 0;
		parameters->cp_disto_alloc = 0;
		parameters->cp_fixed_alloc = 0;
		parameters->cp_fixed_quality = 0;
		parameters->jpip_on = OPJ_FALSE;
/* UniPG>> */
#ifdef USE_JPWL
		parameters->jpwl_epc_on = OPJ_FALSE;
		parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
		{
			int i;
			for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
				parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
				parameters->jpwl_hprot_TPH[i] = 0; /* absent */
			}
		};
		{
			int i;
			for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
				parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
				parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
				parameters->jpwl_pprot[i] = 0; /* absent */
			}
		};
		parameters->jpwl_sens_size = 0; /* 0 means no ESD */
		parameters->jpwl_sens_addr = 0; /* 0 means auto */
		parameters->jpwl_sens_range = 0; /* 0 means packet */
		parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
		{
			int i;
			for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
				parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
				parameters->jpwl_sens_TPH[i] = -1; /* absent */
			}
		};
#endif /* USE_JPWL */
/* <<UniPG */
	}
}

opj_bool OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, 
										opj_cparameters_t *parameters, 
										opj_image_t *p_image)
{
	if (p_codec && parameters && p_image) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;

		if (! l_codec->is_decompressor) {
			l_codec->m_codec_data.m_compression.opj_setup_encoder(	l_codec->m_codec,
																	parameters,
																	p_image,
																	&(l_codec->m_event_mgr) );
			return OPJ_TRUE;
		}
	}

	return OPJ_FALSE;
}

opj_bool OPJ_CALLCONV opj_start_compress (	opj_codec_t *p_codec,
											opj_image_t * p_image,
											opj_stream_t *p_stream)
{
	if (p_codec && p_stream) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;

		if (! l_codec->is_decompressor) {
			return l_codec->m_codec_data.m_compression.opj_start_compress(	l_codec->m_codec,
																			l_stream,
																			p_image,
																			&(l_codec->m_event_mgr));
		}
	}

	return OPJ_FALSE;
}

opj_bool OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream)
{
	if (p_info && p_stream) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_info;
		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,
															l_stream,
															&(l_codec->m_event_mgr));
			return OPJ_TRUE;
		}
	}

	return OPJ_FALSE;

}

opj_bool OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
										opj_stream_t *p_stream)
{
	if (p_codec && p_stream) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;

		if (! l_codec->is_decompressor) {
			return l_codec->m_codec_data.m_compression.opj_end_compress(l_codec->m_codec,
																		l_stream,
																		&(l_codec->m_event_mgr));
		}
	}
	return OPJ_FALSE;

}

/*
 *
 *
 */
opj_bool OPJ_CALLCONV opj_end_decompress (	opj_codec_t *p_codec,
											opj_stream_t *p_stream)
{
	if (p_codec && p_stream) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;

		if (! l_codec->is_decompressor) {
			return OPJ_FALSE;
		}
		
		return l_codec->m_codec_data.m_decompression.opj_end_decompress(l_codec->m_codec,
																		l_stream,
																		&(l_codec->m_event_mgr) );
	}

	return OPJ_FALSE;
}


opj_bool OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,
                                  OPJ_FLOAT32 * pEncodingMatrix,
                                  OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp)
{
	OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * sizeof(OPJ_FLOAT32);
	OPJ_UINT32 l_dc_shift_size = pNbComp * sizeof(OPJ_INT32);
	OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size;

	/* add MCT capability */
	int rsiz = (int)parameters->cp_rsiz | (int)MCT;
	parameters->cp_rsiz = (OPJ_RSIZ_CAPABILITIES)rsiz;
	parameters->irreversible = 1;

	/* use array based MCT */
	parameters->tcp_mct = 2;
	parameters->mct_data = opj_malloc(l_mct_total_size);
	if (! parameters->mct_data) {
		return OPJ_FALSE;
	}

	memcpy(parameters->mct_data,pEncodingMatrix,l_matrix_size);
	memcpy(((OPJ_BYTE *) parameters->mct_data) +  l_matrix_size,p_dc_shift,l_dc_shift_size);

	return OPJ_TRUE;
}

/**
 * Writes a tile with the given data.
 *
 * @param	p_compressor		the jpeg2000 codec.
 * @param	p_tile_index		the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
 * @param	p_data				pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, 
 *                               then ... NO INTERLEAVING should be set.
 * @param	p_data_size			this value os used to make sure the data being written is correct. The size must be 
 *                               equal to the sum for each component of tile_width * tile_height * component_size. 
 *                               component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
 * @param	p_stream			the stream to write data to.
 */
opj_bool OPJ_CALLCONV opj_write_tile (	opj_codec_t *p_codec,
										OPJ_UINT32 p_tile_index,
										OPJ_BYTE * p_data,
										OPJ_UINT32 p_data_size,
										opj_stream_t *p_stream )
{
	if (p_codec && p_stream && p_data) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
		opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;

		if (l_codec->is_decompressor) {
			return OPJ_FALSE;
		}

		return l_codec->m_codec_data.m_compression.opj_write_tile(	l_codec->m_codec,
																	p_tile_index,
																	p_data,
																	p_data_size,
																	l_stream,
																	&(l_codec->m_event_mgr) );
	}

	return OPJ_FALSE;
}

/* ---------------------------------------------------------------------- */

void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec)
{
	if (p_codec) {
		opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;

		if (l_codec->is_decompressor) {
			l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec);
		}
		else {
			l_codec->m_codec_data.m_compression.opj_destroy(l_codec->m_codec);
		}

		l_codec->m_codec = 00;
		opj_free(l_codec);
	}
}

/* ---------------------------------------------------------------------- */

/*
 *
 *
 */
void OPJ_CALLCONV opj_dump_codec(	opj_codec_t *p_codec,
									OPJ_INT32 info_flag,
									FILE* output_stream)
{
	if (p_codec) {
		opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;

		l_codec->opj_dump_codec(l_codec->m_codec, info_flag, output_stream);
		return;
	}

	fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n");
	return;
}

/*
 *
 *
 */
opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
{
	if (p_codec) {
		opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;

		return l_codec->opj_get_codec_info(l_codec->m_codec);
	}

	return NULL;
}

/*
 *
 *
 */
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) {
	if (cstr_info) {

		if ((*cstr_info)->m_default_tile_info.tccp_info){
			opj_free((*cstr_info)->m_default_tile_info.tccp_info);
		}

		if ((*cstr_info)->tile_info){
			/* FIXME not used for the moment*/
		}

		opj_free((*cstr_info));
		(*cstr_info) = NULL;
	}
}

/*
 *
 *
 */
opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec)
{
	if (p_codec) {
		opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;

		return l_codec->opj_get_codec_index(l_codec->m_codec);
	}

	return NULL;
}

/*
 *
 *
 */
void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
{
	if (*p_cstr_index){
		j2k_destroy_cstr_index(*p_cstr_index);
		(*p_cstr_index) = NULL;
	}
}

/* ---------------------------------------------------------------------- */
/**
 * Helper function.
 * Sets the stream to be a file stream. The FILE must have been open previously.
 * @param		p_stream	the stream to modify
 * @param		p_file		handler to an already open file.
*/
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,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)
{
	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;
}