コード例 #1
0
 public H264VideoEncoder()
 {
     _handle           = VsNetVideoEncoderSdk.VideoEncoderEx_AllocInstance();
     _bitmapInfoHeader = new BitmapInfoHeader();
 }
コード例 #2
0
 internal static BitmapInfoHeader InitSize()
 {
     BitmapInfoHeader @this = new BitmapInfoHeader();
     @this.biSize = (uint)Marshal.SizeOf(@this);
     return @this;
 }
コード例 #3
0
 public static extern int freenect_set_depth_mode( IntPtr device, BitmapInfoHeader infoHeader );
コード例 #4
0
ファイル: VfwApi.cs プロジェクト: bobahml/SharpAvi
 public static extern int ICCompress(IntPtr handle, int inFlags,
                                      ref BitmapInfoHeader outHeader, IntPtr encodedData,
                                      ref BitmapInfoHeader inHeader, IntPtr frameData,
                                      out int chunkID, out int outFlags, int frameNumber,
                                      int requestedFrameSize, int requestedQuality,
                                      IntPtr prevHeaderPtr, IntPtr prevFrameData);
コード例 #5
0
ファイル: MainForm.cs プロジェクト: coolsula/vidplaycorder
        private void snapImage()
        {
            if (windowlessCtrl != null)
            {
                IntPtr currentImage = IntPtr.Zero;
                Bitmap bmp = null;

                try
                {
                    int hr = windowlessCtrl.GetCurrentImage(out currentImage);
                    DsError.ThrowExceptionForHR(hr);

                    if (currentImage != IntPtr.Zero)
                    {
                        BitmapInfoHeader structure = new BitmapInfoHeader();
                        Marshal.PtrToStructure(currentImage, structure);

                        bmp = new Bitmap(structure.Width, structure.Height, (structure.BitCount / 8) * structure.Width, System.Drawing.Imaging.PixelFormat.Format32bppArgb, currentImage);
                        bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

                        if (saveFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            bmp.Save(saveFileDialog.FileName.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                    }
                }
                catch (Exception anyException)
                {
                    MessageBox.Show("Failed getting image: " + anyException.Message);
                }
                finally
                {
                    if (bmp != null)
                    {
                        bmp.Dispose();
                    }

                    Marshal.FreeCoTaskMem(currentImage);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Set the media type on the IGenericSampleConfig
        /// </summary>
        public override void SetMediaType(IGenericSampleConfig psc)
        {
            BitmapInfoHeader bmi = new BitmapInfoHeader();

            // Build a BitmapInfo struct using the parms from the file
            bmi.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));
            bmi.Width = WIDTH;
            bmi.Height = HEIGHT * -1;
            bmi.Planes = 1;
            bmi.BitCount = BPP;
            bmi.Compression = 0;
            bmi.ImageSize = (bmi.BitCount / 8) * bmi.Width * bmi.Height;
            bmi.XPelsPerMeter = 0;
            bmi.YPelsPerMeter = 0;
            bmi.ClrUsed = 0;
            bmi.ClrImportant = 0;

            int hr = psc.SetMediaTypeFromBitmap(bmi, m_FPS);
            DsError.ThrowExceptionForHR(hr);
        }
コード例 #7
0
ファイル: Icon.Unix.cs プロジェクト: walneyjsilva/corefx
        private void SaveBitmapAsIcon(BinaryWriter writer)
        {
            writer.Write((ushort)0);    // idReserved must be 0
            writer.Write((ushort)1);    // idType must be 1
            writer.Write((ushort)1);    // only one icon

            // when transformed into a bitmap only a single image exists
            IconDirEntry ide = new IconDirEntry();

            ide.width       = (byte)bitmap.Width;
            ide.height      = (byte)bitmap.Height;
            ide.colorCount  = 0; // 32 bbp == 0, for palette size
            ide.reserved    = 0; // always 0
            ide.planes      = 0;
            ide.bitCount    = 32;
            ide.imageOffset = 22;   // 22 is the first icon position (for single icon files)

            BitmapInfoHeader bih = new BitmapInfoHeader();

            bih.biSize          = (uint)Marshal.SizeOf(typeof(BitmapInfoHeader));
            bih.biWidth         = bitmap.Width;
            bih.biHeight        = 2 * bitmap.Height; // include both XOR and AND images
            bih.biPlanes        = 1;
            bih.biBitCount      = 32;
            bih.biCompression   = 0;
            bih.biSizeImage     = 0;
            bih.biXPelsPerMeter = 0;
            bih.biYPelsPerMeter = 0;
            bih.biClrUsed       = 0;
            bih.biClrImportant  = 0;

            IconImage ii = new IconImage();

            ii.iconHeader = bih;
            ii.iconColors = Array.Empty <uint>();    // no palette
            int xor_size = (((bih.biBitCount * bitmap.Width + 31) & ~31) >> 3) * bitmap.Height;

            ii.iconXOR = new byte[xor_size];
            int p = 0;

            for (int y = bitmap.Height - 1; y >= 0; y--)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    Color c = bitmap.GetPixel(x, y);
                    ii.iconXOR[p++] = c.B;
                    ii.iconXOR[p++] = c.G;
                    ii.iconXOR[p++] = c.R;
                    ii.iconXOR[p++] = c.A;
                }
            }
            int and_line_size = (((Width + 31) & ~31) >> 3);    // must be a multiple of 4 bytes
            int and_size      = and_line_size * bitmap.Height;

            ii.iconAND = new byte[and_size];

            ide.bytesInRes = (uint)(bih.biSize + xor_size + and_size);

            SaveIconDirEntry(writer, ide, uint.MaxValue);
            SaveIconImage(writer, ii);
        }
コード例 #8
0
ファイル: Icon.cs プロジェクト: kumpera/mono
		private void InitFromStreamWithSize (Stream stream, int width, int height)
		{
			//read the icon header
			if (stream == null || stream.Length == 0)
				throw new System.ArgumentException ("The argument 'stream' must be a picture that can be used as a Icon", "stream");
			
			BinaryReader reader = new BinaryReader (stream);

			//iconDir = new IconDir ();
			iconDir.idReserved = reader.ReadUInt16();
			if (iconDir.idReserved != 0) //must be 0
				throw new System.ArgumentException ("Invalid Argument", "stream");
			
			iconDir.idType = reader.ReadUInt16();
			if (iconDir.idType != 1) //must be 1
				throw new System.ArgumentException ("Invalid Argument", "stream");

			ushort dirEntryCount = reader.ReadUInt16();
			ArrayList entries = new ArrayList (dirEntryCount);
			bool sizeObtained = false;
			// now read in the IconDirEntry structures
			for (int i = 0; i < dirEntryCount; i++) {
				IconDirEntry ide;
				ide.width = reader.ReadByte ();
				ide.height = reader.ReadByte ();
				ide.colorCount = reader.ReadByte ();
				ide.reserved = reader.ReadByte ();
				ide.planes = reader.ReadUInt16 ();
				ide.bitCount = reader.ReadUInt16 ();
				ide.bytesInRes = reader.ReadUInt32 ();
				ide.imageOffset = reader.ReadUInt32 ();
#if false
Console.WriteLine ("Entry: {0}", i);
Console.WriteLine ("\tide.width: {0}", ide.width);
Console.WriteLine ("\tide.height: {0}", ide.height);
Console.WriteLine ("\tide.colorCount: {0}", ide.colorCount);
Console.WriteLine ("\tide.reserved: {0}", ide.reserved);
Console.WriteLine ("\tide.planes: {0}", ide.planes);
Console.WriteLine ("\tide.bitCount: {0}", ide.bitCount);
Console.WriteLine ("\tide.bytesInRes: {0}", ide.bytesInRes);
Console.WriteLine ("\tide.imageOffset: {0}", ide.imageOffset);
#endif

				// 256x256 icons are decoded as 0x0 (width and height are encoded as BYTE)
				// and we ignore them just like MS does (at least up to fx 2.0)
				if ((ide.width == 0) && (ide.height == 0))
					continue;

				int index = entries.Add (ide);

				//is this is the best fit??
				if (!sizeObtained) {
					if ((ide.height == height) || (ide.width == width)) {
						this.id = (ushort) index;
						sizeObtained = true;
						this.iconSize.Height = ide.height;
						this.iconSize.Width = ide.width;
					}
				}
			}

			// Vista 256x256 icons points directly to a PNG bitmap
			dirEntryCount = (ushort) entries.Count;
			if (dirEntryCount == 0)
				throw new Win32Exception (0, "No valid icon entry were found.");

			iconDir.idCount = dirEntryCount;
			imageData = new IconImage [dirEntryCount];
			iconDir.idEntries = new IconDirEntry [dirEntryCount];
			entries.CopyTo (iconDir.idEntries);

			//if we havent found the best match, return the one with the
			//largest size. Is this approach correct??
			if (!sizeObtained){
				uint largestSize = 0;
				for (int j=0; j<dirEntryCount; j++){
					if (iconDir.idEntries [j].bytesInRes >= largestSize)	{
						largestSize = iconDir.idEntries [j].bytesInRes;
						this.id = (ushort) j;
						this.iconSize.Height = iconDir.idEntries [j].height;
						this.iconSize.Width = iconDir.idEntries [j].width;
					}
				}
			}
			
			//now read in the icon data
			for (int j = 0; j<dirEntryCount; j++)
			{
				IconImage iidata = new IconImage();
				BitmapInfoHeader bih = new BitmapInfoHeader();
				stream.Seek (iconDir.idEntries [j].imageOffset, SeekOrigin.Begin);
				byte [] buffer = new byte [iconDir.idEntries [j].bytesInRes];
				stream.Read (buffer, 0, buffer.Length);
				BinaryReader bihReader = new BinaryReader (new MemoryStream(buffer));
				bih.biSize = bihReader.ReadUInt32 ();
				bih.biWidth = bihReader.ReadInt32 ();
				bih.biHeight = bihReader.ReadInt32 ();
				bih.biPlanes = bihReader.ReadUInt16 ();
				bih.biBitCount = bihReader.ReadUInt16 ();
				bih.biCompression = bihReader.ReadUInt32 ();
				bih.biSizeImage = bihReader.ReadUInt32 ();
				bih.biXPelsPerMeter = bihReader.ReadInt32 ();
				bih.biYPelsPerMeter = bihReader.ReadInt32 ();
				bih.biClrUsed = bihReader.ReadUInt32 ();
				bih.biClrImportant = bihReader.ReadUInt32 ();
#if false
Console.WriteLine ("Entry: {0}", j);
Console.WriteLine ("\tbih.biSize: {0}", bih.biSize);
Console.WriteLine ("\tbih.biWidth: {0}", bih.biWidth);
Console.WriteLine ("\tbih.biHeight: {0}", bih.biHeight);
Console.WriteLine ("\tbih.biPlanes: {0}", bih.biPlanes);
Console.WriteLine ("\tbih.biBitCount: {0}", bih.biBitCount);
Console.WriteLine ("\tbih.biCompression: {0}", bih.biCompression);
Console.WriteLine ("\tbih.biSizeImage: {0}", bih.biSizeImage);
Console.WriteLine ("\tbih.biXPelsPerMeter: {0}", bih.biXPelsPerMeter);
Console.WriteLine ("\tbih.biYPelsPerMeter: {0}", bih.biYPelsPerMeter);
Console.WriteLine ("\tbih.biClrUsed: {0}", bih.biClrUsed);
Console.WriteLine ("\tbih.biClrImportant: {0}", bih.biClrImportant);
#endif
				iidata.iconHeader = bih;
				//Read the number of colors used and corresponding memory occupied by
				//color table. Fill this memory chunk into rgbquad[]
				int numColors;
				switch (bih.biBitCount){
					case 1: numColors = 2;
						break;
					case 4: numColors = 16;
						break;
					case 8: numColors = 256;
						break;
					default: numColors = 0;
						break;
				}
				
				iidata.iconColors = new uint [numColors];
				for (int i=0; i<numColors; i++)
					iidata.iconColors [i] = bihReader.ReadUInt32 ();

				//XOR mask is immediately after ColorTable and its size is 
				//icon height* no. of bytes per line
				
				//icon height is half of BITMAPINFOHEADER.biHeight, since it contains
				//both XOR as well as AND mask bytes
				int iconHeight = bih.biHeight/2;
				
				//bytes per line should should be uint aligned
				int numBytesPerLine = ((((bih.biWidth * bih.biPlanes * bih.biBitCount)+ 31)>>5)<<2);
				
				//Determine the XOR array Size
				int xorSize = numBytesPerLine * iconHeight;
				iidata.iconXOR = new byte [xorSize];
				int nread = bihReader.Read (iidata.iconXOR, 0, xorSize);
				if (nread != xorSize) {
					string msg = Locale.GetText ("{0} data length expected {1}, read {2}", "XOR", xorSize, nread);
					throw new ArgumentException (msg, "stream");
				}
				
				//Determine the AND array size
				numBytesPerLine = (int)((((bih.biWidth) + 31) & ~31) >> 3);
				int andSize = numBytesPerLine * iconHeight;
				iidata.iconAND = new byte [andSize];
				nread = bihReader.Read (iidata.iconAND, 0, andSize);
				if (nread != andSize) {
					string msg = Locale.GetText ("{0} data length expected {1}, read {2}", "AND", andSize, nread);
					throw new ArgumentException (msg, "stream");
				}
				
				imageData [j] = iidata;
				bihReader.Close();
			}			

			reader.Close();
		}
コード例 #9
0
        internal Bitmap BuildBitmapOnWin32()
        {
            Bitmap bmp;

            if (imageData == null)
            {
                return(new Bitmap(32, 32));
            }

            IconImage        ii  = (IconImage)imageData [id];
            BitmapInfoHeader bih = ii.iconHeader;
            int biHeight         = bih.biHeight / 2;

            int ncolors = (int)bih.biClrUsed;

            if ((ncolors == 0) && (bih.biBitCount < 24))
            {
                ncolors = (int)(1 << bih.biBitCount);
            }

            switch (bih.biBitCount)
            {
            case 1:
                bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format1bppIndexed);
                break;

            case 4:
                bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format4bppIndexed);
                break;

            case 8:
                bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format8bppIndexed);
                break;

            case 24:
                bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format24bppRgb);
                break;

            case 32:
                bmp = new Bitmap(bih.biWidth, biHeight, PixelFormat.Format32bppArgb);
                break;

            default:
                string msg = Locale.GetText("Unexpected number of bits: {0}", bih.biBitCount);
                throw new Exception(msg);
            }

            if (bih.biBitCount < 24)
            {
                ColorPalette pal = bmp.Palette;                 // Managed palette

                for (int i = 0; i < ii.iconColors.Length; i++)
                {
                    pal.Entries[i] = Color.FromArgb((int)ii.iconColors[i] | unchecked ((int)0xff000000));
                }
                bmp.Palette = pal;
            }

            int        bytesPerLine = (int)((((bih.biWidth * bih.biBitCount) + 31) & ~31) >> 3);
            BitmapData bits         = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);

            for (int y = 0; y < biHeight; y++)
            {
                Marshal.Copy(ii.iconXOR, bytesPerLine * y,
                             (IntPtr)(bits.Scan0.ToInt64() + bits.Stride * (biHeight - 1 - y)), bytesPerLine);
            }

            bmp.UnlockBits(bits);

            bmp = new Bitmap(bmp);              // This makes a 32bpp image out of an indexed one

            // Apply the mask to make properly transparent
            bytesPerLine = (int)((((bih.biWidth) + 31) & ~31) >> 3);
            for (int y = 0; y < biHeight; y++)
            {
                for (int x = 0; x < bih.biWidth / 8; x++)
                {
                    for (int bit = 7; bit >= 0; bit--)
                    {
                        if (((ii.iconAND[y * bytesPerLine + x] >> bit) & 1) != 0)
                        {
                            bmp.SetPixel(x * 8 + 7 - bit, biHeight - y - 1, Color.Transparent);
                        }
                    }
                }
            }

            return(bmp);
        }
