diff --git a/examples/test-pattern.ppm b/examples/test-pattern.ppm new file mode 100644 index 0000000..d01c1aa --- /dev/null +++ b/examples/test-pattern.ppm @@ -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 diff --git a/main.go b/main.go index 39fcb0d..37a1467 100644 --- a/main.go +++ b/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()) }