예제 #1
0
        void UnpackV2(ParallelCbgDecoder decoder)
        {
            var base_offset = Input.Position;

            decoder.Tree1 = new HuffmanTree(ReadWeightTable(Input, 0x10), true);
            decoder.Tree2 = new HuffmanTree(ReadWeightTable(Input, 0xB0), true);

            int y_blocks   = decoder.Height / 8;
            var offsets    = new int[y_blocks + 1];
            int input_base = (int)(Input.Position + offsets.Length * 4 - base_offset);

            using (var reader = new ArcView.Reader(Input))
            {
                for (int i = 0; i < offsets.Length; ++i)
                {
                    offsets[i] = reader.ReadInt32() - input_base;
                }
                decoder.Input = reader.ReadBytes((int)(Input.Length - Input.Position));
            }
            int pad_skip = ((decoder.Width >> 3) + 7) >> 3;
            var tasks    = new List <Task> (y_blocks + 1);

            decoder.Output = new byte[decoder.Width * decoder.Height * 4];
            int dst = 0;

            for (int i = 0; i < y_blocks; ++i)
            {
                int block_offset = offsets[i] + pad_skip;
                int next_offset  = i + 1 == y_blocks ? decoder.Input.Length : offsets[i + 1];
                int closure_dst  = dst;
                var task         = Task.Run(() => decoder.UnpackBlock(block_offset, next_offset - block_offset, closure_dst));
                tasks.Add(task);
                dst += decoder.Width * 32;
            }
            if (32 == m_info.BPP)
            {
                var task = Task.Run(() => decoder.UnpackAlpha(offsets[y_blocks]));
                tasks.Add(task);
            }
            var complete = Task.WhenAll(tasks);

            complete.Wait();
            Format   = decoder.HasAlpha ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
            Stride   = decoder.Width * 4;
            m_output = decoder.Output;
        }
예제 #2
0
 public void Unpack()
 {
     Input.Position = 0x30;
     if (m_info.Version < 2)
     {
         UnpackV1();
     }
     else if (2 == m_info.Version)
     {
         if (m_info.EncLength < 0x80)
         {
             throw new InvalidFormatException();
         }
         using (var decoder = new ParallelCbgDecoder(m_info, ReadEncoded()))
             UnpackV2(decoder);
     }
     else
     {
         throw new NotSupportedException("Not supported CompressedBG version");
     }
 }
예제 #3
0
파일: ImageBGI.cs 프로젝트: Casidi/GARbro
        void UnpackV2(ParallelCbgDecoder decoder)
        {
            var base_offset = Input.Position;
            decoder.Tree1 = new HuffmanTree (ReadWeightTable (Input, 0x10), true);
            decoder.Tree2 = new HuffmanTree (ReadWeightTable (Input, 0xB0), true);

            int y_blocks = decoder.Height / 8;
            var offsets = new int[y_blocks+1];
            int input_base = (int)(Input.Position + offsets.Length*4 - base_offset);
            using (var reader = new ArcView.Reader (Input))
            {
                for (int i = 0; i < offsets.Length; ++i)
                    offsets[i] = reader.ReadInt32() - input_base;
                decoder.Input = reader.ReadBytes ((int)(Input.Length - Input.Position));
            }
            int pad_skip = ((decoder.Width >> 3) + 7) >> 3;
            var tasks = new List<Task> (y_blocks+1);
            decoder.Output = new byte[decoder.Width * decoder.Height * 4];
            int dst = 0;
            for (int i = 0; i < y_blocks; ++i)
            {
                int block_offset = offsets[i] + pad_skip;
                int next_offset = i+1 == y_blocks ? decoder.Input.Length : offsets[i+1];
                int closure_dst = dst;
                var task = Task.Run (() => decoder.UnpackBlock (block_offset, next_offset-block_offset, closure_dst));
                tasks.Add (task);
                dst += decoder.Width * 32;
            }
            if (32 == m_info.BPP)
            {
                var task = Task.Run (() => decoder.UnpackAlpha (offsets[y_blocks]));
                tasks.Add (task);
            }
            var complete = Task.WhenAll (tasks);
            complete.Wait();
            Format = decoder.HasAlpha ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
            Stride = decoder.Width * 4;
            m_output = decoder.Output;
        }
예제 #4
0
파일: ImageBGI.cs 프로젝트: Casidi/GARbro
 public void Unpack()
 {
     Input.Position = 0x30;
     if (m_info.Version < 2)
         UnpackV1();
     else if (2 == m_info.Version)
     {
         if (m_info.EncLength < 0x80)
             throw new InvalidFormatException();
         using (var decoder = new ParallelCbgDecoder (m_info, ReadEncoded()))
             UnpackV2 (decoder);
     }
     else
         throw new NotSupportedException ("Not supported CompressedBG version");
 }