コード例 #10
0
        private void InitFromStreamWithSize(Stream stream, int width, int height)
        {
            //read the icon header
            if (stream == null || stream.Length == 0)
            {
                throw new System.ArgumentException("The argument 'stream' must be a picture that can be used as a Icon", "stream");
            }

            BinaryReader reader = new BinaryReader(stream);

            //iconDir = new IconDir ();
            iconDir.idReserved = reader.ReadUInt16();
            if (iconDir.idReserved != 0)             //must be 0
            {
                throw new System.ArgumentException("Invalid Argument", "stream");
            }

            iconDir.idType = reader.ReadUInt16();
            if (iconDir.idType != 1)             //must be 1
            {
                throw new System.ArgumentException("Invalid Argument", "stream");
            }

            ushort dirEntryCount = reader.ReadUInt16();

            imageData         = new ImageData [dirEntryCount];
            iconDir.idCount   = dirEntryCount;
            iconDir.idEntries = new IconDirEntry [dirEntryCount];
            bool sizeObtained = false;

            // now read in the IconDirEntry structures
            for (int i = 0; i < dirEntryCount; i++)
            {
                IconDirEntry ide;
                ide.width       = reader.ReadByte();
                ide.height      = reader.ReadByte();
                ide.colorCount  = reader.ReadByte();
                ide.reserved    = reader.ReadByte();
                ide.planes      = reader.ReadUInt16();
                ide.bitCount    = reader.ReadUInt16();
                ide.bytesInRes  = reader.ReadUInt32();
                ide.imageOffset = reader.ReadUInt32();
#if false
                Console.WriteLine("Entry: {0}", i);
                Console.WriteLine("\tide.width: {0}", ide.width);
                Console.WriteLine("\tide.height: {0}", ide.height);
                Console.WriteLine("\tide.colorCount: {0}", ide.colorCount);
                Console.WriteLine("\tide.reserved: {0}", ide.reserved);
                Console.WriteLine("\tide.planes: {0}", ide.planes);
                Console.WriteLine("\tide.bitCount: {0}", ide.bitCount);
                Console.WriteLine("\tide.bytesInRes: {0}", ide.bytesInRes);
                Console.WriteLine("\tide.imageOffset: {0}", ide.imageOffset);
#endif
                // Vista 256x256 icons points directly to a PNG bitmap
                // 256x256 icons are decoded as 0x0 (width and height are encoded as BYTE)
                // and we ignore them just like MS does (at least up to fx 2.0)
                // Added: storing data so it can be saved back
                if ((ide.width == 0) && (ide.height == 0))
                {
                    ide.ignore = true;
                }
                else
                {
                    ide.ignore = false;
                }

                iconDir.idEntries [i] = ide;

                //is this is the best fit??
                if (!sizeObtained)
                {
                    if (((ide.height == height) || (ide.width == width)) && !ide.ignore)
                    {
                        this.id              = (ushort)i;
                        sizeObtained         = true;
                        this.iconSize.Height = ide.height;
                        this.iconSize.Width  = ide.width;
                    }
                }
            }

            // throw error if no valid entries found
            int valid = 0;
            for (int i = 0; i < dirEntryCount; i++)
            {
                if (!(iconDir.idEntries [i].ignore))
                {
                    valid++;
                }
            }

            if (valid == 0)
            {
                throw new Win32Exception(0, "No valid icon entry were found.");
            }

            // if we havent found the best match, return the one with the
            // largest size. Is this approach correct??
            if (!sizeObtained)
            {
                uint largestSize = 0;
                for (int j = 0; j < dirEntryCount; j++)
                {
                    if (iconDir.idEntries [j].bytesInRes >= largestSize && !iconDir.idEntries [j].ignore)
                    {
                        largestSize          = iconDir.idEntries [j].bytesInRes;
                        this.id              = (ushort)j;
                        this.iconSize.Height = iconDir.idEntries [j].height;
                        this.iconSize.Width  = iconDir.idEntries [j].width;
                    }
                }
            }

            //now read in the icon data
            for (int j = 0; j < dirEntryCount; j++)
            {
                // process ignored into IconDump
                if (iconDir.idEntries [j].ignore)
                {
                    IconDump id = new IconDump();
                    stream.Seek(iconDir.idEntries [j].imageOffset, SeekOrigin.Begin);
                    id.data = new byte [iconDir.idEntries [j].bytesInRes];
                    stream.Read(id.data, 0, id.data.Length);
                    imageData [j] = id;
                    continue;
                }
                // standard image
                IconImage        iidata = new IconImage();
                BitmapInfoHeader bih    = new BitmapInfoHeader();
                stream.Seek(iconDir.idEntries [j].imageOffset, SeekOrigin.Begin);
                byte [] buffer = new byte [iconDir.idEntries [j].bytesInRes];
                stream.Read(buffer, 0, buffer.Length);
                BinaryReader bihReader = new BinaryReader(new MemoryStream(buffer));
                bih.biSize          = bihReader.ReadUInt32();
                bih.biWidth         = bihReader.ReadInt32();
                bih.biHeight        = bihReader.ReadInt32();
                bih.biPlanes        = bihReader.ReadUInt16();
                bih.biBitCount      = bihReader.ReadUInt16();
                bih.biCompression   = bihReader.ReadUInt32();
                bih.biSizeImage     = bihReader.ReadUInt32();
                bih.biXPelsPerMeter = bihReader.ReadInt32();
                bih.biYPelsPerMeter = bihReader.ReadInt32();
                bih.biClrUsed       = bihReader.ReadUInt32();
                bih.biClrImportant  = bihReader.ReadUInt32();
#if false
                Console.WriteLine("Entry: {0}", j);
                Console.WriteLine("\tbih.biSize: {0}", bih.biSize);
                Console.WriteLine("\tbih.biWidth: {0}", bih.biWidth);
                Console.WriteLine("\tbih.biHeight: {0}", bih.biHeight);
                Console.WriteLine("\tbih.biPlanes: {0}", bih.biPlanes);
                Console.WriteLine("\tbih.biBitCount: {0}", bih.biBitCount);
                Console.WriteLine("\tbih.biCompression: {0}", bih.biCompression);
                Console.WriteLine("\tbih.biSizeImage: {0}", bih.biSizeImage);
                Console.WriteLine("\tbih.biXPelsPerMeter: {0}", bih.biXPelsPerMeter);
                Console.WriteLine("\tbih.biYPelsPerMeter: {0}", bih.biYPelsPerMeter);
                Console.WriteLine("\tbih.biClrUsed: {0}", bih.biClrUsed);
                Console.WriteLine("\tbih.biClrImportant: {0}", bih.biClrImportant);
#endif
                iidata.iconHeader = bih;
                //Read the number of colors used and corresponding memory occupied by
                //color table. Fill this memory chunk into rgbquad[]
                int numColors;
                switch (bih.biBitCount)
                {
                case 1: numColors = 2;
                    break;

                case 4: numColors = 16;
                    break;

                case 8: numColors = 256;
                    break;

                default: numColors = 0;
                    break;
                }

                iidata.iconColors = new uint [numColors];
                for (int i = 0; i < numColors; i++)
                {
                    iidata.iconColors [i] = bihReader.ReadUInt32();
                }

                //XOR mask is immediately after ColorTable and its size is
                //icon height* no. of bytes per line

                //icon height is half of BITMAPINFOHEADER.biHeight, since it contains
                //both XOR as well as AND mask bytes
                int iconHeight = bih.biHeight / 2;

                //bytes per line should should be uint aligned
                int numBytesPerLine = ((((bih.biWidth * bih.biPlanes * bih.biBitCount) + 31) >> 5) << 2);

                //Determine the XOR array Size
                int xorSize = numBytesPerLine * iconHeight;
                iidata.iconXOR = new byte [xorSize];
                int nread = bihReader.Read(iidata.iconXOR, 0, xorSize);
                if (nread != xorSize)
                {
                    string msg = Locale.GetText("{0} data length expected {1}, read {2}", "XOR", xorSize, nread);
                    throw new ArgumentException(msg, "stream");
                }

                //Determine the AND array size
                numBytesPerLine = (int)((((bih.biWidth) + 31) & ~31) >> 3);
                int andSize = numBytesPerLine * iconHeight;
                iidata.iconAND = new byte [andSize];
                nread          = bihReader.Read(iidata.iconAND, 0, andSize);
                if (nread != andSize)
                {
                    string msg = Locale.GetText("{0} data length expected {1}, read {2}", "AND", andSize, nread);
                    throw new ArgumentException(msg, "stream");
                }

                imageData [j] = iidata;
                bihReader.Dispose();
            }

            reader.Dispose();
        }
