Fixes fit resizing smaller images and adds comments about broken scaling
This commit is contained in:
parent
eb17eb1859
commit
120d0dd63e
|
@ -0,0 +1,5 @@
|
||||||
|
P3 6 4 1
|
||||||
|
1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1
|
||||||
|
1 1 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0
|
||||||
|
1 1 0 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0
|
||||||
|
1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1
|
22
main.go
22
main.go
|
@ -152,6 +152,9 @@ func (i *image) BuildCells(bm []int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO this works for shrinking mostly, but blowing up is broken
|
||||||
|
// particularly for small images. This is due to rows being combined
|
||||||
|
// in pairs. Maybe this processing can happen elsewhere?
|
||||||
func (i *image) ScaleColor(newWidth int) {
|
func (i *image) ScaleColor(newWidth int) {
|
||||||
newHeight := int(float64(newWidth) * (float64(i.height) / float64(i.width))) / 2
|
newHeight := int(float64(newWidth) * (float64(i.height) / float64(i.width))) / 2
|
||||||
|
|
||||||
|
@ -173,6 +176,9 @@ func (i *image) ScaleColor(newWidth int) {
|
||||||
i.colorImage = out
|
i.colorImage = out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO this works for shrinking mostly, but blowing up is broken
|
||||||
|
// particularly for small images. This is due to rows being combined
|
||||||
|
// in pairs. Maybe this processing can happen elsewhere?
|
||||||
func (i *image) Scale(newWidth int) {
|
func (i *image) Scale(newWidth int) {
|
||||||
newHeight := int(float64(newWidth) * (float64(i.height) / float64(i.width))) / 2
|
newHeight := int(float64(newWidth) * (float64(i.height) / float64(i.width))) / 2
|
||||||
|
|
||||||
|
@ -293,19 +299,23 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
HandleError(err)
|
HandleError(err)
|
||||||
}
|
}
|
||||||
if *fitToWidth || *scaleToWidth != -1 {
|
cols := -1
|
||||||
cols, _ := termios.GetWindowSize()
|
if *fitToWidth {
|
||||||
|
cols, _ = termios.GetWindowSize()
|
||||||
if img.width < cols {
|
if img.width < cols {
|
||||||
cols = img.width
|
cols = -1
|
||||||
}
|
|
||||||
if *scaleToWidth != -1 {
|
|
||||||
cols = *scaleToWidth
|
|
||||||
}
|
}
|
||||||
|
} else if *scaleToWidth != -1 {
|
||||||
|
cols = *scaleToWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
if cols != -1 {
|
||||||
if img.pbmType == "P3" {
|
if img.pbmType == "P3" {
|
||||||
img.ScaleColor(cols)
|
img.ScaleColor(cols)
|
||||||
} else {
|
} else {
|
||||||
img.Scale(cols)
|
img.Scale(cols)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(img.String())
|
fmt.Print(img.String())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue