コード例 #1
0
 protected override void Convert(String sourceName, ArraySegment <Byte> sourceData, String target)
 {
     using (MemoryStream ms = new MemoryStream(sourceData.Array, sourceData.Offset, sourceData.Count))
         using (FileStream output = File.Create(target))
         {
             UnsafeList <Byte>   result = _reader.Read(sourceName, ms);
             ArraySegment <Byte> buff   = result.GetBuffer();
             output.Write(buff.Array, buff.Offset, buff.Count);
         }
 }
コード例 #2
0
ファイル: ImageSource.cs プロジェクト: Albeoris/Septerra
        private UnsafeList <Byte> Read()
        {
            _reader = new TiffReader(_tiff);

            (Int32 animationType, AMAnimation[] animations, AMFrame[] frames) = GetMetadata(_tiff);

            try
            {
                ReadPages();

                _header.AnimationType = animationType;

                _header.AnimationCount    = animations.Length;
                _header.FrameCount        = frames.Length;
                _header.PaletteCount      = _palettes.Count;
                _header.ImageHeaderCount  = _images.Count;
                _header.ImageContentSize  = (Int32)_content.Length;
                _header.ImageSegmentCount = _segments.Count;
                _header.ImageLineCount    = _lines.Count;

                unsafe
                {
                    _result.SetPosition(sizeof(AMHeader));

                    _header.AnimationOffset = CurrentPosition;
                    _result.WriteStructs(animations);

                    _header.FrameOffset = CurrentPosition;
                    _result.WriteStructs(frames);

                    _header.PaletteOffset = CurrentPosition;
                    _result.WriteStructs(_palettes.GetBuffer());

                    _header.ImageHeaderOffset = CurrentPosition;
                    _result.WriteStructs(_images.GetBuffer());

                    _header.ImageContentOffset = CurrentPosition;
                    _content.SetPosition(0);
                    _content.CopyTo(_result);

                    _header.ImageSegmentOffset = CurrentPosition;
                    _result.WriteStructs(_segments.GetBuffer());

                    _header.ImageLineOffset = CurrentPosition;
                    _result.WriteStructs(_lines.GetBuffer());

                    _result.SetPosition(0);
                    _result.WriteStruct(_header);
                }

                if (!_result.TryGetBuffer(out var result))
                {
                    throw new NotSupportedException();
                }

                return(new UnsafeList <Byte>(result));
            }
            finally
            {
                _images.Clear();
                _paletteMaps.Clear();
                _palettes.Clear();
                _segments.Clear();
                _lines.Clear();

                _contentOffset = 0;
                _content.SetLength(0);
                _result.SetLength(0);
            }
        }