mpo

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 9 Imported by: 1

README

MPO Encoder/Decoder Library

Go Report Card GoDoc awesome-go

Simple Go JPEG MPO (Multi Picture Object) Decoder and Encoder - Library and CLI Tool

The library and CLI can:

  • Decode an MPO into individual JPEG frames.
  • Encode multiple JPEG frames into a Baseline-MP MPO.
  • Convert an MPO to a stereoscopic (side-by-side) JPEG.
  • Create anaglyph images (red–cyan, cyan–red, red–green, green–red).

A Web UI for converting MPO to JPEG is available at:

https://donatstudios.com/MPO-to-JPEG-Stereo

Install CLI Tool

Binaries are available for Darwin (macOS), Linux and Windows on the release page:

https://github.com/donatj/mpo/releases

From Source
go install github.com/donatj/mpo/cmd/mpo2img@latest
go install github.com/donatj/mpo/cmd/img2mpo@latest

CLI Usage

mpo2img

Convert an MPO file to a stereoscopic JPEG or anaglyph image.

$ mpo2img -help
Usage: mpo2img <mpofile>

Convert a Multi-Picture Object (MPO) file to an image.

  -format string
        Output format [stereo|red-cyan|cyan-red|red-green|green-red] (default "stereo")
  -help
        Displays this text
  -outfile string
        Output filename (default "output.jpg")
img2mpo

encode multiple images into an MPO file.

$ img2mpo -help
Usage: img2mpo <imagefile> [<imagefile> ...]

Convert one or more images to a Multi-Picture Object (MPO) file.

Supported image formats: JPEG, PNG, GIF, BMP, TIFF, WebP

  -help
        Displays this text
  -outfile string
        Output filename (default "output.mpo")
  -quality int
        JPEG quality [0-100] (default 90)

WIP

Todo:

  • Optimization
  • Add more control over stereo/anaglyph

Documentation

Overview

Package mpo provides simple read and write support for Multi‑Picture Object (MPO) files, a format that stores two or more JPEG frames in a single byte stream, and is used in some 3D cameras.

The package is designed to be simple and easy to use, with a focus on extracting and writing the JPEG frames. It does not attempt to implement the full specification of the MPO format, but rather provides a basic set of functions to work with the most common use cases.

The package offers:

  • DecodeAll – extract every JPEG frame present in an MPO.
  • EncodeAll – write a Baseline‑MP MPO from a slice of image.Image.
  • ConvertToStereo – merge the first two frames side‑by‑side.
  • ConvertToAnaglyph – create red/cyan or similar anaglyphs.

EncodeAll produces only the subset required for a Baseline‑MP file: the first frame is flagged as the representative image and is given MP type 0x00030000. DecodeAll imposes no such restriction and simply returns every JPEG it finds.

Specification references:

Offsets in the MP Image List are measured relative to the TIFF endian marker inside the APP2/MPF segment, as required by DC‑X007 §5.2.3.3. The code relies only on the Go standard library and is safe for pure‑Go builds.

Index

Constants

View Source
const (
	// RedCyan is Red on left eye, cyan on right
	RedCyan colorType = iota

	// CyanRed is Cyan on left eye, red on right
	CyanRed

	// RedGreen is Red on left eye, green on right
	RedGreen

	// GreenRed is Green on left eye, red on right
	GreenRed
)

Variables

View Source
var ErrInconsistentBounds = errors.New("anaglyph images must be the same size")

ErrInconsistentBounds indicates that not all images within the MPO file were found to be the same size, which is a requirement for the anaglyph conversion.

View Source
var ErrInvalidImageCount = errors.New("anaglyph conversion only supports 2 images")

ErrInvalidImageCount indicates that incorrect number of images were found during the anaglyph conversion process.

View Source
var ErrNoImages = errors.New("no images found in mpo image")

ErrNoImages indicates that no images were found in the specified file.

View Source
var ErrUnsupportedColorType = errors.New("unsupported color type")

ErrUnsupportedColorType indicates that the color type requested is not supported by the anaglyph conversion process.

Functions

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode reads a MPO image from r and returns it as an image.Image.

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

DecodeConfig returns the color model and dimensions of an MPO image without decoding the entire image.

TODO Optimize this - possibly just falling back to jpeg.DecodeConfig

func EncodeAll added in v0.1.0

func EncodeAll(w io.Writer, m *MPO, o *jpeg.Options) error

EncodeAll encodes all images in m into a Baseline‑MP MPO and writes it to w.

Types

type MPO

type MPO struct {
	Image []image.Image
}

MPO represents the likely multiple images stored in a MPO file.

func DecodeAll

func DecodeAll(rr io.Reader) (*MPO, error)

DecodeAll reads an MPO image from r and returns the sequential frames

func (*MPO) ConvertToAnaglyph

func (m *MPO) ConvertToAnaglyph(ct colorType) (image.Image, error)

ConvertToAnaglyph converts an MPO to the anaglyph format specified by ct colorType constant and returns the resulting image.

ErrInconsistentBounds is returned if the images within the MPO are not the same size. ErrInvalidImageCount is returned if the number of images in the MPO is not exactly 2. ErrUnsupportedColorType is returned if the color type requested is not supported.

func (*MPO) ConvertToStereo

func (m *MPO) ConvertToStereo() image.Image

ConvertToStereo converts an MPO to a StereoScopic image

Directories

Path Synopsis
cmd
img2mpo command
mpo2img command

Jump to

Keyboard shortcuts

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