Ejemplo n.º 1
0
 public StreamInfo(FourCC standardIndexChunkId)
 {
     this.standardIndexChunkId = standardIndexChunkId;
     FrameCount = 0;
     MaxChunkDataSize = 0;
     TotalDataSize = 0;
 }
Ejemplo n.º 2
0
        public Recorder(string fileName, 
            FourCC codec, int quality, 
            int audioSourceIndex, SupportedWaveFormat audioWaveFormat, bool encodeAudio, int audioBitRate)
        {
            System.Windows.Media.Matrix toDevice;
            using (var source = new HwndSource(new HwndSourceParameters()))
            {
                toDevice = source.CompositionTarget.TransformToDevice;
            }

            screenWidth = (int)Math.Round(SystemParameters.PrimaryScreenWidth * toDevice.M11);
            screenHeight = (int)Math.Round(SystemParameters.PrimaryScreenHeight * toDevice.M22);

            // Create AVI writer and specify FPS
            writer = new AviWriter(fileName)
            {
                FramesPerSecond = 10,
                EmitIndex1 = true,
            };

            // Create video stream
            videoStream = CreateVideoStream(codec, quality);
            // Set only name. Other properties were when creating stream,
            // either explicitly by arguments or implicitly by the encoder used
            videoStream.Name = "Screencast";

            if (audioSourceIndex >= 0)
            {
                var waveFormat = ToWaveFormat(audioWaveFormat);

                audioStream = CreateAudioStream(waveFormat, encodeAudio, audioBitRate);
                // Set only name. Other properties were when creating stream,
                // either explicitly by arguments or implicitly by the encoder used
                audioStream.Name = "Voice";

                audioSource = new WaveInEvent
                {
                    DeviceNumber = audioSourceIndex,
                    WaveFormat = waveFormat,
                    // Buffer size to store duration of 1 frame
                    BufferMilliseconds = (int)Math.Ceiling(1000 / writer.FramesPerSecond),
                    NumberOfBuffers = 3,
                };
                audioSource.DataAvailable += audioSource_DataAvailable;
            }

            screenThread = new Thread(RecordScreen)
            {
                Name = typeof(Recorder).Name + ".RecordScreen",
                IsBackground = true
            };

            if (audioSource != null)
            {
                videoFrameWritten.Set();
                audioBlockWritten.Reset();
                audioSource.StartRecording();
            }
            screenThread.Start();
        }
Ejemplo n.º 3
0
        public static RiffItem OpenList(this BinaryWriter writer, FourCC fourcc, FourCC listType)
        {
            Contract.Requires(writer != null);

            var result = writer.OpenChunk(listType);
            writer.Write((uint)fourcc);
            return result;
        }
Ejemplo n.º 4
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            _Predefined = stream.ReadBEUInt32();
            HandlerType = new FourCC(stream.ReadBytes(4));
            for (int i = 0; i < _Reserved.Length; i++) _Reserved[i] = stream.ReadBEUInt32();
            Name = stream.ReadNullTerminatedUTF8String();
        }
Ejemplo n.º 5
0
        private static string GetVideoFormat(SharpDX.MediaFoundation.MediaType mediaType)
        {
            // https://docs.microsoft.com/en-us/windows/desktop/medfound/video-subtype-guids
            var subTypeId     = mediaType.Get(MediaTypeAttributeKeys.Subtype);
            var fourccEncoded = BitConverter.ToInt32(subTypeId.ToByteArray(), 0);
            var fourcc        = new FourCC(fourccEncoded);

            return(fourcc.ToString());
        }
Ejemplo n.º 6
0
        public static RiffItem OpenList(this BinaryWriter writer, FourCC fourcc, FourCC listType)
        {
            Argument.IsNotNull(writer, nameof(writer));

            var result = writer.OpenChunk(listType);

            writer.Write((uint)fourcc);
            return(result);
        }
Ejemplo n.º 7
0
        public static RiffItem OpenList(this BinaryWriter writer, FourCC fourcc, FourCC listType)
        {
            Contract.Requires(writer != null);

            var result = writer.OpenChunk(listType);

            writer.Write((uint)fourcc);
            return(result);
        }
Ejemplo n.º 8
0
        public virtual void PrepareForWriting()
        {
            if (!isFrozen)
            {
                isFrozen = true;

                chunkId = GenerateChunkId();
            }
        }
