New C# port from Suraj Supekar
[zxing.git] / csharp / common / ByteMatrix.cs
diff --git a/csharp/common/ByteMatrix.cs b/csharp/common/ByteMatrix.cs
new file mode 100755 (executable)
index 0000000..c656d40
--- /dev/null
@@ -0,0 +1,131 @@
+/*\r
+* Copyright 2008 ZXing authors\r
+*\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+*      http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+using System;\r
+namespace com.google.zxing.common\r
+{\r
+       \r
+       /// <summary> A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a\r
+       /// unsigned container, it's up to you to do byteValue & 0xff at each location.\r
+       /// \r
+       /// JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned\r
+       /// -1, 0, and 1, I'm going to use less memory and go with bytes.\r
+       /// \r
+       /// </summary>\r
+       /// <author>  dswitkin@google.com (Daniel Switkin)\r
+       /// </author>\r
+       /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
+       /// </author>\r
+       public sealed class ByteMatrix\r
+       {\r
+               public int Height\r
+               {\r
+                       get\r
+                       {\r
+                               return height;\r
+                       }\r
+                       \r
+               }\r
+               public int Width\r
+               {\r
+                       get\r
+                       {\r
+                               return width;\r
+                       }\r
+                       \r
+               }\r
+               public sbyte[][] Array\r
+               {\r
+                       get\r
+                       {\r
+                               return bytes;\r
+                       }\r
+                       \r
+               }\r
+               \r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'bytes '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private sbyte[][] bytes;\r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'width '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private int width;\r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'height '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private int height;\r
+               \r
+               public ByteMatrix(int width, int height)\r
+               {\r
+                       bytes = new sbyte[height][];\r
+                       for (int i = 0; i < height; i++)\r
+                       {\r
+                               bytes[i] = new sbyte[width];\r
+                       }\r
+                       this.width = width;\r
+                       this.height = height;\r
+               }\r
+               \r
+               public sbyte get_Renamed(int x, int y)\r
+               {\r
+                       return bytes[y][x];\r
+               }\r
+               \r
+               public void  set_Renamed(int x, int y, sbyte value_Renamed)\r
+               {\r
+                       bytes[y][x] = value_Renamed;\r
+               }\r
+               \r
+               public void  set_Renamed(int x, int y, int value_Renamed)\r
+               {\r
+                       bytes[y][x] = (sbyte) value_Renamed;\r
+               }\r
+               \r
+               public void  clear(sbyte value_Renamed)\r
+               {\r
+                       for (int y = 0; y < height; ++y)\r
+                       {\r
+                               for (int x = 0; x < width; ++x)\r
+                               {\r
+                                       bytes[y][x] = value_Renamed;\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               public override System.String ToString()\r
+               {\r
+                       System.Text.StringBuilder result = new System.Text.StringBuilder(2 * width * height + 2);\r
+                       for (int y = 0; y < height; ++y)\r
+                       {\r
+                               for (int x = 0; x < width; ++x)\r
+                               {\r
+                                       switch (bytes[y][x])\r
+                                       {\r
+                                               \r
+                                               case 0: \r
+                                                       result.Append(" 0");\r
+                                                       break;\r
+                                               \r
+                                               case 1: \r
+                                                       result.Append(" 1");\r
+                                                       break;\r
+                                               \r
+                                               default: \r
+                                                       result.Append("  ");\r
+                                                       break;\r
+                                               \r
+                                       }\r
+                               }\r
+                               result.Append('\n');\r
+                       }\r
+                       return result.ToString();\r
+               }\r
+       }\r
+}
\ No newline at end of file