Documentation
¶
Index ¶
- Constants
- func MIMETypeDetect(image []byte) string
- type Decoder
- type Encoder
- type Reader
- type Row
- type RowEmpty
- type RowFP
- type RowGray16
- type RowGray8
- type RowGrayFP32
- func (r RowGrayFP32) At(x int) color.Color
- func (r RowGrayFP32) Copy(r2 Row) int
- func (r RowGrayFP32) Fill(c color.Color)
- func (r RowGrayFP32) Gray16At(x int) color.Gray16
- func (r RowGrayFP32) GrayAt(x int) color.Gray
- func (r RowGrayFP32) MultiplyAccumulate(r2 Row, w float32)
- func (r RowGrayFP32) Set(x int, c color.Color)
- func (r RowGrayFP32) Slice(low, high int) Row
- func (r RowGrayFP32) Width() int
- func (r RowGrayFP32) ZeroFill()
- type RowRGBA32
- type RowRGBA64
- type RowRGBAFP32
- func (r RowRGBAFP32) At(x int) color.Color
- func (r RowRGBAFP32) Copy(r2 Row) int
- func (r RowRGBAFP32) Fill(c color.Color)
- func (r RowRGBAFP32) MultiplyAccumulate(r2 Row, w float32)
- func (r RowRGBAFP32) RGBA64At(x int) color.RGBA64
- func (r RowRGBAFP32) RGBAAt(x int) color.RGBA
- func (r RowRGBAFP32) Set(x int, c color.Color)
- func (r RowRGBAFP32) Slice(low, high int) Row
- func (r RowRGBAFP32) Width() int
- func (r RowRGBAFP32) ZeroFill()
- type Writer
Constants ¶
const ( MIMETypeBMP = "image/bmp" MIMETypeJPEG = "image/jpeg" MIMETypePDF = "application/pdf" MIMETypePNG = "image/png" MIMETypeTIFF = "image/tiff" MIMETypeData = "application/octet-stream" )
MIME types for known document formats:
Variables ¶
This section is empty.
Functions ¶
func MIMETypeDetect ¶
MIMETypeDetect detects image type by its few starting bytes and returns its MIME type.
If format cannot be guessed, "" is returned.
Types ¶
type Decoder ¶
type Decoder interface {
Reader
// MIMEType returns the MIME type of the image being decoded.
MIMEType() string
}
Decoder is the Reader with few additional methods, intended for decoding image formats, such as JPEG, PNG, ...
func NewJPEGReader ¶
NewJPEGReader creates a new Reader for JPEG images.
type Encoder ¶
type Encoder interface {
Writer
// MIMEType returns the MIME type of the image being decoded.
MIMEType() string
}
Encoder is the Writer with few additional methods, intended for encoding image formats, such as JPEG, PNG, ...
func NewJPEGWriter ¶
func NewJPEGWriter(output io.Writer, wid, hei int, model color.Model, quality int) (w Encoder, err error)
NewJPEGWriter creates a new Writer for JPEG images. Supported color models are following:
- color.GrayModel
- color.RGBAModel
The following color models are also supported, but resulting image depth is 8 bit (this is the JPEG format limitation):
- color.Gray16Model
- color.RGBA64Model
The quality is the [0...100] integer that defines the tradeoff between level of compression and image quality. 0 is the best compression, lowest quality, 100 is the best quality, lowest compression.
type Reader ¶
type Reader interface {
// ColorModel returns the [color.Model] of image being decoded.
ColorModel() color.Model
// Size returns the image size.
Size() (wid, hei int)
// NewRow allocates a [Row] of the appropriate type and width for
// use with the [Reader.Read] function.
NewRow() Row
// Read returns the next image [Row].
// It returns the resulting row length, in pixels, or an error.
Read(Row) (int, error)
// Close closes the reader.
Close()
}
Reader implements streaming image reader. It allows to read image line by line and doesn't use the whole image internal buffer, so even the large images can be processed using very small amount of memory.
There are two kinds of readers:
- image format reader (for example, PNG reader). They work on a top of io.Reader.
- image filter (for example, image resizer). They work on a top of existent Reader and also implement the Reader interface, which allows filters to be stacked.
[Reader.Read] may block or fail, if its source io.Reader blocks of fails, and this condition propagates over the entire reader stack.
Once Reader.Read fails, all subsequent calls to Reader.Read will return the same error.
Attempt to Read after the last line returns io.EOF. However, if underlying io.Reader unexpectedly returns io.EOF (i.e., if image is truncated), Reader.Read will return some other error code (typically, io.ErrUnexpectedEOF).
Reader may own some resources associated with it, which will not be automatically garbage-collected. So Reader needs to be explicitly closed after use (with the Reader.Close call).
Closing the input format reader doesn't close the underlying io.Reader. However, closing the image filter closes its underlying input Reader. So the entire filter chain can be closed by closing the top-level filter, but the bottom io.Reader still needs to be closed explicitly.
Reader doesn't guarantee that its input stream (io.Reader or underlying Reader) will be consumed till the end or even that at least some data will be consumed from it.
func NewColorModelFilter ¶
NewColorModelFilter creates a new image filter on a top of the existent Reader.
This filter converts image's color.Model.
func NewDetectReader ¶
NewDetectReader automatically detects image format and returns the appropriate reader.
func NewGrayScale ¶
NewGrayScale creates a new image filter on a top of the existent Reader.
This filter converts color images into the Grayscale without changing the image color.Model. For example, the full-color RGB24 image will be converted into the RGB24 with all color channels set to the same value, effectively making it Grayscale.
func NewResizer ¶
NewResizer creates a new image resize filter on a top of the existent Reader.
Resizer works by either clipping or expanding image to fit the specified region.
Resizer implements the Reader interface, which allows to build a chain of image filters.
When resizer is closed, its input Reader is also closed.
type Row ¶
type Row interface {
// Width returns the row width, in pixels.
Width() int
// At returns the pixel at the specified position.
At(x int) color.Color
// Set sets the pixel at the specified position.
Set(x int, c color.Color)
// Slice returns a [low:high] sub-slice of the original Row.
Slice(low, high int) Row
// Fill fills Row with the pixels of the specified color
Fill(c color.Color)
// Copy copies content of the r2 into the receiver Row.
// If they have a different color model, pixels are converted.
// Rows may be of the different size and may overlap.
//
// It returns number of pixels copied.
Copy(r2 Row) int
}
Row represents a single row of image
type RowEmpty ¶
type RowEmpty struct{}
RowEmpty represents an empty row
func (RowEmpty) At ¶
At returns the pixel at the specified position as color.Color.
type RowFP ¶
type RowFP interface {
Row
// ZeroFill fills the row with all-zero values
ZeroFill()
// MultiplyAccumulate performs the multiply-accumulate operation on
// the entire row:
//
// r += r2 * w
//
// Rows must be of the same type and size.
MultiplyAccumulate(r2 Row, w float32)
// contains filtered or unexported methods
}
RowFP extends the Row interface with the operations, required for image processing.
func NewRowFP ¶
NewRowFP returns the new Row with the RowGrayFP32 or RowRGBAFP32, compatible with the color.Model (grayscale or RGBA).
The following color models are supported:
- color.GrayModel
- color.Gray16Model
- color.RGBAModel
- color.RGBA64Model
For unknown (unsupported) model nil is returned.
type RowGray16 ¶
RowGray16 represents a row of 16-bit grayscale image.
func (RowGray16) At ¶
At returns pixel at the specified position as color.Color.
func (RowGray16) Gray16At ¶
Gray16At returns pixel at the specified position as color.Gray16.
type RowGray8 ¶
RowGray8 represents a row of 8-bit grayscale image.
func (RowGray8) At ¶
At returns pixel at the specified position as color.Color.
func (RowGray8) GrayAt ¶
GrayAt returns pixel at the specified position as color.Gray.
type RowGrayFP32 ¶
type RowGrayFP32 []float32
RowGrayFP32 represents a row of the grayscale image as a sequence of the 32-bit floating point numbers in range [0...1.0].
func (RowGrayFP32) At ¶
func (r RowGrayFP32) At(x int) color.Color
At returns pixel at the specified position as color.Color.
func (RowGrayFP32) Copy ¶
func (r RowGrayFP32) Copy(r2 Row) int
Copy copies content of the r2 into the receiver Row.
func (RowGrayFP32) Fill ¶
func (r RowGrayFP32) Fill(c color.Color)
Fill fills Row with the pixels of the specified color
func (RowGrayFP32) Gray16At ¶
func (r RowGrayFP32) Gray16At(x int) color.Gray16
Gray16At returns pixel at the specified position as color.Gray16.
func (RowGrayFP32) GrayAt ¶
func (r RowGrayFP32) GrayAt(x int) color.Gray
GrayAt returns pixel at the specified position as color.Gray.
func (RowGrayFP32) MultiplyAccumulate ¶
func (r RowGrayFP32) MultiplyAccumulate(r2 Row, w float32)
MultiplyAccumulate performs the multiply-accumulate operation on the entire row:
r += r2 * w
Rows must be of the same type and size.
func (RowGrayFP32) Set ¶
func (r RowGrayFP32) Set(x int, c color.Color)
Set sets the pixel at the specified position.
func (RowGrayFP32) Slice ¶
func (r RowGrayFP32) Slice(low, high int) Row
Slice returns a [low:high] sub-slice of the original Row.
func (RowGrayFP32) ZeroFill ¶
func (r RowGrayFP32) ZeroFill()
ZeroFill fills the row with all-zero values
type RowRGBA32 ¶
RowRGBA32 represents a row of 8-bit RGBA image.
func (RowRGBA32) At ¶
At returns pixel at the specified position as color.Color.
func (RowRGBA32) RGBAAt ¶
RGBAAt returns pixel at the specified position as color.RGBA.
type RowRGBA64 ¶
RowRGBA64 represents a row of 16-bit RGBA image.
func (RowRGBA64) At ¶
At returns pixel at the specified position as color.Color.
func (RowRGBA64) RGBA64At ¶
RGBA64At returns pixel at the specified position as color.RGBA64.
type RowRGBAFP32 ¶
type RowRGBAFP32 []float32
RowRGBAFP32 represents a row of the RGBA image as a sequence of the 32-bit floating point numbers in range [0...1.0]. The sequence is ordered as follows: R-G-B-A-R-G-B-A-...
func (RowRGBAFP32) At ¶
func (r RowRGBAFP32) At(x int) color.Color
At returns pixel at the specified position as color.Color.
func (RowRGBAFP32) Copy ¶
func (r RowRGBAFP32) Copy(r2 Row) int
Copy copies content of the r2 into the receiver Row.
func (RowRGBAFP32) Fill ¶
func (r RowRGBAFP32) Fill(c color.Color)
Fill fills Row with the pixels of the specified color
func (RowRGBAFP32) MultiplyAccumulate ¶
func (r RowRGBAFP32) MultiplyAccumulate(r2 Row, w float32)
MultiplyAccumulate performs the multiply-accumulate operation on the entire row:
r += r2 * w
Rows must be of the same type and size.
func (RowRGBAFP32) RGBA64At ¶
func (r RowRGBAFP32) RGBA64At(x int) color.RGBA64
RGBA64At returns pixel at the specified position as color.RGBA64.
func (RowRGBAFP32) RGBAAt ¶
func (r RowRGBAFP32) RGBAAt(x int) color.RGBA
RGBAAt returns pixel at the specified position as color.RGBA.
func (RowRGBAFP32) Set ¶
func (r RowRGBAFP32) Set(x int, c color.Color)
Set sets the pixel at the specified position.
func (RowRGBAFP32) Slice ¶
func (r RowRGBAFP32) Slice(low, high int) Row
Slice returns a [low:high] sub-slice of the original Row.
func (RowRGBAFP32) ZeroFill ¶
func (r RowRGBAFP32) ZeroFill()
ZeroFill fills the row with all-zero values
type Writer ¶
type Writer interface {
// ColorModel returns the [color.Model] of image being written.
ColorModel() color.Model
// Size returns the image size.
Size() (wid, hei int)
// Write writes the next image [Row].
Write(Row) error
// Close flushes the buffered data and then closes the Writer
Close() error
}
Writer implements streaming image writer.
It writes image row by row into the supplied io.Writer.
Writer may own some resources associated with it, which will not be automatically garbage-collected. So Writer needs to be explicitly closed after use (with the Writer.Close call).