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 |
|
|
/* |
28 |
|
|
** what a NrrdEncoding can assume: |
29 |
|
|
** -- the given nrrd struct has been filled out for the sake of knowing |
30 |
|
|
** nrrd->dim, nrrd->axis[0].size, nrrd->type, and nrrd->blockSize |
31 |
|
|
** AND NOTHING ELSE. See nrrd.h for why those fields, of all things |
32 |
|
|
** are needed for {en/de}coding |
33 |
|
|
** |
34 |
|
|
** what a NrrdEncoding has to do: |
35 |
|
|
** -- read data from file into the "data" argument (BUT NOT nrrd->data!!), |
36 |
|
|
** or vice versa. |
37 |
|
|
** -- respect nrrdStateVerboseIO with messages to stderr, if possible |
38 |
|
|
** -- in case of error, put text error messages into biff via |
39 |
|
|
** biffAddf(NRRD, <error char*> ...) |
40 |
|
|
** |
41 |
|
|
** The "unknown" encoding below is intended to serve as a template for |
42 |
|
|
** any new encodings being developed. |
43 |
|
|
*/ |
44 |
|
|
|
45 |
|
|
static int |
46 |
|
|
_nrrdEncodingUnknown_available(void) { |
47 |
|
|
|
48 |
|
|
/* insert code here */ |
49 |
|
|
|
50 |
|
|
return AIR_FALSE; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
static int |
54 |
|
|
_nrrdEncodingUnknown_read(FILE *file, void *data, |
55 |
|
|
size_t elementNum, Nrrd *nrrd, |
56 |
|
|
struct NrrdIoState_t *nio) { |
57 |
|
|
static const char me[]="_nrrdEncodingUnknown_read"; |
58 |
|
|
|
59 |
|
|
/* insert code here, and remove error handling below */ |
60 |
|
|
AIR_UNUSED(file); |
61 |
|
|
AIR_UNUSED(data); |
62 |
|
|
AIR_UNUSED(elementNum); |
63 |
|
|
AIR_UNUSED(nrrd); |
64 |
|
|
AIR_UNUSED(nio); |
65 |
|
|
|
66 |
|
|
biffAddf(NRRD, "%s: ERROR!!! trying to read unknown encoding", me); |
67 |
|
|
return 1; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
static int |
71 |
|
|
_nrrdEncodingUnknown_write(FILE *file, const void *data, |
72 |
|
|
size_t elementNum, const Nrrd *nrrd, |
73 |
|
|
struct NrrdIoState_t *nio) { |
74 |
|
|
static const char me[]="_nrrdEncodingUnknown_write"; |
75 |
|
|
|
76 |
|
|
/* insert code here, and remove error handling below */ |
77 |
|
|
AIR_UNUSED(file); |
78 |
|
|
AIR_UNUSED(data); |
79 |
|
|
AIR_UNUSED(elementNum); |
80 |
|
|
AIR_UNUSED(nrrd); |
81 |
|
|
AIR_UNUSED(nio); |
82 |
|
|
|
83 |
|
|
biffAddf(NRRD, "%s: ERROR!!! trying to write unknown encoding", me); |
84 |
|
|
return 1; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
const NrrdEncoding |
88 |
|
|
_nrrdEncodingUnknown = { |
89 |
|
|
"unknown", /* name */ |
90 |
|
|
"unknown", /* suffix */ |
91 |
|
|
AIR_FALSE, /* endianMatters */ |
92 |
|
|
AIR_FALSE, /* isCompression */ |
93 |
|
|
_nrrdEncodingUnknown_available, |
94 |
|
|
_nrrdEncodingUnknown_read, |
95 |
|
|
_nrrdEncodingUnknown_write |
96 |
|
|
}; |
97 |
|
|
|
98 |
|
|
const NrrdEncoding *const |
99 |
|
|
nrrdEncodingUnknown = &_nrrdEncodingUnknown; |
100 |
|
|
|
101 |
|
|
const NrrdEncoding *const |
102 |
|
|
nrrdEncodingArray[NRRD_ENCODING_TYPE_MAX+1] = { |
103 |
|
|
&_nrrdEncodingUnknown, |
104 |
|
|
&_nrrdEncodingRaw, |
105 |
|
|
&_nrrdEncodingAscii, |
106 |
|
|
&_nrrdEncodingHex, |
107 |
|
|
&_nrrdEncodingGzip, |
108 |
|
|
&_nrrdEncodingBzip2, |
109 |
|
|
&_nrrdEncodingZRL, |
110 |
|
|
}; |
111 |
|
|
|