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) {
|
||||
newHeight := int(float64(newWidth) * (float64(i.height) / float64(i.width))) / 2
|
||||
|
||||
|
@ -173,6 +176,9 @@ func (i *image) ScaleColor(newWidth int) {
|
|||
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) {
|
||||
newHeight := int(float64(newWidth) * (float64(i.height) / float64(i.width))) / 2
|
||||
|
||||
|
@ -293,19 +299,23 @@ func main() {
|
|||
if err != nil {
|
||||
HandleError(err)
|
||||
}
|
||||
if *fitToWidth || *scaleToWidth != -1 {
|
||||
cols, _ := termios.GetWindowSize()
|
||||
cols := -1
|
||||
if *fitToWidth {
|
||||
cols, _ = termios.GetWindowSize()
|
||||
if img.width < cols {
|
||||
cols = img.width
|
||||
}
|
||||
if *scaleToWidth != -1 {
|
||||
cols = *scaleToWidth
|
||||
cols = -1
|
||||
}
|
||||
} else if *scaleToWidth != -1 {
|
||||
cols = *scaleToWidth
|
||||
}
|
||||
|
||||
if cols != -1 {
|
||||
if img.pbmType == "P3" {
|
||||
img.ScaleColor(cols)
|
||||
} else {
|
||||
img.Scale(cols)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print(img.String())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue