Small style things
[zxing.git] / csharp / multi / ByQuadrantReader.cs
1 /*\r
2 * Copyright 2009 ZXing authors\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16 using System;\r
17 using BinaryBitmap = com.google.zxing.BinaryBitmap;\r
18 using Reader = com.google.zxing.Reader;\r
19 using ReaderException = com.google.zxing.ReaderException;\r
20 using Result = com.google.zxing.Result;\r
21 namespace com.google.zxing.multi\r
22 {\r
23         \r
24         /// <summary> This class attempts to decode a barcode from an image, not by scanning the whole image,\r
25         /// but by scanning subsets of the image. This is important when there may be multiple barcodes in\r
26         /// an image, and detecting a barcode may find parts of multiple barcode and fail to decode\r
27         /// (e.g. QR Codes). Instead this scans the four quadrants of the image -- and also the center\r
28         /// 'quadrant' to cover the case where a barcode is found in the center.\r
29         /// \r
30         /// </summary>\r
31         /// <seealso cref="GenericMultipleBarcodeReader">\r
32         /// </seealso>\r
33         public sealed class ByQuadrantReader : Reader\r
34         {\r
35                 \r
36                 //UPGRADE_NOTE: Final was removed from the declaration of 'delegate '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
37                 private Reader delegate_Renamed;\r
38                 \r
39                 public ByQuadrantReader(Reader delegate_Renamed)\r
40                 {\r
41                         this.delegate_Renamed = delegate_Renamed;\r
42                 }\r
43                 \r
44                 public Result decode(BinaryBitmap image)\r
45                 {\r
46                         return decode(image, null);\r
47                 }\r
48                 \r
49                 public Result decode(BinaryBitmap image, System.Collections.Hashtable hints)\r
50                 {\r
51                         \r
52                         int width = image.Width;\r
53                         int height = image.Height;\r
54                         int halfWidth = width / 2;\r
55                         int halfHeight = height / 2;\r
56                         \r
57                         BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight);\r
58                         try\r
59                         {\r
60                                 return delegate_Renamed.decode(topLeft, hints);\r
61                         }\r
62                         catch (ReaderException re)\r
63                         {\r
64                                 // continue\r
65                         }\r
66                         \r
67                         BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight);\r
68                         try\r
69                         {\r
70                                 return delegate_Renamed.decode(topRight, hints);\r
71                         }\r
72                         catch (ReaderException re)\r
73                         {\r
74                                 // continue\r
75                         }\r
76                         \r
77                         BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight);\r
78                         try\r
79                         {\r
80                                 return delegate_Renamed.decode(bottomLeft, hints);\r
81                         }\r
82                         catch (ReaderException re)\r
83                         {\r
84                                 // continue\r
85                         }\r
86                         \r
87                         BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight);\r
88                         try\r
89                         {\r
90                                 return delegate_Renamed.decode(bottomRight, hints);\r
91                         }\r
92                         catch (ReaderException re)\r
93                         {\r
94                                 // continue\r
95                         }\r
96                         \r
97                         int quarterWidth = halfWidth / 2;\r
98                         int quarterHeight = halfHeight / 2;\r
99                         BinaryBitmap center = image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight);\r
100                         return delegate_Renamed.decode(center, hints);\r
101                 }\r
102         }\r
103 }