private void Decode(IoBuffer io) { var y = 0; var endmarker = false; var hasPixels = (this.Flags & 0x01) == 0x01; var hasZBuffer = (this.Flags & 0x02) == 0x02; var hasAlpha = (this.Flags & 0x04) == 0x04; if (this.Parent.ChunkLabel != null && this.Parent.ChunkLabel.StartsWith("SRC6GADB84")) { var qq = 22; } var numPixels = this.Width * this.Height; if (hasPixels){ this.PixelData = new Color[numPixels]; } if (hasZBuffer){ this.ZBufferData = new byte[numPixels]; } if (hasAlpha){ this.AlphaData = new byte[numPixels]; } var palette = Parent.ChunkParent.Get<PALT>(this.PaletteID); var transparentPixel = palette.Colors[TransparentColorIndex]; while (!endmarker){ var marker = io.ReadUInt16(); var command = marker >> 13; var count = marker & 0x1FFF; switch (command){ /** Fill with pixel data **/ case 0x00: var bytes = count; bytes -= 2; var x = 0; while (bytes > 0){ var pxMarker = io.ReadUInt16(); var pxCommand = pxMarker >> 13; var pxCount = pxMarker & 0x1FFF; bytes -= 2; switch (pxCommand){ case 0x01: case 0x02: var pxWithAlpha = pxCommand == 0x02; for (var col = 0; col < pxCount; col++){ var zValue = io.ReadByte(); var pxValue = io.ReadByte(); bytes -= 2; var pxColor = palette.Colors[pxValue]; if (pxWithAlpha) { pxColor.A = io.ReadByte(); bytes--; }else{ if (pxColor.PackedValue == transparentPixel.PackedValue) { pxColor.A = 0; } } var offset = (y * Width) + x; this.PixelData[offset] = pxColor; this.ZBufferData[offset] = zValue; x++; } if (pxWithAlpha){ /** Padding? **/ if ((pxCount * 3) % 2 != 0){ bytes--; io.ReadByte(); } } break; case 0x03: for (var col = 0; col < pxCount; col++){ var offset = (y * Width) + x; this.PixelData[offset] = transparentPixel; this.PixelData[offset].A = 0; if (hasZBuffer){ this.ZBufferData[offset] = 255; } x++; } break; case 0x06: for (var col = 0; col < pxCount; col++) { var pxIndex = io.ReadByte(); bytes--; var offset = (y * Width) + x; var pxColor = palette.Colors[pxIndex]; byte z = 0; if (pxColor.PackedValue == transparentPixel.PackedValue){ pxColor.A = 0; z = 255; } this.PixelData[offset] = pxColor; if (hasZBuffer){ this.ZBufferData[offset] = z; } x++; } if (pxCount % 2 != 0){ bytes--; io.ReadByte(); } break; } } /** If row isnt filled in, the rest is transparent **/ while (x < Width){ var offset = (y * Width) + x; if (hasZBuffer){ this.ZBufferData[offset] = 255; } x++; } break; /** Leave the next count rows in the color channel filled with the transparent color, * in the z-buffer channel filled with 255, and in the alpha channel filled with 0. **/ case 0x04: for (var row = 0; row < count; row++){ for (var col = 0; col < Width; col++){ var offset = (row * Width) + col; if (hasPixels) { this.PixelData[offset] = transparentPixel; } if (hasAlpha){ this.PixelData[offset].A = 0; } if (hasZBuffer){ ZBufferData[offset] = 255; } } } break; case 0x05: endmarker = true; break; } y++; } }
public void Read(uint version, IoBuffer io) { if (version == 1001){ var spriteVersion = io.ReadUInt32(); var spriteSize = io.ReadUInt32(); } this.Width = io.ReadUInt16(); this.Height = io.ReadUInt16(); this.Flags = io.ReadUInt32(); io.ReadUInt16(); if (this.PaletteID == 0 || this.PaletteID == 0xA3A3) { this.PaletteID = (ushort)Parent.DefaultPaletteID; } TransparentColorIndex = io.ReadUInt16(); var y = io.ReadInt16(); var x = io.ReadInt16(); this.Position = new Vector2(x, y); this.Decode(io); }
public void Read(uint version, IoBuffer io) { uint spriteCount = 0; if (version < 20003){ spriteCount = io.ReadUInt16(); Direction = io.ReadByte(); Zoom = io.ReadByte(); }else{ Direction = io.ReadUInt32(); Zoom = io.ReadUInt32(); spriteCount = io.ReadUInt32(); } this.Sprites = new DGRPSprite[spriteCount]; for (var i = 0; i < spriteCount; i++){ var sprite = new DGRPSprite(Parent); sprite.Read(version, io); this.Sprites[i] = sprite; } }
public void Read(uint version, IoBuffer io) { if (version < 20003) { //Unknown ignored "Type" field var type = io.ReadUInt16(); SpriteID = io.ReadUInt16(); SpriteFrameIndex = io.ReadUInt16(); var flagsRaw = io.ReadUInt16(); Flags = (DGRPSpriteFlags)flagsRaw; SpriteOffset.X = io.ReadInt16(); SpriteOffset.Y = io.ReadInt16(); if(version == 20001) { ObjectOffset.Z = io.ReadFloat(); } } else { SpriteID = io.ReadUInt32(); SpriteFrameIndex = io.ReadUInt32(); SpriteOffset.X = io.ReadInt32(); SpriteOffset.Y = io.ReadInt32(); ObjectOffset.Z = io.ReadFloat(); Flags = (DGRPSpriteFlags)io.ReadUInt32(); if (version == 20004) { ObjectOffset.X = io.ReadFloat(); ObjectOffset.Y = io.ReadFloat(); } } this.Flip = (Flags & DGRPSpriteFlags.Flip) == DGRPSpriteFlags.Flip; }
public void Read(uint version, IoBuffer io) { if (version == 1001){ var spriteFersion = io.ReadUInt32(); var size = io.ReadUInt32(); this.Version = spriteFersion; }else{ this.Version = version; } var reserved = io.ReadUInt32(); var height = io.ReadUInt16(); var width = io.ReadUInt16(); this.Init(width, height); this.Decode(io); }