Use backtick code blocks for syntax highlighting
This commit is contained in:
parent
8ed9dea394
commit
f658bfbb40
203 changed files with 26546 additions and 25801 deletions
44
55-03.md
44
55-03.md
|
|
@ -12,28 +12,30 @@ pages: 1038-1040
|
|||
|
||||
**LISTING 55.3 L55-3.C**
|
||||
|
||||
/* Converts a model color (a color in the RGB color cube, in the current
|
||||
color model) to a color index for mode X. Pure primary colors are
|
||||
special-cased, and everything else is handled by a 2-2-2 model. */
|
||||
int ModelColorToColorIndex(ModelColor * Color)
|
||||
{
|
||||
if (Color->Red == 0) {
|
||||
if (Color->Green == 0) {
|
||||
/* Pure blue */
|
||||
return(192+(Color->Blue >> 2));
|
||||
} else if (Color->Blue == 0) {
|
||||
/* Pure green */
|
||||
return(128+(Color->Green >> 2));
|
||||
}
|
||||
} else if ((Color->Green == 0) && (Color->Blue == 0)) {
|
||||
/* Pure red */
|
||||
return(64+(Color->Red >> 2));
|
||||
}
|
||||
/* Multi-color mix; look up the index with the two most significant bits
|
||||
of each color component */
|
||||
return(((Color->Red & 0xC0) >> 2) | ((Color->Green & 0xC0) >> 4) |
|
||||
((Color->Blue & 0xC0) >> 6));
|
||||
```c
|
||||
/* Converts a model color (a color in the RGB color cube, in the current
|
||||
color model) to a color index for mode X. Pure primary colors are
|
||||
special-cased, and everything else is handled by a 2-2-2 model. */
|
||||
int ModelColorToColorIndex(ModelColor * Color)
|
||||
{
|
||||
if (Color->Red == 0) {
|
||||
if (Color->Green == 0) {
|
||||
/* Pure blue */
|
||||
return(192+(Color->Blue >> 2));
|
||||
} else if (Color->Blue == 0) {
|
||||
/* Pure green */
|
||||
return(128+(Color->Green >> 2));
|
||||
}
|
||||
} else if ((Color->Green == 0) && (Color->Blue == 0)) {
|
||||
/* Pure red */
|
||||
return(64+(Color->Red >> 2));
|
||||
}
|
||||
/* Multi-color mix; look up the index with the two most significant bits
|
||||
of each color component */
|
||||
return(((Color->Red & 0xC0) >> 2) | ((Color->Green & 0xC0) >> 4) |
|
||||
((Color->Blue & 0xC0) >> 6));
|
||||
}
|
||||
```
|
||||
|
||||
In DEMO1, three-quarters of the palette is set up with 64 intensity
|
||||
levels of each of the three pure primary colors (red, green, and blue),
|
||||
|
|
|
|||
Loading…
Reference in a new issue