Пример #1
0
        private int getCMarkerWSQ(TokenD token, int type)
        {
            if (token.pointer >= token.buffer.Length)
            {
                throw new SystemException("Error, Invalid pointer : " + token.pointer);
            }

            int marker = token.readShort();

            switch (type)
            {
                case WSQConstants.SOI_WSQ:
                    if (marker != WSQConstants.SOI_WSQ)
                    {
                        throw new SystemException("ERROR : getCMarkerWSQ : No SOI marker : " + marker);
                    }

                    return marker;

                case WSQConstants.TBLS_N_SOF:
                    if (marker != WSQConstants.DTT_WSQ
                            && marker != WSQConstants.DQT_WSQ
                            && marker != WSQConstants.DHT_WSQ
                            && marker != WSQConstants.SOF_WSQ
                            && marker != WSQConstants.COM_WSQ)
                    {
                        throw new SystemException("ERROR : getc_marker_wsq : No SOF, Table, or comment markers : " + marker);
                    }

                    return marker;

                case WSQConstants.TBLS_N_SOB:
                    if (marker != WSQConstants.DTT_WSQ
                            && marker != WSQConstants.DQT_WSQ
                            && marker != WSQConstants.DHT_WSQ
                            && marker != WSQConstants.SOB_WSQ
                            && marker != WSQConstants.COM_WSQ)
                    {
                        throw new SystemException("ERROR : getc_marker_wsq : No SOB, Table, or comment markers : " +
                                marker);
                    }
                    return marker;
                case WSQConstants.ANY_WSQ:
                    if ((marker & 0xff00) != 0xff00)
                    {
                        throw new SystemException("ERROR : getc_marker_wsq : no marker found : " + marker);
                    }

                    /* Added by MDG on 03-07-05 */
                    if ((marker < WSQConstants.SOI_WSQ) || (marker > WSQConstants.COM_WSQ))
                    {
                        throw new SystemException("ERROR : getc_marker_wsq : not a valid marker : " + marker);
                    }

                    return marker;
                default:
                    throw new SystemException("ERROR : getc_marker_wsq : Invalid marker : " + marker);
            }
        }
Пример #2
0
        private void getCTransformTable(TokenD token)
        {
            // read header Size;
            int tmp;
            tmp = token.readShort();

            token.tableDTT.hisz = token.readByte();
            token.tableDTT.losz = token.readByte();

            token.tableDTT.hifilt = new float[token.tableDTT.hisz];
            token.tableDTT.lofilt = new float[token.tableDTT.losz];

            int aSize;
            if (token.tableDTT.hisz % 2 != 0)
            {
                aSize = (token.tableDTT.hisz + 1) / 2;
            }
            else
            {
                aSize = token.tableDTT.hisz / 2;
            }

            float[] aLofilt = new float[aSize];

            aSize--;
            for (int cnt = 0; cnt <= aSize; cnt++)
            {
                int sign = token.readByte();
                int scale = token.readByte();
                long shrtDat = token.readInt();
                aLofilt[cnt] = (float)shrtDat;

                while (scale > 0)
                {
                    aLofilt[cnt] /= 10.0F;
                    scale--;
                }

                if (sign != 0)
                {
                    aLofilt[cnt] *= -1.0F;
                }

                if (token.tableDTT.hisz % 2 != 0)
                {
                    token.tableDTT.hifilt[cnt + aSize] = intSign(cnt) * aLofilt[cnt];
                    if (cnt > 0)
                    {
                        token.tableDTT.hifilt[aSize - cnt] = token.tableDTT.hifilt[cnt + aSize];
                    }
                }
                else
                {
                    token.tableDTT.hifilt[cnt + aSize + 1] = intSign(cnt) * aLofilt[cnt];
                    token.tableDTT.hifilt[aSize - cnt] = -1 * token.tableDTT.hifilt[cnt + aSize + 1];
                }
            }

            if (token.tableDTT.losz % 2 != 0)
            {
                aSize = (token.tableDTT.losz + 1) / 2;
            }
            else
            {
                aSize = token.tableDTT.losz / 2;
            }

            float[] aHifilt = new float[aSize];

            aSize--;
            for (int cnt = 0; cnt <= aSize; cnt++)
            {
                int sign = token.readByte();
                int scale = token.readByte();
                long shrtDat = token.readInt();

                aHifilt[cnt] = (float)shrtDat;

                while (scale > 0)
                {
                    aHifilt[cnt] /= 10.0F;
                    scale--;
                }

                if (sign != 0)
                {
                    aHifilt[cnt] *= -1.0F;
                }

                if (token.tableDTT.losz % 2 != 0)
                {
                    token.tableDTT.lofilt[cnt + aSize] = intSign(cnt) * aHifilt[cnt];
                    if (cnt > 0)
                    {
                        token.tableDTT.lofilt[aSize - cnt] = token.tableDTT.lofilt[cnt + aSize];
                    }
                }
                else
                {
                    token.tableDTT.lofilt[cnt + aSize + 1] = intSign(cnt + 1) * aHifilt[cnt];
                    token.tableDTT.lofilt[aSize - cnt] = token.tableDTT.lofilt[cnt + aSize + 1];
                }
            }

            token.tableDTT.lodef = 1;
            token.tableDTT.hidef = 1;
        }
