Why are all my colors wrong in SWIM?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why are all my colors wrong in SWIM?

1,284 Views
lpcware-support
Senior Contributor I

The SWM graphics library supports varying color depths but can only be staically compiled for one color depth that must be defined before SWIM is compiled. SWIM supoprts any frame buffer that has 8-bit, 16-bit, or 32-bit addressable pixel color data. Packed pixel formats such as 2 pixels/byte (16 colors/pixel) are not supported.

Before compiling SWIM, several defines need to be setup in the lpc_colors.h file. These defines specify the size of the basic pixel in bits/bytes, maximum number of colors, red/green/blue color masks, and pre-defined color defines for basic colors. Pre-defined values for color depths of 256 colors (8-bits stored in a byte), 4096 colors (12-bits stored in a half-word), 32768 colors (15-bits stored in a half-word), and 65536 colors (16-bits stored in a half-word) are already defined. You can pick one of these pre-defined color configurations by setting the COLORS_DEF definition in the lpc_colors.h file to the number of color bits - either 8, 12, 15, or 16. Optionally, you can setup the define in your compiler arguments and avoid changing the lpc_colors.h file.

#ifndef COLORS_DEF
#define COLORS_DEF 16 /* 16-bit 565 color mode */
//#define COLORS_DEF 15 /* 15-bit 555 color mode */
//#define COLORS_DEF 12 /* 12-bit 444 color mode */
//#define COLORS_DEF 8 /* 8-bit color mode */
#endif

If you are using one of the pre-defined color depths, the definitions for BLACK, WHITE, RED, GREEN will be selected for you. This also applies to the color masks and number of colors.

/* Black color, 565 mode */
#define BLACK         0x0000
/* Light gray color, 565 mode */
#define LIGHTGRAY     0X7BEF
/* Dark gray color, 565 mode */
#define DARKGRAY      0x39E7
/* White color, 565 mode */
#define WHITE         0x7fff
...
...
/* Red color mask, 565 mode */
#define REDMASK       0xF800
/* Red shift value, 565 mode */
#define REDSHIFT      11
/* Green color mask, 565 mode */
#define GREENMASK     0x07E0
/* Green shift value, 565 mode */
#define GREENSHIFT    5
/* Blue color mask, 565 mode */
#define BLUEMASK      0x001F
/* Blue shift value, 565 mode */
#define BLUESHIFT     0
/* Number of colors in 565 mode */
#define NUM_COLORS    65536
/* Number of red colors in 565 mode */
#define RED_COLORS    0x20
/* Number of green colors in 565 mode */
#define GREEN_COLORS  0x40
/* Number of blue colors in 565 mode */
#define BLUE_COLORS   0x20


If you need to customize your colors or want to use a custom color palette, you will need to add your own values or change the existing values. For 32-bit colors stored as a single 32-bit word in memory in ARGB888 format, data is stored for a pixel as 8-bits of Alpha data in the high 8-bits of the word, red data in the next 8-bits, green data in the next 8-bits, and blue data in the lower 8-bits. For this to work, I might change my entries to appear as below. (Not all possible colors or choices are shown).

#define COLORS_DEF 24      /* 32-bit 888 color mode */
/* White color, 888 mode */
#define WHITE         0xFFFFFF
/* Red color, 888 mode */
#define RED           0xFF0000
/* Green color, 888 mode */
#define GREEN         0x00FF00
/* Blue color, 888 mode */
#define BLUE          0x0000FF
...
...
/* Red color mask, 888 mode */
#define REDMASK       0xFF0000
/* Red shift value, 888 mode */
#define REDSHIFT      16
/* Green color mask, 888 mode */
#define GREENMASK     0x00FF00
/* Green shift value, 888 mode */
#define GREENSHIFT    8
/* Blue color mask, 888 mode */
#define BLUEMASK      0x0000FF
/* Blue shift value, 888 mode */
#define BLUESHIFT     0
/* Number of colors in 888 mode */
#define NUM_COLORS    16777216
/* Number of red colors in 888 mode */
#define RED_COLORS    0x100
/* Number of green colors in 888 mode */
#define GREEN_COLORS  0x100
/* Number of blue colors in 888 mode */
#define BLUE_COLORS   0x100


The last thing that needs to be done is to define the basic color type used for storing pixel data. This type must match the size of the pixel data. For 32-bit pixel data, this would be a 32-bit word.

/* Color type is a 32-bit value */
typedef UNS_32 COLOR_T;

Labels (2)
Tags (1)
0 Kudos
Reply
0 Replies