コード例 #1
0
        public override bool write(laszip_point item)
        {
            int diff_l = 0;
            int diff_h = 0;

            uint sym = 0;

            bool rl = (last_item[0] & 0x00FF) != (item.rgb[0] & 0x00FF); if (rl)
            {
                sym |= 1;
            }
            bool rh = (last_item[0] & 0xFF00) != (item.rgb[0] & 0xFF00); if (rh)
            {
                sym |= 2;
            }
            bool gl = (last_item[1] & 0x00FF) != (item.rgb[1] & 0x00FF); if (gl)
            {
                sym |= 4;
            }
            bool gh = (last_item[1] & 0xFF00) != (item.rgb[1] & 0xFF00); if (gh)
            {
                sym |= 8;
            }
            bool bl = (last_item[2] & 0x00FF) != (item.rgb[2] & 0x00FF); if (bl)
            {
                sym |= 16;
            }
            bool bh = (last_item[2] & 0xFF00) != (item.rgb[2] & 0xFF00); if (bh)
            {
                sym |= 32;
            }

            bool allColors = ((item.rgb[0] & 0x00FF) != (item.rgb[1] & 0x00FF)) || ((item.rgb[0] & 0x00FF) != (item.rgb[2] & 0x00FF)) ||
                             ((item.rgb[0] & 0xFF00) != (item.rgb[1] & 0xFF00)) || ((item.rgb[0] & 0xFF00) != (item.rgb[2] & 0xFF00));

            if (allColors)
            {
                sym |= 64;
            }

            enc.encodeSymbol(m_byte_used, sym);
            if (rl)
            {
                diff_l = ((int)(item.rgb[0] & 255)) - (last_item[0] & 255);
                enc.encodeSymbol(m_rgb_diff_0, (byte)MyDefs.U8_FOLD(diff_l));
            }
            if (rh)
            {
                diff_h = ((int)(item.rgb[0] >> 8)) - (last_item[0] >> 8);
                enc.encodeSymbol(m_rgb_diff_1, (byte)MyDefs.U8_FOLD(diff_h));
            }

            if (allColors)
            {
                if (gl)
                {
                    int corr = ((int)(item.rgb[1] & 255)) - MyDefs.U8_CLAMP(diff_l + (last_item[1] & 255));
                    enc.encodeSymbol(m_rgb_diff_2, (byte)MyDefs.U8_FOLD(corr));
                }
                if (bl)
                {
                    diff_l = (diff_l + (item.rgb[1] & 255) - (last_item[1] & 255)) / 2;
                    int corr = ((int)(item.rgb[2] & 255)) - MyDefs.U8_CLAMP(diff_l + (last_item[2] & 255));
                    enc.encodeSymbol(m_rgb_diff_4, (byte)MyDefs.U8_FOLD(corr));
                }
                if (gh)
                {
                    int corr = ((int)(item.rgb[1] >> 8)) - MyDefs.U8_CLAMP(diff_h + (last_item[1] >> 8));
                    enc.encodeSymbol(m_rgb_diff_3, (byte)MyDefs.U8_FOLD(corr));
                }
                if (bh)
                {
                    diff_h = (diff_h + (item.rgb[1] >> 8) - (last_item[1] >> 8)) / 2;
                    int corr = ((int)(item.rgb[2] >> 8)) - MyDefs.U8_CLAMP(diff_h + (last_item[2] >> 8));
                    enc.encodeSymbol(m_rgb_diff_5, (byte)MyDefs.U8_FOLD(corr));
                }
            }

            last_item[0] = item.rgb[0];
            last_item[1] = item.rgb[1];
            last_item[2] = item.rgb[2];

            return(true);
        }
コード例 #2
0
        public override void read(laszip_point item)
        {
            int corr;
            int diff = 0;

            uint sym = dec.decodeSymbol(m_byte_used);

            if ((sym & (1 << 0)) != 0)
            {
                corr        = (int)dec.decodeSymbol(m_rgb_diff_0);
                item.rgb[0] = (ushort)MyDefs.U8_FOLD(corr + (last_item[0] & 255));
            }
            else
            {
                item.rgb[0] = (ushort)(last_item[0] & 0xFF);
            }

            if ((sym & (1 << 1)) != 0)
            {
                corr         = (int)dec.decodeSymbol(m_rgb_diff_1);
                item.rgb[0] |= (ushort)((MyDefs.U8_FOLD(corr + (last_item[0] >> 8))) << 8);
            }
            else
            {
                item.rgb[0] |= (ushort)(last_item[0] & 0xFF00);
            }

            if ((sym & (1 << 6)) != 0)
            {
                diff = (item.rgb[0] & 0x00FF) - (last_item[0] & 0x00FF);
                if ((sym & (1 << 2)) != 0)
                {
                    corr        = (int)dec.decodeSymbol(m_rgb_diff_2);
                    item.rgb[1] = (ushort)MyDefs.U8_FOLD(corr + MyDefs.U8_CLAMP(diff + (last_item[1] & 255)));
                }
                else
                {
                    item.rgb[1] = (ushort)(last_item[1] & 0xFF);
                }

                if ((sym & (1 << 4)) != 0)
                {
                    corr        = (int)dec.decodeSymbol(m_rgb_diff_4);
                    diff        = (diff + ((item.rgb[1] & 0x00FF) - (last_item[1] & 0x00FF))) / 2;
                    item.rgb[2] = (ushort)MyDefs.U8_FOLD(corr + MyDefs.U8_CLAMP(diff + (last_item[2] & 255)));
                }
                else
                {
                    item.rgb[2] = (ushort)(last_item[2] & 0xFF);
                }

                diff = (item.rgb[0] >> 8) - (last_item[0] >> 8);
                if ((sym & (1 << 3)) != 0)
                {
                    corr         = (int)dec.decodeSymbol(m_rgb_diff_3);
                    item.rgb[1] |= (ushort)((MyDefs.U8_FOLD(corr + MyDefs.U8_CLAMP(diff + (last_item[1] >> 8)))) << 8);
                }
                else
                {
                    item.rgb[1] |= (ushort)(last_item[1] & 0xFF00);
                }

                if ((sym & (1 << 5)) != 0)
                {
                    corr         = (int)dec.decodeSymbol(m_rgb_diff_5);
                    diff         = (diff + ((item.rgb[1] >> 8) - (last_item[1] >> 8))) / 2;
                    item.rgb[2] |= (ushort)((MyDefs.U8_FOLD(corr + MyDefs.U8_CLAMP(diff + (last_item[2] >> 8)))) << 8);
                }
                else
                {
                    item.rgb[2] |= (ushort)(last_item[2] & 0xFF00);
                }
            }
            else
            {
                item.rgb[1] = item.rgb[0];
                item.rgb[2] = item.rgb[0];
            }

            last_item[0] = item.rgb[0];
            last_item[1] = item.rgb[1];
            last_item[2] = item.rgb[2];
        }