1 using com.google.zxing;
\r
2 using com.google.zxing.common;
\r
3 using System.Drawing.Imaging;
\r
4 using System.Drawing;
\r
7 public class RGBLuminanceSource : LuminanceSource
\r
10 private sbyte[] luminances;
\r
11 private bool isRotated = false;
\r
12 private bool __isRegionSelect = false;
\r
13 private Rectangle __Region;
\r
15 override public int Height
\r
26 override public int Width
\r
37 private int __height;
\r
38 private int __width;
\r
40 public RGBLuminanceSource(byte[] d, int W, int H)
\r
47 // In order to measure pure decoding speed, we convert the entire image to a greyscale array
\r
48 // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
\r
49 luminances = new sbyte[width * height];
\r
50 for (int y = 0; y < height; y++)
\r
52 int offset = y * width;
\r
53 for (int x = 0; x < width; x++)
\r
55 int r = d[offset * 3 + x * 3];
\r
56 int g = d[offset * 3 + x * 3 + 1];
\r
57 int b = d[offset * 3 + x * 3 + 2];
\r
58 if (r == g && g == b)
\r
60 // Image is already greyscale, so pick any channel.
\r
61 luminances[offset + x] = (sbyte)r;
\r
65 // Calculate luminance cheaply, favoring green.
\r
66 luminances[offset + x] = (sbyte)((r + g + g + b) >> 2);
\r
71 public RGBLuminanceSource(byte[] d, int W, int H,bool Is8Bit)
\r
76 luminances = new sbyte[W * H];
\r
77 Buffer.BlockCopy(d,0, luminances,0, W * H);
\r
80 public RGBLuminanceSource(byte[] d, int W, int H, bool Is8Bit,Rectangle Region)
\r
83 __width = Region.Width;
\r
84 __height = Region.Height;
\r
86 __isRegionSelect = true;
\r
87 //luminances = Red.Imaging.Filters.CropArea(d, W, H, Region);
\r
91 public RGBLuminanceSource(Bitmap d, int W, int H)
\r
94 int width = __width = W;
\r
95 int height = __height = H;
\r
96 // In order to measure pure decoding speed, we convert the entire image to a greyscale array
\r
97 // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
\r
98 luminances = new sbyte[width * height];
\r
99 //if (format == PixelFormat.Format8bppIndexed)
\r
102 for (int y = 0; y < height; y++)
\r
104 int offset = y * width;
\r
105 for (int x = 0; x < width; x++)
\r
107 c = d.GetPixel(x, y);
\r
108 luminances[offset + x] = (sbyte)(((int)c.R) << 16 | ((int)c.G) << 8 | ((int)c.B));
\r
113 override public sbyte[] getRow(int y, sbyte[] row)
\r
115 if (isRotated == false)
\r
118 if (row == null || row.Length < width)
\r
120 row = new sbyte[width];
\r
122 for (int i = 0; i < width; i++)
\r
123 row[i] = luminances[y * width + i];
\r
124 //System.arraycopy(luminances, y * width, row, 0, width);
\r
129 int width = __width;
\r
130 int height = __height;
\r
131 if (row == null || row.Length < height)
\r
133 row = new sbyte[height];
\r
135 for (int i = 0; i < height; i++)
\r
136 row[i] = luminances[i * width + y];
\r
137 //System.arraycopy(luminances, y * width, row, 0, width);
\r
141 public override sbyte[] Matrix
\r
143 get { return luminances; }
\r
146 public override LuminanceSource crop(int left, int top, int width, int height)
\r
148 return base.crop(left, top, width, height);
\r
150 public override LuminanceSource rotateCounterClockwise()
\r
155 public override bool RotateSupported
\r