]> Creatis software - gdcm.git/blob - src/gdcmopenjpeg/libopenjpeg/raw.c
ENH: Huge update to openjpeg 1.0 (actually more CVS)...
[gdcm.git] / src / gdcmopenjpeg / libopenjpeg / raw.c
1 /*\r
2  * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe\r
3  * Copyright (c) 2005, HervĂ© Drolon, FreeImage Team\r
4  * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium\r
5  * All rights reserved.\r
6  *\r
7  * Redistribution and use in source and binary forms, with or without\r
8  * modification, are permitted provided that the following conditions\r
9  * are met:\r
10  * 1. Redistributions of source code must retain the above copyright\r
11  *    notice, this list of conditions and the following disclaimer.\r
12  * 2. Redistributions in binary form must reproduce the above copyright\r
13  *    notice, this list of conditions and the following disclaimer in the\r
14  *    documentation and/or other materials provided with the distribution.\r
15  *\r
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'\r
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
26  * POSSIBILITY OF SUCH DAMAGE.\r
27  */\r
28 \r
29 #include "opj_includes.h"\r
30 \r
31 /* \r
32 ==========================================================\r
33    local functions\r
34 ==========================================================\r
35 */\r
36 \r
37 \r
38 /* \r
39 ==========================================================\r
40    RAW encoding interface\r
41 ==========================================================\r
42 */\r
43 \r
44 opj_raw_t* raw_create() {\r
45   opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));\r
46   return raw;\r
47 }\r
48 \r
49 void raw_destroy(opj_raw_t *raw) {\r
50   if(raw) {\r
51     opj_free(raw);\r
52   }\r
53 }\r
54 \r
55 int raw_numbytes(opj_raw_t *raw) {\r
56   return raw->bp - raw->start;\r
57 }\r
58 \r
59 void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) {\r
60   raw->start = bp;\r
61   raw->lenmax = len;\r
62   raw->len = 0;\r
63   raw->c = 0;\r
64   raw->ct = 0;\r
65 }\r
66 \r
67 int raw_decode(opj_raw_t *raw) {\r
68   int d;\r
69   if (raw->ct == 0) {\r
70     raw->ct = 8;\r
71     if (raw->len == raw->lenmax) {\r
72       raw->c = 0xff;\r
73     } else {\r
74       if (raw->c == 0xff) {\r
75         raw->ct = 7;\r
76       }\r
77       raw->c = *(raw->start + raw->len);\r
78       raw->len++;\r
79     }\r
80   }\r
81   raw->ct--;\r
82   d = (raw->c >> raw->ct) & 0x01;\r
83   \r
84   return d;\r
85 }\r
86 \r