Display "Real" Image in Terminal

When studying the data visualization tool `Gnuplot` these days, I found an interesting technology: sixel.
Simply put, it's about how to display a bitmap in the terminal.

You may wonder, how could it be possible to display a bitmap in the terminal, since the definition of "terminal" is a character display device?

Exactly. I have to apologize that it's just a convenient way to describe sixel as "bitmap in terminal".
Strictly speaking, sixel is a technology about displays bitmap in a terminal emulator, rather than a terminal.

You may ask, why make things more confused with another jargon?
Well, there's a little quirk here, but trust me, it's not complicated. Let me explain.

When you click the "CMD" icon on Windows, mac, or Linux desktop, the application appeared is a "terminal emulator". The REPL (read, evaluate, print loop) process running inside the terminal emulator is a "terminal". In the viewpoint of a terminal, there's a stream of characters (called standard input, stdin for short). Its job is to interpret the stream to instructions and data. Do what the instruction says, (possibly with the data), and omit the result data to output (called standard output, stdout). And these outputs are meant to be read by human beings like us.

Now the interesting part comes. How do we "read" characters?

The answer may be more complex than what you imagined. The screen has no concept of "character", all it knows is a bitmap. And our eyes don't know characters, too. It receives bitmaps on our retina (not Apple's Retina screen) and our brains interpret those bitmaps into characters. So the bridge between the terminal (only deals with abstract characters) and the screen (only deals with visual bitmaps) is the terminal emulator. It transforms each character from terminal to bitmap according to its "glyph", or "font". To print an image on a terminal emulator, the terminal omits a special sequence of characters called "sixel", and tells the terminal emulator: hi buddy, please rendered these things as a bitmap.

Since the terminal emulator is a device to map characters to bitmap, this task is really a trivial job.

With this technology, we can display "real" images in the terminal, which makes working remotely on a host exactly the same as working on your own laptop. There're other ways to achieve similar effects. For example, by using X forwarding or remote desktop. However sixel is more lightweight than them, hence a good choice when the bandwidth is very limited.

Comments

  1. You are keeping on learning different technologies. I really admire you about this.

    ReplyDelete

Post a Comment

Popular posts from this blog

2023: On the Road

Yet another advice to kids

The Joy of Reading in Natural Light