Masking is done by a bitwise AND operation ( & To get ONLY the upper 5 bits, we need to mask them. Why the upper bits? Because they have the highest significance/impact on the color. In a first step, we have to shift in the upper 5 bits of red
#COLOR MAKER 255 255 255 CODE#
The code for converting a 4 byte type such as intĬan be found after this section. Let’s assume we have 3 individual input bytes, one for each color. Note that since we have less bits (information) available, we can represent less colors. Providing 5 bits for 2 colors and 6 bits for another seems asymmetric but storing and transmitting something which cannot nicely be packed in bytes would be complicated. It provides 5 bits for Red and Blue and 6 bits for Green. RGB565 requires only 16 (5+6+5) bits/2 bytes and is commonly used with embedded screens. Moreover, storing and/or transmitting 3 bytes per pixel is consuming quite some memory and creates latency. ( read more about bit numbering)Įspecially (cheap) screens used with embedded devices do not provide 24 bit color-depth. This is a common convention, though there are also others (LSB first). If the bits on the left have the highest significance, then its called MSB (most signficant bit) first. The bits on the left have a higher significance and hence have a stronger impact on the color. In the first row I indicate the bit number and in the second row I indicate which color this bit represents and how "significant" it is. In the table below you can see how RGB888 is stored in memory. I highlighted the color each digit represents. Usually the color code is represented in hexadecimal digits (because 1 byte results in exactly 2 digits).Īn example with common notations for the color yellow (R=255,G=255,B=0) can be seen below. It defines that we have 8 bits/1 byte of information for each primary color (Red, Green, Blue) which, if added, result in the desired color.
#COLOR MAKER 255 255 255 HOW TO#
There are different ways on how to represent a color but virtually all displays use RGB, where a color is represented by its Red Green and Blue components (you might have heard something about it in school, a long long time ago, if not: primary colors).Ī common representation of color information is the RGB888 (24 bit/3 byte) format. The more bits (information), the more colors we can display. The color depth defines how many bits are used to represent a color. If we want to have colored pictures, we also need information about the color. This however brings the limitation that we can only indicate if a pixel is ON or OFF (e.g. For monochrome images this is simply a single bit of information, where a prominent example are images on LCD displays such as those in old GameBoys. If we want to store or transmit an image, we have to provide information about each individual pixel. Development platform: Excel 2016 64 bit.Digital images consist out of pixels (big news huh?).xlRange.Characters(1, 2).Font.Color = 6 (equivalent to: RGB(6,0,0)).= RGB(150,0,0) (equivalent to ColorIndex 3).Where value can be created by the RGB function returned as a long whole number. Fig 5: binary AND - last 8 digits on the right.Only the last 8 digits on the right are relevant. Line 95: 16737843 And 255 returns 51, 51 \ 1 returns 51, remainder 0įurther details of the binary And are provided in figure 5.' omitted (&HFF00), the assigned value is -256 ' leading &H is the prefix radix (base) for hexadecimal R = (ColDec And &HFF) \ 256 ^ 0 ' &HFF hexadecimal = 255 decimal Includes test routineįunction xlfDec2RGB(ByVal ColDec As Long) As String The ColorConstants Auto List drop down is shown in figure 4.įig 4: VBA ColorConstants - VBA Auto List drop down with 8 itemsĬode 3 prints a list of the ColorConstants numerical values to the immediate window (figure 5).Ĭode 5: Function xlfDec2RGB converts color decimal to RGB comma separated values. The 8 colours listed in section 1.1 have name equivalents listed as members of the VBA ColorConstants class in the decimal colour system. Ten of the ColorIndex colours are duplicate pairs: Offset(i - 1, j - 1).Font.ColorIndex = 1 Offset(i - 1, j - 1).Font.ColorIndex = 2 Code 2: Sub ColIndx2WSarraS procedure prints ColorIndex to WS array (7 rows by 8 columns)Ĭonst TLC As String = "B2" ' top left cell