sorter

package
v0.3.3-beta Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSortingCancellation = errors.New("sorter: sorting operation has been cancelled")

Error indicating that the sorting has been cancelled using the sorters CancelSort() function.

Functions

This section is empty.

Types

type BufferedEntry

type BufferedEntry[TEntry any] struct {
	First TEntry
}

type BufferedPairEntry

type BufferedPairEntry[TEntry any] struct {
	First  TEntry
	Second TEntry
}

type BufferedSorter

type BufferedSorter interface {
	// Perform the sorting operation with the given properties and return the sorted version of the image
	Sort(options *SorterOptions) (image.Image, error)

	// Cancel the currently running sorting operation and return a boolean value indicating if the sorting was cancelled
	CancelSort() bool
}

[Experimental] Utility used to create a pixel sorted version of a given image. The buffered sorted is adjusted to be used multiple times on the same input images with different options. The implementation is still in a experimental development state adn the underlying API can change.

func CreateBufferedSorter

func CreateBufferedSorter(image image.Image, mask image.Image, logger SorterLogger) (BufferedSorter, error)

Create a new buffered image sorter instance by providing the image to be sorted and optional parameters such as mask image and a logger instance. This function will return a new buffered sorter instance or a error.

type BufferedSorterState

type BufferedSorterState interface {
	// Apply sorter options changes to the buffered sorter state machine
	Apply(options *SorterOptions)

	// Confirm the incoming changes to the buffered sorter state machine
	Commit()

	// Reset non-commited incoming changes that came to the buffered sorter state machine
	Rollback()

	// Get the buffered scaled images set and a boolean value indicating if the values were buffered
	GetScaledImages() (*image.NRGBA, *image.NRGBA, bool)

	// Set the buffered scaled images associated to the incoming sorter options changes
	SetScaledImages(img, maskImage *image.NRGBA)

	// Get the buffered rotated images set and a boolean value indicating if the values were buffered
	GetRotatedImages() (*image.NRGBA, *image.NRGBA, bool)

	// Set the buffered rotated images associated to the incoming sorter options changes
	SetRotatedImages(img, maskImage *image.NRGBA)

	// Get the buffered edge detection image and a boolean value indicating if the value were buffered
	GetEdgeDetectionImage() (*image.NRGBA, bool)

	// Set the buffered edge detection image associated to the incoming sorter options changes
	SetEdgeDetectionImage(img *image.NRGBA)
}

func CreateBufferedSorterState

func CreateBufferedSorterState() BufferedSorterState

type Interval

type Interval interface {
	// Add a RGBA color to the given interval
	Append(color color.RGBA) error

	// Get the count of colors stored in the interval
	Count() int

	// Get a boolean value representing the presence of elements in the given interval
	Any() bool

	// Sort all interval colors by weight in the specified direction and return the interval as a new slice of RGBA
	// colors. The internal interval items collection will be cleared after the sort.
	Sort(direction SortDirection, painting IntervalPainting) []color.RGBA

	// Sort all interval colors by weight in the specified direction and return the interval by writing the RGBA
	// colors to the provided buffer. The internal interval items collection will be cleared after the sort.
	SortToBuffer(direction SortDirection, painting IntervalPainting, buffer *[]color.RGBA)
}

Collection of image vertical or horizontal pixel neighbours with a propererty meeting some ceratin requirements

func CreateInterval

func CreateInterval(sort SortDeterminant) Interval

Create a new interval instance based on the specifications required by the provided sort determinant

func CreateNormalizedWeightInterval

func CreateNormalizedWeightInterval(weightDeterminantFunc func(color.RGBA) float64) Interval

Create a new interval instance with the item weights represented as normalzied values

func CreateValueWeightInterval

func CreateValueWeightInterval(weightDeterminantFunc func(color.RGBA) int) Interval

Create a new interval instance with the item weights represented as a integer values

type IntervalDeterminant

type IntervalDeterminant int

Flag representing the determinant for spliting the image into intervals

const (
	SplitByBrightness IntervalDeterminant = iota
	SplitByHue
	SplitBySaturation
	SplitByMask
	SplitByAbsoluteColor
	SplitByEdgeDetection
)

