Пример #1
0
		private Image ParseImage(BinaryParser parser)
		{
			var image = new Image();

			image.Format = (ImageFormat)parser.ConsumeUInt8();

			image.Flags = parser.ConsumeUInt16();

			image.width = parser.ConsumeUInt16();
			image.height = parser.ConsumeUInt16();
			image.pitch = parser.ConsumeUInt16();
			image.palette = parser.ConsumeUInt32();

			byte[] d = new byte[image.height * image.pitch];
			parser.ConsumeArray(d);
			image.data = d;

			switch (image.Format)
			{
				case ImageFormat.ABGR_8888:
				case ImageFormat.BGR_888:
				case ImageFormat.RGB_888:
					return image;
					//case Image.PALETTE4_ABGR_1555:
					//    format = (new Palette4Abgr1555(image.width, image.height, image.pitch));
					//    Debug.WriteLine(string.Format("Image PALETTE4_ABGR_1555 {0}x{1}", image.width, image.height));
					//    break;
					//case Image.PALETTE4_RGB_888:
					//    format = (new Palette4Rgb888(image.width, image.height, image.pitch));
					//    Debug.WriteLine(string.Format("Image PALETTE4_RGB_888 {0}x{1}", image.width, image.height));
					//    break;
					//case Image.PALETTE8_ABGR_1555:
					//    format = (new Palette8Abgr1555(image.width, image.height, image.pitch));
					//    Debug.WriteLine(string.Format("Image PALETTE8_ABGR_1555 {0}x{1}", image.width, image.height));
					//    break;
					//case Image.ABGR_1555:
					//    Debug.WriteLine(string.Format("Image ABGR_1555 {0}x{1}", image.width, image.height));
					//    LoadABGR1555(serialise);
					//    return;
					//case Image.RGBA_6666:
					//    Debug.WriteLine(string.Format("Image RGBA_6666 {0}x{1}", image.width, image.height));
					//    LoadRgba6666(serialise);
					//    return;
				case ImageFormat.PALETTE8_RGB_888:
					image.PaletteData = parser.ConsumeByteArray(256 * 3);
					return image;
				case ImageFormat.PALETTE8_ABGR_8888:
				case ImageFormat.PALETTE8_ARGB_8888:
				case ImageFormat.PALETTE8_RGBA_8888:
					image.PaletteData = parser.ConsumeByteArray(256 * 4);
					return image;
				case ImageFormat.PALETTE4_RGB_888:
					image.PaletteData = parser.ConsumeByteArray(16 * 3);
					return image;
				case ImageFormat.PALETTE4_ABGR_8888:
				case ImageFormat.PALETTE4_ARGB_8888:
				case ImageFormat.PALETTE4_RGBA_8888:
					image.PaletteData = parser.ConsumeByteArray(16 * 4);
					return image;
				default:
					throw new FormatException(string.Format(CultureInfo.CurrentCulture, "Unknown image format 0x{0:x}", image.Format));
			}
		}