1 |
|
|
/* |
2 |
|
|
Teem: Tools to process and visualize scientific data and images . |
3 |
|
|
Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago |
4 |
|
|
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann |
5 |
|
|
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public License |
9 |
|
|
(LGPL) as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
The terms of redistributing and/or modifying this software also |
12 |
|
|
include exceptions to the LGPL that facilitate static linking. |
13 |
|
|
|
14 |
|
|
This library is distributed in the hope that it will be useful, |
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
|
|
Lesser General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
along with this library; if not, write to Free Software Foundation, Inc., |
21 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "nrrd.h" |
25 |
|
|
#include "privateNrrd.h" |
26 |
|
|
|
27 |
|
|
static int |
28 |
|
|
_nrrdEncodingZRL_available(void) { |
29 |
|
|
|
30 |
|
4 |
return AIR_TRUE; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
static int |
34 |
|
|
_nrrdEncodingZRL_read(FILE *file, void *data, size_t elementNum, |
35 |
|
|
Nrrd *nrrd, NrrdIoState *nio) { |
36 |
|
|
|
37 |
|
|
AIR_UNUSED(nio); |
38 |
|
|
unsigned char *output_buffer = (unsigned char *) data; |
39 |
|
|
size_t toread = elementNum*nrrdElementSize(nrrd); |
40 |
|
|
/* |
41 |
|
|
static const char me[]="_nrrdEncodingZRL_read"; |
42 |
|
|
printf("!%s: looking for %u values (%u bytes) of type %s\n", me, |
43 |
|
|
(unsigned int)elementNum, (unsigned int)toread, |
44 |
|
|
airEnumStr(nrrdType, nrrd->type)); */ |
45 |
|
|
int cc, dd; |
46 |
|
|
unsigned int j = 0; |
47 |
|
|
while (j < toread) { |
48 |
|
|
cc = fgetc(file); |
49 |
|
|
if (cc == 0) { |
50 |
|
|
dd = fgetc(file); |
51 |
|
|
if (dd == 0) { |
52 |
|
|
dd = fgetc(file); |
53 |
|
|
j += dd + fgetc(file)*256; |
54 |
|
|
} else { |
55 |
|
|
j += (unsigned char)dd; |
56 |
|
|
} |
57 |
|
|
} else { |
58 |
|
|
output_buffer[j] = (unsigned char)cc; |
59 |
|
|
j++; |
60 |
|
|
} |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
return 0; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
static int |
67 |
|
|
_nrrdEncodingZRL_write(FILE *file, const void *data, size_t elementNum, |
68 |
|
|
const Nrrd *nrrd, NrrdIoState *nio) { |
69 |
|
|
static const char me[]="_nrrdEncodingZRL_write"; |
70 |
|
|
|
71 |
|
|
AIR_UNUSED(file); |
72 |
|
|
AIR_UNUSED(data); |
73 |
|
|
AIR_UNUSED(elementNum); |
74 |
|
|
AIR_UNUSED(nrrd); |
75 |
|
|
AIR_UNUSED(nio); |
76 |
|
|
biffAddf(NRRD, "%s: sorry, currently a read-only encoding", me); |
77 |
|
|
|
78 |
|
|
return 0; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
const NrrdEncoding |
82 |
|
|
_nrrdEncodingZRL = { |
83 |
|
|
"zrl", /* name */ |
84 |
|
|
"zrl", /* suffix */ |
85 |
|
|
AIR_TRUE, /* endianMatters */ |
86 |
|
|
AIR_FALSE, /* isCompression: HEY this is a hack: this IS certainly a |
87 |
|
|
compression. However, with compressed encodings the nrrd |
88 |
|
|
format has no way of specifying whether a byteskip |
89 |
|
|
between be outside the encoding (in the uncompressed |
90 |
|
|
data) vs inside the encoding (within the compuressed |
91 |
|
|
data). To date the convention has been that byte skip is |
92 |
|
|
done *inside* compressions, but for the ZRL-encoded data |
93 |
|
|
as currently generated, the relevant byte skipping is |
94 |
|
|
certainly *outside* the compression. Thus we claim |
95 |
|
|
ignorance about how ZRL is a compression, so that byte |
96 |
|
|
skipping can be used. */ |
97 |
|
|
_nrrdEncodingZRL_available, |
98 |
|
|
_nrrdEncodingZRL_read, |
99 |
|
|
_nrrdEncodingZRL_write |
100 |
|
|
}; |
101 |
|
|
|
102 |
|
|
const NrrdEncoding *const |
103 |
|
|
nrrdEncodingZRL = &_nrrdEncodingZRL; |