コード例 #11
0
        private void InitFromStreamWithSize(Stream stream, int width, int height)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (stream.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidPictureType, "picture", nameof(stream)));
            }

            bool   sizeObtained = false;
            ushort dirEntryCount;

            // Read the icon header
            using (var reader = new BinaryReader(stream))
            {
                iconDir.idReserved = reader.ReadUInt16();
                if (iconDir.idReserved != 0) //must be 0
                {
                    throw new ArgumentException(SR.Format(SR.InvalidPictureType, "picture", nameof(stream)));
                }

                iconDir.idType = reader.ReadUInt16();
                if (iconDir.idType != 1) //must be 1
                {
                    throw new ArgumentException(SR.Format(SR.InvalidPictureType, "picture", nameof(stream)));
                }

                dirEntryCount     = reader.ReadUInt16();
                imageData         = new ImageData[dirEntryCount];
                iconDir.idCount   = dirEntryCount;
                iconDir.idEntries = new IconDirEntry[dirEntryCount];
                // Now read in the IconDirEntry structures
                for (int i = 0; i < dirEntryCount; i++)
                {
                    var ide = new IconDirEntry
                    {
                        width       = reader.ReadByte(),
                        height      = reader.ReadByte(),
                        colorCount  = reader.ReadByte(),
                        reserved    = reader.ReadByte(),
                        planes      = reader.ReadUInt16(),
                        bitCount    = reader.ReadUInt16(),
                        bytesInRes  = reader.ReadUInt32(),
                        imageOffset = reader.ReadUInt32()
                    };

                    // Vista 256x256 icons points directly to a PNG bitmap
                    // 256x256 icons are decoded as 0x0 (width and height are encoded as BYTE)
                    // We mark them as png and later on we just store the raw bytes to be able to save to a file.
                    ide.png = (ide.width == 0) && (ide.height == 0);

                    iconDir.idEntries[i] = ide;

                    if (!sizeObtained)
                    {
                        if (((ide.height == height) || (ide.width == width)) && !ide.png)
                        {
                            this.id              = (ushort)i;
                            sizeObtained         = true;
                            this.iconSize.Height = ide.height;
                            this.iconSize.Width  = ide.width;
                        }
                    }
                }

                // If we havent found the best match, return the one with the largest size.
                if (!sizeObtained)
                {
                    uint largestSize = 0;
                    for (int j = 0; j < dirEntryCount; j++)
                    {
                        if (iconDir.idEntries[j].bytesInRes >= largestSize && !iconDir.idEntries[j].png)
                        {
                            largestSize          = iconDir.idEntries[j].bytesInRes;
                            this.id              = (ushort)j;
                            this.iconSize.Height = iconDir.idEntries[j].height;
                            this.iconSize.Width  = iconDir.idEntries[j].width;
                        }
                    }
                }

                // Now read in the icon data
                bool valid = false;
                for (int j = 0; j < dirEntryCount; j++)
                {
                    stream.Seek(iconDir.idEntries[j].imageOffset, SeekOrigin.Begin);
                    byte[] buffer = new byte[iconDir.idEntries[j].bytesInRes];
                    stream.Read(buffer, 0, buffer.Length);
                    using (var bihReader = new BinaryReader(new MemoryStream(buffer)))
                    {
                        uint headerSize  = bihReader.ReadUInt32();
                        int  headerWidth = bihReader.ReadInt32();

                        // Process PNG images into IconDump
                        if (iconDir.idEntries[j].png || (headerSize == PNGSignature1 && headerWidth == (int)PNGSignature2))
                        {
                            IconDump id = new IconDump();
                            id.data                  = buffer;
                            imageData[j]             = id;
                            iconDir.idEntries[j].png = true;
                            continue;
                        }

                        // We found a valid icon BMP entry.
                        valid = true;

                        var bih = new BitmapInfoHeader
                        {
                            biSize          = headerSize,
                            biWidth         = headerWidth,
                            biHeight        = bihReader.ReadInt32(),
                            biPlanes        = bihReader.ReadUInt16(),
                            biBitCount      = bihReader.ReadUInt16(),
                            biCompression   = bihReader.ReadUInt32(),
                            biSizeImage     = bihReader.ReadUInt32(),
                            biXPelsPerMeter = bihReader.ReadInt32(),
                            biYPelsPerMeter = bihReader.ReadInt32(),
                            biClrUsed       = bihReader.ReadUInt32(),
                            biClrImportant  = bihReader.ReadUInt32()
                        };
                        var iidata = new IconImage
                        {
                            iconHeader = bih
                        };
                        // Read the number of colors used and corresponding memory occupied by
                        // color table. Fill this memory chunk into rgbquad[]
                        int numColors;
                        switch (bih.biBitCount)
                        {
                        case 1:
                            numColors = 2;
                            break;

                        case 4:
                            numColors = 16;
                            break;

                        case 8:
                            numColors = 256;
                            break;

                        default:
                            numColors = 0;
                            break;
                        }

                        iidata.iconColors = new uint[numColors];
                        for (int i = 0; i < numColors; i++)
                        {
                            iidata.iconColors[i] = bihReader.ReadUInt32();
                        }

                        //XOR mask is immediately after ColorTable and its size is
                        //icon height* no. of bytes per line

                        //icon height is half of BITMAPINFOHEADER.biHeight, since it contains
                        //both XOR as well as AND mask bytes
                        int iconHeight = bih.biHeight / 2;

                        //bytes per line should should be uint aligned
                        int numBytesPerLine = checked ((((bih.biWidth * bih.biPlanes * bih.biBitCount) + 31) >> 5) << 2);

                        //Determine the XOR array Size
                        int xorSize = checked (numBytesPerLine * iconHeight);
                        iidata.iconXOR = new byte[xorSize];
                        int nread = bihReader.Read(iidata.iconXOR, 0, xorSize);
                        if (nread != xorSize)
                        {
                            throw new ArgumentException(SR.Format(SR.IconInvalidMaskLength, "XOR", xorSize, nread), nameof(stream));
                        }

                        //Determine the AND array size
                        numBytesPerLine = checked ((((bih.biWidth) + 31) & ~31) >> 3);
                        int andSize = checked (numBytesPerLine * iconHeight);
                        iidata.iconAND = new byte[andSize];
                        nread          = bihReader.Read(iidata.iconAND, 0, andSize);
                        if (nread != andSize)
                        {
                            throw new ArgumentException(SR.Format(SR.IconInvalidMaskLength, "AND", andSize, nread), nameof(stream));
                        }

                        imageData[j] = iidata;
                    }
                }

                // Throw error if no valid entries found
                if (!valid)
                {
                    throw new Win32Exception(SafeNativeMethods.ERROR_INVALID_PARAMETER, SR.Format(SR.InvalidPictureType, "picture", nameof(stream)));
                }
            }
        }
