10 KiB
Palette
In computer graphics palette is a set of possible colors that can be displayed, the term usually refers to a selected smaller subset of all colors that can in theory be displayed (large sets of colors tend to be called color spaces rather than palettes). Nowadays mainstream computers are powerful enough to work with over 6 million 24bit RBG colors (so called True Color) practically without limitations so the use of palettes is no longer such a huge thing, but with resource-limited machines, such as embedded devices and older computers, the use of palettes is sometimes necessary or at least offers many advantages (e.g. saving a lot of memory). Nevertheless palettes find uses even in "modern" graphics, e.g. in the design of image formats that save space. Palettes are also greatly important in pixel art as an artistic choice.
Palettes usually contain a few to few thousand colors and the number is normally a power of 2, i.e. we see palettes with number of colors being 8, 16, 256, 2048, etc. -- this has advantages such as efficiency (fully utilizing color indices, keeping memory aligned etc.). Palettes can be general purpose or specialized (for example some image formats such as GIF create a special palette for every individual image so as to best preserve its colors). Palettes can also be explicitly stored (the palette colors are stored somewhere in the memory) or implicit (the color can somehow be derived from its index, e.g. the 565 palette).
Palettes are related to screen modes -- systems that work with palettes will usually offer to set a specific screen mode that defines parameters such as screen resolution and number of colors we can use, i.e. the number of colors of our palette (we can normally set the colors in a palette). Modes that make use of palettes are called indexed because each pixel in memory is stored as an index to the palette (for example if we have a palette {red, yellow, white}, a pixel value 0 will stand for red, 1 for yellow and 2 for white) -- the palette serves as a color look-up table (CLUT). Non-indexed modes on the other hand store the color directly (i.e. there will typically be a direct RGB value stored for each pixel). We can see that an indexed mode (i.e. choosing to use a palette) will save a lot of memory for the framebuffer (VRAM) thanks to reducing the number of bits per pixel: e.g. when using an 8 bit palette, storing each pixel (index) will take up 1 byte (8 bits, 256 colors) while in a non-indexed 24 bit RGB mode (over 6 million colors) each pixel will take 3 bytes (24 bits), i.e. three times as much. The same goes for using bigger palettes: e.g. using a 16 bit palette (65536 colors) will take four times as much memory for storing pixels than a 4 bit palette (16 colors). Note that even in indexed modes we may sometimes be able to draw pixels of arbitrary color with so called direct writes to the display, i.e. without the color being stored in framebuffer. With palettes we may see the use of dithering to achieve the illusion of mixing colors.
Using palettes has also more advantages, for example we can cycle the palette colors or quickly switch it for another palette and so e.g. increase contrast or apply some color effect (this trick was used e.g. in Doom). Palettes can be constructed in clever ways (for example in Anarch) so that it is e.g. easy to make a color brighter or darker by simply incrementing or decrementing its index (while increasing brightness of a three-component RGB value is complex and slow) -- as we generally process big numbers of pixels this can lead to tremendous speed ups. Having fewer colors also makes them easier to compare and so easily implement things such as pixel art upscaling (huge number of colors generally forces us to compare pixels with some amount of bias which is slower).
Can palettes be copyrighted? We hope not, that would indeed be pretty fucked up, however trademarks already allowed corporations to own even single colors (Milka chocolate's lilac color), and some websites for sharing palettes claim that a picture of a palette can be copyrighted as some kind of a "digital painting", even though they acknowledge a set of colors as such can't be copyrighted. So for maximum safety try to create your own palette (and share it under CC0 to spare others the same pain) as a first option, as a second option use a palette that's explicitly shared under free terms (CC0 is probably best), and if you absolutely have to reuse someone else's "proprietary" palette, at least reorder its colors and possibly slightly change the RGB values to make it a bit distinct.
Examples
Example of a basic 8 color palette may be (the color notation is in hexadecimal #rrggbb
format):
#000000 #808080 #ffffff #ff0000 #00ff00 #0000ff #ffff00 #00ffff
black gray white red green blue yellow cyan
The following is a general purpose 256 color palette made by drummyfish and used in Anarch. It is based on HSV model: it divides colors into 4 saturations, 10 or 11 hues and 8 levels of value ("brightness") which can easily be changed by incrementing/decrementing the color index (which in Anarch was exploited for ligtening up and darkening textures depending on distance).
#000000 #242424 #494949 #6d6d6d #929292 #b6b6b6 #dbdbdb #ffffff
#201515 #402a2a #604040 #805555 #a06a6a #c08080 #e09595 #ffaaaa
#201b15 #40372a #605240 #806e55 #a08a6a #c0a580 #e0c195 #ffdcaa
#1d2015 #3b402a #596040 #778055 #95a06a #b3c080 #d1e095 #edffaa
#172015 #2f402a #466040 #5e8055 #75a06a #8dc080 #a5e095 #bcffaa
#152019 #2a4033 #40604c #558066 #6aa080 #80c099 #95e0b3 #aaffcc
#15201f #2a403f #40605f #55807f #6aa09f #80c0bf #95e0df #aafffe
#151920 #2a3340 #404c60 #556680 #6a80a0 #8099c0 #95b3e0 #aaccff
#171520 #2e2a40 #464060 #5d5580 #746aa0 #8c80c0 #a395e0 #b9aaff
#1d1520 #3b2a40 #594060 #775580 #956aa0 #b380c0 #d195e0 #eeaaff
#20151b #402a37 #604053 #80556f #a06a8b #c080a7 #e095c3 #ffaadd
#200a0a #401515 #602020 #802a2a #a03535 #c04040 #e04a4a #ff5555
#20170a #402e15 #604520 #805c2a #a07435 #c08b40 #e0a24a #ffb955
#1b200a #374015 #536020 #6e802a #8aa035 #a6c040 #c2e04a #dcff55
#f200a0 #1e4015 #2d6020 #3c802a #4ba035 #5bc040 #6ae04a #79ff55
#a20130 #154026 #206039 #2a804c #35a060 #40c073 #4ae086 #55ff99
#a201f0 #15403f #20605f #2a807e #35a09e #40c0be #4ae0de #55fffd
#a13200 #152640 #203960 #2a4c80 #3560a0 #4073c0 #4a86e0 #5599ff
#e0a200 #1d1540 #2c2060 #3a2a80 #4935a0 #5840c0 #664ae0 #7455ff
#1b0a20 #371540 #532060 #6e2a80 #8a35a0 #a640c0 #c24ae0 #dd55ff
#200a17 #40152f #602047 #802a5e #a03576 #c0408e #e04aa6 #ff55bc
#200000 #400000 #600000 #800000 #a00000 #c00000 #e00000 #ff0000
#201100 #402200 #603300 #804500 #a05600 #c06700 #e07900 #ff8a00
#1d2000 #3a4000 #586000 #758000 #92a000 #b0c000 #cde000 #eaff00
#c20000 #184000 #246000 #308000 #3ca000 #48c000 #54e000 #60ff00
#200500 #400a00 #600f00 #801500 #a01a00 #c01f00 #e02400 #ff2900
#201600 #402d00 #604300 #805a00 #a07000 #c08700 #e09e00 #ffb400
#172000 #2e4000 #466000 #5d8000 #74a000 #8cc000 #a3e000 #baff00
#620000 #c40000 #126000 #188000 #1ea000 #24c000 #2ae000 #30ff00
#b00200 #160040 #210060 #2d0080 #3800a0 #4300c0 #4f00e0 #5900ff
#1c0020 #390040 #550060 #720080 #8f00a0 #ab00c0 #c800e0 #e400ff
#200012 #400024 #600036 #800048 #a0005a #c0006c #e0007e #ff008f
Another generally usable 256 color palette is the 332 palette which can be used as an implicit palette -- it doesn't have to be stored in memory because in the 332 format the color index determines the color in the following way: the upper 3 bits encode the amount of red, the following 3 bits encode the amount of green and the remaining 2 bits encode the amount of blue (blue gets fewest bits because human eye is least sensitive to it). The RGB values of this palette are following.
#000000 #000055 #0000aa #0000ff #002400 #002455 #0024aa #0024ff
#004800 #004855 #0048aa #0048ff #006d00 #006d55 #006daa #006dff
#009100 #009155 #0091aa #0091ff #00b600 #00b655 #00b6aa #00b6ff
#00da00 #00da55 #00daaa #00daff #00ff00 #00ff55 #00ffaa #00ffff
#240000 #240055 #2400aa #2400ff #242400 #242455 #2424aa #2424ff
#244800 #244855 #2448aa #2448ff #246d00 #246d55 #246daa #246dff
#249100 #249155 #2491aa #2491ff #24b600 #24b655 #24b6aa #24b6ff
#24da00 #24da55 #24daaa #24daff #24ff00 #24ff55 #24ffaa #24ffff
#480000 #480055 #4800aa #4800ff #482400 #482455 #4824aa #4824ff
#484800 #484855 #4848aa #4848ff #486d00 #486d55 #486daa #486dff
#489100 #489155 #4891aa #4891ff #48b600 #48b655 #48b6aa #48b6ff
#48da00 #48da55 #48daaa #48daff #48ff00 #48ff55 #48ffaa #48ffff
#6d0000 #6d0055 #6d00aa #6d00ff #6d2400 #6d2455 #6d24aa #6d24ff
#6d4800 #6d4855 #6d48aa #6d48ff #6d6d00 #6d6d55 #6d6daa #6d6dff
#6d9100 #6d9155 #6d91aa #6d91ff #6db600 #6db655 #6db6aa #6db6ff
#6dda00 #6dda55 #6ddaaa #6ddaff #6dff00 #6dff55 #6dffaa #6dffff
#910000 #910055 #9100aa #9100ff #912400 #912455 #9124aa #9124ff
#914800 #914855 #9148aa #9148ff #916d00 #916d55 #916daa #916dff
#919100 #919155 #9191aa #9191ff #91b600 #91b655 #91b6aa #91b6ff
#91da00 #91da55 #91daaa #91daff #91ff00 #91ff55 #91ffaa #91ffff
#b60000 #b60055 #b600aa #b600ff #b62400 #b62455 #b624aa #b624ff
#b64800 #b64855 #b648aa #b648ff #b66d00 #b66d55 #b66daa #b66dff
#b69100 #b69155 #b691aa #b691ff #b6b600 #b6b655 #b6b6aa #b6b6ff
#b6da00 #b6da55 #b6daaa #b6daff #b6ff00 #b6ff55 #b6ffaa #b6ffff
#da0000 #da0055 #da00aa #da00ff #da2400 #da2455 #da24aa #da24ff
#da4800 #da4855 #da48aa #da48ff #da6d00 #da6d55 #da6daa #da6dff
#da9100 #da9155 #da91aa #da91ff #dab600 #dab655 #dab6aa #dab6ff
#dada00 #dada55 #dadaaa #dadaff #daff00 #daff55 #daffaa #daffff
#ff0000 #ff0055 #ff00aa #ff00ff #ff2400 #ff2455 #ff24aa #ff24ff
#ff4800 #ff4855 #ff48aa #ff48ff #ff6d00 #ff6d55 #ff6daa #ff6dff
#ff9100 #ff9155 #ff91aa #ff91ff #ffb600 #ffb655 #ffb6aa #ffb6ff
#ffda00 #ffda55 #ffdaaa #ffdaff #ffff00 #ffff55 #ffffaa #ffffff
A similar one is the 565 palette that uses 2 bytes to encode RGB with 5 bits for red, 6 for green and 5 for blue (most bits are allocated to green to which human eye is most sensitive).