Microsoft Paint

Also Known As: MSP


Type Bitmap
Colors Mono
Compression RLE, uncompressed
Maximum Image Size 64Kx64K pixels
Multiple Images Per File No
Numerical Format Little-endian
Originator Microsoft Corporation
Platform Microsoft Windows, MS-DOS
Supporting Applications Microsoft Paint, others
See Also Microsoft Windows Bitmap

Usage
Black-and-white drawings, clip art

Comments
A format that was in wider use in the early days of Microsoft Windows. It is a simple format that is not currently suitable for deep pixel or truecolor images.

Sample images are available for this format.


The Microsoft Paint (MSP) image file format is used exclusively for storing black-and-white images. The vast majority of MSP files contain line drawings and clip art. MSP is used most often by Microsoft Windows applications, but may be used by MS-DOS-based programs as well. The Microsoft Paint format is apparently being replaced by the more versatile Microsoft Windows BMP format; it contains information specifically for use in the Microsoft Windows operating environment. For information on the Windows-specific use of the header information, refer to the Microsoft Paint format specification available from Microsoft.

Contents:
File Organization
File Details
For Further Information

File Organization

The Microsoft Paint header is 32 bytes in length and has the following structure. In the discussion that follows, a WORD is a 16-bit unsigned value.

typedef struct _MicrosoftPaint
{
WORD  Key1;             /* Magic number    */
WORD  Key2;             /* Magic number    */
WORD  Width;            /* Width of the bitmap in pixels   */
WORD  Height;           /* Height of the bitmap in pixels   */
WORD  XARBitmap;        /* X Aspect ratio of the bitmap   */
WORD  YARBitmap;        /* Y Aspect ratio of the bitmap   */
WORD  XARPrinter;       /* X Aspect ratio of the printer   */
WORD  YARPrinter;       /* Y Aspect ratio of the printer   */
WORD  PrinterWidth;     /* Width of the printer in pixels   */
WORD  PrinterHeight;    /* Height of the printer in pixels   */
WORD  XAspectCorr;      /* X aspect correction (unused)     */
WORD  YAspectCorr;      /* Y aspect correction (unused)     */
WORD  Checksum;         /* Checksum of previous 24 bytes   */
WORD  Padding[3];       /* Unused padding    */
}MSPHEAD;

File Details

In the Microsoft Paint header, Key1 and Key2 contain identification values used to determine the version of the file format. For version 1.x of the Microsoft Paint format, the values of the Key1 and Key2 fields are 6144h and 4D6Eh respectively. For version 2.0, the Key1 and Key2 field values are 694Ch and 536Eh respectively.

Width and Height are the size of the bitmap in pixels. The size of the bitmap in bytes is calculated by dividing Width by 8 and multiplying it by Height.

XARBitmap and YARBitmap contain the aspect ratio in pixels of the screen used to create the bitmapped image.

XARPrinter and YARPrinter contain the aspect ratio in pixels of the output device used to render the bitmapped image. When an MSP file is created by a non-Windows application, these four fields typically contains the same values as the Width and Height fields.

PrinterWidth and PrinterHeight contain the size in pixels of the output device for which the image is specifically formatted. Typical values for these fields are the same values as those stored in Width and Height.

XAspectCorr and YAspectCorr are used to store aspect ratio correction information, but are not used in version 2.0 or earlier versions of the Microsoft Paint format and should be set to 0.

Checksum contains the XORed values of the first 12 WORDs of the header. When an MSP file is read, the first 13 WORDs, including the Checksum field, are XORed together, and if the resulting value is 0, the header information is considered valid.

Padding extends the header out to a full 32 bytes in length and is reserved for future use.

The image data directly follows the header. The format of this image data depends upon the version of the Microsoft Paint file. For image files prior to version 2.0, the image data immediately follows the header. There are eight pixels stored per byte, and the data is not encoded.

Each scan line in a version 2.0 or later Microsoft Paint bitmap is always RLE-encoded to reduce the size of the data. Each encoded scan line varies in size depending upon the bit patterns it contains. To aid in the decoding process, a scan-line map immediately follows the header. The scan-line map is used to seek to a specific scan line in the encoded image data without needing to decode all image data prior to it. There is one element in the map per scan line in the image. Each element in the scan-line map is 16 bits in size and contains the number of bytes used to encode the scan line it represents. The scan-line map starts at offset 32 in the MSP file and is sizeof(WORD).

Consider the following example. If an application needs to seek directly to the start of scan-line 20, it adds together the first 20 values in the scan-line map. This sum is the offset from the beginning of the image data of the 20th encoded scan line. The scan-line map values can also be used to double-check that the decoding process read the proper number of bytes for each scan line.

Following the scan-line map is the run-length encoded monochrome bitmapped data. A byte-wise run-length encoding scheme is used to compress the monochrome bitmapped data contained in an MSP-format image file. Each scan line is encoded as a series of packets containing runs of identical byte values. If there are very few runs of identical byte values, or if all the runs are very small, then a way to encode a literal run of different byte values may be used.

The following pseudocode illustrates the decoding process:


Read a BYTE value as the RunType
    If the RunType value is zero
        Read next byte as the RunCount
        Read the next byte as the RunValue
        Write the RunValue byte RunCount times
    If the RunType value is non-zero
        Use this value as the RunCount
        Read and write the next RunCount bytes literally

As you can see, this is yet another variation of a simple run-length encoding scheme. A byte is read, and if it contains a value of 0, then the following byte is the RunCount (the number of bytes in the run). The byte following the RunCount is the RunValue (the value of the bytes in the run). If the byte read is non-zero, then the byte value is used as the RunCount and the next RunCount bytes are read literally from the encoded data stream.

For Further Information

For further information about Microsoft Paint, contact:

Microsoft Corporation
One Microsoft Way
Redmond, WA 98052-6399
Voice: 206-882-8080
FAX: 206-936-7329
BBS: 206-637-9009
WWW: http://www.microsoft.com/

The Microsoft Windows Programmer's Reference Library is the master reference for programmers working with all aspects of Microsoft Windows. The books in this library are supplied with the Microsoft Windows Software Development Kit (SDK). The manuals supplied with the Microsoft C 7.0 Professional Development Systems are also very helpful. You can get information about obtaining these products from:

Microsoft Information Center
Voice: 800-426-9400

You may also be able to get information via FTP through the Developer Relations Group at:

ftp://ftp.microsoft.com/developer/drg/



Copyright © 1996, 1994 O'Reilly & Associates, Inc. All Rights Reserved.