Beispiel #1
0
        public int SaveToStream(BinaryWriter bw)
        {
            // 将数据保存为未压缩格式

            long offset = bw.BaseStream.Position;

            header.SetToUncompressFormat();

            if (chunkMetas != null) // framecapture section
            {
                //生成临时数据,以跳过被remove的chunk
                using (MemoryStream msTmp = new MemoryStream(uncompressedData.Length + 64))
                    using (BinaryWriter bwTmp = new BinaryWriter(msTmp))
                    {
                        foreach (var meta in chunkMetas)
                        {
                            if (meta.isRemoved)
                            {
                                continue;
                            }

                            bwTmp.AlignUp(64);
                            bwTmp.Write(uncompressedData, (int)meta.offset, (int)meta.fullLength);
                            bwTmp.AlignUp(64);
                        }

                        header.sectionUncompressedLength = (ulong)msTmp.Position; // Position 有可能比 Length 大。。。。
                        header.sectionCompressedLength   = header.sectionUncompressedLength;

                        header.SaveToStream(bw);
                        bw.Write(msTmp.GetBuffer(), 0, (int)msTmp.Position);
                    }
            }
            else if (thumbPixels != null) // thumbnail section
            {
                header.sectionCompressedLength = (ulong)(ExtThumbnailHeader.headerSize + thumbPixels.Length);
                header.sectionCompressedLength = header.sectionUncompressedLength;

                header.SaveToStream(bw);
                thumbHeader.SaveToStream(bw);
                bw.Write(thumbPixels, 0, thumbPixels.Length);
            }
            else
            {
                header.SaveToStream(bw);
                bw.Write(uncompressedData, 0, uncompressedData.Length);
            }

            return((int)(bw.BaseStream.Position - offset));
        }