Bitmap Converter

Bitmaps which can be used with C/GUI are normally defined as GUI_BITMAP structures in C. The structures or rather the picture data which is referenced by these structures can be quite large. It is time-consuming and inefficient to generate these bitmaps manually, especially if you are dealing with images of considerable size and with multiple shades of gray or colors. We therefore recommend using the bitmap converter, which automatically generates C files from bitmaps. The bitmap converter is an easy to use Windows program. Simply load a bitmap (in the form of a .bmp file) into the application. Convert the color format if you want or have to, and convert the bitmap into a C file by saving it in the appropriate format. The C file may then be compiled, allowing the image to be shown on your display with C/GUI.
What it doesBitmaps which can be used with C/GUI are normally defined as GUI_BITMAP structures in C. The structures or rather the picture data which is referenced by these structures can be quite large. It is time-consuming and inefficient to generate these bitmaps manually, especially if you are dealing with images of considerable size and with multiple shades of gray or colors. We therefore recommend using the bitmap converter, which automatically generates C files from bitmaps. The bitmap converter is an easy to use Windows program. Simply load a bitmap (in the form of a .bmp file) into the application. Convert the color format if you want or have to, and convert the bitmap into a C file by saving it in the appropriate format. The C file may then be compiled, allowing the image to be shown on your display with C/GUI.
What it does

The bitmap converter is intended as a tool to convert bitmaps from a PC format to a C file. It also features color conversion, so that the resulting C code is not unnecessarily large. You would typically reduce the number of bits per pixel in order to reduce memory consumption. The bitmap converter displays the converted image. A number of simple functions can be performed with the bitmap converter, including flipping the bitmap horizontally or vertically, rotating it, and inverting the bitmap indices or colors (these features can be found under the Image menu). Any further modifications to an image must be made in a bitmap manipulation program such as Adobe Photoshop or Corel Photopaint. It usually makes the most sense to perform any image modifications in such a program, using the bitmap converter for converting purposes only.

Loading a bitmap

Loading from a file
The bitmap converter is intended as a tool to convert bitmaps from a PC format to a C file. It also features color conversion, so that the resulting C code is not unnecessarily large. You would typically reduce the number of bits per pixel in order to reduce memory consumption. The bitmap converter displays the converted image. A number of simple functions can be performed with the bitmap converter, including flipping the bitmap horizontally or vertically, rotating it, and inverting the bitmap indices or colors (these features can be found under the Image menu). Any further modifications to an image must be made in a bitmap manipulation program such as Adobe Photoshop or Corel Photopaint. It usually makes the most sense to perform any image modifications in such a program, using the bitmap converter for converting purposes only.
Loading a bitmap
Loading from a file

A bitmap image in .bmp format may be opened directly in the bitmap converter by selecting File/Open . The following .bmp files may be loaded:

  • 1,4,8,16 or 32 bits per pixel (bpp) with palette;
  • 24 bpp without palette (RGB/full-color mode);
  • RLE4 and RLE8.
Using the clipboard
Any other type of bitmap (i.e. .gif , .jpg , .jpeg , .png , .tif ) may be opened with another program, copied to the clipboard, and pasted into the bitmap converter. This process will achieve the same effect as loading directly from a file.
Generating C files from bitmaps
The main function of the bitmap converter is to convert PC-formatted bitmaps into C files which can be used by C/GUI. Before doing so, however, it is often desirable to modify the color palette of an image so that the generated C file is not excessively large. When using full-color bitmaps, it will be necessary to convert the image into a palette format, as the bitmap converter cannot generate C files from bitmaps in full-color mode. The bitmap may be saved as a .bmp file (which can be reloaded and used or loaded into other bitmap manipulation programs) or as a C file. A C file will serve as an input file for your C compiler. It may contain a palette (device-independent bitmap, or DIB) or be saved without (device-dependent bitmap, or DDB). DIBs are recommended, as they will display correctly on any LCD; a DDB will only display correctly on an LCD which uses the same palette as the bitmap. "C"-files may be generated as "C/GUI C with palette", "C/GUI C without palette", "C/GUI C with palette, compressed" or "C/GUI C without palette, compressed".

The basic procedure for using the bitmap converter is illustrated step by step in the table below:

Step 1:

  • Start the application.
  • The bitmap converter is opened as an empty window
Step 2:
  • Load a bitmap into the bitmap converter.
  • Choose File/Open .
  • Locate the document you want to open and click Open (must be a .bmp file).
  • In this example, the file MicriumLogo.bmp is chosen.
The bitmap converter displays the loaded bitmap. Step 3:
  • Convert the image if necessary.
  • Choose Image/Convert Into .
  • Select the desired palette.
  • In this example, the option Best palette is chosen.
  • The bitmap converter displays the converted bitmap.
