Improve docs
This commit is contained in:
parent
c81987e7ab
commit
d134f4db56
40
avif.go
40
avif.go
|
@ -1,6 +1,6 @@
|
||||||
// Package avif implements a AVIF image encoder.
|
// Package avif implements a AVIF image encoder.
|
||||||
//
|
//
|
||||||
// AVIF is defined in https://aomediacodec.github.io/av1-avif/
|
// The AVIF specification is at https://aomediacodec.github.io/av1-avif/.
|
||||||
package avif
|
package avif
|
||||||
|
|
||||||
// #cgo CFLAGS: -Wall -O2 -DNDEBUG
|
// #cgo CFLAGS: -Wall -O2 -DNDEBUG
|
||||||
|
@ -15,13 +15,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
// Encoder constants.
|
||||||
Threads int
|
|
||||||
Speed int
|
|
||||||
Quality int
|
|
||||||
SubsampleRatio *image.YCbCrSubsampleRatio
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MinSpeed = 0
|
MinSpeed = 0
|
||||||
MaxSpeed = 8
|
MaxSpeed = 8
|
||||||
|
@ -29,21 +23,34 @@ const (
|
||||||
MaxQuality = 63
|
MaxQuality = 63
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// Options are the encoding parameters. Threads ranges from 1, 0 means
|
||||||
DefaultOptions = Options{
|
// use all available cores. Speed ranges from MinSpeed to MaxSpeed.
|
||||||
Threads: 0,
|
// Quality ranges from MinQuality to MaxQuality, lower is better, 0
|
||||||
Speed: 4,
|
// means lossless encoding. SubsampleRatio specifies subsampling of the
|
||||||
Quality: 25,
|
// encoded image, nil means 4:2:0.
|
||||||
SubsampleRatio: nil,
|
type Options struct {
|
||||||
}
|
Threads int
|
||||||
)
|
Speed int
|
||||||
|
Quality int
|
||||||
|
SubsampleRatio *image.YCbCrSubsampleRatio
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultOptions defines default encoder config.
|
||||||
|
var DefaultOptions = Options{
|
||||||
|
Threads: 0,
|
||||||
|
Speed: 4,
|
||||||
|
Quality: 25,
|
||||||
|
SubsampleRatio: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
// An OptionsError reports that the passed options are not valid.
|
||||||
type OptionsError string
|
type OptionsError string
|
||||||
|
|
||||||
func (e OptionsError) Error() string {
|
func (e OptionsError) Error() string {
|
||||||
return fmt.Sprintf("options error: %s", string(e))
|
return fmt.Sprintf("options error: %s", string(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An EncoderError reports that the encoder error has occured.
|
||||||
type EncoderError int
|
type EncoderError int
|
||||||
|
|
||||||
func (e EncoderError) ToString() string {
|
func (e EncoderError) ToString() string {
|
||||||
|
@ -65,6 +72,7 @@ func (e EncoderError) Error() string {
|
||||||
return fmt.Sprintf("encoder error: %s", e.ToString())
|
return fmt.Sprintf("encoder error: %s", e.ToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A MuxerError reports that the muxer error has occured.
|
||||||
type MuxerError string
|
type MuxerError string
|
||||||
|
|
||||||
func (e MuxerError) Error() string {
|
func (e MuxerError) Error() string {
|
||||||
|
|
|
@ -9,10 +9,11 @@ import (
|
||||||
"github.com/Kagami/go-avif"
|
"github.com/Kagami/go-avif"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This example shows the basic usage of the package.
|
const usageHelp = "Usage: %s src.jpg dst.avif"
|
||||||
func Example_basic() {
|
|
||||||
|
func Example() {
|
||||||
if len(os.Args) != 3 {
|
if len(os.Args) != 3 {
|
||||||
log.Fatalf("Usage: %s src.jpg dst.avif", os.Args[0])
|
log.Fatalf(usageHelp, os.Args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
srcPath := os.Args[1]
|
srcPath := os.Args[1]
|
||||||
|
|
Loading…
Reference in New Issue