Advertisement
Guest User

MyBarcodeDatamatrix

a guest
Jul 16th, 2021
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 91.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Text;
  5. using iTextSharp.text.pdf.codec;
  6.  
  7. namespace iTextSharp.text.pdf
  8. {
  9.     public class MyBarcodeDatamatrix
  10.     {
  11.         private static readonly iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams[] dmSizes = new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams[30]
  12.         {
  13.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(10, 10, 10, 10, 3, 3, 5),
  14.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(12, 12, 12, 12, 5, 5, 7),
  15.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(8, 18, 8, 18, 5, 5, 7),
  16.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(14, 14, 14, 14, 8, 8, 10),
  17.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(8, 32, 8, 16, 10, 10, 11),
  18.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(16, 16, 16, 16, 12, 12, 12),
  19.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(12, 26, 12, 26, 16, 16, 14),
  20.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(18, 18, 18, 18, 18, 18, 14),
  21.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(20, 20, 20, 20, 22, 22, 18),
  22.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(12, 36, 12, 18, 22, 22, 18),
  23.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(22, 22, 22, 22, 30, 30, 20),
  24.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(16, 36, 16, 18, 32, 32, 24),
  25.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(24, 24, 24, 24, 36, 36, 24),
  26.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(26, 26, 26, 26, 44, 44, 28),
  27.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(16, 48, 16, 24, 49, 49, 28),
  28.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(32, 32, 16, 16, 62, 62, 36),
  29.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(36, 36, 18, 18, 86, 86, 42),
  30.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(40, 40, 20, 20, 114, 114, 48),
  31.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(44, 44, 22, 22, 144, 144, 56),
  32.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(48, 48, 24, 24, 174, 174, 68),
  33.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(52, 52, 26, 26, 204, 102, 42),
  34.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(64, 64, 16, 16, 280, 140, 56),
  35.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(72, 72, 18, 18, 368, 92, 36),
  36.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(80, 80, 20, 20, 456, 114, 48),
  37.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(88, 88, 22, 22, 576, 144, 56),
  38.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(96, 96, 24, 24, 696, 174, 68),
  39.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(104, 104, 26, 26, 816, 136, 56),
  40.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(120, 120, 20, 20, 1050, 175, 68),
  41.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(132, 132, 22, 22, 1304, 163, 62),
  42.           new iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams(144, 144, 24, 24, 1558, 156, 62)
  43.         };
  44.         /// No error.
  45.         public const int DM_NO_ERROR = 0;
  46.         /// The text is too big for the symbology capabilities.
  47.         public const int DM_ERROR_TEXT_TOO_BIG = 1;
  48.         /// The dimensions given for the symbol are illegal.
  49.         public const int DM_ERROR_INVALID_SQUARE = 3;
  50.         /// An error while parsing an extension.
  51.         public const int DM_ERROR_EXTENSION = 5;
  52.         /// The best encodation will be used.
  53.         public const int DM_AUTO = 0;
  54.         /// ASCII encodation.
  55.         public const int DM_ASCII = 1;
  56.         /// C40 encodation.
  57.         public const int DM_C40 = 2;
  58.         /// TEXT encodation.
  59.         public const int DM_TEXT = 3;
  60.         /// Binary encodation.
  61.         public const int DM_B256 = 4;
  62.         /// X21 encodation.
  63.         public const int DM_X12 = 5;
  64.         /// X12 encodation.
  65.         ///            
  66.         ///              @deprecated Use {@link BarcodeDataMatrix#DM_X12} instead.
  67.         public const int DM_X21 = 5;
  68.         /// EDIFACT encodation.
  69.         public const int DM_EDIFACT = 6;
  70.         /// No encodation needed. The bytes provided are already encoded.
  71.         public const int DM_RAW = 7;
  72.         /// Allows extensions to be embedded at the start of the text.
  73.         public const int DM_EXTENSION = 32;
  74.         /// Doesn't generate the image but returns all the other information.
  75.         public const int DM_TEST = 64;
  76.         private const byte LATCH_B256 = 231;
  77.         private const byte LATCH_EDIFACT = 240;
  78.         private const byte LATCH_X12 = 238;
  79.         private const byte LATCH_TEXT = 239;
  80.         private const byte LATCH_C40 = 230;
  81.         private const byte UNLATCH = 254;
  82.         private const byte EXTENDED_ASCII = 235;
  83.         private const byte PADDING = 129;
  84.         public const string DEFAULT_DATA_MATRIX_ENCODING = "iso-8859-1";
  85.         private const string X12 = "\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  86.         private string encoding;
  87.         private int extOut;
  88.         private short[] place;
  89.         private byte[] image;
  90.         private int height;
  91.         private int width;
  92.         private int ws;
  93.         private int options;
  94.         private bool forceSquareSize;
  95.  
  96.         //private static int[][] f;
  97.         //private static int[][] switchMode;
  98.         private int[][] f;
  99.         private int[][] switchMode;
  100.  
  101.         /// Creates an instance of this class.
  102.         public MyBarcodeDatamatrix()
  103.         {
  104.             this.encoding = "iso-8859-1";
  105.         }
  106.  
  107.         public MyBarcodeDatamatrix(string code)
  108.         {
  109.             this.encoding = "iso-8859-1";
  110.             this.Generate(code);
  111.         }
  112.  
  113.         public MyBarcodeDatamatrix(string code, string encoding)
  114.         {
  115.             this.encoding = encoding;
  116.             this.Generate(code);
  117.         }
  118.  
  119.         private void SetBit(int x, int y, int xByte)
  120.         {
  121.             this.image[y * xByte + x / 8] |= (byte)(128 >> (x & 7));
  122.         }
  123.  
  124.         private void Draw(byte[] data, int dataSize, iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams dm)
  125.         {
  126.             int xByte = (dm.width + this.ws * 2 + 7) / 8;
  127.             for (int index = 0; index < this.image.Length; ++index)
  128.                 this.image[index] = (byte)0;
  129.             for (int ws1 = this.ws; ws1 < dm.height + this.ws; ws1 += dm.heightSection)
  130.             {
  131.                 for (int ws2 = this.ws; ws2 < dm.width + this.ws; ws2 += 2)
  132.                     this.SetBit(ws2, ws1, xByte);
  133.             }
  134.             for (int y = dm.heightSection - 1 + this.ws; y < dm.height + this.ws; y += dm.heightSection)
  135.             {
  136.                 for (int ws = this.ws; ws < dm.width + this.ws; ++ws)
  137.                     this.SetBit(ws, y, xByte);
  138.             }
  139.             for (int ws1 = this.ws; ws1 < dm.width + this.ws; ws1 += dm.widthSection)
  140.             {
  141.                 for (int ws2 = this.ws; ws2 < dm.height + this.ws; ++ws2)
  142.                     this.SetBit(ws1, ws2, xByte);
  143.             }
  144.             for (int x = dm.widthSection - 1 + this.ws; x < dm.width + this.ws; x += dm.widthSection)
  145.             {
  146.                 for (int y = 1 + this.ws; y < dm.height + this.ws; y += 2)
  147.                     this.SetBit(x, y, xByte);
  148.             }
  149.             int num1 = 0;
  150.             for (int index1 = 0; index1 < dm.height; index1 += dm.heightSection)
  151.             {
  152.                 for (int index2 = 1; index2 < dm.heightSection - 1; ++index2)
  153.                 {
  154.                     for (int index3 = 0; index3 < dm.width; index3 += dm.widthSection)
  155.                     {
  156.                         for (int index4 = 1; index4 < dm.widthSection - 1; ++index4)
  157.                         {
  158.                             int num2 = (int)this.place[num1++];
  159.                             if (num2 == 1 || num2 > 1 && ((int)data[num2 / 8 - 1] & (int)byte.MaxValue & 128 >> num2 % 8) != 0)
  160.                                 this.SetBit(index4 + index3 + this.ws, index2 + index1 + this.ws, xByte);
  161.                         }
  162.                     }
  163.                 }
  164.             }
  165.         }
  166.  
  167.         private static void MakePadding(byte[] data, int position, int count)
  168.         {
  169.             if (count <= 0)
  170.                 return;
  171.             data[position++] = (byte)129;
  172.             while (--count > 0)
  173.             {
  174.                 int num = 129 + (position + 1) * 149 % 253 + 1;
  175.                 if (num > 254)
  176.                     num -= 254;
  177.                 data[position++] = (byte)num;
  178.             }
  179.         }
  180.  
  181.         private static bool IsDigit(int c)
  182.         {
  183.             if (c >= 48)
  184.                 return c <= 57;
  185.             return false;
  186.         }
  187.  
  188.         private static int AsciiEncodation(
  189.           byte[] text,
  190.           int textOffset,
  191.           int textLength,
  192.           byte[] data,
  193.           int dataOffset,
  194.           int dataLength,
  195.           int symbolIndex,
  196.           int prevEnc,
  197.           int origDataOffset)
  198.         {
  199.             int index1 = textOffset;
  200.             int num1 = dataOffset;
  201.             textLength += textOffset;
  202.             dataLength += dataOffset;
  203.             while (index1 < textLength)
  204.             {
  205.                 int c = (int)text[index1++] & (int)byte.MaxValue;
  206.                 if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) && symbolIndex > 0 && (prevEnc == 1 && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[index1 - 2] & (int)byte.MaxValue)) && (data[dataOffset - 1] > (byte)48 && data[dataOffset - 1] < (byte)59))
  207.                 {
  208.                     data[num1 - 1] = (byte)((((int)text[index1 - 2] & (int)byte.MaxValue) - 48) * 10 + c - 48 + 130);
  209.                     return num1 - origDataOffset;
  210.                 }
  211.                 if (num1 >= dataLength)
  212.                     return -1;
  213.                 if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) && symbolIndex < 0 && (index1 < textLength && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[index1] & (int)byte.MaxValue)))
  214.                     data[num1++] = (byte)((c - 48) * 10 + ((int)text[index1++] & (int)byte.MaxValue) - 48 + 130);
  215.                 else if (c > (int)sbyte.MaxValue)
  216.                 {
  217.                     if (num1 + 1 >= dataLength)
  218.                         return -1;
  219.                     byte[] numArray1 = data;
  220.                     int index2 = num1;
  221.                     int num2 = index2 + 1;
  222.                     numArray1[index2] = (byte)235;
  223.                     byte[] numArray2 = data;
  224.                     int index3 = num2;
  225.                     num1 = index3 + 1;
  226.                     int num3 = (int)(byte)(c - 128 + 1);
  227.                     numArray2[index3] = (byte)num3;
  228.                 }
  229.                 else
  230.                     data[num1++] = (byte)(c + 1);
  231.             }
  232.             return num1 - origDataOffset;
  233.         }
  234.  
  235.         private int B256Encodation(
  236.           byte[] text,
  237.           int textOffset,
  238.           int textLength,
  239.           byte[] data,
  240.           int dataOffset,
  241.           int dataLength,
  242.           int symbolIndex,
  243.           int prevEnc,
  244.           int origDataOffset)
  245.         {
  246.             if (textLength == 0)
  247.                 return 0;
  248.             int num1 = dataOffset;
  249.             if (prevEnc != 4)
  250.             {
  251.                 if (textLength < 250 && textLength + 2 > dataLength || textLength >= 250 && textLength + 3 > dataLength)
  252.                     return -1;
  253.                 data[dataOffset] = (byte)231;
  254.             }
  255.             else
  256.             {
  257.                 int index = symbolIndex - 1;
  258.                 while (index > 0 && switchMode[3][index] == 4)
  259.                     --index;
  260.                 textLength = symbolIndex - index + 1;
  261.                 if (textLength != 250 && 1 > dataLength || textLength == 250 && 2 > dataLength)
  262.                     return -1;
  263.                 num1 -= textLength - 1 + (textLength < 250 ? 2 : 3);
  264.             }
  265.             int num2;
  266.             if (textLength < 250)
  267.             {
  268.                 data[num1 + 1] = (byte)textLength;
  269.                 num2 = prevEnc != 4 ? 2 : 0;
  270.             }
  271.             else if (textLength == 250 && prevEnc == 4)
  272.             {
  273.                 data[num1 + 1] = (byte)(textLength / 250 + 249);
  274.                 for (int index = dataOffset + 1; index > num1 + 2; --index)
  275.                     data[index] = data[index - 1];
  276.                 data[num1 + 2] = (byte)(textLength % 250);
  277.                 num2 = 1;
  278.             }
  279.             else
  280.             {
  281.                 data[num1 + 1] = (byte)(textLength / 250 + 249);
  282.                 data[num1 + 2] = (byte)(textLength % 250);
  283.                 num2 = prevEnc != 4 ? 3 : 0;
  284.             }
  285.             if (prevEnc == 4)
  286.                 textLength = 1;
  287.             Array.Copy((Array)text, textOffset, (Array)data, num2 + dataOffset, textLength);
  288.             for (int j = prevEnc != 4 ? dataOffset + 1 : dataOffset; j < num2 + textLength + dataOffset; ++j)
  289.                 RandomizationAlgorithm255(data, j);
  290.             if (prevEnc == 4)
  291.                 RandomizationAlgorithm255(data, num1 + 1);
  292.             return textLength + dataOffset + num2 - origDataOffset;
  293.         }
  294.  
  295.         private void RandomizationAlgorithm255(byte[] data, int j)
  296.         {
  297.             int num = ((int)data[j] & (int)byte.MaxValue) + (149 * (j + 1) % (int)byte.MaxValue + 1);
  298.             if (num > (int)byte.MaxValue)
  299.                 num -= 256;
  300.             data[j] = (byte)num;
  301.         }
  302.  
  303.         private int X12Encodation(
  304.           byte[] text,
  305.           int textOffset,
  306.           int textLength,
  307.           byte[] data,
  308.           int dataOffset,
  309.           int dataLength,
  310.           int symbolIndex,
  311.           int prevEnc,
  312.           int origDataOffset)
  313.         {
  314.             bool flag1 = true;
  315.             if (textLength == 0)
  316.                 return 0;
  317.             int index1 = 0;
  318.             int num1 = 0;
  319.             byte[] numArray1 = new byte[textLength];
  320.             int num2 = 0;
  321.             for (; index1 < textLength; ++index1)
  322.             {
  323.                 int num3 = "\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[index1 + textOffset]);
  324.                 if (num3 >= 0)
  325.                 {
  326.                     numArray1[index1] = (byte)num3;
  327.                     ++num2;
  328.                 }
  329.                 else
  330.                 {
  331.                     numArray1[index1] = (byte)100;
  332.                     if (num2 >= 6)
  333.                         num2 -= num2 / 3 * 3;
  334.                     for (int index2 = 0; index2 < num2; ++index2)
  335.                         numArray1[index1 - index2 - 1] = (byte)100;
  336.                     num2 = 0;
  337.                 }
  338.             }
  339.             if (num2 >= 6)
  340.                 num2 -= num2 / 3 * 3;
  341.             for (int index2 = 0; index2 < num2; ++index2)
  342.                 numArray1[index1 - index2 - 1] = (byte)100;
  343.             int index3 = 0;
  344.             for (; index3 < textLength; ++index3)
  345.             {
  346.                 byte num3 = numArray1[index3];
  347.                 if (num1 <= dataLength)
  348.                 {
  349.                     if (num3 < (byte)40)
  350.                     {
  351.                         if (index3 == 0 && flag1 || index3 > 0 && numArray1[index3 - 1] > (byte)40)
  352.                             data[dataOffset + num1++] = (byte)238;
  353.                         if (num1 + 2 <= dataLength)
  354.                         {
  355.                             int num4 = 1600 * (int)numArray1[index3] + 40 * (int)numArray1[index3 + 1] + (int)numArray1[index3 + 2] + 1;
  356.                             byte[] numArray2 = data;
  357.                             int num5 = dataOffset;
  358.                             int num6 = num1;
  359.                             int num7 = num6 + 1;
  360.                             int index2 = num5 + num6;
  361.                             int num8 = (int)(byte)(num4 / 256);
  362.                             numArray2[index2] = (byte)num8;
  363.                             byte[] numArray3 = data;
  364.                             int num9 = dataOffset;
  365.                             int num10 = num7;
  366.                             num1 = num10 + 1;
  367.                             int index4 = num9 + num10;
  368.                             int num11 = (int)(byte)num4;
  369.                             numArray3[index4] = (byte)num11;
  370.                             index3 += 2;
  371.                         }
  372.                         else
  373.                             break;
  374.                     }
  375.                     else
  376.                     {
  377.                         bool flag2 = true;
  378.                         if (symbolIndex <= 0)
  379.                         {
  380.                             if (index3 > 0 && numArray1[index3 - 1] < (byte)40)
  381.                                 data[dataOffset + num1++] = (byte)254;
  382.                         }
  383.                         else if (symbolIndex > 4 && prevEnc == 5 && ("\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[textOffset]) >= 0 && "\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[textOffset - 1]) >= 0))
  384.                         {
  385.                             int index2 = symbolIndex - 1;
  386.                             while (index2 > 0 && switchMode[4][index2] == 5 && "\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[textOffset - (symbolIndex - index2 + 1)]) >= 0)
  387.                                 --index2;
  388.                             int num4 = -1;
  389.                             if (symbolIndex - index2 >= 5)
  390.                             {
  391.                                 for (int index4 = 1; index4 <= symbolIndex - index2; ++index4)
  392.                                 {
  393.                                     if (data[dataOffset - index4] == (byte)254)
  394.                                     {
  395.                                         num4 = dataOffset - index4;
  396.                                         break;
  397.                                     }
  398.                                 }
  399.                                 int num5 = num4 >= 0 ? dataOffset - num4 - 1 : symbolIndex - index2;
  400.                                 if (num5 % 3 == 2)
  401.                                 {
  402.                                     flag2 = false;
  403.                                     textLength = num5 + 1;
  404.                                     textOffset -= num5;
  405.                                     dataLength += num4 < 0 ? num5 : num5 + 1;
  406.                                     dataOffset -= num4 < 0 ? num5 : num5 + 1;
  407.                                     index3 = -1;
  408.                                     flag1 = num4 != dataOffset;
  409.                                     numArray1 = new byte[num5 + 1];
  410.                                     for (int index4 = 0; index4 <= num5; ++index4)
  411.                                         numArray1[index4] = (byte)"\r*> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf((char)text[textOffset + index4]);
  412.                                 }
  413.                                 else
  414.                                     numArray1 = new byte[1] { (byte)100 };
  415.                             }
  416.                         }
  417.                         if (flag2)
  418.                         {
  419.                             if (iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset + index3, 1, data, dataOffset + num1, dataLength, -1, -1, origDataOffset) < 0)
  420.                                 return -1;
  421.                             if (data[dataOffset + num1] == (byte)235)
  422.                                 ++num1;
  423.                             ++num1;
  424.                         }
  425.                     }
  426.                 }
  427.                 else
  428.                     break;
  429.             }
  430.             byte num12 = 100;
  431.             if (textLength > 0)
  432.                 num12 = numArray1[textLength - 1];
  433.             if (index3 != textLength)
  434.                 return -1;
  435.             if (num12 < (byte)40)
  436.                 data[dataOffset + num1++] = (byte)254;
  437.             if (num1 > dataLength)
  438.                 return -1;
  439.             return num1 + dataOffset - origDataOffset;
  440.         }
  441.  
  442.         private int EdifactEncodation(
  443.           byte[] text,
  444.           int textOffset,
  445.           int textLength,
  446.           byte[] data,
  447.           int dataOffset,
  448.           int dataLength,
  449.           int symbolIndex,
  450.           int prevEnc,
  451.           int origDataOffset,
  452.           bool sizeFixed)
  453.         {
  454.             if (textLength == 0)
  455.                 return 0;
  456.             int num1 = 0;
  457.             int num2 = 0;
  458.             int num3 = 0;
  459.             int num4 = 18;
  460.             bool flag1 = true;
  461.             int index1 = -1;
  462.             int index2 = -1;
  463.             int num5 = -1;
  464.             if (prevEnc == 6 && (((int)text[textOffset] & (int)byte.MaxValue & 224) == 64 || ((int)text[textOffset] & (int)byte.MaxValue & 224) == 32) && (((int)text[textOffset] & (int)byte.MaxValue) != 95 && (((int)text[textOffset - 1] & (int)byte.MaxValue & 224) == 64 || ((int)text[textOffset - 1] & (int)byte.MaxValue & 224) == 32)) && ((int)text[textOffset - 1] & (int)byte.MaxValue) != 95)
  465.             {
  466.                 for (index1 = symbolIndex - 1; index1 > 0 && switchMode[5][index1] == 6; --index1)
  467.                 {
  468.                     int num6 = (int)text[textOffset - (symbolIndex - index1 + 1)] & (int)byte.MaxValue;
  469.                     if ((num6 & 224) != 64 && (num6 & 224) != 32 || num6 == 95)
  470.                         break;
  471.                 }
  472.                 num5 = switchMode[5][index1] == 2 || switchMode[5][index1] == 5 ? switchMode[5][index1] : -1;
  473.                 if (num5 > 0)
  474.                     index2 = index1;
  475.                 for (; num5 > 0 && index2 > 0 && switchMode[num5 - 1][index2] == num5; --index2)
  476.                 {
  477.                     int num6 = (int)text[textOffset - (symbolIndex - index2 + 1)] & (int)byte.MaxValue;
  478.                     if (((num6 & 224) == 64 || (num6 & 224) == 32) && num6 != 95)
  479.                         continue;
  480.                     index2 = -1;
  481.                     break;
  482.                 }
  483.             }
  484.             int num7 = dataOffset + dataLength;
  485.             bool flag2 = false;
  486.             if (symbolIndex != -1)
  487.                 flag2 = true;
  488.             int num8 = 0;
  489.             int num9 = 0;
  490.             if (index2 >= 0 && symbolIndex - index2 + 1 > 9)
  491.             {
  492.                 textLength = symbolIndex - index2 + 1;
  493.                 int num6 = 0;
  494.                 int num10 = 0 + (1 + textLength / 4 * 3);
  495.                 if (!sizeFixed && (symbolIndex == text.Length - 1 || symbolIndex < 0) && textLength % 4 < 3)
  496.                 {
  497.                     num7 = int.MaxValue;
  498.                     for (int index3 = 0; index3 < iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length; ++index3)
  499.                     {
  500.                         if (iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index3].dataSize >= num10 + textLength % 4)
  501.                         {
  502.                             num7 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index3].dataSize;
  503.                             break;
  504.                         }
  505.                     }
  506.                 }
  507.                 int num11;
  508.                 if (num7 - dataOffset - num10 <= 2 && textLength % 4 <= 2)
  509.                 {
  510.                     num11 = num10 + textLength % 4;
  511.                 }
  512.                 else
  513.                 {
  514.                     num11 = num10 + (textLength % 4 + 1);
  515.                     if (textLength % 4 == 3)
  516.                         --num11;
  517.                 }
  518.                 for (int index3 = dataOffset - 1; index3 >= 0; --index3)
  519.                 {
  520.                     ++num6;
  521.                     if ((int)data[index3] == (num5 == 2 ? 230 : 238))
  522.                         break;
  523.                 }
  524.                 if (num11 <= num6)
  525.                 {
  526.                     flag2 = false;
  527.                     textOffset -= textLength - 1;
  528.                     dataOffset -= num6;
  529.                     dataLength += num6;
  530.                 }
  531.             }
  532.             else if (index1 >= 0 && symbolIndex - index1 + 1 > 9)
  533.             {
  534.                 textLength = symbolIndex - index1 + 1;
  535.                 int num6 = num9 + (1 + textLength / 4 * 3);
  536.                 int num10;
  537.                 if (num7 - dataOffset - num6 <= 2 && textLength % 4 <= 2)
  538.                 {
  539.                     num10 = num6 + textLength % 4;
  540.                 }
  541.                 else
  542.                 {
  543.                     num10 = num6 + (textLength % 4 + 1);
  544.                     if (textLength % 4 == 3)
  545.                         --num10;
  546.                 }
  547.                 int num11 = 0;
  548.                 int num12 = -1;
  549.                 for (int index3 = origDataOffset; index3 < dataOffset; ++index3)
  550.                 {
  551.                     if (data[index3] == (byte)240 && dataOffset - index3 <= num10)
  552.                     {
  553.                         num12 = index3;
  554.                         break;
  555.                     }
  556.                 }
  557.                 if (num12 != -1)
  558.                 {
  559.                     int num13 = num8 + (dataOffset - num12);
  560.                     if (((int)text[textOffset] & (int)byte.MaxValue) > (int)sbyte.MaxValue)
  561.                     {
  562.                         num8 = num13 + 2;
  563.                     }
  564.                     else
  565.                     {
  566.                         if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset] & (int)byte.MaxValue) && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - 1] & (int)byte.MaxValue) && (data[dataOffset - 1] >= (byte)49 && data[dataOffset - 1] <= (byte)58))
  567.                             --num13;
  568.                         num8 = num13 + 1;
  569.                     }
  570.                     num11 = dataOffset - num12;
  571.                 }
  572.                 else
  573.                 {
  574.                     for (int index3 = symbolIndex - index1; index3 >= 0; --index3)
  575.                     {
  576.                         if (((int)text[textOffset - index3] & (int)byte.MaxValue) > (int)sbyte.MaxValue)
  577.                         {
  578.                             num8 += 2;
  579.                         }
  580.                         else
  581.                         {
  582.                             if (index3 > 0 && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index3] & (int)byte.MaxValue) && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index3 + 1] & (int)byte.MaxValue))
  583.                             {
  584.                                 if (index3 == 1)
  585.                                     num11 = num8;
  586.                                 --index3;
  587.                             }
  588.                             ++num8;
  589.                         }
  590.                         if (index3 == 1)
  591.                             num11 = num8;
  592.                     }
  593.                 }
  594.                 if (num10 <= num8)
  595.                 {
  596.                     flag2 = false;
  597.                     textOffset -= textLength - 1;
  598.                     dataOffset -= num11;
  599.                     dataLength += num11;
  600.                 }
  601.             }
  602.             if (flag2)
  603.             {
  604.                 int c = (int)text[textOffset] & (int)byte.MaxValue;
  605.                 if (!iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) || textOffset + num1 <= 0 || (!iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - 1] & (int)byte.MaxValue) || prevEnc != 6) || (data[dataOffset - 1] < (byte)49 || data[dataOffset - 1] > (byte)58))
  606.                     return iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset + num1, 1, data, dataOffset + num2, dataLength, -1, -1, origDataOffset);
  607.                 data[dataOffset + num2 - 1] = (byte)((((int)text[textOffset - 1] & (int)byte.MaxValue) - 48) * 10 + c - 48 + 130);
  608.                 return dataOffset - origDataOffset;
  609.             }
  610.             for (; num1 < textLength; ++num1)
  611.             {
  612.                 int c = (int)text[num1 + textOffset] & (int)byte.MaxValue;
  613.                 if (((c & 224) == 64 || (c & 224) == 32) && c != 95)
  614.                 {
  615.                     if (flag1)
  616.                     {
  617.                         if (num2 + 1 <= dataLength)
  618.                         {
  619.                             data[dataOffset + num2++] = (byte)240;
  620.                             flag1 = false;
  621.                         }
  622.                         else
  623.                             break;
  624.                     }
  625.                     int num6 = c & 63;
  626.                     num3 |= num6 << num4;
  627.                     if (num4 == 0)
  628.                     {
  629.                         if (num2 + 3 <= dataLength)
  630.                         {
  631.                             byte[] numArray1 = data;
  632.                             int num10 = dataOffset;
  633.                             int num11 = num2;
  634.                             int num12 = num11 + 1;
  635.                             int index3 = num10 + num11;
  636.                             int num13 = (int)(byte)(num3 >> 16);
  637.                             numArray1[index3] = (byte)num13;
  638.                             byte[] numArray2 = data;
  639.                             int num14 = dataOffset;
  640.                             int num15 = num12;
  641.                             int num16 = num15 + 1;
  642.                             int index4 = num14 + num15;
  643.                             int num17 = (int)(byte)(num3 >> 8);
  644.                             numArray2[index4] = (byte)num17;
  645.                             byte[] numArray3 = data;
  646.                             int num18 = dataOffset;
  647.                             int num19 = num16;
  648.                             num2 = num19 + 1;
  649.                             int index5 = num18 + num19;
  650.                             int num20 = (int)(byte)num3;
  651.                             numArray3[index5] = (byte)num20;
  652.                             num3 = 0;
  653.                             num4 = 18;
  654.                         }
  655.                         else
  656.                             break;
  657.                     }
  658.                     else
  659.                         num4 -= 6;
  660.                 }
  661.                 else
  662.                 {
  663.                     if (!flag1)
  664.                     {
  665.                         num3 |= 31 << num4;
  666.                         if (num2 + 3 - num4 / 8 <= dataLength)
  667.                         {
  668.                             data[dataOffset + num2++] = (byte)(num3 >> 16);
  669.                             if (num4 <= 12)
  670.                                 data[dataOffset + num2++] = (byte)(num3 >> 8);
  671.                             if (num4 <= 6)
  672.                                 data[dataOffset + num2++] = (byte)num3;
  673.                             flag1 = true;
  674.                             num4 = 18;
  675.                             num3 = 0;
  676.                         }
  677.                         else
  678.                             break;
  679.                     }
  680.                     if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) && textOffset + num1 > 0 && (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset + num1 - 1] & (int)byte.MaxValue) && prevEnc == 6) && (data[dataOffset - 1] >= (byte)49 && data[dataOffset - 1] <= (byte)58))
  681.                     {
  682.                         data[dataOffset + num2 - 1] = (byte)((((int)text[textOffset - 1] & (int)byte.MaxValue) - 48) * 10 + c - 48 + 130);
  683.                         --num2;
  684.                     }
  685.                     else
  686.                     {
  687.                         if (iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset + num1, 1, data, dataOffset + num2, dataLength, -1, -1, origDataOffset) < 0)
  688.                             return -1;
  689.                         if (data[dataOffset + num2] == (byte)235)
  690.                             ++num2;
  691.                         ++num2;
  692.                     }
  693.                 }
  694.             }
  695.             if (num1 != textLength)
  696.                 return -1;
  697.             if (!sizeFixed && (symbolIndex == text.Length - 1 || symbolIndex < 0))
  698.             {
  699.                 num7 = int.MaxValue;
  700.                 for (int index3 = 0; index3 < iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length; ++index3)
  701.                 {
  702.                     if (iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index3].dataSize >= dataOffset + num2 + (3 - num4 / 6))
  703.                     {
  704.                         num7 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index3].dataSize;
  705.                         break;
  706.                     }
  707.                 }
  708.             }
  709.             if (num7 - dataOffset - num2 <= 2 && num4 >= 6)
  710.             {
  711.                 if (num4 != 18 && num2 + 2 - num4 / 8 > dataLength)
  712.                     return -1;
  713.                 if (num4 <= 12)
  714.                 {
  715.                     byte num6 = (byte)(num3 >> 18 & 63);
  716.                     if (((int)num6 & 32) == 0)
  717.                         num6 |= (byte)64;
  718.                     data[dataOffset + num2++] = (byte)((uint)num6 + 1U);
  719.                 }
  720.                 if (num4 <= 6)
  721.                 {
  722.                     byte num6 = (byte)(num3 >> 12 & 63);
  723.                     if (((int)num6 & 32) == 0)
  724.                         num6 |= (byte)64;
  725.                     data[dataOffset + num2++] = (byte)((uint)num6 + 1U);
  726.                 }
  727.             }
  728.             else if (!flag1)
  729.             {
  730.                 int num6 = num3 | 31 << num4;
  731.                 if (num2 + 3 - num4 / 8 > dataLength)
  732.                     return -1;
  733.                 data[dataOffset + num2++] = (byte)(num6 >> 16);
  734.                 if (num4 <= 12)
  735.                     data[dataOffset + num2++] = (byte)(num6 >> 8);
  736.                 if (num4 <= 6)
  737.                     data[dataOffset + num2++] = (byte)num6;
  738.             }
  739.             return num2 + dataOffset - origDataOffset;
  740.         }
  741.  
  742.         private int C40OrTextEncodation(
  743.           byte[] text,
  744.           int textOffset,
  745.           int textLength,
  746.           byte[] data,
  747.           int dataOffset,
  748.           int dataLength,
  749.           bool c40,
  750.           int symbolIndex,
  751.           int prevEnc,
  752.           int origDataOffset)
  753.         {
  754.             if (textLength == 0)
  755.                 return 0;
  756.             int num1 = 0;
  757.             int num2 = 0;
  758.             string str1 = "!\"#$%&'()*+,-./:;<=>?@[\\]^_";
  759.             string str2;
  760.             string str3;
  761.             if (c40)
  762.             {
  763.                 str2 = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  764.                 str3 = "`abcdefghijklmnopqrstuvwxyz{|}~\\177";
  765.             }
  766.             else
  767.             {
  768.                 str2 = " 0123456789abcdefghijklmnopqrstuvwxyz";
  769.                 str3 = "`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~\\177";
  770.             }
  771.             bool flag1 = true;
  772.             bool flag2 = false;
  773.             int num3 = c40 ? 2 : 3;
  774.             if (prevEnc == num3)
  775.             {
  776.                 flag2 = true;
  777.                 int index1 = symbolIndex - 1;
  778.                 while (index1 > 0 && switchMode[num3 - 1][index1] == num3)
  779.                     --index1;
  780.                 int num4 = -1;
  781.                 int num5 = 0;
  782.                 if (symbolIndex - index1 >= 5)
  783.                 {
  784.                     for (int index2 = symbolIndex - index1; index2 > 0; --index2)
  785.                     {
  786.                         if (((int)text[textOffset - index2] & (int)byte.MaxValue) > (int)sbyte.MaxValue)
  787.                             num5 += 2;
  788.                         else
  789.                             ++num5;
  790.                     }
  791.                     for (int index2 = 1; index2 <= num5 && index2 <= dataOffset; ++index2)
  792.                     {
  793.                         if (data[dataOffset - index2] == (byte)254)
  794.                         {
  795.                             num4 = dataOffset - index2;
  796.                             break;
  797.                         }
  798.                     }
  799.                     int num6 = 0;
  800.                     if (num4 >= 0)
  801.                     {
  802.                         for (int index2 = num4 + 1; index2 < dataOffset; ++index2)
  803.                         {
  804.                             if (data[index2] == (byte)235)
  805.                                 ++index2;
  806.                             if (data[index2] >= (byte)129 && data[index2] <= (byte)229)
  807.                                 ++num6;
  808.                             ++num6;
  809.                         }
  810.                     }
  811.                     else
  812.                         num6 = symbolIndex - index1;
  813.                     int num7 = 0;
  814.                     for (int index2 = num6; index2 > 0; --index2)
  815.                     {
  816.                         int num8 = 0;
  817.                         int num9 = 0;
  818.                         for (int index3 = index2; index3 >= 0; --index3)
  819.                         {
  820.                             int c = (int)text[textOffset - index3] & (int)byte.MaxValue;
  821.                             if (c > (int)sbyte.MaxValue)
  822.                             {
  823.                                 c -= 128;
  824.                                 num9 += 2;
  825.                             }
  826.                             num9 += str2.IndexOf((char)c) >= 0 ? 1 : 2;
  827.                             if (c > (int)sbyte.MaxValue)
  828.                             {
  829.                                 num8 += 2;
  830.                             }
  831.                             else
  832.                             {
  833.                                 if (index3 > 0 && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit(c) && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index3 + 1] & (int)byte.MaxValue))
  834.                                 {
  835.                                     num9 += str2.IndexOf((char)text[textOffset - index3 + 1]) >= 0 ? 1 : 2;
  836.                                     --index3;
  837.                                     num7 = num8 + 1;
  838.                                 }
  839.                                 ++num8;
  840.                             }
  841.                             if (index3 == 1)
  842.                                 num7 = num8;
  843.                         }
  844.                         flag1 = num4 < 0 || dataOffset - num8 != num4;
  845.                         if (num9 % 3 == 0 && num9 / 3 * 2 + (flag1 ? 2 : 0) < num8)
  846.                         {
  847.                             flag2 = false;
  848.                             textLength = index2 + 1;
  849.                             textOffset -= index2;
  850.                             dataOffset -= flag1 ? num7 : num7 + 1;
  851.                             dataLength += flag1 ? num7 : num7 + 1;
  852.                             break;
  853.                         }
  854.                         if (iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index2] & (int)byte.MaxValue) && iTextSharp.text.pdf.MyBarcodeDatamatrix.IsDigit((int)text[textOffset - index2 + 1] & (int)byte.MaxValue))
  855.                             --index2;
  856.                     }
  857.                 }
  858.             }
  859.             else if (symbolIndex != -1)
  860.                 flag2 = true;
  861.             if (flag2)
  862.                 return iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset, 1, data, dataOffset, dataLength, prevEnc == num3 ? 1 : -1, 1, origDataOffset);
  863.             if (flag1)
  864.                 data[dataOffset + num2++] = !c40 ? (byte)239 : (byte)230;
  865.             int[] numArray1 = new int[textLength * 4 + 10];
  866.             int num10 = 0;
  867.             int num11 = 0;
  868.             int num12 = 0;
  869.             while (num1 < textLength)
  870.             {
  871.                 if (num10 % 3 == 0)
  872.                 {
  873.                     num11 = num1;
  874.                     num12 = num10;
  875.                 }
  876.                 int num4 = (int)text[textOffset + num1++] & (int)byte.MaxValue;
  877.                 if (num4 > (int)sbyte.MaxValue)
  878.                 {
  879.                     num4 -= 128;
  880.                     int[] numArray2 = numArray1;
  881.                     int index1 = num10;
  882.                     int num5 = index1 + 1;
  883.                     numArray2[index1] = 1;
  884.                     int[] numArray3 = numArray1;
  885.                     int index2 = num5;
  886.                     num10 = index2 + 1;
  887.                     numArray3[index2] = 30;
  888.                 }
  889.                 int num6 = str2.IndexOf((char)num4);
  890.                 if (num6 >= 0)
  891.                     numArray1[num10++] = num6 + 3;
  892.                 else if (num4 < 32)
  893.                 {
  894.                     int[] numArray2 = numArray1;
  895.                     int index1 = num10;
  896.                     int num5 = index1 + 1;
  897.                     numArray2[index1] = 0;
  898.                     int[] numArray3 = numArray1;
  899.                     int index2 = num5;
  900.                     num10 = index2 + 1;
  901.                     int num7 = num4;
  902.                     numArray3[index2] = num7;
  903.                 }
  904.                 else
  905.                 {
  906.                     int num5;
  907.                     if ((num5 = str1.IndexOf((char)num4)) >= 0)
  908.                     {
  909.                         int[] numArray2 = numArray1;
  910.                         int index1 = num10;
  911.                         int num7 = index1 + 1;
  912.                         numArray2[index1] = 1;
  913.                         int[] numArray3 = numArray1;
  914.                         int index2 = num7;
  915.                         num10 = index2 + 1;
  916.                         int num8 = num5;
  917.                         numArray3[index2] = num8;
  918.                     }
  919.                     else
  920.                     {
  921.                         int num7;
  922.                         if ((num7 = str3.IndexOf((char)num4)) >= 0)
  923.                         {
  924.                             int[] numArray2 = numArray1;
  925.                             int index1 = num10;
  926.                             int num8 = index1 + 1;
  927.                             numArray2[index1] = 2;
  928.                             int[] numArray3 = numArray1;
  929.                             int index2 = num8;
  930.                             num10 = index2 + 1;
  931.                             int num9 = num7;
  932.                             numArray3[index2] = num9;
  933.                         }
  934.                     }
  935.                 }
  936.             }
  937.             if (num10 % 3 != 0)
  938.             {
  939.                 num1 = num11;
  940.                 num10 = num12;
  941.             }
  942.             if (num10 / 3 * 2 > dataLength - 2)
  943.                 return -1;
  944.             for (int index1 = 0; index1 < num10; index1 += 3)
  945.             {
  946.                 int num4 = 1600 * numArray1[index1] + 40 * numArray1[index1 + 1] + numArray1[index1 + 2] + 1;
  947.                 byte[] numArray2 = data;
  948.                 int num5 = dataOffset;
  949.                 int num6 = num2;
  950.                 int num7 = num6 + 1;
  951.                 int index2 = num5 + num6;
  952.                 int num8 = (int)(byte)(num4 / 256);
  953.                 numArray2[index2] = (byte)num8;
  954.                 byte[] numArray3 = data;
  955.                 int num9 = dataOffset;
  956.                 int num13 = num7;
  957.                 num2 = num13 + 1;
  958.                 int index3 = num9 + num13;
  959.                 int num14 = (int)(byte)num4;
  960.                 numArray3[index3] = (byte)num14;
  961.             }
  962.             if (dataLength - num2 > 2)
  963.                 data[dataOffset + num2++] = (byte)254;
  964.             if (symbolIndex < 0 && textLength > num1)
  965.                 return iTextSharp.text.pdf.MyBarcodeDatamatrix.AsciiEncodation(text, textOffset + num1, textLength - num1, data, dataOffset + num2, dataLength - num2, -1, -1, origDataOffset);
  966.             return num2 + dataOffset - origDataOffset;
  967.         }
  968.  
  969.         private static int MinValueInColumn(int[][] array, int column)
  970.         {
  971.             int maxValue = int.MaxValue;
  972.             for (int index = 0; index < 6; ++index)
  973.             {
  974.                 if (array[index][column] < maxValue && array[index][column] >= 0)
  975.                     maxValue = array[index][column];
  976.             }
  977.             if (maxValue == int.MaxValue)
  978.                 return -1;
  979.             return maxValue;
  980.         }
  981.  
  982.         private static int ValuePositionInColumn(int[][] array, int column, int value)
  983.         {
  984.             for (int index = 0; index < 6; ++index)
  985.             {
  986.                 if (array[index][column] == value)
  987.                     return index;
  988.             }
  989.             return -1;
  990.         }
  991.  
  992.         private void SolveFAndSwitchMode(int[] forMin, int mode, int currIndex)
  993.         {
  994.             if (forMin[mode] >= 0 && f[mode][currIndex - 1] >= 0)
  995.             {
  996.                 f[mode][currIndex] = forMin[mode];
  997.                 switchMode[mode][currIndex] = mode + 1;
  998.             }
  999.             else
  1000.                 f[mode][currIndex] = int.MaxValue;
  1001.             for (int index = 0; index < 6; ++index)
  1002.             {
  1003.                 if (forMin[index] < f[mode][currIndex] && forMin[index] >= 0 && f[index][currIndex - 1] >= 0)
  1004.                 {
  1005.                     f[mode][currIndex] = forMin[index];
  1006.                     switchMode[mode][currIndex] = index + 1;
  1007.                 }
  1008.             }
  1009.             if (f[mode][currIndex] != int.MaxValue)
  1010.                 return;
  1011.             f[mode][currIndex] = -1;
  1012.         }
  1013.  
  1014.         private int GetEncodation(
  1015.           byte[] text,
  1016.           int textOffset,
  1017.           int textSize,
  1018.           byte[] data,
  1019.           int dataOffset,
  1020.           int dataSize,
  1021.           int options,
  1022.           bool sizeFixed)
  1023.         {
  1024.             if (dataSize < 0)
  1025.                 return -1;
  1026.             options &= 7;
  1027.             switch (options)
  1028.             {
  1029.                 case 0:
  1030.                     if (textSize == 0)
  1031.                         return 0;
  1032.                     int length = data.Length;
  1033.                     byte[][] numArray1 = new byte[6][];
  1034.                     for (int index = 0; index < numArray1.Length; ++index)
  1035.                         numArray1[index] = new byte[length];
  1036.                     for (int index = 0; index < 6; ++index)
  1037.                     {
  1038.                         Array.Copy((Array)data, 0, (Array)numArray1[index], 0, data.Length);
  1039.                         switchMode[index][0] = index + 1;
  1040.                     }
  1041.                     f[0][0] = AsciiEncodation(text, textOffset, 1, numArray1[0], dataOffset, dataSize, 0, -1, dataOffset);
  1042.                     f[1][0] = C40OrTextEncodation(text, textOffset, 1, numArray1[1], dataOffset, dataSize, true, 0, -1, dataOffset);
  1043.                     f[2][0] = C40OrTextEncodation(text, textOffset, 1, numArray1[2], dataOffset, dataSize, false, 0, -1, dataOffset);
  1044.                     f[3][0] = B256Encodation(text, textOffset, 1, numArray1[3], dataOffset, dataSize, 0, -1, dataOffset);
  1045.                     f[4][0] = X12Encodation(text, textOffset, 1, numArray1[4], dataOffset, dataSize, 0, -1, dataOffset);
  1046.                     f[5][0] = EdifactEncodation(text, textOffset, 1, numArray1[5], dataOffset, dataSize, 0, -1, dataOffset, sizeFixed);
  1047.                     int[] numArray2 = new int[6];
  1048.                     for (int index1 = 1; index1 < textSize; ++index1)
  1049.                     {
  1050.                         int[] forMin = new int[6];
  1051.                         for (int index2 = 0; index2 < 6; ++index2)
  1052.                             numArray2[index2] = f[index2][index1 - 1] >= 0 ? f[index2][index1 - 1] : int.MaxValue;
  1053.                         for (int mode = 0; mode < 6; ++mode)
  1054.                         {
  1055.                             byte[][] numArray3 = new byte[6][];
  1056.                             for (int index2 = 0; index2 < numArray3.Length; ++index2)
  1057.                                 numArray3[index2] = new byte[length];
  1058.                             for (int index2 = 0; index2 < 6; ++index2)
  1059.                             {
  1060.                                 Array.Copy((Array)numArray1[index2], 0, (Array)numArray3[index2], 0, data.Length);
  1061.                                 if (mode == 0)
  1062.                                     forMin[index2] = AsciiEncodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], index1, index2 + 1, dataOffset);
  1063.                                 if (mode == 1)
  1064.                                     forMin[index2] = C40OrTextEncodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], true, index1, index2 + 1, dataOffset);
  1065.                                 if (mode == 2)
  1066.                                     forMin[index2] = C40OrTextEncodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], false, index1, index2 + 1, dataOffset);
  1067.                                 if (mode == 3)
  1068.                                     forMin[index2] = B256Encodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], index1, index2 + 1, dataOffset);
  1069.                                 if (mode == 4)
  1070.                                     forMin[index2] = X12Encodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], index1, index2 + 1, dataOffset);
  1071.                                 if (mode == 5)
  1072.                                     forMin[index2] = EdifactEncodation(text, textOffset + index1, 1, numArray3[index2], numArray2[index2] + dataOffset, dataSize - numArray2[index2], index1, index2 + 1, dataOffset, sizeFixed);
  1073.                             }
  1074.                             SolveFAndSwitchMode(forMin, mode, index1);
  1075.                             if (switchMode[mode][index1] != 0)
  1076.                                 Array.Copy((Array)numArray3[switchMode[mode][index1] - 1], 0, (Array)numArray1[mode], 0, data.Length);
  1077.                         }
  1078.                     }
  1079.                     int num = iTextSharp.text.pdf.MyBarcodeDatamatrix.MinValueInColumn(f, textSize - 1);
  1080.                     if (num > dataSize || num < 0)
  1081.                         return -1;
  1082.                     int index3 = iTextSharp.text.pdf.MyBarcodeDatamatrix.ValuePositionInColumn(f, textSize - 1, num);
  1083.                     Array.Copy((Array)numArray1[index3], 0, (Array)data, 0, data.Length);
  1084.                     return num;
  1085.                 case 1:
  1086.                     return AsciiEncodation(text, textOffset, textSize, data, dataOffset, dataSize, -1, -1, dataOffset);
  1087.                 case 2:
  1088.                     return C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, true, -1, -1, dataOffset);
  1089.                 case 3:
  1090.                     return C40OrTextEncodation(text, textOffset, textSize, data, dataOffset, dataSize, false, -1, -1, dataOffset);
  1091.                 case 4:
  1092.                     return B256Encodation(text, textOffset, textSize, data, dataOffset, dataSize, -1, -1, dataOffset);
  1093.                 case 5:
  1094.                     return X12Encodation(text, textOffset, textSize, data, dataOffset, dataSize, -1, -1, dataOffset);
  1095.                 case 6:
  1096.                     return EdifactEncodation(text, textOffset, textSize, data, dataOffset, dataSize, -1, -1, dataOffset, sizeFixed);
  1097.                 case 7:
  1098.                     if (textSize > dataSize)
  1099.                         return -1;
  1100.                     Array.Copy((Array)text, textOffset, (Array)data, dataOffset, textSize);
  1101.                     return textSize;
  1102.                 default:
  1103.                     return -1;
  1104.             }
  1105.         }
  1106.  
  1107.         private static int GetNumber(byte[] text, int ptrIn, int n)
  1108.         {
  1109.             int num1 = 0;
  1110.             for (int index = 0; index < n; ++index)
  1111.             {
  1112.                 int num2 = (int)text[ptrIn++] & (int)byte.MaxValue;
  1113.                 if (num2 < 48 || num2 > 57)
  1114.                     return -1;
  1115.                 num1 = num1 * 10 + num2 - 48;
  1116.             }
  1117.             return num1;
  1118.         }
  1119.  
  1120.         private int ProcessExtensions(byte[] text, int textOffset, int textSize, byte[] data)
  1121.         {
  1122.             if ((this.options & 32) == 0)
  1123.                 return 0;
  1124.             int num1 = 0;
  1125.             int num2 = 0;
  1126.             int num3 = 0;
  1127.             while (num2 < textSize && num1 <= 20)
  1128.             {
  1129.                 int num4 = (int)text[textOffset + num2++] & (int)byte.MaxValue;
  1130.                 ++num1;
  1131.                 switch (num4)
  1132.                 {
  1133.                     case 46:
  1134.                         this.extOut = num2;
  1135.                         return num3;
  1136.                     case 101:
  1137.                         if (num2 + 6 > textSize)
  1138.                             return -1;
  1139.                         int number1 = iTextSharp.text.pdf.MyBarcodeDatamatrix.GetNumber(text, textOffset + num2, 6);
  1140.                         if (number1 < 0)
  1141.                             return -1;
  1142.                         num2 += 6;
  1143.                         byte[] numArray1 = data;
  1144.                         int index1 = num3;
  1145.                         int num5 = index1 + 1;
  1146.                         numArray1[index1] = (byte)241;
  1147.                         if (number1 < (int)sbyte.MaxValue)
  1148.                         {
  1149.                             byte[] numArray2 = data;
  1150.                             int index2 = num5;
  1151.                             num3 = index2 + 1;
  1152.                             int num6 = (int)(byte)(number1 + 1);
  1153.                             numArray2[index2] = (byte)num6;
  1154.                             continue;
  1155.                         }
  1156.                         if (number1 < 16383)
  1157.                         {
  1158.                             byte[] numArray2 = data;
  1159.                             int index2 = num5;
  1160.                             int num6 = index2 + 1;
  1161.                             int num7 = (int)(byte)((number1 - (int)sbyte.MaxValue) / 254 + 128);
  1162.                             numArray2[index2] = (byte)num7;
  1163.                             byte[] numArray3 = data;
  1164.                             int index3 = num6;
  1165.                             num3 = index3 + 1;
  1166.                             int num8 = (int)(byte)((number1 - (int)sbyte.MaxValue) % 254 + 1);
  1167.                             numArray3[index3] = (byte)num8;
  1168.                             continue;
  1169.                         }
  1170.                         byte[] numArray4 = data;
  1171.                         int index4 = num5;
  1172.                         int num9 = index4 + 1;
  1173.                         int num10 = (int)(byte)((number1 - 16383) / 64516 + 192);
  1174.                         numArray4[index4] = (byte)num10;
  1175.                         byte[] numArray5 = data;
  1176.                         int index5 = num9;
  1177.                         int num11 = index5 + 1;
  1178.                         int num12 = (int)(byte)((number1 - 16383) / 254 % 254 + 1);
  1179.                         numArray5[index5] = (byte)num12;
  1180.                         byte[] numArray6 = data;
  1181.                         int index6 = num11;
  1182.                         num3 = index6 + 1;
  1183.                         int num13 = (int)(byte)((number1 - 16383) % 254 + 1);
  1184.                         numArray6[index6] = (byte)num13;
  1185.                         continue;
  1186.                     case 102:
  1187.                         switch (num1)
  1188.                         {
  1189.                             case 1:
  1190.                                 data[num3++] = (byte)232;
  1191.                                 continue;
  1192.                             case 2:
  1193.                                 if (text[textOffset] == (byte)115 || text[textOffset] == (byte)109)
  1194.                                     goto case 1;
  1195.                                 else
  1196.                                     break;
  1197.                         }
  1198.                         return -1;
  1199.                     case 109:
  1200.                         if (num1 != 1 || num2 + 1 > textSize)
  1201.                             return -1;
  1202.                         int num14 = (int)text[textOffset + num2++] & (int)byte.MaxValue;
  1203.                         if (num14 != 53 && num14 != 53)
  1204.                             return -1;
  1205.                         byte[] numArray7 = data;
  1206.                         int index7 = num3;
  1207.                         int num15 = index7 + 1;
  1208.                         numArray7[index7] = (byte)234;
  1209.                         byte[] numArray8 = data;
  1210.                         int index8 = num15;
  1211.                         num3 = index8 + 1;
  1212.                         int num16 = num14 == 53 ? 236 : 237;
  1213.                         numArray8[index8] = (byte)num16;
  1214.                         continue;
  1215.                     case 112:
  1216.                         if (num1 != 1)
  1217.                             return -1;
  1218.                         data[num3++] = (byte)234;
  1219.                         continue;
  1220.                     case 115:
  1221.                         if (num1 != 1 || num2 + 9 > textSize)
  1222.                             return -1;
  1223.                         int number2 = iTextSharp.text.pdf.MyBarcodeDatamatrix.GetNumber(text, textOffset + num2, 2);
  1224.                         if (number2 <= 0 || number2 > 16)
  1225.                             return -1;
  1226.                         int num17 = num2 + 2;
  1227.                         int number3 = iTextSharp.text.pdf.MyBarcodeDatamatrix.GetNumber(text, textOffset + num17, 2);
  1228.                         if (number3 <= 1 || number3 > 16)
  1229.                             return -1;
  1230.                         int num18 = num17 + 2;
  1231.                         int number4 = iTextSharp.text.pdf.MyBarcodeDatamatrix.GetNumber(text, textOffset + num18, 5);
  1232.                         if (number4 < 0 || number2 >= 64516)
  1233.                             return -1;
  1234.                         num2 = num18 + 5;
  1235.                         byte[] numArray9 = data;
  1236.                         int index9 = num3;
  1237.                         int num19 = index9 + 1;
  1238.                         numArray9[index9] = (byte)233;
  1239.                         byte[] numArray10 = data;
  1240.                         int index10 = num19;
  1241.                         int num20 = index10 + 1;
  1242.                         int num21 = (int)(byte)(number2 - 1 << 4 | 17 - number3);
  1243.                         numArray10[index10] = (byte)num21;
  1244.                         byte[] numArray11 = data;
  1245.                         int index11 = num20;
  1246.                         int num22 = index11 + 1;
  1247.                         int num23 = (int)(byte)(number4 / 254 + 1);
  1248.                         numArray11[index11] = (byte)num23;
  1249.                         byte[] numArray12 = data;
  1250.                         int index12 = num22;
  1251.                         num3 = index12 + 1;
  1252.                         int num24 = (int)(byte)(number4 % 254 + 1);
  1253.                         numArray12[index12] = (byte)num24;
  1254.                         continue;
  1255.                     default:
  1256.                         continue;
  1257.                 }
  1258.             }
  1259.             return -1;
  1260.         }
  1261.  
  1262.         public virtual int Generate(string text)
  1263.         {
  1264.             byte[] bytes = Encoding.GetEncoding(this.encoding).GetBytes(text);
  1265.             return this.Generate(bytes, 0, bytes.Length);
  1266.         }
  1267.  
  1268.         public virtual int Generate(string text, string encoding)
  1269.         {
  1270.             byte[] bytes = Encoding.GetEncoding(encoding).GetBytes(text);
  1271.             return this.Generate(bytes, 0, bytes.Length);
  1272.         }
  1273.  
  1274.         public virtual int Generate(byte[] text, int textOffset, int textSize)
  1275.         {
  1276.             byte[] numArray = new byte[2500];
  1277.             this.extOut = 0;
  1278.             int dataOffset = this.ProcessExtensions(text, textOffset, textSize, numArray);
  1279.             if (dataOffset < 0)
  1280.                 return 5;
  1281.             int length = textSize - this.extOut;
  1282.             f = new int[6][];
  1283.             switchMode = new int[6][];
  1284.             for (int index = 0; index < f.Length; ++index)
  1285.             {
  1286.                 f[index] = new int[length];
  1287.                 switchMode[index] = new int[length];
  1288.             }
  1289.             int position;
  1290.             iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams dmSize1;
  1291.             if (this.height == 0 || this.width == 0)
  1292.             {
  1293.                 iTextSharp.text.pdf.MyBarcodeDatamatrix.DmParams dmSize2 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length - 1];
  1294.                 int encodation = GetEncodation(text, textOffset + this.extOut, textSize - this.extOut, numArray, dataOffset, dmSize2.dataSize - dataOffset, this.options, false);
  1295.                 if (encodation < 0)
  1296.                     return 1;
  1297.                 position = encodation + dataOffset;
  1298.                 int index = 0;
  1299.                 while (index < iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length && iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index].dataSize < position)
  1300.                     ++index;
  1301.                 dmSize1 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index];
  1302.                 this.height = dmSize1.height;
  1303.                 this.width = dmSize1.width;
  1304.             }
  1305.             else
  1306.             {
  1307.                 int index = 0;
  1308.                 while (index < iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length && (this.height != iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index].height || this.width != iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index].width))
  1309.                     ++index;
  1310.                 if (index == iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes.Length)
  1311.                     return 3;
  1312.                 dmSize1 = iTextSharp.text.pdf.MyBarcodeDatamatrix.dmSizes[index];
  1313.                 int encodation = GetEncodation(text, textOffset + this.extOut, textSize - this.extOut, numArray, dataOffset, dmSize1.dataSize - dataOffset, this.options, true);
  1314.                 if (encodation < 0)
  1315.                     return 1;
  1316.                 position = encodation + dataOffset;
  1317.             }
  1318.             if ((this.options & 64) != 0)
  1319.                 return 0;
  1320.             this.image = new byte[(dmSize1.width + 2 * this.ws + 7) / 8 * (dmSize1.height + 2 * this.ws)];
  1321.             iTextSharp.text.pdf.MyBarcodeDatamatrix.MakePadding(numArray, position, dmSize1.dataSize - position);
  1322.             this.place = iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.DoPlacement(dmSize1.height - dmSize1.height / dmSize1.heightSection * 2, dmSize1.width - dmSize1.width / dmSize1.widthSection * 2);
  1323.             int dataSize = dmSize1.dataSize + (dmSize1.dataSize + 2) / dmSize1.dataBlock * dmSize1.errorBlock;
  1324.             iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.GenerateECC(numArray, dmSize1.dataSize, dmSize1.dataBlock, dmSize1.errorBlock);
  1325.             this.Draw(numArray, dataSize, dmSize1);
  1326.             return 0;
  1327.         }
  1328.  
  1329.         public virtual void PlaceBarcode(
  1330.           PdfContentByte cb,
  1331.           BaseColor foreground,
  1332.           float moduleHeight,
  1333.           float moduleWidth)
  1334.         {
  1335.             int num1 = this.width + 2 * this.ws;
  1336.             int num2 = this.height + 2 * this.ws;
  1337.             int num3 = (num1 + 7) / 8;
  1338.             cb.SetColorFill(foreground);
  1339.             for (int index1 = 0; index1 < num2; ++index1)
  1340.             {
  1341.                 int num4 = index1 * num3;
  1342.                 for (int index2 = 0; index2 < num1; ++index2)
  1343.                 {
  1344.                     if ((((int)this.image[num4 + index2 / 8] & (int)byte.MaxValue) << index2 % 8 & 128) != 0)
  1345.                         cb.Rectangle((float)index2 * moduleWidth, (float)(num2 - index1 - 1) * moduleHeight, moduleWidth, moduleHeight);
  1346.                 }
  1347.             }
  1348.             cb.Fill();
  1349.         }
  1350.  
  1351.         /// Gets an <CODE>Image</CODE>
  1352.         ///  with the barcode. A successful call to the method <CODE>generate()</CODE>
  1353.         ///
  1354.         ///             before calling this method is required.
  1355.         ///             @return the barcode <CODE>Image</CODE>
  1356.         ///
  1357.         ///             @throws BadElementException on error
  1358.         public virtual iTextSharp.text.Image CreateImage()
  1359.         {
  1360.             if (this.image == null)
  1361.                 return (iTextSharp.text.Image)null;
  1362.             return iTextSharp.text.Image.GetInstance(this.width + 2 * this.ws, this.height + 2 * this.ws, false, 256, 0, CCITTG4Encoder.Compress(this.image, this.width + 2 * this.ws, this.height + 2 * this.ws), (int[])null);
  1363.         }
  1364.  
  1365.         /// Creates a <CODE>java.awt.Image</CODE>
  1366.         /// . A successful call to the method <CODE>generate()</CODE>
  1367.         ///
  1368.         ///             before calling this method is required.
  1369.         ///             @param foreground the color of the bars
  1370.         ///             @param background the color of the background
  1371.         ///             @return the image
  1372.         public virtual System.Drawing.Image CreateDrawingImage(Color foreground, Color background)
  1373.         {
  1374.             if (this.image == null)
  1375.                 return (System.Drawing.Image)null;
  1376.             int height = this.height + 2 * this.ws;
  1377.             int width = this.width + 2 * this.ws;
  1378.             int num1 = (width + 7) / 8;
  1379.             Bitmap bitmap = new Bitmap(width, height);
  1380.             for (int y = 0; y < height; ++y)
  1381.             {
  1382.                 int num2 = y * num1;
  1383.                 for (int x = 0; x < width; ++x)
  1384.                 {
  1385.                     int num3 = ((int)this.image[num2 + x / 8] & (int)byte.MaxValue) << x % 8;
  1386.                     bitmap.SetPixel(x, y, (num3 & 128) == 0 ? background : foreground);
  1387.                 }
  1388.             }
  1389.             return (System.Drawing.Image)bitmap;
  1390.         }
  1391.  
  1392.         /// Gets the generated image. The image is represented as a stream of bytes, each byte representing
  1393.         ///             8 pixels, 0 for white and 1 for black, with the high-order bit of each byte first. Each row
  1394.         ///             is aligned at byte boundaries. The dimensions of the image are defined by height and width
  1395.         ///             plus 2 * ws.
  1396.         ///             @return the generated image
  1397.         public virtual byte[] BitImage
  1398.         {
  1399.             get
  1400.             {
  1401.                 return this.image;
  1402.             }
  1403.         }
  1404.  
  1405.         public virtual int Height
  1406.         {
  1407.             get
  1408.             {
  1409.                 return this.height;
  1410.             }
  1411.             set
  1412.             {
  1413.                 this.height = value;
  1414.             }
  1415.         }
  1416.  
  1417.         public virtual int Width
  1418.         {
  1419.             get
  1420.             {
  1421.                 return this.width;
  1422.             }
  1423.             set
  1424.             {
  1425.                 this.width = value;
  1426.             }
  1427.         }
  1428.  
  1429.         /// Gets/sets the whitespace border around the barcode.
  1430.         ///             @param ws the whitespace border around the barcode
  1431.         public virtual int Ws
  1432.         {
  1433.             get
  1434.             {
  1435.                 return this.ws;
  1436.             }
  1437.             set
  1438.             {
  1439.                 this.ws = value;
  1440.             }
  1441.         }
  1442.  
  1443.         public virtual int Options
  1444.         {
  1445.             get
  1446.             {
  1447.                 return this.options;
  1448.             }
  1449.             set
  1450.             {
  1451.                 this.options = value;
  1452.             }
  1453.         }
  1454.  
  1455.         public virtual bool ForceSquareSize
  1456.         {
  1457.             set
  1458.             {
  1459.                 this.forceSquareSize = value;
  1460.             }
  1461.         }
  1462.  
  1463.         private class DmParams
  1464.         {
  1465.             internal int height;
  1466.             internal int width;
  1467.             internal int heightSection;
  1468.             internal int widthSection;
  1469.             internal int dataSize;
  1470.             internal int dataBlock;
  1471.             internal int errorBlock;
  1472.  
  1473.             internal DmParams(
  1474.               int height,
  1475.               int width,
  1476.               int heightSection,
  1477.               int widthSection,
  1478.               int dataSize,
  1479.               int dataBlock,
  1480.               int errorBlock)
  1481.             {
  1482.                 this.height = height;
  1483.                 this.width = width;
  1484.                 this.heightSection = heightSection;
  1485.                 this.widthSection = widthSection;
  1486.                 this.dataSize = dataSize;
  1487.                 this.dataBlock = dataBlock;
  1488.                 this.errorBlock = errorBlock;
  1489.             }
  1490.         }
  1491.  
  1492.         internal class Placement
  1493.         {
  1494.             private static Dictionary<int, short[]> cache = new Dictionary<int, short[]>();
  1495.             private int nrow;
  1496.             private int ncol;
  1497.             private short[] array;
  1498.  
  1499.             private Placement()
  1500.             {
  1501.             }
  1502.  
  1503.             internal static short[] DoPlacement(int nrow, int ncol)
  1504.             {
  1505.                 int key = nrow * 1000 + ncol;
  1506.                 lock (iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.cache)
  1507.                 {
  1508.                     short[] numArray;
  1509.                     if (iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.cache.TryGetValue(key, out numArray))
  1510.                         return numArray;
  1511.                 }
  1512.                 iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement placement = new iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement();
  1513.                 placement.nrow = nrow;
  1514.                 placement.ncol = ncol;
  1515.                 placement.array = new short[nrow * ncol];
  1516.                 placement.Ecc200();
  1517.                 lock (iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.cache)
  1518.                     iTextSharp.text.pdf.MyBarcodeDatamatrix.Placement.cache[key] = placement.array;
  1519.                 return placement.array;
  1520.             }
  1521.  
  1522.             private void Module(int row, int col, int chr, int bit)
  1523.             {
  1524.                 if (row < 0)
  1525.                 {
  1526.                     row += this.nrow;
  1527.                     col += 4 - (this.nrow + 4) % 8;
  1528.                 }
  1529.                 if (col < 0)
  1530.                 {
  1531.                     col += this.ncol;
  1532.                     row += 4 - (this.ncol + 4) % 8;
  1533.                 }
  1534.                 this.array[row * this.ncol + col] = (short)(8 * chr + bit);
  1535.             }
  1536.  
  1537.             private void Utah(int row, int col, int chr)
  1538.             {
  1539.                 this.Module(row - 2, col - 2, chr, 0);
  1540.                 this.Module(row - 2, col - 1, chr, 1);
  1541.                 this.Module(row - 1, col - 2, chr, 2);
  1542.                 this.Module(row - 1, col - 1, chr, 3);
  1543.                 this.Module(row - 1, col, chr, 4);
  1544.                 this.Module(row, col - 2, chr, 5);
  1545.                 this.Module(row, col - 1, chr, 6);
  1546.                 this.Module(row, col, chr, 7);
  1547.             }
  1548.  
  1549.             private void Corner1(int chr)
  1550.             {
  1551.                 this.Module(this.nrow - 1, 0, chr, 0);
  1552.                 this.Module(this.nrow - 1, 1, chr, 1);
  1553.                 this.Module(this.nrow - 1, 2, chr, 2);
  1554.                 this.Module(0, this.ncol - 2, chr, 3);
  1555.                 this.Module(0, this.ncol - 1, chr, 4);
  1556.                 this.Module(1, this.ncol - 1, chr, 5);
  1557.                 this.Module(2, this.ncol - 1, chr, 6);
  1558.                 this.Module(3, this.ncol - 1, chr, 7);
  1559.             }
  1560.  
  1561.             private void Corner2(int chr)
  1562.             {
  1563.                 this.Module(this.nrow - 3, 0, chr, 0);
  1564.                 this.Module(this.nrow - 2, 0, chr, 1);
  1565.                 this.Module(this.nrow - 1, 0, chr, 2);
  1566.                 this.Module(0, this.ncol - 4, chr, 3);
  1567.                 this.Module(0, this.ncol - 3, chr, 4);
  1568.                 this.Module(0, this.ncol - 2, chr, 5);
  1569.                 this.Module(0, this.ncol - 1, chr, 6);
  1570.                 this.Module(1, this.ncol - 1, chr, 7);
  1571.             }
  1572.  
  1573.             private void Corner3(int chr)
  1574.             {
  1575.                 this.Module(this.nrow - 3, 0, chr, 0);
  1576.                 this.Module(this.nrow - 2, 0, chr, 1);
  1577.                 this.Module(this.nrow - 1, 0, chr, 2);
  1578.                 this.Module(0, this.ncol - 2, chr, 3);
  1579.                 this.Module(0, this.ncol - 1, chr, 4);
  1580.                 this.Module(1, this.ncol - 1, chr, 5);
  1581.                 this.Module(2, this.ncol - 1, chr, 6);
  1582.                 this.Module(3, this.ncol - 1, chr, 7);
  1583.             }
  1584.  
  1585.             private void Corner4(int chr)
  1586.             {
  1587.                 this.Module(this.nrow - 1, 0, chr, 0);
  1588.                 this.Module(this.nrow - 1, this.ncol - 1, chr, 1);
  1589.                 this.Module(0, this.ncol - 3, chr, 2);
  1590.                 this.Module(0, this.ncol - 2, chr, 3);
  1591.                 this.Module(0, this.ncol - 1, chr, 4);
  1592.                 this.Module(1, this.ncol - 3, chr, 5);
  1593.                 this.Module(1, this.ncol - 2, chr, 6);
  1594.                 this.Module(1, this.ncol - 1, chr, 7);
  1595.             }
  1596.  
  1597.             private void Ecc200()
  1598.             {
  1599.                 for (int index = 0; index < this.array.Length; ++index)
  1600.                     this.array[index] = (short)0;
  1601.                 int num = 1;
  1602.                 int row1 = 4;
  1603.                 int col1 = 0;
  1604.                 do
  1605.                 {
  1606.                     if (row1 == this.nrow && col1 == 0)
  1607.                         this.Corner1(num++);
  1608.                     if (row1 == this.nrow - 2 && col1 == 0 && this.ncol % 4 != 0)
  1609.                         this.Corner2(num++);
  1610.                     if (row1 == this.nrow - 2 && col1 == 0 && this.ncol % 8 == 4)
  1611.                         this.Corner3(num++);
  1612.                     if (row1 == this.nrow + 4 && col1 == 2 && this.ncol % 8 == 0)
  1613.                         this.Corner4(num++);
  1614.                     do
  1615.                     {
  1616.                         if (row1 < this.nrow && col1 >= 0 && this.array[row1 * this.ncol + col1] == (short)0)
  1617.                             this.Utah(row1, col1, num++);
  1618.                         row1 -= 2;
  1619.                         col1 += 2;
  1620.                     }
  1621.                     while (row1 >= 0 && col1 < this.ncol);
  1622.                     int row2 = row1 + 1;
  1623.                     int col2 = col1 + 3;
  1624.                     do
  1625.                     {
  1626.                         if (row2 >= 0 && col2 < this.ncol && this.array[row2 * this.ncol + col2] == (short)0)
  1627.                             this.Utah(row2, col2, num++);
  1628.                         row2 += 2;
  1629.                         col2 -= 2;
  1630.                     }
  1631.                     while (row2 < this.nrow && col2 >= 0);
  1632.                     row1 = row2 + 3;
  1633.                     col1 = col2 + 1;
  1634.                 }
  1635.                 while (row1 < this.nrow || col1 < this.ncol);
  1636.                 if (this.array[this.nrow * this.ncol - 1] != (short)0)
  1637.                     return;
  1638.                 this.array[this.nrow * this.ncol - 1] = this.array[this.nrow * this.ncol - this.ncol - 2] = (short)1;
  1639.             }
  1640.         }
  1641.  
  1642.         internal class ReedSolomon
  1643.         {
  1644.             private static readonly int[] log = new int[256]
  1645.             {
  1646.         0,
  1647.         (int) byte.MaxValue,
  1648.         1,
  1649.         240,
  1650.         2,
  1651.         225,
  1652.         241,
  1653.         53,
  1654.         3,
  1655.         38,
  1656.         226,
  1657.         133,
  1658.         242,
  1659.         43,
  1660.         54,
  1661.         210,
  1662.         4,
  1663.         195,
  1664.         39,
  1665.         114,
  1666.         227,
  1667.         106,
  1668.         134,
  1669.         28,
  1670.         243,
  1671.         140,
  1672.         44,
  1673.         23,
  1674.         55,
  1675.         118,
  1676.         211,
  1677.         234,
  1678.         5,
  1679.         219,
  1680.         196,
  1681.         96,
  1682.         40,
  1683.         222,
  1684.         115,
  1685.         103,
  1686.         228,
  1687.         78,
  1688.         107,
  1689.         125,
  1690.         135,
  1691.         8,
  1692.         29,
  1693.         162,
  1694.         244,
  1695.         186,
  1696.         141,
  1697.         180,
  1698.         45,
  1699.         99,
  1700.         24,
  1701.         49,
  1702.         56,
  1703.         13,
  1704.         119,
  1705.         153,
  1706.         212,
  1707.         199,
  1708.         235,
  1709.         91,
  1710.         6,
  1711.         76,
  1712.         220,
  1713.         217,
  1714.         197,
  1715.         11,
  1716.         97,
  1717.         184,
  1718.         41,
  1719.         36,
  1720.         223,
  1721.         253,
  1722.         116,
  1723.         138,
  1724.         104,
  1725.         193,
  1726.         229,
  1727.         86,
  1728.         79,
  1729.         171,
  1730.         108,
  1731.         165,
  1732.         126,
  1733.         145,
  1734.         136,
  1735.         34,
  1736.         9,
  1737.         74,
  1738.         30,
  1739.         32,
  1740.         163,
  1741.         84,
  1742.         245,
  1743.         173,
  1744.         187,
  1745.         204,
  1746.         142,
  1747.         81,
  1748.         181,
  1749.         190,
  1750.         46,
  1751.         88,
  1752.         100,
  1753.         159,
  1754.         25,
  1755.         231,
  1756.         50,
  1757.         207,
  1758.         57,
  1759.         147,
  1760.         14,
  1761.         67,
  1762.         120,
  1763.         128,
  1764.         154,
  1765.         248,
  1766.         213,
  1767.         167,
  1768.         200,
  1769.         63,
  1770.         236,
  1771.         110,
  1772.         92,
  1773.         176,
  1774.         7,
  1775.         161,
  1776.         77,
  1777.         124,
  1778.         221,
  1779.         102,
  1780.         218,
  1781.         95,
  1782.         198,
  1783.         90,
  1784.         12,
  1785.         152,
  1786.         98,
  1787.         48,
  1788.         185,
  1789.         179,
  1790.         42,
  1791.         209,
  1792.         37,
  1793.         132,
  1794.         224,
  1795.         52,
  1796.         254,
  1797.         239,
  1798.         117,
  1799.         233,
  1800.         139,
  1801.         22,
  1802.         105,
  1803.         27,
  1804.         194,
  1805.         113,
  1806.         230,
  1807.         206,
  1808.         87,
  1809.         158,
  1810.         80,
  1811.         189,
  1812.         172,
  1813.         203,
  1814.         109,
  1815.         175,
  1816.         166,
  1817.         62,
  1818.         (int) sbyte.MaxValue,
  1819.         247,
  1820.         146,
  1821.         66,
  1822.         137,
  1823.         192,
  1824.         35,
  1825.         252,
  1826.         10,
  1827.         183,
  1828.         75,
  1829.         216,
  1830.         31,
  1831.         83,
  1832.         33,
  1833.         73,
  1834.         164,
  1835.         144,
  1836.         85,
  1837.         170,
  1838.         246,
  1839.         65,
  1840.         174,
  1841.         61,
  1842.         188,
  1843.         202,
  1844.         205,
  1845.         157,
  1846.         143,
  1847.         169,
  1848.         82,
  1849.         72,
  1850.         182,
  1851.         215,
  1852.         191,
  1853.         251,
  1854.         47,
  1855.         178,
  1856.         89,
  1857.         151,
  1858.         101,
  1859.         94,
  1860.         160,
  1861.         123,
  1862.         26,
  1863.         112,
  1864.         232,
  1865.         21,
  1866.         51,
  1867.         238,
  1868.         208,
  1869.         131,
  1870.         58,
  1871.         69,
  1872.         148,
  1873.         18,
  1874.         15,
  1875.         16,
  1876.         68,
  1877.         17,
  1878.         121,
  1879.         149,
  1880.         129,
  1881.         19,
  1882.         155,
  1883.         59,
  1884.         249,
  1885.         70,
  1886.         214,
  1887.         250,
  1888.         168,
  1889.         71,
  1890.         201,
  1891.         156,
  1892.         64,
  1893.         60,
  1894.         237,
  1895.         130,
  1896.         111,
  1897.         20,
  1898.         93,
  1899.         122,
  1900.         177,
  1901.         150
  1902.             };
  1903.             private static readonly int[] alog = new int[256]
  1904.             {
  1905.         1,
  1906.         2,
  1907.         4,
  1908.         8,
  1909.         16,
  1910.         32,
  1911.         64,
  1912.         128,
  1913.         45,
  1914.         90,
  1915.         180,
  1916.         69,
  1917.         138,
  1918.         57,
  1919.         114,
  1920.         228,
  1921.         229,
  1922.         231,
  1923.         227,
  1924.         235,
  1925.         251,
  1926.         219,
  1927.         155,
  1928.         27,
  1929.         54,
  1930.         108,
  1931.         216,
  1932.         157,
  1933.         23,
  1934.         46,
  1935.         92,
  1936.         184,
  1937.         93,
  1938.         186,
  1939.         89,
  1940.         178,
  1941.         73,
  1942.         146,
  1943.         9,
  1944.         18,
  1945.         36,
  1946.         72,
  1947.         144,
  1948.         13,
  1949.         26,
  1950.         52,
  1951.         104,
  1952.         208,
  1953.         141,
  1954.         55,
  1955.         110,
  1956.         220,
  1957.         149,
  1958.         7,
  1959.         14,
  1960.         28,
  1961.         56,
  1962.         112,
  1963.         224,
  1964.         237,
  1965.         247,
  1966.         195,
  1967.         171,
  1968.         123,
  1969.         246,
  1970.         193,
  1971.         175,
  1972.         115,
  1973.         230,
  1974.         225,
  1975.         239,
  1976.         243,
  1977.         203,
  1978.         187,
  1979.         91,
  1980.         182,
  1981.         65,
  1982.         130,
  1983.         41,
  1984.         82,
  1985.         164,
  1986.         101,
  1987.         202,
  1988.         185,
  1989.         95,
  1990.         190,
  1991.         81,
  1992.         162,
  1993.         105,
  1994.         210,
  1995.         137,
  1996.         63,
  1997.         126,
  1998.         252,
  1999.         213,
  2000.         135,
  2001.         35,
  2002.         70,
  2003.         140,
  2004.         53,
  2005.         106,
  2006.         212,
  2007.         133,
  2008.         39,
  2009.         78,
  2010.         156,
  2011.         21,
  2012.         42,
  2013.         84,
  2014.         168,
  2015.         125,
  2016.         250,
  2017.         217,
  2018.         159,
  2019.         19,
  2020.         38,
  2021.         76,
  2022.         152,
  2023.         29,
  2024.         58,
  2025.         116,
  2026.         232,
  2027.         253,
  2028.         215,
  2029.         131,
  2030.         43,
  2031.         86,
  2032.         172,
  2033.         117,
  2034.         234,
  2035.         249,
  2036.         223,
  2037.         147,
  2038.         11,
  2039.         22,
  2040.         44,
  2041.         88,
  2042.         176,
  2043.         77,
  2044.         154,
  2045.         25,
  2046.         50,
  2047.         100,
  2048.         200,
  2049.         189,
  2050.         87,
  2051.         174,
  2052.         113,
  2053.         226,
  2054.         233,
  2055.         (int) byte.MaxValue,
  2056.         211,
  2057.         139,
  2058.         59,
  2059.         118,
  2060.         236,
  2061.         245,
  2062.         199,
  2063.         163,
  2064.         107,
  2065.         214,
  2066.         129,
  2067.         47,
  2068.         94,
  2069.         188,
  2070.         85,
  2071.         170,
  2072.         121,
  2073.         242,
  2074.         201,
  2075.         191,
  2076.         83,
  2077.         166,
  2078.         97,
  2079.         194,
  2080.         169,
  2081.         (int) sbyte.MaxValue,
  2082.         254,
  2083.         209,
  2084.         143,
  2085.         51,
  2086.         102,
  2087.         204,
  2088.         181,
  2089.         71,
  2090.         142,
  2091.         49,
  2092.         98,
  2093.         196,
  2094.         165,
  2095.         103,
  2096.         206,
  2097.         177,
  2098.         79,
  2099.         158,
  2100.         17,
  2101.         34,
  2102.         68,
  2103.         136,
  2104.         61,
  2105.         122,
  2106.         244,
  2107.         197,
  2108.         167,
  2109.         99,
  2110.         198,
  2111.         161,
  2112.         111,
  2113.         222,
  2114.         145,
  2115.         15,
  2116.         30,
  2117.         60,
  2118.         120,
  2119.         240,
  2120.         205,
  2121.         183,
  2122.         67,
  2123.         134,
  2124.         33,
  2125.         66,
  2126.         132,
  2127.         37,
  2128.         74,
  2129.         148,
  2130.         5,
  2131.         10,
  2132.         20,
  2133.         40,
  2134.         80,
  2135.         160,
  2136.         109,
  2137.         218,
  2138.         153,
  2139.         31,
  2140.         62,
  2141.         124,
  2142.         248,
  2143.         221,
  2144.         151,
  2145.         3,
  2146.         6,
  2147.         12,
  2148.         24,
  2149.         48,
  2150.         96,
  2151.         192,
  2152.         173,
  2153.         119,
  2154.         238,
  2155.         241,
  2156.         207,
  2157.         179,
  2158.         75,
  2159.         150,
  2160.         1
  2161.             };
  2162.             private static readonly int[] poly5 = new int[5]
  2163.             {
  2164.         228,
  2165.         48,
  2166.         15,
  2167.         111,
  2168.         62
  2169.             };
  2170.             private static readonly int[] poly7 = new int[7]
  2171.             {
  2172.         23,
  2173.         68,
  2174.         144,
  2175.         134,
  2176.         240,
  2177.         92,
  2178.         254
  2179.             };
  2180.             private static readonly int[] poly10 = new int[10]
  2181.             {
  2182.         28,
  2183.         24,
  2184.         185,
  2185.         166,
  2186.         223,
  2187.         248,
  2188.         116,
  2189.         (int) byte.MaxValue,
  2190.         110,
  2191.         61
  2192.             };
  2193.             private static readonly int[] poly11 = new int[11]
  2194.             {
  2195.         175,
  2196.         138,
  2197.         205,
  2198.         12,
  2199.         194,
  2200.         168,
  2201.         39,
  2202.         245,
  2203.         60,
  2204.         97,
  2205.         120
  2206.             };
  2207.             private static readonly int[] poly12 = new int[12]
  2208.             {
  2209.         41,
  2210.         153,
  2211.         158,
  2212.         91,
  2213.         61,
  2214.         42,
  2215.         142,
  2216.         213,
  2217.         97,
  2218.         178,
  2219.         100,
  2220.         242
  2221.             };
  2222.             private static readonly int[] poly14 = new int[14]
  2223.             {
  2224.         156,
  2225.         97,
  2226.         192,
  2227.         252,
  2228.         95,
  2229.         9,
  2230.         157,
  2231.         119,
  2232.         138,
  2233.         45,
  2234.         18,
  2235.         186,
  2236.         83,
  2237.         185
  2238.             };
  2239.             private static readonly int[] poly18 = new int[18]
  2240.             {
  2241.         83,
  2242.         195,
  2243.         100,
  2244.         39,
  2245.         188,
  2246.         75,
  2247.         66,
  2248.         61,
  2249.         241,
  2250.         213,
  2251.         109,
  2252.         129,
  2253.         94,
  2254.         254,
  2255.         225,
  2256.         48,
  2257.         90,
  2258.         188
  2259.             };
  2260.             private static readonly int[] poly20 = new int[20]
  2261.             {
  2262.         15,
  2263.         195,
  2264.         244,
  2265.         9,
  2266.         233,
  2267.         71,
  2268.         168,
  2269.         2,
  2270.         188,
  2271.         160,
  2272.         153,
  2273.         145,
  2274.         253,
  2275.         79,
  2276.         108,
  2277.         82,
  2278.         27,
  2279.         174,
  2280.         186,
  2281.         172
  2282.             };
  2283.             private static readonly int[] poly24 = new int[24]
  2284.             {
  2285.         52,
  2286.         190,
  2287.         88,
  2288.         205,
  2289.         109,
  2290.         39,
  2291.         176,
  2292.         21,
  2293.         155,
  2294.         197,
  2295.         251,
  2296.         223,
  2297.         155,
  2298.         21,
  2299.         5,
  2300.         172,
  2301.         254,
  2302.         124,
  2303.         12,
  2304.         181,
  2305.         184,
  2306.         96,
  2307.         50,
  2308.         193
  2309.             };
  2310.             private static readonly int[] poly28 = new int[28]
  2311.             {
  2312.         211,
  2313.         231,
  2314.         43,
  2315.         97,
  2316.         71,
  2317.         96,
  2318.         103,
  2319.         174,
  2320.         37,
  2321.         151,
  2322.         170,
  2323.         53,
  2324.         75,
  2325.         34,
  2326.         249,
  2327.         121,
  2328.         17,
  2329.         138,
  2330.         110,
  2331.         213,
  2332.         141,
  2333.         136,
  2334.         120,
  2335.         151,
  2336.         233,
  2337.         168,
  2338.         93,
  2339.         (int) byte.MaxValue
  2340.             };
  2341.             private static readonly int[] poly36 = new int[36]
  2342.             {
  2343.         245,
  2344.         (int) sbyte.MaxValue,
  2345.         242,
  2346.         218,
  2347.         130,
  2348.         250,
  2349.         162,
  2350.         181,
  2351.         102,
  2352.         120,
  2353.         84,
  2354.         179,
  2355.         220,
  2356.         251,
  2357.         80,
  2358.         182,
  2359.         229,
  2360.         18,
  2361.         2,
  2362.         4,
  2363.         68,
  2364.         33,
  2365.         101,
  2366.         137,
  2367.         95,
  2368.         119,
  2369.         115,
  2370.         44,
  2371.         175,
  2372.         184,
  2373.         59,
  2374.         25,
  2375.         225,
  2376.         98,
  2377.         81,
  2378.         112
  2379.             };
  2380.             private static readonly int[] poly42 = new int[42]
  2381.             {
  2382.         77,
  2383.         193,
  2384.         137,
  2385.         31,
  2386.         19,
  2387.         38,
  2388.         22,
  2389.         153,
  2390.         247,
  2391.         105,
  2392.         122,
  2393.         2,
  2394.         245,
  2395.         133,
  2396.         242,
  2397.         8,
  2398.         175,
  2399.         95,
  2400.         100,
  2401.         9,
  2402.         167,
  2403.         105,
  2404.         214,
  2405.         111,
  2406.         57,
  2407.         121,
  2408.         21,
  2409.         1,
  2410.         253,
  2411.         57,
  2412.         54,
  2413.         101,
  2414.         248,
  2415.         202,
  2416.         69,
  2417.         50,
  2418.         150,
  2419.         177,
  2420.         226,
  2421.         5,
  2422.         9,
  2423.         5
  2424.             };
  2425.             private static readonly int[] poly48 = new int[48]
  2426.             {
  2427.         245,
  2428.         132,
  2429.         172,
  2430.         223,
  2431.         96,
  2432.         32,
  2433.         117,
  2434.         22,
  2435.         238,
  2436.         133,
  2437.         238,
  2438.         231,
  2439.         205,
  2440.         188,
  2441.         237,
  2442.         87,
  2443.         191,
  2444.         106,
  2445.         16,
  2446.         147,
  2447.         118,
  2448.         23,
  2449.         37,
  2450.         90,
  2451.         170,
  2452.         205,
  2453.         131,
  2454.         88,
  2455.         120,
  2456.         100,
  2457.         66,
  2458.         138,
  2459.         186,
  2460.         240,
  2461.         82,
  2462.         44,
  2463.         176,
  2464.         87,
  2465.         187,
  2466.         147,
  2467.         160,
  2468.         175,
  2469.         69,
  2470.         213,
  2471.         92,
  2472.         253,
  2473.         225,
  2474.         19
  2475.             };
  2476.             private static readonly int[] poly56 = new int[56]
  2477.             {
  2478.         175,
  2479.         9,
  2480.         223,
  2481.         238,
  2482.         12,
  2483.         17,
  2484.         220,
  2485.         208,
  2486.         100,
  2487.         29,
  2488.         175,
  2489.         170,
  2490.         230,
  2491.         192,
  2492.         215,
  2493.         235,
  2494.         150,
  2495.         159,
  2496.         36,
  2497.         223,
  2498.         38,
  2499.         200,
  2500.         132,
  2501.         54,
  2502.         228,
  2503.         146,
  2504.         218,
  2505.         234,
  2506.         117,
  2507.         203,
  2508.         29,
  2509.         232,
  2510.         144,
  2511.         238,
  2512.         22,
  2513.         150,
  2514.         201,
  2515.         117,
  2516.         62,
  2517.         207,
  2518.         164,
  2519.         13,
  2520.         137,
  2521.         245,
  2522.         (int) sbyte.MaxValue,
  2523.         67,
  2524.         247,
  2525.         28,
  2526.         155,
  2527.         43,
  2528.         203,
  2529.         107,
  2530.         233,
  2531.         53,
  2532.         143,
  2533.         46
  2534.             };
  2535.             private static readonly int[] poly62 = new int[62]
  2536.             {
  2537.         242,
  2538.         93,
  2539.         169,
  2540.         50,
  2541.         144,
  2542.         210,
  2543.         39,
  2544.         118,
  2545.         202,
  2546.         188,
  2547.         201,
  2548.         189,
  2549.         143,
  2550.         108,
  2551.         196,
  2552.         37,
  2553.         185,
  2554.         112,
  2555.         134,
  2556.         230,
  2557.         245,
  2558.         63,
  2559.         197,
  2560.         190,
  2561.         250,
  2562.         106,
  2563.         185,
  2564.         221,
  2565.         175,
  2566.         64,
  2567.         114,
  2568.         71,
  2569.         161,
  2570.         44,
  2571.         147,
  2572.         6,
  2573.         27,
  2574.         218,
  2575.         51,
  2576.         63,
  2577.         87,
  2578.         10,
  2579.         40,
  2580.         130,
  2581.         188,
  2582.         17,
  2583.         163,
  2584.         31,
  2585.         176,
  2586.         170,
  2587.         4,
  2588.         107,
  2589.         232,
  2590.         7,
  2591.         94,
  2592.         166,
  2593.         224,
  2594.         124,
  2595.         86,
  2596.         47,
  2597.         11,
  2598.         204
  2599.             };
  2600.             private static readonly int[] poly68 = new int[68]
  2601.             {
  2602.         220,
  2603.         228,
  2604.         173,
  2605.         89,
  2606.         251,
  2607.         149,
  2608.         159,
  2609.         56,
  2610.         89,
  2611.         33,
  2612.         147,
  2613.         244,
  2614.         154,
  2615.         36,
  2616.         73,
  2617.         (int) sbyte.MaxValue,
  2618.         213,
  2619.         136,
  2620.         248,
  2621.         180,
  2622.         234,
  2623.         197,
  2624.         158,
  2625.         177,
  2626.         68,
  2627.         122,
  2628.         93,
  2629.         213,
  2630.         15,
  2631.         160,
  2632.         227,
  2633.         236,
  2634.         66,
  2635.         139,
  2636.         153,
  2637.         185,
  2638.         202,
  2639.         167,
  2640.         179,
  2641.         25,
  2642.         220,
  2643.         232,
  2644.         96,
  2645.         210,
  2646.         231,
  2647.         136,
  2648.         223,
  2649.         239,
  2650.         181,
  2651.         241,
  2652.         59,
  2653.         52,
  2654.         172,
  2655.         25,
  2656.         49,
  2657.         232,
  2658.         211,
  2659.         189,
  2660.         64,
  2661.         54,
  2662.         108,
  2663.         153,
  2664.         132,
  2665.         63,
  2666.         96,
  2667.         103,
  2668.         82,
  2669.         186
  2670.             };
  2671.  
  2672.             private static int[] GetPoly(int nc)
  2673.             {
  2674.                 switch (nc)
  2675.                 {
  2676.                     case 5:
  2677.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly5;
  2678.                     case 7:
  2679.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly7;
  2680.                     case 10:
  2681.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly10;
  2682.                     case 11:
  2683.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly11;
  2684.                     case 12:
  2685.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly12;
  2686.                     case 14:
  2687.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly14;
  2688.                     case 18:
  2689.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly18;
  2690.                     case 20:
  2691.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly20;
  2692.                     case 24:
  2693.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly24;
  2694.                     case 28:
  2695.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly28;
  2696.                     case 36:
  2697.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly36;
  2698.                     case 42:
  2699.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly42;
  2700.                     case 48:
  2701.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly48;
  2702.                     case 56:
  2703.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly56;
  2704.                     case 62:
  2705.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly62;
  2706.                     case 68:
  2707.                         return iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.poly68;
  2708.                     default:
  2709.                         return (int[])null;
  2710.                 }
  2711.             }
  2712.  
  2713.             private static void ReedSolomonBlock(byte[] wd, int nd, byte[] ncout, int nc, int[] c)
  2714.             {
  2715.                 for (int index = 0; index <= nc; ++index)
  2716.                     ncout[index] = (byte)0;
  2717.                 for (int index1 = 0; index1 < nd; ++index1)
  2718.                 {
  2719.                     int index2 = ((int)ncout[0] ^ (int)wd[index1]) & (int)byte.MaxValue;
  2720.                     for (int index3 = 0; index3 < nc; ++index3)
  2721.                         ncout[index3] = (byte)((int)ncout[index3 + 1] ^ (index2 == 0 ? 0 : (int)(byte)iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.alog[(iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.log[index2] + iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.log[c[nc - index3 - 1]]) % (int)byte.MaxValue]));
  2722.                 }
  2723.             }
  2724.  
  2725.             internal static void GenerateECC(byte[] wd, int nd, int datablock, int nc)
  2726.             {
  2727.                 int num1 = (nd + 2) / datablock;
  2728.                 byte[] wd1 = new byte[256];
  2729.                 byte[] ncout = new byte[256];
  2730.                 int[] poly = iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.GetPoly(nc);
  2731.                 for (int index1 = 0; index1 < num1; ++index1)
  2732.                 {
  2733.                     int nd1 = 0;
  2734.                     for (int index2 = index1; index2 < nd; index2 += num1)
  2735.                         wd1[nd1++] = wd[index2];
  2736.                     iTextSharp.text.pdf.MyBarcodeDatamatrix.ReedSolomon.ReedSolomonBlock(wd1, nd1, ncout, nc, poly);
  2737.                     int num2 = 0;
  2738.                     for (int index2 = index1; index2 < nc * num1; index2 += num1)
  2739.                         wd[nd + index2] = ncout[num2++];
  2740.                 }
  2741.             }
  2742.         }
  2743.     }
  2744. }
  2745.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement