iv

package module
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 46 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

iv

Build Status Go Reference

Native windows for images and video in pure Go, without cgo.

Applications: iv, an image viewer, and vv, a video player.

screenshot

Features

  • Platforms: Linux (X11, Wayland, DRM), Windows (Win32), macOS (Cocoa), BSDs (X11)
  • No cgo: builds and cross-compiles with CGO_ENABLED=0
  • Images: Display shows an image.Image fitted to the window, Present shows it at the next vertical blank
  • Video: PresentFrame shows YCbCr frames, converted and scaled in hardware where the platform can: XVideo or XRender (X11), NV12 shm or dmabuf, else wp_viewporter (Wayland), planes (DRM), Direct3D 11 (Windows), AVSampleBufferDisplayLayer (macOS)
  • Input: key, button, motion, scroll, enter and leave handlers
  • Window: title, icon, cursors, fullscreen, maximize, resize and close handlers

On wlroots compositors (labwc, sway, ...) set WLR_RENDERER=vulkan, the default GLES2 renderer cannot take YCbCr frames.

Applications

iv

Small and simple image viewer.

  • Formats: JPEG, GIF, PNG, BMP, WEBP, AVIF, JXL, HEIC, ICO, PCX, TIFF, PNM/PBM/PGM/PPM, SVG, PSD, PSP, MPO, QOI, HDR, PFM, ICNS, XBM, XPM
  • Animation: GIF, PNG, WEBP, AVIF, JXL, HEIC
  • Auto-rotate: applies the EXIF orientation (JPEG, PNG, WEBP, AVIF, HEIC)
  • URLs: HTTP arguments, and image scraping from HTML pages
  • Auto-reload: when the current image is modified or its directory changes
  • Single instance: open files in an already-running window
  • Clipboard: copy the current image, or its path, to the clipboard
  • Self-contained: no external runtime dependencies, single static binary
vv

Small and simple video player.

  • Video: H.264, HEVC, AV1, VP9, VP8, MPEG-4 Part 2, H.263, MPEG-1
  • Audio: AAC, MP3, MP2, Opus, Vorbis, FLAC, PCM
  • Containers: MP4, 3GP, Matroska, WebM, AVI, FLV, IVF, MPEG program stream, raw H.264 and HEVC
  • Sound: PulseAudio or ALSA (Linux), OSS (FreeBSD), Core Audio (macOS), WASAPI (Windows)
  • Playback: frames shown at the vertical blank and paced by the audio clock, seeking, frame step
  • Self-contained: decoders in pure Go, no external runtime dependencies, single static binary

Download

Download the latest binaries from the releases.

Installation

CGO_ENABLED=0 go install github.com/gen2brain/iv/cmd/iv@latest
CGO_ENABLED=0 go install github.com/gen2brain/iv/cmd/vv@latest

These commands install iv and vv in GOBIN, you can point GOBIN to e.g. /usr/local/bin or ~/.local/bin. CGO_ENABLED=0 gives a static binary, cgo is not needed on any platform. Add -ldflags "-s -w" to strip debug symbols.

Build tags

  • x11 - use X11 in macOS or Windows (e.g., via XQuartz or Xming)

Library usage

runtime.LockOSThread()

view, err := iv.New()
if err != nil {
    panic(err)
}

view.Display(context.Background(), img)

Documentation

Overview

Package iv shows images and video frames in native windows, without cgo.

The window is X11, Wayland or the DRM console on Linux, picked from the session (IV_DRIVER=x11, wayland or drm overrides it), X11 on the BSDs, Win32 on Windows and Cocoa on macOS; the x11 build tag selects X11 on Windows and macOS.

View.Display shows an image fitted to the window, View.Present shows it at the next vertical blank, and View.PresentFrame shows a YCbCr Frame (BT.601, BT.709, BT.2020, GBR or YCgCo, limited or full range), converted and scaled in hardware where the platform can; View.FramePath names the path taken.

Call New and the display methods from the main goroutine, after runtime.LockOSThread.

Index

Constants

View Source
const (
	MatrixGBR   = ycbcr.GBR
	MatrixYCgCo = ycbcr.YCgCo
)

Matrix values for RGB-coded samples: G, B and R in the Y, Cb and Cr planes, or YCgCo.

