示例#1
0
 public static void WriteBits(
     ImageBinWriter s, ref BitBuffer32 bitBuf, PointU16 point)
 {
     WriteBits(s, ref bitBuf, point.X, point.Y);
 }
示例#2
0
        public static int ProcessDU(
            ImageBinWriter s, ref BitBuffer32 bitBuf,
            Span <float> CDU, int duStride, Span <float> fdtbl, int DC,
            PointU16[] HTDC, PointU16[] HTAC)
        {
            Debug.Assert(HTDC != null);
            Debug.Assert(HTAC != null);

            Span <int> DU = stackalloc int[64];

            CalculateCDU(CDU, duStride, fdtbl, DU);

            int diff = DU[0] - DC;

            if (diff == 0)
            {
                WriteBits(s, ref bitBuf, HTDC[0]);
            }
            else
            {
                BitBuffer16 bitBuf16 = CalcBitBuffer16(diff);
                WriteBits(s, ref bitBuf, HTDC[bitBuf16.Count]);
                WriteBits(s, ref bitBuf, bitBuf16.Value, bitBuf16.Count);
            }

            int end0pos = 63;

            for (; (end0pos > 0) && (DU[end0pos] == 0); end0pos--)
            {
            }

            if (end0pos == 0)
            {
                WriteBits(s, ref bitBuf, HTAC[0x00]);
                return(DU[0]);
            }

            for (int i = 1; i <= end0pos; i++)
            {
                int startpos = i;
                for (; (DU[i] == 0) && (i <= end0pos); i++)
                {
                }

                int nrzeroes = i - startpos;
                if (nrzeroes >= 16)
                {
                    int lng = nrzeroes >> 4;
                    for (int nrmarker = 1; nrmarker <= lng; nrmarker++)
                    {
                        WriteBits(s, ref bitBuf, HTAC[0xF0]);
                    }

                    nrzeroes &= 15;
                }

                BitBuffer16 bitBuf16 = CalcBitBuffer16(DU[i]);
                WriteBits(s, ref bitBuf, HTAC[(nrzeroes << 4) + bitBuf16.Count]);
                WriteBits(s, ref bitBuf, bitBuf16.Value, bitBuf16.Count);
            }

            if (end0pos != 63)
            {
                WriteBits(s, ref bitBuf, HTAC[0x00]);
            }

            return(DU[0]);
        }