コード例 #12
0
 internal static extern int AVIStreamReadFormat(IntPtr streamPtr, int lPos,
                                                ref BitmapInfoHeader lpFormat, ref int cbFormat);
コード例 #13
0
 internal static extern int AVIStreamGetFrameOpen(IntPtr streamPtr, ref BitmapInfoHeader bih);
コード例 #14
0
 public BitmapInfo(ref byte[] contents, long offset)
 {
     BitmapHeader = new BitmapInfoHeader(ref contents, offset);
     Rgb = new RGBQuad(ref contents, offset);
 }
コード例 #15
0
ファイル: Icon2.jvm.cs プロジェクト: carrie901/mono
		private void InitFromStreamWithSize (Stream stream, int width, int height)
		{
			//read the icon header
			if (stream == null || stream.Length == 0)
				throw new System.ArgumentException ("The argument 'stream' must be a picture that can be used as a Icon", "stream");
			
			BinaryReader reader = new BinaryReader (stream);
            
			//iconDir = new IconDir ();
			iconDir.idReserved = reader.ReadUInt16();
			if (iconDir.idReserved != 0) //must be 0
				throw new System.ArgumentException ("Invalid Argument", "stream");
			
			iconDir.idType = reader.ReadUInt16();
			if (iconDir.idType != 1) //must be 1
				throw new System.ArgumentException ("Invalid Argument", "stream");

			ushort dirEntryCount = reader.ReadUInt16();
			iconDir.idCount = dirEntryCount;
			iconDir.idEntries = new IconDirEntry [dirEntryCount];
			imageData = new IconImage [dirEntryCount];
			bool sizeObtained = false;
			//now read in the IconDirEntry structures
			for (int i=0; i<dirEntryCount; i++){
				IconDirEntry ide;
				ide.width = reader.ReadByte ();
				ide.height = reader.ReadByte ();
				ide.colorCount = reader.ReadByte ();
				ide.reserved = reader.ReadByte ();
				ide.planes = reader.ReadUInt16 ();
				ide.bitCount = reader.ReadUInt16 ();
				ide.bytesInRes = reader.ReadUInt32 ();
				ide.imageOffset = reader.ReadUInt32 ();
				iconDir.idEntries [i] = ide;
				//is this is the best fit??
				if (!sizeObtained)   
					if (ide.height==height && ide.width==width) {
						this.id = (ushort) i;
						sizeObtained = true;
						this.iconSize.Height = ide.height;
						this.iconSize.Width = ide.width;
					}			
			}
			//if we havent found the best match, return the one with the
			//largest size. Is this approach correct??
			if (!sizeObtained){
				uint largestSize = 0;
				for (int j=0; j<dirEntryCount; j++){
					if (iconDir.idEntries [j].bytesInRes >= largestSize)	{
						largestSize = iconDir.idEntries [j].bytesInRes;
						this.id = (ushort) j;
						this.iconSize.Height = iconDir.idEntries [j].height;
						this.iconSize.Width = iconDir.idEntries [j].width;
					}
				}
			}
			
			//now read in the icon data
			for (int j = 0; j<dirEntryCount; j++)
			{
				IconImage iidata = new IconImage();
				BitmapInfoHeader bih = new BitmapInfoHeader();
				stream.Seek (iconDir.idEntries [j].imageOffset, SeekOrigin.Begin);
				byte [] buffer = new byte [iconDir.idEntries [j].bytesInRes];
				stream.Read (buffer, 0, buffer.Length);
				BinaryReader bihReader = new BinaryReader (new MemoryStream(buffer));
				bih.biSize = bihReader.ReadUInt32 ();
				bih.biWidth = bihReader.ReadInt32 ();
				bih.biHeight = bihReader.ReadInt32 ();
				bih.biPlanes = bihReader.ReadUInt16 ();
				bih.biBitCount = bihReader.ReadUInt16 ();
				bih.biCompression = bihReader.ReadUInt32 ();
				bih.biSizeImage = bihReader.ReadUInt32 ();
				bih.biXPelsPerMeter = bihReader.ReadInt32 ();
				bih.biYPelsPerMeter = bihReader.ReadInt32 ();
				bih.biClrUsed = bihReader.ReadUInt32 ();
				bih.biClrImportant = bihReader.ReadUInt32 ();

				iidata.iconHeader = bih;
				//Read the number of colors used and corresponding memory occupied by
				//color table. Fill this memory chunk into rgbquad[]
				int numColors;
				switch (bih.biBitCount){
					case 1: numColors = 2;
						break;
					case 4: numColors = 16;
						break;
					case 8: numColors = 256;
						break;
					default: numColors = 0;
						break;
				}
				
				iidata.iconColors = new uint [numColors];
				for (int i=0; i<numColors; i++)
					iidata.iconColors [i] = bihReader.ReadUInt32 ();

				//XOR mask is immediately after ColorTable and its size is 
				//icon height* no. of bytes per line
				
				//icon height is half of BITMAPINFOHEADER.biHeight, since it contains
				//both XOR as well as AND mask bytes
				int iconHeight = bih.biHeight/2;
				
				//bytes per line should should be uint aligned
				int numBytesPerLine = ((((bih.biWidth * bih.biPlanes * bih.biBitCount)+ 31)>>5)<<2);
				
				//Determine the XOR array Size
				int xorSize = numBytesPerLine * iconHeight;
				iidata.iconXOR = new byte [xorSize];
				for (int i=0; i<xorSize; i++)
					iidata.iconXOR[i] = bihReader.ReadByte();		
				
				//Determine the AND array size
				//For this i subtract the current position from the length.
				//ugly hack...
				int andSize = (int) (bihReader.BaseStream.Length - bihReader.BaseStream.Position);
				iidata.iconAND = new byte [andSize];
				for (int i=0; i<andSize; i++)
					iidata.iconAND[i] = bihReader.ReadByte();		
				
				imageData [j] = iidata;
				bihReader.Close();
			}			

			reader.Close();
		}
