_______________________________________________________________________________________________ © 2006 Daniel Vik Color Images on MSX1 © 2006 Daniel Vik -
_______________________________________________________________________________________________ © 2006 Daniel Vik - Screen 2 Images Max 2 colors per 8x1 block Background color Foreground color A screen 2 image is made up of 8x1 pixel sized blocks, which each has a background and a forground color from the palette: The MSX1 palette consists of 15 unique colors:
_______________________________________________________________________________________________ © 2006 Daniel Vik - Interlacing += Switching between two different screen 2 images every frame (50 times/second) creates an illusion of more colors than available in each image alone. For example:
_______________________________________________________________________________________________ © 2006 Daniel Vik - Interlaced palette A screen 2 image can show 15 different colors. By interlacing two screen 2 images its possible to “mix” colors to create a palette with up to 105 unique colors:
_______________________________________________________________________________________________ © 2006 Daniel Vik - Interlaced blocks Since the interlaced image is constructed from two screen 2 images, the available colors in a 8x1 block are the combination of the foreground and background colors of the two images: COLOR 1: background of image 1 + background of image 2 COLOR 2: background of image 1 + foreground of image 2 COLOR 3: foreground of image 1 + background of image 2 COLOR 4: foreground of image 1 + foreground of image 2 So not only do we get more colors, we also can use four different colors instead of two in each 8x1 block.
_______________________________________________________________________________________________ © 2006 Daniel Vik - Interlaced blocks example Even FrameOdd FrameMix
_______________________________________________________________________________________________ © 2006 Daniel Vik - Encoding algorithm Objective:Find the two 8x1 screen 2 blocks that combined give the colors closest to the source image. Converting a 24-bit RGB bitmap into interlaced screen 2 format is done by first dividing the RGB image into 8x1 pixel sized blocks.
_______________________________________________________________________________________________ © 2006 Daniel Vik - Cost Function To find a color x in the 105 color palette that best matches a color y in the source image a cost function is used: Q(x, y) = ( x r - y r ) 2 + ( x g - y g ) 2 + ( x b - y b ) 2 The cost in is the Minimum Square Error calculated in the RGB space but other cost functions can also be used. Doing cost calculations in the YUV space sometimes give better results, especially the intensity levels (gray tones). But it may give quite big color errors because the MSX palette has so few colors. A good way of getting both good color and intensity accuracy is to use YRGB in the cost function.
_______________________________________________________________________________________________ © 2006 Daniel Vik - Color Table An interlaced 8x1 block can hold up to four different colors but not all combinations from the 105 color palette can be used in one block. There are only 6020 ways the foreground and background colors can be combined in one block. The encoding algorithm uses a table T k,i with the 6020 different color combinations for the 8x1 block. Each entry T k in the table contains four RGB values that are made up of foreground and background colors of an even and an odd image.
_______________________________________________________________________________________________ © 2006 Daniel Vik - Cost calculation Next the cost q k of using a color combination T k to match the 8x1 block from the source image B n is calculated. The cost for one pixel n in the block is the color T k,i that gives the lowest cost value when compared with the pixel B n in the source image. The cost q k for the entire block is the sum of the cost of each individual pixel: q k = ∑ n=1..8 min( Q(T k,1, B n ), Q(T k,2, B n ), Q(T k,3, B n ), Q(T k,4, B n ) ) When the cost for all color combinations are calculated, the lowest value d k tells which color combination T k best matches the source image.
_______________________________________________________________________________________________ © 2006 Daniel Vik - Final Steps Once the lowest cost color combination T best is found, the foreground and background colors for the even and odd screen 2 image that made up the RGB values in T best are saved. The patterns of the two images are calculated indirectly in the cost calculation, but given the index i of the color with the lowest cost T best,i it is possible to tell whether a foreground or background color should be used for a pixel in the two screen 2 images.