Пример #1
0
        public static async Task <ChunkBuilder> Create(BA2DX10EntryState state, ChunkState chunk, Stream src, DiskSlabAllocator slab)
        {
            var builder = new ChunkBuilder {
                _chunk = chunk
            };

            if (!chunk.Compressed)
            {
                builder._dataSlab = slab.Allocate(chunk.FullSz);
                await src.CopyToWithStatusAsync((int)chunk.FullSz, builder._dataSlab, $"Writing {state.Path} {chunk.StartMip}:{chunk.EndMip}");
            }
            else
            {
                var deflater = new Deflater(Deflater.BEST_COMPRESSION);
                await using var ms = new MemoryStream();
                await using (var ds = new DeflaterOutputStream(ms, deflater))
                {
                    ds.IsStreamOwner = false;
                    await src.CopyToWithStatusAsync((int)chunk.FullSz, ds, $"Compressing {state.Path} {chunk.StartMip}:{chunk.EndMip}");
                }

                builder._dataSlab = slab.Allocate(ms.Length);
                ms.Position       = 0;
                await ms.CopyToWithStatusAsync(ms.Length, builder._dataSlab, $"Writing {state.Path} {chunk.StartMip}:{chunk.EndMip}");

                builder._packSize = (uint)ms.Length;
            }
            builder._dataSlab.Position = 0;

            return(builder);
        }
Пример #2
0
        public static ChunkBuilder Create(BA2DX10EntryState state, ChunkState chunk, Stream src)
        {
            var builder = new ChunkBuilder {
                _chunk = chunk
            };

            using (var ms = new MemoryStream())
            {
                src.CopyToLimit(ms, (int)chunk.FullSz);
                builder._data = ms.ToArray();
            }

            if (!chunk.Compressed)
            {
                return(builder);
            }

            using (var ms = new MemoryStream())
            {
                using (var ds = new DeflaterOutputStream(ms))
                {
                    ds.Write(builder._data, 0, builder._data.Length);
                }

                builder._data = ms.ToArray();
            }

            builder._packSize = (uint)builder._data.Length;

            return(builder);
        }
Пример #3
0
        public static ChunkBuilder Create(BA2DX10EntryState state, ChunkState chunk, Stream src, DiskSlabAllocator slab)
        {
            var builder = new ChunkBuilder {
                _chunk = chunk
            };

            if (!chunk.Compressed)
            {
                builder._dataSlab = slab.Allocate(chunk.FullSz);
                src.CopyToLimit(builder._dataSlab, (int)chunk.FullSz);
            }
            else
            {
                var deflater = new Deflater(Deflater.BEST_COMPRESSION);
                using var ms = new MemoryStream();
                using (var ds = new DeflaterOutputStream(ms, deflater))
                {
                    ds.IsStreamOwner = false;
                    src.CopyToLimit(ds, (int)chunk.FullSz);
                }

                builder._dataSlab = slab.Allocate(ms.Length);
                ms.Position       = 0;
                ms.CopyTo(builder._dataSlab);
                builder._packSize = (uint)ms.Length;
            }
            builder._dataSlab.Position = 0;

            return(builder);
        }
Пример #4
0
        public BA2DX10FileEntryBuilder(BA2DX10EntryState state, Stream src)
        {
            _state = state;

            var header_size = DDS.HeaderSizeForFormat((DXGI_FORMAT)state.PixelFormat) + 4;

            new BinaryReader(src).ReadBytes((int)header_size);

            _chunks = _state.Chunks.Select(ch => new ChunkBuilder(state, ch, src)).ToList();
        }
Пример #5
0
        public static async Task <BA2DX10FileEntryBuilder> Create(BA2DX10EntryState state, Stream src, DiskSlabAllocator slab)
        {
            var builder = new BA2DX10FileEntryBuilder {
                _state = state
            };

            var headerSize = DDS.HeaderSizeForFormat((DXGI_FORMAT)state.PixelFormat) + 4;

            new BinaryReader(src).ReadBytes((int)headerSize);

            // This can't be parallel because it all runs off the same base IO stream.
            builder._chunks = new List <ChunkBuilder>();

            foreach (var chunk in state.Chunks)
            {
                builder._chunks.Add(await ChunkBuilder.Create(state, chunk, src, slab));
            }

            return(builder);
        }
Пример #6
0
        public ChunkBuilder(BA2DX10EntryState state, ChunkState ch, Stream src)
        {
            _chunk = ch;

            using (var ms = new MemoryStream())
            {
                src.CopyToLimit(ms, (int)_chunk.FullSz);
                _data = ms.ToArray();
            }

            if (_chunk.Compressed)
            {
                using (var ms = new MemoryStream())
                {
                    using (var ds = new DeflaterOutputStream(ms))
                    {
                        ds.Write(_data, 0, _data.Length);
                    }
                    _data = ms.ToArray();
                }
                _packSize = (uint)_data.Length;
            }
        }