コード例 #16
0
ファイル: Icon.cs プロジェクト: kumpera/mono
		private void SaveBitmapAsIcon (BinaryWriter writer)
		{
			writer.Write ((ushort)0);	// idReserved must be 0
			writer.Write ((ushort)1);	// idType must be 1
			writer.Write ((ushort)1);	// only one icon

			// when transformed into a bitmap only a single image exists
			IconDirEntry ide = new IconDirEntry ();
			ide.width = (byte) bitmap.Width;
			ide.height = (byte) bitmap.Height;
			ide.colorCount = 0;	// 32 bbp == 0, for palette size
			ide.reserved = 0;	// always 0
			ide.planes = 0;
			ide.bitCount = 32;
			ide.imageOffset = 22;	// 22 is the first icon position (for single icon files)

			BitmapInfoHeader bih = new BitmapInfoHeader ();
			bih.biSize = (uint) Marshal.SizeOf (typeof (BitmapInfoHeader));
			bih.biWidth = bitmap.Width;
			bih.biHeight = 2 * bitmap.Height; // include both XOR and AND images
			bih.biPlanes = 1;
			bih.biBitCount = 32;
			bih.biCompression = 0;
			bih.biSizeImage = 0;
			bih.biXPelsPerMeter = 0;
			bih.biYPelsPerMeter = 0;
			bih.biClrUsed = 0;
			bih.biClrImportant = 0;

			IconImage ii = new IconImage ();
			ii.iconHeader = bih;
			ii.iconColors = new uint [0];	// no palette
			int xor_size = (((bih.biBitCount * bitmap.Width + 31) & ~31) >> 3) * bitmap.Height;
			ii.iconXOR = new byte [xor_size];
			int p = 0;
			for (int y = bitmap.Height - 1; y >=0; y--) {
				for (int x = 0; x < bitmap.Width; x++) {
					Color c = bitmap.GetPixel (x, y);
					ii.iconXOR [p++] = c.B;
					ii.iconXOR [p++] = c.G;
					ii.iconXOR [p++] = c.R;
					ii.iconXOR [p++] = c.A;
				}
			}
			int and_line_size = (((Width + 31) & ~31) >> 3);	// must be a multiple of 4 bytes
			int and_size = and_line_size * bitmap.Height;
			ii.iconAND = new byte [and_size];

			ide.bytesInRes = (uint) (bih.biSize + xor_size + and_size);

			SaveIconDirEntry (writer, ide, UInt32.MaxValue);
			SaveIconImage (writer, ii);
		}
コード例 #17
0
        /// <summary>
        ///     Read icon data.
        /// </summary>
        /// <param name="lpData">Pointer to the beginning of icon data.</param>
        /// <param name="size">Icon data size.</param>
        internal void Read(IntPtr lpData, uint size) {
            _header = (BitmapInfoHeader)Marshal.PtrToStructure(lpData, typeof (BitmapInfoHeader));

            _data = new byte[size];
            Marshal.Copy(lpData, _data, 0, _data.Length);
        }
コード例 #18
0
 public override void ParseItem (ByteVector id, ByteVector data, int start, int length)
 {
    if (id == "strf")
       Codec = new BitmapInfoHeader (data, start);
 }
