This commit is contained in:
nuknal
2024-05-17 23:53:09 +08:00
parent 0d59c8514b
commit 5b3c4aa0a4
3 changed files with 196 additions and 160 deletions

69
extract/writer.go Normal file
View File

@@ -0,0 +1,69 @@
package extract
import (
"bufio"
"io"
"os"
"path/filepath"
"github.com/sirupsen/logrus"
)
const (
EB_AUX = "EB.AUX"
PLAT_AUX = "PLAT.AUX"
PAN_RAW = "PAN_RAW"
MSS_RAW = "MSS_RAW"
PAN_HDR = "PAN_HDR"
MSS_HDR = "MSS_HDR"
MSS_ALL_IN_ONE = "MSS_ALL_IN_ONE"
)
type l0w struct {
w *bufio.Writer
f *os.File
name string
}
type L0Writer struct {
mssStoredType string
ws map[string]*l0w
}
func newL0Writer(outputDir, name string) *L0Writer {
var err error
suffix := []string{EB_AUX, PLAT_AUX, PAN_RAW, MSS_RAW, PAN_HDR, MSS_HDR}
lw := &L0Writer{
ws: make(map[string]*l0w),
mssStoredType: MSS_ALL_IN_ONE,
}
for _, s := range suffix {
w := &l0w{}
w.name = filepath.Join(outputDir, name+"_"+s)
w.f, err = os.OpenFile(w.name, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
if err != nil {
logrus.Panic("create file failed: ", w.name, err)
}
w.w = bufio.NewWriter(w.f)
lw.ws[s] = w
}
return lw
}
func (lw *L0Writer) Close() {
for _, w := range lw.ws {
w.w.Flush()
w.f.Close()
}
}
// 写入 16 位像素值,小端序
func write16bPixelLittleEndian(w io.Writer, data []byte) (int, error) {
for i := 0; i < len(data)-1; i += 2 {
data[i], data[i+1] = data[i+1], data[i]
}
return w.Write(data)
}