// Constructor Method
        public HuffmanDecode(Stream data)
        {
            size = (int)data.Length;
            dis  = new EmbedData(data);
            // Parse out markers and header info
            bool cont = true;
            byte b;

            while (cont)
            {
                b = dis.Read();
                if (b == 255)
                {
                    b = dis.Read();
                    switch (b)
                    {
                    case 192:
                        SetSOF0();
                        break;

                    case 196:
                        SetDHT();
                        break;

                    case 219:
                        SetDQT();
                        break;

                    case 217:
                    case 218:
                        cont = false;
                        break;

                    case DRI:
                        SetDRI();
                        break;

                    default:
                        if (Array.IndexOf(APP, b) > -1)
                        {
                            dis.Seek(dis.ReadInt() - 2, SeekOrigin.Current);
                        }
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Return image data
        /// </summary>
        public int[] Decode()
        {
            int tmp;

            int[] Cs, Ta, Td; // SOS parameters
            int[] PRED = new int[Nf];
            for (int nComponent = 0; nComponent < Nf; nComponent++)
            {
                PRED[nComponent] = 0;
            }
            CNT = 0;
            // Read in Scan Header information
            Ls = dis.ReadInt();
            Ns = dis.Read();

            Cs = new int[Ns];
            Td = new int[Ns];
            Ta = new int[Ns];

            // get table information
            for (i = 0; i < Ns; i++)
            {
                Cs[i]   = dis.Read();
                Td[i]   = dis.Read();
                Ta[i]   = Td[i] & 0x0f;
                Td[i] >>= 4;
            }

            Ss   = dis.Read();
            Se   = dis.Read();
            Ah   = dis.Read();
            Al   = Ah & 0x0f;
            Ah >>= 4;

            // Calculate the Number of blocks encoded
            // warum doppelt so viel?
            int[] buff     = new int[2 * 8 * 8 * GetBlockCount()];
            int   pos      = 0;
            int   MCUCount = 0;

            bool bDoIt = true;

            while (bDoIt)
            {
                // Get component 1 of MCU
                for (int nComponent = 0; nComponent < Nf; nComponent++)
                {
                    for (j = 0; j < H[nComponent] * V[nComponent]; j++)
                    {
                        // Get DC coefficient
                        hftbl            = Td[nComponent] * 2;
                        tmp              = DECODE();
                        Diff             = Receive(tmp);
                        ZZ[0]            = PRED[0] + Extend(Diff, tmp);
                        PRED[nComponent] = ZZ[0];

                        // Get AC coefficients
                        hftbl = Ta[nComponent] * 2 + 1;
                        Decode_AC_Coefficients();

                        for (i = 0; i < 64; i++)
                        {
                            // Zickzack???
                            // buff[pos++]=ZZ[deZigZag[lp]];
                            buff[pos++] = ZZ[i];
                        }
                    }
                }

                MCUCount++;
                if (MCUCount == RI)
                {
                    MCUCount = 0;
                    CNT      = 0;
                    for (int nComponent = 0; nComponent < Nf; nComponent++)
                    {
                        PRED[nComponent] = 0;
                    }
                    dis.Read();
                    int tmpB = dis.Read();
                    if (tmpB == EOI)
                    {
                        break;
                    }
                }

                if (dis.Available <= 2)
                {
                    if (dis.Available == 2)
                    {
                        dis.Read();
                        if (dis.Read() != EOI)
                        {
                            logger.Warn("file does not end with EOI");
                        }
                    }
                    else
                    {
                        logger.Warn("file does not end with EOI");
                    }
                    break;
                }
            }
            Array.Resize(ref buff, pos);
            return(buff);
        }