mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
go generate
This commit is contained in:
parent
e4aace6c40
commit
faca493fbc
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 3.7 KiB |
@ -53,6 +53,10 @@ func cbPaletted(cb int) bool {
|
|||||||
return cbP1 <= cb && cb <= cbP8
|
return cbP1 <= cb && cb <= cbP8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cbTrueColor(cb int) bool {
|
||||||
|
return cb == cbTC8 || cb == cbTC16
|
||||||
|
}
|
||||||
|
|
||||||
// Filter type, as per the PNG spec.
|
// Filter type, as per the PNG spec.
|
||||||
const (
|
const (
|
||||||
ftNone = 0
|
ftNone = 0
|
||||||
@ -872,7 +876,7 @@ func (d *decoder) parseIEND(length uint32) error {
|
|||||||
return d.verifyChecksum()
|
return d.verifyChecksum()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *decoder) parseChunk() error {
|
func (d *decoder) parseChunk(configOnly bool) error {
|
||||||
// Read the length and chunk type.
|
// Read the length and chunk type.
|
||||||
if _, err := io.ReadFull(d.r, d.tmp[:8]); err != nil {
|
if _, err := io.ReadFull(d.r, d.tmp[:8]); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -900,6 +904,10 @@ func (d *decoder) parseChunk() error {
|
|||||||
if d.stage != dsSeenPLTE {
|
if d.stage != dsSeenPLTE {
|
||||||
return chunkOrderError
|
return chunkOrderError
|
||||||
}
|
}
|
||||||
|
} else if cbTrueColor(d.cb) {
|
||||||
|
if d.stage != dsSeenIHDR && d.stage != dsSeenPLTE {
|
||||||
|
return chunkOrderError
|
||||||
|
}
|
||||||
} else if d.stage != dsSeenIHDR {
|
} else if d.stage != dsSeenIHDR {
|
||||||
return chunkOrderError
|
return chunkOrderError
|
||||||
}
|
}
|
||||||
@ -917,6 +925,9 @@ func (d *decoder) parseChunk() error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
d.stage = dsSeenIDAT
|
d.stage = dsSeenIDAT
|
||||||
|
if configOnly {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return d.parseIDAT(length)
|
return d.parseIDAT(length)
|
||||||
case "IEND":
|
case "IEND":
|
||||||
if d.stage != dsSeenIDAT {
|
if d.stage != dsSeenIDAT {
|
||||||
@ -976,7 +987,7 @@ func Decode(r io.Reader) (image.Image, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for d.stage != dsSeenIEND {
|
for d.stage != dsSeenIEND {
|
||||||
if err := d.parseChunk(); err != nil {
|
if err := d.parseChunk(false); err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
err = io.ErrUnexpectedEOF
|
err = io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
@ -999,21 +1010,26 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
|
|||||||
}
|
}
|
||||||
return image.Config{}, err
|
return image.Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if err := d.parseChunk(); err != nil {
|
if err := d.parseChunk(true); err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
err = io.ErrUnexpectedEOF
|
err = io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
return image.Config{}, err
|
return image.Config{}, err
|
||||||
}
|
}
|
||||||
paletted := cbPaletted(d.cb)
|
|
||||||
if d.stage == dsSeenIHDR && !paletted {
|
if cbPaletted(d.cb) {
|
||||||
|
if d.stage >= dsSeentRNS {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if d.stage == dsSeenPLTE && paletted {
|
} else {
|
||||||
|
if d.stage >= dsSeenIHDR {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var cm color.Model
|
var cm color.Model
|
||||||
switch d.cb {
|
switch d.cb {
|
||||||
case cbG1, cbG2, cbG4, cbG8:
|
case cbG1, cbG2, cbG4, cbG8:
|
||||||
|
@ -452,6 +452,36 @@ func (e *encoder) writeImage(w io.Writer, m image.Image, cb int, level int) erro
|
|||||||
if nrgba != nil {
|
if nrgba != nil {
|
||||||
offset := (y - b.Min.Y) * nrgba.Stride
|
offset := (y - b.Min.Y) * nrgba.Stride
|
||||||
copy(cr[0][1:], nrgba.Pix[offset:offset+b.Dx()*4])
|
copy(cr[0][1:], nrgba.Pix[offset:offset+b.Dx()*4])
|
||||||
|
} else if rgba != nil {
|
||||||
|
dst := cr[0][1:]
|
||||||
|
src := rgba.Pix[rgba.PixOffset(b.Min.X, y):rgba.PixOffset(b.Max.X, y)]
|
||||||
|
for ; len(src) >= 4; dst, src = dst[4:], src[4:] {
|
||||||
|
d := (*[4]byte)(dst)
|
||||||
|
s := (*[4]byte)(src)
|
||||||
|
if s[3] == 0x00 {
|
||||||
|
d[0] = 0
|
||||||
|
d[1] = 0
|
||||||
|
d[2] = 0
|
||||||
|
d[3] = 0
|
||||||
|
} else if s[3] == 0xff {
|
||||||
|
copy(d[:], s[:])
|
||||||
|
} else {
|
||||||
|
// This code does the same as color.NRGBAModel.Convert(
|
||||||
|
// rgba.At(x, y)).(color.NRGBA) but with no extra memory
|
||||||
|
// allocations or interface/function call overhead.
|
||||||
|
//
|
||||||
|
// The multiplier m combines 0x101 (which converts
|
||||||
|
// 8-bit color to 16-bit color) and 0xffff (which, when
|
||||||
|
// combined with the division-by-a, converts from
|
||||||
|
// alpha-premultiplied to non-alpha-premultiplied).
|
||||||
|
const m = 0x101 * 0xffff
|
||||||
|
a := uint32(s[3]) * 0x101
|
||||||
|
d[0] = uint8((uint32(s[0]) * m / a) >> 8)
|
||||||
|
d[1] = uint8((uint32(s[1]) * m / a) >> 8)
|
||||||
|
d[2] = uint8((uint32(s[2]) * m / a) >> 8)
|
||||||
|
d[3] = s[3]
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Convert from image.Image (which is alpha-premultiplied) to PNG's non-alpha-premultiplied.
|
// Convert from image.Image (which is alpha-premultiplied) to PNG's non-alpha-premultiplied.
|
||||||
for x := b.Min.X; x < b.Max.X; x++ {
|
for x := b.Min.X; x < b.Max.X; x++ {
|
||||||
|
2
keys.go
2
keys.go
@ -24,7 +24,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// A Key represents a keyboard key.
|
// A Key represents a keyboard key.
|
||||||
// These keys represent pysical keys of US keyboard.
|
// These keys represent physical keys of US keyboard.
|
||||||
// For example, KeyQ represents Q key on US keyboards and ' (quote) key on Dvorak keyboards.
|
// For example, KeyQ represents Q key on US keyboards and ' (quote) key on Dvorak keyboards.
|
||||||
type Key int
|
type Key int
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user