Bitmap Converter
The bitmap converter is a Windows program which is easy to use. Simply load a bitmap (in the form of a .bmp or a .gif file) into the application. Convert the color format if you want or have to, and convert it 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 emWin.
What it does
The bitmap converter is primarily intended as a tool to convert bitmaps from a PC format to a C file. Bitmaps which can be used with emWin 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. We therefore recommend using the bitmap converter, which automatically generates C files from bitmaps. An other useful feature is the ability to save images as C stream files. The advantage against a normal C file is, that these data streams can be located anywhere on any media whereas C files need to be located in the addressable CPU area. 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 scaling the size, 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 modification in such a program, using the bitmap converter for converting purposes only.
Loading a bitmap
Supported input file formats
The bitmap converter basically supports Windows bitmap files (*.bmp), "Graphic Interchange Format" (*.gif) and "Portable Network Graphics" (*.png):
Windows Bitmap Files (BMP)
The bitmap converter supports the most common bitmap file formats. Bitmap files of the following formats can be opened by the bitmap converter:
- 1, 4 or 8 bits per pixel (bpp) with palette;
- 16, 24 or 32 bpp without palette (full-color mode, in which each color is assigned an RGB value);
- RLE4 and RLE8.
Graphic Interchange Format (GIF)
The bitmap converter supports reading of one image per GIF file. If the file for example contains a movie consisting of more than one image, the converter reads only the first image. Transparency and interlaced GIF images are supported by the converter.
Portable Network Graphic (PNG)
The PNG format is the most recommended format to create images with alpha blending. The bitmap converter supports reading PNG images with alpha channel.
Other formats
Any other type of bitmap (that is, .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 emWin. 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.
The bitmap may be saved as a .bmp or a .gif 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 display; a DDB will only display correctly on a display which uses the same palette as the bitmap. C files may be generated as "C with palette", "C without palette", "C with palette, compressed" or "C without palette, compressed".
The basic procedure for using the bitmap converter is illustrated step by step in the table below:
Step 1:
| ![]() |
Step 2:
| In this example, the loaded bitmap is in full-color mode. |
Step 3:
| The image is unchanged in terms of appearance, but uses less memory since a palette of only 15 colors is used instead of the full-color mode. These 15 colors are the only ones actually required to display this particular image. |
Step 4:
|
Supported bitmap formats
The following table shows the currently available output formats for C files:
| Format | Color depth | Compression | Transparency | Palette |
|---|---|---|---|---|
| 1 bit per pixel | 1bpp | no | yes | yes |
| 2 bit per pixel | 2bpp | no | yes | yes |
| 4 bit per pixel | 4bpp | no | yes | yes |
| 8 bit per pixel | 8bpp | no | yes | yes |
| Compressed, RLE4 | 4bpp | yes | yes | yes |
| Compressed, RLE8 | 8bpp | yes | yes | yes |
| High color 555 | 15bpp | no | no | no |
| High color 555, red and blue swapped | 15bpp | no | no | no |
| High color 565 | 16bpp | no | no | no |
| High color 565, red and blue swapped | 16bpp | no | no | no |
| High color 565, compressed | 16bpp | yes | no | no |
| High color 565, red and blue swapped, compressed | 16bpp | yes | no | no |
| True color 888 | 24bpp | no | no | no |
| True color 8888 with alpha blending | 32bpp | no | yes | no |
Palette information
A bitmap palette is an array of 24 bit RGB color entries. Bitmaps with a color depth from 1 - 8 bpp can be saved with (device independent bitmap, DIB) or without palette information (device dependent bitmap DDB).
Transparency
A palette based bitmap can be converted to a transparent bitmap. Transparency means each pixel with index 0 will not produce any output. The command Image/Transparency can be used to select the color which should be used for transparency.
Alpha blending
Alpha blending is a method of combining an image with the background to create the effect of semi transparency. The alpha value of a pixel determines its transparency. The color of a pixel after drawing the bitmap is a blend of the former color and the color value in the bitmap. In emWin, logical colors are handled as 32 bit values. The lower 24 bits are used for the color information and the upper 8 bits are used to manage the alpha value. An alpha value of 0 means the image is opaque and a value of 0xFF means completely transparent. Whereas BMP and GIF files do not support alpha blending PNG files support alpha blending. So the easiest way to create bitmap files with alpha blending is to load a PNG file. When working with BMP and/or GIF files the bitmap converter initially has no information about the alpha values. The most recommended way for creating bitmaps with alpha mask is loading a PNG file.
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 fullcolor 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 fullcolor mode is to be shown on a display which supports only four grayscales. It would be a waste of memory to keep the image in the original format, since it would only appear as four grayscales 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. | ![]() |
Generating C stream files
A C stream file consists of the same information as a C file. Contrary to a C file a data stream can be located anywhere and does not need to be compiled or linked with the project. All supported output formats described for C files are also available for C stream files. emWin supports creating bitmaps from data streams and drawing data streams directly.
Compressed bitmaps
The bitmap converter and emWin 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 (see the example at the end of the chapter). The ratio of compression can therefore be calculated as 9,400/3,803 = 2.47.
Using a custom palette
Converting bitmaps to a custom palette and saving them without palette information can save memory and can increase the performance of bitmap drawing operations.
More efficient memory utilisation
Per default each bitmap contains its own palette. Even the smallest bitmaps can contain a large palette with up to 256 colors. In many cases only a small fraction of the palette is used by the bitmap. If using many of these bitmaps the amount of memory used by the palettes can grow rapidly. So it can save much ROM if converting the bitmaps used by emWin to the available hardware palette and saving them as (D)evice (D)ependent (B)itmaps without palette information.
Better bitmap drawing performance
Before emWin draws a bitmap, it needs to convert each device independent bitmap palette to the available hardware palette. This is required because the pixel indices of the bitmap file are indices into the device independent bitmap palette and not to the available hardware palette. Converting the bitmap to a DDB means that color conversion at run time is not required and speeds up the drawing.
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.
Valid command line options
The following table lists all permitted bitmap converter commands. It can also be viewed at any time by entering BmpCvt -? at the command prompt.
| Command | Explanation |
|---|---|
| -convertintobw | Convert to BW |
| -convertintogray4 | Convert to Gray4 |
| -convertintogray16 | Convert to Gray16 |
| -convertintogray64 | Convert to Gray64 |
| -convertintogray256 | Convert to Gray256 |
| -convertinto111 | Convert to 111. |
| -convertinto222 | Convert to 222. |
| -convertinto233 | Convert to 233 |
| -convertinto323 | Convert to 323 |
| -convertinto332 | Convert to 332. |
| -convertinto8666 | Convert to 8666 |
| -convertintorgb | Convert to RGB |
| -convertintobestpalette | Convert to best palette |
| -convertintocustompalette<filename> | Convert to a custom palette |
| <filename> | User-specified filename of desired custom palette |
| -exit | Terminate PC program automatically |
| -fliph | Flip image horizontally |
| -flipv | Flip image vertically |
| -help | Display this box |
| -invertindices | Invert indices |
| -rotate90cw | Rotate image by 90 degrees clockwise |
| -rotate90cc | Rotate image by 90 degrees counterclockwise |
| -rotate180 | Rotate image by 180 degrees |
| -saveas<filename>,<type>[,<fmt>[,<noplt>]] | Save file as filename |
| <filename> | User-specified file name including the file extension. |
| <type> | Must be an integer from 1 to 6 as follows: 1: C with palette (.c file) 2: Windows Bitmap file (.bmp file) 3: C stream (.dta file) 4: GIF format (.gif file) |
| <fmt> | Specifies the bitmap format (only if type == 1): 1: 1 bit per pixel 2: 2 bits per pixel 4: 4 bits per pixel 5: 8 bits per pixel 6: RLE4 compression 7: RLE8 compression 8: High color 565 9: High color 565, red and blue swapped 10: High color 555 11: High color 555, red and blue swapped 12: RLE16 compression 13: RLE16 compression, red and blue swapped 17: True color 24bpp If this parameter is not given, the bitmap converter uses the following default formats in dependence of the number of colors of the bitmap: Number of colors <= 2: 1 bit per pixel Number of colors <= 4: 2 bits per pixel Number of colors <= 16: 4 bits per pixel Number of colors <= 256: 8 bits per pixel RGB: High color 565 |
| <noplt> | Saves the bitmap with or without palette (only if type == 1) 0: Save bitmap with palette (default) 1: Save bitmap without palette |
| -transparency<RGB-Color> | Sets the transparent color |
| <RGB-Color> | RGB color which should be used as transparent color |
| -? | Display this box |
Example of a converted bitmap
A typical example for the use of the bitmap converter would be the conversion of your company logo into a C bitmap. Take another look at the example bitmap pictured below:

The bitmap is loaded into the bitmap converter, converted to Best palette, and saved as "C with palette". The resulting C source code is displayed below (some data is not shown to conserve space).
Resulting C code (generated by bitmap converter):
/*********************************************************************
* SEGGER MICROCONTROLLER SYSTEME GmbH *
* Solutions for real time microcontroller applications *
* www.segger.com *
**********************************************************************
* *
C-file generated by
* *
Bitmap converter for emWin V3.76.
* Compiled Feb 10 2004, 09:26:47
* (C) 1998 - 2004 Segger Microcontroller Systeme GmbH
* **********************************************************************
* *
Source file: test
* Dimensions: 200 * 94
* NumColors: 15
* **********************************************************************
*/
#include "stdlib.h"
#include "GUI.h"
#ifndef GUI_CONST_STORAGE
#define GUI_CONST_STORAGE const
#endif
/* Palette
The following are the entries of the palette table.
Every entry is a 32-bit value (of which 24 bits are actually used)
the lower 8 bits represent the Red component,
the middle 8 bits represent the Green component,
the highest 8 bits (of the 24 bits used) represent the Blue component
as follows: 0xBBGGRR
*/
static GUI_CONST_STORAGE GUI_COLOR ColorsLogo[] = {
0xFFFFFF,0xFF0000,0x000000,0x0F0F0F
,0x1C1F23,0xC3C3C3,0x020202,0xFBEFEF
,0xFF3B3B,0x5A5B5E,0x909294,0xFFC1C1
,0xD0D1D1,0xFF6868,0xFF9393
};
static GUI_CONST_STORAGE GUI_LOGPALETTE PalLogo = {
15,/* number of entries */
0, /* No transparency */
&ColorsLogo[0]
};
static GUI_CONST_STORAGE unsigned char acLogo[] = {
0x00, 0x00, 0xC9, 0x43, ... , 0x00,/* Not all data is shown */
0x00, 0x0A, 0x32, 0x22, ... , 0x00,/* in this example */
0x00, 0x92, 0x22, 0x22, ... , 0x00,
0x0A, 0x22, 0x22, 0x22, ... , 0xA0,
0xC6, 0x22, 0x23, 0x95, ... , 0x6C,
.
.
.
0xC6, 0x22, 0x23, 0xA5, ... , 0x6C,
0x0A, 0x22, 0x22, 0x22, ... , 0x90,
0x07, 0x92, 0x22, 0x22, ... , 0x70,
0x00, 0x7A, 0x32, 0x22, ... , 0x00,
0x00, 0x00, 0xCA, 0x44, ... , 0x00
};
GUI_CONST_STORAGE GUI_BITMAP bmLogo = {
200, /* XSize */
94, /* YSize */
100, /* BytesPerLine */
4, /* BitsPerPixel */
acLogo, /* Pointer to picture data (indices) */
&PalLogo /* Pointer to palette */
};
/* *** End of file *** */
Bitmap Converter
Head office Germany
US office 






