public ImageListOptions() { this.Name = string.Empty; this.ColorDepth = ColorDepth.Depth32Bit; this.ImageSize = new Size(16, 16); this.TransparentColor = System.Drawing.Color.Transparent; }
private static Func<BinaryReader, Color> GetColorReader( ColorDepth colorDepth, Func<IndexedPalette> paletteSelector) { switch (colorDepth) { case ColorDepth.RGBA: return reader => { var b = reader.ReadBytes(4); return new Color(b[0] / 255f, b[1] / 255f, b[2] / 255f, b[3] / 255f); }; case ColorDepth.Grayscale: return reader => { var b = reader.ReadBytes(2); return new Color(b[0] / 255f, b[0] / 255f, b[0] / 255f, b[1] / 255f); }; case ColorDepth.Indexed: return reader => { var b = reader.ReadByte(); return paletteSelector()?.GetColor(b) ?? Color.clear; }; default: throw new NotSupportedException($"Color Depth: {colorDepth} not supported. Is the file corrupted?"); } }
/// <summary> /// Send a command to the the display controller along with parameters. /// </summary> /// <param name="command">Command to send.</param> /// <param name="data">Span to send as parameters for the command.</param> private void SendCommand(Ssd1351Command command, Span <byte> data) { Span <byte> commandSpan = stackalloc byte[] { (byte)command }; SendSPI(commandSpan, true); if (data != null && data.Length > 0) { SendSPI(data); // detect certain commands that may alter the state of the device. This is done as the // SPI device cannot read registers from the ssd1351 and so changes need to be captured switch (command) { // capture changes to the colour depth and colour sequence case Ssd1351Command.SetRemap: _colorSequence = (ColorSequence)((data[0] >> 2) & 0x01); _colorDepth = (ColorDepth)((data[0] >> 6) & 0x03); break; } } }
public Image Scan(DeviceInfo device, PageSize pageSize, ColorDepth colorDepth, Resolution resolution, Orientation orientation, bool setSize = true) { if (device == null) { throw new ArgumentException("Device must be specified"); } var scanner = device.Connect(); var wiaCommonDialog = new WPFCommonDialog(); var item = scanner.Items[1]; SetupPageSize(item, pageSize, colorDepth, resolution, orientation, setSize); var image = (ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false); string fileName = Path.GetTempFileName(); File.Delete(fileName); image.SaveFile(fileName); image = null; // add file to output list return(Image.FromFile(fileName)); }
public RGB ToDepth(ColorDepth bitDepth) { if (this.bits == bitDepth) { return(this); } else { if ((byte)this.bits < (byte)bitDepth) { if (this.bits == ColorDepth.Eight) { return(new RGB(this.R.Upsample(3), this.G.Upsample(3), this.B.Upsample(2), bitDepth)); } else { var componentBits = (int)this.bits / 3; return(new RGB(this.R.Upsample(componentBits), this.G.Upsample(componentBits), this.B.Upsample(componentBits), bitDepth)); } } else { return(new RGB(this.R, this.G, this.B, bitDepth)); } } }
public static Color[][] Read_WinPal2(string file, ColorDepth depth) { BinaryReader reader = new BinaryReader(File.OpenRead(file)); NCLR_s _s = new NCLR_s(); _s.header.id = reader.ReadChars(4); _s.header.file_size = reader.ReadUInt32(); _s.pltt.ID = reader.ReadChars(4); reader.ReadChars(4); reader.ReadUInt32(); reader.ReadUInt16(); _s.pltt.nColors = reader.ReadUInt16(); _s.pltt.depth = depth; uint num = (depth == ColorDepth.Depth4Bit) ? 0x10 : _s.pltt.nColors; _s.pltt.paletteLength = num * 2; Color[][] colorArray = new Color[(depth == ColorDepth.Depth4Bit) ? ((int)(_s.pltt.nColors / 0x10)) : 1][]; for (int i = 0; i < colorArray.Length; i++) { colorArray[i] = new Color[num]; for (int j = 0; j < num; j++) { Color color = Color.FromArgb(reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); reader.ReadByte(); colorArray[i][j] = color; } } reader.Close(); return(colorArray); }
public NativeImageSource(uint width, uint height, ColorDepth depth) : this(Interop.NativeImageSource.NewHandle(width, height, (int)depth), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } }
public void ImageList_ImageStream_SetStreamerSerialized_UpdatesImages(ColorDepth colorDepth) { using var sourceList = new ImageList { ColorDepth = colorDepth, ImageSize = new Size(32, 32) }; using var image = new Bitmap(10, 10); sourceList.Images.Add(image); using ImageListStreamer stream = RoundtripSerialize(sourceList.ImageStream); Assert.True(sourceList.HandleCreated); using var list = new ImageList(); int callCount = 0; EventHandler handler = (sender, e) => callCount++; list.RecreateHandle += handler; list.ImageStream = stream; Assert.Equal(colorDepth, list.ColorDepth); Assert.Equal(new Size(32, 32), ((Image)Assert.Single(list.Images)).Size); Assert.Equal(new Size(32, 32), list.ImageSize); Assert.Equal(0, callCount); Assert.True(list.HandleCreated); Assert.True(sourceList.HandleCreated); // Set same. list.ImageStream = stream; Assert.Equal(colorDepth, list.ColorDepth); Assert.Equal(new Size(32, 32), ((Image)Assert.Single(list.Images)).Size); Assert.Equal(new Size(32, 32), list.ImageSize); Assert.Equal(1, callCount); Assert.True(list.HandleCreated); Assert.True(sourceList.HandleCreated); }
public void ImageList_ImageStream_SetStreamerSerializedDisposed_Nop(ColorDepth colorDepth) { using var sourceList = new ImageList { ColorDepth = colorDepth, ImageSize = new Size(32, 32) }; var image = new Bitmap(10, 10); sourceList.Images.Add(image); ImageListStreamer stream = RoundtripSerialize(sourceList.ImageStream); Assert.True(sourceList.HandleCreated); stream.Dispose(); Assert.True(sourceList.HandleCreated); using var list = new ImageList { ImageStream = stream }; Assert.Equal(ColorDepth.Depth8Bit, list.ColorDepth); Assert.Empty(list.Images); Assert.Equal(new Size(16, 16), list.ImageSize); Assert.False(list.HandleCreated); Assert.True(sourceList.HandleCreated); }
public IcDvImg(Size size, ColorDepth colorDepth) { this.colorDepth = ColorDepth.Depth4Bit; this.hIcon = IntPtr.Zero; this.setDeviceImage(size, colorDepth); this.createIcon(); }
public Parte Obtener_ParteARJ(long posicion, ColorDepth tipo) { Parte parte = new Parte(); BinaryReader rdr = new BinaryReader(File.OpenRead(archivo)); rdr.BaseStream.Position = posicion; parte.offSet = (ulong)posicion; ushort width = rdr.ReadUInt16(); ushort height = rdr.ReadUInt16(); parte.posX = (ushort)rdr.ReadUInt16(); parte.posY = (ushort)rdr.ReadUInt16(); parte.width = (ushort)Math.Pow(2, 3 + rdr.ReadUInt16()); parte.height = (ushort)Math.Pow(2, 3 + rdr.ReadUInt16()); if (tipo == ColorDepth.Depth8Bit) { parte.length = (uint)parte.width * parte.height; parte.datos = rdr.ReadBytes((int)parte.length); } else { parte.length = (uint)(parte.width * parte.height) / 2; parte.datos = Ekona.Helper.BitsConverter.BytesToBit4(rdr.ReadBytes((int)parte.length)); } rdr.Close(); return(parte); }
private void ConfigureScreen() { switch (Mode) { case ScreenMode.Zero: _resolution = null; _textResolution = new TextResolution(TextColumnWidth.Eighty, TextRowHeight.TwentyFive); SetWidth(TextColumnWidth.Eighty, TextRowHeight.TwentyFive); _colorEnabled = true; _colorAttributes = ColorAttributes.Sixteen; _colorDepth = ColorDepth.d4Bit; _videoMemoryPages = MinimumPages; InitPages(PageSize.m2K); break; case ScreenMode.One: _resolution = new Resolution(320, 200); break; case ScreenMode.Two: _resolution = new Resolution(640, 200); break; case ScreenMode.Three: _resolution = new Resolution(720, 348); break; case ScreenMode.Four: _resolution = new Resolution(640, 400); break; case ScreenMode.Seven: _resolution = new Resolution(320, 200); break; case ScreenMode.Eight: _resolution = new Resolution(640, 200); break; case ScreenMode.Nine: _resolution = new Resolution(640, 350); break; case ScreenMode.Ten: _resolution = new Resolution(640, 350); break; case ScreenMode.Eleven: _resolution = new Resolution(640, 480); break; case ScreenMode.Twelve: _resolution = new Resolution(640, 480); break; case ScreenMode.Thirteen: _resolution = new Resolution(320, 200); break; } }
/// <summary> /// Saves /// </summary> /// <param name="path"></param> /// <param name="pixels"></param> /// <param name="zeroOffset"></param> /// <param name="colorDepth"></param> public static void SaveMap(string path, float[,] pixels, float zeroOffset, ColorDepth colorDepth, int heightScaleMultiplier = 8) { using (var writer = new BinaryWriter(File.Open($"{path}.raw", FileMode.Create))) { for (int i = pixels.GetLength(0) - 1; i >= 0; i--) { for (int j = 0; j < pixels.GetLength(1); j++) { if (colorDepth == ColorDepth.Gray16) { if (j == 552 && i == 2217) { Console.WriteLine(pixels[i, j]); } ushort normalised = (ushort)((pixels[i, j] + Math.Abs(zeroOffset)) * heightScaleMultiplier); if (j == 552 && i == 2217) { Console.WriteLine(normalised); } writer.Write(normalised); } } } } }
public ImageListOptions(ImageListOptions other) { this.Name = other.Name ?? string.Empty; this.ColorDepth = other.ColorDepth; this.ImageSize = other.ImageSize; this.TransparentColor = other.TransparentColor; this.ImageSources.AddRange(other.ImageSources); }
private Header( uint fileSize, ushort frames, ushort width, ushort height, ColorDepth colorDepth, bool layerOpacityIsValid, byte transparentIndex, byte pixelWidth, byte pixelHeight, byte pixelRatio, short xPos, short yPos, ushort gridWidth, ushort gridHeight) { FileSize = fileSize; Frames = frames; Width = width; Height = height; ColorDepth = colorDepth; LayerOpacityIsValid = layerOpacityIsValid; TransparentIndex = transparentIndex; PixelWidth = pixelWidth; PixelHeight = pixelHeight; XPosition = xPos; YPosition = yPos; GridWidth = gridWidth; GridHeight = gridHeight; PixelRatio = pixelRatio; }
/// <summary> /// Obtiene todas las imágenes contenidas en un archivo. /// </summary> /// <param name="filePath">Archivo</param> /// <returns>Array de bitmap con las imágenes</returns> public Bitmap[] Obtener_Final() { BinaryReader rdr = new BinaryReader(File.OpenRead(archivo)); Image[] imagenes = new Image[rdr.ReadUInt16()]; Bitmap[] resultados = new Bitmap[imagenes.Length]; ColorDepth tipo = rdr.ReadUInt16() == 3 ? ColorDepth.Depth4Bit : ColorDepth.Depth8Bit; for (int i = 0; i < imagenes.Length; i++) { imagenes[i] = Obtener_Imagen(rdr.BaseStream.Position, tipo); rdr.BaseStream.Position = (long)imagenes[i].segmentos[imagenes[i].imgs - 1].offSet + imagenes[i].segmentos[imagenes[i].imgs - 1].length + 8; } Paleta paleta = Obtener_Paleta(rdr.BaseStream.Position); rdr.Close(); for (int i = 0; i < imagenes.Length; i++) { resultados[i] = Transformar_Imagen(imagenes[i], paleta); resultados[i] = resultados[i].Clone(new Rectangle(0, 0, imagenes[i].width, imagenes[i].height), System.Drawing.Imaging.PixelFormat.DontCare); } return(resultados); }
/// <summary> /// Creates a new DisplayPossibleSetting /// </summary> /// <param name="resolution">Display resolution</param> /// <param name="frequency">Display frequency</param> /// <param name="colorDepth">Display color depth</param> /// <param name="isInterlaced">Indicating if display is using interlaces scan out</param> protected DisplayPossibleSetting(Size resolution, int frequency, ColorDepth colorDepth, bool isInterlaced) { ColorDepth = colorDepth; Resolution = resolution; IsInterlaced = isInterlaced; Frequency = frequency; }
private string ColorsToString(ColorDepth colorDepth) { switch (colorDepth) { case ColorDepth.Monochrome: return("Monochrome"); case ColorDepth.Colors256: return("256 colors"); case ColorDepth.Colors32K: return("32K colors"); case ColorDepth.Colors65K: return("65K colors"); case ColorDepth.Colors256K: return("256K colors"); case ColorDepth.Colors16M: return("16M colors"); case ColorDepth.Colors1G: return("1G colors"); case ColorDepth.Colors68G: return("68G colors"); case ColorDepth.Colors281T: return("281T colors"); default: return("[no colors specified]"); } }
public Image Obtener_ImagenARJ(long posicion, ColorDepth tipo) { BinaryReader rdr = new BinaryReader(File.OpenRead(archivo)); rdr.BaseStream.Position = posicion; Image imagen = new Image(); imagen.tipo = tipo; imagen.width = rdr.ReadUInt16(); imagen.height = rdr.ReadUInt16(); imagen.imgs = rdr.ReadUInt16(); imagen.segmentos = new Parte[imagen.imgs]; imagen.length = (uint)imagen.width * imagen.height; rdr.BaseStream.Seek(2, SeekOrigin.Current); for (int i = 0; i < imagen.imgs; i++) { imagen.segmentos[i] = Obtener_ParteARJ(rdr.BaseStream.Position, imagen.tipo); rdr.BaseStream.Seek(imagen.segmentos[i].length + 12, SeekOrigin.Current); } rdr.Close(); return(imagen); }
private void SetupPageSize(WIA.Item item, PageSize pageSize, ColorDepth colorDepth, Resolution resolution, Orientation orientation, bool setSize) { if (item == null) { return; } item.Properties["Horizontal Resolution"].set_Value(resolution.Value); item.Properties["Vertical Resolution"].set_Value(resolution.Value); item.Properties["Current Intent"].set_Value(colorDepth.Value); item.Properties["Bits Per Pixel"].set_Value(colorDepth.BitsPerPixel); double hExtent = item.Properties["Horizontal Extent"].SubTypeMax; double vExtent = item.Properties["Vertical Extent"].SubTypeMax; if (setSize) { if (orientation.Direction == 0) { item.Properties["Horizontal Extent"].set_Value(resolution.Value * pageSize.Width); item.Properties["Vertical Extent"].set_Value(resolution.Value * pageSize.Height); } else { item.Properties["Horizontal Extent"].set_Value(resolution.Value * pageSize.Height); item.Properties["Vertical Extent"].set_Value(resolution.Value * pageSize.Width); } } else { item.Properties["Horizontal Extent"].set_Value(hExtent); item.Properties["Vertical Extent"].set_Value(vExtent); } }
private void CarregarImagemNCGRComNSCR() { ColorDepth depth = Char.IntensidadeDeBits == 3 ? ColorDepth.F4BBP : ColorDepth.F8BBP; BGR565 palette = new BGR565(ArquivoNclr.Pltt.Paleta); ConvertedImage = ImageConverter.TileMappedToBitmap(Char.Tiles, ArquivoNscr.Scrn.InfoTela.ToList(), ArquivoNscr.Scrn.Largura, ArquivoNscr.Scrn.Altura, palette, depth); ArquivoNclr.Colors = palette.Colors; }
private void CarregarImagens() { ColorDepth depth = Char.IntensidadeDeBits == 3 ? ColorDepth.F4BBP : ColorDepth.F8BBP; BGR565 palette = new BGR565(ArquivoNclr.Pltt.Paleta); ConvertedImage = ImageConverter.RawIndexedToBitmap(Char.Tiles, Char.QuatidadeDeTilesX * 8, Char.QuatidadeDeTilesY * 8, palette, TileMode.Tiled, depth); ArquivoNclr.Colors = palette.Colors; }
public RGB(byte R, byte G, byte B, ColorDepth bitDepth) { this.R = this.MakeByte(Channels.R, bitDepth, R); this.G = this.MakeByte(Channels.G, bitDepth, G); this.B = this.MakeByte(Channels.B, bitDepth, B); this.bits = bitDepth; this.bytePattern = Helpers.BytePattern.GenerateArrayFromDepth(bitDepth); }
/// <summary> /// Creates a new DisplaySetting /// </summary> /// <param name="resolution">Display resolution</param> /// <param name="position">Display position on desktop</param> /// <param name="frequency">Display frequency</param> /// <param name="colorDepth">Display color depth</param> /// <param name="isInterlaced">Indicating if display is using interlaces scan out</param> /// <param name="orientation">Display orientation and rotation</param> /// <param name="outputScalingMode"> /// Display output behavior in case of presenting a low-resolution mode on a /// higher-resolution display /// </param> public DisplaySetting(Size resolution, Point position, ColorDepth colorDepth, int frequency, bool isInterlaced = false, DisplayOrientation orientation = DisplayOrientation.Identity, DisplayFixedOutput outputScalingMode = DisplayFixedOutput.Default ) : base(resolution, frequency, colorDepth, isInterlaced) { Position = position; Orientation = orientation; OutputScalingMode = outputScalingMode; }
public void LoadNGCRImageWithNcer(Ebk ebk) { ColorDepth depth = Char.IntensidadeDeBits == 3 ? ColorDepth.F4BBP : ColorDepth.F8BBP; TypeSprite typeSprite = new TypeSprite() { Oams = ebk.Oams, TileBoundary = (int)ArquivoNcer.Cebk.TileBoundary }; TileMode tileMode = Char.FlagDeDimensao == 0 ? TileMode.Tiled : TileMode.NotTiled; ConvertedImage = ImageConverter.SpriteToBitmap(Char.Tiles, ArquivoNclr.Pltt.Paleta, typeSprite, tileMode, depth); }
public Header( Vector2Int frameSize, ColorDepth colorDepth, int frameCount, byte transparentColorIndex) { FrameSize = frameSize; ColorDepth = colorDepth; FrameCount = frameCount; TransparentColorIndex = transparentColorIndex; }
public Palette(ColorAttributes colorAttributes, ColorDepth depth) { ColorValues = new List <Color>(); ColorAttributes = colorAttributes; _depth = depth; for (var i = 0; i < (int)ColorAttributes; i++) { ColorValues.Add(DefaultPalleteColors[i]); } }
public Palette( IList<byte> bytes, ColorDepth depth, bool useRealTransparentColor = false ) { switch (depth) { case ColorDepth._16bit: Build16BitPalette( bytes, useRealTransparentColor ); break; case ColorDepth._32bit: Build32BitPalette( bytes ); break; } }
public void ImageList_Handle_Get_CreatesHandle(ColorDepth colorDepth) { using var list = new ImageList { ColorDepth = colorDepth }; IntPtr handle = list.Handle; Assert.True(list.HandleCreated); Assert.NotEqual(IntPtr.Zero, handle); Assert.Equal(handle, list.Handle); }
public Color32 GetColor(int arrayPos, ColorDepth depth = ColorDepth.middle) { //types /* * None = -1, * Frame = 0, * Triangle, * Text, */ return(ColorClass.list[arrayPos][(int)depth]); }
private UInt32 CalculateFileSize(UInt32 width, UInt32 height, ColorDepth colorDepth) { if (colorDepth == ColorDepth.TrueColor) { return(CalculateImageSize(width, height, colorDepth) + BMPHeaderSize + InfoHeaderSize); } if (colorDepth == ColorDepth.LowColor) { return(CalculateImageSize(width, height, colorDepth) + BMPHeaderSize + InfoHeaderSize + ColorPaletteSize * 4); } return(0); //default }
public byte[] Render(bool landscape, int DpiX, int DpiY, ColorDepth cd, out string mimeType, out string encoding, out string fileNameExtension, out string[] streams, out Warning[] warnings) { string deviceInfo = "<DeviceInfo>" + "<OutputFormat>TIFF</OutputFormat>" + ((landscape) ? "<PageWidth>297mm</PageWidth><PageHeight>210mm</PageHeight>" : "<PageWidth>210mm</PageWidth><PageHeight>297mm</PageHeight>") + "<ColorDepth>" + (int)cd + "</ColorDepth>" + "<DpiX>" + DpiX + "</DpiX>" + "<DpiY>" + DpiY + "</DpiY>" + "</DeviceInfo>"; return(ctlReportViewer.LocalReport.Render("Image", deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings)); }
public static void SetGraphicsMode(ScreenSize screenSize, ColorDepth colorDepth) { HALVGAScreen.ScreenSize ScrSize = HALVGAScreen.ScreenSize.Size320x200; HALVGAScreen.ColorDepth ClrDepth = HALVGAScreen.ColorDepth.BitDepth8; switch (screenSize) { case ScreenSize.Size320x200: ScrSize = HALVGAScreen.ScreenSize.Size320x200; break; case ScreenSize.Size640x480: ScrSize = HALVGAScreen.ScreenSize.Size640x480; break; case ScreenSize.Size720x480: ScrSize = HALVGAScreen.ScreenSize.Size720x480; break; default: throw new Exception("This situation is not implemented!"); } switch (colorDepth) { case ColorDepth.BitDepth2: ClrDepth = HALVGAScreen.ColorDepth.BitDepth2; break; case ColorDepth.BitDepth4: ClrDepth = HALVGAScreen.ColorDepth.BitDepth4; break; case ColorDepth.BitDepth8: ClrDepth = HALVGAScreen.ColorDepth.BitDepth8; break; case ColorDepth.BitDepth16: ClrDepth = HALVGAScreen.ColorDepth.BitDepth16; break; default: throw new Exception("This situation is not implemented!"); } mScreen.SetGraphicsMode(ScrSize, ClrDepth); }
// Methods internal IcDvImg(byte[] b) { this.colorDepth = ColorDepth.Depth4Bit; this.hIcon = IntPtr.Zero; this.data = new byte[b.Length]; for (int i = 0; i < b.Length; i++) { this.data[i] = b[i]; } BITMAPINFOHEADER bitmapinfoheader = new BITMAPINFOHEADER(this.data); this.size.Width = bitmapinfoheader.biWidth; this.size.Height = bitmapinfoheader.biHeight / 2; switch (bitmapinfoheader.biBitCount) { case 1: case 4: this.colorDepth = ColorDepth.Depth4Bit; break; case 8: this.colorDepth = ColorDepth.Depth8Bit; break; case 0x10: this.colorDepth = ColorDepth.Depth16Bit; break; case 0x18: this.colorDepth = ColorDepth.Depth24Bit; break; case 0x20: this.colorDepth = ColorDepth.Depth32Bit; break; } this.createIcon(); }
/// <summary> /// On get an image request from content item. /// </summary> /// <param name="ColorDepth">THe request color depth.</param> private void OnContentImageRequestColorDepth(ColorDepth ColorDepth) { imageRequestColorDepth = ColorDepth; OnCameraCaptureChanged(); }
/* Constuctor of our struct */ public Mode(int columns, int rows, ColorDepth color_depth) { this.columns = columns; this.rows = rows; this.color_depth = color_depth; }
/// <summary> /// Decompresses an RLE-compressed buffer /// </summary> /// <param name="inputBuffer">The compressed data buffer</param> /// <param name="colorDepth">Color depth of compressed image, can be 8, 16, 24(bits). /// Note 4-bit color depth is not supported </param> /// <param name="width">Width of compressed image, in pixels</param> /// <param name="height">Height of compressed image, in pixels</param> /// <returns>The decompressed data, if inputBuffer contains invalid data or decompression fails, null is /// returned</returns> public static byte[] Decompress(byte[] inputBuffer, ColorDepth colorDepth, int width, int height) { if (inputBuffer == null) { throw new ArgumentNullException("inputBuffer"); } const int dwordSize = sizeof(int); const int bitsPerByte = 8; // Number of bytes used by a pixel int bytesPerPixel = 0; // 15 bits, special case if (colorDepth == ColorDepth.Bits15) { bytesPerPixel = 2; } else { // 8 bits, 16 bits or 24 bits, just divide by bitsPerByte bytesPerPixel = (int)colorDepth / bitsPerByte; } int bytesPerLine = width * bytesPerPixel; // The rowDelta must be DWORD-aligned if (bytesPerLine % dwordSize > 0) { // Remove the remainder, and add a DWORD to make bytesPerLine DWORD-aligned bytesPerLine = bytesPerLine / dwordSize * dwordSize + dwordSize; } // Scan line width int rowDelta = bytesPerLine; // Set dest buffer, this is not accurate size. The decompressed size cannot be decided until // decompression is completed. byte[] destBuffer = new byte[rowDelta * height * bytesPerPixel]; int decompressedLength = 0; byte[] outBuffer = null; try { decompressedLength = InternalRleDecompress( inputBuffer, destBuffer, bytesPerPixel, rowDelta); // Now we know the accurate decompressed size outBuffer = new byte[decompressedLength]; // Copy decompressed data Array.Copy(destBuffer, 0, outBuffer, 0, outBuffer.Length); } catch (IndexOutOfRangeException) { return null; } return outBuffer; }
private void setDeviceImage(Size size, ColorDepth colorDepth) { this.size = size; this.colorDepth = colorDepth; BITMAPINFOHEADER bmInfoHeader = new BITMAPINFOHEADER(size, colorDepth); this.data = new byte[this.MaskImageIndex(bmInfoHeader) + this.MaskImageSize(bmInfoHeader)]; MemoryStream output = new MemoryStream(this.data, 0, this.data.Length, true); BinaryWriter bw = new BinaryWriter(output); bmInfoHeader.Write(bw); switch (this.colorDepth) { case ColorDepth.Depth4Bit: this.write16ColorPalette(bw); break; case ColorDepth.Depth8Bit: this.write256ColorPalette(bw); goto Label_0077; } Label_0077: bw.Close(); }
public void SetGraphicsMode(ScreenSize aSize, ColorDepth aDepth) { switch (aSize) { case ScreenSize.Size320x200: if (aDepth == ColorDepth.BitDepth8) { WriteVGARegisters(g_320x200x8); PixelWidth = 320; PixelHeight = 200; Colors = 256; SetPixel = new SetPixelDelegate(SetPixel320x200x8); GetPixel = new GetPixelDelegate(GetPixel320x200x8); } else if (aDepth == ColorDepth.BitDepth4) { WriteVGARegisters(g_320x200x4); PixelWidth = 320; PixelHeight = 200; Colors = 16; //SetPixel = new SetPixelDelegate(SetPixel320x200x4); //GetPixel = new GetPixelDelegate(GetPixel320x200x4); } else throw new Exception("Unsupported color depth passed for specified screen size"); break; case ScreenSize.Size640x480: if (aDepth == ColorDepth.BitDepth2) { WriteVGARegisters(g_640x480x2); PixelWidth = 640; PixelHeight = 480; Colors = 4; //SetPixel = new SetPixelDelegate(SetPixel640x480x2); //GetPixel = new GetPixelDelegate(GetPixel640x480x2); } else if (aDepth == ColorDepth.BitDepth4) { WriteVGARegisters(g_640x480x4); PixelWidth = 640; PixelHeight = 480; Colors = 16; SetPixel = new SetPixelDelegate(SetPixel640x480x4); GetPixel = new GetPixelDelegate(GetPixel640x480x4); } else throw new Exception("Unsupported color depth passed for specified screen size"); break; case ScreenSize.Size720x480: if (aDepth == ColorDepth.BitDepth4) { WriteVGARegisters(g_720x480x4); PixelWidth = 720; PixelHeight = 480; Colors = 16; SetPixel = new SetPixelDelegate(SetPixel720x480x4); GetPixel = new GetPixelDelegate(GetPixel720x480x4); } else throw new Exception("Unsupported color depth passed for specified screen size"); break; default: throw new Exception("Unknown screen size"); } }
private PixelFormat FormatFromDepth(ColorDepth depth) { switch (depth) { case(ColorDepth.Depth4Bit): return PixelFormat.Format4bppIndexed; case (ColorDepth.Depth8Bit): return PixelFormat.Format8bppIndexed; case (ColorDepth.Depth16Bit): return PixelFormat.Format16bppRgb555; case (ColorDepth.Depth24Bit): return PixelFormat.Format24bppRgb; case (ColorDepth.Depth32Bit): return PixelFormat.Format32bppRgb; default: // Never reached return 0; } }
public BITMAPINFOHEADER( Size size, ColorDepth colorDepth ) { this.biSize = 0; this.biWidth = size.Width; this.biHeight = size.Height * 2; this.biPlanes = 1; this.biCompression = BI_RGB; this.biSizeImage = 0; this.biXPelsPerMeter = 0; this.biYPelsPerMeter = 0; this.biClrUsed = 0; this.biClrImportant = 0; switch (colorDepth) { case ColorDepth.Depth4Bit: this.biBitCount = 4; break; case ColorDepth.Depth8Bit: this.biBitCount = 8; break; case ColorDepth.Depth16Bit: this.biBitCount = 16; break; case ColorDepth.Depth24Bit: this.biBitCount = 24; break; case ColorDepth.Depth32Bit: this.biBitCount = 32; break; default: this.biBitCount = 4; break; } this.biSize = Marshal.SizeOf(this.GetType()); }
private Header CreateHeader(UInt32 width, UInt32 height, ColorDepth colorDepth) { switch(colorDepth){ case ColorDepth.TrueColor: header.MagicNumber = BMPFileType; header.FileSize = CalculateFileSize(width,height, colorDepth); header.Reserved1 = 0;//not used header.Reserved2 = 0;//not used header.OffsetBits = BMPHeaderSize + InfoHeaderSize; header.InfoHeaderSize = InfoHeaderSize; header.ImageWidth = width; header.ImageHeight = height; header.Planes = Planes; header.ColorDepth = colorDepth; header.Compression = NoCompression; header.ImageSize = CalculateImageSize(width,height, colorDepth); header.XPixelPerMeter = 0; //zero when color depth = 24 header.YPixelPerMeter = 0; //zero when color depth = 24 header.NumberOfColors =0; //zero when color depth = 24 header.ImportantColors =0; //zero when color depth = 24 paddingSize = (width*3)%4; //no need to add color palette header.ColorPalette = null; Write(header); break; case ColorDepth.LowColor: header.MagicNumber = BMPFileType; header.FileSize = CalculateFileSize(width,height, colorDepth); header.Reserved1 = 0;//not used header.Reserved2 = 0;//not used header.OffsetBits = BMPHeaderSize + InfoHeaderSize + ColorPaletteSize * 4; header.InfoHeaderSize = InfoHeaderSize; header.ImageWidth = width; header.ImageHeight = height; header.Planes = Planes; header.ColorDepth = colorDepth; header.Compression = NoCompression; header.ImageSize = CalculateImageSize(width,height, colorDepth); header.XPixelPerMeter = 0; //zero when color depth = 8 header.YPixelPerMeter = 0; //zero when color depth = 8 header.NumberOfColors =0; //zero when color depth = 8 header.ImportantColors =0; //zero when color depth = 8 paddingSize = (width)%4; header.ColorPalette = CreateColorPalette(); Write(header); break; case ColorDepth.GrayScaleColor: header.MagicNumber = BMPFileType; header.FileSize = CalculateFileSize(width,height, ColorDepth.LowColor); header.Reserved1 = 0;//not used header.Reserved2 = 0;//not used header.OffsetBits = BMPHeaderSize + InfoHeaderSize + ColorPaletteSize * 4; header.InfoHeaderSize = InfoHeaderSize; header.ImageWidth = width; header.ImageHeight = height; header.Planes = Planes; header.ColorDepth = ColorDepth.LowColor; //will be set to GrayScaleColor when header has been written header.Compression = NoCompression;//no comression header.ImageSize = CalculateImageSize(width,height, ColorDepth.LowColor); header.XPixelPerMeter = 0; //zero when color depth = 8 header.YPixelPerMeter = 0; //zero when color depth = 8 header.NumberOfColors =0; //zero when color depth = 8 header.ImportantColors =0; //zero when color depth = 8 paddingSize = (width)%4; header.ColorPalette = CreateGrayScalePalette(); Write(header); header.ColorDepth = ColorDepth.GrayScaleColor; break; } return header; }
/// <summary> /// Initializes a new instance of the <see cref="MonoBrickFirmware.Graphics.BmpFile"/> class. /// </summary> /// <param name="width">Width of image in pixels.</param> /// <param name="height">Height of image in pixels.</param> /// <param name="colorDepth">Color depth.</param> public BmpImage(UInt32 width, UInt32 height, ColorDepth colorDepth) { stream = new MemoryStream (); CreateHeader (width, height, colorDepth); appendIndexHorizontal = 0; }
private UInt32 CalculateFileSize(UInt32 width, UInt32 height, ColorDepth colorDepth) { if(colorDepth == ColorDepth.TrueColor) { return CalculateImageSize(width, height, colorDepth) + BMPHeaderSize + InfoHeaderSize; } if(colorDepth == ColorDepth.LowColor){ return CalculateImageSize(width, height, colorDepth) + BMPHeaderSize + InfoHeaderSize + ColorPaletteSize * 4; } return 0;//default }
private UInt32 CalculateImageSize(UInt32 width, UInt32 height, ColorDepth colorDepth) { uint temp = 0; UInt16 colorDepthAsUInt16 = (UInt16) colorDepth; if(Convert.ToBoolean(( colorDepthAsUInt16 * width)%32) ){ temp =(uint) (colorDepthAsUInt16 * width)/32+1; } else{ temp = (uint) (colorDepthAsUInt16 * width) / 32; } return 4*temp*height; }
public Image Obtener_ImagenARJ(long posicion, ColorDepth tipo) { BinaryReader rdr = new BinaryReader(File.OpenRead(archivo)); rdr.BaseStream.Position = posicion; Image imagen = new Image(); imagen.tipo = tipo; imagen.width = rdr.ReadUInt16(); imagen.height = rdr.ReadUInt16(); imagen.imgs = rdr.ReadUInt16(); imagen.segmentos = new Parte[imagen.imgs]; imagen.length = (uint)imagen.width * imagen.height; rdr.BaseStream.Seek(2, SeekOrigin.Current); for (int i = 0; i < imagen.imgs; i++) { imagen.segmentos[i] = Obtener_ParteARJ(rdr.BaseStream.Position, imagen.tipo); rdr.BaseStream.Seek(imagen.segmentos[i].length + 12, SeekOrigin.Current); } rdr.Close(); return imagen; }
public Parte Obtener_ParteARJ(long posicion, ColorDepth tipo) { Parte parte = new Parte(); BinaryReader rdr = new BinaryReader(File.OpenRead(archivo)); rdr.BaseStream.Position = posicion; parte.offSet = (ulong)posicion; ushort width = rdr.ReadUInt16(); ushort height = rdr.ReadUInt16(); parte.posX = (ushort)rdr.ReadUInt16(); parte.posY = (ushort)rdr.ReadUInt16(); parte.width = (ushort)Math.Pow(2, 3 + rdr.ReadUInt16()); parte.height = (ushort)Math.Pow(2, 3 + rdr.ReadUInt16()); if (tipo == ColorDepth.Depth8Bit) { parte.length = (uint)parte.width * parte.height; parte.datos = rdr.ReadBytes((int)parte.length); } else { parte.length = (uint)(parte.width * parte.height) / 2; parte.datos = Ekona.Helper.BitsConverter.BytesToBit4(rdr.ReadBytes((int)parte.length)); } rdr.Close(); return parte; }
private void ResetColorDepth() { ColorDepth = ColorDepth.Depth8Bit; }
public static byte[] ColorToBytes(Color c, byte alphaByte, ColorDepth depth = ColorDepth._16bit) { if (depth == ColorDepth._16bit) { byte r = (byte)((c.R & 0xF8) >> 3); byte g = (byte)((c.G & 0xF8) >> 3); byte b = (byte)((c.B & 0xF8) >> 3); byte[] result = new byte[2]; result[0] = (byte)(((g & 0x07) << 5) | r); result[1] = (byte)((b << 2) | ((g & 0x18) >> 3) | (alphaByte & 0x80)); return result; } else if (depth == ColorDepth._32bit) { return ColorToBytes_32Bit(c, alphaByte); } else { throw new System.ArgumentException("Color depth must be either 16 or 32 bit."); } }
public Display(double sizeInInches, ColorDepth colordepth) { Size = sizeInInches; Color = colordepth; }
public Display(double sizeInInches, ColorDepth colorDepth) { this.size = sizeInInches; this.colors = colorDepth; }
public IcDvImg(Icon icon) { this.colorDepth = ColorDepth.Depth4Bit; this.hIcon = IntPtr.Zero; }
public GraphicsMode(Resolution resolution, ColorDepth depth) { this.Resolution = resolution; this.ColorDepth = depth; }