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 NrrdFormat can assume: |
29 |
|
|
** -- that nio->format has been set to you already |
30 |
|
|
** -- for read(): that nio->path has been set to the path of the file being |
31 |
|
|
** read in, if the information was ever available |
32 |
|
|
** -- for contentStartsLike() and read(): that nio->line contains the |
33 |
|
|
** first line of of the file, in order to determine the file type |
34 |
|
|
** |
35 |
|
|
** what a NrrdFormat has to do: |
36 |
|
|
** -- respect nio->skipData to whatever extent makes sense on top of how the |
37 |
|
|
** NrrdEncoding respects it (by making read and write no-ops). |
38 |
|
|
** nrrdFormatNRRD, for instance, won't create empty detached data files |
39 |
|
|
** if nio->skipData. |
40 |
|
|
** -- determine what NrrdEncoding to use, if there's a choice |
41 |
|
|
** -- respect nrrdStateVerboseIO with messages to stderr, if possible |
42 |
|
|
** |
43 |
|
|
** The "unknown" format is intended as a template for writing new formats. |
44 |
|
|
*/ |
45 |
|
|
|
46 |
|
|
static int |
47 |
|
|
_nrrdFormatUnknown_available(void) { |
48 |
|
|
|
49 |
|
|
/* insert code here */ |
50 |
|
|
|
51 |
|
|
return AIR_FALSE; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
static int |
55 |
|
|
_nrrdFormatUnknown_nameLooksLike(const char *filename) { |
56 |
|
|
|
57 |
|
|
/* insert code here */ |
58 |
|
|
AIR_UNUSED(filename); |
59 |
|
|
|
60 |
|
|
return AIR_FALSE; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
static int |
64 |
|
|
_nrrdFormatUnknown_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, |
65 |
|
|
int useBiff) { |
66 |
|
|
static const char me[]="_nrrdFormatUnknown_fitsInto"; |
67 |
|
|
|
68 |
|
|
if (!(nrrd && encoding)) { |
69 |
|
|
biffMaybeAddf(useBiff, NRRD, "%s: got NULL nrrd (%p) or encoding (%p)", |
70 |
|
|
me, AIR_CVOIDP(nrrd), AIR_CVOIDP(encoding)); |
71 |
|
|
return AIR_FALSE; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
/* insert code here */ |
75 |
|
|
|
76 |
|
|
return AIR_FALSE; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
static int |
80 |
|
|
_nrrdFormatUnknown_contentStartsLike(NrrdIoState *nio) { |
81 |
|
|
|
82 |
|
|
/* insert code here */ |
83 |
|
|
AIR_UNUSED(nio); |
84 |
|
|
|
85 |
|
|
return AIR_FALSE; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
static int |
89 |
|
|
_nrrdFormatUnknown_read(FILE *file, Nrrd *nrrd, |
90 |
|
|
NrrdIoState *nio) { |
91 |
|
|
static const char me[]="_nrrdFormatUnknown_read"; |
92 |
|
|
|
93 |
|
|
/* insert code here, and remove error handling below */ |
94 |
|
|
AIR_UNUSED(file); |
95 |
|
|
AIR_UNUSED(nrrd); |
96 |
|
|
AIR_UNUSED(nio); |
97 |
|
|
|
98 |
|
|
biffAddf(NRRD, "%s: ERROR!!! trying to read unknown format", me); |
99 |
|
|
return 1; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
static int |
103 |
|
|
_nrrdFormatUnknown_write(FILE *file, const Nrrd *nrrd, |
104 |
|
|
NrrdIoState *nio) { |
105 |
|
|
static const char me[]="_nrrdFormatUnknown_write"; |
106 |
|
|
|
107 |
|
|
/* insert code here, and remove error handling below */ |
108 |
|
|
AIR_UNUSED(file); |
109 |
|
|
AIR_UNUSED(nrrd); |
110 |
|
|
AIR_UNUSED(nio); |
111 |
|
|
|
112 |
|
|
biffAddf(NRRD, "%s: ERROR!!! trying to write unknown format", me); |
113 |
|
|
return 1; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
static const NrrdFormat |
117 |
|
|
_nrrdFormatUnknown = { |
118 |
|
|
"unknown", |
119 |
|
|
AIR_FALSE, /* isImage */ |
120 |
|
|
AIR_TRUE, /* readable */ |
121 |
|
|
AIR_FALSE, /* usesDIO */ |
122 |
|
|
_nrrdFormatUnknown_available, |
123 |
|
|
_nrrdFormatUnknown_nameLooksLike, |
124 |
|
|
_nrrdFormatUnknown_fitsInto, |
125 |
|
|
_nrrdFormatUnknown_contentStartsLike, |
126 |
|
|
_nrrdFormatUnknown_read, |
127 |
|
|
_nrrdFormatUnknown_write |
128 |
|
|
}; |
129 |
|
|
|
130 |
|
|
const NrrdFormat *const |
131 |
|
|
nrrdFormatUnknown = &_nrrdFormatUnknown; |
132 |
|
|
|
133 |
|
|
const NrrdFormat *const |
134 |
|
|
nrrdFormatArray[NRRD_FORMAT_TYPE_MAX+1] = { |
135 |
|
|
&_nrrdFormatUnknown, |
136 |
|
|
&_nrrdFormatNRRD, |
137 |
|
|
&_nrrdFormatPNM, |
138 |
|
|
&_nrrdFormatPNG, |
139 |
|
|
&_nrrdFormatVTK, |
140 |
|
|
&_nrrdFormatText, |
141 |
|
|
&_nrrdFormatEPS |
142 |
|
|
}; |