Giter Club home page Giter Club logo

tmg's Introduction

Text Mode Graphic [TMG]

Image file format for elfboot

elfboot is a bootloader for the x86 architecture which uses VGA video mode 3 for displaying information. Since a bootloader usually resides in the first 64 KB of memory, loading and displaying images might waste precious memory. The TMG project aims to drastically reduce image files by only using the 16 available colors in VGA video mode 3 and the ASCII/Code Page 737 character 220 (bottom half block ▄ ).

Basic idea:

Usually, VGA video mode 3 uses 9x16 pixels for each glyph. Since an image consists of square pixels, we use the ▄ glyph to cover half of the area, which results in two vertically stacked pixels. By using the attribute byte of screen character, we can color both "pixels" by defining the foreground color for the bottom and the background color for the top half of the glyph.

 __________________ __________________ _____ _ _
|                  |                  |
|                  |                  |
|                  |  ██████████████  |
|                  |        ██        |
|    Background    |        ██        |
|                  |        ██        |
|                  |        ██        |
|__________________|        ██        |
|██████████████████|        ██        |
|██████████████████|        ██        |
|██████████████████|        ██        |
|█ Code Page 737 ██|                  |
|█ Character 220 ██|                  |
|██████████████████|                  |
|██████████████████|                  |
|██████████████████|__________________|_____ _ _

Further additions:

A new approach has been developed to support transparent images [alpha color is set in the image creation process and thereafter set in the file header]:

  • Both blocks (top and bottom) transparent:
    • background color = alpha color
    • foreground color = black
    • ASCII character 32 (Space)
  • Upper block transparent
    • background color = alpha color
    • foreground color = color of the pixel
    • ASCII character 220 ( ▄ )
  • Lower block transparent
    • background color = alpha color
    • foreground color = color of the pixel
    • ASCII characters 223 ( ▀ )
  • Both blocks have the same color (not transparent):
    • background color = alpha color
    • foreground color = color of the pixels
    • ASCII character 219 ( █ )
  • Both blocks have different colors (not transparent)
    • background color = color of the upper pixel
    • foreground color = color of the lower pixel
    • ASCII character 220 ( ▄ )

TMG File schematic:

  • Mode: 0 or 1
    • 0: smaller image size, no transparency and no ascii values in body
    • 1: bigger image size, transparency and ascii values in body
  • Alpha_Color: color value
  • Width: pixel width of the picture
  • Height: pixel height of the picture
HEADER (8 Byte)
+-----------------------------------------------------------+-------------------+
| "TMG"                                                (3B) | Version      (1B) |
+-------------------+-------------------+-------------------+-------------------+
| Mode         (1B) | Alpha_Color  (1B) | Width        (1B) | Height       (1B) |
+-------------------+-------------------+-------------------+-------------------+
BODY (mode = 0)  
+-------------------------------------------------------------------------------+
| fc ff a3 ...                                                                  | 
|                                                                               |
|                                                                               |
+-------------------------------------------------------------------------------+

fc ff a3 <- this are six pixel

To display this file, the parser must insert the ASCII value ▄ before each color block (1 byte).
fc <- f: 15 = white background, c: 12 = light red foreground

BODY (mode = 1)  
+-------------------------------------------------------------------------------+
| dc fc dc ff dc a3 ...                                                         | 
|                                                                               |
|                                                                               |
+-------------------------------------------------------------------------------+

dc ff dc ff dc a3 <- this are six pixel

dc <- 220 <- ASCII value: ▄
fc <- f: 15 = white background, c: 12 = light red foreground ( color of the ASCII value )

...

Example

This beer image is from the fantastic openmoji (License: CC BY-SA 4.0) project:

alt text

alt text

How to use tmg.py:

alt text

Requirements:

tmg's People

Contributors

croemheld avatar p4cx avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.