Documentation
¶
Overview ¶
Package jpeg implements a JPEG image decoder and encoder.
JPEG is defined in ITU-T T.81: https://www.w3.org/Graphics/JPEG/itu-t81.pdf.
Index ¶
Constants ¶
const DefaultQuality = 75
DefaultQuality is the default quality encoding parameter.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads a JPEG image from r and returns it as an image.Image.
func DecodeConfig ¶
DecodeConfig returns the color model and dimensions of a JPEG image without decoding the entire image.
func DecodePartial ¶ added in v0.2.0
DecodePartial decodes as much of a JPEG as r holds, and says how much of it is real.
It returns the image at its FULL declared size, the number of pixel rows that are complete counting from the top, and the error that stopped the decode — nil when the whole image arrived. Rows past the count hold whatever the image was allocated with, so a caller draws the first rows and nothing else.
⛔ This exists because Decode is all-or-nothing, and for a file still arriving that is the same as having nothing. Measured on a real 750 KB photograph truncated at 25, 50 and 75 per cent: the standard decoder — and this one, which is its sibling — returned a nil image and "short Huffman data" every time, with three quarters of the picture on disk. image/png and image/gif answer the same way, so this is a gap in the shape of every decoder rather than in one of them.
⛔ The row count names FINISHED rows and never the row being decoded. A truncated stream stops inside an MCU row, and a caller handed that row would draw a band of half-decoded blocks: visibly wrong in a way that reads as a broken image rather than a partial one.
Three shapes are deliberately NOT served partially, and each returns a nil image with the error:
- A PROGRESSIVE JPEG. Its early scans cover the whole frame at low fidelity, so no row is ever final until the last scan, and "rows from the top" cannot describe it. A caller told rows=0 would draw nothing, which is the honest answer here rather than a wrong one. Measured on 300 files from one real library: 5.7% were progressive, 94.3% sequential.
- CMYK, and RGB carried in a JPEG (the Adobe APP14 marker). Both need a conversion pass over the finished image, and running it over rows that are partly unwritten produces colour nobody sent.
- Anything that failed before the first MCU row completed. There is no picture yet, only a size.
Types ¶
type FormatError ¶
type FormatError string
A FormatError reports that the input is not a valid JPEG.
func (FormatError) Error ¶
func (e FormatError) Error() string
type Options ¶
type Options struct {
Quality int
}
Options are the encoding parameters. Quality ranges from 1 to 100 inclusive, higher is better.
type Reader
deprecated
type Reader interface {
io.ByteReader
io.Reader
}
Deprecated: Reader is not used by the image/jpeg package and should not be used by others. It is kept for compatibility.
type UnsupportedError ¶
type UnsupportedError string
An UnsupportedError reports that the input uses a valid but unimplemented JPEG feature.
func (UnsupportedError) Error ¶
func (e UnsupportedError) Error() string