Skip to content

Commit 12e5813

Browse files
committed
remove unwanted structs/functions from public facing API
1 parent e1d1574 commit 12e5813

File tree

4 files changed

+149
-131
lines changed

4 files changed

+149
-131
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Cogger is a standalone binary and a golang library that reads an internally tiled geotiff (optionally with overviews and masks)
66
and rewrites it as a [Cloud Optimized Geotiff (COG)](https://www.cogeo.org). This process being a reshuffling of the original
7-
geotiff's bytes, it is very efficient and runs as fast as the underlying i/o.
7+
geotiff's bytes, it should run as fast as the underlying disk or network i/o.
88

99
Cogger does not do any pixel manipulation on the provided image, it is up to you to provide an input geotiff which can be suitably
1010
transformed to a COG, namely:
@@ -60,13 +60,31 @@ streamed to http/cloud storage without having to be stored in an intermediate fi
6060

6161
For an full example of library usage, see the `main.go` file in `cmd/cogger`.
6262

63+
### Advanced
64+
65+
Cogger is able to assemble a single COG from a main tif file and overviews that have been computed
66+
in distinct files. This may be useful as `gdaladdo` is missing some features to fine tune the options
67+
of each individual overview.
68+
69+
```bash
70+
gdal_translate -of GTIFF -co BIGTIFF=YES -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 input.file geotif.tif
71+
# compute first overview
72+
gdal_translate -of GTIFF -outsize 50% 50% -co BLOCKXSIZE=128 -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 geotif.tif ovr.tif.1
73+
# compute second overview
74+
gdal_translate -of GTIFF -outsize 50% 50% -co BLOCKXSIZE=256 -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 ovr.tif.1 ovr.tif.2
75+
# compute third overview
76+
gdal_translate -of GTIFF -outsize 50% 50% -co BLOCKXSIZE=512 -co TILED=YES -co COMPRESS=ZSTD -co NUM_THREADS=4 ovr.tif.2 ovr.tif.3
77+
# compute COG from geotif.tif and ovr.tif.* overviews
78+
cogger -output mycog.tif geotif.tif ovr.tif.1 ovr.tif.2 ovr.tif.3
79+
```
80+
6381
## Contributing
6482

6583
Contributions are welcome. Please read the [contribution guidelines](CONTRIBUTING.md)
6684
before submitting fixes or enhancements.
6785

6886
## Licensing
69-
cogger is licensed under the Apache License, Version 2.0. See
87+
Cogger is licensed under the Apache License, Version 2.0. See
7088
[LICENSE](https://github.com/airbusgeo/cogger/blob/main/LICENSE) for the full
7189
license text.
7290

cog.go

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,67 @@ import (
1010
_ "github.com/google/tiff/bigtiff"
1111
)
1212

13-
type SubfileType uint32
13+
type subfileType uint32
1414

1515
const (
16-
SubfileTypeNone = 0
17-
SubfileTypeReducedImage = 1
18-
SubfileTypePage = 2
19-
SubfileTypeMask = 4
16+
subfileTypeNone = 0
17+
subfileTypeReducedImage = 1
18+
subfileTypePage = 2
19+
subfileTypeMask = 4
2020
)
2121

22-
type PlanarConfiguration uint16
22+
type planarConfiguration uint16
2323

2424
const (
25-
PlanarConfigurationContig = 1
26-
PlanarConfigurationSeparate = 2
25+
planarConfigurationContig = 1
26+
planarConfigurationSeparate = 2
2727
)
2828

29-
type Predictor uint16
29+
type predictor uint16
3030

3131
const (
32-
PredictorNone = 1
33-
PredictorHorizontal = 2
34-
PredictorFloatingPoint = 3
32+
predictorNone = 1
33+
predictorHorizontal = 2
34+
predictorFloatingPoint = 3
3535
)
3636

37-
type SampleFormat uint16
37+
type sampleFormat uint16
3838

3939
const (
40-
SampleFormatUInt = 1
41-
SampleFormatInt = 2
42-
SampleFormatIEEEFP = 3
43-
SampleFormatVoid = 4
44-
SampleFormatComplexInt = 5
45-
SampleFormatComplexIEEEFP = 6
40+
sampleFormatUInt = 1
41+
sampleFormatInt = 2
42+
sampleFormatIEEEFP = 3
43+
sampleFormatVoid = 4
44+
sampleFormatComplexInt = 5
45+
sampleFormatComplexIEEEFP = 6
4646
)
4747

48-
type ExtraSamples uint16
48+
type extraSamples uint16
4949

5050
const (
51-
ExtraSamplesUnspecified = 0
52-
ExtraSamplesAssocAlpha = 1
53-
ExtraSamplesUnassAlpha = 2
51+
extraSamplesUnspecified = 0
52+
extraSamplesAssocAlpha = 1
53+
extraSamplesUnassAlpha = 2
5454
)
5555

56-
type PhotometricInterpretation uint16
56+
type photometricInterpretation uint16
5757

5858
const (
59-
PhotometricInterpretationMinIsWhite = 0
60-
PhotometricInterpretationMinIsBlack = 1
61-
PhotometricInterpretationRGB = 2
62-
PhotometricInterpretationPalette = 3
63-
PhotometricInterpretationMask = 4
64-
PhotometricInterpretationSeparated = 5
65-
PhotometricInterpretationYCbCr = 6
66-
PhotometricInterpretationCIELab = 8
67-
PhotometricInterpretationICCLab = 9
68-
PhotometricInterpretationITULab = 10
69-
PhotometricInterpretationLOGL = 32844
70-
PhotometricInterpretationLOGLUV = 32845
59+
photometricInterpretationMinIsWhite = 0
60+
photometricInterpretationMinIsBlack = 1
61+
photometricInterpretationRGB = 2
62+
photometricInterpretationPalette = 3
63+
photometricInterpretationMask = 4
64+
photometricInterpretationSeparated = 5
65+
photometricInterpretationYCbCr = 6
66+
photometricInterpretationCIELab = 8
67+
photometricInterpretationICCLab = 9
68+
photometricInterpretationITULab = 10
69+
photometricInterpretationLOGL = 32844
70+
photometricInterpretationLOGLUV = 32845
7171
)
7272

73-
type IFD struct {
73+
type ifd struct {
7474
//Any field added here should also be accounted for in WriteIFD and ifd.Fieldcount
7575
SubfileType uint32 `tiff:"field,tag=254"`
7676
ImageWidth uint64 `tiff:"field,tag=256"`
@@ -106,8 +106,8 @@ type IFD struct {
106106
LERCParams []uint32 `tiff:"field,tag=50674"`
107107
RPCs []float64 `tiff:"field,tag=50844"`
108108

109-
overview *IFD
110-
masks []*IFD
109+
overview *ifd
110+
masks []*ifd
111111

112112
ntags uint64
113113
ntilesx, ntilesy uint64
@@ -131,8 +131,8 @@ func (ifd *IFD) StrileSize() uint64 {
131131
}
132132
*/
133133

134-
func (ifd *IFD) AddOverview(ovr *IFD) {
135-
ovr.SubfileType = SubfileTypeReducedImage
134+
func (ifd *ifd) AddOverview(ovr *ifd) {
135+
ovr.SubfileType = subfileTypeReducedImage
136136
ovr.ModelPixelScaleTag = nil
137137
ovr.ModelTiePointTag = nil
138138
ovr.ModelTransformationTag = nil
@@ -141,15 +141,15 @@ func (ifd *IFD) AddOverview(ovr *IFD) {
141141
ovr.GeoKeyDirectoryTag = nil
142142
ifd.overview = ovr
143143
}
144-
func (ifd *IFD) AddMask(msk *IFD) error {
144+
func (ifd *ifd) AddMask(msk *ifd) error {
145145
if len(msk.masks) > 0 || msk.overview != nil {
146146
return fmt.Errorf("cannot add mask with overviews or masks")
147147
}
148148
switch ifd.SubfileType {
149-
case SubfileTypeNone:
150-
msk.SubfileType = SubfileTypeMask
151-
case SubfileTypeReducedImage:
152-
msk.SubfileType = SubfileTypeMask | SubfileTypeReducedImage
149+
case subfileTypeNone:
150+
msk.SubfileType = subfileTypeMask
151+
case subfileTypeReducedImage:
152+
msk.SubfileType = subfileTypeMask | subfileTypeReducedImage
153153
default:
154154
return fmt.Errorf("invalid subfiledtype")
155155
}
@@ -163,7 +163,7 @@ func (ifd *IFD) AddMask(msk *IFD) error {
163163
return nil
164164
}
165165

166-
func (ifd *IFD) structure(bigtiff bool) (tagCount, ifdSize, strileSize uint64) {
166+
func (ifd *ifd) structure(bigtiff bool) (tagCount, ifdSize, strileSize uint64) {
167167
cnt := uint64(0)
168168
size := uint64(16) //8 for field count + 8 for next ifd offset
169169
tagSize := uint64(20)
@@ -298,26 +298,26 @@ func (ifd *IFD) structure(bigtiff bool) (tagCount, ifdSize, strileSize uint64) {
298298
return cnt, size, strileSize
299299
}
300300

301-
type TagData struct {
301+
type tagData struct {
302302
bytes.Buffer
303303
Offset uint64
304304
}
305305

306-
func (t *TagData) NextOffset() uint64 {
306+
func (t *tagData) NextOffset() uint64 {
307307
return t.Offset + uint64(t.Buffer.Len())
308308
}
309309

310-
type COG struct {
310+
type cog struct {
311311
enc binary.ByteOrder
312-
ifd *IFD
312+
ifd *ifd
313313
bigtiff bool
314314
}
315315

316-
func New() *COG {
317-
return &COG{enc: binary.LittleEndian}
316+
func new() *cog {
317+
return &cog{enc: binary.LittleEndian}
318318
}
319319

320-
func (cog *COG) writeHeader(w io.Writer) error {
320+
func (cog *cog) writeHeader(w io.Writer) error {
321321
if cog.bigtiff {
322322
buf := [16]byte{}
323323
if cog.enc == binary.LittleEndian {
@@ -346,24 +346,24 @@ func (cog *COG) writeHeader(w io.Writer) error {
346346
}
347347

348348
const (
349-
TByte = 1
350-
TAscii = 2
351-
TShort = 3
352-
TLong = 4
353-
TRational = 5
354-
TSByte = 6
355-
TUndefined = 7
356-
TSShort = 8
357-
TSLong = 9
358-
TSRational = 10
359-
TFloat = 11
360-
TDouble = 12
361-
TLong8 = 16
362-
TSLong8 = 17
363-
TIFD8 = 18
349+
tByte = 1
350+
tAscii = 2
351+
tShort = 3
352+
tLong = 4
353+
tRational = 5
354+
tSByte = 6
355+
tUndefined = 7
356+
tSShort = 8
357+
tSLong = 9
358+
tSRational = 10
359+
tFloat = 11
360+
tDouble = 12
361+
tLong8 = 16
362+
tSLong8 = 17
363+
tIFD8 = 18
364364
)
365365

366-
func (cog *COG) computeStructure() {
366+
func (cog *cog) computeStructure() {
367367
ifd := cog.ifd
368368
for ifd != nil {
369369
ifd.ntags, ifd.tagsSize, ifd.strileSize = ifd.structure(cog.bigtiff)
@@ -382,7 +382,7 @@ func (cog *COG) computeStructure() {
382382
}
383383
}
384384

385-
func (cog *COG) computeImageryOffsets() error {
385+
func (cog *cog) computeImageryOffsets() error {
386386
ifd := cog.ifd
387387
for ifd != nil {
388388
if cog.bigtiff {
@@ -423,7 +423,7 @@ func (cog *COG) computeImageryOffsets() error {
423423
}
424424

425425
datas := cog.dataInterlacing()
426-
tiles := datas.Tiles()
426+
tiles := datas.tiles()
427427
for tile := range tiles {
428428
tileidx := tile.x + tile.y*tile.ifd.ntilesx
429429
cnt := uint64(tile.ifd.TileByteCounts[tileidx])
@@ -451,7 +451,7 @@ func (cog *COG) computeImageryOffsets() error {
451451
return nil
452452
}
453453

454-
func (cog *COG) Write(out io.Writer) error {
454+
func (cog *cog) write(out io.Writer) error {
455455

456456
err := cog.computeImageryOffsets()
457457
if err != nil {
@@ -460,7 +460,7 @@ func (cog *COG) Write(out io.Writer) error {
460460

461461
//compute start of strile data, and offsets to subIFDs
462462
//striles are placed after all ifds
463-
strileData := &TagData{Offset: 16}
463+
strileData := &tagData{Offset: 16}
464464
if !cog.bigtiff {
465465
strileData.Offset = 8
466466
}
@@ -504,7 +504,7 @@ func (cog *COG) Write(out io.Writer) error {
504504
}
505505

506506
datas := cog.dataInterlacing()
507-
tiles := datas.Tiles()
507+
tiles := datas.tiles()
508508
buf := &bytes.Buffer{}
509509
for tile := range tiles {
510510
buf.Reset()
@@ -525,7 +525,7 @@ func (cog *COG) Write(out io.Writer) error {
525525
return err
526526
}
527527

528-
func (cog *COG) writeIFD(w io.Writer, ifd *IFD, offset uint64, striledata *TagData, next bool) error {
528+
func (cog *cog) writeIFD(w io.Writer, ifd *ifd, offset uint64, striledata *tagData, next bool) error {
529529

530530
nextOff := uint64(0)
531531
if next {
@@ -534,7 +534,7 @@ func (cog *COG) writeIFD(w io.Writer, ifd *IFD, offset uint64, striledata *TagDa
534534
var err error
535535
// Make space for "pointer area" containing IFD entry data
536536
// longer than 4 bytes.
537-
overflow := &TagData{
537+
overflow := &tagData{
538538
Offset: offset + 8 + 20*ifd.ntags + 8,
539539
}
540540
if !cog.bigtiff {
@@ -787,33 +787,33 @@ func (cog *COG) writeIFD(w io.Writer, ifd *IFD, offset uint64, striledata *TagDa
787787
}
788788

789789
type tile struct {
790-
ifd *IFD
790+
ifd *ifd
791791
x, y uint64
792792
}
793793

794-
type datas [][]*IFD
794+
type datas [][]*ifd
795795

796-
func (cog *COG) dataInterlacing() datas {
796+
func (cog *cog) dataInterlacing() datas {
797797
//count overviews
798-
ifd := cog.ifd
798+
ifdo := cog.ifd
799799
count := 0
800-
for ifd != nil {
800+
for ifdo != nil {
801801
count++
802-
ifd = ifd.overview
802+
ifdo = ifdo.overview
803803
}
804-
ret := make([][]*IFD, count)
805-
ifd = cog.ifd
804+
ret := make([][]*ifd, count)
805+
ifdo = cog.ifd
806806
for idx := count - 1; idx >= 0; idx-- {
807-
ret[idx] = append(ret[idx], ifd)
808-
for _, mi := range ifd.masks {
807+
ret[idx] = append(ret[idx], ifdo)
808+
for _, mi := range ifdo.masks {
809809
ret[idx] = append(ret[idx], mi)
810810
}
811-
ifd = ifd.overview
811+
ifdo = ifdo.overview
812812
}
813813
return ret
814814
}
815815

816-
func (d datas) Tiles() chan tile {
816+
func (d datas) tiles() chan tile {
817817
ch := make(chan tile)
818818
go func() {
819819
defer close(ch)

0 commit comments

Comments
 (0)