Exemplo n.º 1
0
        private DmtxChannel FindBestChannel(DmtxChannelGroup group, DmtxScheme targetScheme)
        {
            bool err;
            DmtxChannel channel;
            DmtxChannel winner = null;

            for (DmtxScheme encFrom = DmtxScheme.DmtxSchemeAscii; encFrom <= DmtxScheme.DmtxSchemeBase256; encFrom++)
            {

                channel = group.Channels[(int)encFrom];

                /* If from channel doesn't hold valid data because it couldn't
                   represent the previous value then skip it */
                if (channel.Invalid != DmtxChannelStatus.DmtxChannelValid)
                {
                    continue;
                }

                /* If channel has already processed all of its input values then it
                   cannot be used as a starting point */
                if (channel.InputIndex == channel.Input.Length)
                    continue;

                err = EncodeNextWord(channel, targetScheme);
                if (err == false)
                {
                    /* XXX fix this */
                }

                /* If channel scheme can't represent next word then stop for this channel */
                if ((channel.Invalid & DmtxChannelStatus.DmtxChannelUnsupportedChar) != 0)
                {
                    winner = channel;
                    break;
                }

                /* If channel scheme was unable to unlatch here then skip */
                if ((channel.Invalid & DmtxChannelStatus.DmtxChannelCannotUnlatch) != 0)
                {
                    continue;
                }

                if (winner == null || channel.CurrentLength < winner.CurrentLength)
                {
                    winner = channel;
                }
            }

            return winner;
        }
Exemplo n.º 2
-1
        private int EncodeAutoBest(byte[] buf, byte[] codewords)
        {
            DmtxScheme targetScheme;
            int winnerSize;
            bool err;
            DmtxChannelGroup optimal = new DmtxChannelGroup();
            DmtxChannelGroup best = new DmtxChannelGroup();
            DmtxChannel winner;

            /* Intialize optimizing channels and encode first codeword from default ASCII */
            for (targetScheme = DmtxScheme.DmtxSchemeAscii; targetScheme <= DmtxScheme.DmtxSchemeBase256; targetScheme++)
            {
                DmtxChannel channel = (optimal.Channels[(int)targetScheme]);
                InitChannel(channel, codewords);
                err = EncodeNextWord(channel, targetScheme);
                if (err)
                    return 0;
            }

            /* For each remaining word in the input stream, test the efficiency of
               getting to this encodation scheme for each input character by
               switching here from each of the other channels (which are always
               optimally encoded) */
            while (optimal.Channels[0].InputIndex < optimal.Channels[0].Input.Length)
            { /* XXX only tracking first channel */

                for (targetScheme = DmtxScheme.DmtxSchemeAscii; targetScheme <= DmtxScheme.DmtxSchemeBase256; targetScheme++)
                {
                    best.Channels[(int)targetScheme] = FindBestChannel(optimal, targetScheme);
                }
                optimal = best;
            }

            /* Choose a winner now that all channels are finished */
            winner = optimal.Channels[(int)DmtxScheme.DmtxSchemeAscii];
            for (targetScheme = DmtxScheme.DmtxSchemeAscii + 1; targetScheme <= DmtxScheme.DmtxSchemeBase256; targetScheme++)
            {
                if (optimal.Channels[(int)targetScheme].Invalid != DmtxChannelStatus.DmtxChannelValid)
                {
                    continue;
                }

                if (optimal.Channels[(int)targetScheme].EncodedLength < winner.EncodedLength)
                {
                    winner = optimal.Channels[(int)targetScheme];
                }
            }

            /* XXX get rid of buf concept and try to do something with channel -> matrix copy instead */
            winnerSize = winner.EncodedLength / 12;
            for (int i = 0; i < winnerSize; i++)
            {
                buf[i] = winner.EncodedWords[i];
            }

            return winnerSize;
        }