Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeGIF(images []image.Image, delays []int) ([]byte, error)
- func EncodeGIFWithOptions(images []image.Image, opts EncodeOptions) ([]byte, error)
- func MAXCODE(nBits int) int
- type ByteArray
- type DitherMethod
- type DitheringKernel
- type EncodeOptions
- type GIFEncoder
- func (ge *GIFEncoder) AddFrame(img image.Image) error
- func (ge *GIFEncoder) Cleanup()
- func (ge *GIFEncoder) CleanupAll()
- func (ge *GIFEncoder) Finish()
- func (ge *GIFEncoder) GetData() []byte
- func (ge *GIFEncoder) GetGlobalPalette() []byte
- func (ge *GIFEncoder) SetColorEnhancement(saturationBoost, contrastBoost float64)
- func (ge *GIFEncoder) SetDelay(milliseconds int)
- func (ge *GIFEncoder) SetDispose(disposalCode int)
- func (ge *GIFEncoder) SetDither(method interface{})
- func (ge *GIFEncoder) SetFrameRate(fps int)
- func (ge *GIFEncoder) SetGlobalPalette(palette []byte)
- func (ge *GIFEncoder) SetQuality(quality int)
- func (ge *GIFEncoder) SetRepeat(repeat int)
- func (ge *GIFEncoder) SetTransparent(c *color.RGBA)
- func (ge *GIFEncoder) Stream() *ByteArray
- type LZWEncoder
- type NeuQuant
Constants ¶
const ( EOF = -1 BITS = 12 HSIZE = 5003 // 80% occupancy )
Variables ¶
var ( // FalseFloydSteinberg 抖动核心 FalseFloydSteinberg = DitheringKernel{ {3.0 / 8.0, 1, 0}, {3.0 / 8.0, 0, 1}, {2.0 / 8.0, 1, 1}, } // FloydSteinberg 抖动核心(最常用) FloydSteinberg = DitheringKernel{ {7.0 / 16.0, 1, 0}, {3.0 / 16.0, -1, 1}, {5.0 / 16.0, 0, 1}, {1.0 / 16.0, 1, 1}, } // Stucki 抖动核心 Stucki = DitheringKernel{ {8.0 / 42.0, 1, 0}, {4.0 / 42.0, 2, 0}, {2.0 / 42.0, -2, 1}, {4.0 / 42.0, -1, 1}, {8.0 / 42.0, 0, 1}, {4.0 / 42.0, 1, 1}, {2.0 / 42.0, 2, 1}, {1.0 / 42.0, -2, 2}, {2.0 / 42.0, -1, 2}, {4.0 / 42.0, 0, 2}, {2.0 / 42.0, 1, 2}, {1.0 / 42.0, 2, 2}, } // Atkinson 抖动核心 Atkinson = DitheringKernel{ {1.0 / 8.0, 1, 0}, {1.0 / 8.0, 2, 0}, {1.0 / 8.0, -1, 1}, {1.0 / 8.0, 0, 1}, {1.0 / 8.0, 1, 1}, {1.0 / 8.0, 0, 2}, } )
预定义的抖动核心
Functions ¶
func EncodeGIF ¶
EncodeGIF is a convenience function to quickly encode multiple images into a GIF images: slice of images to encode delays: slice of delays in milliseconds for each frame
func EncodeGIFWithOptions ¶
func EncodeGIFWithOptions(images []image.Image, opts EncodeOptions) ([]byte, error)
EncodeGIFWithOptions encodes images with custom options
Types ¶
type ByteArray ¶
type ByteArray struct {
// contains filtered or unexported fields
}
ByteArray implements a growing byte buffer similar to the JavaScript version
func NewByteArray ¶
func NewByteArray() *ByteArray
NewByteArray creates a new ByteArray with default page size
func (*ByteArray) GetPageSize ¶
GetPageSize returns the page size
func (*ByteArray) WriteBytes ¶
WriteBytes writes a byte slice to the buffer
func (*ByteArray) WriteUTFBytes ¶
WriteUTFBytes writes a string as UTF-8 bytes
type DitherMethod ¶
type DitherMethod string
DitherMethod 抖动方法
const ( DitherNone DitherMethod = "none" DitherFloydSteinberg DitherMethod = "FloydSteinberg" DitherFalseFloydSteinberg DitherMethod = "FalseFloydSteinberg" DitherStucki DitherMethod = "Stucki" DitherAtkinson DitherMethod = "Atkinson" )
type EncodeOptions ¶
type EncodeOptions struct {
Width int // width of output GIF
Height int // height of output GIF
Repeat int // -1 = once, 0 = forever, >0 = count
Quality int // 1-30, lower is better
Dither interface{} // dithering method: bool, string, or DitherMethod
GlobalPalette []byte // optional global palette
Delays []int // delays in milliseconds
SaturationBoost float64 // 饱和度增强, [0.0,2.0], 1.0为原始
ContrastBoost float64 // 对比度增强, [0.0,2.0], 1.0为原始
}
EncodeGIFWithOptions provides more control over encoding options
type GIFEncoder ¶
type GIFEncoder struct {
// contains filtered or unexported fields
}
GIFEncoder encodes images into GIF format
func NewGIFEncoder ¶
func NewGIFEncoder(width, height int) *GIFEncoder
NewGIFEncoder creates a new GIF encoder
func NewGIFEncoderWithOptions ¶
func NewGIFEncoderWithOptions(width, height int, opts EncodeOptions) *GIFEncoder
func (*GIFEncoder) AddFrame ¶
func (ge *GIFEncoder) AddFrame(img image.Image) error
AddFrame adds next GIF frame
func (*GIFEncoder) Cleanup ¶
func (ge *GIFEncoder) Cleanup()
func (*GIFEncoder) CleanupAll ¶
func (ge *GIFEncoder) CleanupAll()
CleanupAll 完全清理包括输出缓冲区 只在确定不再需要GetData()时调用
func (*GIFEncoder) Finish ¶
func (ge *GIFEncoder) Finish()
Finish adds final trailer to the GIF stream
func (*GIFEncoder) GetData ¶
func (ge *GIFEncoder) GetData() []byte
GetData retrieves the GIF stream as byte array
func (*GIFEncoder) GetGlobalPalette ¶
func (ge *GIFEncoder) GetGlobalPalette() []byte
GetGlobalPalette returns global palette used for all frames
func (*GIFEncoder) SetColorEnhancement ¶
func (ge *GIFEncoder) SetColorEnhancement(saturationBoost, contrastBoost float64)
SetColorEnhancement 设置颜色增强选项 saturationBoost: 饱和度 ([0.0,2.0], 1.0为原始) contrastBoost: 对比度 ([0.0,2.0], 1.0为原始)
func (*GIFEncoder) SetDelay ¶
func (ge *GIFEncoder) SetDelay(milliseconds int)
SetDelay sets the delay time between each frame, or changes it for subsequent frames
func (*GIFEncoder) SetDispose ¶
func (ge *GIFEncoder) SetDispose(disposalCode int)
SetDispose sets the GIF frame disposal code
func (*GIFEncoder) SetDither ¶
func (ge *GIFEncoder) SetDither(method interface{})
SetDither sets dithering method. Available methods: - "none" or "" or false: no dithering - "FloydSteinberg" or true: Floyd-Steinberg dithering (recommended) - "FalseFloydSteinberg": False Floyd-Steinberg dithering - "Stucki": Stucki dithering - "Atkinson": Atkinson dithering Add "-serpentine" suffix to use serpentine scanning (e.g., "FloydSteinberg-serpentine")
func (*GIFEncoder) SetFrameRate ¶
func (ge *GIFEncoder) SetFrameRate(fps int)
SetFrameRate sets frame rate in frames per second
func (*GIFEncoder) SetGlobalPalette ¶
func (ge *GIFEncoder) SetGlobalPalette(palette []byte)
SetGlobalPalette sets global palette for all frames
func (*GIFEncoder) SetQuality ¶
func (ge *GIFEncoder) SetQuality(quality int)
SetQuality sets quality of color quantization (1-30, lower is better)
func (*GIFEncoder) SetRepeat ¶
func (ge *GIFEncoder) SetRepeat(repeat int)
SetRepeat sets the number of times the set of GIF frames should be played
func (*GIFEncoder) SetTransparent ¶
func (ge *GIFEncoder) SetTransparent(c *color.RGBA)
SetTransparent sets the transparent color
func (*GIFEncoder) Stream ¶
func (ge *GIFEncoder) Stream() *ByteArray
Stream returns the output ByteArray
type LZWEncoder ¶
type LZWEncoder struct {
// contains filtered or unexported fields
}
LZWEncoder encodes image data using LZW compression
func NewLZWEncoder ¶
func NewLZWEncoder(width, height int, pixels []byte, colorDepth int) *LZWEncoder
NewLZWEncoder creates a new LZW encoder
func (*LZWEncoder) Encode ¶
func (enc *LZWEncoder) Encode(out *ByteArray)
Encode encodes and writes pixel data to the output stream
type NeuQuant ¶
type NeuQuant struct {
// contains filtered or unexported fields
}
NeuQuant is a neural network color quantizer
func NewNeuQuant ¶
NewNeuQuant creates a new NeuQuant instance pixels: array of pixels in RGB format [r,g,b,r,g,b,...] samplefac: sampling factor 1 to 30 where lower is better quality
func (*NeuQuant) BuildColormap ¶
func (nq *NeuQuant) BuildColormap()
BuildColormap builds the color map 1. initializes network 2. trains it 3. removes misconceptions 4. builds colorindex
func (*NeuQuant) GetColormap ¶
GetColormap returns the color map as byte array [r,g,b,r,g,b,...]