Raw VGA Image

From ModdingWiki
Jump to navigation Jump to search
Raw VGA Image
There is no example of an image in this format — upload one!
Format typeImage
HardwareVGA
Colour depth8-bit
Minimum size (pixels)0×0
Maximum size (pixels)Unlimited
PaletteVaries
Plane count1
Transparent pixels?No
Hitmap pixels?No
Games

This format is an exact match for the memory layout of VGA standard mode 13.

Each byte in the image data is treated as an 8-bit number for that pixel. The number is an index into the palette, so a number of 1 refers to the second index in the palette (0 being the first.) The bytes/pixels are arranged on the screen from left-to-right, top-to-bottom.

To render an image correctly, some more information is required which is not part of the raw data:

  • Image width
  • Image height (optional; can be deduced from file size and width)
  • Colour palette

Examples

Full-screen images

Full-screen images are 320×200 pixels in size, so at 8bpp they are also 64000 bytes long - in this case often with an accompanying 768-byte palette (256 colours × 24-bits).

In real-mode DOS, the 64000 bytes of image data are loaded into address A000:0000 and the image will appear on the screen, subject to the correct palette being loaded.

Palette

Very few images use the default VGA Palette, and a number of schemes are possible for storing the palette.

  • As a separate file (e.g. example.img and example.pal), typically the palette file is 768-bytes in length
  • Before or after the image data (resulting in a file of 64768 bytes in size for a full-screen image)
  • Stored inside the game executable
  • As part of another image

Unfortunately since there is no standard in this regard, the palette must be located manually.

Source Code

The following code will read and display a raw VGA image, where the 768-byte palette follows the image data at offset 64,000.

' Load needed variables.
Dim sFile As String
Dim sX As UShort, sY As UShort
Dim bPixel As UByte

' Set the file path to the graphic image.
sFile = "E:\Games\SPISPOPD\map.256"
Open sFile For Binary As #1

' Set to 320x200 256 color mode.
Screen 13

' Load and Draw Image.
For sY = 0 To 199
    For sX = 0 To 319
        Get #1, , bPixel
        PSet(sX, sY), bPixel
    Next sX
Next sY

Dim bColor As UShort
Dim bR As UByte, bG As UByte, bB As UByte

' Load and change palette.
For bColor = 0 To 255
    Get #1, , bR
    Get #1, , bG
    Get #1, , bB
    Palette bColor, (bR * 4), (bG * 4), (bB * 4)
Next bColor

' Close the graphic file.
Close #1

' Wait for a key press.
Sleep

Credits

FreeBASIC example code by TheAlmightyGuru. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)