Beispiel #1
0
        public SpriteClip(BinaryReader reader, FileFormatVersion version)
            : this()
        {
            X = reader.ReadInt32();
            Y = reader.ReadInt32();
            SpriteNumber = reader.ReadInt32();
            MirrorOnVertical = reader.ReadInt32() > 0;

            if (version.Version >= 0x200) {
                // RGBA
                var c = reader.ReadBytes(4);
                Color = Color.FromArgb(c[3], c[0], c[1], c[2]);
                if (version.Version >= 0x204) {
                    ZoomX = reader.ReadInt32();
                    ZoomY = reader.ReadInt32();
                } else {
                    ZoomX = ZoomY = reader.ReadInt32();
                }

                Angle = reader.ReadInt32();
                SpriteType = reader.ReadInt32();
                if (version.Version >= 0x205) {
                    Width = reader.ReadInt32();
                    Height = reader.ReadInt32();
                }
            }
        }
Beispiel #2
0
        public SpriteClip(BinaryReader reader, FileFormatVersion version)
            : this()
        {
            X                = reader.ReadInt32();
            Y                = reader.ReadInt32();
            SpriteNumber     = reader.ReadInt32();
            MirrorOnVertical = reader.ReadInt32() > 0;

            if (version.Version >= 0x200)
            {
                // RGBA
                var c = reader.ReadBytes(4);
                Color = Color.FromArgb(c[3], c[0], c[1], c[2]);
                if (version.Version >= 0x204)
                {
                    ZoomX = reader.ReadInt32();
                    ZoomY = reader.ReadInt32();
                }
                else
                {
                    ZoomX = ZoomY = reader.ReadInt32();
                }

                Angle      = reader.ReadInt32();
                SpriteType = reader.ReadInt32();
                if (version.Version >= 0x205)
                {
                    Width  = reader.ReadInt32();
                    Height = reader.ReadInt32();
                }
            }
        }
Beispiel #3
0
        public AttachPoint(BinaryReader reader, FileFormatVersion version)
        {
            var ignored = reader.ReadInt32();

            X = reader.ReadInt32();
            Y = reader.ReadInt32();
            Attribute = reader.ReadInt32();
        }
Beispiel #4
0
 public FileFormatHeader(BinaryReader reader, char[] expectedMagicBytes = null)
 {
     _expectedMagicBytes = expectedMagicBytes;
     if (expectedMagicBytes != null) {
         MagicBytes = reader.ReadChars(expectedMagicBytes.Length);
     }
     Version = new FileFormatVersion(reader);
 }
Beispiel #5
0
        public AttachPoint(BinaryReader reader, FileFormatVersion version)
        {
            var ignored = reader.ReadInt32();

            X         = reader.ReadInt32();
            Y         = reader.ReadInt32();
            Attribute = reader.ReadInt32();
        }
Beispiel #6
0
 public FileFormatHeader(BinaryReader reader, char[] expectedMagicBytes = null)
 {
     _expectedMagicBytes = expectedMagicBytes;
     if (expectedMagicBytes != null)
     {
         MagicBytes = reader.ReadChars(expectedMagicBytes.Length);
     }
     Version = new FileFormatVersion(reader);
 }
Beispiel #7
0
        public Motion(BinaryReader reader, FileFormatVersion version)
            : this()
        {
            Range1 = new[] {
                reader.ReadInt32(),
                    reader.ReadInt32(),
                    reader.ReadInt32(),
                    reader.ReadInt32()
            };
            Range2 = new[] {
                reader.ReadInt32(),
                    reader.ReadInt32(),
                    reader.ReadInt32(),
                    reader.ReadInt32()
            };

            var spriteClipCount = reader.ReadInt32();

            for (var i = 0; i < spriteClipCount; i++)
            {
                SpriteClips.Add(new SpriteClip(reader, version));
            }

            // Events
            if (version.Version >= 0x200)
            {
                EventId = reader.ReadInt32();
                // No array of events in this version
                if (version.Version == 0x200)
                {
                    EventId = -1;
                }
            }

            // Attach points
            if (version.Version >= 0x203)
            {
                var attachPointCount = reader.ReadInt32();
                for (var i = 0; i < attachPointCount; i++)
                {
                    AttachPoints.Add(new AttachPoint(reader, version));
                }
            }
        }
