示例#1
0
        public bool DrawPalImage(int imageIndex)
        {
            if (ImagesPal == null || ImagesPal.Count <= imageIndex)
            {
                return(false);
            }
            if (imageIndex < 0 || imageIndex >= ImagesPal.Count)
            {
                return(false);
            }

            RoSpriteImagePal sprImg = ImagesPal[imageIndex];

            if (Version >= 0x201 && sprImg.Decoded == false)
            {
                sprImg.Data    = RLE.Decode(sprImg.Data);
                sprImg.Decoded = true;
            }
            if (sprImg.Data == null || sprImg.Data.Length == 0 || sprImg.Width < 1 || sprImg.Height < 1)
            {
                return(false);
            }

            sprImg.Image = new Bitmap(sprImg.Width, sprImg.Height);
            FastBitmap fb = new FastBitmap(sprImg.Image);

            int index;

            fb.LockImage();
            for (int x = 0; x < sprImg.Width; x++)
            {
                for (int y = 0; y < sprImg.Height; y++)
                {
                    index = (x + (y * sprImg.Width));
                    if (index >= sprImg.Data.Length)
                    {
                        fb.SetPixel(x, y, Color.Transparent);
                        continue;
                    }
                    fb.SetPixel(x, y, Palette[sprImg.Data[index]]);
                }
            }
            fb.UnlockImage();

            return(true);
        }
示例#2
0
        public void AddImagePal(Bitmap image, int position)
        {
            RoSpriteImagePal img = new RoSpriteImagePal();

            img.Width   = (ushort)image.Width;
            img.Height  = (ushort)image.Height;
            img.Image   = image.Clone() as Bitmap;
            img.Decoded = true;
            img.Size    = (ushort)(img.Width * img.Height);
            img.Data    = new byte[img.Size];

            // build data
            for (int x = 0; x < img.Width; x++)
            {
                for (int y = 0; y < img.Height; y++)
                {
                    Color c = image.GetPixel(x, y);
                    int   i = Palette.IndexOf(c);
                    if (i == -1)
                    {
                        continue;                         // TODO: color not found?
                    }
                    img.Data[(x + (y * img.Width))] = (byte)i;
                }
            }

            if (position >= ImagesPal.Count)
            {
                ImagesPal.Add(img);
            }
            else
            {
                ImagesPal[position].Image = null;                 // force redraw
                ImagesPal.Insert(position, img);
            }
        }
示例#3
0
		public void AddImagePal(Bitmap image, int position) {
			RoSpriteImagePal img = new RoSpriteImagePal();
			img.Width = (ushort)image.Width;
			img.Height = (ushort)image.Height;
			img.Image = image.Clone() as Bitmap;
			img.Decoded = true;
			img.Size = (ushort)(img.Width * img.Height);
			img.Data = new byte[img.Size];

			// build data
			for (int x = 0; x < img.Width; x++) {
				for (int y = 0; y < img.Height; y++) {
					Color c = image.GetPixel(x, y);
					int i = Palette.IndexOf(c);
					if (i == -1)
						continue; // TODO: color not found?
					img.Data[(x + (y * img.Width))] = (byte)i;
				}
			}

			if (position >= ImagesPal.Count) {
				ImagesPal.Add(img);
			} else {
				ImagesPal[position].Image = null; // force redraw
				ImagesPal.Insert(position, img);
			}
		}
示例#4
0
		protected override bool ReadInternal() {
			ImagesPal = new List<RoSpriteImagePal>();
			ImagesRgba = new List<RoSpriteImageRgba>();
			Palette = new RoPalette();

			MagicHead = Reader.ReadChars(2);
			if (MagicHead[0] != 0x53 || MagicHead[1] != 0x50) {
				// Invalid header
				return false;
			}
			Version = new GenericFileFormatVersion(Reader);
			if (Version.Major > 2) {
				// Unsupported version
				return false;
			}

			int imgPalCount = Reader.ReadUInt16();
			int imgRgbaCount = 0;
			if (Version >= 0x201) {
				imgRgbaCount = Reader.ReadUInt16();
			}

			// Images - Palette \\
			RoSpriteImagePal imgPal;
			for (int i = 0; i < imgPalCount; i++) {
				imgPal = new RoSpriteImagePal() {
					Width = Reader.ReadUInt16(),
					Height = Reader.ReadUInt16()
				};
				if (Version >= 0x201) {
					imgPal.Size = Reader.ReadUInt16();
				} else {
					imgPal.Size = (ushort)(imgPal.Width * imgPal.Height);
				}
				imgPal.Data = Reader.ReadBytes(imgPal.Size);

				ImagesPal.Add(imgPal);
			}

			// Images - RGBA \\
			RoSpriteImageRgba imgRgba;
			for (int i = 0; i < imgRgbaCount; i++) {
				imgRgba = new RoSpriteImageRgba() {
					Width = Reader.ReadUInt16(),
					Height = Reader.ReadUInt16()
				};

				int size = (imgRgba.Width * imgRgba.Height * 4);
				imgRgba.Data = Reader.ReadBytes(size);

				ImagesRgba.Add(imgRgba);
			}

			// Palette \\
			Reader.BaseStream.Position = (Reader.BaseStream.Length - (4 * RoPalette.ColorCount));

			Palette.Read(Reader.BaseStream);

			Flush();
			return true;
		}
示例#5
0
        protected override bool ReadInternal()
        {
            ImagesPal  = new List <RoSpriteImagePal>();
            ImagesRgba = new List <RoSpriteImageRgba>();
            Palette    = new RoPalette();

            MagicHead = Reader.ReadChars(2);
            if (MagicHead[0] != 0x53 || MagicHead[1] != 0x50)
            {
                // Invalid header
                return(false);
            }
            Version = new GenericFileFormatVersion(Reader);
            if (Version.Major > 2)
            {
                // Unsupported version
                return(false);
            }

            int imgPalCount  = Reader.ReadUInt16();
            int imgRgbaCount = 0;

            if (Version >= 0x201)
            {
                imgRgbaCount = Reader.ReadUInt16();
            }

            // Images - Palette \\
            RoSpriteImagePal imgPal;

            for (int i = 0; i < imgPalCount; i++)
            {
                imgPal = new RoSpriteImagePal()
                {
                    Width  = Reader.ReadUInt16(),
                    Height = Reader.ReadUInt16()
                };
                if (Version >= 0x201)
                {
                    imgPal.Size = Reader.ReadUInt16();
                }
                else
                {
                    imgPal.Size = (ushort)(imgPal.Width * imgPal.Height);
                }
                imgPal.Data = Reader.ReadBytes(imgPal.Size);

                ImagesPal.Add(imgPal);
            }

            // Images - RGBA \\
            RoSpriteImageRgba imgRgba;

            for (int i = 0; i < imgRgbaCount; i++)
            {
                imgRgba = new RoSpriteImageRgba()
                {
                    Width  = Reader.ReadUInt16(),
                    Height = Reader.ReadUInt16()
                };

                int size = (imgRgba.Width * imgRgba.Height * 4);
                imgRgba.Data = Reader.ReadBytes(size);

                ImagesRgba.Add(imgRgba);
            }

            // Palette \\
            Reader.BaseStream.Position = (Reader.BaseStream.Length - (4 * RoPalette.ColorCount));

            Palette.Read(Reader.BaseStream);

            Flush();
            return(true);
        }