Removed bloat and improved function comments
This commit is contained in:
parent
1bc953f59e
commit
42399c299e
|
|
@ -106,10 +106,11 @@ var asciiTableDetailed = map[int]string{
|
|||
// For each individual element of imgSet in ConvertToASCIISlice()
|
||||
const MAX_VAL float32 = 65535
|
||||
|
||||
// Converts the 2D uint32 slice of image data (each element being each pixel of shrinked image)
|
||||
// to a 2D string slice with each pixel value being compared to a map of hardcoded ascii characters.
|
||||
// Converts the 2D uint32 slice of image data (each value representing each pixel of image)
|
||||
// to a 2D string slice with each string having an ASCII character corresponding to
|
||||
// the original uint32 value.
|
||||
//
|
||||
// This function contains 69 characters
|
||||
// Values are compared to 69 ASCII characters
|
||||
func ConvertToAsciiDetailed(imgSet [][]uint32) [][]string {
|
||||
|
||||
height := len(imgSet)
|
||||
|
|
@ -140,10 +141,11 @@ func ConvertToAsciiDetailed(imgSet [][]uint32) [][]string {
|
|||
return result
|
||||
}
|
||||
|
||||
// Converts the 2D uint32 slice of image data (each element being each pixel of shrinked image)
|
||||
// to a 2D string slice with each pixel value being compared to a map of hardcoded ascii characters.
|
||||
// Converts the 2D uint32 slice of image data (each value representing each pixel of image)
|
||||
// to a 2D string slice with each string having an ASCII character corresponding to
|
||||
// the original uint32 value.
|
||||
//
|
||||
// This function contains 10 characters
|
||||
// Values are compared to 10 ASCII characters
|
||||
func ConvertToAsciiSimple(imgSet [][]uint32) [][]string {
|
||||
|
||||
height := len(imgSet)
|
||||
|
|
|
|||
|
|
@ -32,11 +32,12 @@ import (
|
|||
"github.com/nfnt/resize"
|
||||
)
|
||||
|
||||
// This function shrinks the passed image according to terminal size and
|
||||
// turns it into grayscale pixel by pixel to make ASCII character matching easier
|
||||
// This function shrinks the passed image according to passed dimensions or terminal
|
||||
// size if none are passed turns each pixel into grayscale to simplify getting numeric
|
||||
// data for ASCII character comparison
|
||||
//
|
||||
// The returned 2D uint32 slice contains each corresponding pixel's value to be
|
||||
// compared to an ASCII character
|
||||
// The returned 2D uint32 slice contains each corresponding pixel's value ranging from
|
||||
// 0 to 65535
|
||||
func ConvertToTerminalSizedSlices(img image.Image, dimensions []int) [][]uint32 {
|
||||
|
||||
var terminalWidth, terminalHeight int
|
||||
|
|
@ -83,8 +84,6 @@ func ConvertToTerminalSizedSlices(img image.Image, dimensions []int) [][]uint32
|
|||
smallImg := resize.Resize(uint(terminalWidth), uint(terminalHeight), img, resize.Lanczos3)
|
||||
b := smallImg.Bounds()
|
||||
|
||||
newImg := image.NewGray(b)
|
||||
|
||||
for y := b.Min.Y; y < b.Max.Y; y++ {
|
||||
|
||||
var temp []uint32
|
||||
|
|
@ -92,7 +91,6 @@ func ConvertToTerminalSizedSlices(img image.Image, dimensions []int) [][]uint32
|
|||
|
||||
oldPixel := smallImg.At(x, y)
|
||||
pixel := color.GrayModel.Convert(oldPixel)
|
||||
newImg.Set(x, y, pixel)
|
||||
|
||||
// We only need Red from Red, Green, Blue since they have the same value for grayscale images
|
||||
r, _, _, _ := pixel.RGBA()
|
||||
|
|
|
|||
Loading…
Reference in New Issue