Beispiel #8
0
        public Motion(BinaryReader reader, FileFormatVersion version)
            : this()
        {
            Range1 = new[] {
                reader.ReadInt32(),
                reader.ReadInt32(),
                reader.ReadInt32(),
                reader.ReadInt32()
            };
            Range2 = new[] {
                reader.ReadInt32(),
                reader.ReadInt32(),
                reader.ReadInt32(),
                reader.ReadInt32()
            };

            var spriteClipCount = reader.ReadInt32();
            for (var i = 0; i < spriteClipCount; i++) {
                SpriteClips.Add(new SpriteClip(reader, version));
            }

            // Events
            if (version.Version >= 0x200) {
                EventId = reader.ReadInt32();
                // No array of events in this version
                if (version.Version == 0x200) {
                    EventId = -1;
                }
            }

            // Attach points
            if (version.Version >= 0x203) {
                var attachPointCount = reader.ReadInt32();
                for (var i = 0; i < attachPointCount; i++) {
                    AttachPoints.Add(new AttachPoint(reader, version));
                }
            }
        }
Beispiel #9
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (Cookie != null ? Cookie.GetHashCode() : 0);
         result = (result * 397) ^ Features.GetHashCode();
         result = (result * 397) ^ (FileFormatVersion != null ? FileFormatVersion.GetHashCode() : 0);
         result = (result * 397) ^ HeaderOffset.GetHashCode();
         result = (result * 397) ^ TimeStamp.GetHashCode();
         result = (result * 397) ^ (CreatorApplication != null ? CreatorApplication.GetHashCode() : 0);
         result = (result * 397) ^ (CreatorVersion != null ? CreatorVersion.GetHashCode() : 0);
         result = (result * 397) ^ CreatorHostOsType.GetHashCode();
         result = (result * 397) ^ PhsyicalSize.GetHashCode();
         result = (result * 397) ^ VirtualSize.GetHashCode();
         result = (result * 397) ^ (DiskGeometry != null ? DiskGeometry.GetHashCode() : 0);
         result = (result * 397) ^ DiskType.GetHashCode();
         result = (result * 397) ^ CheckSum.GetHashCode();
         result = (result * 397) ^ UniqueId.GetHashCode();
         result = (result * 397) ^ SavedState.GetHashCode();
         result = (result * 397) ^ (Reserved != null ? Reserved.GetHashCode() : 0);
         result = (result * 397) ^ (RawData != null ? RawData.GetHashCode() : 0);
         return(result);
     }
 }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlpFile"/> class.
        /// </summary>
        /// <param name="stream">A <see cref="Stream"/> that contains the BLP file.</param>
        public BlpFile(Stream stream)
        {
            _baseStream = stream;

            using (var reader = new BinaryReader(_baseStream, Encoding.ASCII, true))
            {
                // Checking for correct Magic-Code
                _fileFormatVersion = (FileFormatVersion)reader.ReadUInt32();
                if (!Enum.IsDefined(typeof(FileFormatVersion), _fileFormatVersion))
                {
                    throw new Exception("Invalid BLP Format.");
                }

                if (_fileFormatVersion == FileFormatVersion.BLP0)
                {
                    throw new NotSupportedException("Unable to open BLP0 file.");
                }

                // Reading type
                _formatVersion = (FileContent)reader.ReadUInt32();
                if (!Enum.IsDefined(typeof(FileContent), _formatVersion))
                {
                    throw new Exception("Invalid content type.");
                }

                if (_fileFormatVersion == FileFormatVersion.BLP2)
                {
                    // Reading _colorEncoding, _alphaDepth, _alphaEncoding, and _hasMipMaps.
                    _colorEncoding = reader.ReadByte();
                    _alphaDepth    = reader.ReadByte();
                    _alphaEncoding = reader.ReadByte();
                    _hasMipMaps    = reader.ReadByte();
                }
                else
                {
                    // Should be 0, 1, 4, or 8, and default to 0 if invalid.
                    _alphaDepth = reader.ReadUInt32();

                    if (_formatVersion != FileContent.JPG)
                    {
                        _colorEncoding = 1;
                    }
                }

                // Reading width and height
                _width  = (int)reader.ReadUInt32();
                _height = (int)reader.ReadUInt32();

                if (_fileFormatVersion != FileFormatVersion.BLP2)
                {
                    // http://www.wc3c.net/tools/specs/
                    // flag for alpha channel and team colors (usually 3, 4 or 5)
                    // 3 and 4 means color and alpha information for paletted files
                    // 5 means only color information, if >=5 on 'unit' textures, it won't show the team color.
                    _extra      = reader.ReadUInt32();
                    _hasMipMaps = reader.ReadUInt32();
                }

                const int mipMaps = 16;
                _mipMapCount = 0;

                // Reading MipMapOffset Array
                _mipMapOffsets = new uint[mipMaps];
                for (var i = 0; i < mipMaps; i++)
                {
                    _mipMapOffsets[i] = reader.ReadUInt32();

                    if (_mipMapOffsets[i] != 0)
                    {
                        _mipMapCount++;
                    }
                }

                // Reading MipMapSize Array
                _mipMapSizes = new uint[mipMaps];
                for (var i = 0; i < mipMaps; i++)
                {
                    _mipMapSizes[i] = reader.ReadUInt32();
                }

                // When encoding is 1, there is no image compression and we have to read a color palette
                // This palette always exists when the formatVersion is set to FileContent.Direct, even when it's not used.
                if (_colorEncoding == 1)
                {
                    const int paletteSize = 256;
#if SkiaSharpColorPalette
                    _colorPalette = new SKColor[paletteSize];
#else
                    _colorPalette = new uint[paletteSize];
#endif

                    // Reading palette
                    for (var i = 0; i < paletteSize; i++)
                    {
#if SkiaSharpColorPalette
                        _colorPalette[i] = new SKColor(reader.ReadUInt32());
#else
                        _colorPalette[i] = reader.ReadUInt32();
#endif
                    }
                }
                else if (_fileFormatVersion == FileFormatVersion.BLP1 && _formatVersion == FileContent.JPG)
                {
                    var jpgHeaderSize = reader.ReadUInt32(); // max 624 bytes
                    _jpgHeaderData = reader.ReadBytes((int)jpgHeaderSize);
                }
            }
        }
 /// <summary>
 /// Serialize the data into byte data.
 /// </summary>
 /// <returns>Byte data.</returns>
 public override byte[] GetBytes()
 {
     return(GetBytes(AttributeUse.Bytes(),
                     SimpleTypeIndex.Bytes(),
                     FileFormatVersion.Bytes()));
 }