The image is unchanged in terms of appearance, but uses less memory since a palette of only 2 colors is used instead of the full-color mode. These 2 colors are the only ones actually required to display this particular image.
Step 4:
  • Save the bitmap as a C file.
  • Choose File/Save.
  • Select a destination and a name for the C file.
  • Select the file type. In this example, the file is saved as "C" with palette (*.c)."
  • Click Save.
  • The bitmap converter will create a separate file in the specified destination, containing the C source code for the bitmap.
Color conversion

The primary reason for converting the color format of a bitmap is to reduce memory consumption. The most common way of doing this is by using the option Best palette as in the above example, which customizes the palette of a particular bitmap to include only the colors which are used in the image. It is especially useful with full-color bitmaps in order to make the palette as small as possible while still fully supporting the image. Once a bitmap file has been opened in the bitmap converter, simply select Image/Convert Into/Best palette from the menu.
For certain applications, it may be more efficient to use a fixed color palette, chosen from the menu under Image/Convert Into . For example, suppose a bitmap in full-color mode is to be shown on a display which supports only four gray scales. It would be a waste of memory to keep the image in the original format, since it would only appear as four gray scales on the display. The full-color bitmap can be converted into a four-grayscale, 2bpp bitmap for maximum efficiency. The procedure for conversion would be as follows: The bitmap converter is opened and the same file is loaded as in steps 1 and 2 of the previous example.
The bitmap converter displays the loaded bitmap.
Choose Image/Convert Into/Gray4. The bitmap converter displays the converted bitmap.
In this example, the image uses less memory since a palette of only 4 gray scales is used instead of the full-color mode. If the target display supports only 4 gray scales, there is no use in having a higher pixel depth as it would only waste memory.

Compressed bitmaps

The bitmap converter and C/GUI support run-length encoding (RLE) compression of bitmaps in the resulting source code files. The RLE compression method works most efficiently if your bitmap contains many horizontal sequences of equal-colored pixels. An efficiently compressed bitmap will save a significant amount of space. However, compression is not recommended for photographic images since they do not normally have sequences of identical pixels. It should also be noted that a compressed image may take slightly longer to display. If you want to save a bitmap using RLE compression, you can do so by selecting one of the compressed output formats when saving as a C file: "C with palette, compressed" or "C without palette, compressed". There are no special functions needed for displaying compressed bitmaps; it works in the same way as displaying uncompressed bitmaps.
Compression ratios
The ratio of compression achieved will vary depending on the bitmap used. The more horizontal uniformity in the image, the better the ratio will be. A higher number of bits per pixel will also result in a higher degree of compression. In the bitmap used in the previous examples, the total number of pixels in the image is (200*94) = 18,800. Since 2 pixels are stored in 1 byte, the total uncompressed size of the image is 18,800/2 = 9,400 bytes. The total compressed size for this particular bitmap is 3,803 bytes for 18,800 pixels. The ratio of compression can therefore be calculated as 9,400/3,803 = 2.47.

Using a custom palette
Under certain circumstances it may be desirable to use a custom palette for conversions. In these cases (usually only if you have a color display using a special custom palette and you would like to use the same palette for bitmaps) a custom palette may be used. In the menu, you would select Image/Convert Into/Custom palette.
File format for custom palette
Custom palette files are simple files defining the available colors for conversion. They contain the following:
  • Header (8 bytes).
  • NumColors (U32, 4 bytes).
  • 0 (4 bytes).
  • U32 Colors[NumColors] (NumColors*4 bytes, type GUI_COLOR)
Total file size is therefore: 16+(NumColors*4) bytes. A custom palette file with 8 colors would be 16+(8*4) = 48 bytes. At this point, a binary editor must be used in order to create such a file. The maximum number of colors supported is 256; the minimum is 2.

Custom palette sample file
This sample file would define a palette containing 2 colors -- red and white: 0000: 65 6d 57 69 6e 50 61 6c 02 00 00 00 00 00 00 00 0010: ff 00 00 00 ff ff ff 00 The 8 headers make up the first eight bytes of the first line. The U32 is stored lsb first (big endian) and represents the next four bytes, followed by the four 0 bytes. Colors are stored 1 byte per color, where the 4th byte is 0 as follows: RRGGBB00. The second line of code therefore defines the two colors used in this sample.
BmpCvt.exe: Command line usage It is also possible to work with the bitmap converter using the command prompt . All conversion functions available in the bitmap converter menu are available as commands, and any number of functions may be performed on a bitmap in one command line. Commands are entered using the following format: BmpCvt .bmp <-command> (If more than one command is used, one space is typed between each.) For example, a bitmap with the name logo.bmp is converted into Best palette format and saved as a C file named logo.bmp all at once by entering the following at the command prompt: BmpCvt logo.bmp -convertintobestpalette -saveaslogo,1 -exit
Note that while the file to be loaded into the bitmap converter always includes its .bmp extension, no file extension is written in the -saveas command. An integer is used instead to specify the desired file type. The number 1 in the -saveas command above designates "C with palette". The -exit command automatically closes the program upon completion. See the table below for more information.
Members Login
username
password
New MemberRegister Here
Newsletter Signup