コード例 #19
0
 /// <summary>
 ///     Create a copy of an image.
 /// </summary>
 /// <param name="image">Source image.</param>
 public DeviceIndependentBitmap(DeviceIndependentBitmap image) {
     _data = new byte[image._data.Length];
     Buffer.BlockCopy(image._data, 0, _data, 0, image._data.Length);
     _header = image._header;
 }
コード例 #20
0
        /// <summary>
        /// Set the Mediatype from a bitmap
        /// </summary>
        public override void SetMediaType(IGenericSampleConfig psc)
        {
            BitmapInfoHeader bmi = new BitmapInfoHeader();

            // Make sure we have an image to get the data from
            if (m_bmp == null)
            {
                int i;
                IntPtr ip = IntPtr.Zero;
                GetImage(0, ip, 0, out i);
            }

            // Build a BitmapInfo struct using the parms from the file
            bmi.Size = Marshal.SizeOf(typeof(BitmapInfoHeader));
            bmi.Width = m_bmd.Width;
            bmi.Height = m_bmd.Height * -1;
            bmi.Planes = 1;
            bmi.BitCount = 32;
            bmi.Compression = 0;
            bmi.ImageSize = (bmi.BitCount / 8) * bmi.Width * bmi.Height;
            bmi.XPelsPerMeter = 0;
            bmi.YPelsPerMeter = 0;
            bmi.ClrUsed = 0;
            bmi.ClrImportant = 0;

            int hr = psc.SetMediaTypeFromBitmap(bmi, m_FPS);
            DsError.ThrowExceptionForHR(hr);
        }
