本文整理汇总了Golang中golang.org/x/image/webp.Decode函数的典型用法代码示例。如果您正苦于以下问题:Golang Decode函数的具体用法?Golang Decode怎么用?Golang Decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Decode函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkDecode_yellow_rose_lossless_x_image_webp
func BenchmarkDecode_yellow_rose_lossless_x_image_webp(b *testing.B) {
data := tbLoadData(b, "yellow_rose.lossless.webp")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m, err := x_image_webp.Decode(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_ = m
}
}
示例2: BenchmarkDecode_video_001_x_image_webp
func BenchmarkDecode_video_001_x_image_webp(b *testing.B) {
data := tbLoadData(b, "video-001.webp")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m, err := x_image_webp.Decode(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_ = m
}
}
示例3: BenchmarkDecode_gopher_doc_8bpp_lossless_x_image_webp
func BenchmarkDecode_gopher_doc_8bpp_lossless_x_image_webp(b *testing.B) {
data := tbLoadData(b, "gopher-doc.8bpp.lossless.webp")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m, err := x_image_webp.Decode(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_ = m
}
}
示例4: BenchmarkDecode_blue_purple_pink_lossy_x_image_webp
func BenchmarkDecode_blue_purple_pink_lossy_x_image_webp(b *testing.B) {
data := tbLoadData(b, "blue-purple-pink.lossy.webp")
b.ResetTimer()
for i := 0; i < b.N; i++ {
m, err := x_image_webp.Decode(bytes.NewReader(data))
if err != nil {
b.Fatal(err)
}
_ = m
}
}
示例5: Fuzz
func Fuzz(data []byte) int {
cfg, err := webp.DecodeConfig(bytes.NewReader(data))
if err != nil {
return 0
}
if cfg.Width*cfg.Height > 1e6 {
return 0
}
if _, err := webp.Decode(bytes.NewReader(data)); err != nil {
return 0
}
return 1
}
示例6: test
// test tests a single WEBP image.
func test(name string) error {
filename := filepath.Join(*testdata, name)
f, err := os.Open(filename)
if err != nil {
return fmt.Errorf("Open: %v", err)
}
defer f.Close()
gotImage, err := webp.Decode(f)
if err != nil {
return fmt.Errorf("Decode: %v", err)
}
format, encode := "-pgm", encodePGM
if _, lossless := gotImage.(*image.NRGBA); lossless {
format, encode = "-pam", encodePAM
}
got, err := encode(gotImage)
if err != nil {
return fmt.Errorf("encode: %v", err)
}
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
c := exec.Command(*dwebp, filename, format, "-o", "/dev/stdout")
c.Stdout = stdout
c.Stderr = stderr
if err := c.Run(); err != nil {
os.Stderr.Write(stderr.Bytes())
return fmt.Errorf("executing dwebp: %v", err)
}
want := stdout.Bytes()
if len(got) != len(want) {
return fmt.Errorf("encodings have different length: got %d, want %d", len(got), len(want))
}
for i, g := range got {
if w := want[i]; g != w {
return fmt.Errorf("encodings differ at position 0x%x: got 0x%02x, want 0x%02x", i, g, w)
}
}
return nil
}
示例7: main
func main() {
inname := flag.String("input", "-", "can be - for standard in")
outname := flag.String("output", "-", "can be - for standard out")
flag.Parse()
var (
infile io.Reader
outfile io.Writer
)
if *inname == "-" {
infile = os.Stdin
} else {
file, err := os.Open(*inname)
if err != nil {
log.Fatal(err)
}
defer file.Close()
infile = file
}
if *outname == "-" {
outfile = os.Stdout
} else {
flag := os.O_WRONLY | os.O_CREATE | os.O_TRUNC
file, err := os.OpenFile(*outname, flag, 0666)
if err != nil {
log.Fatal(err)
}
defer file.Close()
outfile = file
}
if m, err := webp.Decode(infile); err != nil {
log.Fatal(err)
} else {
if err := png.Encode(outfile, m); err != nil {
log.Fatal(err)
}
}
}