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