Very nice looking tests!
Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
parent
3b41c9dd5f
commit
c1a45bf8e3
149 changed files with 1241 additions and 443 deletions
102
vendor/github.com/dsoprea/go-png-image-structure/chunk_decoder.go
generated
vendored
102
vendor/github.com/dsoprea/go-png-image-structure/chunk_decoder.go
generated
vendored
|
@ -1,87 +1,89 @@
|
|||
package pngstructure
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"fmt"
|
||||
"bytes"
|
||||
|
||||
"encoding/binary"
|
||||
"encoding/binary"
|
||||
|
||||
log "github.com/dsoprea/go-logging"
|
||||
"github.com/dsoprea/go-logging"
|
||||
)
|
||||
|
||||
type ChunkDecoder struct {
|
||||
|
||||
}
|
||||
|
||||
func NewChunkDecoder() *ChunkDecoder {
|
||||
return new(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)
|
||||
}
|
||||
}()
|
||||
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)
|
||||
switch c.Type {
|
||||
case "IHDR":
|
||||
ihdr, err := cd.decodeIHDR(c)
|
||||
log.PanicIf(err)
|
||||
|
||||
return ihdr, nil
|
||||
}
|
||||
return ihdr, nil
|
||||
}
|
||||
|
||||
// We don't decode this particular type.
|
||||
return nil, 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
|
||||
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)
|
||||
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)
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err := log.Wrap(state.(error))
|
||||
log.Panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
b := bytes.NewBuffer(c.Data)
|
||||
b := bytes.NewBuffer(c.Data)
|
||||
|
||||
ihdr = new(ChunkIHDR)
|
||||
ihdr = new(ChunkIHDR)
|
||||
|
||||
err = binary.Read(b, binary.BigEndian, &ihdr.Width)
|
||||
log.PanicIf(err)
|
||||
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.Height)
|
||||
log.PanicIf(err)
|
||||
|
||||
err = binary.Read(b, binary.BigEndian, &ihdr.BitDepth)
|
||||
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.ColorType)
|
||||
log.PanicIf(err)
|
||||
|
||||
err = binary.Read(b, binary.BigEndian, &ihdr.CompressionMethod)
|
||||
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.FilterMethod)
|
||||
log.PanicIf(err)
|
||||
|
||||
err = binary.Read(b, binary.BigEndian, &ihdr.InterlaceMethod)
|
||||
log.PanicIf(err)
|
||||
err = binary.Read(b, binary.BigEndian, &ihdr.InterlaceMethod)
|
||||
log.PanicIf(err)
|
||||
|
||||
return ihdr, nil
|
||||
return ihdr, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue