-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.go
274 lines (262 loc) · 6.04 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package tiff
import (
"fmt"
"math"
"math/big"
)
// A FormatError reports that the input is not a valid TIFF image.
type FormatError string
func (e FormatError) Error() string {
return fmt.Sprintf("tiff: invalid format: %s", string(e))
}
// An UnsupportedError reports that the input uses a valid but
// unimplemented feature.
type UnsupportedError string
func (e UnsupportedError) Error() string {
return fmt.Sprintf("tiff: unsupported feature: %s", string(e))
}
// An InternalError reports that an internal error was encountered.
type InternalError string
func (e InternalError) Error() string {
return fmt.Sprintf("tiff: internal error: %s", string(e))
}
// minInt returns the smaller of x or y.
func minInt(a, b int) int {
if a <= b {
return a
}
return b
}
func tagname(t uint16) string {
switch t {
case tBitsPerSample:
return "BitsPerSample"
case tExtraSamples:
return "BitsPerSample"
case tPhotometricInterpretation:
return "PhotometricInterpretation"
case tCompression:
return "Compression"
case tPredictor:
return "Predictor"
case tNewSubFileType:
return "NewSubFileType"
case tSubIFDs:
return "SubIFDs"
case tStripOffsets:
return "StripOffsets"
case tStripByteCounts:
return "StripByteCounts"
case tSamplesPerPixel:
return "SamplesPerPixel"
case tRowsPerStrip:
return "RowsPerStrip"
case tTileWidth:
return "TileWidth"
case tTileLength:
return "TileLength"
case tTileOffsets:
return "TileOffsets"
case tTileByteCounts:
return "TileByteCounts"
case tPlanarConfiguration:
return "PlanarConfiguration"
case tImageLength:
return "ImageLength"
case tImageWidth:
return "ImageWidth"
case tStonits:
return "StoNits"
case tCFARepeatPatternDim:
return "CFARepeatPatternDim"
case tCFAPattern:
return "CFAPattern"
case tDNGVersion:
return "DNG Version"
case tDNGBackwardVersion:
return "DNG Backward Version"
case tCFAPlaneColor:
return "CFAPlaneColor"
case tCFALayout:
return "CFALayout"
case tLinearizationTable:
return "LinearizationTable"
case tBlackLevel:
return "BlackLevel"
case tWhiteLevel:
return "WhiteLevel"
case tColorMatrix1:
return "ColorMatrix1"
case tColorMatrix2:
return "ColorMatrix2"
case tCameraCalibration1:
return "CameraCalibration1"
case tCameraCalibration2:
return "CameraCalibration2"
case tReductionMatrix1:
return "ReductionMatrix1"
case tReductionMatrix2:
return "ReductionMatrix2"
case tAsShotNeutral:
return "AsShotNeutral"
case tBaselineExposure:
return "BaselineExposure"
case tCalibrationIlluminant1:
return "CalibrationIlluminant1"
case tCalibrationIlluminant2:
return "CalibrationIlluminant2"
default:
return fmt.Sprintf("Unknown(%d)", t)
}
}
func valuename(t tag) string {
var v interface{}
switch t.id {
case tNewSubFileType:
switch t.firstVal() {
case sftPrimaryImage:
v = "Primary image"
case sftThumbnail:
v = "Thumbnail/Preview image"
default:
v = t.firstVal()
}
case tPhotometricInterpretation:
switch t.firstVal() {
case pWhiteIsZero:
v = "WhiteIsZero"
case pBlackIsZero:
v = "BlackIsZero"
case pRGB:
v = "RGB"
case pPaletted:
v = "Paletted"
case pTransMask:
v = "TransMask"
case pCMYK:
v = "CMYK"
case pYCbCr:
v = "YCbCr"
case pCIELab:
v = "CIE-Lab"
case pColorFilterArray:
v = "Color Filter Array"
case pLogL:
v = "LogL (GrayScale)"
case pLogLuv:
v = "SGI LogLuv (Color)"
default:
v = t.firstVal()
}
case tCompression:
switch t.firstVal() {
case cNone:
v = "None"
case cCCITT:
v = "CCITT"
case cG3:
v = "Group 3 Fax"
case cG4:
v = "Group 4 Fax"
case cLZW:
v = "LZW"
case cJPEGOld:
v = "Old JPEG"
case cJPEG:
v = "JPEG"
case cDeflate:
v = "Deflate (zlib compression)"
case cPackBits:
v = "PackBits"
case cDeflateOld:
v = "Old Deflate"
case cSGILogRLE:
v = "SGI Log Luminance RLE"
case cSGILog24Packed:
v = "SGI Log 24-bits packed"
case cLossyJPEG:
v = "Lossy JPEG"
default:
v = t.firstVal()
}
case tStripOffsets:
v = fmt.Sprintf("contains %d offset entries", len(t.val))
case tStripByteCounts:
v = fmt.Sprintf("contains %d byte-count entries", len(t.val))
case tSamplesPerPixel:
fallthrough
case tRowsPerStrip:
fallthrough
case tTileWidth:
fallthrough
case tTileLength:
fallthrough
case tImageLength:
fallthrough
case tImageWidth:
v = t.firstVal()
case tPlanarConfiguration:
switch t.firstVal() {
case 1:
v = "Contiguous (aka RGBRGBRGBRGB)"
case 2:
v = "Separate (aka RRRRGGGGBBBB)"
}
case tStonits:
v = math.Float64frombits(uint64(t.val[0]))
case tCFARepeatPatternDim:
v = fmt.Sprintf("%d CFARepeatRows, %d CFARepeatCols", t.val[0], t.val[1])
case tCFAPattern:
v = fmt.Sprintf("%v (%s%s%s%s)", t.val, cfaColors[t.val[0]], cfaColors[t.val[1]], cfaColors[t.val[2]], cfaColors[t.val[3]])
case tDNGVersion:
fallthrough
case tDNGBackwardVersion:
v = fmt.Sprintf("%d.%d.%d.%d", t.val[0], t.val[1], t.val[2], t.val[3])
case tCFALayout:
switch t.firstVal() {
case 1:
v = "Rectangular (or square) layout"
case 2:
v = "Staggered layout A: even columns are offset down by 1/2 row"
case 3:
v = "Staggered layout B: even columns are offset up by 1/2 row"
case 4:
v = "Staggered layout C: even rows are offset right by 1/2 column"
case 5:
v = "Staggered layout D: even rows are offset left by 1/2 column"
default:
v = t.firstVal()
}
case tCFAPlaneColor:
v = fmt.Sprintf("%v (%s%s%s)", t.val, cfaColors[t.val[0]], cfaColors[t.val[1]], cfaColors[t.val[2]])
case tBaselineExposure:
v = t.sRational(0)
default:
v = formatDatatype(t)
}
return fmt.Sprintf("%v", v)
}
func formatDatatype(t tag) interface{} {
switch t.datatype {
case dtRational:
sl := make([]*big.Rat, 0, len(t.val))
for i := range t.val {
sl = append(sl, t.rational(i))
}
return sl
case dtSRational:
sl := make([]*big.Rat, 0, len(t.val))
for i := range t.val {
sl = append(sl, t.sRational(i))
}
return sl
case dtDouble:
sl := make([]float64, 0, len(t.val))
for i := range t.val {
sl = append(sl, t.double(i))
}
return sl
default:
return t.val
}
}