stefanhaustein / TerminalImageViewer

Small C++ program to display images in a (modern) terminal using RGB ANSI codes and unicode block graphics characters
Other
1.56k stars 111 forks source link

Nothing is rendered at all for very small images at full size #46

Open AlanDeSmet opened 5 years ago

AlanDeSmet commented 5 years ago

Given the attached files, I'd expect some sort of output, but tiv reports nothing.

./tiv -f 1x1.png 2x2.png 3x3.png 4x4.png 5x5.png 

5x5 4x4 3x3 2x2 1x1

I believe this applies to any image less than 8 pixel tall or 4 pixels wide. Ideally, something should be rendered for these tiny images.

I'm imaging two options:

My initial thought was to rescale the image so it's at least 4x8. This commit does exactly that. It's the only commit on the branch fix-tiny.

However, I'm now thinking of a different approach: If the image is smaller than target window in both directions, scale up to fill the space, but limit the scale to the the largest integer that won't cause the image to exceed the allotted space. Also use nearest neightbor interpolation. The result should provide larger "pixels". On the down side, this approach won't work for images that are very narrow but tall or very wide but short. That may yet require special case logic.

AlanDeSmet commented 5 years ago

I'm happy to take a crack at the second proposal I made above, but before I dive in, I'd like to know if you'd welcome it. :-)

stefanhaustein commented 5 years ago

I think the general algorithm should be as follows:

  1. Scale down as necessary to meet the w/h constraints (I think this should work already, but I think that somebody pointed out that determining the terminal size might not work when redirecting the output?)
  2. Expand (=pad) to the nearest 4x8 size

The main problem with 2 might be that we might not know the best background color... perhaps just use the bottom right corner pixel color? Or just black or white?