1 : /******************************************************************************
2 : * $Id: fit.cpp 14048 2008-03-20 18:47:21Z rouault $
3 : *
4 : * Project: FIT Driver
5 : * Purpose: Implement FIT Support - not using the SGI iflFIT library.
6 : * Author: Philip Nemec, nemec@keyholecorp.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2001, Keyhole, Inc.
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include <limits.h>
31 : #include "fit.h"
32 :
33 : CPL_CVSID("$Id: fit.cpp 14048 2008-03-20 18:47:21Z rouault $");
34 :
35 74 : GDALDataType fitDataType(int dtype) {
36 74 : switch (dtype) {
37 : case 1: // iflBit /* single-bit */
38 : fprintf(stderr,
39 0 : "GDAL unsupported data type (single-bit) in fitDataType\n");
40 0 : return GDT_Unknown;
41 : case 2: // iflUChar /* unsigned character (byte) */
42 26 : return GDT_Byte;
43 : case 4: // iflChar /* signed character (byte) */
44 : fprintf(stderr,
45 0 : "GDAL unsupported data type (signed char) in fitDataType\n");
46 0 : return GDT_Unknown;
47 : // return Byte;
48 : case 8: // iflUShort /* unsigned short integer (nominally 16 bits) */
49 8 : return GDT_UInt16;
50 : case 16: // iflShort /* signed short integer */
51 8 : return GDT_Int16;
52 : case 32: // iflUInt /* unsigned integer (nominally 32 bits) */
53 : // case 32: // iflULong /* deprecated, same as iflUInt */
54 8 : return GDT_UInt32;
55 : break;
56 : case 64: // iflInt /* integer */
57 : // case 64: // iflLong /* deprecated, same as iflULong */
58 8 : return GDT_Int32;
59 : case 128: // iflFloat /* floating point */
60 8 : return GDT_Float32;
61 : case 256: // iflDouble /* double precision floating point */
62 8 : return GDT_Float64;
63 : default:
64 : CPLError(CE_Failure, CPLE_NotSupported,
65 0 : "FIT - unknown data type %i in fitDataType", dtype);
66 0 : return GDT_Unknown;
67 : } // switch
68 : }
69 :
70 22 : int fitGetDataType(GDALDataType eDataType) {
71 22 : switch (eDataType) {
72 : case GDT_Byte:
73 6 : return 2; // iflUChar - unsigned character (byte)
74 : case GDT_UInt16:
75 2 : return 8; // iflUShort - unsigned short integer (nominally 16 bits)
76 : case GDT_Int16:
77 2 : return 16; // iflShort - signed short integer
78 : case GDT_UInt32:
79 2 : return 32; // iflUInt - unsigned integer (nominally 32 bits)
80 : case GDT_Int32:
81 2 : return 64; // iflInt - integer
82 : case GDT_Float32:
83 2 : return 128; // iflFloat - floating point
84 : case GDT_Float64:
85 2 : return 256; // iflDouble - double precision floating point
86 : default:
87 : CPLError(CE_Failure, CPLE_NotSupported,
88 : "FIT - unsupported GDALDataType %i in fitGetDataType",
89 4 : eDataType);
90 4 : return 0;
91 : } // switch
92 : }
93 :
94 : #define UNSUPPORTED_COMBO() \
95 : CPLError(CE_Failure, CPLE_NotSupported, \
96 : "FIT write - unsupported combination (band 1 = %s " \
97 : "and %i bands) - ignoring color model", \
98 : GDALGetColorInterpretationName(colorInterp), nBands); \
99 : return 0
100 :
101 :
102 18 : int fitGetColorModel(GDALColorInterp colorInterp, int nBands) {
103 : // XXX - shoould check colorInterp for all bands, not just first one
104 :
105 18 : switch(colorInterp) {
106 : case GCI_GrayIndex:
107 16 : switch (nBands) {
108 : case 1:
109 14 : return 2; // iflLuminance - luminance
110 : case 2:
111 1 : return 13; // iflLuminanceAlpha - Luminance plus alpha
112 : default:
113 1 : UNSUPPORTED_COMBO();
114 : } // switch
115 :
116 : case GCI_PaletteIndex:
117 : CPLError(CE_Failure, CPLE_NotSupported,
118 0 : "FIT write - unsupported ColorInterp PaletteIndex\n");
119 0 : return 0;
120 :
121 : case GCI_RedBand:
122 2 : switch (nBands) {
123 : case 3:
124 1 : return 3; // iflRGB - full color (Red, Green, Blue triplets)
125 : case 4:
126 1 : return 5; // iflRGBA - full color with transparency (alpha channel)
127 : default:
128 0 : UNSUPPORTED_COMBO();
129 : } // switch
130 :
131 : case GCI_BlueBand:
132 0 : switch (nBands) {
133 : case 3:
134 0 : return 9; // iflBGR - full color (ordered Blue, Green, Red)
135 : default:
136 0 : UNSUPPORTED_COMBO();
137 : } // switch
138 :
139 : case GCI_AlphaBand:
140 0 : switch (nBands) {
141 : case 4:
142 0 : return 10; // iflABGR - Alpha, Blue, Green, Red (SGI frame buffers)
143 : default:
144 0 : UNSUPPORTED_COMBO();
145 : } // switch
146 :
147 : case GCI_HueBand:
148 0 : switch (nBands) {
149 : case 3:
150 0 : return 6; // iflHSV - Hue, Saturation, Value
151 : default:
152 0 : UNSUPPORTED_COMBO();
153 : } // switch
154 :
155 : case GCI_CyanBand:
156 0 : switch (nBands) {
157 : case 3:
158 0 : return 7; // iflCMY - Cyan, Magenta, Yellow
159 : case 4:
160 0 : return 8; // iflCMYK - Cyan, Magenta, Yellow, Black
161 : default:
162 0 : UNSUPPORTED_COMBO();
163 : } // switch
164 :
165 : case GCI_GreenBand:
166 : case GCI_SaturationBand:
167 : case GCI_LightnessBand:
168 : case GCI_MagentaBand:
169 : case GCI_YellowBand:
170 : case GCI_BlackBand:
171 : CPLError(CE_Failure, CPLE_NotSupported,
172 : "FIT write - unsupported combination (band 1 = %s) "
173 : "- ignoring color model",
174 0 : GDALGetColorInterpretationName(colorInterp));
175 0 : return 0;
176 :
177 : default:
178 : CPLDebug("FIT write", "unrecognized colorInterp %i - deriving from "
179 0 : "number of bands (%i)", colorInterp, nBands);
180 0 : switch (nBands) {
181 : case 1:
182 0 : return 2; // iflLuminance - luminance
183 : case 2:
184 0 : return 13; // iflLuminanceAlpha - Luminance plus alpha
185 : case 3:
186 0 : return 3; // iflRGB - full color (Red, Green, Blue triplets)
187 : case 4:
188 0 : return 5; // iflRGBA - full color with transparency (alpha channel)
189 : } // switch
190 :
191 : CPLError(CE_Failure, CPLE_NotSupported,
192 : "FIT write - unrecognized colorInterp %i and "
193 0 : "unrecognized number of bands (%i)", colorInterp, nBands);
194 :
195 0 : return 0;
196 : } // switch
197 : }
|