mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-11 02:59:40 +02:00
Get 24 bit RGB transmission working
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func add_frame(imgd *image_data, img image.Image) {
|
||||
func add_frame(imgd *image_data, img image.Image, is_opaque bool) {
|
||||
if flip {
|
||||
img = imaging.FlipV(img)
|
||||
}
|
||||
@@ -23,33 +23,48 @@ func add_frame(imgd *image_data, img image.Image) {
|
||||
b := img.Bounds()
|
||||
f := image_frame{width: b.Dx(), height: b.Dy()}
|
||||
dest_rect := image.Rect(0, 0, f.width, f.height)
|
||||
var rgba *image.NRGBA
|
||||
m, err := shm.CreateTemp("icat-*", uint64(f.width*f.height*4))
|
||||
if err != nil {
|
||||
rgba = image.NewNRGBA(dest_rect)
|
||||
} else {
|
||||
rgba = &image.NRGBA{
|
||||
Pix: m.Slice(),
|
||||
Stride: 4 * f.width,
|
||||
Rect: dest_rect,
|
||||
var final_img image.Image
|
||||
|
||||
if is_opaque || remove_alpha != nil {
|
||||
var rgb *images.NRGB
|
||||
m, err := shm.CreateTemp("icat-*", uint64(f.width*f.height*3))
|
||||
if err != nil {
|
||||
rgb = images.NewNRGB(dest_rect)
|
||||
} else {
|
||||
rgb = &images.NRGB{Pix: m.Slice(), Stride: 3 * f.width, Rect: dest_rect}
|
||||
f.shm = m
|
||||
}
|
||||
f.shm = m
|
||||
imgd.format_uppercase = "RGB"
|
||||
f.in_memory_bytes = rgb.Pix
|
||||
final_img = rgb
|
||||
} else {
|
||||
var rgba *image.NRGBA
|
||||
m, err := shm.CreateTemp("icat-*", uint64(f.width*f.height*4))
|
||||
if err != nil {
|
||||
rgba = image.NewNRGBA(dest_rect)
|
||||
} else {
|
||||
rgba = &image.NRGBA{Pix: m.Slice(), Stride: 4 * f.width, Rect: dest_rect}
|
||||
f.shm = m
|
||||
}
|
||||
imgd.format_uppercase = "RGBA"
|
||||
f.in_memory_bytes = rgba.Pix
|
||||
final_img = rgba
|
||||
}
|
||||
images.PasteCenter(rgba, img, remove_alpha)
|
||||
imgd.format_uppercase = "RGBA"
|
||||
f.in_memory_bytes = rgba.Pix
|
||||
images.PasteCenter(final_img, img, remove_alpha)
|
||||
imgd.frames = append(imgd.frames, &f)
|
||||
}
|
||||
|
||||
func load_one_frame_image(imgd *image_data, src *opened_input) (image.Image, error) {
|
||||
img, err := imaging.Decode(src.file, imaging.AutoOrientation(true))
|
||||
func load_one_frame_image(imgd *image_data, src *opened_input) (img image.Image, is_opaque bool, err error) {
|
||||
img, err = imaging.Decode(src.file, imaging.AutoOrientation(true))
|
||||
src.Rewind()
|
||||
if err == nil {
|
||||
// reset the sizes as we read EXIF tags here which could have rotated the image
|
||||
imgd.canvas_width = img.Bounds().Dx()
|
||||
imgd.canvas_height = img.Bounds().Dy()
|
||||
set_basic_metadata(imgd)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// reset the sizes as we read EXIF tags here which could have rotated the image
|
||||
imgd.canvas_width = img.Bounds().Dx()
|
||||
imgd.canvas_height = img.Bounds().Dy()
|
||||
set_basic_metadata(imgd)
|
||||
is_opaque = images.IsOpaque(img)
|
||||
if imgd.needs_scaling {
|
||||
if imgd.canvas_width < imgd.available_width && opts.ScaleUp && place != nil {
|
||||
r := float64(imgd.available_width) / float64(imgd.canvas_width)
|
||||
@@ -59,7 +74,7 @@ func load_one_frame_image(imgd *image_data, src *opened_input) (image.Image, err
|
||||
img = imaging.Resize(img, imgd.canvas_width, imgd.canvas_height, imaging.Lanczos)
|
||||
imgd.needs_scaling = false
|
||||
}
|
||||
return img, err
|
||||
return
|
||||
}
|
||||
|
||||
func render_image_with_go(imgd *image_data, src *opened_input) (err error) {
|
||||
@@ -67,11 +82,11 @@ func render_image_with_go(imgd *image_data, src *opened_input) (err error) {
|
||||
case "GIF":
|
||||
return fmt.Errorf("TODO: implement GIF decoding")
|
||||
default:
|
||||
img, err := load_one_frame_image(imgd, src)
|
||||
img, is_opaque, err := load_one_frame_image(imgd, src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
add_frame(imgd, img)
|
||||
add_frame(imgd, img, is_opaque)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user