Beispiel #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlpFile"/> class.
        /// </summary>
        /// <param name="stream">A <see cref="Stream"/> that contains the BLP file.</param>
        public BlpFile(Stream stream)
        {
            _baseStream = stream;

            using (var reader = new BinaryReader(_baseStream, Encoding.ASCII, true))
            {
                // Checking for correct Magic-Code
                _fileFormatVersion = (FileFormatVersion)reader.ReadUInt32();
                if (!Enum.IsDefined(typeof(FileFormatVersion), _fileFormatVersion))
                {
                    throw new Exception("Invalid BLP Format.");
                }

                if (_fileFormatVersion == FileFormatVersion.BLP0)
                {
                    throw new NotSupportedException("Unable to open BLP0 file.");
                }

                // Reading type
                _formatVersion = (FileContent)reader.ReadUInt32();
                if (!Enum.IsDefined(typeof(FileContent), _formatVersion))
                {
                    throw new Exception("Invalid content type.");
                }

                if (_fileFormatVersion == FileFormatVersion.BLP2)
                {
                    // Reading _colorEncoding, _alphaDepth, _alphaEncoding, and _hasMipMaps.
                    _colorEncoding = reader.ReadByte();
                    _alphaDepth    = reader.ReadByte();
                    _alphaEncoding = reader.ReadByte();
                    _hasMipMaps    = reader.ReadByte();
                }
                else
                {
                    // Should be 0, 1, 4, or 8, and default to 0 if invalid.
                    _alphaDepth = reader.ReadUInt32();

                    if (_formatVersion == FileContent.JPG)
                    {
                        if (_alphaDepth != 0 && _alphaDepth != 8)
                        {
                            throw new NotSupportedException();
                        }
                    }
                    else
                    {
                        _colorEncoding = 1;
                    }
                }

                // Reading width and height
                _width  = (int)reader.ReadUInt32();
                _height = (int)reader.ReadUInt32();

                if (_fileFormatVersion != FileFormatVersion.BLP2)
                {
                    _extra      = reader.ReadUInt32(); // usually 5
                    _hasMipMaps = reader.ReadUInt32();
                }

                const int mipMaps = 16;
                _mipMapCount = 0;

                // Reading MipMapOffset Array
                _mipMapOffsets = new uint[mipMaps];
                for (var i = 0; i < mipMaps; i++)
                {
                    _mipMapOffsets[i] = reader.ReadUInt32();

                    if (_mipMapOffsets[i] != 0)
                    {
                        _mipMapCount++;
                    }
                }

                // Reading MipMapSize Array
                _mipMapSizes = new uint[mipMaps];
                for (var i = 0; i < mipMaps; i++)
                {
                    _mipMapSizes[i] = reader.ReadUInt32();
                }

                // When encoding is 1, there is no image compression and we have to read a color palette
                // This palette always exists when the formatVersion is set to FileContent.Direct, even when it's not used.
                if (_colorEncoding == 1)
                {
                    const int paletteSize = 256;
                    _colorPalette = new SKColor[paletteSize];

                    // Reading palette
                    for (var i = 0; i < paletteSize; i++)
                    {
                        _colorPalette[i] = new SKColor(reader.ReadUInt32());
                    }
                }
                else if (_fileFormatVersion == FileFormatVersion.BLP1 && _formatVersion == FileContent.JPG)
                {
                    var jpgHeaderSize = reader.ReadUInt32(); // max 624 bytes
                    _jpgHeaderData = new byte[jpgHeaderSize];
                    for (var i = 0; i < jpgHeaderSize; i++)
                    {
                        _jpgHeaderData[i] = reader.ReadByte();
                    }
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// 全レコードをタブ区切り形式テキストを生成して返す
        /// </summary>
        /// <returns>タグ区切りテキスト</returns>
        public string ToString(bool WithSpeakerLabel = false, FileFormatVersion version = FileFormatVersion.Type2)
        {
            string result = "";

            //JsonJSのヘッダー
            if (version == FileFormatVersion.JsonJS)
            {
                result += "const scriptsJson = [\r\n";
            }

            List <Dogagan_Record> sortedRecords = _records.OrderBy(r => r.TimeStamp).ToList();

            foreach (var r in sortedRecords)
            {
                switch (version)
                {
                case FileFormatVersion.Type1:
                    //動画眼1.x形式(タイムスタンプが00:00:00形式)
                    var span = new TimeSpan(0, 0, (int)r.TimeStamp);
                    result += span.ToString(@"hh\:mm\:ss") + "\t";
                    if (WithSpeakerLabel == true)
                    {
                        result += r.Speaker + " 「" + r.Transcript + "」";
                    }
                    else
                    {
                        result += r.Transcript;
                    }
                    break;

                case FileFormatVersion.JsonJS:
                    //動画眼Lite用のJSON形式を含むJSファイル。SpeakerLabelは強制で付与
                    result += "\t{ in:" + r.TimeStamp + ", script:\"" + r.Transcript.Replace("\"", "\\\"") + "\", speaker:" + r.Speaker + " },";
                    break;

                default:
                    //動画眼2.x形式(タイムスタンプそのまま、話者フィールド対応)
                    result += r.TimeStamp;
                    if (WithSpeakerLabel)
                    {
                        //話者ラベル、「」あり
                        result += "\t" + r.Speaker + " 「" + r.Transcript + "」";
                    }
                    else
                    {
                        result += "\t" + r.Transcript;
                    }
                    result += "\t" + r.Speaker;
                    break;
                }
                result += "\r\n";
            }

            //JsonJSのフッター処理
            if (version == FileFormatVersion.JsonJS)
            {
                //最終行のカンマを削除
                result = result.Substring(0, result.Length - 3); //末尾のカンマ、\r、\nの3文字を削る

                result += "\r\n];";
            }

            return(result);
        }