mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
internal/png: update for Go 1.18
This commit is contained in:
parent
bb2cd3059b
commit
6e19c793f6
@ -25,37 +25,48 @@ import (
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/ast/astutil"
|
||||
)
|
||||
|
||||
func run() error {
|
||||
// TODO: Use go/packages with specifying build tags so that stdlibfuzz can be avoided.
|
||||
dir := filepath.Join(runtime.GOROOT(), "src", "image", "png")
|
||||
func pngDir() (string, error) {
|
||||
dir, err := exec.Command("go", "list", "-f", "{{.Dir}}", "image/png").Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(string(dir)), nil
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
func pngFiles() ([]string, error) {
|
||||
files, err := exec.Command("go", "list", "-f", `{{join .GoFiles ","}}`, "image/png").Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return strings.Split(strings.TrimSpace(string(files)), ","), nil
|
||||
}
|
||||
|
||||
func run() error {
|
||||
dir, err := pngDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
files, err := pngFiles()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
if f.IsDir() {
|
||||
continue
|
||||
}
|
||||
if strings.HasSuffix(f.Name(), "_test.go") {
|
||||
continue
|
||||
}
|
||||
|
||||
in, err := os.Open(filepath.Join(dir, f.Name()))
|
||||
in, err := os.Open(filepath.Join(dir, f))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Create("stdlib" + f.Name())
|
||||
out, err := os.Create("stdlib" + f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
// Code generated by gen.go. DO NOT EDIT.
|
||||
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build gofuzz
|
||||
// +build gofuzz
|
||||
|
||||
package png
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
cfg, err := DecodeConfig(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
if cfg.Width*cfg.Height > 1e6 {
|
||||
return 0
|
||||
}
|
||||
img, err := Decode(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
levels := []CompressionLevel{
|
||||
DefaultCompression,
|
||||
NoCompression,
|
||||
BestSpeed,
|
||||
BestCompression,
|
||||
}
|
||||
for _, l := range levels {
|
||||
var w bytes.Buffer
|
||||
e := &Encoder{CompressionLevel: l}
|
||||
err = e.Encode(&w, img)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
img1, err := Decode(&w)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
got := img1.Bounds()
|
||||
want := img.Bounds()
|
||||
if !got.Eq(want) {
|
||||
fmt.Printf("bounds0: %#v\n", want)
|
||||
fmt.Printf("bounds1: %#v\n", got)
|
||||
panic("bounds have changed")
|
||||
}
|
||||
}
|
||||
return 1
|
||||
}
|
@ -823,9 +823,17 @@ func (d *decoder) mergePassInto(dst image.Image, src image.Image, pass int) {
|
||||
dstPix, stride, rect = target.Pix, target.Stride, target.Rect
|
||||
bytesPerPixel = 8
|
||||
case *image.Paletted:
|
||||
srcPix = src.(*image.Paletted).Pix
|
||||
source := src.(*image.Paletted)
|
||||
srcPix = source.Pix
|
||||
dstPix, stride, rect = target.Pix, target.Stride, target.Rect
|
||||
bytesPerPixel = 1
|
||||
if len(target.Palette) < len(source.Palette) {
|
||||
// readImagePass can return a paletted image whose implicit palette
|
||||
// length (one more than the maximum Pix value) is larger than the
|
||||
// explicit palette length (what's in the PLTE chunk). Make the
|
||||
// same adjustment here.
|
||||
target.Palette = source.Palette
|
||||
}
|
||||
case *image.RGBA:
|
||||
srcPix = src.(*image.RGBA).Pix
|
||||
dstPix, stride, rect = target.Pix, target.Stride, target.Rect
|
||||
|
Loading…
Reference in New Issue
Block a user