Remove old C# port before committing new one
[zxing.git] / csharp / BufferedImageMonochromeBitmapSource.cs
diff --git a/csharp/BufferedImageMonochromeBitmapSource.cs b/csharp/BufferedImageMonochromeBitmapSource.cs
deleted file mode 100755 (executable)
index 5871022..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*\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
-\r
-using System;\r
-using System.Drawing;\r
-using MonochromeBitmapSource = com.google.zxing.MonochromeBitmapSource;\r
-using BlackPointEstimationMethod = com.google.zxing.BlackPointEstimationMethod;\r
-using BitArray = com.google.zxing.common.BitArray;\r
-using BlackPointEstimator = com.google.zxing.common.BlackPointEstimator;\r
-\r
-\r
-namespace com.google.zxing.client.j2se\r
-{\r
-       \r
-       /// <summary> <p>An implementation based upon {@link BufferedImage}. This provides access to the\r
-       /// underlying image as if it were a monochrome image. Behind the scenes, it is evaluating\r
-       /// the luminance of the underlying image by retrieving its pixels' RGB values.</p>\r
-       /// \r
-       /// </summary>\r
-       /// <author>  srowen@google.com (Sean Owen), Daniel Switkin (dswitkin@google.com)\r
-       /// </author>\r
-       public sealed class BufferedImageMonochromeBitmapSource : MonochromeBitmapSource\r
-       {\r
-               public bool iRotateSupported = false;\r
-\r
-        public bool isRotateSupported() {\r
-            return iRotateSupported;\r
-        }\r
-\r
-        public int getWidth() {\r
-            return (iRotateSupported ? image.Height : image.Width);\r
-        }\r
-\r
-        public BlackPointEstimationMethod getLastEstimationMethod() {\r
-            return lastMethod;\r
-        }\r
-\r
-        public int getHeight()\r
-        {\r
-            return (iRotateSupported ? image.Width : image.Height);\r
-        }\r
-\r
-\r
-        public MonochromeBitmapSource rotateCounterClockwise() {\r
-            return null;\r
-        }\r
-\r
-        public BitArray getBlackColumn(int x, BitArray column, int startY, int getHeight) {\r
-            return null;\r
-        }\r
-               \r
-               //UPGRADE_NOTE: Final was removed from the declaration of 'image '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
-               private System.Drawing.Bitmap image;\r
-               private int blackPoint;\r
-               private BlackPointEstimationMethod lastMethod;\r
-               private int lastArgument;\r
-               \r
-               private const int LUMINANCE_BITS = 5;\r
-               //UPGRADE_NOTE: Final was removed from the declaration of 'LUMINANCE_SHIFT '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
-               private static readonly int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS;\r
-               //UPGRADE_NOTE: Final was removed from the declaration of 'LUMINANCE_BUCKETS '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
-               private static readonly int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;\r
-               \r
-               public BufferedImageMonochromeBitmapSource(System.Drawing.Bitmap image, bool rotated)\r
-               {\r
-                       this.image = image;\r
-                       blackPoint = 0x7F;\r
-                       lastMethod = null;\r
-                       lastArgument = 0;\r
-                       iRotateSupported = rotated;\r
-               }\r
-               \r
-               public bool isBlack(int x, int y)\r
-               {\r
-                       return (iRotateSupported ? computeRGBLuminance(image.GetPixel(y, x).ToArgb()) < blackPoint : computeRGBLuminance(image.GetPixel(x, y).ToArgb()) < blackPoint);\r
-               }\r
-\r
-               int[] getRGB(int startx, int starty, int width)\r
-               {\r
-                       int[] pixels = new int[width];\r
-                       for (int k = 0; k < width; k++)\r
-                       {\r
-                               Color c = (iRotateSupported ? image.GetPixel(starty, startx + k) : image.GetPixel(startx + k, starty));\r
-                               pixels[k] = ((int)c.R) << 16 | ((int)c.G) << 8 | ((int)c.B);\r
-                       }\r
-\r
-                       return pixels;\r
-               }\r
-\r
-               public BitArray getBlackRow(int y, BitArray row, int startX, int getWidth)\r
-               {\r
-                       if (row == null)\r
-                       {\r
-                               row = new BitArray(getWidth);\r
-                       }\r
-                       else\r
-                       {\r
-                               row.clear();\r
-                       }\r
-                       //UPGRADE_ISSUE: Method 'java.awt.image.BufferedImage.getRGB' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtimageBufferedImagegetRGB_int_int_int_int_int[]_int_int'"\r
-                       int[] pixelRow = getRGB(startX, y, getWidth);\r
-                       for (int i = 0; i < getWidth; i++)\r
-                       {\r
-                               if (computeRGBLuminance(pixelRow[i]) < blackPoint)\r
-                               {\r
-                                       row.set(i);\r
-                               }\r
-                       }\r
-                       return row;\r
-               }\r
-               \r
-               public void  estimateBlackPoint(BlackPointEstimationMethod method, int argument)\r
-               {\r
-                       if (!method.Equals(lastMethod) || argument != lastArgument)\r
-                       {\r
-                int width = getWidth();\r
-                int height = getHeight();\r
-                               int[] histogram = new int[LUMINANCE_BUCKETS];\r
-                               float biasTowardsWhite = 1.0f;\r
-                               if (method.Equals(BlackPointEstimationMethod.TWO_D_SAMPLING))\r
-                               {\r
-                                       int minDimension = width < height?width:height;\r
-                                       int startI = height == minDimension?0:(height - width) >> 1;\r
-                                       int startJ = width == minDimension?0:(width - height) >> 1;\r
-                                       for (int n = 0; n < minDimension; n++)\r
-                                       {\r
-                                               int pixel = (iRotateSupported ? image.GetPixel(startI + n, startJ + n).ToArgb() : image.GetPixel(startJ + n, startI + n).ToArgb());\r
-                                               histogram[computeRGBLuminance(pixel) >> LUMINANCE_SHIFT]++;\r
-                                       }\r
-                               }\r
-                               else if (method.Equals(BlackPointEstimationMethod.ROW_SAMPLING))\r
-                               {\r
-                                       if (argument < 0 || argument >= height)\r
-                                       {\r
-                                               throw new System.ArgumentException("Row is not within the image: " + argument);\r
-                                       }\r
-                                       biasTowardsWhite = 2.0f;\r
-                                       int[] rgbArray = getRGB(0, argument, width);\r
-                                       for (int x = 0; x < width; x++)\r
-                                       {\r
-                                               int l = computeRGBLuminance(rgbArray[x]);\r
-                                               histogram[l >> LUMINANCE_SHIFT]++;\r
-                                       }\r
-                               }\r
-                               else\r
-                               {\r
-                                       //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"\r
-                                       throw new System.ArgumentException("Unknown method: " + method);\r
-                               }\r
-                               blackPoint = BlackPointEstimator.estimate(histogram) << LUMINANCE_SHIFT;\r
-                               lastMethod = method;\r
-                               lastArgument = argument;\r
-                       }\r
-               }\r
-               \r
-               /// <summary> Extracts luminance from a pixel from this source. By default, the source is assumed to use RGB,\r
-               /// so this implementation computes luminance is a function of a red, green and blue components as\r
-               /// follows:\r
-               /// \r
-               /// <code>Y = 0.299R + 0.587G + 0.114B</code>\r
-               /// \r
-               /// where R, G, and B are values in [0,1].\r
-               /// </summary>\r
-               private static int computeRGBLuminance(int pixel)\r
-               {\r
-                       // Coefficients add up to 1024 to make the divide into a fast shift\r
-                       return (306 * ((pixel >> 16) & 0xFF) + 601 * ((pixel >> 8) & 0xFF) + 117 * (pixel & 0xFF)) >> 10;\r
-               }\r
-       }\r
-}
\ No newline at end of file