Saucexages v0.2.0 Saucexages.AnsiFlags View Source

ANSiFlags allow an author of ANSi and similar files to provide a clue to a viewer / editor how to render the image.

ANSiFlags use the following binary layout:

<<0, 0, 0, aspect_ratio::2, letter_spacing::2, non_blink_mode::1>>

Aspect ratio

Most modern display devices have square pixels, but that has not always been the case. Displaying an ANSI file that was created for one of the older devices on a device with square pixels will vertically compress the image slightly. This can be compensated for by either taking a font that is slightly taller than was used on the legacy device, or by stretching the rendered image.

These 2 bits can be used to signal that the image was created with square pixels in mind, or that it was created for a legacy device with the elongated pixels.

The following values are used to represent decoded aspect ratio flags with respect to image display preferences:

  • :none - Legacy value. No preference.
  • :legacy - Image was created for a legacy device. When displayed on a device with square pixels, either the font or the image needs to be stretched.
  • :modern - Image was created for a modern device with square pixels. No stretching is desired on a device with square pixels.
  • :invalid - Not currently a valid value. This is used to represent an invalid state such as when both aspect ratio bits are set.

Letter Spacing

Letter-spacing for font selection.

Fixed-width text mode as used in DOS and early graphics based computers such as the Amiga used bitmap fonts to display text. Letter-spacing and line spacing is a part of the font bitmap, so the font box inside each bitmap was a bit smaller than the font bitmap.

For the VGA, IBM wanted a smoother font. 2 more lines were added, and the letter-spacing was removed from the font and instead inserted by the VGA hardware during display. All 8 pixels in the font could thus be used, and still have a 1 pixel letter spacing. For the line graphics characters, this was a problem because they needed to match up with their neighbours on both sides. The VGA hardware was wired to duplicate the 8th column of the font bitmap for the character range C0h to DFh. In some code pages was undesired, so this feature could be turned off to get an empty letter spacing on all characters as well (via the ELG field (Enable Line Graphics Character Codes) in the Mode Control register (10h) of the VGA Attribute Controller (3C0h).

While the VGA allows you to enable or disable the 8th column duplication, there is no way to specify which range of characters this needs to be done for, the C0h to DFh range is hardwired into the VGA. These 2 bits can be used to select the 8 pixel or 9 pixel variant of a particular font.

The following values are used to represent decoded letter-spacing flags:

:none - Legacy value. No preference. :eight_pixel_font - Select 8 pixel font. :nine_pixel_font - Select 9 pixel font. invalid - Not currently a valid value.

Changing the font width and wanting to remain at 80 characters per row means that you need to adjust for a change in horizontal resolution (from 720 pixels to 640 or vice versa). When you are trying to match the original aspect ratio (see the AR bits), you will need to adjust the vertical stretching accordingly.

Only the VGA (and the Hercules) video cards actually supported fonts 9 pixels wide. SAUCE does not prevent you from specifying you want a 9 pixel wide font for a font that technically was never used that way. Note that duplicating the 8th column on non-IBM fonts (and even some code pages for IBM fonts) may not give the desired effect. Some people like the 9 pixel fonts, some do not because it causes a visible break in the 3 ‘shadow blocks’ (B0h, B1h and B2h)

When 0, only the 8 low intensity colors are supported for the character background. The high bit set to 1 in each attribute byte results in the foreground color blinking repeatedly.

When 1, all 16 colors are supported for the character background. The high bit set to 1 in each attribute byte selects the high intensity color instead of blinking.

The following values are used to represent a decode non-blink mode flag:

  • true - All 16 color support for character backgrounds, i.e. iCE Color
  • false - Only 8 low intensity colors for character backgrounds, i.e. iCE Color is not supported.

Source

The content in these docs was adapted from the following source:

Link to this section Summary

Functions

Decodes and returns human-readable ansi flags, as specified in the given ANSi flags

Returns the aspect ratio to be used for display as specified in the given ANSi flags

Returns the letter spacing as specified in the given ANSi flags to be used for fonts

Returns whether or not non-blink mode (iCE Colors) are set in the given ANSi flags

Converts an integer t_flags value to binary

Converts a binary t_flags value to an integer

Link to this section Types

Link to this type ansi_flags() View Source
ansi_flags() :: integer() | binary()
Link to this type aspect_ratio() View Source
aspect_ratio() :: :none | :legacy | :modern | :invalid
Link to this type letter_spacing() View Source
letter_spacing() :: :none | :eight_pixel_font | :nine_pixel_font | :invalid
Link to this type t() View Source
t() :: %Saucexages.AnsiFlags{
  aspect_ratio: aspect_ratio(),
  letter_spacing: letter_spacing(),
  non_blink_mode?: boolean()
}

Link to this section Functions

Link to this function ansi_flags(t_flags) View Source
ansi_flags(ansi_flags()) :: t()

Decodes and returns human-readable ansi flags, as specified in the given ANSi flags.

Examples

iex> Saucexages.AnsiFlags.ansi_flags(0)
%Saucexages.AnsiFlags{
aspect_ratio: :none,
letter_spacing: :none,
non_blink_mode?: false
}

iex> Saucexages.AnsiFlags.ansi_flags(17)
%Saucexages.AnsiFlags{
aspect_ratio: :modern,
letter_spacing: :none,
non_blink_mode?: true
}

iex> Saucexages.AnsiFlags.ansi_flags(2)
%Saucexages.AnsiFlags{
aspect_ratio: :none,
letter_spacing: :eight_pixel_font,
non_blink_mode?: false
}

iex>  Saucexages.AnsiFlags.ansi_flags(5)
%Saucexages.AnsiFlags{
aspect_ratio: :none,
letter_spacing: :nine_pixel_font,
non_blink_mode?: true
}
Link to this function aspect_ratio(t_flags) View Source
aspect_ratio(ansi_flags()) :: aspect_ratio()

Returns the aspect ratio to be used for display as specified in the given ANSi flags.

Examples

iex> Saucexages.AnsiFlags.aspect_ratio(<<16>>)
:modern

iex> Saucexages.AnsiFlags.aspect_ratio(1)
:none

iex> Saucexages.AnsiFlags.aspect_ratio(8)
:legacy

iex> Saucexages.AnsiFlags.aspect_ratio(16)
:modern
Link to this function letter_spacing(t_flags) View Source
letter_spacing(ansi_flags()) :: letter_spacing()

Returns the letter spacing as specified in the given ANSi flags to be used for fonts.

Examples

iex> Saucexages.AnsiFlags.letter_spacing(<<2>>)
:eight_pixel_font

iex> Saucexages.AnsiFlags.letter_spacing(11)
:eight_pixel_font

iex> Saucexages.AnsiFlags.letter_spacing(12)
:nine_pixel_font

iex> Saucexages.AnsiFlags.letter_spacing(14)
:invalid
Link to this function to_binary(t_flags) View Source
to_binary(integer()) :: binary()

Converts an integer t_flags value to binary.

Link to this function to_integer(t_flags) View Source
to_integer(binary()) :: integer()

Converts a binary t_flags value to an integer.