コード例 #21
0
ファイル: MainForm.cs プロジェクト: dgis/CodeTV
        public void ExecuteCommand(CommandName commandName, int repeat)
        {
            if (repeat == 0)
            {
                switch (commandName)
                {
                    case CommandName.Nop:
                        break;
                    case CommandName.ToggleMenu:
                        break;
                    case CommandName.Ok:
                        break;
                    case CommandName.Cancel:
                        if (Settings.StartVideoMode == VideoMode.Fullscreen)
                            ExecuteCommand(CommandName.VideoModeNormal);
                        break;
                    case CommandName.Left:
                        break;
                    case CommandName.Right:
                        break;
                    case CommandName.Up:
                        break;
                    case CommandName.Down:
                        break;
                    case CommandName.Key0: BuildChannelNumber(0); break;
                    case CommandName.Key1: BuildChannelNumber(1); break;
                    case CommandName.Key2: BuildChannelNumber(2); break;
                    case CommandName.Key3: BuildChannelNumber(3); break;
                    case CommandName.Key4: BuildChannelNumber(4); break;
                    case CommandName.Key5: BuildChannelNumber(5); break;
                    case CommandName.Key6: BuildChannelNumber(6); break;
                    case CommandName.Key7: BuildChannelNumber(7); break;
                    case CommandName.Key8: BuildChannelNumber(8); break;
                    case CommandName.Key9: BuildChannelNumber(9); break;
                    case CommandName.VolumePlus:
                        this.panelMediaTuning.trackBarVolume.Value = Math.Min(this.panelMediaTuning.trackBarVolume.Value + 250, 0);
                        break;
                    case CommandName.VolumeMinus:
                        this.panelMediaTuning.trackBarVolume.Value = Math.Max(this.panelMediaTuning.trackBarVolume.Value - 250, -10000);
                        break;
                    case CommandName.ChannelNextInFolder:
                        {
                            GraphBuilderTV currentGraph = this.currentGraphBuilder as GraphBuilderTV;
                            if (currentGraph != null)
                            {
                                Channel channel = currentGraph.CurrentChannel;
                                if (channel != null)
                                {
                                    ChannelFolder parentChannel = channel.Parent;
                                    int pos = parentChannel.ChannelList.IndexOf(channel);
                                    if (pos >= 0 && pos < parentChannel.ChannelList.Count - 1)
                                    {
                                        Channel newChannel = parentChannel.ChannelList[pos + 1];
                                        if (newChannel is ChannelTV)
                                            TuneChannelGUI(newChannel);
                                    }
                                }
                            }
                        }
                        break;
                    case CommandName.ChannelPreviousInFolder:
                        {
                            GraphBuilderTV currentGraph = this.currentGraphBuilder as GraphBuilderTV;
                            if (currentGraph != null)
                            {
                                Channel channel = currentGraph.CurrentChannel;
                                if (channel != null)
                                {
                                    ChannelFolder parentChannel = channel.Parent;
                                    int pos = parentChannel.ChannelList.IndexOf(channel);
                                    if (pos > 0)
                                    {
                                        Channel newChannel = parentChannel.ChannelList[pos - 1];
                                        if (newChannel is ChannelTV)
                                            TuneChannelGUI(newChannel);
                                    }
                                }
                            }
                        }
                        break;
                    case CommandName.ChannelNext:
                        {
                            short currentNumber = (short)-1;
                            bool channelFound = false;
                            GraphBuilderTV currentGraph = this.currentGraphBuilder as GraphBuilderTV;
                            if (currentGraph != null)
                            {
                                ChannelTV channel = currentGraph.CurrentChannel as ChannelTV;
                                if (channel != null && channel.ChannelNumber >= 0)
                                {
                                    currentNumber = channel.ChannelNumber;
                                    channelFound = true;
                                }
                            }
                            if (!channelFound)
                            {
                                if (panelChannel.treeViewChannel.SelectedNode != null)
                                {
                                    ChannelTV channel = panelChannel.treeViewChannel.SelectedNode.Tag as ChannelTV;
                                    if (channel != null && channel.ChannelNumber >= 0)
                                    {
                                        currentNumber = channel.ChannelNumber;
                                        channelFound = true;
                                    }
                                }
                            }
                            ChannelTV newChannel = null;
                            while ((newChannel = this.channelByChannelNumber[++currentNumber] as ChannelTV) == null && currentNumber <= channelNumberMax) ;

                            if (newChannel is ChannelTV)
                                TuneChannelGUI(newChannel);
                        }
                        break;
                    case CommandName.ChannelPrevious:
                        {
                            short currentNumber = (short)(channelNumberMax + 1);
                            bool channelFound = false;
                            GraphBuilderTV currentGraph = this.currentGraphBuilder as GraphBuilderTV;
                            if (currentGraph != null)
                            {
                                ChannelTV channel = currentGraph.CurrentChannel as ChannelTV;
                                if (channel != null && channel.ChannelNumber >= 0)
                                {
                                    currentNumber = channel.ChannelNumber;
                                    channelFound = true;
                                }
                            }
                            if (!channelFound)
                            {
                                if (panelChannel.treeViewChannel.SelectedNode != null)
                                {
                                    ChannelTV channel = panelChannel.treeViewChannel.SelectedNode.Tag as ChannelTV;
                                    if (channel != null && channel.ChannelNumber >= 0)
                                    {
                                        currentNumber = channel.ChannelNumber;
                                        channelFound = true;
                                    }
                                }
                            }
                            ChannelTV newChannel = null;
                            while ((newChannel = this.channelByChannelNumber[--currentNumber] as ChannelTV) == null && currentNumber >= 0);

                            if (newChannel is ChannelTV)
                                TuneChannelGUI(newChannel);
                        }
                        break;
                    case CommandName.MediaPlay:

                        if (this.currentGraphBuilder is ITimeShifting)
                            (this.currentGraphBuilder as ITimeShifting).Resume();
                        else if (this.currentGraphBuilder is IPlayer)
                            (this.currentGraphBuilder as IPlayer).Play();

                        break;
                    case CommandName.MediaPause:

                        if (this.currentGraphBuilder is IBDA)
                        {
                            if (!(this.currentGraphBuilder is ITimeShifting) && !Settings.TimeShiftingActivated)
                            {
                                Settings.TimeShiftingActivated = true;
                                //this.graphBuilderType = GraphBuilderType.BDATimeShifting;
                                //this.toolStripButtonTimeShifting.Checked = true;

                                //ChannelDVB currentChannelDVB = (this.currentGraphBuilder as ITV).CurrentChannel as ChannelDVB;
                                //if (currentChannelDVB != null)
                                //    TuneChannelGUI(currentChannelDVB, true);
                            }

                            if (this.currentGraphBuilder is ITimeShifting)
                            {
                                if ((this.currentGraphBuilder as ITimeShifting).Status == TimeShiftingStatus.Recording)
                                    (this.currentGraphBuilder as ITimeShifting).Pause();
                                else if ((this.currentGraphBuilder as ITimeShifting).Status == TimeShiftingStatus.Paused)
                                    (this.currentGraphBuilder as ITimeShifting).Resume();
                            }
                        }
                        else if (this.currentGraphBuilder is IPlayer)
                            (this.currentGraphBuilder as IPlayer).Pause();

                        break;
                    case CommandName.MediaStop:

                        if (this.currentGraphBuilder is IRecorder)
                        {
                            IRecorder recorder = this.currentGraphBuilder as IRecorder;
                            if (recorder.Status == RecorderStatus.Recording)
                            {
                                recorder.Stop();
                                break;
                            }
                        }
                        else if (this.currentGraphBuilder is ITimeShifting && Settings.TimeShiftingActivated)
                        {
                            Settings.TimeShiftingActivated = false;
                            //this.graphBuilderType = GraphBuilderType.BDA;
                            //this.toolStripButtonTimeShifting.Checked = false;

                            //ChannelDVB currentChannelDVB = (this.currentGraphBuilder as ITV).CurrentChannel as ChannelDVB;
                            //if (currentChannelDVB != null)
                            //    TuneChannelGUI(currentChannelDVB, true);
                        }
                        else //if (this.currentGraphBuilder is IPlayer)
                            //(this.currentGraphBuilder as IPlayer).Stop();
                            ClearGraph();

                        break;
                    case CommandName.MediaRecord:

                        if (this.currentGraphBuilder is IBDA)
                        {
                            if (!(this.currentGraphBuilder is IRecorder) && !Settings.TimeShiftingActivated)
                            {
                                Settings.TimeShiftingActivated = true;
                                //this.graphBuilderType = GraphBuilderType.BDATimeShifting;
                                //this.toolStripButtonTimeShifting.Checked = true;

                                //ChannelDVB currentChannelDVB = (this.currentGraphBuilder as ITV).CurrentChannel as ChannelDVB;
                                //if (currentChannelDVB != null)
                                //    TuneChannelGUI(currentChannelDVB, true);
                            }

                            if (this.currentGraphBuilder is IRecorder)
                            {
                                IRecorder recorder = this.currentGraphBuilder as IRecorder;
                                if (recorder.Status == RecorderStatus.Stopped)
                                {
                                    string filename = DateTime.Now.ToString(Properties.Resources.VideoRecorderTimeFormat);
                                    if (this.currentGraphBuilder is ITV)
                                    {
                                        ITV tv = this.currentGraphBuilder as ITV;
                                        if (tv.CurrentChannel != null)
                                            filename += " " + tv.CurrentChannel.Name;
                                    }

                                    if (!Directory.Exists(Settings.VideosFolder))
                                        Directory.CreateDirectory(Settings.VideosFolder);

                                    filename += ".dvr-ms";
                                    recorder.Start(Settings.VideosFolder + "\\" + filename);

                                    toolStripStatusLabelVideoStatus.Text = string.Format(Properties.Resources.RecordingInFile, filename);
                                }
                                else if (recorder.Status == RecorderStatus.Recording)
                                {
                                    recorder.Stop();
                                }
                            }
                        }

                        break;
                    case CommandName.MediaRewind:
                        break;
                    case CommandName.MediaFastForward:
                        break;
                    case CommandName.VideoReset:
                    case CommandName.VideoZoomHalf:
                    case CommandName.VideoZoomNormal:
                    case CommandName.VideoZoomDouble:
                    case CommandName.VideoZoomFreeMode:
                    case CommandName.VideoZoomFromInside:
                    case CommandName.VideoZoomFromOutside:
                    case CommandName.VideoZoomStretchToWindow:
                    case CommandName.VideoZoomIncrease:
                    case CommandName.VideoZoomDecrease:
                    case CommandName.VideoResetAspectRatio:
                    case CommandName.VideoIncreaseAspectRatio:
                    case CommandName.VideoDecreaseAspectRatio:
                    case CommandName.VideoCenter:
                    case CommandName.VideoMoveLeft:
                    case CommandName.VideoMoveRight:
                    case CommandName.VideoMoveUp:
                    case CommandName.VideoMoveDown:
                        if (this.currentGraphBuilder != null)
                        {
                            int x = 0, y = 0;
                            int dx = 0, dy = 0;

                            PointF videoOffset = this.currentGraphBuilder.VideoOffset;
                            double videoZoom = this.currentGraphBuilder.VideoZoom;
                            double videoAspectRatioFactor = this.currentGraphBuilder.VideoAspectRatioFactor;

                            switch (commandName)
                            {
                                case CommandName.VideoReset:
                                    videoOffset = new PointF(0.5f, 0.5f);
                                    videoZoom = 1.0;
                                    videoAspectRatioFactor = 1.0;
                                    break;
                                case CommandName.VideoZoomHalf:
                                    this.currentGraphBuilder.VideoZoomMode = VideoSizeMode.Free;
                                    videoZoom = 0.5;
                                    break;
                                case CommandName.VideoZoomNormal:
                                    this.currentGraphBuilder.VideoZoomMode = VideoSizeMode.Free;
                                    videoZoom = 1.0;
                                    break;
                                case CommandName.VideoZoomDouble:
                                    this.currentGraphBuilder.VideoZoomMode = VideoSizeMode.Free;
                                    videoZoom = 2.0;
                                    break;
                                case CommandName.VideoZoomFreeMode:
                                    this.currentGraphBuilder.VideoZoomMode = VideoSizeMode.Free;
                                    break;
                                case CommandName.VideoZoomFromInside:
                                    this.currentGraphBuilder.VideoZoomMode = VideoSizeMode.FromInside;
                                    videoOffset = new PointF(0.5f, 0.5f);
                                    videoZoom = 1.0;
                                    break;
                                case CommandName.VideoZoomFromOutside:
                                    this.currentGraphBuilder.VideoZoomMode = VideoSizeMode.FromOutside;
                                    videoOffset = new PointF(0.5f, 0.5f);
                                    videoZoom = 1.0;
                                    break;
                                case CommandName.VideoZoomStretchToWindow:
                                    this.currentGraphBuilder.VideoZoomMode = VideoSizeMode.StretchToWindow;
                                    break;
                                case CommandName.VideoZoomIncrease: x = 1; break;
                                case CommandName.VideoZoomDecrease: x = -1; break;
                                case CommandName.VideoResetAspectRatio:
                                    videoAspectRatioFactor = 1.0;
                                    break;
                                case CommandName.VideoIncreaseAspectRatio: y = 1; break;
                                case CommandName.VideoDecreaseAspectRatio: y = -1; break;
                                case CommandName.VideoCenter: videoOffset = new PointF(0.5f, 0.5f); break;
                                case CommandName.VideoMoveLeft: dx = -1; break;
                                case CommandName.VideoMoveRight: dx = 1; break;
                                case CommandName.VideoMoveUp: dy = -1; break;
                                case CommandName.VideoMoveDown: dy = 1; break;
                                default: break;
                            }

                            if (x > 0 && videoZoom < 3f)
                                videoZoom *= 1.02f;
                            if (x < 0 && videoZoom > 0.2f)
                                videoZoom /= 1.02f;
                            if (y > 0 && videoAspectRatioFactor < 3f)
                                videoAspectRatioFactor *= 1.02f;
                            if (y < 0 && videoAspectRatioFactor > 0.2f)
                                videoAspectRatioFactor /= 1.02f;

                            if (dx < 0 && videoOffset.X > 0f)
                                videoOffset.X = (float)Math.Max((double)videoOffset.X - 0.005 * videoZoom, 0.0);
                            if (dx > 0 && videoOffset.X < 1f)
                                videoOffset.X = (float)Math.Min((double)videoOffset.X + 0.005 * videoZoom, 1.0);
                            if (dy < 0 && videoOffset.Y > 0f)
                                videoOffset.Y = (float)Math.Max((double)videoOffset.Y - 0.005 * videoZoom, 0.0);
                            if (dy > 0 && videoOffset.Y < 1f)
                                videoOffset.Y = (float)Math.Min((double)videoOffset.Y + 0.005 * videoZoom, 1.0);

                            this.currentGraphBuilder.VideoOffset = videoOffset;
                            this.currentGraphBuilder.VideoZoom = videoZoom;
                            this.currentGraphBuilder.VideoAspectRatioFactor = videoAspectRatioFactor;

                            this.currentGraphBuilder.VideoRefresh();
                        }
                        break;
                    case CommandName.VideoModeNormal:
                        ChangeVideoMode(VideoMode.Normal);
                        break;
                    case CommandName.VideoModeTV:
                        ChangeVideoMode(VideoMode.TV);
                        break;
                    case CommandName.VideoModeFullscreen:
                        ChangeVideoMode(VideoMode.Fullscreen);
                        break;
                    case CommandName.SnapShot:
                        IVMRWindowlessControl9 vmrWindowlessControl9 = null;
                        if (this.currentGraphBuilder != null)
                            vmrWindowlessControl9 = this.currentGraphBuilder.VideoRenderer as IVMRWindowlessControl9;
                        if (vmrWindowlessControl9 != null)
                        {
                            IntPtr lpDib;
                            int hr = vmrWindowlessControl9.GetCurrentImage(out lpDib);
                            if (hr >= 0)
                            {
                                try
                                {
                                    BitmapInfoHeader bih = new BitmapInfoHeader();
                                    Marshal.PtrToStructure(lpDib, bih);
                                    Bitmap bitmap = new Bitmap(bih.Width, bih.Height, PixelFormat.Format32bppRgb);
                                    Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                                    BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, bitmap.PixelFormat);

                                    int sourceBitsSize = bih.ImageSize;
                                    byte[] rgbValues = new byte[sourceBitsSize];
                                    int ptrIntBits = (int)lpDib + bih.Size;
                                    IntPtr ptrBits = (IntPtr)ptrIntBits;
                                    Marshal.Copy(ptrBits, rgbValues, 0, sourceBitsSize);
                                    Marshal.Copy(rgbValues, 0, bmpData.Scan0, sourceBitsSize);

                                    //unsafe
                                    //{
                                    //    int* sourceBits = (int*)lpDib.ToPointer();
                                    //    int* destinationBits = (int*)bmpData.Scan0.ToPointer();
                                    //    sourceBits += Marshal.SizeOf(typeof(BitmapInfoHeader)) / 4;
                                    //    for (int i = 0; i < bih.ImageSize; i += 4)
                                    //        *destinationBits++ = *sourceBits++;
                                    //}

                                    bitmap.UnlockBits(bmpData);

                                    // If the image is upsidedown
                                    bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

                                    if (!Directory.Exists(Settings.SnapshotsFolder))
                                        Directory.CreateDirectory(Settings.SnapshotsFolder);

                                    string path = Settings.SnapshotsFolder + '\\';
                                    string filename = DateTime.Now.ToString(Properties.Resources.SnapShotTimeFormat);
                                    if (this.currentGraphBuilder is ITV)
                                        filename += " " + MakeCorrectFilename((this.currentGraphBuilder as ITV).CurrentChannel.Name);
                                    filename += ".png";

                                    try
                                    {
                                        bitmap.Save(path + filename, ImageFormat.Png);
                                        toolStripStatusLabelVideoStatus.Text = string.Format(Properties.Resources.SnapshotSaved, filename);
                                    }
                                    catch(Exception)
                                    {
                                        MessageBox.Show(string.Format(Properties.Resources.SnapshotNotSaved, path + filename));
                                    }
                                }
                                finally
                                {
                                    Marshal.FreeCoTaskMem(lpDib);
                                }
                            }
                        }
                        break;
                }
            }
        }
