diff --git a/avif.go b/avif.go index ec09dc9..fba6a42 100644 --- a/avif.go +++ b/avif.go @@ -1,6 +1,6 @@ // 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 // #cgo CFLAGS: -Wall -O2 -DNDEBUG @@ -15,13 +15,7 @@ import ( "runtime" ) -type Options struct { - Threads int - Speed int - Quality int - SubsampleRatio *image.YCbCrSubsampleRatio -} - +// Encoder constants. const ( MinSpeed = 0 MaxSpeed = 8 @@ -29,21 +23,34 @@ const ( MaxQuality = 63 ) -var ( - DefaultOptions = Options{ - Threads: 0, - Speed: 4, - Quality: 25, - SubsampleRatio: nil, - } -) +// Options are the encoding parameters. Threads ranges from 1, 0 means +// use all available cores. Speed ranges from MinSpeed to MaxSpeed. +// Quality ranges from MinQuality to MaxQuality, lower is better, 0 +// means lossless encoding. SubsampleRatio specifies subsampling of the +// encoded image, nil means 4:2:0. +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 func (e OptionsError) Error() string { return fmt.Sprintf("options error: %s", string(e)) } +// An EncoderError reports that the encoder error has occured. type EncoderError int func (e EncoderError) ToString() string { @@ -65,6 +72,7 @@ func (e EncoderError) Error() string { return fmt.Sprintf("encoder error: %s", e.ToString()) } +// A MuxerError reports that the muxer error has occured. type MuxerError string func (e MuxerError) Error() string { diff --git a/example_test.go b/example_test.go index d788dc0..f68b0d2 100644 --- a/example_test.go +++ b/example_test.go @@ -9,10 +9,11 @@ import ( "github.com/Kagami/go-avif" ) -// This example shows the basic usage of the package. -func Example_basic() { +const usageHelp = "Usage: %s src.jpg dst.avif" + +func Example() { 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]