View Source
const (
	KeySpace        = 65
	KeyEscape       = 9
	KeyEnter        = 36
	KeyTab          = 23
	KeyBackspace    = 22
	KeyInsert       = 118
	KeyDelete       = 119
	KeyRight        = 114
	KeyLeft         = 113
	KeyDown         = 116
	KeyUp           = 111
	KeyPageUp       = 112
	KeyPageDown     = 117
	KeyHome         = 110
	KeyEnd          = 115
	KeyCapsLock     = 66
	KeyScrollLock   = 78
	KeyNumLock      = 77
	KeyPrintScreen  = 107
	KeyPause        = 127
	KeyF1           = 67
	KeyF2           = 68
	KeyF3           = 69
	KeyF4           = 70
	KeyF5           = 71
	KeyF6           = 72
	KeyF7           = 73
	KeyF8           = 74
	KeyF9           = 75
	KeyF10          = 76
	KeyF11          = 95
	KeyF12          = 96
	KeyLeftShift    = 50
	KeyLeftControl  = 37
	KeyLeftAlt      = 64
	KeyLeftSuper    = 133
	KeyRightShift   = 62
	KeyRightControl = 105
	KeyRightAlt     = 108
	KeyRightSuper   = 134
	KeyLeftBracket  = 34
	KeyBackSlash    = 51
	KeyRightBracket = 35
	KeyGrave        = 49
	KeyKp0          = 90
	KeyKp1          = 87
	KeyKp2          = 88
	KeyKp3          = 89
	KeyKp4          = 83
	KeyKp5          = 84
	KeyKp6          = 85
	KeyKp7          = 79
	KeyKp8          = 80
	KeyKp9          = 81
	KeyKpDecimal    = 91
	KeyKpDivide     = 106
	KeyKpMultiply   = 63
	KeyKpSubtract   = 82
	KeyKpAdd        = 8
	KeyKpEnter      = 104
	KeyApostrophe   = 48
	KeyComma        = 59
	KeyMinus        = 20
	KeyPeriod       = 60
	KeySlash        = 61
	Key0            = 19
	Key1            = 10
	Key2            = 11
	Key3            = 12
	Key4            = 13
	Key5            = 14
	Key6            = 15
	Key7            = 16
	Key8            = 17
	Key9            = 18
	KeySemicolon    = 47
	KeyEqual        = 21
	KeyA            = 38
	KeyB            = 56
	KeyC            = 54
	KeyD            = 40
	KeyE            = 26
	KeyF            = 41
	KeyG            = 42
	KeyH            = 43
	KeyI            = 31
	KeyJ            = 44
	KeyK            = 45
	KeyL            = 46
	KeyM            = 58
	KeyN            = 57
	KeyO            = 32
	KeyP            = 33
	KeyQ            = 24
	KeyR            = 27
	KeyS            = 39
	KeyT            = 28
	KeyU            = 30
	KeyV            = 55
	KeyW            = 25
	KeyX            = 53
	KeyY            = 29
	KeyZ            = 52

	ButtonLeft   = 1
	ButtonMiddle = 2
	ButtonRight  = 3

	ScrollUp   = 4
	ScrollDown = 5
)

Variables

View Source
var (
	// ErrUnsupported is returned when operating system is not supported.
	ErrUnsupported = fmt.Errorf("unsupported os: %s", runtime.GOOS)
)

Functions

This section is empty.

Types

type ButtonPressHandler

type ButtonPressHandler func(button int)

ButtonPressHandler function.

type ButtonReleaseHandler

type ButtonReleaseHandler func(button int)

ButtonReleaseHandler function.

type ClosedHandler

type ClosedHandler func()

ClosedHandler function.

type CreatedHandler

type CreatedHandler func()

CreatedHandler function.

type Cursor added in v0.3.0

type Cursor int

Cursor is a window cursor shape. Backends map each to the closest native cursor.

const (
	// CursorDefault is the arrow cursor.
	CursorDefault Cursor = iota
	// CursorPointer is the pointing hand, used for links.
	CursorPointer
	// CursorGrab is the open hand.
	CursorGrab
	// CursorGrabbing is the closed hand, shown while dragging.
	CursorGrabbing
	// CursorText is the text I-beam.
	CursorText
	// CursorCrosshair is the crosshair.
	CursorCrosshair
)

type EnterHandler

type EnterHandler func()

EnterHandler function.

type Frame added in v0.6.1

type Frame struct {
	*image.YCbCr

	// Matrix is 601, 709, 2020, MatrixGBR or MatrixYCgCo.
	Matrix int
	// FullRange is set for full range samples.
	FullRange bool
	// Width and Height are the display size for the aspect ratio, zero for the picture size.
	Width, Height int
	// OSD brightens luma under its alpha, in picture coordinates.
	OSD *image.Alpha
}

Frame is a YCbCr video frame and how to show it; it must stay unchanged until the next frame or image.

type KeyPressHandler

type KeyPressHandler func(key int)

KeyPressHandler function.

type KeyReleaseHandler

type KeyReleaseHandler func(key int)

KeyReleaseHandler function.

type LeaveHandler

type LeaveHandler func()

LeaveHandler function.

type MotionHandler

type MotionHandler func(x, y int)

MotionHandler function.

type Options

type Options struct {
	// AppID e.g. class name
	AppID string
	// Window width
	Width int
	// Window height
	Height int
	// DRM device index
	Device int
	// Text color (HEX)
	TextColor string
	// Window background color (HEX)
	BackgroundColor string
}

Options type.

type ResizeHandler

type ResizeHandler func(width, height int)

ResizeHandler function.

type ScrollHandler

type ScrollHandler func(direction int)

ScrollHandler function.

type View

type View struct {
	// contains filtered or unexported fields
}

View type.

func New

func New(args ...any) (*View, error)

New returns new View.

func (*View) Clear

func (v *View) Clear()

Clear clears the window contents.

func (*View) Close

func (v *View) Close() error

Close closes the window.

