![]() ![]() 10 10 10 20 20 20 30 30 30) is also a good indication of a palette with a greyscale section in it, which is another common feature. Looking at the palette in a hex editor will often reveal the file starts with three 0x00 bytes, on account of nearly all games using palette index #0 as black. It is relatively simple to "detect" a VGA palette file, particularly if they are 6-bit RGB as the files will be exactly 768 bytes long - almost no other files are exactly this size. The VGA treats 0x40 the same as 0x3F however (TODO: Confirm). Note however that the input VGA values may need to be capped to 0x3F (63) as some games output the value 0x40 for 100% instead of 0x3F (TODO: Confirm/link to example). ![]() More efficient conversions can also be used when speed is more important than code readability: Performing the multiplication before the division removes the need to use floating point numbers and minimises any rounding errors. Six_bit_value = (eight_bit_value * 63) / 255 To easily convert between one format to another, some simple formulae can be used for each of the red, green and blue values:Įight_bit_value = (six_bit_value * 255) / 63 In most cases the fourth byte (A) isn't used and can be ignored. Some variants of this format pad the values out to 32-bits, and this format is often referred to as 8-bit RGBA. This format is often referred to as 8-bit RGB. All this means is that each of the red, green and blue bytes will have the full range of values (0-255) instead of the limited VGA values (0-63). Since the widespread use of video cards capable of displaying 24-bit images, 256 colour palettes have been increased to use the full eight bits in each byte for storing colour levels. This format is often referred to as 6-bit RGB. (However be aware that some games use values between zero and 64! In these cases 64 should be treated the same as 63, as this is what the VGA does.) Each colour takes up three bytes (one each for red, green and blue) and only the lower six bits of each byte are used (as the VGA only uses six bits per colour.) In practice this means each byte will only contain values between zero and 63 inclusive. ![]() See TestSqDiff for correctness check.The classic palette format maps exactly to the VGA registers. 333 // 334 // Considering these properties and the fact that this function is 335 // called in the hot paths (x,y loops), it is reduced to the below code 336 // which is slightly faster. Loosely speaking, these unsigned integer operations 331 // > discard high bits upon overflow, and programs may rely on ``wrap 332 // > around''. 10 type Color interface 323 // return (d * d) > 2 324 // 325 // Language spec guarantees the following properties of unsigned integer 326 // values operations with respect to overflow/wrap around: 327 // 328 // > For unsigned integer values, the operations +, -, *, and computed modulo 2n, where n is the bit width of the unsigned 330 // > integer's type. 6 package colorħ 8 // Color can convert itself to alpha-premultiplied 16-bits per channel RGBA. 4 5 // Package color implements a basic color library. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. Src/ image/ color/ color.go 1 // Copyright 2011 The Go Authors. ![]()
0 Comments
Leave a Reply. |