Prettify scan result screen, I think
[zxing.git] / csharp / LuminanceSource.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 namespace com.google.zxing\r
18 {\r
19         \r
20         /// <summary> The purpose of this class hierarchy is to abstract different bitmap implementations across\r
21         /// platforms into a standard interface for requesting greyscale luminance values. The interface\r
22         /// only provides immutable methods; therefore crop and rotation create copies. This is to ensure\r
23         /// that one Reader does not modify the original luminance source and leave it in an unknown state\r
24         /// for other Readers in the chain.\r
25         /// \r
26         /// </summary>\r
27         /// <author>  dswitkin@google.com (Daniel Switkin)\r
28         /// </author>\r
29         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
30         /// </author>\r
31 \r
32         public abstract class LuminanceSource\r
33         {\r
34                 /// <summary> Fetches luminance data for the underlying bitmap. Values should be fetched using:\r
35                 /// int luminance = array[y * width + x] & 0xff;\r
36                 /// \r
37                 /// </summary>\r
38                 /// <returns> A row-major 2D array of luminance values. Do not use result.length as it may be\r
39                 /// larger than width * height bytes on some platforms. Do not modify the contents\r
40                 /// of the result.\r
41                 /// </returns>\r
42                 public abstract sbyte[] Matrix{get;}\r
43                 /// <returns> The width of the bitmap.\r
44                 /// </returns>\r
45                 virtual public int Width\r
46                 {\r
47                         get\r
48                         {\r
49                                 return width;\r
50                         }\r
51                         \r
52                 }\r
53                 /// <returns> The height of the bitmap.\r
54                 /// </returns>\r
55                 virtual public int Height\r
56                 {\r
57                         get\r
58                         {\r
59                                 return height;\r
60                         }\r
61                         \r
62                 }\r
63                 /// <returns> Whether this subclass supports cropping.\r
64                 /// </returns>\r
65                 virtual public bool CropSupported\r
66                 {\r
67                         get\r
68                         {\r
69                                 return false;\r
70                         }\r
71                         \r
72                 }\r
73                 /// <returns> Whether this subclass supports counter-clockwise rotation.\r
74                 /// </returns>\r
75                 virtual public bool RotateSupported\r
76                 {\r
77                         get\r
78                         {\r
79                                 return false;\r
80                         }\r
81                         \r
82                 }\r
83                 \r
84                 //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
85                 private int width;\r
86                 //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
87                 private int height;\r
88                 \r
89                 protected internal LuminanceSource(int width, int height)\r
90                 {\r
91                         this.width = width;\r
92                         this.height = height;\r
93                 }\r
94                 \r
95                 /// <summary> Fetches one row of luminance data from the underlying platform's bitmap. Values range from\r
96                 /// 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have\r
97                 /// to bitwise and with 0xff for each value. It is preferable for implementations of this method\r
98                 /// to only fetch this row rather than the whole image, since no 2D Readers may be installed and\r
99                 /// getMatrix() may never be called.\r
100                 /// \r
101                 /// </summary>\r
102                 /// <param name="y">The row to fetch, 0 <= y < getHeight().\r
103                 /// </param>\r
104                 /// <param name="row">An optional preallocated array. If null or too small, it will be ignored.\r
105                 /// Always use the returned object, and ignore the .length of the array.\r
106                 /// </param>\r
107                 /// <returns> An array containing the luminance data.\r
108                 /// </returns>\r
109                 public abstract sbyte[] getRow(int y, sbyte[] row);\r
110                 \r
111                 /// <summary> Returns a new object with cropped image data. Implementations may keep a reference to the\r
112                 /// original data rather than a copy. Only callable if isCropSupported() is true.\r
113                 /// \r
114                 /// </summary>\r
115                 /// <param name="left">The left coordinate, 0 <= left < getWidth().\r
116                 /// </param>\r
117                 /// <param name="top">The top coordinate, 0 <= top <= getHeight().\r
118                 /// </param>\r
119                 /// <param name="width">The width of the rectangle to crop.\r
120                 /// </param>\r
121                 /// <param name="height">The height of the rectangle to crop.\r
122                 /// </param>\r
123                 /// <returns> A cropped version of this object.\r
124                 /// </returns>\r
125                 public virtual LuminanceSource crop(int left, int top, int width, int height)\r
126                 {\r
127                         throw new System.SystemException("This luminance source does not support cropping.");\r
128                 }\r
129                 \r
130                 /// <summary> Returns a new object with rotated image data. Only callable if isRotateSupported() is true.\r
131                 /// \r
132                 /// </summary>\r
133                 /// <returns> A rotated version of this object.\r
134                 /// </returns>\r
135                 public virtual LuminanceSource rotateCounterClockwise()\r
136                 {\r
137                         throw new System.SystemException("This luminance source does not support rotation.");\r
138                 }\r
139         }\r
140 }