{"id":69,"date":"2014-05-04T18:50:47","date_gmt":"2014-05-04T22:50:47","guid":{"rendered":"https:\/\/dorcgames.com\/blog\/?p=69"},"modified":"2014-05-05T13:17:24","modified_gmt":"2014-05-05T17:17:24","slug":"developing-a-palate-for-palettes","status":"publish","type":"post","link":"https:\/\/dorcgames.com\/blog\/?p=69","title":{"rendered":"Developing a Palate for Palettes"},"content":{"rendered":"<p><a href=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/04\/SuperPaletteBros.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-84\" src=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/04\/SuperPaletteBros.png\" alt=\"Super Palette Bros\" width=\"880\" height=\"881\" srcset=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/04\/SuperPaletteBros.png 880w, https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/04\/SuperPaletteBros-150x150.png 150w, https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/04\/SuperPaletteBros-300x300.png 300w, https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/04\/SuperPaletteBros-800x800.png 800w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>What do kitschy paint-by-numbers kits, Japanese kimono design, animated beer signs, and mood rings have to do with old school video games?\u00a0 The answer, if you&#8217;ve been paying attention, is palettes.\u00a0 In this post, we&#8217;ll look at how and why palettes exist, what affordances they offer, and insight into this lost art.<\/p>\n<p><!--more--><\/p>\n<p>Though rarely used in today&#8217;s development, palettes&#8211;color look up tables built into the video display hardware&#8211;played an important role in early 8- and 16-bit hardware, and continued to be used well into the era of 3D-acceleration.<\/p>\n<p>As an analogy, think of a paint-by-numbers kit:<\/p>\n<div id=\"attachment_87\" style=\"width: 454px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/CraftMasterAd.img_assist_custom-444x592.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-87\" class=\"size-full wp-image-87\" src=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/CraftMasterAd.img_assist_custom-444x592.jpg\" alt=\"I Painted it Myself!  Courtesy of the Paint By Numbers Museum.\" width=\"444\" height=\"591\" srcset=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/CraftMasterAd.img_assist_custom-444x592.jpg 444w, https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/CraftMasterAd.img_assist_custom-444x592-225x300.jpg 225w\" sizes=\"auto, (max-width: 444px) 100vw, 444px\" \/><\/a><p id=\"caption-attachment-87\" class=\"wp-caption-text\">&#8220;I Painted it Myself!&#8221; Courtesy of the <a href=\"http:\/\/www.paintbynumbermuseum.com\/\" target=\"_blank\">Paint By Numbers Museum<\/a>.<\/p><\/div>\n<p>The image is made up of regions, identified with numbers, each of which correspond to a particular color.\u00a0 This makes it very easy to reproduce the image, and even easier to store it.\u00a0 If we move this into the realm of the digital, we need only store the color&#8217;s\u00a0<em>index<\/em> for each pixel rather than the individual red, green, and blue components that make up the image.\u00a0 The video hardware does this look-up as it draws the screen, translating the index into signals to the electron gun inside the TV.<\/p>\n<p>When people use the term &#8220;palette swap,&#8221; what they&#8217;re talking about is specifying a new set of colors for the indexes.\u00a0 In the image at the top of this post, Mario and Lugi use the exact same paint-by-numbers values in <em>Super Mario Bros.<\/em>, but simply change how those numbers are interpreted.<\/p>\n<div id=\"attachment_92\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/DictionaryOfColorCombinations.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-92\" class=\"size-full wp-image-92\" src=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/DictionaryOfColorCombinations.jpg\" alt=\"TODO\" width=\"500\" height=\"353\" srcset=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/DictionaryOfColorCombinations.jpg 500w, https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/DictionaryOfColorCombinations-300x211.jpg 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><p id=\"caption-attachment-92\" class=\"wp-caption-text\">The concept of pre-selected color packages wasn&#8217;t anything new, of course.\u00a0 One of my favorites is <a href=\"http:\/\/www.amazon.com\/A-Dictionary-Of-Color-Combinations\/dp\/4861522471\/ref=sr_1_1?ie=UTF8&amp;qid=1399242101&amp;sr=8-1&amp;keywords=dictionary+of+color+combinations\" target=\"_blank\">Sanzo Wada&#8217;s 1933 <em>Haishoku Soukan<\/em><\/a>, a 6-volume set which laid out palette selections for kimonos and other Japanese fashion.<\/p><\/div>\n<p>The classic graphics text by Foley &amp; Van Dam cites palettes as a commonly used technique in display processor technology:\u00a0 Barring the gory details, palettes reduced the memory footprint of images significantly and also eased memory bandwidth issues.\u00a0 For cheap hardware in the 80s, maximizing the CPU was paramount, which meant offloading work into auxiliary chips and keeping the memory bus freed up.<\/p>\n<p>As an example, the IBM PC VGA standard could display 18-bit colors (6 bits each Red, Green, Blue).\u00a0 A 100&#215;100 pixel image at 18-bits turns out to be 22,500 bytes.\u00a0 However, if we use an 8-bit palette (256 entries, each entry mapping to an 18-bit color as before), our 100&#215;100 image turns out to only need 10,000 bytes&#8230;a dramatic savings!<\/p>\n<p>So while our overall number of <em>unique<\/em> colors decreases, we can employ some of the same tricks that newspapers learned long ago:\u00a0 by putting colors adjacent to each other, we can trick the eye into seeing more than is actually there, or even to seemingly generate new colors altogether.\u00a0 Known as &#8220;dithering,&#8221; this artform can produce some staggeringly deep visuals using only a handful of unique colors.<\/p>\n<div id=\"attachment_88\" style=\"width: 251px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/CastlevaniaScallopPattern.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-88\" class=\"size-full wp-image-88\" src=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/CastlevaniaScallopPattern.png\" alt=\"Dithering used to great effect in Castlevania:  Circle of the Moon.\" width=\"241\" height=\"112\" \/><\/a><p id=\"caption-attachment-88\" class=\"wp-caption-text\">Dithering used to great effect in <em>Castlevania: Circle of the Moon<\/em>.\u00a0 This image uses only 5 colors!\u00a0 For more dithering magic, check out <a title=\"Dan Fessler's amazing Photoshop plugin.\" href=\"http:\/\/danfessler.com\/blog\/hd-index-painting-in-photoshop\" target=\"_blank\">Dan Fessler&#8217;s amazing Photoshop plugin<\/a>.<\/p><\/div>\n<p>Some machines had hard-coded color values:\u00a0 On the ZX Spectrum, palette entry 0 was always black, palette entry 1 was always dark blue, etc.\u00a0 <em>Pac-Man<\/em> has its color palette stored in a special PROM.\u00a0 Other devices allowed the programer to specify the mapping of index to color value and dynamically change them at runtime.\u00a0 This led to cool special effects such as fading the screen to black (interpolating all colors in the palette towards black), flashing a character white when struck (by setting all of their colors to white for several frames before restoring them).<\/p>\n<p>One could even achieve animation through palette changes.\u00a0 A mood ring, for example, changes the surface of the ring as the bearer&#8217;s mood&#8211;ahem&#8211;changes.\u00a0 By isolating color values in the palette in a video game, you can make a sword pulse with magical energy by making <em>just<\/em> that color index change over time.\u00a0 If you ever saw a character steadily change to red as he was injured in a game, you saw this technique being used.<\/p>\n<p>Motion can also be conveyed through palette changes.\u00a0 The old <a href=\"https:\/\/www.youtube.com\/watch?v=xtTNlgw-X-g\" target=\"_blank\">Hamm&#8217;s beer signs<\/a> (I knew you were waiting for that one) rotated colors to give the illusion of flowing water, or day turning into night and back to day again.\u00a0 By dedicating a swath of colors in the palette, we can use color cycling to emulate motion.<\/p>\n<div id=\"attachment_90\" style=\"width: 522px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/LivingWorlds.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-90\" class=\"wp-image-90 size-full\" src=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/LivingWorlds.jpg\" alt=\"LivingWorlds\" width=\"512\" height=\"384\" srcset=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/LivingWorlds.jpg 512w, https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/05\/LivingWorlds-300x225.jpg 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><p id=\"caption-attachment-90\" class=\"wp-caption-text\">Joe Huckaby and Mark J. Ferrari use palettes to fantastic effect for animation and time of day.\u00a0 Be sure to visit their <a href=\"http:\/\/www.effectgames.com\/demos\/worlds\/\" target=\"_blank\">Living Worlds<\/a> site to play with this interactively!<\/p><\/div>\n<p>More ambitious coders pulled off strange tricks to display more colors than would normally be possible:\u00a0 waiting for a specific scanline and then re-loading the palette with a new set of colors.<\/p>\n<div id=\"attachment_79\" style=\"width: 266px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/04\/image.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-79\" class=\"size-full wp-image-79\" src=\"https:\/\/dorcgames.com\/blog\/wp-content\/uploads\/2014\/04\/image.jpg\" alt=\"Charles MacDonald's 64 Color Palette Test Program draws the top half of the screen using 32 of the available colors, and then reloads the palette registers midway down the screen to draw the other 32.\" width=\"256\" height=\"192\" \/><\/a><p id=\"caption-attachment-79\" class=\"wp-caption-text\">Charles MacDonald&#8217;s <a href=\"http:\/\/www.smspower.org\/Homebrew\/64ColorPaletteTestProgram-SMS?sid=c80fb92dffdc222ae8f048c47999673a\">64 Color Palette Test Program<\/a> draws the top half of the screen using 32 of the available colors, and then reloads the palette registers midway down the screen to draw the other 32.<\/p><\/div>\n<p>The mappings were also limited to what the device could actually display:\u00a0 the NES was only capable of outputting 64 colors drawn from the NTSC standard, and of those, only 54 were unique.\u00a0 The Genesis could output 512 colors from the RGB spectrum (3 bits each Red, Green, and Blue).\u00a0 Some 3D accelerator cards had oddball palette support, such as 5-bits red, 6-bits green, and 5-bits blue.<\/p>\n<p>As the hardware evolved, we started to see more and more specialization:\u00a0 Moving objects (&#8220;sprites&#8221;) used their own palettes (or section of a larger palette) while the grid-like background (&#8220;BG&#8221;) used another one.\u00a0 On the NES, the sprite and background palettes are totally distinct:\u00a0 sprites use one of 4 4-color palettes, and each BG tile uses one of 4 totally different 4-color palettes.\u00a0 The Master System allowed BG tiles to use either of its two 16-color palettes, but sprites could use only one of them.\u00a0 To make matters weirder, palette entry #0 is often used as a hardware &#8220;clear&#8221; color <em>for sprites only<\/em>, letting the background show through.<\/p>\n<p>In terms of how these palettes were used in practice, here are the most common approaches:<\/p>\n<ul>\n<li>Specify the palette up front and force all artwork to conform to this.\u00a0 I&#8217;ve heard horror stories from artists about the impact of changing a single color on <em>Ultima VII<\/em>&#8216;s fixed 256-color palette.<\/li>\n<li>Dedicate swaths of the palette to specific use and don&#8217;t allow overlap.\u00a0 For example, <em>Wonder Boy in Monster Land<\/em> sets aside several palette slots for the player&#8217;s boot color, shield color, and armor color.\u00a0 If the player had the same color boots as their shield, the color was duplicated.<\/li>\n<li>Create entire palettes for each situation and re-direct images to those palettes.\u00a0 This wasn&#8217;t really feasible until the 16-bit era, when machines could manage dozens of palettes at once.<\/li>\n<li>Dynamically swap in and out palette entries, depending on where the player is, to maximize color usage.\u00a0 <em>Super Mario Bros. 3<\/em> does this frequently, shifting the palettes up at key points in levels or while tallying up the end-round bonuses.<\/li>\n<\/ul>\n<p>Clearly, that last approach is the holy grail of sorts.\u00a0 Getting there, however, requires a lot of knowledge about where the user is and how controlled the experience can be.\u00a0 In a future post, I&#8217;ll go into the approach I&#8217;m taking for HUSSAR and get a little bit into the nuts-and-bolts of how I think we can achieve that holy grail.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; What do kitschy paint-by-numbers kits, Japanese kimono design, animated beer signs, and mood rings have to do with old school video games?\u00a0 The answer, if you&#8217;ve been paying attention, is palettes.\u00a0 In this post, we&#8217;ll look at how and &hellip; <a href=\"https:\/\/dorcgames.com\/blog\/?p=69\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7,8],"tags":[10],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-hussar","category-palettes","tag-palettes"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69"}],"version-history":[{"count":10,"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dorcgames.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}