Imports #
"compress/zlib"
"encoding/binary"
"fmt"
"hash"
"hash/crc32"
"image"
"image/color"
"io"
"bufio"
"compress/zlib"
"encoding/binary"
"hash/crc32"
"image"
"image/color"
"io"
"strconv"
"compress/zlib"
"encoding/binary"
"fmt"
"hash"
"hash/crc32"
"image"
"image/color"
"io"
"bufio"
"compress/zlib"
"encoding/binary"
"hash/crc32"
"image"
"image/color"
"io"
"strconv"
const BestCompression CompressionLevel = *ast.UnaryExpr
const BestSpeed CompressionLevel = *ast.UnaryExpr
const DefaultCompression CompressionLevel = 0
const NoCompression CompressionLevel = *ast.UnaryExpr
A cb is a combination of color type and bit depth.
const cbG1
A cb is a combination of color type and bit depth.
const cbG16
A cb is a combination of color type and bit depth.
const cbG2
A cb is a combination of color type and bit depth.
const cbG4
A cb is a combination of color type and bit depth.
const cbG8
A cb is a combination of color type and bit depth.
const cbGA16
A cb is a combination of color type and bit depth.
const cbGA8
A cb is a combination of color type and bit depth.
const cbInvalid = iota
A cb is a combination of color type and bit depth.
const cbP1
A cb is a combination of color type and bit depth.
const cbP2
A cb is a combination of color type and bit depth.
const cbP4
A cb is a combination of color type and bit depth.
const cbP8
A cb is a combination of color type and bit depth.
const cbTC16
A cb is a combination of color type and bit depth.
const cbTC8
A cb is a combination of color type and bit depth.
const cbTCA16
A cb is a combination of color type and bit depth.
const cbTCA8
var chunkOrderError = *ast.CallExpr
Color type, as per the PNG spec.
const ctGrayscale = 0
Color type, as per the PNG spec.
const ctGrayscaleAlpha = 4
Color type, as per the PNG spec.
const ctPaletted = 3
Color type, as per the PNG spec.
const ctTrueColor = 2
Color type, as per the PNG spec.
const ctTrueColorAlpha = 6
Decoding stage. The PNG specification says that the IHDR, PLTE (if present), tRNS (if present), IDAT and IEND chunks must appear in that order. There may be multiple IDAT chunks, and IDAT chunks must be sequential (i.e. they may not have any other chunks between them). https://www.w3.org/TR/PNG/#5ChunkOrdering
const dsSeenIDAT
Decoding stage. The PNG specification says that the IHDR, PLTE (if present), tRNS (if present), IDAT and IEND chunks must appear in that order. There may be multiple IDAT chunks, and IDAT chunks must be sequential (i.e. they may not have any other chunks between them). https://www.w3.org/TR/PNG/#5ChunkOrdering
const dsSeenIEND
Decoding stage. The PNG specification says that the IHDR, PLTE (if present), tRNS (if present), IDAT and IEND chunks must appear in that order. There may be multiple IDAT chunks, and IDAT chunks must be sequential (i.e. they may not have any other chunks between them). https://www.w3.org/TR/PNG/#5ChunkOrdering
const dsSeenIHDR
Decoding stage. The PNG specification says that the IHDR, PLTE (if present), tRNS (if present), IDAT and IEND chunks must appear in that order. There may be multiple IDAT chunks, and IDAT chunks must be sequential (i.e. they may not have any other chunks between them). https://www.w3.org/TR/PNG/#5ChunkOrdering
const dsSeenPLTE
Decoding stage. The PNG specification says that the IHDR, PLTE (if present), tRNS (if present), IDAT and IEND chunks must appear in that order. There may be multiple IDAT chunks, and IDAT chunks must be sequential (i.e. they may not have any other chunks between them). https://www.w3.org/TR/PNG/#5ChunkOrdering
const dsSeentRNS
Decoding stage. The PNG specification says that the IHDR, PLTE (if present), tRNS (if present), IDAT and IEND chunks must appear in that order. There may be multiple IDAT chunks, and IDAT chunks must be sequential (i.e. they may not have any other chunks between them). https://www.w3.org/TR/PNG/#5ChunkOrdering
const dsStart = iota
Filter type, as per the PNG spec.
const ftAverage = 3
Filter type, as per the PNG spec.
const ftNone = 0
Filter type, as per the PNG spec.
const ftPaeth = 4
Filter type, as per the PNG spec.
const ftSub = 1
Filter type, as per the PNG spec.
const ftUp = 2
intSize is either 32 or 64.
const intSize = *ast.BinaryExpr
interlacing defines Adam7 interlacing, with 7 passes of reduced images. See https://www.w3.org/TR/PNG/#8Interlace
var interlacing = []interlaceScan{...}
Interlace type.
const itAdam7 = 1
Interlace type.
const itNone = 0
Filter type, as per the PNG spec.
const nFilter = 5
const pngHeader = "\x89PNG\r\n\x1a\n"
CompressionLevel indicates the compression level.
type CompressionLevel int
EncoderBuffer holds the buffers used for encoding PNG images.
type EncoderBuffer encoder
A FormatError reports that the input is not a valid PNG.
type FormatError string
An UnsupportedError reports that the input uses a valid but unimplemented PNG feature.
type UnsupportedError string
EncoderBufferPool is an interface for getting and returning temporary instances of the [EncoderBuffer] struct. This can be used to reuse buffers when encoding multiple images.
type EncoderBufferPool interface {
Get() *EncoderBuffer
Put(*EncoderBuffer)
}
type opaquer interface {
Opaque() bool
}
Encoder configures encoding PNG images.
type Encoder struct {
CompressionLevel CompressionLevel
BufferPool EncoderBufferPool
}
type decoder struct {
r io.Reader
img image.Image
crc hash.Hash32
width int
height int
depth int
palette color.Palette
cb int
stage int
idatLength uint32
tmp [*ast.BinaryExpr]byte
interlace int
useTransparent bool
transparent [6]byte
}
type encoder struct {
enc *Encoder
w io.Writer
m image.Image
cb int
err error
header [8]byte
footer [4]byte
tmp [*ast.BinaryExpr]byte
cr [nFilter][]uint8
pr []uint8
zw *zlib.Writer
zwLevel int
bw *bufio.Writer
}
interlaceScan defines the placement and size of a pass for Adam7 interlacing.
type interlaceScan struct {
xFactor int
yFactor int
xOffset int
yOffset int
}
Decode reads a PNG image from r and returns it as an [image.Image]. The type of Image returned depends on the PNG contents.
func Decode(r io.Reader) (image.Image, error)
DecodeConfig returns the color model and dimensions of a PNG image without decoding the entire image.
func DecodeConfig(r io.Reader) (image.Config, error)
Encode writes the Image m to w in PNG format.
func (enc *Encoder) Encode(w io.Writer, m image.Image) error
Encode writes the Image m to w in PNG format. Any Image may be encoded, but images that are not [image.NRGBA] might be encoded lossily.
func Encode(w io.Writer, m image.Image) error
func (e FormatError) Error() string
func (e UnsupportedError) Error() string
Read presents one or more IDAT chunks as one continuous stream (minus the intermediate chunk headers and footers). If the PNG data looked like: ... len0 IDAT xxx crc0 len1 IDAT yy crc1 len2 IEND crc2 then this reader presents xxxyy. For well-formed PNG data, the decoder state immediately before the first Read call is that d.r is positioned between the first IDAT and xxx, and the decoder state immediately after the last Read call is that d.r is positioned between yy and crc1.
func (d *decoder) Read(p []byte) (int, error)
An encoder is an io.Writer that satisfies writes by writing PNG IDAT chunks, including an 8-byte header and 4-byte CRC checksum per Write call. Such calls should be relatively infrequent, since writeIDATs uses a [bufio.Writer]. This method should only be called from writeIDATs (via writeImage). No other code should treat an encoder as an io.Writer.
func (e *encoder) Write(b []byte) (int, error)
func abs(x int) int
The absolute value of a byte interpreted as a signed int8.
func abs8(d uint8) int
func cbPaletted(cb int) bool
func cbTrueColor(cb int) bool
func (d *decoder) checkHeader() error
decode decodes the IDAT data into an image.
func (d *decoder) decode() (image.Image, error)
Chooses the filter to use for encoding the current row, and applies it. The return value is the index of the filter and also of the row in cr that has had it applied.
func filter(cr *[nFilter][]byte, pr []byte, bpp int) int
filterPaeth applies the Paeth filter to the cdat slice. cdat is the current row's data, pdat is the previous row's data.
func filterPaeth(cdat []byte, pdat []byte, bytesPerPixel int)
func init()
This function is required because we want the zero value of Encoder.CompressionLevel to map to zlib.DefaultCompression.
func levelToZlib(l CompressionLevel) int
mergePassInto merges a single pass into a full sized image.
func (d *decoder) mergePassInto(dst image.Image, src image.Image, pass int)
Returns whether or not the image is fully opaque.
func opaque(m image.Image) bool
paeth implements the Paeth filter function, as per the PNG specification.
func paeth(a uint8, b uint8, c uint8) uint8
func (d *decoder) parseChunk(configOnly bool) error
func (d *decoder) parseIDAT(length uint32) (err error)
func (d *decoder) parseIEND(length uint32) error
func (d *decoder) parseIHDR(length uint32) error
func (d *decoder) parsePLTE(length uint32) error
func (d *decoder) parsetRNS(length uint32) error
readImagePass reads a single image pass, sized according to the pass number.
func (d *decoder) readImagePass(r io.Reader, pass int, allocateOnly bool) (image.Image, error)
func (d *decoder) verifyChecksum() error
func (e *encoder) writeChunk(b []byte, name string)
Write the actual image data to one or more IDAT chunks.
func (e *encoder) writeIDATs()
func (e *encoder) writeIEND()
func (e *encoder) writeIHDR()
func (e *encoder) writeImage(w io.Writer, m image.Image, cb int, level int) error
func (e *encoder) writePLTEAndTRNS(p color.Palette)
Generated with Arrow