mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Faster is_opaque implementation for paletted images
This commit is contained in:
@@ -9,6 +9,35 @@ import (
|
|||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
|
||||||
|
func paletted_is_opaque(p *image.Paletted) bool {
|
||||||
|
if len(p.Palette) > 256 {
|
||||||
|
return p.Opaque()
|
||||||
|
}
|
||||||
|
var is_alpha [256]bool
|
||||||
|
has_alpha := false
|
||||||
|
for i, c := range p.Palette {
|
||||||
|
_, _, _, a := c.RGBA()
|
||||||
|
if a != 0xffff {
|
||||||
|
is_alpha[i] = true
|
||||||
|
has_alpha = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !has_alpha {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
i0, i1 := 0, p.Rect.Dx()
|
||||||
|
for y := p.Rect.Min.Y; y < p.Rect.Max.Y; y++ {
|
||||||
|
for _, c := range p.Pix[i0:i1] {
|
||||||
|
if is_alpha[c] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i0 += p.Stride
|
||||||
|
i1 += p.Stride
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func IsOpaque(img image.Image) bool {
|
func IsOpaque(img image.Image) bool {
|
||||||
switch i := img.(type) {
|
switch i := img.(type) {
|
||||||
case *image.RGBA:
|
case *image.RGBA:
|
||||||
@@ -30,7 +59,7 @@ func IsOpaque(img image.Image) bool {
|
|||||||
case *image.CMYK:
|
case *image.CMYK:
|
||||||
return i.Opaque()
|
return i.Opaque()
|
||||||
case *image.Paletted:
|
case *image.Paletted:
|
||||||
return i.Opaque()
|
return paletted_is_opaque(i)
|
||||||
case *image.Uniform:
|
case *image.Uniform:
|
||||||
return i.Opaque()
|
return i.Opaque()
|
||||||
case *image.YCbCr:
|
case *image.YCbCr:
|
||||||
|
|||||||
Reference in New Issue
Block a user