magpie

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsNRGBA

func AsNRGBA(img image.Image) *image.NRGBA

AsNRGBA returns the image as an *image.NRGBA. If the image is already in this format, it is returned directly. Otherwise, a new NRGBA image is created and the content is drawn onto it.

func AsRGBA

func AsRGBA(img image.Image) *image.RGBA

AsRGBA returns the image as an *image.RGBA. If the image is already in this format, it is returned directly. Otherwise, a new RGBA image is created and the content is drawn onto it.

func Blend

func Blend(dst image.Image, r image.Rectangle, src image.Image, sp image.Point, op op.BlendOp, output core.Output) (image.Image, error)

Blend performs a blend operation using the default context. See Context.Blend for details.

func Composite

func Composite(dst image.Image, r image.Rectangle, src image.Image, sp image.Point, op op.CompositeOp, output core.Output) (image.Image, error)

Composite performs a composite operation using the default context. See Context.Composite for details.

func Draw

func Draw(dst image.Image, r image.Rectangle, src image.Image, sp image.Point, oper internal.Op, output core.Output) (image.Image, error)

Draw is the primary function for applying image manipulation operations (both blend and composite) using the default context. It follows similar semantics as Go's draw.Draw function. However, rather than always writing to the destination image, this function writes to a specified output which may be the destination image, a provided image, or a new image. It returns the modified output image.

func DrawToDst

func DrawToDst(dst image.Image, r image.Rectangle, src image.Image, sp image.Point, op internal.Op) (image.Image, error)

DrawToDst is a convenience function that applies an operation using the default context and writes the result directly to the destination image (dst). It is equivalent to calling Draw with ToDst() as the output.

func DrawToImage

func DrawToImage(dst image.Image, r image.Rectangle, src image.Image, sp image.Point, op internal.Op, out image.Image, outPt image.Point) (image.Image, error)

DrawToImage is a convenience function that applies an operation using the default context and writes the result to a user-provided image at a specified point. It is equivalent to calling Draw with ToImage(out, outPt) as the output.

func DrawToNewImage

func DrawToNewImage(dst image.Image, r image.Rectangle, src image.Image, sp image.Point, op internal.Op) (image.Image, error)

DrawToNewImage is a convenience function that applies an operation using the default context and writes the result to a newly created image. It is equivalent to calling Draw with ToNewImage() as the output.

func SetDefaultContext

func SetDefaultContext(ctx Context)

SetDefaultContext sets the default configuration for the project. This will affect all subsequent operations that use the default context.

func ToDst

func ToDst() core.Output

ToDst returns an Output that writes to the destination image.

func ToImage

func ToImage(img image.Image, pt image.Point) core.Output

ToImage returns an Output that writes to the provided image.

func ToNewImage

func ToNewImage() core.Output

ToNewImage returns an Output that creates a new image.

Types

type Context

type Context interface {
	core.Config

	// Blend applies a blend operation and optional compositing.
	// It follows similar semantics as draw.Draw. However, rather than always writing to the destination image,
	// this function writes to output which may be the destination image, a provided image, or a new image.
	// Returns the modified output image.
	Blend(dst image.Image, r image.Rectangle, src image.Image, sp image.Point, op op.BlendOp, out core.Output) (image.Image, error)

	// Composite applies a composite operation.
	// It follows similar semantics as draw.Draw. However, rather than always writing to the destination image,
	// this function writes to output which may be the destination image, a provided image, or a new image.
	// Returns the modified output image.
	Composite(dst image.Image, r image.Rectangle, src image.Image, sp image.Point, op op.CompositeOp, out core.Output) (image.Image, error)
}

Context defines the interface for image manipulation operations. It holds configuration settings that control how blending and compositing operations are performed.

func DefaultContext

func DefaultContext() Context

DefaultContext returns the default Magpie context. This context is used by the top-level Blend and Composite functions.

func NewContext

func NewContext(options ...func(*context)) Context

NewContext creates a new Context with the given options. The default configuration is used as a base, with the options overriding default values.

type Option

type Option func(*context)

Option is a function that configures a Context.

func WithDefaultColorModelNRGBA

func WithDefaultColorModelNRGBA() Option

WithDefaultColorModelNRGBA sets the default color model to NRGBA. The default color model is only used when none of the images use a supported color model.

func WithDefaultColorModelRGBA

func WithDefaultColorModelRGBA() Option

WithDefaultColorModelRGBA sets the default color model to RGBA. The default color model is only used when none of the images use a supported color model.

func WithDefaultToDst

func WithDefaultToDst() Option

WithDefaultToDst sets the default output mode to write to the destination image.

func WithDefaultToNewImage

func WithDefaultToNewImage() Option

WithDefaultToNewImage sets the default output mode to create a new image.

func WithPixelIterator

func WithPixelIterator(concurrency int) Option

WithPixelIterator sets the pixel iterator to be used by the context. The concurrency parameter specifies the number of goroutines to use for parallel processing.

func WithPixelIteratorInstance

func WithPixelIteratorInstance(pixIter core.PixelIterator) Option

WithPixelIteratorInstance sets the pixel iterator to be used by the context. The provided instance will be used instead of creating a new one.

type PixCalculator

type PixCalculator[T image.Image] = core.PixCalculator[T]

PixCalculator calculates the set of Pix slices for a given row.

type PixRowCalculator

type PixRowCalculator = core.PixRowCalculator

type PixelIterator

type PixelIterator = core.PixelIterator

PixelIterator is an alias for core.PixelIterator. It iterates over pixels in an image an passes each row to a PixRowCalculator.

func NewPixelIterator

func NewPixelIterator(concurrency int) PixelIterator

NewPixelIterator creates a new PixelIterator. Concurrency specifies the number of goroutines to use for parallel processing.

Directories

Path Synopsis
image
tests
Package tests contains tests for both nrgba and rgba functions.
Package tests contains tests for both nrgba and rgba functions.

Jump to

Keyboard shortcuts

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