コード例 #22
0
ファイル: Camera.cs プロジェクト: robotsrulz/Sardauscan
        /// <summary>
        /// Make snapshot of output image. Slow, but includes all graph's effects.
        /// </summary>
        /// <returns>Snapshot as a Bitmap</returns>
        /// <seealso cref="SnapshotSourceImage"/>
        public Bitmap SnapshotOutputImage()
        {
            if (DX.WindowlessCtrl == null)
                throw new Exception("WindowlessCtrl is not initialized.");

            IntPtr currentImage = IntPtr.Zero;
            Bitmap bitmap = null;
            Bitmap bitmap_clone = null;

            try
            {
                int hr = DX.WindowlessCtrl.GetCurrentImage(out currentImage);
                DsError.ThrowExceptionForHR(hr);

                if (currentImage != IntPtr.Zero)
                {
                    BitmapInfoHeader structure = new BitmapInfoHeader();
                    Marshal.PtrToStructure(currentImage, structure);

                    PixelFormat pixelFormat = PixelFormat.Format24bppRgb;
                    switch (structure.BitCount)
                    {
                        case 24:
                            pixelFormat = PixelFormat.Format24bppRgb;
                            break;
                        case 32:
                            pixelFormat = PixelFormat.Format32bppRgb;
                            break;
                        case 48:
                            pixelFormat = PixelFormat.Format48bppRgb;
                            break;
                        default:
                            throw new Exception("Unsupported BitCount.");
                    }

                    bitmap = new Bitmap(structure.Width, structure.Height, (structure.BitCount / 8) * structure.Width, pixelFormat, new IntPtr(currentImage.ToInt64() + DIB_Image_HeaderSize));

                    bitmap_clone = bitmap.Clone(new Rectangle(0, 0, structure.Width, structure.Height), PixelFormat.Format24bppRgb);

                    bitmap_clone.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }
            }
            catch
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                    bitmap = null;
                }

                throw;
            }
            finally
            {
                Marshal.FreeCoTaskMem(currentImage);
            }

            return bitmap_clone;
        }
コード例 #23
0
ファイル: AviInterop.cs プロジェクト: whztt07/DeltaEngine
		internal static extern int AVIStreamGetFrameOpen(IntPtr streamPtr, ref BitmapInfoHeader bih);
コード例 #24
0
ファイル: Grabber.cs プロジェクト: andrewjswan/mvcentral
        private void snapImage(string outFileName)
        {
            if (windowlessCtrl != null)
            {
                IntPtr currentImage = IntPtr.Zero;
                Bitmap bmp = null;

                try
                {
                    int hr = windowlessCtrl.GetCurrentImage(out currentImage);
                    DsError.ThrowExceptionForHR(hr);

                    if (currentImage != IntPtr.Zero)
                    {
                        BitmapInfoHeader structure = new BitmapInfoHeader();
                        Marshal.PtrToStructure(currentImage, structure);

                        bmp = new Bitmap(structure.Width, structure.Height, (structure.BitCount / 8) * structure.Width, System.Drawing.Imaging.PixelFormat.Format32bppArgb, new IntPtr(currentImage.ToInt64() + 40));
                        bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

                        bmp.Save(outFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                }
                catch (Exception anyException)
                {
                    logger.ErrorException("Failed getting image: ", anyException);

               }
                finally
                {
                    if (bmp != null)
                    {
                        bmp.Dispose();
                    }

                    Marshal.FreeCoTaskMem(currentImage);
                }
            }
        }
コード例 #25
0
ファイル: AviInterop.cs プロジェクト: whztt07/DeltaEngine
		internal static extern int AVIStreamReadFormat(IntPtr streamPtr, int lPos,
			ref BitmapInfoHeader lpFormat, ref int cbFormat);
コード例 #26
0
ファイル: VfwApi.cs プロジェクト: bobahml/SharpAvi
 public static extern int ICSendMessage(IntPtr handle, int message, ref BitmapInfoHeader inHeader, ref BitmapInfoHeader outHeader);
コード例 #27
0
 private bool SetEncoderInfo(IntPtr bitmapInfoHeader, int rate, int outputWidth, int outputHeight, BitmapInfoHeader outputBitmapInfoHeader, ref int headerSize)
 {
     return(VsNetVideoEncoderSdk.VideoEncoderEx_StartEnc(_handle, bitmapInfoHeader, rate, outputWidth, outputHeight, outputBitmapInfoHeader, ref headerSize) == 0);
 }