Exemple #1
0
        void Unpack24bpp()
        {
            int extra_row = m_output.Length - m_stride;
            var rows      = new int[3] {
                0, extra_row, extra_row
            };
            var offset_table = OffsetTable.Clone() as int[];

            for (int y = 0; y < m_height; ++y)
            {
                int dst = rows[0];
                for (int x = 0; x < m_width;)
                {
                    int ctl = m_input.GetBits(ControlTable1, 13);
                    if (0xB8 == ctl)
                    {
                        ctl += m_input.GetBits(ControlTable2, 13);
                    }

                    int pos      = m_input.GetBits(PosTable24, 6) * 2;
                    int x_offset = offset_table[pos];
                    int y_offset = offset_table[pos + 1];
                    if (pos > 0)
                    {
                        offset_table[pos]     = offset_table[pos - 2];
                        offset_table[pos + 1] = offset_table[pos - 1];
                        offset_table[pos - 2] = x_offset;
                        offset_table[pos - 1] = y_offset;
                    }

                    int src = rows[y_offset] + (x + x_offset) * 4;
                    if (ctl >= 0xD8)
                    {
                        int count = ctl - 0xD6;
                        Binary.CopyOverlapped(m_output, src, dst, count * 4);
                        dst += count * 4;
                        x   += count;
                    }
                    else
                    {
                        for (int j = 2; j >= 0; --j)
                        {
                            byte r = RgbBits[j, ctl];
                            if (0xFD == r)
                            {
                                r = GetDelta(DeltaTable);
                            }

                            m_output[dst + j] = (byte)(m_output[src + j] - r);
                        }
                        dst += 4;
                        ++x;
                    }
                }
                rows[2]  = rows[1];
                rows[1]  = rows[0];
                rows[0] += m_stride;
            }
        }
Exemple #2
0
        void Unpack32bpp()
        {
            for (int i = 3; i < m_stride; i += 4)
            {
                m_output[i] = 0xFF;
            }
            var rows         = new int[3];
            var offset_table = OffsetTable.Clone() as int[];

            for (int y = 0; y < m_height; ++y)
            {
                int dst = rows[0];
                for (int x = 0; x < m_width;)
                {
                    int ctl = m_input.GetBits(ControlTable1, 13);
                    if (0xB8 == ctl)
                    {
                        ctl += m_input.GetBits(ControlTable2, 13);
                    }

                    int  t          = m_input.GetBits(ControlTable32, 9) * 2;
                    int  pos        = PosTable32[t] * 2;
                    bool diff_alpha = PosTable32[t + 1] != 0;

                    int x_offset = offset_table[pos];
                    int y_offset = offset_table[pos + 1];
                    if (pos > 0)
                    {
                        offset_table[pos]     = offset_table[pos - 2];
                        offset_table[pos + 1] = offset_table[pos - 1];
                        offset_table[pos - 2] = x_offset;
                        offset_table[pos - 1] = y_offset;
                    }

                    int src = rows[y_offset] + (x + x_offset) * 4;
                    if (ctl >= 0xD8)
                    {
                        int count = ctl - 0xD6;
                        Binary.CopyOverlapped(m_output, src, dst, count * 4);
                        dst += count * 4;
                        x   += count;
                    }
                    else
                    {
                        for (int j = 2; j >= 0; --j)
                        {
                            byte r = RgbBits[j, ctl];
                            if (0xFD == r)
                            {
                                r = GetDelta(DeltaTable);
                            }

                            m_output[dst + j] = (byte)(m_output[src + j] - r);
                        }
                        byte alpha = 0;
                        if (diff_alpha)
                        {
                            alpha = GetDelta(AlphaTable);
                        }

                        m_output[dst + 3] = (byte)(m_output[src + 3] - alpha);
                        dst += 4;
                        ++x;
                    }
                }
                rows[2]  = rows[1];
                rows[1]  = rows[0];
                rows[0] += m_stride;
            }
        }