mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
internal/png: update with Go 1.22
This commit is contained in:
parent
6552ae1dbe
commit
04c4676b7c
@ -24,6 +24,9 @@ import (
|
|||||||
"go/token"
|
"go/token"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
exec "golang.org/x/sys/execabs"
|
exec "golang.org/x/sys/execabs"
|
||||||
@ -47,6 +50,20 @@ func pngFiles() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
|
reVer := regexp.MustCompile(`^go1\.(\d+)(\.\d+)?$`)
|
||||||
|
verStr := runtime.Version()
|
||||||
|
m := reVer.FindStringSubmatch(verStr)
|
||||||
|
if m == nil {
|
||||||
|
return fmt.Errorf("png: unexpected Go version: %s", verStr)
|
||||||
|
}
|
||||||
|
ver, err := strconv.Atoi(m[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if ver < 22 {
|
||||||
|
return fmt.Errorf("png: use Go 1.22 or newer")
|
||||||
|
}
|
||||||
|
|
||||||
dir, err := pngDir()
|
dir, err := pngDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -115,6 +132,18 @@ func run() error {
|
|||||||
fmt.Fprintln(out, "// Code generated by gen.go. DO NOT EDIT.")
|
fmt.Fprintln(out, "// Code generated by gen.go. DO NOT EDIT.")
|
||||||
fmt.Fprintln(out)
|
fmt.Fprintln(out)
|
||||||
format.Node(out, fset, tree)
|
format.Node(out, fset, tree)
|
||||||
|
|
||||||
|
if f == "reader.go" {
|
||||||
|
// The min function was removed as of Go 1.22, but this is needed for old Go.
|
||||||
|
// TODO: Remove this when Go 1.21 is the minimum supported version.
|
||||||
|
fmt.Fprintln(out, `
|
||||||
|
func min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -138,13 +138,6 @@ type UnsupportedError string
|
|||||||
|
|
||||||
func (e UnsupportedError) Error() string { return "png: unsupported feature: " + string(e) }
|
func (e UnsupportedError) Error() string { return "png: unsupported feature: " + string(e) }
|
||||||
|
|
||||||
func min(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *decoder) parseIHDR(length uint32) error {
|
func (d *decoder) parseIHDR(length uint32) error {
|
||||||
if length != 13 {
|
if length != 13 {
|
||||||
return FormatError("bad IHDR length")
|
return FormatError("bad IHDR length")
|
||||||
@ -973,7 +966,7 @@ func (d *decoder) checkHeader() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode reads a PNG image from r and returns it as an image.Image.
|
// Decode reads a PNG image from r and returns it as an [image.Image].
|
||||||
// The type of Image returned depends on the PNG contents.
|
// The type of Image returned depends on the PNG contents.
|
||||||
func Decode(r io.Reader) (image.Image, error) {
|
func Decode(r io.Reader) (image.Image, error) {
|
||||||
d := &decoder{
|
d := &decoder{
|
||||||
@ -1061,3 +1054,10 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
|
|||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
@ -27,7 +27,7 @@ type Encoder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EncoderBufferPool is an interface for getting and returning temporary
|
// EncoderBufferPool is an interface for getting and returning temporary
|
||||||
// instances of the EncoderBuffer struct. This can be used to reuse buffers
|
// instances of the [EncoderBuffer] struct. This can be used to reuse buffers
|
||||||
// when encoding multiple images.
|
// when encoding multiple images.
|
||||||
type EncoderBufferPool interface {
|
type EncoderBufferPool interface {
|
||||||
Get() *EncoderBuffer
|
Get() *EncoderBuffer
|
||||||
@ -192,7 +192,7 @@ func (e *encoder) writePLTEAndTRNS(p color.Palette) {
|
|||||||
|
|
||||||
// An encoder is an io.Writer that satisfies writes by writing PNG IDAT chunks,
|
// An encoder is an io.Writer that satisfies writes by writing PNG IDAT chunks,
|
||||||
// including an 8-byte header and 4-byte CRC checksum per Write call. Such calls
|
// including an 8-byte header and 4-byte CRC checksum per Write call. Such calls
|
||||||
// should be relatively infrequent, since writeIDATs uses a bufio.Writer.
|
// should be relatively infrequent, since writeIDATs uses a [bufio.Writer].
|
||||||
//
|
//
|
||||||
// This method should only be called from writeIDATs (via writeImage).
|
// This method should only be called from writeIDATs (via writeImage).
|
||||||
// No other code should treat an encoder as an io.Writer.
|
// No other code should treat an encoder as an io.Writer.
|
||||||
@ -588,7 +588,7 @@ func levelToZlib(l CompressionLevel) int {
|
|||||||
func (e *encoder) writeIEND() { e.writeChunk(nil, "IEND") }
|
func (e *encoder) writeIEND() { e.writeChunk(nil, "IEND") }
|
||||||
|
|
||||||
// Encode writes the Image m to w in PNG format. Any Image may be
|
// Encode writes the Image m to w in PNG format. Any Image may be
|
||||||
// encoded, but images that are not image.NRGBA might be encoded lossily.
|
// encoded, but images that are not [image.NRGBA] might be encoded lossily.
|
||||||
func Encode(w io.Writer, m image.Image) error {
|
func Encode(w io.Writer, m image.Image) error {
|
||||||
var e Encoder
|
var e Encoder
|
||||||
return e.Encode(w, m)
|
return e.Encode(w, m)
|
||||||
|
Loading…
Reference in New Issue
Block a user