Graphics encoding help

I have some sprites that I want to add to my game. Currently they are stored as PNG but it takes too much space. I was looking at some source code from other games and I found the following one from Pitfall Scorpion Island:


			// -- DECOMPRESS SPRITES BEGIN
			// -------------------------------------------------
			int[] spriteData = new int[1024];
			BufferedImage[][] sprites = new BufferedImage[10][2];
			String GRAPHICS_DATA = "\u1800\u1818\u1810\u1a18\u1c1e\u1818\u1818\u1818\u1818\u1818\u1c18\u1800\u1818\u1810\u3818\u3e3a\u183c\u1818\u1c1c\u7414\u4344\u0002\u1800\u1818\u1810\u1818\u1818\u1c1c\u1818\u0e1c\u3e0a\u2828\u0c08\u1800\u1818\u1810\u1818\u1c18\u181c\u1c18\u161e\u3432\u2224\u1020\u1800\u1818\u1810\u3818\u3e3a\u183c\u1c18\u363e\u6262\u80c3\u0080\u1800\u1818\u1810\u3e1a\u587c\u1858\u1e1c\u72da\u0033\u0000\u0000\u0000\ud870\u9288\ufac4\u3c78\u4933\u7000\u88d8\u8290\uf8c6\u3d78\u8532\u0000\u0000\u0604\u55ff\uffab\u8000\ubae0\u0b2e\u0303\uffab";
			for (int s = 0, dataIndex = 0; s < 10; s++) {
				int height = (s < 6) ? 11 : (s < 8) ? 6 : 5;
				int off = 0;
				for (int y = 0; y < height; y++, dataIndex++) {
					int data = GRAPHICS_DATA.charAt(dataIndex);
					for (int j = 0; j < 2; j++, off += 32) {
						int row = data & 0xff;
						data >>= 8;
						int Y = (y << 1) + j;
						for (int k = 0; k < 8; k++) {
							int color = (row & 1) == 0 ? 0
									: (s < 6) ? ((Y < 2) ? 0xFF887000
											: (Y < 5) ? 0xFFFC9838
													: (Y < 12) ? 0xFF80D010
															: 0xFF2A5F00)
											: (s < 8) ? 0xFFFFFFFF : 0xFF80FF10;
							int off2 = off + (k << 1);
							spriteData[off2] = spriteData[off2 + 1] = spriteData[off2 + 16] = spriteData[off2 + 17] = color;
							row >>= 1;
						}
					}
				}
				for (int i = 0; i < 2; i++) {
					int hi = height << 2;
					for (int y = 0; y < hi; y++) {
						for (int left = y << 4, right = left + 15; left < right; left++, right--) {
							int temp = spriteData[left];
							spriteData[left] = spriteData[right];
							spriteData[right] = temp;
						}
					}
					BufferedImage image = new BufferedImage(16, hi,
							BufferedImage.TYPE_INT_ARGB_PRE);
					image.setRGB(0, 0, image.getWidth(), image.getHeight(),
							spriteData, 0, image.getWidth());
					sprites[s][i] = image;
				}
			}

			// -- DECOMPRESS SPRITES END
			// ---------------------------------------------------

It seems to me that this option uses lesser space but I didn’t get how the code above works (specially the GRAPHICS_DATA constant).

Could someone explain it to me?

Or how is the best way to put sprites graphics instead of creating them using drawLine and similar functions?

Thanks for the help.

if the sprites are small why not use .gif?

There are a couple of sprite compression tools/ techniques for 4k competitions that have been created through out the years.

The two i know of are :

Ordered Index Differences compression tool

and

SuperPackME

The Ordered Index Differences compression tool is one i created for my 2007 entry ( http://www.java4k.com/index.php?action=games&method=view&gid=165 )

See http://www.java-gaming.org/index.php/topic,17876.0.html for details and downloads.

The SuperPackMe details can be found at http://jgcwiki.datadino.com/jgcwiki/index.php?title=Image:SuperPackME.zip