-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdoc.go
159 lines (134 loc) · 7.02 KB
/
doc.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
// Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Package tiff offers a rich TIFF/BigTIFF/GeoTIFF decoder/encoder for Go.
The Classic TIFF specification is at http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
The Big TIFF specification is at http://www.remotesensing.org/libtiff/bigtiffdesign.html
The Geo TIFF specification is at http://www.remotesensing.org/geotiff/spec/geotiffhome.html
TIFF Tags: http://www.awaresystems.be/imaging/tiff/tifftags.html
Features:
1. Support BigTiff
2. Support decode multiple image
3. Support decode subifd image
4. Support RGB format
5. Support Float DataType
6. More ...
Example:
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"path/filepath"
tiff "github.com/chai2010/tiff"
)
func main() {
var data []byte
var err error
var files = []string{
"./testdata/BigTIFFSamples/BigTIFFSubIFD8.tif",
"./testdata/multipage/multipage-gopher.tif",
}
for _, filename := range files {
// Load file data
if data, err = ioutil.ReadFile(filename); err != nil {
log.Fatal(err)
}
// Decode tiff
m, errors, err := tiff.DecodeAll(bytes.NewReader(data))
if err != nil {
log.Println(err)
}
// Encode tiff
for i := 0; i < len(m); i++ {
for j := 0; j < len(m[i]); j++ {
newname := fmt.Sprintf("%s-%02d-%02d.tiff", filepath.Base(filename), i, j)
if errors[i][j] != nil {
log.Printf("%s: %v\n", newname, err)
continue
}
var buf bytes.Buffer
if err = tiff.Encode(&buf, m[i][j], nil); err != nil {
log.Fatal(err)
}
if err = ioutil.WriteFile(newname, buf.Bytes(), 0666); err != nil {
log.Fatal(err)
}
fmt.Printf("Save %s ok\n", newname)
}
}
}
}
Report bugs to <chaishushan@gmail.com>.
Thanks!
*/
package tiff
/*
The Classic TIFF specification is at http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
The Big TIFF specification is at http://www.remotesensing.org/libtiff/bigtiffdesign.html
The Geo TIFF specification is at http://www.remotesensing.org/geotiff/spec/geotiffhome.html
Classic TIFF Structure:
+------------------------------------------------------------------------------+
| Classic TIFF Structure |
| IFH |
| +-----------------+ |
| | II/MM ([2]byte) | |
| +-----------------+ |
| | 42 (uint16) | IFD |
| +-----------------+ +------------------+ |
| | Offset (uint32) |---->| Num (uint16) | |
| +-----------------+ +------------------+ |
| | Entry ([12]byte) | |
| +------------------+ |
| | Entry ([12]byte) | |
| +------------------+ |
| | ... | IFD |
| +------------------+ +------------------+ |
| IFD Entry | Offset (uint32) |--->| Num (uint16) | |
| +-----------------+ +------------------+ +------------------+ |
| | Tag (uint16) | | Entry ([12]byte) | |
| +-----------------+ +------------------+ |
| | Type (uint16) |<-------------------------| Entry ([12]byte) | |
| +-----------------+ +------------------+ |
| | Count (uint32) | | ... | |
| +-----------------+ +------------------+ |
| | Offset (uint32) |---> Value | Offset (uint32) |--->NULL |
| +-----------------+ +------------------+ |
| |
+------------------------------------------------------------------------------+
Big TIFF Structure:
+------------------------------------------------------------------------------+
| Big TIFF Structure |
| IFH |
| +-----------------+ |
| | II/MM ([2byte]) | |
| +-----------------+ |
| | 43 (uint16) | |
| +-----------------+ |
| | 8 (uint16) | |
| +-----------------+ |
| | 0 (uint16) | IFD |
| +-----------------+ +------------------+ |
| | Offset (uint64) |---->| Num (uint64) | |
| +-----------------+ +------------------+ |
| | Entry ([20]byte) | |
| +------------------+ |
| | Entry ([20]byte) | |
| +------------------+ |
| | ... | IFD |
| +------------------+ +------------------+ |
| IFD Entry | Offset (uint64) |--->| Num (uint64) | |
| +-----------------+ +------------------+ +------------------+ |
| | Tag (uint16) | | Entry ([12]byte) | |
| +-----------------+ +------------------+ |
| | Type (uint16) |<-------------------------| Entry ([12]byte) | |
| +-----------------+ +------------------+ |
| | Count (uint64) | | ... | |
| +-----------------+ +------------------+ |
| | Offset (uint64) |---> Value | Offset (uint64) |--->NULL |
| +-----------------+ +------------------+ |
| |
+------------------------------------------------------------------------------+
*/