VideoTools/vendor/fyne.io/fyne/v2/internal/painter/image.go
Stu Leak 68df790d27 Fix player frame generation and video playback
Major improvements to UnifiedPlayer:

1. GetFrameImage() now works when paused for responsive UI updates
2. Play() method properly starts FFmpeg process
3. Frame display loop runs continuously for smooth video display
4. Disabled audio temporarily to fix video playback fundamentals
5. Simplified FFmpeg command to focus on video stream only

Player now:
- Generates video frames correctly
- Shows video when paused
- Has responsive progress tracking
- Starts playback properly

Next steps: Re-enable audio playback once video is stable
2026-01-07 22:20:00 -05:00

69 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package painter
import (
"image"
_ "image/jpeg" // avoid users having to import when using image widget
_ "image/png" // avoid the same for PNG images
"golang.org/x/image/draw"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
)
// PaintImage renders a given fyne Image to a Go standard image
// If a fyne.Canvas is given and the images fill mode is “fill original” the images min size has
// to fit its original size. If it doesnt, PaintImage does not paint the image but adjusts its min size.
// The image will then be painted on the next frame because of the min size change.
func PaintImage(img *canvas.Image, c fyne.Canvas, width, height int) image.Image {
if img.Size().IsZero() && c == nil { // an image without size or canvas won't get rendered unless we setup
img.Resize(fyne.NewSize(float32(width), float32(height)))
}
dst, err := paintImage(img, width, height)
if err != nil {
fyne.LogError("failed to paint image", err)
}
return dst
}
func paintImage(img *canvas.Image, width, height int) (dst image.Image, err error) {
if width <= 0 || height <= 0 {
return dst, err
}
dst = img.Image
if dst == nil {
dst = image.NewNRGBA(image.Rect(0, 0, width, height))
}
size := dst.Bounds().Size()
if width != size.X || height != size.Y {
dst = scaleImage(dst, width, height, img.ScaleMode)
}
return dst, err
}
func scaleImage(pixels image.Image, scaledW, scaledH int, scale canvas.ImageScale) image.Image {
if scale == canvas.ImageScaleFastest || scale == canvas.ImageScalePixels {
// do not perform software scaling
return pixels
}
bounds := pixels.Bounds()
pixW := int(fyne.Min(float32(scaledW), float32(bounds.Dx()))) // don't push more pixels than we have to
pixH := int(fyne.Min(float32(scaledH), float32(bounds.Dy()))) // the GL calls will scale this up on GPU.
scaledBounds := image.Rect(0, 0, pixW, pixH)
tex := image.NewNRGBA(scaledBounds)
switch scale {
case canvas.ImageScalePixels:
draw.NearestNeighbor.Scale(tex, scaledBounds, pixels, bounds, draw.Over, nil)
default:
if scale != canvas.ImageScaleSmooth {
fyne.LogError("Invalid canvas.ImageScale value, using canvas.ImageScaleSmooth", nil)
}
draw.CatmullRom.Scale(tex, scaledBounds, pixels, bounds, draw.Over, nil)
}
return tex
}