pngstructure

package module
v2.0.1-SSB Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PngSignature  = [8]byte{137, 'P', 'N', 'G', '\r', '\n', 26, '\n'}
	EXifChunkType = "eXIf"
	IHDRChunkType = "IHDR"
)
View Source
var (
	ErrNotPng     = errors.New("not png data")
	ErrCrcFailure = errors.New("crc failure")
)

Functions

func DumpBytes

func DumpBytes(data []byte)

func DumpBytesClause

func DumpBytesClause(data []byte)

func DumpBytesClauseToString

func DumpBytesClauseToString(data []byte) (string, error)

func DumpBytesToString

func DumpBytesToString(data []byte) (string, error)

func NewPngMediaParser

func NewPngMediaParser() riimage.MediaParser

NewPngMediaParser returns a new `PngMediaParser`.

Types

type Chunk

type Chunk struct {
	Offset int
	Length uint32
	Type   string
	Data   []byte
	Crc    uint32
}

Chunk describes a single chunk.

func (*Chunk) Bytes

func (c *Chunk) Bytes() ([]byte, error)

Bytes encodes and returns the bytes for this chunk.

func (*Chunk) CheckCrc32

func (c *Chunk) CheckCrc32() bool

func (*Chunk) String

func (c *Chunk) String() string

func (*Chunk) UpdateCrc32

func (c *Chunk) UpdateCrc32()

func (*Chunk) WriteTo

func (c *Chunk) WriteTo(w io.Writer) (int, error)

Write encodes and writes the bytes for this chunk.

type ChunkDecoder

type ChunkDecoder struct {
}

func NewChunkDecoder

func NewChunkDecoder() *ChunkDecoder

func (*ChunkDecoder) Decode

func (cd *ChunkDecoder) Decode(c *Chunk) (decoded interface{}, err error)

type ChunkIHDR

type ChunkIHDR struct {
	Width             uint32
	Height            uint32
	BitDepth          uint8
	ColorType         uint8
	CompressionMethod uint8
	FilterMethod      uint8
	InterlaceMethod   uint8
}

func (*ChunkIHDR) String

func (ihdr *ChunkIHDR) String() string

type ChunkSlice

type ChunkSlice struct {
	// contains filtered or unexported fields
}

ChunkSlice encapsulates a slice of chunks.

func NewChunkSlice

func NewChunkSlice(chunks []*Chunk) (*ChunkSlice, error)

func NewPngChunkSlice

func NewPngChunkSlice() (*ChunkSlice, error)

func (*ChunkSlice) Chunks

func (cs *ChunkSlice) Chunks() []*Chunk

Chunks exposes the actual slice.

func (*ChunkSlice) ConstructExifBuilder

func (cs *ChunkSlice) ConstructExifBuilder() (*exif.IfdBuilder, error)

ConstructExifBuilder returns an `exif.IfdBuilder` instance (needed for modifying) preloaded with all existing tags.

func (*ChunkSlice) Exif

func (cs *ChunkSlice) Exif() (*exif.Ifd, []byte, error)

Exif returns an `exif.Ifd` instance with the existing tags.

func (*ChunkSlice) FindExif

func (cs *ChunkSlice) FindExif() (chunk *Chunk, err error)

FindExif returns the the segment that hosts the EXIF data.

func (*ChunkSlice) Index

func (cs *ChunkSlice) Index() (index map[string][]*Chunk)

Index returns a map of chunk types to chunk slices, grouping all like chunks.

func (*ChunkSlice) SetExif

func (cs *ChunkSlice) SetExif(ib *exif.IfdBuilder) error

SetExif encodes and sets EXIF data into this segment.

func (*ChunkSlice) String

func (cs *ChunkSlice) String() string

func (*ChunkSlice) WriteTo

func (cs *ChunkSlice) WriteTo(w io.Writer) error

Write encodes and writes all chunks.

type PngMediaParser

type PngMediaParser struct {
}

PngMediaParser knows how to parse a PNG stream.

func (*PngMediaParser) GetImage

func (pmp *PngMediaParser) GetImage(r io.Reader) (img image.Image, err error)

GetImage returns an image.Image-compatible struct.

func (*PngMediaParser) LooksLikeFormat

func (pmp *PngMediaParser) LooksLikeFormat(data []byte) bool

LooksLikeFormat returns a boolean indicating whether the stream looks like a PNG image.

func (*PngMediaParser) Parse

func (pmp *PngMediaParser) Parse(
	rs io.ReadSeeker,
	size int,
) (riimage.MediaContext, error)

Parse parses a PNG stream given a `io.ReadSeeker`.

func (*PngMediaParser) ParseBytes

func (pmp *PngMediaParser) ParseBytes(data []byte) (riimage.MediaContext, error)

ParseBytes parses a PNG stream given a byte-slice.

func (*PngMediaParser) ParseFile

func (pmp *PngMediaParser) ParseFile(filepath string) (riimage.MediaContext, error)

ParseFile parses a PNG stream given a file-path.

type PngSplitter

type PngSplitter struct {
	// contains filtered or unexported fields
}

PngSplitter hosts the princpal `Split()` method uses by `bufio.Scanner`.

func NewPngSplitter

func NewPngSplitter() *PngSplitter

func (*PngSplitter) Chunks

func (ps *PngSplitter) Chunks() (*ChunkSlice, error)

func (*PngSplitter) CrcErrors

func (ps *PngSplitter) CrcErrors() []string

func (*PngSplitter) DoCheckCrc

func (ps *PngSplitter) DoCheckCrc(doCheck bool)

func (*PngSplitter) Split

func (ps *PngSplitter) Split(
	data []byte,
	atEOF bool,
) (
	advance int,
	token []byte,
	err error,
)

Split fulfills the `bufio.SplitFunc` function definition for `bufio.Scanner`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL