Sprite encoding/decoding for compact graphics data
|
08-22-2015, 12:48 PM
(This post was last modified: 08-22-2015 06:44 PM by komame.)
Post: #4
|
|||
|
|||
RE: Sprite encoding/decoding for compact graphics data
Hi,
I present you the final version of 4-bit encryption / 15 color images. The source code for the encoding and decoding functions is here: Code: // 15-color sprite encoding/decoding Now I'll show how to do the sprite encoding. 1. First, you need to have / create the image that you want to encode. The image can have up to 15 colors including transparency color. I drew a small tank 16x12 pixels of 6 colors that will be used in this example (PNG file in the attachment). 2. Then transcribe the color palette to a list of integers. 16-bit color is encoded as follows: ARRRRRGGGGGBBBBB (standard for the DIMGROB_P). A - alpha (transparency bit) - if set, the next bits (RGB) are not important. R - red 5-bits G - green 5-bits B - blue 5-bits There are 6 colors in my picture: - 1. black (0 00000 00000 00000 = #0) - 2. dark gray (0 00101 00101 00101 = #14A5) - 3. middle gray (0 01010 01010 01010 = #294A) - 4. light gray (0 01110 01110 01110 = #39CE) - 5. red (0 11111 00000 00000 = #7C00) - 6. transparent (1 11111 11111 11111 = #FFFF). Now we create a list of these colors: {#0, #14A5, #294A, #39CE, #7C00, #FFFF}; 3. Then, each pixel of your image you writes using numbers that correspond to the colors on your list of colors. In my case, it must look like this: 6663434343434342 6664333333333332 6662232323232322 6666663344444336 6666633433333135 3333333433333135 1111111433333135 6666661433333135 6666663311111336 6663434343434342 6664333333333332 6662232323232322 Now you combine these lines in one long row and a string is an input parameter to the encoding function: "666343434343434266643333333333326662232323232322666666334444433666666334333331353333333433333135111111143333313566666614333331356666663311111336666343434343434266643333333333326662232323232322" 4. So, let's do the encoding! Code: ES15("666343434343434266643333333333326662232323232322666666334444433666666334333331353333333433333135111111143333313566666614333331356666663311111336666343434343434266643333333333326662232323232322"); ..and this is the result (much shorter string): "晣䍃䍃䍂晤㌳㌳㌲晢⌣⌣⌢晦昳䑄䌶晦挴㌳ㄵ㌳㌴㌳ㄵᄑᄔ㌳ㄵ晦昔㌳ㄵ晦昳ᄑጶ晣䍃䍃䍂晤㌳㌳㌲晢⌣⌣⌢" 5. Now we should copy the function of decoding DS15 into our program and as its parameter specify the encoded string and color palette, which had previously been written. Code: DS15("晣䍃䍃䍂晤㌳㌳㌲晢⌣⌣⌢晦昳䑄䌶晦挴㌳ㄵ㌳㌴㌳ㄵᄑᄔ㌳ㄵ晦昔㌳ㄵ晦昳ᄑጶ晣䍃䍃䍂晤㌳㌳㌲晢⌣⌣⌢",p); Our encoded string can be decoded to a variable or directly to DIMGROB_P, for example: Code: DIMGROB_P(G1,16,12,DS15("晣䍃䍃䍂晤㌳㌳㌲晢⌣⌣⌢晦昳䑄䌶晦挴㌳ㄵ㌳㌴㌳ㄵᄑᄔ㌳ㄵ晦昔㌳ㄵ晦昳ᄑጶ晣䍃䍃䍂晤㌳㌳㌲晢⌣⌣⌢",p)); 6. That's all. Now you can use BLIT_P to display the decoded image. Code: BLIT_P(G0,32,32,G1); You can use several color palettes and decode the same images with different brightness (for example). I did have a small comparison as between ICON, a list of integers and my encoding method. Now, the image of the tank size is 50 characters plus size of color palette, which can be only one to multiple images. If we use the command ICON the same image will take 387 characters. If we use a list of integers this image will take 1090 characters. So if you have several or even dozens of sprits in yours program the aggregated differences could be very significant. In the attachment is placed a finished solution for those who do not want to prescribe |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Sprite encoding/decoding for compact graphics data - komame - 08-20-2015, 04:10 PM
RE: Sprite encoding/decoding for compact graphics data - Han - 08-21-2015, 01:50 PM
RE: Sprite encoding/decoding for compact graphics data - komame - 08-21-2015, 08:43 PM
RE: Sprite encoding/decoding for compact graphics data - komame - 08-22-2015 12:48 PM
RE: Sprite encoding/decoding for compact graphics data - webmasterpdx - 06-25-2017, 02:33 PM
|
User(s) browsing this thread: 2 Guest(s)