Пример #3
0
        private WSQHelper.HuffmanTable getCHuffmanTable(TokenD token, int maxHuffcounts, int bytesLeft, bool readTableLen)
        {
            WSQHelper.HuffmanTable huffmanTable = new WSQHelper.HuffmanTable();

            /* table_len */
            if (readTableLen)
            {
                huffmanTable.tableLen = token.readShort();
                huffmanTable.bytesLeft = huffmanTable.tableLen - 2;
                bytesLeft = huffmanTable.bytesLeft;
            }
            else
            {
                huffmanTable.bytesLeft = bytesLeft;
            }

            /* If no bytes left ... */
            if (bytesLeft <= 0)
            {
                throw new SystemException("ERROR : getCHuffmanTable : no huffman table bytes remaining");
            }

            /* Table ID */
            huffmanTable.tableId = token.readByte();
            huffmanTable.bytesLeft--;

            huffmanTable.huffbits = new int[WSQConstants.MAX_HUFFBITS];
            int numHufvals = 0;
            /* L1 ... L16 */
            for (int i = 0; i < WSQConstants.MAX_HUFFBITS; i++)
            {
                huffmanTable.huffbits[i] = token.readByte();
                numHufvals += huffmanTable.huffbits[i];
            }
            huffmanTable.bytesLeft -= WSQConstants.MAX_HUFFBITS;

            if (numHufvals > maxHuffcounts + 1)
            {
                throw new SystemException("ERROR : getCHuffmanTable : numHufvals is larger than MAX_HUFFCOUNTS");
            }

            /* Could allocate only the amount needed ... then we wouldn't */
            /* need to pass MAX_HUFFCOUNTS. */
            huffmanTable.huffvalues = new int[maxHuffcounts + 1];

            /* V1,1 ... V16,16 */
            for (int i = 0; i < numHufvals; i++)
            {
                huffmanTable.huffvalues[i] = token.readByte();
            }
            huffmanTable.bytesLeft -= numHufvals;

            return huffmanTable;
        }
Пример #4
0
        private WSQHelper.HeaderFrm getCFrameHeaderWSQ(TokenD token)
        {
            WSQHelper.HeaderFrm headerFrm = new WSQHelper.HeaderFrm();

            //noinspection UnusedDeclaration
            int hdrSize = token.readShort(); /* header size */

            headerFrm.black = token.readByte();
            headerFrm.white = token.readByte();
            headerFrm.height = token.readShort();
            headerFrm.width = token.readShort();
            int scale = token.readByte(); /* exponent scaling parameter */
            int shrtDat = token.readShort(); /* buffer pointer */
            headerFrm.mShift = (float)shrtDat;
            while (scale > 0)
            {
                headerFrm.mShift /= 10.0F;
                scale--;
            }

            scale = token.readByte();
            shrtDat = token.readShort();
            headerFrm.rScale = (float)shrtDat;
            while (scale > 0)
            {
                headerFrm.rScale /= 10.0F;
                scale--;
            }

            headerFrm.wsqEncoder = token.readByte();
            headerFrm.software = token.readShort();

            return headerFrm;
        }
Пример #5
0
 private string getCComment(TokenD token)
 {
     int size = token.readShort() - 2;
     byte[] t = token.readBytes(size);
     return ASCIIEncoding.ASCII.GetString(t, 0, t.Length);
 }
Пример #6
0
 private int getCBlockHeader(TokenD token)
 {
     token.readShort(); /* block header size */
     return token.readByte();
 }
Пример #7
0
        public void getCQuantizationTable(TokenD token)
        {
            int tmp;
            tmp = token.readShort(); /* header size */
            int scale = token.readByte(); /* scaling parameter */
            int shrtDat = token.readShort(); /* counter and temp short buffer */

            token.tableDQT.binCenter = (float)shrtDat;
            while (scale > 0)
            {
                token.tableDQT.binCenter /= 10.0F;
                scale--;
            }

            for (int cnt = 0; cnt < Table_DQT.MAX_SUBBANDS; cnt++)
            {
                scale = token.readByte();
                shrtDat = token.readShort();
                token.tableDQT.qBin[cnt] = (float)shrtDat;
                while (scale > 0)
                {
                    token.tableDQT.qBin[cnt] /= 10.0F;
                    scale--;
                }

                scale = token.readByte();
                shrtDat = token.readShort();
                token.tableDQT.zBin[cnt] = (float)shrtDat;
                while (scale > 0)
                {
                    token.tableDQT.zBin[cnt] /= 10.0F;
                    scale--;
                }
            }

            token.tableDQT.dqtDef = (char)1;
        }