Documentation
¶
Index ¶
- Constants
- func ScaleImage(input image.Image, zoom int) image.Image
- type PngUtil
- type Xbr
- func (xbr *Xbr) Xbr2x(pixelArray *[]uint32, width, height int, blendColors, scaleAlpha bool) (*[]uint32, int, int)
- func (xbr *Xbr) Xbr3x(pixelArray *[]uint32, width, height int, blendColors, scaleAlpha bool) (*[]uint32, int, int)
- func (xbr *Xbr) Xbr4x(pixelArray *[]uint32, width, height int, blendColors, scaleAlpha bool) (*[]uint32, int, int)
Constants ¶
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PngUtil ¶
type PngUtil struct {
// contains filtered or unexported fields
}
func NewPngScaler ¶
NewPngScaler creates and returns a new instance of PngUtil, a utility for scaling PNG images.
This function initializes a PngUtil struct with the specified configuration for image scaling. The PngUtil struct provides methods for scaling PNG images using the xBR algorithm, allowing customization through various options.
Parameters:
blendColors bool: Determines whether color blending should be applied during scaling. When set to true, the algorithm blends colors to create smoother transitions. scaleAlpha bool: Indicates whether alpha values should be scaled, affecting transparency handling. use3XOriginalImplementation bool: Specifies which version of the xBR algorithm to use. If set to true, the original 3X implementation of the algorithm is used. If false, an alternative or updated version is used.
Returns:
*PngUtil: A pointer to a new PngUtil instance, configured with the provided scaling options.
The returned PngUtil instance can be used to perform PNG image scaling operations. The provided options allow for control over color blending, alpha scaling, and the choice of xBR algorithm implementation, affecting the visual outcome and performance of the scaling process.
func (*PngUtil) ScalePng ¶
ScalePng scales a PNG image using the xBR algorithm and saves the result to a file.
This method applies the xBR scaling algorithm to a PNG image specified by `inputFilename`. The scaled image is saved to the file specified by `outputFilename`. The scaling factor is determined by the `zoom` parameter, which can be set to 2, 3, or 4, corresponding to 2x, 3x, or 4x scaling respectively.
Parameters:
inputFilename string: The file path of the input PNG image to be scaled. outputFilename string: The file path where the scaled PNG image will be saved. zoom byte: The scaling factor (2, 3, or 4) to apply to the image.
Returns:
error: An error if the scaling process fails or if invalid arguments are provided. It returns an error if `zoom` is not in the range of 2 to 4, if the input file cannot be loaded, or if there's an issue saving the scaled image.
The method utilizes an `Xbr` scaler instance (created via `NewXbrScaler`) to perform the image scaling. It also uses internal methods `loadPngImage`, `extractPixels`, `createImageFromPixels`, and `savePngImage` for handling image data. The choice of xBR scaling (2x, 3x, or 4x) depends on the `zoom` parameter. The method ensures that only valid zoom levels are used and returns an error for invalid inputs.
type Xbr ¶
type Xbr struct {
// contains filtered or unexported fields
}
func NewXbrScaler ¶
NewXbrScaler creates and returns a new instance of the Xbr scaler.
This function initializes an Xbr struct, which implements the xBR scaling algorithm for pixel art images. The xBR algorithm is used for upscaling low-resolution pixel art while preserving its original artistic style.
Parameter:
use3XOriginalImplementation bool: A flag that determines which version of the xBR algorithm to use. If set to true, the original 3X implementation of the algorithm is used. If false, an alternative or updated version of the algorithm is used.
Returns:
*Xbr: A pointer to a new instance of the Xbr struct configured with the specified algorithm version.
The returned Xbr instance can be used to perform pixel art scaling operations. The choice of algorithm version (original 3X implementation or an alternative) can affect the visual results and performance of the scaling process.
func (*Xbr) Xbr2x ¶
func (xbr *Xbr) Xbr2x(pixelArray *[]uint32, width, height int, blendColors, scaleAlpha bool) (*[]uint32, int, int)
Xbr2x applies the 2x xBR scaling algorithm to a given pixel array.
This method takes a slice of uint32 representing the original pixel data in ARGB format, along with the width and height of the original image. It then scales the image by a factor of 2 using the xBR algorithm, which is designed for pixel art upscaling.
Parameters:
pixelArray *[]uint32: Pointer to a slice of uint32 representing the original pixel data in ARGB format. width, height int: The width and height of the original image. blendColors: A boolean flag indicating whether color blending should be used during the scaling process. When set to true, the algorithm blends colors to create smoother transitions. scaleAlpha: A boolean flag indicating whether alpha values should be scaled, affecting the handling of transparency.
Returns:
*[]uint32: Pointer to a slice of uint32 containing the scaled pixel data. int: The width of the scaled image, which is twice the width of the original image. int: The height of the scaled image, which is twice the height of the original image.
The method uses the computeXbr2x function internally to process each pixel and write the results to a new slice that represents the scaled image. The returned slice contains the pixel data of the scaled image, and its dimensions are double those of the input image.
func (*Xbr) Xbr3x ¶
func (xbr *Xbr) Xbr3x(pixelArray *[]uint32, width, height int, blendColors, scaleAlpha bool) (*[]uint32, int, int)
Xbr3x applies the 3x xBR scaling algorithm to a given pixel array.
This method takes a slice of uint32 representing the original pixel data in ARGB format, along with the width and height of the original image. It then scales the image by a factor of 2 using the xBR algorithm, which is designed for pixel art upscaling.
Parameters:
pixelArray *[]uint32: Pointer to a slice of uint32 representing the original pixel data in ARGB format. width, height int: The width and height of the original image. blendColors: A boolean flag indicating whether color blending should be used during the scaling process. When set to true, the algorithm blends colors to create smoother transitions. scaleAlpha: A boolean flag indicating whether alpha values should be scaled, affecting the handling of transparency.
Returns:
*[]uint32: Pointer to a slice of uint32 containing the scaled pixel data. int: The width of the scaled image, which is twice the width of the original image. int: The height of the scaled image, which is twice the height of the original image.
The method uses the computeXbr2x function internally to process each pixel and write the results to a new slice that represents the scaled image. The returned slice contains the pixel data of the scaled image, and its dimensions are double those of the input image.
func (*Xbr) Xbr4x ¶
func (xbr *Xbr) Xbr4x(pixelArray *[]uint32, width, height int, blendColors, scaleAlpha bool) (*[]uint32, int, int)
Xbr4x applies the 4x xBR scaling algorithm to a given pixel array.
This method takes a slice of uint32 representing the original pixel data in ARGB format, along with the width and height of the original image. It then scales the image by a factor of 2 using the xBR algorithm, which is designed for pixel art upscaling.
Parameters:
pixelArray *[]uint32: Pointer to a slice of uint32 representing the original pixel data in ARGB format. width, height int: The width and height of the original image. blendColors: A boolean flag indicating whether color blending should be used during the scaling process. When set to true, the algorithm blends colors to create smoother transitions. scaleAlpha: A boolean flag indicating whether alpha values should be scaled, affecting the handling of transparency.
Returns:
*[]uint32: Pointer to a slice of uint32 containing the scaled pixel data. int: The width of the scaled image, which is twice the width of the original image. int: The height of the scaled image, which is twice the height of the original image.
The method uses the computeXbr2x function internally to process each pixel and write the results to a new slice that represents the scaled image. The returned slice contains the pixel data of the scaled image, and its dimensions are double those of the input image.