func (*View) Display

func (v *View) Display(ctx context.Context, img image.Image, args ...any) error

Display displays image, optional argument is the title of the window.

func (*View) Driver

func (v *View) Driver() string

Driver returns the name of the display driver.

func (*View) FramePath added in v0.6.1

func (v *View) FramePath() string

FramePath names how the last frame was shown, empty when the last image shown was not a frame.

func (*View) Fullscreen

func (v *View) Fullscreen() bool

Fullscreen returns current fullscreen state.

func (*View) Maximize added in v0.2.0

func (v *View) Maximize() error

Maximize maximizes the window to the available work area.

func (*View) Present added in v0.6.0

func (v *View) Present(ctx context.Context, img image.Image) error

Present displays image and waits until it is on screen at a vertical blank, or ctx is done.

func (*View) PresentFrame added in v0.6.1

func (v *View) PresentFrame(ctx context.Context, f *Frame) error

PresentFrame presents a video frame like Present, converting and scaling it as the backend allows.

func (*View) Raise

func (v *View) Raise() error

Raise brings the window to the front.

func (*View) ScreenSize

func (v *View) ScreenSize() (int, int)

ScreenSize returns screen dimensions.

func (*View) SetButtonPressHandler

func (v *View) SetButtonPressHandler(handler ButtonPressHandler)

SetButtonPressHandler sets mouse button press handler.

func (*View) SetButtonReleaseHandler

func (v *View) SetButtonReleaseHandler(handler ButtonReleaseHandler)

SetButtonReleaseHandler sets mouse button release handler.

func (*View) SetClosedHandler

func (v *View) SetClosedHandler(handler ClosedHandler)

SetClosedHandler sets window closed handler.

func (*View) SetCreatedHandler

func (v *View) SetCreatedHandler(handler CreatedHandler)

SetCreatedHandler sets window created handler.

func (*View) SetCursor added in v0.3.0

func (v *View) SetCursor(c Cursor) error

SetCursor sets the window cursor shape.

func (*View) SetEnterHandler

func (v *View) SetEnterHandler(handler EnterHandler)

SetEnterHandler sets mouse enter handler.

func (*View) SetIcon

func (v *View) SetIcon(img image.Image) error

SetIcon sets the window icon.

func (*View) SetKeyPressHandler

func (v *View) SetKeyPressHandler(handler KeyPressHandler)

SetKeyPressHandler sets key press handler.

func (*View) SetKeyReleaseHandler

func (v *View) SetKeyReleaseHandler(handler KeyReleaseHandler)

SetKeyReleaseHandler sets key release handler.

func (*View) SetLeaveHandler

func (v *View) SetLeaveHandler(handler LeaveHandler)

SetLeaveHandler sets mouse leave handler.

func (*View) SetMotionHandler

func (v *View) SetMotionHandler(handler MotionHandler)

SetMotionHandler sets mouse motion handler.

func (*View) SetResizeHandler

func (v *View) SetResizeHandler(handler ResizeHandler)

SetResizeHandler sets window resize handler.

func (*View) SetScrollHandler

func (v *View) SetScrollHandler(handler ScrollHandler)

SetScrollHandler sets mouse scroll handler.

func (*View) SetTitle

func (v *View) SetTitle(title string) error

SetTitle sets window title.

func (*View) ToggleFullscreen

func (v *View) ToggleFullscreen() error

ToggleFullscreen toggles window fullscreen.

func (*View) WindowSize

func (v *View) WindowSize() (int, int)

WindowSize returns window dimensions.

type Viewer

type Viewer interface {
	Driver() string
	Display(ctx context.Context, img image.Image, args ...any) error
	Present(ctx context.Context, img image.Image) error
	PresentFrame(ctx context.Context, f *Frame) error
	FramePath() string
	ToggleFullscreen() error
	Fullscreen() bool
	Maximize() error
	Raise() error
	SetTitle(string) error
	SetIcon(image.Image) error
	SetCursor(Cursor) error
	ScreenSize() (int, int)
	WindowSize() (int, int)
	Close() error
	Clear()

	SetKeyPressHandler(handler KeyPressHandler)
	SetKeyReleaseHandler(handler KeyReleaseHandler)
	SetButtonPressHandler(handler ButtonPressHandler)
	SetButtonReleaseHandler(handler ButtonReleaseHandler)
	SetMotionHandler(handler MotionHandler)
	SetScrollHandler(handler ScrollHandler)
	SetEnterHandler(handler EnterHandler)
	SetLeaveHandler(handler LeaveHandler)
	SetResizeHandler(handler ResizeHandler)
	SetCreatedHandler(handler CreatedHandler)
	SetClosedHandler(handler ClosedHandler)
}

Viewer interface.

Directories

Path Synopsis
cmd
iv module
vv module
internal
swizzle
Package swizzle converts pixel buffers between RGBA and BGRA byte order.
Package swizzle converts pixel buffers between RGBA and BGRA byte order.
ycbcr
Package ycbcr converts YCbCr rows to RGBA or BGRA.
Package ycbcr converts YCbCr rows to RGBA or BGRA.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址