public void Clear() { m_PixelFormat = GR.Drawing.PixelFormat.Undefined; m_Width = 0; m_Height = 0; m_PaletteData.Clear(); }
public void Create(int Width, int Height, GR.Drawing.PixelFormat PixelFormat) { Clear(); m_Width = Width; m_Height = Height; m_PixelFormat = PixelFormat; int bytesPerLine = BitsPerPixel * Width / 8; m_ImageData.Resize((uint)(bytesPerLine * Height)); switch (m_PixelFormat) { case GR.Drawing.PixelFormat.Format1bppIndexed: m_PaletteData = new GR.Memory.ByteBuffer(2 * 3); break; case GR.Drawing.PixelFormat.Format4bppIndexed: m_PaletteData = new GR.Memory.ByteBuffer(16 * 3); break; case GR.Drawing.PixelFormat.Format8bppIndexed: m_PaletteData = new GR.Memory.ByteBuffer(256 * 3); break; case GR.Drawing.PixelFormat.Format16bppRgb555: case GR.Drawing.PixelFormat.Format24bppRgb: case GR.Drawing.PixelFormat.Format32bppArgb: case GR.Drawing.PixelFormat.Format32bppRgb: break; default: throw new NotSupportedException("Pixelformat " + PixelFormat + " not supported"); } }
public bool ReadFromBuffer(GR.Memory.ByteBuffer ProjectFile) { ColorMapping.Clear(); for (int i = 0; i < 16; ++i) { ColorMapping.Add(i, new List <ColorMappingTarget> { ColorMappingTarget.ANY }); } Colors.Palettes.Clear(); GR.IO.MemoryReader memReader = new GR.IO.MemoryReader(ProjectFile); GR.IO.FileChunk chunk = new GR.IO.FileChunk(); while (chunk.ReadFromStream(memReader)) { GR.IO.MemoryReader chunkReader = chunk.MemoryReader(); switch (chunk.Type) { case FileChunkConstants.GRAPHIC_SCREEN_INFO: SelectedCheckType = (CheckType)chunkReader.ReadUInt32(); ScreenOffsetX = chunkReader.ReadInt32(); ScreenOffsetY = chunkReader.ReadInt32(); ScreenWidth = chunkReader.ReadInt32(); ScreenHeight = chunkReader.ReadInt32(); if ((ScreenWidth == 0) || (ScreenHeight == 0)) { ScreenWidth = 320; ScreenHeight = 200; } break; case FileChunkConstants.GRAPHIC_COLOR_MAPPING: { ColorMapping.Clear(); int numEntries = chunkReader.ReadInt32(); for (int i = 0; i < numEntries; ++i) { ColorMapping.Add(i, new List <ColorMappingTarget>()); int numMappings = chunkReader.ReadInt32(); for (int j = 0; j < numMappings; ++j) { ColorMappingTarget mappingTarget = (ColorMappingTarget)chunkReader.ReadUInt8(); ColorMapping[i].Add(mappingTarget); } } } break; case FileChunkConstants.GRAPHIC_DATA: { int width = chunkReader.ReadInt32(); int height = chunkReader.ReadInt32(); GR.Drawing.PixelFormat format = (GR.Drawing.PixelFormat)chunkReader.ReadInt32(); int paletteCount = chunkReader.ReadInt32(); Image.Create(width, height, format); for (int i = 0; i < paletteCount; ++i) { byte r = chunkReader.ReadUInt8(); byte g = chunkReader.ReadUInt8(); byte b = chunkReader.ReadUInt8(); Image.SetPaletteColor(i, r, g, b); } uint dataSize = chunkReader.ReadUInt32(); GR.Memory.ByteBuffer imageData = new GR.Memory.ByteBuffer(); chunkReader.ReadBlock(imageData, dataSize); Image.SetData(imageData); } break; case FileChunkConstants.MULTICOLOR_DATA: MultiColor = (chunkReader.ReadUInt8() == 1); Colors.BackgroundColor = chunkReader.ReadUInt8(); Colors.MultiColor1 = chunkReader.ReadUInt8(); Colors.MultiColor2 = chunkReader.ReadUInt8(); Colors.ActivePalette = chunkReader.ReadInt32(); if ((Colors.MultiColor1 < 0) || (Colors.MultiColor1 >= 16)) { Colors.MultiColor1 = 0; } if ((Colors.MultiColor2 < 0) || (Colors.MultiColor2 >= 16)) { Colors.MultiColor2 = 0; } break; case FileChunkConstants.PALETTE: Colors.Palettes.Add(Palette.Read(chunkReader)); break; } } memReader.Close(); if (Colors.Palettes.Count == 0) { Colors.Palettes.Add(PaletteManager.PaletteFromMachine(MachineType.C64)); } return(true); }
public MemoryImage(int Width, int Height, GR.Drawing.PixelFormat PixelFormat) { Create(Width, Height, PixelFormat); }