Documentation ¶
Overview ¶
OpenImageIO bindings
https://sites.google.com/site/openimageio/home
OpenImageIO is a library for reading and writing images, and a bunch of related classes, utilities, and applications. There is a particular emphasis on formats and functionality used in professional, large-scale animation and visual effects work for film. OpenImageIO is used extensively in animation and VFX studios all over the world, and is also incorporated into several commercial products.
Index ¶
- Constants
- func Add(dst, a, b *ImageBuf, opts ...AlgoOpts) error
- func AddValue(dst, src *ImageBuf, value float32, opts ...AlgoOpts) error
- func AddValues(dst, src *ImageBuf, values []float32, opts ...AlgoOpts) error
- func ChannelAppend(dst, a, b *ImageBuf, opts ...AlgoOpts) error
- func Channels(dst, src *ImageBuf, nchannels int, opts ...*ChannelOpts) error
- func Checker(dst *ImageBuf, width, height, depth int, color1, color2 []float32, ...) error
- func Checker2D(dst *ImageBuf, width, height int, color1, color2 []float32, ...) error
- func ColorConvert(dst, src *ImageBuf, from, to string, unpremult bool, opts ...AlgoOpts) error
- func ColorConvertProcessor(dst, src *ImageBuf, cp *ColorProcessor, unpremult bool, opts ...AlgoOpts) error
- func ComputePixelHashSHA1(src *ImageBuf, extraInfo string, blockSize int, opts ...AlgoOpts) string
- func ConstantColors(src *ImageBuf, opts ...AlgoOpts) []float32
- func Crop(dst, src *ImageBuf, opts ...AlgoOpts) error
- func Cut(dst, src *ImageBuf, opts ...AlgoOpts) error
- func Fill(dst *ImageBuf, values []float32, opts ...AlgoOpts) error
- func Flatten(dst, src *ImageBuf, opts ...AlgoOpts) error
- func Flip(dst, src *ImageBuf, opts ...AlgoOpts) error
- func Flipflop(dst, src *ImageBuf, opts ...AlgoOpts) error
- func Flop(dst, src *ImageBuf, opts ...AlgoOpts) error
- func IsConstantChannel(src *ImageBuf, channel int, val float32, opts ...AlgoOpts) bool
- func IsConstantColor(src *ImageBuf, opts ...AlgoOpts) bool
- func IsMonochrome(src *ImageBuf, opts ...AlgoOpts) bool
- func Mul(dst, a, b *ImageBuf, opts ...AlgoOpts) error
- func MulValue(dst, src *ImageBuf, value float32, opts ...AlgoOpts) error
- func MulValues(dst, src *ImageBuf, values []float32, opts ...AlgoOpts) error
- func Over(dst, a, b *ImageBuf, opts ...AlgoOpts) error
- func Paste(dst, src *ImageBuf, xbegin, ybegin, zbegin, chbegin int, opts ...AlgoOpts) error
- func Paste2D(dst, src *ImageBuf, xbegin, ybegin int, opts ...AlgoOpts) error
- func Premult(dst, src *ImageBuf, opts ...AlgoOpts) error
- func RenderTextColor(dst *ImageBuf, x, y int, text string, fontSize int, fontName string, ...) error
- func Resample(dst, src *ImageBuf, interpolate bool, opts ...AlgoOpts) error
- func Resize(dst, src *ImageBuf, opts ...AlgoOpts) error
- func ResizeFilter(dst, src *ImageBuf, filter string, filterWidth float32, opts ...AlgoOpts) error
- func Sub(dst, a, b *ImageBuf, opts ...AlgoOpts) error
- func SubValue(dst, src *ImageBuf, value float32, opts ...AlgoOpts) error
- func SubValues(dst, src *ImageBuf, values []float32, opts ...AlgoOpts) error
- func SupportsOpenColorIO() bool
- func Transpose(dst, src *ImageBuf, opts ...AlgoOpts) error
- func Unpremult(dst, src *ImageBuf, opts ...AlgoOpts) error
- func Zero(dst *ImageBuf, opts ...AlgoOpts) error
- type AlgoOpts
- type ChannelOpts
- type ColorConfig
- func (c *ColorConfig) ColorSpaceNameByIndex(index int) string
- func (c *ColorConfig) ColorSpaceNameByRole(role string) string
- func (c *ColorConfig) CreateColorProcessor(inColorSpace, outColorSpace string) (*ColorProcessor, error)
- func (c *ColorConfig) Destroy()
- func (c *ColorConfig) DisplayNameByIndex(index int) string
- func (c *ColorConfig) LookNameByIndex(index int) string
- func (c *ColorConfig) NumColorSpaces() int
- func (c *ColorConfig) NumDisplays() int
- func (c *ColorConfig) NumLooks() int
- func (c *ColorConfig) NumViews(displayName string) int
- func (c *ColorConfig) ViewNameByIndex(displayName string, index int) string
- type ColorProcessor
- type IBStorage
- type ImageBuf
- func (i *ImageBuf) CachedPixels() bool
- func (i *ImageBuf) Clear()
- func (i *ImageBuf) Copy(src *ImageBuf) error
- func (i *ImageBuf) CopyMetadata(src *ImageBuf) error
- func (i *ImageBuf) CopyPixels(src *ImageBuf) error
- func (i *ImageBuf) Deep() bool
- func (i *ImageBuf) Destroy()
- func (i *ImageBuf) FileFormatName() string
- func (i *ImageBuf) GetFloatPixels() ([]float32, error)
- func (i *ImageBuf) GetPixelRegion(roi *ROI, format TypeDesc) (interface{}, error)
- func (i *ImageBuf) GetPixels(format TypeDesc) (interface{}, error)
- func (i *ImageBuf) ImageCache() *ImageCache
- func (i *ImageBuf) InitSpec(filename string, subimage, miplevel int) error
- func (i *ImageBuf) Initialized() bool
- func (i *ImageBuf) LastError() error
- func (i *ImageBuf) MipLevel() int
- func (i *ImageBuf) Name() string
- func (i *ImageBuf) NativeSpec() *ImageSpec
- func (i *ImageBuf) NumChannels() int
- func (i *ImageBuf) NumMipLevels() int
- func (i *ImageBuf) NumSubImages() int
- func (i *ImageBuf) Orientation() int
- func (i *ImageBuf) OrientedFullHeight() int
- func (i *ImageBuf) OrientedFullWidth() int
- func (i *ImageBuf) OrientedFullX() int
- func (i *ImageBuf) OrientedFullY() int
- func (i *ImageBuf) OrientedHeight() int
- func (i *ImageBuf) OrientedWidth() int
- func (i *ImageBuf) OrientedX() int
- func (i *ImageBuf) OrientedY() int
- func (i *ImageBuf) PixelType() TypeDesc
- func (i *ImageBuf) PixelsValid() bool
- func (i *ImageBuf) ROI() *ROI
- func (i *ImageBuf) ROIFull() *ROI
- func (i *ImageBuf) Read(force bool) error
- func (i *ImageBuf) ReadCallback(force bool, progress *ProgressCallback) error
- func (i *ImageBuf) ReadFormatCallback(force bool, convert TypeDesc, progress *ProgressCallback) error
- func (i *ImageBuf) ReadSubImage(subimage, miplevel int, force bool) error
- func (i *ImageBuf) ReadSubImageCallback(subimage, miplevel int, force bool, progress *ProgressCallback) error
- func (i *ImageBuf) ReadSubImageFormatCallback(subimage, miplevel int, force bool, convert TypeDesc, ...) error
- func (i *ImageBuf) Reset(filename string, cache *ImageCache) error
- func (i *ImageBuf) ResetNameSpec(filename string, spec *ImageSpec) error
- func (i *ImageBuf) ResetSpec(spec *ImageSpec) error
- func (i *ImageBuf) ResetSubImage(filename string, subimage, miplevel int, cache *ImageCache, config *ImageSpec) error
- func (i *ImageBuf) SetFull(xbegin, xend, ybegin, yend, zbegin, zend int)
- func (i *ImageBuf) SetROIFull(roi *ROI) error
- func (i *ImageBuf) SetWriteFormat(format TypeDesc)
- func (i *ImageBuf) SetWriteTiles(width, height, depth int)
- func (i *ImageBuf) Spec() *ImageSpec
- func (i *ImageBuf) SpecMod() *ImageSpec
- func (i *ImageBuf) Storage() IBStorage
- func (i *ImageBuf) SubImage() int
- func (i *ImageBuf) Swap(other *ImageBuf) error
- func (i *ImageBuf) WriteFile(filepath, fileformat string) error
- func (i *ImageBuf) WriteFileProgress(filepath, fileformat string, progress *ProgressCallback) error
- func (i *ImageBuf) WriteImageOutput(output *ImageOutput) error
- func (i *ImageBuf) WriteImageOutputProgress(output *ImageOutput, progress *ProgressCallback) error
- func (i *ImageBuf) XBegin() int
- func (i *ImageBuf) XEnd() int
- func (i *ImageBuf) XMax() int
- func (i *ImageBuf) XMin() int
- func (i *ImageBuf) YBegin() int
- func (i *ImageBuf) YEnd() int
- func (i *ImageBuf) YMax() int
- func (i *ImageBuf) YMin() int
- func (i *ImageBuf) ZBegin() int
- func (i *ImageBuf) ZEnd() int
- func (i *ImageBuf) ZMax() int
- func (i *ImageBuf) ZMin() int
- type ImageCache
- type ImageInput
- func (i *ImageInput) Close() error
- func (i *ImageInput) CurrentMipLevel() int
- func (i *ImageInput) CurrentSubimage() int
- func (i *ImageInput) Destroy()
- func (i *ImageInput) FormatName() string
- func (i *ImageInput) LastError() error
- func (i *ImageInput) Open(filename string) error
- func (i *ImageInput) ReadImage() ([]float32, error)
- func (i *ImageInput) ReadImageFormat(format TypeDesc, progress *ProgressCallback) (interface{}, error)
- func (i *ImageInput) ReadScanline(y, z int) ([]float32, error)
- func (i *ImageInput) ReadTile(x, y, z int) ([]float32, error)
- func (i *ImageInput) SeekMipLevel(subimage, miplevel int, newSpec *ImageSpec) bool
- func (i *ImageInput) SeekSubimage(index int, newSpec *ImageSpec) bool
- func (i *ImageInput) Spec() *ImageSpec
- func (i *ImageInput) Supports(feature string) bool
- func (i *ImageInput) ValidFile(filename string) bool
- type ImageOutput
- type ImageSpec
- func (s *ImageSpec) AlphaChannel() int
- func (s *ImageSpec) AttributeFloat(name string, defaultVal ...float32) float32
- func (s *ImageSpec) AttributeInt(name string, defaultVal ...int) int
- func (s *ImageSpec) AttributeString(name string, defaultVal ...string) string
- func (s *ImageSpec) ChannelBytes() int
- func (s *ImageSpec) ChannelBytesChan(chanNum int, native bool) int
- func (s *ImageSpec) ChannelFormat(chanNum int) TypeDesc
- func (s *ImageSpec) ChannelFormats() []TypeDesc
- func (s *ImageSpec) ChannelNames() []string
- func (s *ImageSpec) Deep() bool
- func (s *ImageSpec) DefaultChannelNames()
- func (s *ImageSpec) Depth() int
- func (s *ImageSpec) Destroy()
- func (s *ImageSpec) EraseAttribute(name string, caseSensitive bool)
- func (s *ImageSpec) EraseAttributeType(name string, searchType TypeDesc, caseSensitive bool)
- func (s *ImageSpec) Format() TypeDesc
- func (s *ImageSpec) FullDepth() int
- func (s *ImageSpec) FullHeight() int
- func (s *ImageSpec) FullWidth() int
- func (s *ImageSpec) FullX() int
- func (s *ImageSpec) FullY() int
- func (s *ImageSpec) FullZ() int
- func (s *ImageSpec) Height() int
- func (s *ImageSpec) ImageBytes(native bool) int
- func (s *ImageSpec) ImagePixels() int
- func (s *ImageSpec) NumChannels() int
- func (s *ImageSpec) PixelBytes(native bool) int
- func (s *ImageSpec) PixelBytesChans(chanBegin, chanEnd int, native bool) int
- func (s *ImageSpec) ScanlineBytes(native bool) int
- func (s *ImageSpec) SetAlphaChannel(val int)
- func (s *ImageSpec) SetAttribute(name string, val interface{}) error
- func (s *ImageSpec) SetChannelFormats(formats []TypeDesc)
- func (s *ImageSpec) SetChannelNames(names []string)
- func (s *ImageSpec) SetDeep(val bool)
- func (s *ImageSpec) SetDepth(val int)
- func (s *ImageSpec) SetFormat(format TypeDesc)
- func (s *ImageSpec) SetFullDepth(val int)
- func (s *ImageSpec) SetFullHeight(val int)
- func (s *ImageSpec) SetFullWidth(val int)
- func (s *ImageSpec) SetFullX(val int)
- func (s *ImageSpec) SetFullY(val int)
- func (s *ImageSpec) SetFullZ(val int)
- func (s *ImageSpec) SetHeight(val int)
- func (s *ImageSpec) SetNumChannels(val int)
- func (s *ImageSpec) SetTileDepth(val int)
- func (s *ImageSpec) SetTileHeight(val int)
- func (s *ImageSpec) SetTileWidth(val int)
- func (s *ImageSpec) SetWidth(val int)
- func (s *ImageSpec) SetX(val int)
- func (s *ImageSpec) SetY(val int)
- func (s *ImageSpec) SetZ(val int)
- func (s *ImageSpec) SetZChannel(val int)
- func (s *ImageSpec) SizeSafe() bool
- func (s *ImageSpec) TileBytes(native bool) int
- func (s *ImageSpec) TileDepth() int
- func (s *ImageSpec) TileHeight() int
- func (s *ImageSpec) TilePixels() int
- func (s *ImageSpec) TileWidth() int
- func (s *ImageSpec) ToXml() string
- func (s *ImageSpec) Width() int
- func (s *ImageSpec) X() int
- func (s *ImageSpec) Y() int
- func (s *ImageSpec) Z() int
- func (s *ImageSpec) ZChannel() int
- type ProgressCallback
- type ROI
- func (r *ROI) ChannelsBegin() int
- func (r *ROI) ChannelsEnd() int
- func (r *ROI) Copy() *ROI
- func (r *ROI) Defined() bool
- func (r *ROI) Depth() int
- func (r *ROI) Destroy()
- func (r *ROI) Height() int
- func (r *ROI) NumChannels() int
- func (r *ROI) NumPixels() int
- func (r *ROI) SetChannelsBegin(ch int)
- func (r *ROI) SetChannelsEnd(ch int)
- func (r *ROI) SetXBegin(x int)
- func (r *ROI) SetXEnd(x int)
- func (r *ROI) SetYBegin(y int)
- func (r *ROI) SetYEnd(y int)
- func (r *ROI) SetZBegin(z int)
- func (r *ROI) SetZEnd(z int)
- func (r *ROI) String() string
- func (r *ROI) Width() int
- func (r *ROI) XBegin() int
- func (r *ROI) XEnd() int
- func (r *ROI) YBegin() int
- func (r *ROI) YEnd() int
- func (r *ROI) ZBegin() int
- func (r *ROI) ZEnd() int
- type TypeDesc
Examples ¶
Constants ¶
const ( // Let OIIO choose the best filter FilterDefault = "" // Let OIIO choose the best filter and filter width FilterDefaultWidth = 0.0 // Use a default system font FontNameDefault = "" // Use the global OIIO-determined thread count GlobalThreads = 0 )
Variables ¶
This section is empty.
Functions ¶
func Add ¶
For all pixels and channels within the designated region, set dst to the sum of image A and image B. All of the images must have the same number of channels.
func AddValue ¶
For all pixels and channels within the designated region, set dst to the sum of image src and float value (added to all channels). All of the images must have the same number of channels.
func AddValues ¶
For all pixels and channels within the designated region, set dst to the sum of image src and per-channel float slice values. All of the images must have the same number of channels.
func ChannelAppend ¶
ChannelAppend appends the channels of A and B together into dst over the region of interest. If a roi is passed, it will be interpreted as being the union of the pixel windows of A and B (and all channels of both images). If dst is not already initialized to a size, it will be resized to be big enough for the region.
func Channels ¶
func Channels(dst, src *ImageBuf, nchannels int, opts ...*ChannelOpts) error
Generic channel shuffling: copy src to dst, but with channels in the order specified by ChannelOpts.Order[0..nchannels-1]. Does not support in-place operation.
See ChannelOpts docs for more details on the options.
func Checker ¶
func Checker(dst *ImageBuf, width, height, depth int, color1, color2 []float32, xoffset, yoffset, zoffset int, opts ...AlgoOpts) error
Checker sets the pixels in the destination image within the specified region to a checkerboard pattern with origin given by the offset values, checker size given by the width, height, depth values, and alternating between color1 and color2. The colors must contain enough values for all channels in the image.
func Checker2D ¶
func Checker2D(dst *ImageBuf, width, height int, color1, color2 []float32, xoffset, yoffset int, opts ...AlgoOpts) error
Checker2D sets the pixels in the destination image within the specified region to a checkerboard pattern with origin given by the offset values, checker size given by the width and height values, and alternating between color1 and color2. The colors must contain enough values for all channels in the image.
Example:
// Create a new 640x480 RGB image, fill it with a two-toned gray // checkerboard, the checkers being 64x64 pixels each. spec := NewImageSpecSize(640, 480, 3, TypeFloat) dark := []float32{0.1, 0.1, 0.1} light := []float32{0.4, 0.4, 0.4} Checker(spec, 64, 64, dark, light, 0, 0)
func ColorConvert ¶
Copy pixels within the ROI from src to dst, applying a color transform. If dst is not yet initialized, it will be allocated to the same size as specified by roi. If roi is not defined it will be all of dst, if dst is defined, or all of src, if dst is not yet defined. In-place operations (dst == src) are supported. If unpremult is true, unpremultiply before color conversion, then premultiply after the color conversion. You may want to use this flag if your image contains an alpha channel. Works with all data types.
func ColorConvertProcessor ¶
func ColorConvertProcessor(dst, src *ImageBuf, cp *ColorProcessor, unpremult bool, opts ...AlgoOpts) error
Copy pixels within the ROI from src to dst, applying a color transform. If dst is not yet initialized, it will be allocated to the same size as specified by roi. If roi is not defined it will be all of dst, if dst is defined, or all of src, if dst is not yet defined. In-place operations (dst == src) are supported. If unpremult is true, unpremultiply before color conversion, then premultiply after the color conversion. You may want to use this flag if your image contains an alpha channel. Works with all data types.
func ComputePixelHashSHA1 ¶
ComputePixelHashSHA1 computes the SHA-1 byte hash for all the pixels in the specifed region of the image. If blocksize > 0, the function will compute separate SHA-1 hashes of each blocksize batch of scanlines, then return a hash of the individual hashes. This is just as strong a hash, but will NOT match a single hash of the entire image (blocksize == 0). But by breaking up the hash into independent blocks, we can parallelize across multiple threads, given by nthreads. The extrainfo provides additional text that will be incorporated into the hash.
func ConstantColors ¶
ConstantColors returns a slice of the constant pixel values of all channels within either the src image, or the specific channel range of the given ROI. If the image does not have constant colors in the given channel range, a nil value is returned.
func Crop ¶
Crop resets dst to be the specified region of src. Note that the crop operation does not actually move the pixels on the image plane or adjust the full/display window; it merely restricts which pixels are copied from src to dst. (Note the difference compared to Cut()).
func Cut ¶
Cut assigns to dst the designated region of src, but shifted to be at the (0,0) origin, and with the full/display resolution set to be identical to the data region.
The nthreads AlgoOpts specifies how many threads (potentially) may be used, but it's not a guarantee. If nthreads == 0, it will use the global OIIO attribute "nthreads". If nthreads == 1, it guarantees that it will not launch any new threads.
func Fill ¶
Fill sets the pixels in the destination image within the specified region to the values in []values. The values slice must point to at least chend values, or the number of channels in the image, whichever is smaller.
func Flatten ¶ added in v1.2.1
Set dst to the flattened composite of deep image src. That is, it converts a deep image to a simple flat image by front-to-back compositing the samples within each pixel. If src is already a non- deep/flat image, it will just copy pixel values from src to dst. If dst is not already an initialized ImageBuf, it will be sized to match src (but made non-deep).
'roi' specifies the region of dst's pixels which will be computed; existing pixels outside this range will not be altered. If not specified, the default ROI value will be the pixel data window of src.
func Flip ¶
Flip copies src (or a subregion of src) to the corresponding pixels of dst, but with the scanlines exchanged vertically.
func Flipflop ¶
Flipflop copies src (or a subregion of src to the corresponding pixels of dst, but with both the rows exchanged vertically and the columns exchanged horizontally (this is equivalent to a 180 degree rotation).
func Flop ¶
Flop copies src (or a subregion of src) to the corresponding pixels of dst, but with the columns exchanged horizontally.
func IsConstantChannel ¶
IsConstantChannel returns true if all pixels of src within the ROI have the given channel value val
func IsConstantColor ¶
IsConstantColor returns true if all pixels of src within the ROI have the same values (for the subset of channels described by roi)
func IsMonochrome ¶
IsMonochrome returns true if the image is monochrome within the ROI, that is, for all pixels within the region, do all channels [roi.chbegin, roi.chend) have the same value? If roi is not defined (the default), it will be understood to be all of the defined pixels and channels of source.
func Mul ¶
For all pixels within the designated region, multiply the pixel values of image A by image B (channel by channel), putting the product in dst. All of the images must have the same number of channels.
func MulValue ¶
For all pixels within the designated region, multiply the pixel values of image A by float value B (applied to all channels), putting the product in dst. All of the images must have the same number of channels.
func MulValues ¶
For all pixels within the designated region, multiply the pixel values of image A by per-channel float array, putting the product in dst. All of the images must have the same number of channels.
func Over ¶
Over sets dst to the composite of A over B using the Porter/Duff definition of "over", returning true upon success and false for any of a variety of failures (as described below).
A and B (and dst, if already defined/allocated) must have valid alpha channels identified by their ImageSpec alpha_channel field. If A or B do not have alpha channels (as determined by those rules) or if the number of non-alpha channels do not match between A and B, Over() will fail.
If dst is not already an initialized ImageBuf, it will be sized to encompass the minimal rectangular pixel region containing the union of the defined pixels of A and B, and with a number of channels equal to the number of non-alpha channels of A and B, plus an alpha channel. However, if dst is already initialized, it will not be resized, and the "over" operation will apply to its existing pixel data window. In this case, dst must have an alpha channel designated and must have the same number of non-alpha channels as A and B, otherwise it will fail.
'roi' AlgoOpts specifies the region of dst's pixels which will be computed; existing pixels outside this range will not be altered. If not specified, the default ROI value will be interpreted as a request to apply "A over B" to the entire region of dst's pixel data.
A, B, and dst need not perfectly overlap in their pixel data windows; pixel values of A or B that are outside their respective pixel data window will be treated as having "zero" (0,0,0...) value.
The nthreads AlgoOpts specifies how many threads (potentially) may be used, but it's not a guarantee. If nthreads == 0, it will use the global OIIO attribute "nthreads". If nthreads == 1, it guarantees that it will not launch any new threads.
Example ¶
srcSpec := NewImageSpecSize(16, 16, 4, TypeFloat) srcSpec.SetAlphaChannel(3) srcA, _ := NewImageBufSpec(srcSpec) srcB, _ := NewImageBufSpec(srcSpec) // Red with 50% alpha Fill(srcA, []float32{1.0, 0.0, 0.0, 0.5}) // Blue with solid alpha Fill(srcB, []float32{0.0, 0.0, 1.0, 1.0}) // Make sure the foreground image is premult Premult(srcA, srcA) dst := NewImageBuf() Over(dst, srcA, srcB)
Output:
func Paste ¶
Copy into dst, beginning at (xbegin, ybegin, zbegin, chbegin), the pixels of src described by roi. If roi is nil, the entirety of src will be used.
func Paste2D ¶
Copy into dst, beginning at (xbegin, ybegin), the pixels of src described by roi. If roi is nil, the entirety of src will be used.
func Premult ¶
Premult copies pixels from src to dst, and in the process multiply all color channels (those not alpha or z) by the alpha value, to "premultiply" them. This presumes that the image starts of as "unassociated alpha" a.k.a. "non-premultipled." The alterations are restricted to the pixels and channels of the supplied ROI (which defaults to all of src). This is just a copy if there is no identified alpha channel (and a no-op if dst and src are the same image).
func RenderTextColor ¶
func RenderTextColor(dst *ImageBuf, x, y int, text string, fontSize int, fontName string, color []float32) error
RenderTextColor renders a text string into image dst, essentially doing an "over" of the character into the existing pixel data. The baseline of the first character will start at position (x,y), and with a nominal height of fontSize (in pixels). The font is given by fontName as either a full pathname to the font file, or a font basename which can be found in the standard system font locations. If an empty string is provided or font is not found, it defaults to some reasonable system font if not supplied at all. The characters will be drawn in opaque white (1.0,1.0,...) in all channels, unless color is supplied (and is expected to point to a float slice of length at least equal to R.Spec().NumChannels).
func Resample ¶
Set dst, over the region of interest, to be a resampled version of the corresponding portion of src (mapping such that the "full" image window of each correspond to each other, regardless of resolution). Unlike Resize(), Resample does not take a filter; it just samples either with a bilinear interpolation (if interpolate is true, the default) or uses the single "closest" pixel (if interpolate is false). This makes it a lot faster than a proper Resize(), though obviously with lower quality (aliasing when downsizing, pixel replication when upsizing). Works on all pixel data types.
func Resize ¶
Set dst, over the region of interest, to be a resized version of the corresponding portion of src (mapping such that the "full" image window of each correspond to each other, regardless of resolution).
Default high-quality filters are used: blackman-harris when upsizing, lanczos3 when downsizing
The nthreads AlgoOpts specifies how many threads (potentially) may be used, but it's not a guarantee. If nthreads == 0, it will use the global OIIO attribute "nthreads". If nthreads == 1, it guarantees that it will not launch any new threads.
func ResizeFilter ¶
Set dst, over the region of interest, to be a resized version of the corresponding portion of src (mapping such that the "full" image window of each correspond to each other, regardless of resolution).
The filter is used to weight the src pixels falling underneath it for each dst pixel. The caller may specify a reconstruction filter by name and width (expressed in pixels unts of the dst image), or ResizeFilter() will choose a reasonable default high-quality default filter (blackman-harris when upsizing, lanczos3 when downsizing) if the empty string is passed or if filterWidth is 0.
The nthreads AlgoOpts specifies how many threads (potentially) may be used, but it's not a guarantee. If nthreads == 0, it will use the global OIIO attribute "nthreads". If nthreads == 1, it guarantees that it will not launch any new threads.
func Sub ¶
For all pixels and channels within the designated region, subtract image B from image A. All of the images must have the same number of channels.
func SubValue ¶
For all pixels and channels within the designated region, subtract float value (subtracted from all channels) from image src. All of the images must have the same number of channels.
func SubValues ¶
For all pixels and channels within the designated region, subtract per-channel float slice B from image src. All of the images must have the same number of channels.
func SupportsOpenColorIO ¶
func SupportsOpenColorIO() bool
Return if OpenImageIO was built with OCIO support
func Transpose ¶
Transpose copies src (or a subregion of src to the corresponding transposed (x$y) pixels
func Unpremult ¶
Unpremult copies pixels from src to dst, and in the process divide all color channels (those not alpha or z) by the alpha value, to "un-premultiply" them. This presumes that the image starts of as "associated alpha" a.k.a. "premultipled." The alterations are restricted to the pixels and channels of the supplied ROI (which defaults to all of src). Pixels in which the alpha channel is 0 will not be modified (since the operation is undefined in that case). This is just a copy if there is no identified alpha channel (and a no-op if dst and src are the same image).
func Zero ¶
Zero out (set to 0, black) the image region. Only the pixels (and channels) in dst that are specified by roi will be altered; the default roi is to alter all the pixels in dst. If dst is uninitialized, it will be resized to be a float ImageBuf large enough to hold the region specified by roi. It is an error to pass both an uninitialied dst and an undefined roi. Works on all pixel data types.
Types ¶
type AlgoOpts ¶
type AlgoOpts struct { // The Region of interest to use when applying the operation. // Some algorithms require either an ROI or to fallback on the // spec of the ImageBuf being given. ROI *ROI // The Threads parameter specifies how many threads (potentially) may // be used, but it's not a guarantee. // If Threads == 0, it will use the global OIIO attribute "threads". // If Threads == 1, it guarantees that it will // not launch any new threads. Threads int }
AlgoOpts allows common arguments to be passed to algorithm functions.
type ChannelOpts ¶
ChannelOpts are options that can be passed to the Channels() function
For any channel in which ChannelOpts.Order[i] < 0, it will just make dst channel i be a constant value set to ChannelOpts.Values[i] (if ChannelOpts.Values is not nil) or 0.0 (if ChannelOpts.Values is nil). If ChannelOpts.Order is nil, it will be interpreted as {0, 1, ..., nchannels-1}, mean- ing that it's only renaming channels, not reordering them. If ChannelOpts.NewNames is not nil, it points to a list of new channel names. Channels for which ChannelOpts.NewNames[i] is the empty string (or all channels, if ChannelOpts.NewNames == nil) will be named as follows: If ChannelOpts.ShuffleNames is false, the result- ing dst image will have default channel names in the usual order ("R", "G", etc.), but if ChannelOpts.ShuffleNames is true, the names will be taken from the corresponding channels of the source image - be careful with this, shuffling both channel ordering and their names could result in no semantic change at all, if you catch the drift.
type ColorConfig ¶
type ColorConfig struct {
// contains filtered or unexported fields
}
Represents the set of all color transformations that are allowed. If OpenColorIO is enabled at build time, this configuration is loaded at runtime, allowing the user to have complete control of all color transformation math. ($OCIO) (See opencolorio.org for details). If OpenColorIO is not enabled at build time, a generic color configuration is provided for minimal color support.
NOTE: ColorConfig(s) and ColorProcessor(s) are potentially heavy-weight. Their construction / destruction should be kept to a minimum.
func NewColorConfig ¶
func NewColorConfig() (*ColorConfig, error)
If OpenColorIO is enabled at build time, initialize with the current color configuration. ($OCIO) If OpenColorIO is not enabled, this does nothing.
Multiple calls to this are inexpensive.
func NewColorConfigPath ¶
func NewColorConfigPath(path string) (*ColorConfig, error)
If OpenColorIO is enabled at build time, initialize with the specified color configuration (.ocio) file If OpenColorIO is not enabled, this will result in an error.
Multiple calls to this are potentially expensive.
func (*ColorConfig) ColorSpaceNameByIndex ¶
func (c *ColorConfig) ColorSpaceNameByIndex(index int) string
Return the name of the colorspace at a given index
func (*ColorConfig) ColorSpaceNameByRole ¶
func (c *ColorConfig) ColorSpaceNameByRole(role string) string
Get the name of the color space representing the named role, or empty string if none could be identified.
func (*ColorConfig) CreateColorProcessor ¶
func (c *ColorConfig) CreateColorProcessor(inColorSpace, outColorSpace string) (*ColorProcessor, error)
Given the specified input and output ColorSpace, construct the processor. It is possible that this will return nil and an error, if the inputColorSpace doesnt exist, the outputColorSpace doesn't exist, or if the specified transformation is illegal (for example, it may require the inversion of a 3D-LUT, etc). When the user is finished with a ColorProcess, ColorProcess.Destroy() should be called. ColorProcessor(s) remain valid even if the ColorConfig that created them no longer exists.
Multiple calls to this are potentially expensive, so you should call once to create a ColorProcessor to use on an entire image (or multiple images), NOT for every scanline or pixel separately!
func (*ColorConfig) Destroy ¶ added in v1.1.0
func (c *ColorConfig) Destroy()
Destroy the object immediately instead of waiting for GC.
func (*ColorConfig) DisplayNameByIndex ¶
func (c *ColorConfig) DisplayNameByIndex(index int) string
Return the name of the display at a given index
func (*ColorConfig) LookNameByIndex ¶
func (c *ColorConfig) LookNameByIndex(index int) string
Return the name of the look at a given index
func (*ColorConfig) NumColorSpaces ¶
func (c *ColorConfig) NumColorSpaces() int
Get the number of ColorSpace(s) defined in this configuration
func (*ColorConfig) NumDisplays ¶
func (c *ColorConfig) NumDisplays() int
Get the number of displays defined in this configuration
func (*ColorConfig) NumLooks ¶
func (c *ColorConfig) NumLooks() int
Get the number of Looks defined in this configuration
func (*ColorConfig) NumViews ¶
func (c *ColorConfig) NumViews(displayName string) int
Get the number of displays defined in this configuration
func (*ColorConfig) ViewNameByIndex ¶
func (c *ColorConfig) ViewNameByIndex(displayName string, index int) string
Get the name of a view at a specific index of a display
type ColorProcessor ¶
type ColorProcessor struct {
// contains filtered or unexported fields
}
The ColorProcessor encapsulates a baked color transformation, suitable for application to raw pixels, or ImageBuf(s). These are generated using ColorConfig.CreateColorProcessor, and referenced in ImageBufAlgo (amongst other places)
func (*ColorProcessor) Destroy ¶ added in v1.1.0
func (c *ColorProcessor) Destroy()
Destroy the object immediately instead of waiting for GC.
type IBStorage ¶
type IBStorage int
Description of where the pixels live for this ImageBuf
const ( // Derive the file format from the file path name (empty string) FileFormatAuto = "" IBStorageLocalBuffer IBStorage = C.IBSTORAGE_LOCALBUFFER IBStorageAppBuffer IBStorage = C.IBSTORAGE_APPBUFFER IBStorageImageCache IBStorage = C.IBSTORAGE_IMAGECACHE IBStorageUninitialized IBStorage = C.IBSTORAGE_UNINITIALIZED )
type ImageBuf ¶
type ImageBuf struct {
// contains filtered or unexported fields
}
An ImageBuf is a simple in-memory representation of a 2D image. It uses ImageInput and ImageOutput underneath for its file I/O, and has simple routines for setting and getting individual pixels, that hides most of the details of memory layout and data representation (translating to/from float automatically).
func NewImageBuf ¶
func NewImageBuf() *ImageBuf
Construct an empty/uninitialized ImageBuf. This is relatively useless until you call reset().
func NewImageBufPath ¶
Construct an ImageBuf to read the named image - but don't actually read it yet! The image will actually be read when other methods need to access the spec and/or pixels, or when an explicit call to init_spec() or read() is made, whichever comes first.
Uses the global/shared ImageCache.
func NewImageBufPathCache ¶
func NewImageBufPathCache(path string, cache *ImageCache) (*ImageBuf, error)
Construct an ImageBuf to read the named image - but don't actually read it yet! The image will actually be read when other methods need to access the spec and/or pixels, or when an explicit call to init_spec() or read() is made, whichever comes first.
Uses an explicitly passed ImageCache
func NewImageBufSpec ¶
Construct an Imagebuf given a proposed spec describing the image size and type, and allocate storage for the pixels of the image (whose values will be uninitialized).
func (*ImageBuf) CachedPixels ¶
func (*ImageBuf) Copy ¶
Try to copy the pixels and metadata from src to this, returning true upon success and false upon error/failure.
If the previous state of this was uninitialized, owning its own local pixel memory, or referring to a read-only image backed by ImageCache, then local pixel memory will be allocated to hold the new pixels and the call always succeeds unless the memory cannot be allocated.
If this previously referred to an app-owned memory buffer, the memory cannot be re-allocated, so the call will only succeed if the app-owned buffer is already the correct resolution and number of channels. The data type of the pixels will be converted automatically to the data type of the app buffer.
func (*ImageBuf) CopyMetadata ¶
Copy all the metadata from src to this (except for pixel data resolution, channel information, and data format).
func (*ImageBuf) CopyPixels ¶
Copy the pixel data from src to this, automatically converting to the existing data format of this. It only copies pixels in the overlap regions (and channels) of the two images; pixel data in this that do exist in src will be set to 0, and pixel data in src that do not exist in this will not be copied.
func (*ImageBuf) Destroy ¶ added in v1.1.0
func (i *ImageBuf) Destroy()
Destroy the object immediately instead of waiting for GC.
func (*ImageBuf) FileFormatName ¶
Return the name of the image file format of the disk file we read into this image. Returns an empty string if this image was not the result of a Read().
func (*ImageBuf) GetFloatPixels ¶
GetFloatPixels retrieves the rectangle of pixels spanning the entire image, at the current subimage and MIP-map level, storing the float pixel values in a []float32
func (*ImageBuf) GetPixelRegion ¶
GetPixelRegion retrieves the rectangle of pixels defined by an ROI, at the current subimage and MIP-map level, storing the pixel values in a slice that has been casted to an interface, and in the pixel format type described by 'format'.
The underlying type of data is determined by the given TypeDesc. Returned interface{} will be:
TypeUint8 => []uint8 TypeInt8 => []int8 TypeUint16 => []uint16 TypeInt16 => []int16 TypeUint => []uint TypeInt => []int TypeUint64 => []uint64 TypeInt64 => []int64 TypeHalf => []float32 TypeFloat => []float32 TypeDouble => []float64
Example:
val, err := buf.GetPixelRegion(roi, TypeFloat) if err != nil { panic(err.Error()) } floatPixels := val.([]float32)
func (*ImageBuf) GetPixels ¶
GetPixels retrieves the rectangle of pixels spanning the entire image, at the current subimage and MIP-map level, storing the pixel values in a slice that has been casted to an interface, and in the pixel format type described by 'format'.
The underlying type of data is determined by the given TypeDesc. Returned interface{} will be:
TypeUint8 => []uint8 TypeInt8 => []int8 TypeUint16 => []uint16 TypeInt16 => []int16 TypeUint => []uint TypeInt => []int TypeUint64 => []uint64 TypeInt64 => []int64 TypeHalf => []float32 TypeFloat => []float32 TypeDouble => []float64
Example:
val, err := buf.GetPixels(TypeFloat) if err != nil { panic(err.Error()) } floatPixels := val.([]float32)
func (*ImageBuf) ImageCache ¶
func (i *ImageBuf) ImageCache() *ImageCache
Return the ImageCache in which backs this ImageBuf
func (*ImageBuf) InitSpec ¶
Initialize this ImageBuf with the named image file, and read its header to fill out the spec correctly. Return true if this succeeded, false if the file could not be read. But don't allocate or read the pixels.
func (*ImageBuf) Initialized ¶
Is this ImageBuf object initialized?
func (*ImageBuf) LastError ¶
Return the last error generated by API calls. An nil error will be returned if no error has occured.
func (*ImageBuf) NativeSpec ¶
Return a reference to the "native" image spec (that describes the file, which may be slightly different than the spec of the ImageBuf, particularly if the IB is backed by an ImageCache that is imposing some particular data format or tile size).
func (*ImageBuf) NumChannels ¶
Return the number of color channels in the image.
func (*ImageBuf) NumMipLevels ¶
Return the number of miplevels of the current subimage.
func (*ImageBuf) NumSubImages ¶
Return the number of subimages in the file.
func (*ImageBuf) Orientation ¶
By default, image pixels are ordered from the top of the display to the bottom, and within each scanline, from left to right (i.e., the same ordering as English text and scan progression on a CRT). But the "Orientation" field can suggest that it should be displayed with a different orientation, according to the TIFF/EXIF conventions:
1 normal (top to bottom, left to right) 2 flipped horizontally (top to botom, right to left) 3 rotate 180 (bottom to top, right to left) 4 flipped vertically (bottom to top, left to right) 5 transposed (left to right, top to bottom) 6 rotated 90 clockwise (right to left, top to bottom) 7 transverse (right to left, bottom to top) 8 rotated 90 counter-clockwise (left to right, bottom to top)
func (*ImageBuf) OrientedFullHeight ¶
func (*ImageBuf) OrientedFullWidth ¶
func (*ImageBuf) OrientedFullX ¶
func (*ImageBuf) OrientedFullY ¶
func (*ImageBuf) OrientedHeight ¶
func (*ImageBuf) OrientedWidth ¶
func (*ImageBuf) PixelsValid ¶
func (*ImageBuf) Read ¶
Read the file from disk. Generally will skip the read if we've already got a current version of the image in memory, unless force==true. This uses ImageInput underneath, so will read any file format for which an appropriate imageio plugin can be found.
func (*ImageBuf) ReadCallback ¶
func (i *ImageBuf) ReadCallback(force bool, progress *ProgressCallback) error
Read the file from disk. Generally will skip the read if we've already got a current version of the image in memory, unless force==true. This uses ImageInput underneath, so will read any file format for which an appropriate imageio plugin can be found.
This call optionally supports passing a callback pointer to both track the progress, and to optionally abort the processing. The callback function will receive a float32 value indicating the percentage done of the processing, and should return true if the process should abort, and false if it should continue.
func (*ImageBuf) ReadFormatCallback ¶
func (i *ImageBuf) ReadFormatCallback(force bool, convert TypeDesc, progress *ProgressCallback) error
Read the file from disk. Generally will skip the read if we've already got a current version of the image in memory, unless force==true. This uses ImageInput underneath, so will read any file format for which an appropriate imageio plugin can be found.
Specify a specific conversion format or TypeUnknown for automatic handling.
This call optionally supports passing a callback pointer to both track the progress, and to optionally abort the processing. The callback function will receive a float32 value indicating the percentage done of the processing, and should return true if the process should abort, and false if it should continue.
func (*ImageBuf) ReadSubImage ¶ added in v1.3.0
Read the file from disk. Generally will skip the read if we've already got a current version of the image in memory, unless force==true. This uses ImageInput underneath, so will read any file format for which an appropriate imageio plugin can be found.
func (*ImageBuf) ReadSubImageCallback ¶ added in v1.3.0
func (i *ImageBuf) ReadSubImageCallback(subimage, miplevel int, force bool, progress *ProgressCallback) error
Read the file from disk. Generally will skip the read if we've already got a current version of the image in memory, unless force==true. This uses ImageInput underneath, so will read any file format for which an appropriate imageio plugin can be found.
This call optionally supports passing a callback pointer to both track the progress, and to optionally abort the processing. The callback function will receive a float32 value indicating the percentage done of the processing, and should return true if the process should abort, and false if it should continue.
func (*ImageBuf) ReadSubImageFormatCallback ¶ added in v1.3.0
func (i *ImageBuf) ReadSubImageFormatCallback(subimage, miplevel int, force bool, convert TypeDesc, progress *ProgressCallback) error
Read the file from disk. Generally will skip the read if we've already got a current version of the image in memory, unless force==true. This uses ImageInput underneath, so will read any file format for which an appropriate imageio plugin can be found.
Specify a specific conversion format or TypeUnknown for automatic handling.
This call optionally supports passing a callback pointer to both track the progress, and to optionally abort the processing. The callback function will receive a float32 value indicating the percentage done of the processing, and should return true if the process should abort, and false if it should continue.
func (*ImageBuf) Reset ¶ added in v1.3.0
func (i *ImageBuf) Reset(filename string, cache *ImageCache) error
Reset forgets all previous info, and resets this ImageBuf to a new image that is uninitialized (no pixel values, no size or spec). 'cache' may be nil, or can be a specific cache to use instead of the global.
func (*ImageBuf) ResetNameSpec ¶ added in v1.3.0
ResetNameSpec forgets all previous info, and reset this ImageBuf to a blank image of the given name and dimensions.
func (*ImageBuf) ResetSpec ¶ added in v1.3.0
ResetSpec forgets all previous info, and reset this ImageBuf to a blank image of the given dimensions.
func (*ImageBuf) ResetSubImage ¶ added in v1.3.0
func (i *ImageBuf) ResetSubImage(filename string, subimage, miplevel int, cache *ImageCache, config *ImageSpec) error
ResetSubImage forgets all previous info, and resets this ImageBuf to a new image that is uninitialized (no pixel values, no size or spec). If 'config' is not nil, it points to an ImageSpec giving requests or special instructions to be passed on to the eventual ImageInput.Open() call. 'cache' may be nil, or can be a specific cache to use instead of the global.
func (*ImageBuf) SetFull ¶
Set the "full" (a.k.a. display) window to [xbegin,xend) x [ybegin,yend) x [zbegin,zend).
func (*ImageBuf) SetROIFull ¶
Set full/display window for this ImageBuf to a ROI. Does NOT change the channels of the spec, regardless of newroi.
func (*ImageBuf) SetWriteFormat ¶
Inform the ImageBuf what data format you'd like for any subsequent write().
func (*ImageBuf) SetWriteTiles ¶
Inform the ImageBuf what tile size (or no tiling, for 0) for any subsequent Write*()
func (*ImageBuf) SpecMod ¶
Return a writable reference to the image spec that describes the buffer. Use with extreme caution! If you use this for anything other than adding attribute metadata, you are really taking your chances!
func (*ImageBuf) WriteFile ¶
Write the image to the named file and file format (fileformat=="" means to infer the type from the filename extension).
func (*ImageBuf) WriteFileProgress ¶
func (i *ImageBuf) WriteFileProgress(filepath, fileformat string, progress *ProgressCallback) error
Write the image to the named file and file format (fileformat=="" means to infer the type from the filename extension).
This call optionally supports passing a callback pointer to both track the progress, and to optionally abort the processing. The callback function will receive a float32 value indicating the percentage done of the processing, and should return true if the process should abort, and false if it should continue.
func (*ImageBuf) WriteImageOutput ¶
func (i *ImageBuf) WriteImageOutput(output *ImageOutput) error
Write the image to the open ImageOutput 'out'. Return true if all went ok, false if there were errors writing. It does NOT close the file when it's done (and so may be called in a loop to write a multi-image file).
func (*ImageBuf) WriteImageOutputProgress ¶
func (i *ImageBuf) WriteImageOutputProgress(output *ImageOutput, progress *ProgressCallback) error
Write the image to the open ImageOutput 'out'. Return true if all went ok, false if there were errors writing. It does NOT close the file when it's done (and so may be called in a loop to write a multi-image file).
This call optionally supports passing a callback pointer to both track the progress, and to optionally abort the processing. The callback function will receive a float32 value indicating the percentage done of the processing, and should return true if the process should abort, and false if it should continue.
type ImageCache ¶
type ImageCache struct {
// contains filtered or unexported fields
}
Define an API to an abstract class that manages image files, caches of open file handles as well as tiles of pixels so that truly huge amounts of image data may be accessed by an application with low memory footprint.
func CreateImageCache ¶
func CreateImageCache(shared bool) *ImageCache
Create an ImageCache. *This should be freed by calling ImageCache.Destroy()*
If shared==true, it's intended to be shared with other like-minded owners in the same process who also ask for a shared cache.
If false, a private image cache will be created.
func (*ImageCache) Clear ¶
func (i *ImageCache) Clear()
Close everything, free resources, start from scratch.
func (*ImageCache) Destroy ¶
func (i *ImageCache) Destroy(teardown bool)
Destroy a ImageCache that was created using CreateImageCache(). When 'teardown' parameter is set to true, it will fully destroy even a "shared" ImageCache.
func (*ImageCache) GetStats ¶
func (i *ImageCache) GetStats(level int) string
Return the statistics output as a huge string. Suitable default for level == 1
func (*ImageCache) Invalidate ¶
func (i *ImageCache) Invalidate(filename string)
Invalidate any loaded tiles or open file handles associated with the filename, so that any subsequent queries will be forced to re-open the file or re-load any tiles (even those that were previously loaded and would ordinarily be reused). A client might do this if, for example, they are aware that an image being held in the cache has been updated on disk. This is safe to do even if other procedures are currently holding reference-counted tile pointers from the named image, but those procedures will not get updated pixels until they release the tiles they are holding.
func (*ImageCache) InvalidateAll ¶
func (i *ImageCache) InvalidateAll(force bool)
Invalidate all loaded tiles and open file handles. This is safe to do even if other procedures are currently holding reference-counted tile pointers from the named image, but those procedures will not get updated pixels until they release the tiles they are holding. If force is true, everything will be invalidated, no matter how wasteful it is, but if force is false, in actuality files will only be invalidated if their modification times have been changed since they were first opened.
func (*ImageCache) LastError ¶
func (i *ImageCache) LastError() error
Return the last error generated by API calls. An nil error will be returned if no error has occured.
func (*ImageCache) ResetStats ¶
func (i *ImageCache) ResetStats()
Reset most statistics to be as they were with a fresh ImageCache. Caveat emptor: this does not flush the cache itelf, so the resulting statistics from the next set of texture requests will not match the number of tile reads, etc., that would have resulted from a new ImageCache.
type ImageInput ¶
type ImageInput struct {
// contains filtered or unexported fields
}
ImageInput abstracts the reading of an image file in a file format-agnostic manner.
func OpenImageInput ¶
func OpenImageInput(filename string) (*ImageInput, error)
Create an ImageInput subclass instance that is able to read the given file and open it, returning the opened ImageInput if successful. If it fails, return error.
func (*ImageInput) Close ¶
func (i *ImageInput) Close() error
Close an image that we are totally done with.
func (*ImageInput) CurrentMipLevel ¶
func (i *ImageInput) CurrentMipLevel() int
Returns the index of the MIPmap image that is currently being read. The highest-res MIP level (or the only level, if there is just one) is number 0.
func (*ImageInput) CurrentSubimage ¶
func (i *ImageInput) CurrentSubimage() int
CurrentSubimage returns the index of the subimage that is currently being read. The first subimage (or the only subimage, if there is just one) is number 0.
func (*ImageInput) Destroy ¶ added in v1.1.0
func (i *ImageInput) Destroy()
Destroy the object immediately instead of waiting for GC.
func (*ImageInput) FormatName ¶
func (i *ImageInput) FormatName() string
Return the name of the format implemented by this image.
func (*ImageInput) LastError ¶
func (i *ImageInput) LastError() error
Return the last error generated by API calls. An nil error will be returned if no error has occured.
func (*ImageInput) Open ¶
func (i *ImageInput) Open(filename string) error
Open file with given name. Return true if the file was found and opened okay.
func (*ImageInput) ReadImage ¶
func (i *ImageInput) ReadImage() ([]float32, error)
Read the entire image of width * height * depth * channels into contiguous float32 pixels. Read tiles or scanlines automatically.
func (*ImageInput) ReadImageFormat ¶
func (i *ImageInput) ReadImageFormat(format TypeDesc, progress *ProgressCallback) (interface{}, error)
Read the entire image of width * height * depth * channels into contiguous pixels. Read tiles or scanlines automatically.
This call supports passing a callback pointer to both track the progress, and to optionally abort the processing. The callback function will receive a float32 value indicating the percentage done of the processing, and should return true if the process should abort, and false if it should continue.
The underlying type of data is determined by the given TypeDesc. Returned interface{} will be:
TypeUint8 => []uint8 TypeInt8 => []int8 TypeUint16 => []uint16 TypeInt16 => []int16 TypeUint => []uint TypeInt => []int TypeUint64 => []uint64 TypeInt64 => []int64 TypeHalf => []float32 TypeFloat => []float32 TypeDouble => []float64
Example:
// Without a callback val, err := in.ReadImageFormat(TypeFloat, nil) if err != nil { panic(err.Error()) } floatPixels := val.([]float32) // With a callback var cbk ProgressCallback = func(done float32) bool { fmt.Printf("Progress: %0.2f\n", done) // Keep processing (return true to abort) return false } val, _ = in.ReadImageFormat(TypeFloat, &cbk) floatPixels = val.([]float32)
func (*ImageInput) ReadScanline ¶
func (i *ImageInput) ReadScanline(y, z int) ([]float32, error)
Read the scanline that includes pixels (*,y,z), converting if necessary from the native data format of the file into contiguous float32 pixels (z==0 for non-volume images). The size of the slice is: width * depth * channels
func (*ImageInput) ReadTile ¶
func (i *ImageInput) ReadTile(x, y, z int) ([]float32, error)
Read the tile whose upper-left origin is (x,y,z), converting if necessary from the native data format of the file into contiguous float32 pixels. The size of the slice is: tilewidth * tileheight * depth * channels (z==0 for non-volume images.)
func (*ImageInput) SeekMipLevel ¶
func (i *ImageInput) SeekMipLevel(subimage, miplevel int, newSpec *ImageSpec) bool
Seek to the given subimage and MIP-map level within the open image file. The first subimage of the file has index 0, the highest-resolution MIP level has index 0. Return true on success, false on failure (including that there is not a subimage or MIP level with the specified index). The new subimage's vital statistics are put in newspec (and also saved in ImageInpit.Spec()). The reader is expected to give the appearance of random access to subimages and MIP levels -- in other words, if it can't randomly seek to the given subimage/level, it should transparently close, reopen, and sequentially read through prior subimages and levels.
func (*ImageInput) SeekSubimage ¶
func (i *ImageInput) SeekSubimage(index int, newSpec *ImageSpec) bool
Seek to the given subimage within the open image file. The first subimage of the file has index 0. Return true on success, false on failure (including that there is not a subimage with the specified index). The new subimage's vital statistics are put in newspec (and also saved in ImageInput.Spec()). The reader is expected to give the appearance of random access to subimages -- in other words, if it can't randomly seek to the given subimage, it should transparently close, reopen, and sequentially read through prior subimages.
func (*ImageInput) Spec ¶
func (i *ImageInput) Spec() *ImageSpec
Return a reference to the image format specification of the current subimage/MIPlevel. Note that the contents of the spec are invalid before Open() or after Close(), and may change with a call to SeekSubImage().
func (*ImageInput) Supports ¶
func (i *ImageInput) Supports(feature string) bool
Given the name of a 'feature', return whether this ImageOutput supports output of images with the given properties. Feature names that ImageIO plugins are expected to recognize include:
"tiles" Is this format able to write tiled images? "rectangles" Does this plugin accept arbitrary rectangular pixel regions, not necessarily aligned to scanlines or tiles? "random_access" May tiles or scanlines be written in any order (false indicates that they MUST be in successive order). "multiimage" Does this format support multiple subimages within a file? "appendsubimage" Does this format support adding subimages one at a time through open(name,spec,AppendSubimage)? If not, then open(name,subimages,specs) must be used instead. "mipmap" Does this format support multiple resolutions for an image/subimage? "volumes" Does this format support "3D" pixel arrays? "rewrite" May the same scanline or tile be sent more than once? (Generally, this will be true for plugins that implement interactive display.) "empty" Does this plugin support passing a NULL data pointer to write_scanline or write_tile to indicate that the entire data block is zero? "channelformats" Does the plugin/format support per-channel data formats? "displaywindow" Does the format support display ("full") windows distinct from the pixel data window? "origin" Does the format support a nonzero x,y,z origin of the pixel data window? "negativeorigin" Does the format support negative x,y,z and full_{x,y,z} origin values? "deepdata" Deep (multi-sample per pixel) data
Note that main advantage of this approach, versus having separate individual supports_foo() methods, is that this allows future expansion of the set of possible queries without changing the API, adding new entry points, or breaking linkage compatibility.
func (*ImageInput) ValidFile ¶
func (i *ImageInput) ValidFile(filename string) bool
Return true if the named file is file of the type for this ImageInput. The implementation will try to determine this as efficiently as possible, in most cases much less expensively than doing a full Open(). Note that a file can appear to be of the right type (i.e., ValidFIle() returning true) but still fail a subsequent call to Open(), such as if the contents of the file are truncated, nonsensical, or otherwise corrupted.
type ImageOutput ¶
type ImageOutput struct {
// contains filtered or unexported fields
}
ImageOutput abstracts the writing of an image file in a file format-agnostic manner.
func OpenImageOutput ¶
func OpenImageOutput(filename string) (*ImageOutput, error)
Create an ImageOutput that will write to a file, with the format inferred from the extension of the name. This just creates the ImageOutput, it does not open the file.
func (*ImageOutput) Destroy ¶ added in v1.1.0
func (i *ImageOutput) Destroy()
Destroy the object immediately instead of waiting for GC.
func (*ImageOutput) FormatName ¶
func (i *ImageOutput) FormatName() string
Return the name of the format implemented by this image.
func (*ImageOutput) LastError ¶
func (i *ImageOutput) LastError() error
Return the last error generated by API calls. An nil error will be returned if no error has occured.
func (*ImageOutput) Spec ¶
func (i *ImageOutput) Spec() *ImageSpec
Return a reference to the image format specification of the current subimage/MIPlevel. Note that the contents of the spec will be empty unless it is further added to it
func (*ImageOutput) Supports ¶
func (i *ImageOutput) Supports(feature string) bool
Given the name of a 'feature', return whether this ImageOutput supports output of images with the given properties. Feature names that ImageIO plugins are expected to recognize include:
"tiles" Is this format able to write tiled images? "rectangles" Does this plugin accept arbitrary rectangular pixel regions, not necessarily aligned to scanlines or tiles? "random_access" May tiles or scanlines be written in any order (false indicates that they MUST be in successive order). "multiimage" Does this format support multiple subimages within a file? "appendsubimage" Does this format support adding subimages one at a time through open(name,spec,AppendSubimage)? If not, then open(name,subimages,specs) must be used instead. "mipmap" Does this format support multiple resolutions for an image/subimage? "volumes" Does this format support "3D" pixel arrays? "rewrite" May the same scanline or tile be sent more than once? (Generally, this will be true for plugins that implement interactive display.) "empty" Does this plugin support passing a NULL data pointer to write_scanline or write_tile to indicate that the entire data block is zero? "channelformats" Does the plugin/format support per-channel data formats? "displaywindow" Does the format support display ("full") windows distinct from the pixel data window? "origin" Does the format support a nonzero x,y,z origin of the pixel data window? "negativeorigin" Does the format support negative x,y,z and full_{x,y,z} origin values? "deepdata" Deep (multi-sample per pixel) data
Note that main advantage of this approach, versus having separate individual supports_foo() methods, is that this allows future expansion of the set of possible queries without changing the API, adding new entry points, or breaking linkage compatibility.
type ImageSpec ¶
type ImageSpec struct {
// contains filtered or unexported fields
}
ImageSpec describes the data format of an image - dimensions, layout, number and meanings of image channels.
func NewImageSpec ¶
given just the data format, set the default quantize and set all other channels to something reasonable.
func NewImageSpecSize ¶
for simple 2D scanline image with nothing special. If fmt is not supplied, default to unsigned 8-bit data.
func (*ImageSpec) AlphaChannel ¶
Index of alpha channel, or -1 if not known.
func (*ImageSpec) AttributeFloat ¶
AttributeFloat looks up an existing attrib by name and returns the float value, or a default value if it does not exist. Default value is 0, if not specified.
func (*ImageSpec) AttributeInt ¶
AttributeInt looks up an existing attrib by name and returns the int value, or a default value if it does not exist. Default value is 0, if not specified.
func (*ImageSpec) AttributeString ¶
AttributeString looks up an existing attrib by name and returns the string value, or a default value if it does not exist. Default value is an empty string, if not specified.
func (*ImageSpec) ChannelBytes ¶
Return the number of bytes for each channel datum, assuming they are all stored using the data format given by format.
func (*ImageSpec) ChannelBytesChan ¶
Return the number of bytes needed for the single specified channel. If native is false (default), compute the size of one channel of format, but if native is true, compute the size of the channel in terms of the "native" data format of that channel as stored in the file.
func (*ImageSpec) ChannelFormat ¶
func (*ImageSpec) ChannelFormats ¶
Optional per-channel formats.
func (*ImageSpec) ChannelNames ¶
String name of each channel
func (*ImageSpec) DefaultChannelNames ¶
func (s *ImageSpec) DefaultChannelNames()
Set the channelnames to reasonable defaults ("R", "G", "B", "A"), and alpha_channel, based on the number of channels.
func (*ImageSpec) Destroy ¶ added in v1.1.0
func (s *ImageSpec) Destroy()
Destroy the object immediately instead of waiting for GC.
func (*ImageSpec) EraseAttribute ¶
EraseAttribute removes the specified attribute from the list of extra_attribs. If not found, do nothing. If caseSensitive is true, the name search will be case-sensitive, otherwise the name search will be performed without regard to case
func (*ImageSpec) EraseAttributeType ¶
EraseAttributeType removes the specified attribute from the list of extra_attribs. If not found, do nothing. If searchtype is anything but TypeUnknown, restrict matches to only those of the given type. If caseSensitive is true, the name search will be case-sensitive, otherwise the name search will be performed without regard to case
func (*ImageSpec) FullHeight ¶
height of the full (display) window
func (*ImageSpec) ImageBytes ¶
Return the number of bytes for an entire image. This will return a max value in the event of an overflow where it's not representable in an int. If native is false, assume all channels are in format, but if native is true, compute the size of a pixel in the "native" data format of the file (these may differ in the case of per-channel formats).
func (*ImageSpec) ImagePixels ¶
Return the number of pixels for an entire image. This will return a max value in the event of an overflow where it's not representable in an int.
func (*ImageSpec) NumChannels ¶
number of image channels, e.g., 4 for RGBA
func (*ImageSpec) PixelBytes ¶
Return the number of bytes for each pixel (counting all channels). If native is false, assume all channels are in format, but if native is true, compute the size of a pixel in the "native" data format of the file (these may differ in the case of per-channel formats). This will return a max value in the event of an overflow where it's not representable in a int.
func (*ImageSpec) PixelBytesChans ¶
Return the number of bytes for just the subset of channels in each pixel described by [chanBegin, chanEnd). If native is false, assume all channels are in format, but if native is true, compute the size of a pixel in the "native" data format of the file (these may differ in the case of per-channel formats). This will return a max value in the event of an overflow where it's not representable in a int.
func (*ImageSpec) ScanlineBytes ¶
Return the number of bytes for each scanline. This will return a max value in the event of an overflow where it's not representable in an int. If native is false, assume all channels are in format, but if native is true, compute the size of a pixel in the "native" data format of the file (these may differ in the case of per-channel formats).
func (*ImageSpec) SetAlphaChannel ¶
func (*ImageSpec) SetAttribute ¶
SetAttribute sets a metadata value in the extra attribs. Acceptable types are string, int, and float32.
Example:
s = NewImageSpec(...) s.SetAttribute("foo_str", "blah") s.SetAttribute("foo_int", 14) s.SetAttribute("foo_float", 3.14)
func (*ImageSpec) SetChannelFormats ¶
func (*ImageSpec) SetChannelNames ¶
SetChannelNames re-labels each existing channel, from a slice of string names.
func (*ImageSpec) SetFormat ¶
Set the data format, and as a side effect set quantize to good defaults for that format
func (*ImageSpec) SetFullDepth ¶
func (*ImageSpec) SetFullHeight ¶
func (*ImageSpec) SetFullWidth ¶
func (*ImageSpec) SetNumChannels ¶
func (*ImageSpec) SetTileDepth ¶
func (*ImageSpec) SetTileHeight ¶
func (*ImageSpec) SetTileWidth ¶
func (*ImageSpec) SetZChannel ¶
Set the index of the depth channel.
func (*ImageSpec) SizeSafe ¶
Verify that on this platform, a size_t is big enough to hold the number of bytes (and pixels) in a scanline, a tile, and the whole image. If this returns false, the image is much too big to allocate and read all at once, so client apps beware and check these routines for overflows!
func (*ImageSpec) TileBytes ¶
Return the number of bytes for each a tile of the image. This will return a max value in the event of an overflow where it's not representable in an imagesize_t. If native is false, assume all channels are in format, but if native is true, compute the size of a pixel in the "native" data format of the file (these may differ in the case of per-channel formats).
func (*ImageSpec) TileHeight ¶
tile height (0 for a non-tiled image)
func (*ImageSpec) TilePixels ¶
Return the number of pixels for a tile. This will return a max value in the event of an overflow where it's not representable in an int.
type ProgressCallback ¶
For image processing functions that accept a callback to monitor progress. A function that will be passed a float value indicating the progress percentage of the current operation. If the functon returns true, then the process should be aborted. Return false to allow processing to continue.
type ROI ¶
type ROI struct {
// contains filtered or unexported fields
}
Helper struct describing a region of interest in an image. The region is [xbegin,xend) x [begin,yend) x [zbegin,zend), with the "end" designators signifying one past the last pixel, a la C++ STL style.
func NewROIRegion2D ¶
Constructor with an explicitly defined region, where you are concerned with just the X/Y region, and not the Z or the channels
func NewROIRegion3D ¶
Constructor with an explicitly defined region. Reasonable default values are:
zbegin = 0 zend = 1 chbegin = 0 chend = 1000
func (*ROI) ChannelsBegin ¶
func (*ROI) ChannelsEnd ¶
func (*ROI) Destroy ¶ added in v1.1.0
func (r *ROI) Destroy()
Destroy the object immediately instead of waiting for GC.
func (*ROI) SetChannelsBegin ¶
func (*ROI) SetChannelsEnd ¶
type TypeDesc ¶
type TypeDesc int
Various representation formats for image data
const ( TypeUnknown TypeDesc = C.TYPE_UNKNOWN TypeUint8 TypeDesc = C.TYPE_UINT8 TypeInt8 TypeDesc = C.TYPE_INT8 TypeUint16 TypeDesc = C.TYPE_UINT16 TypeInt16 TypeDesc = C.TYPE_INT16 TypeUint TypeDesc = C.TYPE_UINT TypeInt TypeDesc = C.TYPE_INT TypeUint64 TypeDesc = C.TYPE_UINT64 TypeInt64 TypeDesc = C.TYPE_INT64 TypeHalf TypeDesc = C.TYPE_HALF TypeFloat TypeDesc = C.TYPE_FLOAT TypeDouble TypeDesc = C.TYPE_DOUBLE )