utils

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp8bit

func Clamp8bit(value int) uint8

Clamp8bit clamp the value between 0 and 255:

Parameters:

  • value: int

Returns:

  • uint8

func Clamp16bit

func Clamp16bit(val int32) uint16

Clamp16bit clamp the value between 0 and 65535:

Parameters:

  • value: int32

Returns:

  • uint16

func ClampFloat64 added in v0.7.5

func ClampFloat64(value, min, max float64) float64

ClampFloat64 clamps a float64 value between a minimum and maximum value.

Parameters:

  • value: float64 representing the value to be clamped
  • min: float64 representing the minimum value
  • max: float64 representing the maximum value

Returns:

  • float64 representing the clamped value

func ClampGeneric

func ClampGeneric(value, min, max int) int

ClampGeneric constrains an integer value between a minimum and maximum value.

Parameters:

  • value: int representing the value to be clamped
  • min: int representing the minimum allowed value
  • max: int representing the maximum allowed value

Returns:

  • int representing the clamped value

func ColorAverage added in v0.6.4

func ColorAverage(colors []color.Color) color.Color

ColorAverage calculates the average color of a slice of colors:

Parameters:

  • colors: []color.Color

Returns:

  • color.Color

func Luminance8bit

func Luminance8bit(r, g, b uint32) float64

Luminance8bit calculates the luminance of an image (0-255) using the formula: L = 0.299*R + 0.587*G + 0.114*B

Parameters:

  • r,g,b: uint32 representing the red, green, and blue components of a color

Returns:

  • float64 representing the luminance of the color

func Luminance16bit

func Luminance16bit(r, g, b uint32) float64

Luminance16bit calculates the luminance of an image (0-65535) using the formula: L = 0.299*R + 0.587*G + 0.114*B

Parameters:

  • r,g,b: uint32 representing the red, green, and blue components of a color

Returns:

  • float64 representing the luminance of the color

func ParallelExecution

func ParallelExecution(exec ParallelExecutionStruct) image.Image

ParallelExecution processes an image in parallel using multiple CPU cores. It distributes the workload by dividing the image into horizontal strips and processing each strip concurrently with the provided function.

Parameters:

  • exec: ParallelExecutionStruct containing the image, processing function, and optional size limit

Returns:

  • image.Image: The resulting processed RGBA64 image

Types

type ParallelExecutionStruct

type ParallelExecutionStruct struct {
	Image    image.Image
	Function func(int, int, *image.RGBA64, *sync.WaitGroup)
	EndSize  int
}

ParallelExecutionStruct contains parameters for parallel image processing.

Fields:

  • Image: The source image to be processed
  • Function: The function to apply to image regions (params: start y, end y, output image, waitgroup)
  • EndSize: Optional limit for the y-coordinate (defaults to image height if <= 0)

Jump to

Keyboard shortcuts

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