Transmission format should be per frame

This commit is contained in:
Kovid Goyal 2023-01-02 17:49:11 +05:30
parent 4623f580b9
commit 481cebbd29
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 13 additions and 9 deletions

View File

@ -34,7 +34,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
} }
imgd.format_uppercase = "RGB" f.transmission_format_uppercase = "RGB"
f.in_memory_bytes = rgb.Pix f.in_memory_bytes = rgb.Pix
final_img = rgb final_img = rgb
} else { } else {
@ -46,7 +46,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
} }
imgd.format_uppercase = "RGBA" f.transmission_format_uppercase = "RGBA"
f.in_memory_bytes = rgba.Pix f.in_memory_bytes = rgba.Pix
final_img = rgba final_img = rgba
} }

View File

@ -142,6 +142,7 @@ type image_frame struct {
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
} }
type image_data struct { type image_data struct {
@ -190,6 +191,7 @@ 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 ok { if ok {
frame.in_memory_bytes = bb.data frame.in_memory_bytes = bb.data
} else { } else {

View File

@ -32,13 +32,15 @@ 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 imgd.format_uppercase { switch frame.transmission_format_uppercase {
case "PNG": case "PNG":
gc.SetFormat(graphics.GRT_format_png) gc.SetFormat(graphics.GRT_format_png)
default: case "RGB":
gc.SetFormat(graphics.GRT_format_rgb) gc.SetFormat(graphics.GRT_format_rgb)
case "RGBA": case "RGBA":
gc.SetFormat(graphics.GRT_format_rgba) gc.SetFormat(graphics.GRT_format_rgba)
default:
panic(fmt.Sprintf("Unknown transmission format: %s", frame.transmission_format_uppercase))
} }
return &gc return &gc