Giter Club home page Giter Club logo

nfo2png's Introduction

nfo2png

Greg Kennedy, 2021

Render ASCII text files to PNG images.

Fairlight Logo

Usage

cat input.txt | ./nfo2png.pl > output.png

About

This is a tool to render an ASCII text file to a .png output. There is only one code page supported, CP437, and only one choice of font: the VGA BIOS 9x16 font from the IBM PS/2.

The restrictive set of output formats is deliberate. This script is part of a larger project and is used to render .nfo files, commonly distributed by warez groups along with their releases. NFO files were usually intended for viewing on ANSI-compatible systems, especially MS-DOS, and often featured elaborate ASCII art or logos built from the standard CP437 character set. These systems are rare today: for example, Windows 95 would instead use Windows-1252 by default, replacing many of the box-drawing characters with international characters (accented vowels, etc) instead.

The IBM PS/2, in VGA Text mode, could display 80x25 characters on screen pulled from a 9x16 font. This makes effectively a 720x400 pixel "virtual" screen. However, CRT monitors at the time were exclusively 4:3 which caused the mode to use non-square pixels. In other words, the font at 1:1 appears too wide. The image should be scaled vertically by 1.35x to make a "correct" image. This tool supports integer scaling of the output: with SCALE_W of 3, and SCALE_H of 4, we achieve a 1.33x vertical increase - quite close to the intended value.

Config

A few settings are available by editing these constants at the top of the script:

use constant {
  MARGIN_W => 0,
  MARGIN_H => 0,
  SCALE_W => 3,
  SCALE_H => 4,
  INVERT => 0
};

MARGIN_W and MARGIN_H add extra padding to the sides and top/bottom of the output. The values are in whole-character units, so MARGIN_W => 1 creates an 82-column-wide output image, where the left- and right-most columns are always empty. Similarly, MARGIN_H => 1 effectively adds a blank line to the top and bottom of the output.

SCALE_W and SCALE_H repeat columns or rows in the output image to perform nearest-neighbor upscaling. The minimum values are 1 for each, and must be whole integer values. As stated earlier, SCALE_W => 3 and SCALE_H => 4 achieves a nearly 4:3 aspect ratio as it would appear on legacy hardware.

INVERT can be 0 or 1. When set to 1 it swaps the black and white pixels - in other words, the image will become black text on a white background.

Hacking

The IBM BIOS font is stored as a 16-element list constant, containing long strings of hex characters. Characters are 9 bits wide, which makes editing complicated. These values were obtained by taking a 256x1 image of the IBM character set, converting to .pbm format, and extracting the image data. Perl's vec() function works only in little-endian mode, so it was necessary to reverse the bit positions of each byte when creating the font constant.

Devel::NYTProf was helpful in identifying hot areas of the code to improve, allowing me to drastically cut the runtime.

nfo2png's People

Contributors

greg-kennedy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.