public static int[,] GetPixelArray(int width, int height, Bitmap b, AdvImageSection.GetPixelMode mode) { bool stretch = mode != AdvImageSection.GetPixelMode.Raw8Bit; uint maxval = 256; if (stretch) { if (mode == AdvImageSection.GetPixelMode.StretchTo12Bit) maxval = 4096; else if (mode == AdvImageSection.GetPixelMode.StretchTo16Bit) maxval = ushort.MaxValue; } Random rnd = new Random((int)DateTime.Now.Ticks); int[,] rv = new int[height, width]; if (b != null) { // GDI+ still lies to us - the return format is BGR, NOT RGB. BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); try { int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; unsafe { byte* p = (byte*)(void*)Scan0; int nOffset = stride - b.Width * 3; for (int y = 0; y < b.Height; ++y) { for (int x = 0; x < b.Width; ++x) { ushort red = p[2]; if (stretch) { uint stretchedVal = Math.Max(0, Math.Min(maxval, (uint)(red * maxval / 256.0 + (2 * (rnd.NextDouble() - 0.5) * maxval / 256.0)))); red = (ushort)stretchedVal; } rv[y, x] = red; p += 3; } p += nOffset; } } } finally { b.UnlockBits(bmData); } } return rv; }
public AdvImageLayout(AdvImageSection imageSection, byte layoutId, uint width, uint height, BinaryReader reader) { m_ImageSection = imageSection; LayoutId = layoutId; Width = width; Height = height; byte version = reader.ReadByte(); if (version >= 1) { BitsPerPixel = reader.ReadByte(); byte propCnt = reader.ReadByte(); for (int i = 0; i < propCnt; i++) { string propName = reader.ReadAsciiString256(); string propValue = reader.ReadAsciiString256(); ImageSerializationProperties.Add(propName, propValue); } } InitSerializationProperties(); }
private AstroDigitalVideoStream(string fileName) { m_FileName = fileName; m_AdvFile = AdvFile.OpenFile(fileName); m_ImageSection = m_AdvFile.ImageSection; CheckAdvFileFormatInternal(); }