DRYer
This commit is contained in:
@@ -5,6 +5,7 @@ package icat
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
"kitty/tools/tui/graphics"
|
||||||
"kitty/tools/utils/images"
|
"kitty/tools/utils/images"
|
||||||
"kitty/tools/utils/shm"
|
"kitty/tools/utils/shm"
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ func add_frame(imgd *image_data, img image.Image, is_opaque bool) {
|
|||||||
rgb = &images.NRGB{Pix: m.Slice(), Stride: 3 * f.width, Rect: dest_rect}
|
rgb = &images.NRGB{Pix: m.Slice(), Stride: 3 * f.width, Rect: dest_rect}
|
||||||
f.shm = m
|
f.shm = m
|
||||||
}
|
}
|
||||||
f.transmission_format_uppercase = "RGB"
|
f.transmission_format = graphics.GRT_format_rgb
|
||||||
f.in_memory_bytes = rgb.Pix
|
f.in_memory_bytes = rgb.Pix
|
||||||
final_img = rgb
|
final_img = rgb
|
||||||
} else {
|
} else {
|
||||||
@@ -46,7 +47,7 @@ func add_frame(imgd *image_data, img image.Image, is_opaque bool) {
|
|||||||
rgba = &image.NRGBA{Pix: m.Slice(), Stride: 4 * f.width, Rect: dest_rect}
|
rgba = &image.NRGBA{Pix: m.Slice(), Stride: 4 * f.width, Rect: dest_rect}
|
||||||
f.shm = m
|
f.shm = m
|
||||||
}
|
}
|
||||||
f.transmission_format_uppercase = "RGBA"
|
f.transmission_format = graphics.GRT_format_rgba
|
||||||
f.in_memory_bytes = rgba.Pix
|
f.in_memory_bytes = rgba.Pix
|
||||||
final_img = rgba
|
final_img = rgba
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"kitty/tools/tty"
|
"kitty/tools/tty"
|
||||||
|
"kitty/tools/tui/graphics"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/shm"
|
"kitty/tools/utils/shm"
|
||||||
)
|
)
|
||||||
@@ -137,12 +138,12 @@ func (self *opened_input) Release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type image_frame struct {
|
type image_frame struct {
|
||||||
filename string
|
filename string
|
||||||
shm shm.MMap
|
shm shm.MMap
|
||||||
in_memory_bytes []byte
|
in_memory_bytes []byte
|
||||||
filename_is_temporary bool
|
filename_is_temporary bool
|
||||||
width, height int
|
width, height int
|
||||||
transmission_format_uppercase string
|
transmission_format graphics.GRT_f
|
||||||
}
|
}
|
||||||
|
|
||||||
type image_data struct {
|
type image_data struct {
|
||||||
@@ -191,7 +192,10 @@ func make_output_from_input(imgd *image_data, f *opened_input) {
|
|||||||
imgd.frames = append(imgd.frames, &frame)
|
imgd.frames = append(imgd.frames, &frame)
|
||||||
frame.width = imgd.canvas_width
|
frame.width = imgd.canvas_width
|
||||||
frame.height = imgd.canvas_height
|
frame.height = imgd.canvas_height
|
||||||
frame.transmission_format_uppercase = imgd.format_uppercase
|
if imgd.format_uppercase != "PNG" {
|
||||||
|
panic(fmt.Sprintf("Unknown transmission format: %s", imgd.format_uppercase))
|
||||||
|
}
|
||||||
|
frame.transmission_format = graphics.GRT_format_png
|
||||||
if ok {
|
if ok {
|
||||||
frame.in_memory_bytes = bb.data
|
frame.in_memory_bytes = bb.data
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"kitty/tools/tui/graphics"
|
|
||||||
"kitty/tools/utils"
|
|
||||||
"kitty/tools/utils/shm"
|
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"kitty/tools/tui/graphics"
|
||||||
|
"kitty/tools/utils"
|
||||||
|
"kitty/tools/utils/shm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@@ -32,17 +33,7 @@ func gc_for_image(imgd *image_data, frame_num int, frame *image_frame) *graphics
|
|||||||
if imgd.image_number != 0 {
|
if imgd.image_number != 0 {
|
||||||
gc.SetImageNumber(imgd.image_number)
|
gc.SetImageNumber(imgd.image_number)
|
||||||
}
|
}
|
||||||
switch frame.transmission_format_uppercase {
|
gc.SetFormat(frame.transmission_format)
|
||||||
case "PNG":
|
|
||||||
gc.SetFormat(graphics.GRT_format_png)
|
|
||||||
case "RGB":
|
|
||||||
gc.SetFormat(graphics.GRT_format_rgb)
|
|
||||||
case "RGBA":
|
|
||||||
gc.SetFormat(graphics.GRT_format_rgba)
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("Unknown transmission format: %s", frame.transmission_format_uppercase))
|
|
||||||
}
|
|
||||||
|
|
||||||
return &gc
|
return &gc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user