Ejemplo n.º 9
0
        public virtual int WriteData(FourCC type, IntPtr buffer, int sizeInBytes)
        {
            if (native)
            {
                return(NativeInputSystem.WriteDeviceData(id, type, buffer, sizeInBytes));
            }

            return(0);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RiffChunk"/> class.
 /// </summary>
 /// <param name="stream">The stream holding this chunk</param>
 /// <param name="type">The type.</param>
 /// <param name="size">The size.</param>
 /// <param name="dataPosition">The data offset.</param>
 /// <param name="isList">if set to <c>true</c> [is list].</param>
 /// <param name="isHeader">if set to <c>true</c> [is header].</param>
 public RiffChunk(Stream stream, FourCC type, uint size, uint dataPosition, bool isList = false, bool isHeader = false)
 {
     Stream       = stream;
     Type         = type;
     Size         = size;
     DataPosition = dataPosition;
     IsList       = isList;
     IsHeader     = isHeader;
 }
Ejemplo n.º 11
0
 public static int GetSizeOfPrimitiveFormatInBits(FourCC type)
 {
     if (type == kTypeBit)
     {
         return(1);
     }
     if (type == kTypeInt || type == kTypeUInt)
     {
         return(4 * 8);
     }
     if (type == kTypeShort || type == kTypeUShort)
     {
         return(2 * 8);
     }
     if (type == kTypeByte || type == kTypeSByte)
     {
         return(1 * 8);
     }
     if (type == kTypeFloat)
     {
         return(4 * 8);
     }
     if (type == kTypeDouble)
     {
         return(8 * 8);
     }
     if (type == kTypeVector2)
     {
         return(2 * 4 * 8);
     }
     if (type == kTypeVector3)
     {
         return(3 * 4 * 8);
     }
     if (type == kTypeQuaternion)
     {
         return(4 * 4 * 8);
     }
     if (type == kTypeVector2Short)
     {
         return(2 * 2 * 8);
     }
     if (type == kTypeVector3Short)
     {
         return(3 * 2 * 8);
     }
     if (type == kTypeVector2Byte)
     {
         return(2 * 1 * 8);
     }
     if (type == kTypeVector3Byte)
     {
         return(3 * 1 * 8);
     }
     return(-1);
 }
        /// <summary>
        ///  This method for loading/saving a font file generated from MakeSpriteFont.
        /// </summary>
        /// <param name="serializer">The binary serializer to use.</param>
        /// <returns></returns>
        private void SerializeMakeSpriteFont(BinarySerializer serializer)
        {
            FourCC magicCode2 = "font";

            serializer.Serialize(ref magicCode2);
            if (magicCode2 != "font")
            {
                return;
            }

            // Writes the version
            if (serializer.Mode == SerializerMode.Read)
            {
                int version = serializer.Reader.ReadInt32();
                if (version != Version)
                {
                    throw new NotSupportedException(string.Format("SpriteFontData version [0x{0:X}] is not supported. Expecting [0x{1:X}]", version, Version));
                }
            }
            else
            {
                serializer.Writer.Write(Version);
            }

            // Deserialize Glyphs
            int glyphCount = 0;

            serializer.Serialize(ref glyphCount);

            // For MakeSpriteFont, there is only one GlyphPage.
            Glyphs = new Glyph[glyphCount];
            for (int i = 0; i < glyphCount; i++)
            {
                serializer.Serialize(ref Glyphs[i].Character);
                serializer.Serialize(ref Glyphs[i].Subrect);
                serializer.Serialize(ref Glyphs[i].Offset);
                serializer.Serialize(ref Glyphs[i].XAdvance);
            }

            serializer.Serialize(ref LineSpacing);
            serializer.Serialize(ref DefaultCharacter);

            var image = new BitmapData();

            Bitmaps = new Bitmap[1] {
                new Bitmap()
            };
            Bitmaps[0].Data = image;

            serializer.Serialize(ref image.Width);
            serializer.Serialize(ref image.Height);
            serializer.SerializeEnum(ref image.PixelFormat);
            serializer.Serialize(ref image.RowStride);
            serializer.Serialize(ref image.CompressedHeight);
            serializer.Serialize(ref image.Data, image.RowStride * image.CompressedHeight);
        }
Ejemplo n.º 13
0
        public static RiffItem OpenChunk(this BinaryWriter writer, FourCC fourcc, int expectedDataSize = -1)
        {
            Argument.IsNotNull(writer, nameof(writer));
            Argument.Meets(expectedDataSize <= int.MaxValue - RiffItem.ITEM_HEADER_SIZE, nameof(expectedDataSize));

            writer.Write((uint)fourcc);
            writer.Write((uint)(expectedDataSize >= 0 ? expectedDataSize : 0));

            return(new RiffItem(writer.BaseStream.Position, expectedDataSize));
        }
        public RecorderParams(string filename, double scale, int FrameRate, FourCC Encoder, int Quality, int height, int width)
        {
            FileName        = filename;
            FramesPerSecond = FrameRate;
            Codec           = Encoder;
            this.Quality    = Quality;

            Height = (int)(height * scale);
            Width  = (int)(width * scale);
        }
Ejemplo n.º 15
0
        public static Type GetTypeFromEnum(FourCC value)
        {
            switch (value)
            {
            case FourCC.SCLS:
                return(typeof(ExitData));
            }

            return(null);
        }
Ejemplo n.º 16
0
        public static RiffItem OpenChunk(this BinaryWriter writer, FourCC fourcc, int expectedDataSize = -1)
        {
            Contract.Requires(writer != null);
            Contract.Requires(expectedDataSize <= int.MaxValue - RiffItem.ITEM_HEADER_SIZE);

            writer.Write((uint)fourcc);
            writer.Write((uint)(expectedDataSize >= 0 ? expectedDataSize : 0));

            return new RiffItem(writer.BaseStream.Position, expectedDataSize);
        }
        public RecorderParams(string filename, int FrameRate, FourCC Encoder, int Quality)
        {
            FileName        = filename;
            FramesPerSecond = FrameRate;
            Codec           = Encoder;
            this.Quality    = Quality;

            Height = (int)SystemParameters.PrimaryScreenHeight;
            Width  = (int)SystemParameters.PrimaryScreenWidth;
        }
Ejemplo n.º 18
0
        public RoomTableEntryNode(FourCC fourCC, WWorld world) : base(fourCC, world)
        {
            LoadedRoomEntries = new AdvancedBindingList <RoomTableRoomSettings>();

            var room_entry = new RoomTableRoomSettings();

            room_entry.ActivateRoomWhenLoaded = true;
            room_entry.Unk2 = true;
            LoadedRoomEntries.Add(room_entry);
        }
Ejemplo n.º 19
0
 public FileTypeBox(FourCC majorBrand, uint minorVersion, FourCC[] compatibleBrands)
     : this()
 {
     MajorBrand   = majorBrand;
     MinorVersion = minorVersion;
     foreach (FourCC fourCC in compatibleBrands)
     {
         CompatibleBrands.Add(fourCC);
     }
 }
Ejemplo n.º 20
0
        public RecorderParameters(string filename, int frameRate, FourCC encoder, int quality)
        {
            this.fileName   = filename;
            framesPerSecond = frameRate;
            codec           = encoder;
            this.quality    = quality;

            Height = Screen.PrimaryScreen.Bounds.Height;
            Width  = Screen.PrimaryScreen.Bounds.Width;
        }
        public static RiffItem OpenChunk(this BinaryWriter writer, FourCC fourcc, int expectedDataSize = -1)
        {
            Debug.Assert(writer != null);
            Debug.Assert(expectedDataSize <= int.MaxValue - RiffItem.ITEM_HEADER_SIZE);

            writer.Write((uint)fourcc);
            writer.Write((uint)(expectedDataSize >= 0 ? expectedDataSize : 0));

            return(new RiffItem(writer.BaseStream.Position, expectedDataSize));
        }
Ejemplo n.º 22
0
            unsafe public InputEventBytes(InputEventPtr iep)
            {
                //copy raw data from InputEventPtr into a byte[]
                data = CopyEventData(iep);

                //store the other metadata we might need (might not need to do this after all)
                deviceId = iep.deviceId;
                time     = iep.time;
                type     = FourCC.ToInt32(iep.type);
            }
Ejemplo n.º 23
0
 public AviVideoStream(int index, IAviStreamWriteHandler writeHandler,
                       int width, int height, BitsPerPixel bitsPerPixel)
     : base(index)
 {
     this.writeHandler = writeHandler;
     this.width        = width;
     this.height       = height;
     this.bitsPerPixel = bitsPerPixel;
     this.streamCodec  = KnownFourCC.Codecs.Uncompressed;
 }
Ejemplo n.º 24
0
        private bool CheckFormat(LABNFile file)
        {
            FourCC fourCC = file.ReadFourCC();

            if (fourCC == "LABN")
            {
                return(true);
            }
            return(false);
        }
        public RecorderParams(string filename, int FrameRate, FourCC Encoder, int Quality)
        {
            FileName        = filename;
            FramesPerSecond = FrameRate;
            Codec           = Encoder;
            this.Quality    = Quality;

            Height = Screen.PrimaryScreen.Bounds.Height;
            Width  = Screen.PrimaryScreen.Bounds.Width;
        }
Ejemplo n.º 26
0
 public PixelFormat(PixelFormatFlags flags, FourCC formatCode)
 {
     Size         = (uint)MemoryHelper.SizeOf <PixelFormat>();
     Flags        = flags;
     FourCC       = formatCode;
     RGBBitCount  = 0;
     RedBitMask   = 0;
     GreenBitMask = 0;
     BlueBitMask  = 0;
     AlphaBitMask = 0;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Pops a FourCC object from the stack, fills out the size info,
        /// and returns the binary writer to its current position.
        /// </summary>
        /// <param name="bw"></param>
        public void Pop()
        {
            FourCC fourCC = mFourCCStack.Pop();

            int curPos   = (int)mBinaryWriter.BaseStream.Position;
            int dataSize = curPos - fourCC.mStreamPos;

            mBinaryWriter.Seek(fourCC.mStreamPos + 4, SeekOrigin.Begin);
            mBinaryWriter.Write(dataSize);
            mBinaryWriter.Seek(curPos, SeekOrigin.Begin);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Parses the <paramref name="binaryFile" /> and returns a <see cref="RIFFFileChunk" />. Note that the position of the
        /// stream has to point to a riff file chunk.
        /// </summary>
        /// <param name="binaryFile"><see cref="BinaryFile" /> which contains the riff file chunk.</param>
        /// <returns>
        /// Instance of the <see cref="RIFFFileChunk" /> class or any derived classes. It the stream does not point to a
        /// wave file chunk the instance of the <see cref="RIFFFileChunk" /> which gets return will be invalid.
        /// </returns>
        public static RIFFFileChunk FromBinaryFile(BinaryFile binaryFile)
        {
            if (binaryFile == null)
            {
                throw new ArgumentNullException("binaryFile");
            }
            if (binaryFile.CanRead == false)
            {
                throw new ArgumentException("binaryFile is not readable");
            }

            int id = binaryFile.ReadInt32(BinaryFile.ByteOrder.LittleEndian); // Steinberg CPR files have LittleEndian FourCCs

            binaryFile.Position -= 4;

            if (StringUtils.IsAsciiPrintable(FourCC.FromFourCC(id)))
            {
                Log.Verbose("Processing chunk: '{0}'", FourCC.FromFourCC(id));
            }
            else
            {
                if (id == 0)
                {
                    // likely corrupt wav file with alot of crap after the chunk
                    // skip bytes until only 8 bytes are left
                    // stream.Position = stream.Length - 8;
                }
                else
                {
                    // try to fix chunks that are not word-aligned but should have been?!
                    Log.Verbose("Processing chunk: {0}", string.Format("{0} is not FourCC", id));
                    long origPos = binaryFile.Position;

                    // rewind one byte and try again
                    binaryFile.Position -= 1;
                    int id2ndTry = binaryFile.ReadInt32();
                    binaryFile.Position -= 4;

                    if (StringUtils.IsAsciiPrintable(FourCC.FromFourCC(id2ndTry)))
                    {
                        // we believe it worked
                        Log.Verbose("Seem to have fixed non word-aligned chunk: {0}", FourCC.FromFourCC(id2ndTry));
                    }
                    else
                    {
                        // still didn't work
                        // put position back to where it was.
                        binaryFile.Position = origPos;
                    }
                }
            }

            return(new RIFFFileChunk(binaryFile));
        }
Ejemplo n.º 29
0
 public PixelFormat(PixelFormatFlags flags, FourCC formatCode, uint colorBitCount, uint redMask, uint greenMask, uint blueMask, uint alphaMask)
 {
     Size         = (uint)MemoryHelper.SizeOf <PixelFormat>();
     Flags        = flags;
     FourCC       = formatCode;
     RGBBitCount  = colorBitCount;
     RedBitMask   = redMask;
     GreenBitMask = greenMask;
     BlueBitMask  = blueMask;
     AlphaBitMask = alphaMask;
 }
Ejemplo n.º 30
0
        // Extracts the FOURCC code from the subtype.
        // Not all subtypes follow this pattern.
        public void GetFourCC(out int pFourCC)
        {
            Debug.Assert(IsValid());
            Guid guidSubType;

            GetSubType(out guidSubType);

            FourCC f = new FourCC(guidSubType);

            pFourCC = f.ToInt32();
        }
Ejemplo n.º 31
0
        public Recorder(string fileName,
                        FourCC codec, int quality,
                        int audioSourceIndex, SupportedWaveFormat audioWaveFormat, bool encodeAudio, int audioBitRate, Size size)
        {
            screenWidth  = size.Width;
            screenHeight = size.Height;

            // Create AVI writer and specify FPS
            writer = new AviWriter(fileName)
            {
                FramesPerSecond = 10,
                EmitIndex1      = true,
            };

            // Create video stream
            videoStream = CreateVideoStream(codec, quality);
            // Set only name. Other properties were when creating stream,
            // either explicitly by arguments or implicitly by the encoder used
            videoStream.Name = "Screencast";

            if (audioSourceIndex >= 0)
            {
                var waveFormat = ToWaveFormat(audioWaveFormat);

                audioStream = CreateAudioStream(waveFormat, encodeAudio, audioBitRate);
                // Set only name. Other properties were when creating stream,
                // either explicitly by arguments or implicitly by the encoder used
                audioStream.Name = "Voice";

                audioSource = new WaveInEvent
                {
                    DeviceNumber = audioSourceIndex,
                    WaveFormat   = waveFormat,
                    // Buffer size to store duration of 1 frame
                    BufferMilliseconds = (int)Math.Ceiling(1000 / writer.FramesPerSecond),
                    NumberOfBuffers    = 3,
                };
                audioSource.DataAvailable += audioSource_DataAvailable;
            }

            screenThread = new Thread(RecordScreen)
            {
                Name         = typeof(Recorder).Name + ".RecordScreen",
                IsBackground = true
            };

            if (audioSource != null)
            {
                videoFrameWritten.Set();
                audioBlockWritten.Reset();
                audioSource.StartRecording();
            }
            screenThread.Start();
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Format a FourCC code
        /// </summary>
        /// <param name="fcc">The FourCC code</param>
        /// <returns>A string for the FourCC code</returns>
        public static string FormatFourCC(FourCC fcc)
        {
            uint code = (uint)fcc;

            return(string.Format(
                       "{0}{1}{2}{3}",
                       (char)(code & 0xFF),
                       (char)((code >> 8) & 0xFF),
                       (char)((code >> 16) & 0xFF),
                       (char)((code >> 24) & 0xFF)));
        }
Ejemplo n.º 33
0
        public IActionResult OutputMovie(OutputRequest req)
        {
            if (!ServerData.ProjectList.ContainsKey(req.Uuid))
            {
                return(NotFound());
            }

            Movie.OutputMovie(Path.Combine(PileditSystem.AppLocation, "output"), req.Extention,
                              FourCC.FromString(req.FourCC), ServerData.ProjectList[req.Uuid]);
            return(Ok());
        }
Ejemplo n.º 34
0
        public RecorderParams(string filename, int FrameRate, FourCC Encoder, int Quality, int screen)
        {
            FileName        = filename;
            FramesPerSecond = FrameRate;
            Codec           = Encoder;
            this.Quality    = Quality;

            CurrentScreen = Screen.AllScreens[screen];
            Height        = CurrentScreen.Bounds.Height;
            Width         = CurrentScreen.Bounds.Width;
        }
Ejemplo n.º 35
0
        private void InitDefaultSettings()
        {
            outputFolder = Interfaces.Extensions.MyVideos;

            encoder         = KnownFourCCs.Codecs.MotionJpeg;
            encodingQuality = 70;

            audioSourceIndex = -1;
            audioWaveFormat  = SupportedWaveFormat.WAVE_FORMAT_44M16;
            encodeAudio      = true;
            audioQuality     = (Mp3AudioEncoderLame.SupportedBitRates.Length + 1) / 2;
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Pushes a fourcc object onto the stack, and writes out the code
        /// and the stream position.
        /// </summary>
        /// <param name="fourCC"></param>
        /// <param name="bw"></param>
        public void Push(string code)
        {
            FourCC fourCC = new FourCC(code.ToCharArray(0, 4), (int)mBinaryWriter.BaseStream.Position);
            mFourCCStack.Push(fourCC);

            // Since Windows little endian, the correct int representation is the reverse of the fourcc.
            int intCode = System.BitConverter.ToInt32(new byte[] { (byte)fourCC.mFourCC[3], (byte)fourCC.mFourCC[2], (byte)fourCC.mFourCC[1], (byte)fourCC.mFourCC[0] }, 0);

            // Write out the intcode.  The binary writer will write the code out to the appropriate endianness.
            mBinaryWriter.Write(intCode);

            mBinaryWriter.Write(0); // size placeholder
        }
Ejemplo n.º 37
0
        public AviVideoStream(int index, IAviStreamWriteHandler writeHandler, 
            int width, int height, BitsPerPixel bitsPerPixel)
            : base(index)
        {
            Contract.Requires(index >= 0);
            Contract.Requires(writeHandler != null);
            Contract.Requires(width > 0);
            Contract.Requires(height > 0);
            Contract.Requires(Enum.IsDefined(typeof(BitsPerPixel), bitsPerPixel));

            this.writeHandler = writeHandler;
            this.width = width;
            this.height = height;
            this.bitsPerPixel = bitsPerPixel;
            this.streamCodec = KnownFourCCs.Codecs.Uncompressed;
        }
Ejemplo n.º 38
0
 public void Parse(Stream s)
 {
     BinaryReader r = new BinaryReader(s);
     uint size = r.ReadUInt32();
     if (size != this.size) throw new InvalidDataException(string.Format("Expected size: 0x{0:X8}, read 0x{1:X8}", this.size, size));
     //this.pixelFormatFlag = (PixelFormatFlags)r.ReadUInt32();
     //if ((this.pixelFormatFlag & PixelFormatFlags.FourCC) != PixelFormatFlags.FourCC) throw new InvalidDataException("Bad pixel format flag");
     uint pixelFormatFlag = r.ReadUInt32();
     if (!Enum.IsDefined(typeof(PixelFormatFlags), pixelFormatFlag)) throw new InvalidDataException("Bad pixel format flag"); else this.pixelFormatFlag = (PixelFormatFlags) pixelFormatFlag;
     uint fourCC = r.ReadUInt32();
     if (!Enum.IsDefined(typeof(FourCC), fourCC)) throw new InvalidDataException(string.Format("Unexpected data, read 0x{0:X8}", fourCC)); else this.fourcc = (FourCC)fourCC;
     this.RGBBitCount = r.ReadUInt32();
     this.redBitMask = r.ReadUInt32();
     this.greenBitMask = r.ReadUInt32();
     this.blueBitMask = r.ReadUInt32();
     this.alphaBitMask = r.ReadUInt32();
 }
Ejemplo n.º 39
0
        //try to evaluate the xna compatible surface for the present data
        private static SurfaceFormat SurfaceFormatFromLoadFormat(LoadSurfaceFormat loadSurfaceFormat, FourCC compressionFormat, uint pixelFlags, int rgbBitCount)
        {
            if (loadSurfaceFormat == LoadSurfaceFormat.Unknown)
            {
                switch (compressionFormat)
                {
                    case FourCC.D3DFMT_DXT1:
                        return SurfaceFormat.Dxt1;
                    case FourCC.D3DFMT_DXT3:
                        return SurfaceFormat.Dxt3;
                    case FourCC.D3DFMT_DXT5:
                        return SurfaceFormat.Dxt5;
                    case 0:
                        if (rgbBitCount == 8)
                        {
                            return SurfaceFormat.Alpha8;
                        }
                        if (rgbBitCount == 16)
                        {
                            if (HasAlphaTest(pixelFlags))
                            {
                                return SurfaceFormat.Bgr565;
                            }
                            else
                            {
                                return SurfaceFormat.Bgra4444;
                            }
                        }
                        if (rgbBitCount == 32 || rgbBitCount == 24)
                        {
                            return SurfaceFormat.Color;
                        }
                        break;
                    default:
                        throw new Exception("Unsuported format");
                }
            }
            else
            {
                switch (loadSurfaceFormat)
                {
                    case LoadSurfaceFormat.Alpha8:
                        return SurfaceFormat.Alpha8;
                    case LoadSurfaceFormat.Bgr565:
                        return SurfaceFormat.Bgr565;
                    case LoadSurfaceFormat.Bgra4444:
                        return SurfaceFormat.Bgra4444;
                    case LoadSurfaceFormat.Bgra5551:
                        return SurfaceFormat.Bgra5551;
                    case LoadSurfaceFormat.A8R8G8B8:
                        return SurfaceFormat.Color;
                    case LoadSurfaceFormat.Dxt1:
                        return SurfaceFormat.Dxt1;
                    case LoadSurfaceFormat.Dxt3:
                        return SurfaceFormat.Dxt3;
                    case LoadSurfaceFormat.Dxt5:
                        return SurfaceFormat.Dxt5;
                    //Updated at load time to X8R8B8B8
                    case LoadSurfaceFormat.R8G8B8:
                        return SurfaceFormat.Color;
                    case LoadSurfaceFormat.X8B8G8R8:
                        return SurfaceFormat.Color;
                    case LoadSurfaceFormat.X8R8G8B8:
                        return SurfaceFormat.Color;
                    case LoadSurfaceFormat.A8B8G8R8:
                        return SurfaceFormat.Color;
                    case LoadSurfaceFormat.R32F:
                        return SurfaceFormat.Single;
                    case LoadSurfaceFormat.A32B32G32R32F:
                        return SurfaceFormat.Vector4;
                    case LoadSurfaceFormat.G32R32F:
                        return SurfaceFormat.Vector2;
                    case LoadSurfaceFormat.R16F:
                        return SurfaceFormat.HalfSingle;
                    case LoadSurfaceFormat.G16R16F:
                        return SurfaceFormat.HalfVector2;
                    case LoadSurfaceFormat.A16B16G16R16F:
                        return SurfaceFormat.HalfVector4;
                    case LoadSurfaceFormat.CxV8U8:
                        return SurfaceFormat.NormalizedByte2;
                    case LoadSurfaceFormat.Q8W8V8U8:
                        return SurfaceFormat.NormalizedByte4;
                    case LoadSurfaceFormat.G16R16:
                        return SurfaceFormat.Rg32;
                    case LoadSurfaceFormat.A2B10G10R10:
                        return SurfaceFormat.Rgba1010102;
                    case LoadSurfaceFormat.A16B16G16R16:
                        return SurfaceFormat.Rgba64;
                    default:
                        throw new Exception(loadSurfaceFormat.ToString() + " is an unsuported format");
                }
            }

            throw new Exception("Unsuported format");
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Read the container header section. (The 'RIFF' or 'LIST' header.)
        /// This method verifies the header is well-formed and caches the
        /// container'stream FOURCC type.
        /// </summary>
        private void ReadRiffHeader()
        {
            RiffChunk header = new RiffChunk();

            // Riff chunks must be WORD aligned
            if (!IsAligned(this.containerOffset, 2))
            {
                throw new InvalidOperationException("The chunk is not aligned");
            }

            // Offset must be positive.
            if (this.containerOffset < 0)
            {
                throw new InvalidOperationException("The container offset needs to be positive");
            }

            // Seek to the start of the container.
            this.stream.Position = this.containerOffset;

            // Read the header
            header.FCC = (FourCC)this.br.ReadUInt32();
            header.Size = this.br.ReadUInt32();
            header.FCCList = (FourCC)this.br.ReadUInt32();

            // Make sure the header ID matches what the caller expected.
            if (header.FCC != this.fccId)
            {
                throw new InvalidOperationException("We don't have the right FourCC code");
            }

            // The size given in the RIFF header does not include the 8-byte header.
            // However, our _containerOffset is the offset from the start of the
            // header. Therefore our container size = listed size + size of header.
            this.containerSize = header.Size + SizeOfRiffChunk;
            this.fccType = header.FCCList;

            this.currentChunkOffset = this.containerOffset + SizeOfRiffList;

            this.ReadChunkHeader();
        }
Ejemplo n.º 41
0
 /// <summary>
 /// Format a FourCC code
 /// </summary>
 /// <param name="fcc">The FourCC code</param>
 /// <returns>A string for the FourCC code</returns>
 public static string FormatFourCC(FourCC fcc)
 {
     uint code = (uint)fcc;
     return string.Format(
         "{0}{1}{2}{3}",
         (char)(code & 0xFF),
         (char)((code >> 8) & 0xFF),
         (char)((code >> 16) & 0xFF),
         (char)((code >> 24) & 0xFF));
 }
Ejemplo n.º 42
0
        /// <summary>
        /// Initializes a new instance of the RiffParser class.
        /// </summary>
        /// <param name="stream">The stream that we will parse</param>
        /// <param name="id">The primary Riff ID that we need</param>
        /// <param name="startOfContainer">The start offset of the container in the stream</param>
        public RiffParser(Stream stream, FourCC id, long startOfContainer)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            this.fccId = id;
            this.containerOffset = startOfContainer;

            this.stream = stream;
            this.br = new BinaryReader(stream);

            this.ReadRiffHeader();
        }
Ejemplo n.º 43
0
        /// <summary>
        /// ビデオライタを開く
        /// </summary>
        /// <param name="fileName">出力するビデオファイルの名前</param>
        /// <param name="fourcc">
        /// フレームを圧縮するためのコーデックを表す 4 文字.例えば,"PIM1" は,MPEG-1 コーデック, "MJPG" は,motion-jpeg コーデックである. 
        /// Win32 環境下では,null を渡すとダイアログから圧縮方法と圧縮のパラメータを選択できるようになる. 
        /// </param>
        /// <param name="fps">作成されたビデオストリームのフレームレート</param>
        /// <param name="frameSize">ビデオフレームのサイズ</param>
        /// <param name="isColor">trueの場合,エンコーダはカラーフレームとしてエンコードする. falseの場合,グレースケールフレームとして動作する(現在のところ,このフラグは Windows でのみ利用できる).</param>
        /// <returns>CvVideoWriter</returns>
#else
        /// <summary>
        /// Creates video writer structure. 
        /// </summary>
        /// <param name="fileName">Name of the output video file. </param>
        /// <param name="fourcc">4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. 
        /// Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog. </param>
        /// <param name="fps">Framerate of the created video stream. </param>
        /// <param name="frameSize">Size of video frames. </param>
        /// <param name="isColor">If it is true, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only). </param>
        /// <returns></returns>
#endif
        public void Open(string fileName, FourCC fourcc, double fps, Size frameSize, bool isColor = true)
        {
            Open(fileName, (int)fourcc, fps, frameSize, isColor);
        }
Ejemplo n.º 44
0
        //Get pixel format from hader.
        private static LoadSurfaceFormat GetLoadSurfaceFormat(uint pixelFlags, uint pixelFourCC, int bitCount, uint rBitMask, uint gBitMask, uint bBitMask, uint aBitMask, FourCC compressionFormat)
        {
            FourCC givenFourCC = (FourCC)pixelFourCC;

            if (givenFourCC == FourCC.D3DFMT_A16B16G16R16)
            {
                return LoadSurfaceFormat.A16B16G16R16;
            }

            if (givenFourCC == FourCC.D3DFMT_G32R32F)
            {
                return LoadSurfaceFormat.G32R32F;
            }

            if (givenFourCC == FourCC.D3DFMT_G16R16F)
            {
                return LoadSurfaceFormat.G16R16F;
            }

            if (givenFourCC == FourCC.D3DFMT_Q8W8V8U8)
            {
                //This is true if the file was generated with the nvidia tools.
                return LoadSurfaceFormat.Q8W8V8U8;
            }

            if (givenFourCC == FourCC.D3DFMT_CxV8U8)
            {
                return LoadSurfaceFormat.CxV8U8;
            }

            if (givenFourCC == FourCC.D3DFMT_A16B16G16R16F)
            {
                return LoadSurfaceFormat.A16B16G16R16F;
            }

            if (givenFourCC == FourCC.D3DFMT_A32B32G32R32F)
            {
                return LoadSurfaceFormat.A32B32G32R32F;
            }

            if (givenFourCC == FourCC.D3DFMT_R32F)
            {
                return LoadSurfaceFormat.R32F;
            }

            if (givenFourCC == FourCC.D3DFMT_R16F)
            {
                return LoadSurfaceFormat.R16F;
            }

            if ((pixelFlags & DDPF_FOURCC) != 0)
            {
                //The texture is compressed(Dxt1,Dxt3/Dxt2,Dxt5/Dxt4).
                if (pixelFourCC == 0x31545844)
                {
                    return LoadSurfaceFormat.Dxt1;
                }
                if (pixelFourCC == 0x33545844 || pixelFourCC == 0x32545844)
                {
                    return LoadSurfaceFormat.Dxt3;
                }
                if (pixelFourCC == 0x35545844 || pixelFourCC == 0x34545844)
                {
                    return LoadSurfaceFormat.Dxt5;
                }
            }

            if ((pixelFlags & DDPF_RGB) != 0)
            {
                if (pixelFlags == 0x40 &&
                    bitCount == 0x00000010 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0x00007c00 &&
                    gBitMask == 0x000003e0 &&
                    bBitMask == 0x0000001f &&
                    aBitMask == 0x00000000)
                {
                    return LoadSurfaceFormat.RGB555;
                }

                if (pixelFlags == 0x41 &&
                    bitCount == 0x20 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0xff0000 &&
                    gBitMask == 0xff00 &&
                    bBitMask == 0xff &&
                    aBitMask == 0xff000000)
                {
                    return LoadSurfaceFormat.A8R8G8B8;
                }

                if (pixelFlags == 0x40 &&
                    bitCount == 0x20 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0xff0000 &&
                    gBitMask == 0xff00 &&
                    bBitMask == 0xff &&
                    aBitMask == 0)
                {
                    //DDS_FORMAT_X8R8G8B8
                    return LoadSurfaceFormat.X8R8G8B8;
                }

                if (pixelFlags == 0x41 &&
                    bitCount == 0x20 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0xff &&
                    gBitMask == 0xff00 &&
                    bBitMask == 0xff0000 &&
                    aBitMask == 0xff000000)
                {
                    //DDS_FORMAT_A8B8G8R8
                    return LoadSurfaceFormat.A8B8G8R8;
                }

                if (pixelFlags == 0x40 &&
                    bitCount == 0x20 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0xff &&
                    gBitMask == 0xff00 &&
                    bBitMask == 0xff0000 &&
                    aBitMask == 0)
                {
                    //DDS_FORMAT_X8B8G8R8
                    return LoadSurfaceFormat.X8B8G8R8;
                }

                if (pixelFlags == 0x41 &&
                    bitCount == 0x10 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0x7c00 &&
                    gBitMask == 0x3e0 &&
                    bBitMask == 0x1f &&
                    aBitMask == 0x8000)
                {
                    return LoadSurfaceFormat.Bgra5551;
                }

                if (pixelFlags == 0x41 &&
                    bitCount == 0x10 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0xf00 &&
                    gBitMask == 240 &&
                    bBitMask == 15 &&
                    aBitMask == 0xf000)
                {
                    return LoadSurfaceFormat.Bgra4444;
                }

                if (pixelFlags == 0x40 &&
                    bitCount == 0x18 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0xff0000 &&
                    gBitMask == 0xff00 &&
                    bBitMask == 0xff &&
                    aBitMask == 0)
                {
                    //DDS_FORMAT_R8G8B8
                    return LoadSurfaceFormat.R8G8B8;
                }

                if (pixelFlags == 0x40 &&
                    bitCount == 0x10 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0xf800 &&
                    gBitMask == 0x7e0 &&
                    bBitMask == 0x1f &&
                    aBitMask == 0)
                {
                    return LoadSurfaceFormat.Bgr565;
                }

                if (pixelFlags == 2 &&
                    bitCount == 8 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0 &&
                    gBitMask == 0 &&
                    bBitMask == 0 &&
                    aBitMask == 255)
                {
                    return LoadSurfaceFormat.Alpha8;
                }

                if (pixelFlags == 0x40 &&
                    bitCount == 32 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0x0000ffff &&
                    gBitMask == 0xffff0000 &&
                    bBitMask == 0 &&
                    aBitMask == 0)
                {
                    return LoadSurfaceFormat.G16R16;
                }

                if (pixelFlags == 0x41 &&
                    bitCount == 32 &&
                    pixelFourCC == 0 &&
                    rBitMask == 0x3ff00000 &&
                    gBitMask == 0x000ffc00 &&
                    bBitMask == 0x000003ff &&
                    aBitMask == 0xc0000000)
                {
                    return LoadSurfaceFormat.A2B10G10R10;
                }
            }

            //We consider the standard dx pixelFourCC + pixelFourCC == 63(nvidia tools generated dds)
            if (pixelFlags == 0x00080000 &&
                bitCount == 32 &&
                (pixelFourCC == 0 || pixelFourCC == 63) &&
                rBitMask == 0x000000ff &&
                gBitMask == 0x0000ff00 &&
                bBitMask == 0x00ff0000 &&
                aBitMask == 0xff000000)
            {
                return LoadSurfaceFormat.Q8W8V8U8;
            }

            return LoadSurfaceFormat.Unknown;
        }
Ejemplo n.º 45
0
        private void SelectSaveFormat()
        {
            if (Image.Format.IsCompressed || Image.ArraySize > 1)
            {
                PixelFlags = PixelFlagsEnum.FourCC;
                RGBBitCount = RBitMask = GBitMask = BBitMask = ABitMask = 0;

                if (Image.ArraySize == 1)
                {
                    //try to use DXT1/2/3

                    if (Image.Format.Name == "BC1_UNorm")
                    {
                        FourCC = new FourCC("DXT1");
                    }
                    else if (Image.Format.Name == "BC2_UNorm")
                    {
                        FourCC = new FourCC("DXT3");
                    }
                    else if (Image.Format.Name == "BC3_UNorm")
                    {
                        FourCC = new FourCC("DXT5");
                    }
                }
                else
                {
                    //use dx10
                    FourCC = new FourCC("DX10");
                    if (Enum.TryParse<DxgiFormat>(Image.Format.Name, out DxgiFormat))
                        return;
                }
            }
            else
            {
                //try plain formats
                if (Image.Format.Name == "R8G8B8A8_UNorm")
                {
                    PixelFlags = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
                    FourCC = new FourCC(0);
                    RGBBitCount = 32;
                    RBitMask = 0xff;
                    GBitMask = 0xff00;
                    BBitMask = 0xff0000;
                    ABitMask = unchecked((int)0xff000000);
                }
                else if (Image.Format.Name == "B5G6R5_UNorm")
                {
                    PixelFlags = PixelFlagsEnum.Rgb;
                    FourCC = new FourCC(0);
                    RGBBitCount = 15;
                    RBitMask = 0xf800;
                    GBitMask = 0x7e0;
                    BBitMask = 0x1f;
                    ABitMask = 0;
                }
                else if (Image.Format.Name == "B5G5R5A1_UNorm")
                {
                    PixelFlags = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
                    FourCC = new FourCC(0);
                    RGBBitCount = 15;
                    RBitMask = 0xf800;
                    GBitMask = 0x7e0;
                    BBitMask = 0x1f;
                    ABitMask = 0x8000;
                }
                else if (Image.Format.Name == "A8_UNorm")
                {
                    PixelFlags = PixelFlagsEnum.Alpha;
                    FourCC = new FourCC(0);
                    RGBBitCount = 8;
                    RBitMask = 0;
                    GBitMask = 0;
                    BBitMask = 0;
                    ABitMask = 0xff;
                }
                else
                {
                    //use dx10
                    FourCC = new FourCC("DX10");
                    if (Enum.TryParse<DxgiFormat>(Image.Format.Name, out DxgiFormat))
                        return;
                }
            }
            
            throw new NotSupportedException("Unsupported format.");
        }
Ejemplo n.º 46
0
        private void Load(Stream stream)
        {
            var reader = new Ibasa.IO.BinaryReader(stream, System.Text.Encoding.ASCII);

            FourCC signature = new FourCC(reader.ReadInt32());

            if (signature != new FourCC("DDS "))
                throw new InvalidDataException("File signature does not match 'DDS '.");

            int headerSize = reader.ReadInt32();
            if (headerSize != 124)
                throw new InvalidDataException(string.Format("Header size {0} does not match 124.", headerSize));

            ReadHeader(reader);
            ReadDx10Header(reader);
            FixupInternalState();
            Cubemap = CubemapFlags.HasFlag(CubemapFlagsEnum.Cubemap);
            ReadData(reader);
        }
Ejemplo n.º 47
0
        //new 3d-map texture
        private static Texture3D GenerateNewTexture3D(LoadSurfaceFormat loadSurfaceFormat, FourCC compressionFormat, GraphicsDevice device, int width, int height, int depth, bool hasMipMaps, uint pixelFlags, int rgbBitCount)
        {
            SurfaceFormat surfaceFormat = SurfaceFormatFromLoadFormat(loadSurfaceFormat, compressionFormat, pixelFlags, rgbBitCount);

            Texture3D tx = new Texture3D(device, width, height, depth, hasMipMaps, surfaceFormat);

            if (tx.Format != surfaceFormat)
            {
                throw new Exception("Can't generate a " + surfaceFormat.ToString() + " surface.");
            }

            return tx;
        }
Ejemplo n.º 48
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            Format = new FourCC(stream.ReadBytes(4));
        }
Ejemplo n.º 49
0
        /// <summary>
        /// ビデオライタを作成し、返す.
        /// </summary>
        /// <param name="fileName">出力するビデオファイルの名前</param>
        /// <param name="fourcc">
        /// フレームを圧縮するためのコーデックを表す 4 文字.例えば,"PIM1" は,MPEG-1 コーデック, "MJPG" は,motion-jpeg コーデックである. 
        /// Win32 環境下では,null を渡すとダイアログから圧縮方法と圧縮のパラメータを選択できるようになる. 
        /// </param>
        /// <param name="fps">作成されたビデオストリームのフレームレート</param>
        /// <param name="frameSize">ビデオフレームのサイズ</param>
        /// <param name="isColor">trueの場合,エンコーダはカラーフレームとしてエンコードする. falseの場合,グレースケールフレームとして動作する(現在のところ,このフラグは Windows でのみ利用できる).</param>
        /// <returns>CvVideoWriter</returns>
#else
        /// <summary>
        /// Creates video writer structure. 
        /// </summary>
        /// <param name="fileName">Name of the output video file. </param>
        /// <param name="fourcc">4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. 
        /// Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog. </param>
        /// <param name="fps">Framerate of the created video stream. </param>
        /// <param name="frameSize">Size of video frames. </param>
        /// <param name="isColor">If it is true, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only). </param>
        /// <returns></returns>
#endif
        public VideoWriter(string fileName, FourCC fourcc, double fps, Size frameSize, bool isColor = true)
            : this(fileName, (int)fourcc, fps, frameSize, isColor)
        {
        }
Ejemplo n.º 50
0
 private static VfwApi.BitmapInfoHeader CreateBitmapInfo(int width, int height, ushort bitCount, FourCC codec)
 {
     return new VfwApi.BitmapInfoHeader
     {
         SizeOfStruct = (uint)Marshal.SizeOf(typeof(VfwApi.BitmapInfoHeader)),
         Width = width,
         Height = height,
         BitCount = (ushort)bitCount,
         Planes = 1,
         Compression = (uint)codec,
     };
 }
Ejemplo n.º 51
0
        //Get the byte data from a mip-map level.
        private static void GetMipMaps(int offsetInStream, int map, bool hasMipMaps, int width, int height, bool isCompressed, FourCC compressionFormat, int rgbBitCount, bool partOfCubeMap, BinaryReader reader, LoadSurfaceFormat loadSurfaceFormat, ref byte[] data, out int numBytes)
        {
            int seek = 128 + offsetInStream;

            for (int i = 0; i < map; i++)
            {
                seek += MipMapSizeInBytes(i, width, height, isCompressed, compressionFormat, rgbBitCount);
            }

            reader.BaseStream.Seek(seek, SeekOrigin.Begin);

            numBytes = MipMapSizeInBytes(map, width, height, isCompressed, compressionFormat, rgbBitCount);

            if (isCompressed == false && rgbBitCount == 24)
            {
                numBytes += (numBytes / 3);
            }

            if (data == null || data.Length < numBytes)
            {
                data = new byte[numBytes];
            }

            if (isCompressed == false && loadSurfaceFormat == LoadSurfaceFormat.R8G8B8)
            {
                for (int i = 0; i < numBytes; i += 4)
                {
                    data[i] = reader.ReadByte();
                    data[i + 1] = reader.ReadByte();
                    data[i + 2] = reader.ReadByte();
                    data[i + 3] = 255;
                }
            }
            else
            {
                reader.Read(data, 0, numBytes);
            }

            if (loadSurfaceFormat == LoadSurfaceFormat.X8R8G8B8 || loadSurfaceFormat == LoadSurfaceFormat.X8B8G8R8)
            {
                for (int i = 0; i < numBytes; i += 4)
                {
                    data[i + 3] = 255;
                }
            }

            if (loadSurfaceFormat == LoadSurfaceFormat.A8R8G8B8 ||
                loadSurfaceFormat == LoadSurfaceFormat.X8R8G8B8 ||
                loadSurfaceFormat == LoadSurfaceFormat.R8G8B8)
            {
                int bytesPerPixel = (rgbBitCount == 32 || rgbBitCount == 24) ? 4 : 3;

                byte g, b;
                if (bytesPerPixel == 3)
                {
                    for (int i = 0; i < numBytes - 2; i += 3)
                    {
                        g = data[i];
                        b = data[i + 2];
                        data[i] = b;
                        data[i + 2] = g;
                    }
                }
                else
                {
                    for (int i = 0; i < numBytes - 3; i += 4)
                    {
                        g = data[i];
                        b = data[i + 2];
                        data[i] = b;
                        data[i + 2] = g;
                    }
                }
            }
        }
Ejemplo n.º 52
0
        //Write texture data to stream if the texture is a 2d texture the face is ignored.
        private static void WriteTexture(BinaryWriter writer, CubeMapFace face, Texture texture, int mipLevel, int depth, int width, int height, bool isCompressed, FourCC fourCC, int rgbBitCount)
        {
            int size = MipMapSizeInBytes(mipLevel, width, height, isCompressed, fourCC, rgbBitCount);
            byte[] data = mipData;
            if (data == null || data.Length < size)
            {
                data = new byte[size];
            }

            if (texture is TextureCube)
            {
                (texture as TextureCube).GetData<byte>(face, mipLevel, null, data, 0, size);
            }
            if (texture is Texture2D)
            {
                (texture as Texture2D).GetData<byte>(mipLevel, null, data, 0, size);
            }
            if (texture is Texture3D)
            {
                Texture3D tex = (texture as Texture3D);
                int localWidth = MipMapSize(mipLevel, width);
                int localHeight = MipMapSize(mipLevel, height);

                tex.GetData<byte>(mipLevel, 0, 0, localWidth, localHeight, depth, depth + 1, data, 0, size);
            }


#if COLOR_SAVE_TO_ARGB
            if (texture.Format == SurfaceFormat.Color)
            {
                byte g, b;
                for (int k = 0; k < size - 3; k += 4)
                {
                    g = data[k];
                    b = data[k + 2];
                    data[k] = b;
                    data[k + 2] = g;
                }
            }
#endif

            writer.Write(data, 0, size);
            //for (int j = 0; j < size; j++)
            //{
            //    writer.Write(data[j]);
            //}
            mipData = data;


        }
Ejemplo n.º 53
0
        /// <summary>
        /// ビデオライタを作成し、返す.
        /// </summary>
        /// <param name="filename">出力するビデオファイルの名前</param>
        /// <param name="fourcc">
        /// フレームを圧縮するためのコーデックを表す 4 文字.例えば,"PIM1" は,MPEG-1 コーデック, "MJPG" は,motion-jpeg コーデックである. 
        /// Win32 環境下では,null を渡すとダイアログから圧縮方法と圧縮のパラメータを選択できるようになる. 
        /// </param>
        /// <param name="fps">作成されたビデオストリームのフレームレート</param>
        /// <param name="frameSize">ビデオフレームのサイズ</param>
        /// <param name="isColor">trueの場合,エンコーダはカラーフレームとしてエンコードする. falseの場合,グレースケールフレームとして動作する(現在のところ,このフラグは Windows でのみ利用できる).</param>
        /// <returns>CvVideoWriter</returns>
#else
        /// <summary>
        /// Creates video writer structure. 
        /// </summary>
        /// <param name="filename">Name of the output video file. </param>
        /// <param name="fourcc">4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. 
        /// Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog. </param>
        /// <param name="fps">Framerate of the created video stream. </param>
        /// <param name="frameSize">Size of video frames. </param>
        /// <param name="isColor">If it is true, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only). </param>
        /// <returns></returns>
#endif
        public CvVideoWriter(string filename, FourCC fourcc, double fps, CvSize frameSize, bool isColor)
            : this(filename, (int)fourcc, fps, frameSize, isColor)
        {
        }
Ejemplo n.º 54
0
 long OpenRiff(FourCC listType, FourCC fourCC)
 {
     var result = OpenChunk(listType);
     writer.Write(fourCC);
     return result;
 }
Ejemplo n.º 55
0
        private void ReadHeader(Ibasa.IO.BinaryReader reader)
        {
            HeaderFlags = (HeaderFlagsEnum)reader.ReadInt32();
            Height = reader.ReadInt32();
            Width = reader.ReadInt32();
            Pitch = reader.ReadInt32();
            Depth = reader.ReadInt32();
            MipmapCount = reader.ReadInt32();
            reader.ReadBytes(44); //skip padding

            int pixelSize = reader.ReadInt32();
            if (pixelSize != 32)
                throw new InvalidDataException(string.Format("Pixel format size {0} does not match 32.", pixelSize));

            PixelFlags = (PixelFlagsEnum)reader.ReadInt32();
            FourCC = new FourCC(reader.ReadInt32());
            RGBBitCount = reader.ReadInt32();
            RBitMask = reader.ReadInt32();
            GBitMask = reader.ReadInt32();
            BBitMask = reader.ReadInt32();
            ABitMask = reader.ReadInt32();

            SurfaceFlags = (SurfaceFlagsEnum)reader.ReadInt32();
            CubemapFlags = (CubemapFlagsEnum)reader.ReadInt32();

            reader.ReadBytes(12); //skip padding
        }
Ejemplo n.º 56
0
 long OpenList(FourCC fourCC)
 {
     return OpenRiff(FourCC.List, fourCC);
 }
Ejemplo n.º 57
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            DataFormat = new FourCC(stream.ReadBEUInt32());
        }
Ejemplo n.º 58
0
        /// <summary>
        /// ビデオライタを作成し、返す.
        /// </summary>
        /// <param name="filename">出力するビデオファイルの名前</param>
        /// <param name="fourcc">
        /// フレームを圧縮するためのコーデックを表す 4 文字.例えば,"PIM1" は,MPEG-1 コーデック, "MJPG" は,motion-jpeg コーデックである. 
        /// Win32 環境下では,null を渡すとダイアログから圧縮方法と圧縮のパラメータを選択できるようになる. 
        /// </param>
        /// <param name="fps">作成されたビデオストリームのフレームレート</param>
        /// <param name="frameSize">ビデオフレームのサイズ</param>
        /// <returns>CvVideoWriter</returns>
#else
        /// <summary>
        /// Creates video writer structure. 
        /// </summary>
        /// <param name="filename">Name of the output video file. </param>
        /// <param name="fourcc">4-character code of codec used to compress the frames. For example, "PIM1" is MPEG-1 codec, "MJPG" is motion-jpeg codec etc. 
        /// Under Win32 it is possible to pass null in order to choose compression method and additional compression parameters from dialog. </param>
        /// <param name="fps">Framerate of the created video stream. </param>
        /// <param name="frameSize">Size of video frames. </param>
        /// <returns></returns>
#endif
        public CvVideoWriter(string filename, FourCC fourcc, double fps, CvSize frameSize)
            : this(filename, (int)fourcc, fps, frameSize, true)
        {
        }
Ejemplo n.º 59
0
        //Get the size in bytes for a mip-map level.
        private static int MipMapSizeInBytes(int map, int width, int height, bool isCompressed, FourCC compressionFormat, int depth)
        {
            width = MipMapSize(map, width);
            height = MipMapSize(map, height);

            //We hardcoded some compression formats as some flags are not set by all the tools for them,
            //as a result for this formats we must hardcode the outcome.
            if (compressionFormat == FourCC.D3DFMT_R32F)
            {
                return width * height * 4;
            }
            if (compressionFormat == FourCC.D3DFMT_R16F)
            {
                return width * height * 2;
            }
            if (compressionFormat == FourCC.D3DFMT_A32B32G32R32F)
            {
                return width * height * 16;
            }
            if (compressionFormat == FourCC.D3DFMT_A16B16G16R16F)
            {
                return width * height * 8;
            }
            if (compressionFormat == FourCC.D3DFMT_CxV8U8)
            {
                return width * height * 2;
            }
            if (compressionFormat == FourCC.D3DFMT_Q8W8V8U8)
            {
                return width * height * 4;
            }
            if (compressionFormat == FourCC.D3DFMT_G16R16F)
            {
                return width * height * 4;
            }
            if (compressionFormat == FourCC.D3DFMT_G32R32F)
            {
                return width * height * 8;
            }
            if (compressionFormat == FourCC.D3DFMT_A16B16G16R16)
            {
                return width * height * 8;
            }

            if (isCompressed)
            {
                int blockSize = (compressionFormat == FourCC.D3DFMT_DXT1 ? 8 : 16);
                return ((width + 3) / 4) * ((height + 3) / 4) * blockSize;
            }
            else
            {
                return width * height * (depth / 8);
            }
        }
Ejemplo n.º 60
0
        //Write texture data to stream if the texture is a 2d texture the face is ignored.
        private static void WriteTexture(BinaryWriter writer, CubeMapFace face, Texture texture, bool saveMipMaps, int width, int height, bool isCompressed, FourCC fourCC, int rgbBitCount)
        {
            int numMip = texture.LevelCount;
            numMip = saveMipMaps ? numMip : 1;

            for (int i = 0; i < numMip; i++)
            {
                int size = MipMapSizeInBytes(i, width, height, isCompressed, fourCC, rgbBitCount);
                byte[] data = mipData;
                if (data == null || data.Length < size)
                {
                    data = new byte[size];
                }

                if (texture is TextureCube)
                {
                    (texture as TextureCube).GetData<byte>(face, i, null, data, 0, size);
                }
                if (texture is Texture2D)
                {
                    (texture as Texture2D).GetData<byte>(i, null, data, 0, size);
                }


#if COLOR_SAVE_TO_ARGB
                if (texture.Format == SurfaceFormat.Color)
                {
                    byte g, b;
                    for (int k = 0; k < size - 3; k += 4)
                    {
                        g = data[k];
                        b = data[k + 2];
                        data[k] = b;
                        data[k + 2] = g;
                    }
                }
#endif

                writer.Write(data, 0, size);
                //for (int j = 0; j < size; j++)
                //{
                //    writer.Write(data[j]);
                //}
                mipData = data;
            }

        }