type IntervalPainting

type IntervalPainting int

Flag representing the behaviour of interval painting process

const (
	IntervalFill IntervalPainting = iota
	IntervalGradient
	IntervalRepeat
	IntervalAverage
)

type Mask

type Mask interface {
	// Return a byte value representing the mask grayscale value at the given position represented by the x and y position.
	At(x, y int) (uint8, error)

	// Return a boolean value representing if the mask is masking at the given position represented by the x and y postition (value < 127 is masked).
	AtB(x, y int) (bool, error)

	// Return a byte value representing the mask grayscale value at the given position represented by the i index.
	AtByIndex(i int) (uint8, error)

	// Return a boolean value representing if the mask is masking at the given position represented by the i index (value < 127 is masked).
	AtByIndexB(i int) (bool, error)
}

func CreateEmptyMask

func CreateEmptyMask() Mask

func CreateMaskFromNrgba

func CreateMaskFromNrgba(i *image.NRGBA) (Mask, error)

func CreateMaskFromRgba

func CreateMaskFromRgba(i *image.RGBA) (Mask, error)

type ResultImageBlending

type ResultImageBlending int
const (
	BlendingNone ResultImageBlending = iota
	BlendingLighten
	BlendingDarken
)

type SortDeterminant

type SortDeterminant int

Flag representing the determinant parameter for the sorting process

const (
	SortByBrightness SortDeterminant = iota
	SortByHue
	SortBySaturation
	SortByAbsoluteColor
	SortByRedChannel
	SortByGreenChannel
	SortByBlueChannel
)

type SortDirection

type SortDirection int

Flag representing the direction of the sorting

const (
	SortAscending SortDirection = iota
	SortDescending
	Shuffle
	SortRandom
)

type SortOrder

type SortOrder int

Flag representing the order in which should be the image sorted

const (
	SortHorizontal SortOrder = iota
	SortVertical
	SortHorizontalAndVertical
	SortVerticalAndHorizontal
)

type Sorter

type Sorter interface {
	// Perform the sorting operation and return the sorted version of the image
	Sort() (image.Image, error)

	// Cancel the currently running sorting operation and return a boolean value indicating if the sorting was cancelled
	CancelSort() bool
}

Utility used to create a pixel sorted version of a given image

func CreateSorter

func CreateSorter(image image.Image, mask image.Image, logger SorterLogger, options *SorterOptions) (Sorter, error)

Create a new image sorter instance by providing the image to be sorted and optional parameters such as mask image logger instance and custom sorter options. This function will return a new sorter instance or a error.

type SorterLogger

type SorterLogger interface {
	// Log a message with a given format with the Debug log level
	Debugf(format string, args ...interface{})

	// Log a message with a given format with the Info log level
	Infof(format string, args ...interface{})

	// Log a message with a given format with the Warning log level
	Warnf(format string, args ...interface{})

	// Log a message with a given format with the Error log level
	Errorf(format string, args ...interface{})
}

Logger that is able to send log messages from the sorter instance

type SorterOptions

type SorterOptions struct {
	SortDeterminant                   SortDeterminant
	SortDirection                     SortDirection
	SortOrder                         SortOrder
	IntervalDeterminant               IntervalDeterminant
	IntervalPainting                  IntervalPainting
	IntervalDeterminantLowerThreshold float64
	IntervalDeterminantUpperThreshold float64
	IntervalLength                    int
	IntervalLengthRandomFactor        int
	Angle                             int
	UseMask                           bool
	Cycles                            int
	Scale                             float64
	Blending                          ResultImageBlending
}

Structure representing all the parameters for the sorter

func GetDefaultSorterOptions

func GetDefaultSorterOptions() *SorterOptions

Get a SorterOptions structure instance with default values

func (*SorterOptions) AreValid

func (options *SorterOptions) AreValid() (bool, string)

Return a boolean value indicating if the given sorter options combination is valid and a string containing validation failure message if the options came out to be invalid

Jump to

Keyboard shortcuts

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