예제 #1
0
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
0
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
0
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
0
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
0
파일: webp.go 프로젝트: sjn1978/go-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
0
// 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
0
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)
		}
	}
}