mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-16 05:24:20 +02:00
Get 24 bit RGB transmission working
This commit is contained in:
@@ -33,6 +33,8 @@ func IsOpaque(img image.Image) bool {
|
||||
return img.(*image.Paletted).Opaque()
|
||||
case *image.Uniform:
|
||||
return img.(*image.Uniform).Opaque()
|
||||
case *image.YCbCr:
|
||||
return img.(*image.YCbCr).Opaque()
|
||||
case *NRGB:
|
||||
return img.(*NRGB).Opaque()
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ func (s *scanner_rgb) scan(x1, y1, x2, y2 int, dst []uint8) {
|
||||
}
|
||||
}
|
||||
|
||||
func paste_nrgb_onto_opaque(background *image.NRGBA, img image.Image, pos image.Point, bgcol *NRGBColor) {
|
||||
func paste_nrgb_onto_opaque(background *NRGB, img image.Image, pos image.Point, bgcol *NRGBColor) {
|
||||
bg := NRGBColor{}
|
||||
if bgcol != nil {
|
||||
bg = *bgcol
|
||||
@@ -408,3 +408,11 @@ func paste_nrgb_onto_opaque(background *image.NRGBA, img image.Image, pos image.
|
||||
src := newScannerRGB(img, bg)
|
||||
run_paste(src, background, pos, func(dst []byte) {})
|
||||
}
|
||||
|
||||
func NewNRGB(r image.Rectangle) *NRGB {
|
||||
return &NRGB{
|
||||
Pix: make([]uint8, 3*r.Dx()*r.Dy()),
|
||||
Stride: 3 * r.Dx(),
|
||||
Rect: r,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ type Scanner interface {
|
||||
bounds() image.Rectangle
|
||||
}
|
||||
|
||||
func run_paste(src Scanner, background *image.NRGBA, pos image.Point, postprocess func([]byte)) {
|
||||
func run_paste(src Scanner, background image.Image, pos image.Point, postprocess func([]byte)) {
|
||||
pos = pos.Sub(background.Bounds().Min)
|
||||
pasteRect := image.Rectangle{Min: pos, Max: pos.Add(src.bounds().Size())}
|
||||
interRect := pasteRect.Intersect(background.Bounds())
|
||||
@@ -338,15 +338,29 @@ func run_paste(src Scanner, background *image.NRGBA, pos image.Point, postproces
|
||||
return
|
||||
}
|
||||
bytes_per_pixel := src.bytes_per_pixel()
|
||||
var stride int
|
||||
var pix []uint8
|
||||
switch v := background.(type) {
|
||||
case *image.NRGBA:
|
||||
i := background.(*image.NRGBA)
|
||||
stride = i.Stride
|
||||
pix = i.Pix
|
||||
case *NRGB:
|
||||
i := background.(*NRGB)
|
||||
stride = i.Stride
|
||||
pix = i.Pix
|
||||
default:
|
||||
panic(fmt.Sprintf("Unsupported image type: %v", v))
|
||||
}
|
||||
parallel(interRect.Min.Y, interRect.Max.Y, func(ys <-chan int) {
|
||||
for y := range ys {
|
||||
x1 := interRect.Min.X - pasteRect.Min.X
|
||||
x2 := interRect.Max.X - pasteRect.Min.X
|
||||
y1 := y - pasteRect.Min.Y
|
||||
y2 := y1 + 1
|
||||
i1 := y*background.Stride + interRect.Min.X*bytes_per_pixel
|
||||
i1 := y*stride + interRect.Min.X*bytes_per_pixel
|
||||
i2 := i1 + interRect.Dx()*bytes_per_pixel
|
||||
dst := background.Pix[i1:i2]
|
||||
dst := pix[i1:i2]
|
||||
src.scan(x1, y1, x2, y2, dst)
|
||||
postprocess(dst)
|
||||
}
|
||||
@@ -381,7 +395,7 @@ func Paste(background image.Image, img image.Image, pos image.Point, opaque_bg *
|
||||
case *image.NRGBA:
|
||||
paste_nrgba_onto_opaque(background.(*image.NRGBA), img, pos, opaque_bg)
|
||||
case *NRGB:
|
||||
paste_nrgb_onto_opaque(background.(*image.NRGBA), img, pos, opaque_bg)
|
||||
paste_nrgb_onto_opaque(background.(*NRGB), img, pos, opaque_bg)
|
||||
default:
|
||||
panic("Unsupported background image type")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user