diff options
author | 2021-08-12 21:03:24 +0200 | |
---|---|---|
committer | 2021-08-12 21:03:24 +0200 | |
commit | 98263a7de64269898a2f81207e38943b5c8e8653 (patch) | |
tree | 743c90f109a6c5d27832d1dcef2388d939f0f77a /vendor/github.com/dsoprea/go-png-image-structure/chunk_decoder.go | |
parent | Text duplication fix (#137) (diff) | |
download | gotosocial-98263a7de64269898a2f81207e38943b5c8e8653.tar.xz |
Grand test fixup (#138)
* start fixing up tests
* fix up tests + automate with drone
* fiddle with linting
* messing about with drone.yml
* some more fiddling
* hmmm
* add cache
* add vendor directory
* verbose
* ci updates
* update some little things
* update sig
Diffstat (limited to 'vendor/github.com/dsoprea/go-png-image-structure/chunk_decoder.go')
-rw-r--r-- | vendor/github.com/dsoprea/go-png-image-structure/chunk_decoder.go | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/github.com/dsoprea/go-png-image-structure/chunk_decoder.go b/vendor/github.com/dsoprea/go-png-image-structure/chunk_decoder.go new file mode 100644 index 000000000..1358c3df2 --- /dev/null +++ b/vendor/github.com/dsoprea/go-png-image-structure/chunk_decoder.go @@ -0,0 +1,89 @@ +package pngstructure + +import ( + "fmt" + "bytes" + + "encoding/binary" + + "github.com/dsoprea/go-logging" +) + +type ChunkDecoder struct { + +} + +func NewChunkDecoder() *ChunkDecoder { + return new(ChunkDecoder) +} + +func (cd *ChunkDecoder) Decode(c *Chunk) (decoded interface{}, err error) { + defer func() { + if state := recover(); state != nil { + err := log.Wrap(state.(error)) + log.Panic(err) + } + }() + + switch c.Type { + case "IHDR": + ihdr, err := cd.decodeIHDR(c) + log.PanicIf(err) + + return ihdr, nil + } + + // We don't decode this particular type. + return nil, nil +} + + +type ChunkIHDR struct { + Width uint32 + Height uint32 + BitDepth uint8 + ColorType uint8 + CompressionMethod uint8 + FilterMethod uint8 + InterlaceMethod uint8 +} + +func (ihdr *ChunkIHDR) String() string { + return fmt.Sprintf("IHDR<WIDTH=(%d) HEIGHT=(%d) DEPTH=(%d) COLOR-TYPE=(%d) COMP-METHOD=(%d) FILTER-METHOD=(%d) INTRLC-METHOD=(%d)>", ihdr.Width, ihdr.Height, ihdr.BitDepth, ihdr.ColorType, ihdr.CompressionMethod, ihdr.FilterMethod, ihdr.InterlaceMethod) +} + +func (cd *ChunkDecoder) decodeIHDR(c *Chunk) (ihdr *ChunkIHDR, err error) { + defer func() { + if state := recover(); state != nil { + err := log.Wrap(state.(error)) + log.Panic(err) + } + }() + + b := bytes.NewBuffer(c.Data) + + ihdr = new(ChunkIHDR) + + err = binary.Read(b, binary.BigEndian, &ihdr.Width) + log.PanicIf(err) + + err = binary.Read(b, binary.BigEndian, &ihdr.Height) + log.PanicIf(err) + + err = binary.Read(b, binary.BigEndian, &ihdr.BitDepth) + log.PanicIf(err) + + err = binary.Read(b, binary.BigEndian, &ihdr.ColorType) + log.PanicIf(err) + + err = binary.Read(b, binary.BigEndian, &ihdr.CompressionMethod) + log.PanicIf(err) + + err = binary.Read(b, binary.BigEndian, &ihdr.FilterMethod) + log.PanicIf(err) + + err = binary.Read(b, binary.BigEndian, &ihdr.InterlaceMethod) + log.PanicIf(err) + + return ihdr, nil +} |