public Color[] GetBitmapAsFlatArray(int paletteIndex) { int bitmapWidth = ImageData.GetLength(0); int bitmapHeight = ImageData.GetLength(1); var bitmap = new Color[bitmapWidth * bitmapHeight]; for (var y = 0; y < bitmapHeight; ++y) { for (var x = 0; x < bitmapWidth; ++x) { Color pixelColor; ImageDataEntry currentDataEntry = ImageData[x, y]; if (currentDataEntry is IndexedColourDataEntry) { pixelColor = ColourLookupTable.LookupTable [((IndexedColourDataEntry)currentDataEntry).CLUTIndex, paletteIndex] .GetAsSystemColor(); } else if (currentDataEntry is RealColourDataEntry) { pixelColor = ((RealColourDataEntry)currentDataEntry).Color; } bitmap[y * bitmapWidth + x] = pixelColor; } } return(bitmap); }
public ImageDataDirectory *GetDataEntry(ImageDataEntry entry) { if (_magic == Win32.Pe32Magic) { if ((int)entry >= _ntHeaders->OptionalHeader.NumberOfRvaAndSizes) { return(null); } return(&(&_ntHeaders->OptionalHeader.DataDirectory)[(int)entry]); } else if (_magic == Win32.Pe32PlusMagic) { if ((int)entry >= this.GetOptionalHeader64()->NumberOfRvaAndSizes) { return(null); } return(&(&this.GetOptionalHeader64()->DataDirectory)[(int)entry]); } else { return(null); } }
/// <summary> /// Creates image data entries from the provided stream for the given BPP /// </summary> public static ImageDataEntry[] CreateImageDataEntry( List <ushort> frameBufferPixels, BitsPerPixel bitsPerPixel) { switch (bitsPerPixel) { case BitsPerPixel.FOUR: { ImageDataEntry[] imageDataEntries = new ImageDataEntry[4]; ushort data = frameBufferPixels[0]; imageDataEntries[0] = new IndexedColourDataEntry((byte)(data & 0x0F)); imageDataEntries[1] = new IndexedColourDataEntry((byte)((data >> 4) & 0x0F)); imageDataEntries[2] = new IndexedColourDataEntry((byte)((data >> 8) & 0x0F)); imageDataEntries[3] = new IndexedColourDataEntry((byte)((data >> 12) & 0x0F)); return(imageDataEntries); } case BitsPerPixel.EIGHT: { ImageDataEntry[] imageDataEntries = new ImageDataEntry[2]; ushort data = frameBufferPixels[0]; imageDataEntries[0] = new IndexedColourDataEntry((byte)(data & 0xFF)); imageDataEntries[1] = new IndexedColourDataEntry((byte)((data >> 8) & 0xFF)); return(imageDataEntries); } case BitsPerPixel.SIXTEEN: { ImageDataEntry[] imageDataEntries = new ImageDataEntry[1]; imageDataEntries[0] = new RealColourDataEntry(frameBufferPixels[0]); return(imageDataEntries); } case BitsPerPixel.TWENTY_FOUR: { ImageDataEntry[] imageDataEntries = new ImageDataEntry[1]; imageDataEntries[0] = new RealColourDataEntry( frameBufferPixels[0], frameBufferPixels[1], frameBufferPixels[2]); return(imageDataEntries); } default: throw new InvalidOperationException( $"No factory method found for BitsPerPixel value " + $"'{bitsPerPixel}'"); } }
public ImageDataDirectory *GetDataEntry(ImageDataEntry entry) { switch (this._magic) { case Win32.Pe32Magic: if ((int)entry >= this._ntHeaders->OptionalHeader.NumberOfRvaAndSizes) { return(null); } return(&(&this._ntHeaders->OptionalHeader.DataDirectory)[(int)entry]); case Win32.Pe32PlusMagic: if ((int)entry >= this.GetOptionalHeader64()->NumberOfRvaAndSizes) { return(null); } return(&(&this.GetOptionalHeader64()->DataDirectory)[(int)entry]); default: return(null); } }
public ImageDataDirectory* GetDataEntry(ImageDataEntry entry) { if (_magic == Win32.Pe32Magic) { if ((int)entry >= _ntHeaders->OptionalHeader.NumberOfRvaAndSizes) return null; return &(&_ntHeaders->OptionalHeader.DataDirectory)[(int)entry]; } else if (_magic == Win32.Pe32PlusMagic) { if ((int)entry >= this.GetOptionalHeader64()->NumberOfRvaAndSizes) return null; return &(&this.GetOptionalHeader64()->DataDirectory)[(int)entry]; } else { return null; } }
public TIMImage(Stream stream) { byte tag = (byte)stream.ReadByte(); if (tag != 16) { throw new InvalidOperationException( "The first byte found in the stream was not 0x10; the data is not in the TIM" + " format"); } Version = (byte)stream.ReadByte(); stream.Seek(2, SeekOrigin.Current); byte flags = (byte)stream.ReadByte(); BitsPerPixel = (BitsPerPixel)(flags & 0x03); HasCLUT = (flags & 0x08) > 0; stream.Seek(3, SeekOrigin.Current); if (HasCLUT) { CLUT clut = new CLUT(); clut.Length = stream.ReadInt(); clut.X = stream.ReadUShort(); clut.Y = stream.ReadUShort(); clut.Width = stream.ReadUShort(); clut.Height = stream.ReadUShort(); CLUTColor[,] lookupTable = new CLUTColor[clut.Width, clut.Height]; for (int y = 0; y < clut.Height; ++y) { for (int x = 0; x < clut.Width; ++x) { lookupTable[x, y] = new CLUTColor(stream.ReadUShort()); } } clut.LookupTable = lookupTable; ColourLookupTable = clut; } ImageLength = stream.ReadInt(); ImageX = stream.ReadUShort(); ImageY = stream.ReadUShort(); ImageWidth = stream.ReadUShort(); ImageHeight = stream.ReadUShort(); int wordsPerDataEntry = 1; switch (BitsPerPixel) { case BitsPerPixel.FOUR: ImageData = new ImageDataEntry[ImageWidth * 4, ImageHeight]; break; case BitsPerPixel.EIGHT: ImageData = new ImageDataEntry[ImageWidth * 2, ImageHeight]; break; case BitsPerPixel.SIXTEEN: ImageData = new ImageDataEntry[ImageWidth, ImageHeight]; break; case BitsPerPixel.TWENTY_FOUR: ImageData = new ImageDataEntry[(int)Math.Ceiling(ImageWidth / 3f), ImageHeight]; wordsPerDataEntry = 3; break; } for (int y = 0; y < ImageHeight; ++y) { List <ushort> buffer = new List <ushort>(); List <ImageDataEntry> currentRow = new List <ImageDataEntry>(); for (int x = 0; x < ImageWidth; ++x) { buffer.Add(stream.ReadUShort()); if (buffer.Count == wordsPerDataEntry) { currentRow.AddRange( ImageDataEntryFactory.CreateImageDataEntry(buffer, BitsPerPixel)); buffer.Clear(); } } for (int x = 0; x < currentRow.Count; ++x) { ImageData[x, y] = currentRow[x]; } } }
public ImageDataDirectory* GetDataEntry(ImageDataEntry entry) { switch (this._magic) { case Win32.Pe32Magic: if ((int)entry >= this._ntHeaders->OptionalHeader.NumberOfRvaAndSizes) return null; return &(&this._ntHeaders->OptionalHeader.DataDirectory)[(int)entry]; case Win32.Pe32PlusMagic: if ((int)entry >= this.GetOptionalHeader64()->NumberOfRvaAndSizes) return null; return &(&this.GetOptionalHeader64()->DataDirectory)[(int)entry]; default: return null; } }