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:
- CIPA DC‑X007:2012 – Multi‑Picture Format (MPF) https://www.cipa.jp/std/documents/e/DC-007-2012_E.pdf
- ISO/IEC 10918‑1 – JPEG Baseline coding and marker layout.
- JFIF 1.02 – APP0/JFIF segment details.
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 ¶
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 ¶
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.
var ErrInvalidImageCount = errors.New("anaglyph conversion only supports 2 images")
ErrInvalidImageCount indicates that incorrect number of images were found during the anaglyph conversion process.
var ErrNoImages = errors.New("no images found in mpo image")
ErrNoImages indicates that no images were found in the specified file.
var ErrUnsupportedColorType = errors.New("unsupported color type")
ErrUnsupportedColorType indicates that the color type requested is not supported by the anaglyph conversion process.
Functions ¶
func DecodeConfig ¶
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
Types ¶
type MPO ¶
MPO represents the likely multiple images stored in a MPO file.
func (*MPO) ConvertToAnaglyph ¶
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 ¶
ConvertToStereo converts an MPO to a StereoScopic image