init commit

This commit is contained in:
2025-10-09 09:57:24 +09:00
commit 4d551bd74f
6636 changed files with 1218703 additions and 0 deletions

View File

@@ -0,0 +1,218 @@
using MessagingToolkit.QRCode.Codec.Util;
using MessagingToolkit.QRCode.ExceptionHandler;
using MessagingToolkit.QRCode.Geom;
namespace MessagingToolkit.QRCode.Codec.Reader.Pattern;
public class AlignmentPattern
{
internal const int RIGHT = 1;
internal const int BOTTOM = 2;
internal const int LEFT = 3;
internal const int TOP = 4;
internal static DebugCanvas canvas;
internal Point[][] center;
internal int patternDistance;
public virtual int LogicalDistance => patternDistance;
internal AlignmentPattern(Point[][] center, int patternDistance)
{
this.center = center;
this.patternDistance = patternDistance;
}
public static AlignmentPattern findAlignmentPattern(bool[][] image, FinderPattern finderPattern)
{
Point[][] logicalCenter = getLogicalCenter(finderPattern);
int num = logicalCenter[1][0].X - logicalCenter[0][0].X;
Point[][] array = null;
array = getCenter(image, finderPattern, logicalCenter);
return new AlignmentPattern(array, num);
}
public virtual Point[][] getCenter()
{
return center;
}
public virtual void setCenter(Point[][] center)
{
this.center = center;
}
internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
{
int moduleSize = finderPattern.getModuleSize();
Axis axis = new Axis(finderPattern.getAngle(), moduleSize);
int num = logicalCenters.Length;
Point[][] array = new Point[num][];
for (int i = 0; i < num; i++)
{
array[i] = new Point[num];
}
axis.Origin = finderPattern.getCenter(0);
array[0][0] = axis.translate(3, 3);
canvas.drawCross(array[0][0], Color_Fields.BLUE);
axis.Origin = finderPattern.getCenter(1);
array[num - 1][0] = axis.translate(-3, 3);
canvas.drawCross(array[num - 1][0], Color_Fields.BLUE);
axis.Origin = finderPattern.getCenter(2);
array[0][num - 1] = axis.translate(3, -3);
canvas.drawCross(array[0][num - 1], Color_Fields.BLUE);
Point p = array[0][0];
for (int j = 0; j < num; j++)
{
for (int k = 0; k < num; k++)
{
if ((k == 0 && j == 0) || (k == 0 && j == num - 1) || (k == num - 1 && j == 0))
{
continue;
}
Point point = null;
if (j == 0)
{
if (k > 0 && k < num - 1)
{
point = axis.translate(array[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
}
array[k][j] = new Point(point.X, point.Y);
canvas.drawCross(array[k][j], Color_Fields.RED);
}
else if (k == 0)
{
if (j > 0 && j < num - 1)
{
point = axis.translate(array[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
}
array[k][j] = new Point(point.X, point.Y);
canvas.drawCross(array[k][j], Color_Fields.RED);
}
else
{
Point point2 = axis.translate(array[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
Point point3 = axis.translate(array[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
array[k][j] = new Point((point2.X + point3.X) / 2, (point2.Y + point3.Y) / 2 + 1);
}
if (finderPattern.Version > 1)
{
Point precisionCenter = getPrecisionCenter(image, array[k][j]);
if (array[k][j].distanceOf(precisionCenter) < 6)
{
canvas.drawCross(array[k][j], Color_Fields.RED);
int num2 = precisionCenter.X - array[k][j].X;
int num3 = precisionCenter.Y - array[k][j].Y;
canvas.println("Adjust AP(" + k + "," + j + ") to d(" + num2 + "," + num3 + ")");
array[k][j] = precisionCenter;
}
}
canvas.drawCross(array[k][j], Color_Fields.BLUE);
canvas.drawLine(new Line(p, array[k][j]), Color_Fields.LIGHTBLUE);
p = array[k][j];
}
}
return array;
}
internal static Point getPrecisionCenter(bool[][] image, Point targetPoint)
{
int x = targetPoint.X;
int y = targetPoint.Y;
if (x < 0 || y < 0 || x > image.Length - 1 || y > image[0].Length - 1)
{
throw new AlignmentPatternNotFoundException("Alignment Pattern finder exceeded out of image");
}
if (!image[targetPoint.X][targetPoint.Y])
{
int num = 0;
bool flag = false;
while (!flag)
{
num++;
for (int num2 = num; num2 > -num; num2--)
{
for (int num3 = num; num3 > -num; num3--)
{
int num4 = targetPoint.X + num3;
int num5 = targetPoint.Y + num2;
if (num4 < 0 || num5 < 0 || num4 > image.Length - 1 || num5 > image[0].Length - 1)
{
throw new AlignmentPatternNotFoundException("Alignment Pattern finder exceeded out of image");
}
if (image[num4][num5])
{
targetPoint = new Point(targetPoint.X + num3, targetPoint.Y + num2);
flag = true;
}
}
}
}
}
int num7;
int i;
int num6 = (num7 = (i = targetPoint.X));
int num9;
int j;
int num8 = (num9 = (j = targetPoint.Y));
while (num7 >= 1 && !targetPointOnTheCorner(image, num7, num8, num7 - 1, num8))
{
num7--;
}
for (; i < image.Length - 1 && !targetPointOnTheCorner(image, i, num8, i + 1, num8); i++)
{
}
while (num9 >= 1 && !targetPointOnTheCorner(image, num6, num9, num6, num9 - 1))
{
num9--;
}
for (; j < image[0].Length - 1 && !targetPointOnTheCorner(image, num6, j, num6, j + 1); j++)
{
}
return new Point((num7 + i + 1) / 2, (num9 + j + 1) / 2);
}
internal static bool targetPointOnTheCorner(bool[][] image, int x, int y, int nx, int ny)
{
if (x < 0 || y < 0 || nx < 0 || ny < 0 || x > image.Length || y > image[0].Length || nx > image.Length || ny > image[0].Length)
{
throw new AlignmentPatternNotFoundException("Alignment Pattern Finder exceeded image edge");
}
return !image[x][y] && image[nx][ny];
}
public static Point[][] getLogicalCenter(FinderPattern finderPattern)
{
int version = finderPattern.Version;
Point[][] array = new Point[1][];
for (int i = 0; i < 1; i++)
{
array[i] = new Point[1];
}
int[] array2 = new int[1];
array2 = LogicalSeed.getSeed(version);
array = new Point[array2.Length][];
for (int j = 0; j < array2.Length; j++)
{
array[j] = new Point[array2.Length];
}
for (int k = 0; k < array.Length; k++)
{
for (int l = 0; l < array.Length; l++)
{
array[l][k] = new Point(array2[l], array2[k]);
}
}
return array;
}
static AlignmentPattern()
{
canvas = QRCodeDecoder.Canvas;
}
}

View File

@@ -0,0 +1,676 @@
using System;
using System.Collections;
using MessagingToolkit.QRCode.Codec.Util;
using MessagingToolkit.QRCode.ExceptionHandler;
using MessagingToolkit.QRCode.Geom;
namespace MessagingToolkit.QRCode.Codec.Reader.Pattern;
public class FinderPattern
{
public const int UL = 0;
public const int UR = 1;
public const int DL = 2;
internal static readonly int[] VersionInfoBit;
internal static DebugCanvas canvas;
internal Point[] center;
internal int version;
internal int[] sincos;
internal int[] width;
internal int[] moduleSize;
public virtual int Version => version;
public virtual int SqrtNumModules => 17 + 4 * version;
public static FinderPattern findFinderPattern(bool[][] image)
{
Line[] lineAcross = findLineAcross(image);
Line[] crossLines = findLineCross(lineAcross);
Point[] array = null;
try
{
array = getCenter(crossLines);
}
catch (FinderPatternNotFoundException ex)
{
throw ex;
}
int[] angle = getAngle(array);
array = sort(array, angle);
int[] array2 = getWidth(image, array, angle);
int[] array3 = new int[3]
{
(array2[0] << QRCodeImageReader.DECIMAL_POINT) / 7,
(array2[1] << QRCodeImageReader.DECIMAL_POINT) / 7,
(array2[2] << QRCodeImageReader.DECIMAL_POINT) / 7
};
int num = calcRoughVersion(array, array2);
if (num > 6)
{
try
{
num = calcExactVersion(array, angle, array3, image);
}
catch (VersionInformationException)
{
}
}
return new FinderPattern(array, num, angle, array2, array3);
}
internal FinderPattern(Point[] center, int version, int[] sincos, int[] width, int[] moduleSize)
{
this.center = center;
this.version = version;
this.sincos = sincos;
this.width = width;
this.moduleSize = moduleSize;
}
public virtual Point[] getCenter()
{
return center;
}
public virtual Point getCenter(int position)
{
if (position >= 0 && position <= 2)
{
return center[position];
}
return null;
}
public virtual int getWidth(int position)
{
return width[position];
}
public virtual int[] getAngle()
{
return sincos;
}
public virtual int getModuleSize()
{
return moduleSize[0];
}
public virtual int getModuleSize(int place)
{
return moduleSize[place];
}
internal static Line[] findLineAcross(bool[][] image)
{
int num = 0;
int num2 = 1;
int num3 = image.Length;
int num4 = image[0].Length;
Point point = new Point();
ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10));
int[] array = new int[5];
int num5 = 0;
int num6 = num;
bool flag = false;
while (true)
{
bool flag2 = true;
bool flag3 = image[point.X][point.Y];
if (flag3 == flag)
{
array[num5]++;
}
else
{
if (!flag3 && checkPattern(array, num5))
{
int num7;
int x;
int num8;
int y;
if (num6 == num)
{
num7 = point.X;
for (int i = 0; i < 5; i++)
{
num7 -= array[i];
}
x = point.X - 1;
num8 = (y = point.Y);
}
else
{
num7 = (x = point.X);
num8 = point.Y;
for (int i = 0; i < 5; i++)
{
num8 -= array[i];
}
y = point.Y - 1;
}
arrayList.Add(new Line(num7, num8, x, y));
}
num5 = (num5 + 1) % 5;
array[num5] = 1;
flag = !flag;
}
if (num6 == num)
{
if (point.X < num3 - 1)
{
point.translate(1, 0);
}
else if (point.Y < num4 - 1)
{
point.set_Renamed(0, point.Y + 1);
array = new int[5];
}
else
{
point.set_Renamed(0, 0);
array = new int[5];
num6 = num2;
}
}
else if (point.Y < num4 - 1)
{
point.translate(0, 1);
}
else
{
if (point.X >= num3 - 1)
{
break;
}
point.set_Renamed(point.X + 1, 0);
array = new int[5];
}
}
Line[] array2 = new Line[arrayList.Count];
for (int j = 0; j < array2.Length; j++)
{
array2[j] = (Line)arrayList[j];
}
canvas.drawLines(array2, Color_Fields.LIGHTGREEN);
return array2;
}
internal static bool checkPattern(int[] buffer, int pointer)
{
int[] array = new int[5] { 1, 1, 3, 1, 1 };
int num = 0;
for (int i = 0; i < 5; i++)
{
num += buffer[i];
}
num <<= QRCodeImageReader.DECIMAL_POINT;
num /= 7;
for (int j = 0; j < 5; j++)
{
int num2 = num * array[j] - num / 2;
int num3 = num * array[j] + num / 2;
int num4 = buffer[(pointer + j + 1) % 5] << QRCodeImageReader.DECIMAL_POINT;
if (num4 < num2 || num4 > num3)
{
return false;
}
}
return true;
}
internal static Line[] findLineCross(Line[] lineAcross)
{
ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10));
ArrayList arrayList2 = ArrayList.Synchronized(new ArrayList(10));
ArrayList arrayList3 = ArrayList.Synchronized(new ArrayList(10));
for (int i = 0; i < lineAcross.Length; i++)
{
arrayList3.Add(lineAcross[i]);
}
for (int i = 0; i < arrayList3.Count - 1; i++)
{
arrayList2.Clear();
arrayList2.Add(arrayList3[i]);
for (int j = i + 1; j < arrayList3.Count; j++)
{
if (Line.isNeighbor((Line)arrayList2[arrayList2.Count - 1], (Line)arrayList3[j]))
{
arrayList2.Add(arrayList3[j]);
Line line = (Line)arrayList2[arrayList2.Count - 1];
if (arrayList2.Count * 5 > line.Length && j == arrayList3.Count - 1)
{
arrayList.Add(arrayList2[arrayList2.Count / 2]);
for (int k = 0; k < arrayList2.Count; k++)
{
arrayList3.Remove(arrayList2[k]);
}
}
}
else
{
if (!cantNeighbor((Line)arrayList2[arrayList2.Count - 1], (Line)arrayList3[j]) && j != arrayList3.Count - 1)
{
continue;
}
Line line = (Line)arrayList2[arrayList2.Count - 1];
if (arrayList2.Count * 6 > line.Length)
{
arrayList.Add(arrayList2[arrayList2.Count / 2]);
for (int k = 0; k < arrayList2.Count; k++)
{
arrayList3.Remove(arrayList2[k]);
}
}
break;
}
}
}
Line[] array = new Line[arrayList.Count];
for (int i = 0; i < array.Length; i++)
{
array[i] = (Line)arrayList[i];
}
return array;
}
internal static bool cantNeighbor(Line line1, Line line2)
{
if (Line.isCross(line1, line2))
{
return true;
}
if (line1.Horizontal)
{
if (Math.Abs(line1.getP1().Y - line2.getP1().Y) > 1)
{
return true;
}
return false;
}
if (Math.Abs(line1.getP1().X - line2.getP1().X) > 1)
{
return true;
}
return false;
}
internal static int[] getAngle(Point[] centers)
{
Line[] array = new Line[3];
for (int i = 0; i < array.Length; i++)
{
array[i] = new Line(centers[i], centers[(i + 1) % array.Length]);
}
Line longest = Line.getLongest(array);
Point point = new Point();
for (int i = 0; i < centers.Length; i++)
{
if (!longest.getP1().equals(centers[i]) && !longest.getP2().equals(centers[i]))
{
point = centers[i];
break;
}
}
canvas.println("originPoint is: " + point);
Point point2 = new Point();
point2 = (((point.Y <= longest.getP1().Y) & (point.Y <= longest.getP2().Y)) ? ((longest.getP1().X >= longest.getP2().X) ? longest.getP1() : longest.getP2()) : (((point.X >= longest.getP1().X) & (point.X >= longest.getP2().X)) ? ((longest.getP1().Y >= longest.getP2().Y) ? longest.getP1() : longest.getP2()) : (((point.Y >= longest.getP1().Y) & (point.Y >= longest.getP2().Y)) ? ((longest.getP1().X >= longest.getP2().X) ? longest.getP2() : longest.getP1()) : ((longest.getP1().Y >= longest.getP2().Y) ? longest.getP2() : longest.getP1()))));
int length = new Line(point, point2).Length;
return new int[2]
{
(point2.Y - point.Y << QRCodeImageReader.DECIMAL_POINT) / length,
(point2.X - point.X << QRCodeImageReader.DECIMAL_POINT) / length
};
}
internal static Point[] getCenter(Line[] crossLines)
{
ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10));
for (int i = 0; i < crossLines.Length - 1; i++)
{
Line line = crossLines[i];
for (int j = i + 1; j < crossLines.Length; j++)
{
Line line2 = crossLines[j];
if (Line.isCross(line, line2))
{
int num = 0;
int num2 = 0;
if (line.Horizontal)
{
num = line.Center.X;
num2 = line2.Center.Y;
}
else
{
num = line2.Center.X;
num2 = line.Center.Y;
}
arrayList.Add(new Point(num, num2));
}
}
}
Point[] array = new Point[arrayList.Count];
for (int i = 0; i < array.Length; i++)
{
array[i] = (Point)arrayList[i];
}
if (array.Length == 3)
{
canvas.drawPolygon(array, Color_Fields.RED);
return array;
}
throw new FinderPatternNotFoundException("Invalid number of Finder Pattern detected");
}
internal static Point[] sort(Point[] centers, int[] angle)
{
Point[] array = new Point[3];
switch (getURQuadant(angle))
{
case 1:
array[1] = getPointAtSide(centers, 1, 2);
array[2] = getPointAtSide(centers, 2, 4);
break;
case 2:
array[1] = getPointAtSide(centers, 2, 4);
array[2] = getPointAtSide(centers, 8, 4);
break;
case 3:
array[1] = getPointAtSide(centers, 4, 8);
array[2] = getPointAtSide(centers, 1, 8);
break;
case 4:
array[1] = getPointAtSide(centers, 8, 1);
array[2] = getPointAtSide(centers, 2, 1);
break;
}
for (int i = 0; i < centers.Length; i++)
{
if (!centers[i].equals(array[1]) && !centers[i].equals(array[2]))
{
array[0] = centers[i];
}
}
return array;
}
internal static int getURQuadant(int[] angle)
{
int num = angle[0];
int num2 = angle[1];
if (num >= 0 && num2 > 0)
{
return 1;
}
if (num > 0 && num2 <= 0)
{
return 2;
}
if (num <= 0 && num2 < 0)
{
return 3;
}
if (num < 0 && num2 >= 0)
{
return 4;
}
return 0;
}
internal static Point getPointAtSide(Point[] points, int side1, int side2)
{
Point point = new Point();
int x = ((side1 != 1 && side2 != 1) ? int.MaxValue : 0);
int y = ((side1 != 2 && side2 != 2) ? int.MaxValue : 0);
point = new Point(x, y);
for (int i = 0; i < points.Length; i++)
{
switch (side1)
{
case 1:
if (point.X < points[i].X)
{
point = points[i];
}
else
{
if (point.X != points[i].X)
{
break;
}
if (side2 == 2)
{
if (point.Y < points[i].Y)
{
point = points[i];
}
}
else if (point.Y > points[i].Y)
{
point = points[i];
}
}
break;
case 2:
if (point.Y < points[i].Y)
{
point = points[i];
}
else
{
if (point.Y != points[i].Y)
{
break;
}
if (side2 == 1)
{
if (point.X < points[i].X)
{
point = points[i];
}
}
else if (point.X > points[i].X)
{
point = points[i];
}
}
break;
case 4:
if (point.X > points[i].X)
{
point = points[i];
}
else
{
if (point.X != points[i].X)
{
break;
}
if (side2 == 2)
{
if (point.Y < points[i].Y)
{
point = points[i];
}
}
else if (point.Y > points[i].Y)
{
point = points[i];
}
}
break;
case 8:
if (point.Y > points[i].Y)
{
point = points[i];
}
else
{
if (point.Y != points[i].Y)
{
break;
}
if (side2 == 1)
{
if (point.X < points[i].X)
{
point = points[i];
}
}
else if (point.X > points[i].X)
{
point = points[i];
}
}
break;
}
}
return point;
}
internal static int[] getWidth(bool[][] image, Point[] centers, int[] sincos)
{
int[] array = new int[3];
for (int i = 0; i < 3; i++)
{
bool flag = false;
int y = centers[i].Y;
int num;
for (num = centers[i].X; num > 0; num--)
{
if (image[num][y] && !image[num - 1][y])
{
if (flag)
{
break;
}
flag = true;
}
}
flag = false;
int j;
for (j = centers[i].X; j < image.Length; j++)
{
if (image[j][y] && !image[j + 1][y])
{
if (flag)
{
break;
}
flag = true;
}
}
array[i] = j - num + 1;
}
return array;
}
internal static int calcRoughVersion(Point[] center, int[] width)
{
int dECIMAL_POINT = QRCodeImageReader.DECIMAL_POINT;
int num = new Line(center[0], center[1]).Length << dECIMAL_POINT;
int num2 = (width[0] + width[1] << dECIMAL_POINT) / 14;
int num3 = (num / num2 - 10) / 4;
if ((num / num2 - 10) % 4 >= 2)
{
num3++;
}
return num3;
}
internal static int calcExactVersion(Point[] centers, int[] angle, int[] moduleSize, bool[][] image)
{
bool[] array = new bool[18];
Point[] array2 = new Point[18];
Axis axis = new Axis(angle, moduleSize[1]);
axis.Origin = centers[1];
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 3; j++)
{
Point point = axis.translate(j - 7, i - 3);
array[j + i * 3] = image[point.X][point.Y];
array2[j + i * 3] = point;
}
}
canvas.drawPoints(array2, Color_Fields.RED);
int num = 0;
try
{
return checkVersionInfo(array);
}
catch (InvalidVersionInfoException)
{
canvas.println("Version info error. now retry with other place one.");
axis.Origin = centers[2];
axis.ModulePitch = moduleSize[2];
for (int j = 0; j < 6; j++)
{
for (int i = 0; i < 3; i++)
{
Point point = axis.translate(j - 3, i - 7);
array[i + j * 3] = image[point.X][point.Y];
array2[j + i * 3] = point;
}
}
canvas.drawPoints(array2, Color_Fields.RED);
try
{
return checkVersionInfo(array);
}
catch (VersionInformationException ex2)
{
throw ex2;
}
}
}
internal static int checkVersionInfo(bool[] target)
{
int num = 0;
int i;
for (i = 0; i < VersionInfoBit.Length; i++)
{
num = 0;
for (int j = 0; j < 18; j++)
{
if (target[j] ^ ((VersionInfoBit[i] >> j) % 2 == 1))
{
num++;
}
}
if (num <= 3)
{
break;
}
}
if (num <= 3)
{
return 7 + i;
}
throw new InvalidVersionInfoException("Too many errors in version information");
}
static FinderPattern()
{
VersionInfoBit = new int[34]
{
31892, 34236, 39577, 42195, 48118, 51042, 55367, 58893, 63784, 68472,
70749, 76311, 79154, 84390, 87683, 92361, 96236, 102084, 102881, 110507,
110734, 117786, 119615, 126325, 127568, 133589, 136944, 141498, 145311, 150283,
152622, 158308, 161089, 167017
};
canvas = QRCodeDecoder.Canvas;
}
}

View File

@@ -0,0 +1,61 @@
namespace MessagingToolkit.QRCode.Codec.Reader.Pattern;
public class LogicalSeed
{
private static int[][] seed;
public static int[] getSeed(int version)
{
return seed[version - 1];
}
public static int getSeed(int version, int patternNumber)
{
return seed[version - 1][patternNumber];
}
static LogicalSeed()
{
seed = new int[40][];
seed[0] = new int[2] { 6, 14 };
seed[1] = new int[2] { 6, 18 };
seed[2] = new int[2] { 6, 22 };
seed[3] = new int[2] { 6, 26 };
seed[4] = new int[2] { 6, 30 };
seed[5] = new int[2] { 6, 34 };
seed[6] = new int[3] { 6, 22, 38 };
seed[7] = new int[3] { 6, 24, 42 };
seed[8] = new int[3] { 6, 26, 46 };
seed[9] = new int[3] { 6, 28, 50 };
seed[10] = new int[3] { 6, 30, 54 };
seed[11] = new int[3] { 6, 32, 58 };
seed[12] = new int[3] { 6, 34, 62 };
seed[13] = new int[4] { 6, 26, 46, 66 };
seed[14] = new int[4] { 6, 26, 48, 70 };
seed[15] = new int[4] { 6, 26, 50, 74 };
seed[16] = new int[4] { 6, 30, 54, 78 };
seed[17] = new int[4] { 6, 30, 56, 82 };
seed[18] = new int[4] { 6, 30, 58, 86 };
seed[19] = new int[4] { 6, 34, 62, 90 };
seed[20] = new int[5] { 6, 28, 50, 72, 94 };
seed[21] = new int[5] { 6, 26, 50, 74, 98 };
seed[22] = new int[5] { 6, 30, 54, 78, 102 };
seed[23] = new int[5] { 6, 28, 54, 80, 106 };
seed[24] = new int[5] { 6, 32, 58, 84, 110 };
seed[25] = new int[5] { 6, 30, 58, 86, 114 };
seed[26] = new int[5] { 6, 34, 62, 90, 118 };
seed[27] = new int[6] { 6, 26, 50, 74, 98, 122 };
seed[28] = new int[6] { 6, 30, 54, 78, 102, 126 };
seed[29] = new int[6] { 6, 26, 52, 78, 104, 130 };
seed[30] = new int[6] { 6, 30, 56, 82, 108, 134 };
seed[31] = new int[6] { 6, 34, 60, 86, 112, 138 };
seed[32] = new int[6] { 6, 30, 58, 86, 114, 142 };
seed[33] = new int[6] { 6, 34, 62, 90, 118, 146 };
seed[34] = new int[7] { 6, 30, 54, 78, 102, 126, 150 };
seed[35] = new int[7] { 6, 24, 50, 76, 102, 128, 154 };
seed[36] = new int[7] { 6, 28, 54, 80, 106, 132, 158 };
seed[37] = new int[7] { 6, 32, 58, 84, 110, 136, 162 };
seed[38] = new int[7] { 6, 26, 54, 82, 110, 138, 166 };
seed[39] = new int[7] { 6, 30, 58, 86, 114, 142, 170 };
}
}

View File

@@ -0,0 +1,425 @@
using System;
using System.IO;
using MessagingToolkit.QRCode.Codec.Util;
using MessagingToolkit.QRCode.ExceptionHandler;
namespace MessagingToolkit.QRCode.Codec.Reader;
public class QRCodeDataBlockReader
{
private const int MODE_NUMBER = 1;
private const int MODE_ROMAN_AND_NUMBER = 2;
private const int MODE_8BIT_BYTE = 4;
private const int MODE_KANJI = 8;
internal int[] blocks;
internal int dataLengthMode;
internal int blockPointer;
internal int bitPointer;
internal int dataLength;
internal int numErrorCorrectionCode;
internal DebugCanvas canvas;
private int[][] sizeOfDataLengthInfo = new int[3][]
{
new int[4] { 10, 9, 8, 8 },
new int[4] { 12, 11, 16, 10 },
new int[4] { 14, 13, 16, 12 }
};
internal virtual int NextMode
{
get
{
if (blockPointer > blocks.Length - numErrorCorrectionCode - 2)
{
return 0;
}
return getNextBits(4);
}
}
public virtual sbyte[] DataByte
{
get
{
canvas.println("Reading data blocks.");
MemoryStream memoryStream = new MemoryStream();
try
{
while (true)
{
int nextMode = NextMode;
switch (nextMode)
{
case 0:
if (memoryStream.Length > 0)
{
goto end_IL_0019;
}
throw new InvalidDataBlockException("Empty data block");
default:
if (nextMode != 8)
{
throw new InvalidDataBlockException("Invalid mode: " + nextMode + " in (block:" + blockPointer + " bit:" + bitPointer + ")");
}
break;
case 1:
case 2:
case 4:
break;
}
dataLength = getDataLength(nextMode);
if (dataLength < 1)
{
throw new InvalidDataBlockException("Invalid data length: " + dataLength);
}
switch (nextMode)
{
case 1:
{
sbyte[] array4 = SystemUtils.ToSByteArray(SystemUtils.ToByteArray(getFigureString(dataLength)));
memoryStream.Write(SystemUtils.ToByteArray(array4), 0, array4.Length);
break;
}
case 2:
{
sbyte[] array3 = SystemUtils.ToSByteArray(SystemUtils.ToByteArray(getRomanAndFigureString(dataLength)));
memoryStream.Write(SystemUtils.ToByteArray(array3), 0, array3.Length);
break;
}
case 4:
{
sbyte[] array2 = get8bitByteArray(dataLength);
memoryStream.Write(SystemUtils.ToByteArray(array2), 0, array2.Length);
break;
}
case 8:
{
sbyte[] array = SystemUtils.ToSByteArray(SystemUtils.ToByteArray(getKanjiString(dataLength)));
memoryStream.Write(SystemUtils.ToByteArray(array), 0, array.Length);
break;
}
}
bool flag = true;
continue;
end_IL_0019:
break;
}
}
catch (IndexOutOfRangeException throwable)
{
SystemUtils.WriteStackTrace(throwable, Console.Error);
throw new InvalidDataBlockException("Data Block Error in (block:" + blockPointer + " bit:" + bitPointer + ")");
}
catch (IOException ex)
{
throw new InvalidDataBlockException(ex.Message);
}
return SystemUtils.ToSByteArray(memoryStream.ToArray());
}
}
public virtual string DataString
{
get
{
canvas.println("Reading data blocks...");
string text = "";
while (true)
{
int nextMode = NextMode;
canvas.println("mode: " + nextMode);
if (nextMode == 0)
{
break;
}
if (nextMode == 1 || nextMode == 2 || nextMode == 4 || nextMode != 8)
{
}
dataLength = getDataLength(nextMode);
canvas.println(Convert.ToString(blocks[blockPointer]));
Console.Out.WriteLine("length: " + dataLength);
switch (nextMode)
{
case 1:
text += getFigureString(dataLength);
break;
case 2:
text += getRomanAndFigureString(dataLength);
break;
case 4:
text += get8bitByteString(dataLength);
break;
case 8:
text += getKanjiString(dataLength);
break;
}
bool flag = true;
}
Console.Out.WriteLine("");
return text;
}
}
public QRCodeDataBlockReader(int[] blocks, int version, int numErrorCorrectionCode)
{
blockPointer = 0;
bitPointer = 7;
dataLength = 0;
this.blocks = blocks;
this.numErrorCorrectionCode = numErrorCorrectionCode;
if (version <= 9)
{
dataLengthMode = 0;
}
else if (version >= 10 && version <= 26)
{
dataLengthMode = 1;
}
else if (version >= 27 && version <= 40)
{
dataLengthMode = 2;
}
canvas = QRCodeDecoder.Canvas;
}
internal virtual int getNextBits(int numBits)
{
int num = 0;
if (numBits < bitPointer + 1)
{
int num2 = 0;
for (int i = 0; i < numBits; i++)
{
num2 += 1 << i;
}
num2 <<= bitPointer - numBits + 1;
num = (blocks[blockPointer] & num2) >> bitPointer - numBits + 1;
bitPointer -= numBits;
return num;
}
if (numBits < bitPointer + 1 + 8)
{
int num3 = 0;
for (int i = 0; i < bitPointer + 1; i++)
{
num3 += 1 << i;
}
num = (blocks[blockPointer] & num3) << numBits - (bitPointer + 1);
blockPointer++;
num += blocks[blockPointer] >> 8 - (numBits - (bitPointer + 1));
bitPointer -= numBits % 8;
if (bitPointer < 0)
{
bitPointer = 8 + bitPointer;
}
return num;
}
if (numBits < bitPointer + 1 + 16)
{
int num3 = 0;
int num4 = 0;
for (int i = 0; i < bitPointer + 1; i++)
{
num3 += 1 << i;
}
int num5 = (blocks[blockPointer] & num3) << numBits - (bitPointer + 1);
blockPointer++;
int num6 = blocks[blockPointer] << numBits - (bitPointer + 1 + 8);
blockPointer++;
for (int i = 0; i < numBits - (bitPointer + 1 + 8); i++)
{
num4 += 1 << i;
}
num4 <<= 8 - (numBits - (bitPointer + 1 + 8));
int num7 = (blocks[blockPointer] & num4) >> 8 - (numBits - (bitPointer + 1 + 8));
num = num5 + num6 + num7;
bitPointer -= (numBits - 8) % 8;
if (bitPointer < 0)
{
bitPointer = 8 + bitPointer;
}
return num;
}
Console.Out.WriteLine("ERROR!");
return 0;
}
internal virtual int guessMode(int mode)
{
return mode switch
{
3 => 1,
5 => 4,
6 => 4,
7 => 4,
9 => 8,
10 => 8,
11 => 8,
12 => 4,
13 => 4,
14 => 4,
15 => 4,
_ => 8,
};
}
internal virtual int getDataLength(int modeIndicator)
{
int num = 0;
while (true)
{
bool flag = true;
if (modeIndicator >> num == 1)
{
break;
}
num++;
}
return getNextBits(sizeOfDataLengthInfo[dataLengthMode][num]);
}
internal virtual string getFigureString(int dataLength)
{
int num = dataLength;
int num2 = 0;
string text = "";
do
{
if (num >= 3)
{
num2 = getNextBits(10);
if (num2 < 100)
{
text += "0";
}
if (num2 < 10)
{
text += "0";
}
num -= 3;
}
else
{
switch (num)
{
case 2:
num2 = getNextBits(7);
if (num2 < 10)
{
text += "0";
}
num -= 2;
break;
case 1:
num2 = getNextBits(4);
num--;
break;
}
}
text += Convert.ToString(num2);
}
while (num > 0);
return text;
}
internal virtual string getRomanAndFigureString(int dataLength)
{
int num = dataLength;
int num2 = 0;
string text = "";
char[] array = new char[45]
{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*',
'+', '-', '.', '/', ':'
};
do
{
if (num > 1)
{
num2 = getNextBits(11);
int num3 = num2 / 45;
int num4 = num2 % 45;
text += Convert.ToString(array[num3]);
text += Convert.ToString(array[num4]);
num -= 2;
}
else if (num == 1)
{
num2 = getNextBits(6);
text += Convert.ToString(array[num2]);
num--;
}
}
while (num > 0);
return text;
}
public virtual sbyte[] get8bitByteArray(int dataLength)
{
int num = dataLength;
int num2 = 0;
MemoryStream memoryStream = new MemoryStream();
do
{
canvas.println("Length: " + num);
num2 = getNextBits(8);
memoryStream.WriteByte((byte)num2);
num--;
}
while (num > 0);
return SystemUtils.ToSByteArray(memoryStream.ToArray());
}
internal virtual string get8bitByteString(int dataLength)
{
int num = dataLength;
int num2 = 0;
string text = "";
do
{
num2 = getNextBits(8);
text += (char)num2;
num--;
}
while (num > 0);
return text;
}
internal virtual string getKanjiString(int dataLength)
{
int num = dataLength;
int num2 = 0;
string text = "";
do
{
num2 = getNextBits(13);
int num3 = num2 % 192;
int num4 = num2 / 192;
int num5 = (num4 << 8) + num3;
int num6 = 0;
num6 = ((num5 + 33088 > 40956) ? (num5 + 49472) : (num5 + 33088));
text += new string(SystemUtils.ToCharArray(SystemUtils.ToByteArray(new sbyte[2]
{
(sbyte)(num6 >> 8),
(sbyte)(num6 & 0xFF)
})));
num--;
}
while (num > 0);
return text;
}
}

View File

@@ -0,0 +1,543 @@
using System;
using System.Collections;
using MessagingToolkit.QRCode.Codec.Data;
using MessagingToolkit.QRCode.Codec.Reader.Pattern;
using MessagingToolkit.QRCode.Codec.Util;
using MessagingToolkit.QRCode.ExceptionHandler;
using MessagingToolkit.QRCode.Geom;
namespace MessagingToolkit.QRCode.Codec.Reader;
public class QRCodeImageReader
{
private class ModulePitch
{
public int top;
public int left;
public int bottom;
public int right;
private QRCodeImageReader enclosingInstance;
public QRCodeImageReader Enclosing_Instance => enclosingInstance;
public ModulePitch(QRCodeImageReader enclosingInstance)
{
InitBlock(enclosingInstance);
}
private void InitBlock(QRCodeImageReader enclosingInstance)
{
this.enclosingInstance = enclosingInstance;
}
}
public const bool POINT_DARK = true;
public const bool POINT_LIGHT = false;
internal DebugCanvas canvas;
public static int DECIMAL_POINT = 21;
internal SamplingGrid samplingGrid;
internal bool[][] bitmap;
public QRCodeImageReader()
{
canvas = QRCodeDecoder.Canvas;
}
internal virtual bool[][] applyMedianFilter(bool[][] image, int threshold)
{
bool[][] array = new bool[image.Length][];
for (int i = 0; i < image.Length; i++)
{
array[i] = new bool[image[0].Length];
}
for (int j = 1; j < image[0].Length - 1; j++)
{
for (int k = 1; k < image.Length - 1; k++)
{
int num = 0;
for (int l = -1; l < 2; l++)
{
for (int m = -1; m < 2; m++)
{
if (image[k + m][j + l])
{
num++;
}
}
}
if (num > threshold)
{
array[k][j] = true;
}
}
}
return array;
}
internal virtual bool[][] applyCrossMaskingMedianFilter(bool[][] image, int threshold)
{
bool[][] array = new bool[image.Length][];
for (int i = 0; i < image.Length; i++)
{
array[i] = new bool[image[0].Length];
}
for (int j = 2; j < image[0].Length - 2; j++)
{
for (int k = 2; k < image.Length - 2; k++)
{
int num = 0;
for (int l = -2; l < 3; l++)
{
if (image[k + l][j])
{
num++;
}
if (image[k][j + l])
{
num++;
}
}
if (num > threshold)
{
array[k][j] = true;
}
}
}
return array;
}
internal virtual bool[][] filterImage(int[][] image)
{
imageToGrayScale(image);
return grayScaleToBitmap(image);
}
internal virtual void imageToGrayScale(int[][] image)
{
for (int i = 0; i < image[0].Length; i++)
{
for (int j = 0; j < image.Length; j++)
{
int num = (image[j][i] >> 16) & 0xFF;
int num2 = (image[j][i] >> 8) & 0xFF;
int num3 = image[j][i] & 0xFF;
int num4 = (num * 30 + num2 * 59 + num3 * 11) / 100;
image[j][i] = num4;
}
}
}
internal virtual bool[][] grayScaleToBitmap(int[][] grayScale)
{
int[][] middleBrightnessPerArea = getMiddleBrightnessPerArea(grayScale);
int num = middleBrightnessPerArea.Length;
int num2 = grayScale.Length / num;
int num3 = grayScale[0].Length / num;
bool[][] array = new bool[grayScale.Length][];
for (int i = 0; i < grayScale.Length; i++)
{
array[i] = new bool[grayScale[0].Length];
}
for (int j = 0; j < num; j++)
{
for (int k = 0; k < num; k++)
{
for (int l = 0; l < num3; l++)
{
for (int m = 0; m < num2; m++)
{
array[num2 * k + m][num3 * j + l] = ((grayScale[num2 * k + m][num3 * j + l] < middleBrightnessPerArea[k][j]) ? true : false);
}
}
}
}
return array;
}
internal virtual int[][] getMiddleBrightnessPerArea(int[][] image)
{
int num = 4;
int num2 = image.Length / num;
int num3 = image[0].Length / num;
int[][][] array = new int[num][][];
for (int i = 0; i < num; i++)
{
array[i] = new int[num][];
for (int j = 0; j < num; j++)
{
array[i][j] = new int[2];
}
}
for (int k = 0; k < num; k++)
{
for (int l = 0; l < num; l++)
{
array[l][k][0] = 255;
for (int m = 0; m < num3; m++)
{
for (int n = 0; n < num2; n++)
{
int num4 = image[num2 * l + n][num3 * k + m];
if (num4 < array[l][k][0])
{
array[l][k][0] = num4;
}
if (num4 > array[l][k][1])
{
array[l][k][1] = num4;
}
}
}
}
}
int[][] array2 = new int[num][];
for (int num5 = 0; num5 < num; num5++)
{
array2[num5] = new int[num];
}
for (int k = 0; k < num; k++)
{
for (int l = 0; l < num; l++)
{
array2[l][k] = (array[l][k][0] + array[l][k][1]) / 2;
}
}
return array2;
}
public virtual QRCodeSymbol getQRCodeSymbol(int[][] image)
{
int num = ((image.Length < image[0].Length) ? image[0].Length : image.Length);
DECIMAL_POINT = 23 - QRCodeUtility.sqrt(num / 256);
bitmap = filterImage(image);
canvas.println("Drawing matrix.");
canvas.drawMatrix(bitmap);
canvas.println("Scanning Finder Pattern.");
FinderPattern finderPattern = null;
try
{
finderPattern = FinderPattern.findFinderPattern(bitmap);
}
catch (FinderPatternNotFoundException)
{
canvas.println("Not found, now retrying...");
bitmap = applyCrossMaskingMedianFilter(bitmap, 5);
canvas.drawMatrix(bitmap);
for (int i = 0; i < 1000000000; i++)
{
}
try
{
finderPattern = FinderPattern.findFinderPattern(bitmap);
}
catch (FinderPatternNotFoundException ex2)
{
throw new SymbolNotFoundException(ex2.Message);
}
catch (VersionInformationException ex3)
{
throw new SymbolNotFoundException(ex3.Message);
}
}
catch (VersionInformationException ex4)
{
throw new SymbolNotFoundException(ex4.Message);
}
canvas.println("FinderPattern at");
string str = finderPattern.getCenter(0).ToString() + finderPattern.getCenter(1).ToString() + finderPattern.getCenter(2).ToString();
canvas.println(str);
int[] angle = finderPattern.getAngle();
canvas.println("Angle*4098: Sin " + Convert.ToString(angle[0]) + " Cos " + Convert.ToString(angle[1]));
int version = finderPattern.Version;
canvas.println("Version: " + Convert.ToString(version));
if (version < 1 || version > 40)
{
throw new InvalidVersionException("Invalid version: " + version);
}
AlignmentPattern alignmentPattern = null;
try
{
alignmentPattern = AlignmentPattern.findAlignmentPattern(bitmap, finderPattern);
}
catch (AlignmentPatternNotFoundException ex5)
{
throw new SymbolNotFoundException(ex5.Message);
}
int num2 = alignmentPattern.getCenter().Length;
canvas.println("AlignmentPatterns at");
for (int j = 0; j < num2; j++)
{
string text = "";
for (int k = 0; k < num2; k++)
{
text += alignmentPattern.getCenter()[k][j].ToString();
}
canvas.println(text);
}
canvas.println("Creating sampling grid.");
samplingGrid = getSamplingGrid(finderPattern, alignmentPattern);
canvas.println("Reading grid.");
bool[][] array = null;
try
{
array = getQRCodeMatrix(bitmap, samplingGrid);
}
catch (IndexOutOfRangeException)
{
throw new SymbolNotFoundException("Sampling grid exceeded image boundary");
}
return new QRCodeSymbol(array);
}
public virtual QRCodeSymbol getQRCodeSymbolWithAdjustedGrid(Point adjust)
{
if (bitmap == null || samplingGrid == null)
{
throw new SystemException("This method must be called after QRCodeImageReader.getQRCodeSymbol() called");
}
samplingGrid.adjust(adjust);
canvas.println("Sampling grid adjusted d(" + adjust.X + "," + adjust.Y + ")");
bool[][] array = null;
try
{
array = getQRCodeMatrix(bitmap, samplingGrid);
}
catch (IndexOutOfRangeException)
{
throw new SymbolNotFoundException("Sampling grid exceeded image boundary");
}
return new QRCodeSymbol(array);
}
internal virtual SamplingGrid getSamplingGrid(FinderPattern finderPattern, AlignmentPattern alignmentPattern)
{
Point[][] center = alignmentPattern.getCenter();
int version = finderPattern.Version;
int num = version / 7 + 2;
center[0][0] = finderPattern.getCenter(0);
center[num - 1][0] = finderPattern.getCenter(1);
center[0][num - 1] = finderPattern.getCenter(2);
int num2 = num - 1;
SamplingGrid samplingGrid = new SamplingGrid(num2);
Axis axis = new Axis(finderPattern.getAngle(), finderPattern.getModuleSize());
for (int i = 0; i < num2; i++)
{
for (int j = 0; j < num2; j++)
{
ModulePitch modulePitch = new ModulePitch(this);
Line line = new Line();
Line line2 = new Line();
axis.ModulePitch = finderPattern.getModuleSize();
Point[][] logicalCenter = AlignmentPattern.getLogicalCenter(finderPattern);
Point point = center[j][i];
Point point2 = center[j + 1][i];
Point point3 = center[j][i + 1];
Point point4 = center[j + 1][i + 1];
Point point5 = logicalCenter[j][i];
Point point6 = logicalCenter[j + 1][i];
Point point7 = logicalCenter[j][i + 1];
Point point8 = logicalCenter[j + 1][i + 1];
if (j == 0 && i == 0)
{
if (num2 == 1)
{
point = axis.translate(point, -3, -3);
point2 = axis.translate(point2, 3, -3);
point3 = axis.translate(point3, -3, 3);
point4 = axis.translate(point4, 6, 6);
point5.translate(-6, -6);
point6.translate(3, -3);
point7.translate(-3, 3);
point8.translate(6, 6);
}
else
{
point = axis.translate(point, -3, -3);
point2 = axis.translate(point2, 0, -6);
point3 = axis.translate(point3, -6, 0);
point5.translate(-6, -6);
point6.translate(0, -6);
point7.translate(-6, 0);
}
}
else if (j == 0 && i == num2 - 1)
{
point = axis.translate(point, -6, 0);
point3 = axis.translate(point3, -3, 3);
point4 = axis.translate(point4, 0, 6);
point5.translate(-6, 0);
point7.translate(-6, 6);
point8.translate(0, 6);
}
else if (j == num2 - 1 && i == 0)
{
point = axis.translate(point, 0, -6);
point2 = axis.translate(point2, 3, -3);
point4 = axis.translate(point4, 6, 0);
point5.translate(0, -6);
point6.translate(6, -6);
point8.translate(6, 0);
}
else if (j == num2 - 1 && i == num2 - 1)
{
point3 = axis.translate(point3, 0, 6);
point2 = axis.translate(point2, 6, 0);
point4 = axis.translate(point4, 6, 6);
point7.translate(0, 6);
point6.translate(6, 0);
point8.translate(6, 6);
}
else if (j == 0)
{
point = axis.translate(point, -6, 0);
point3 = axis.translate(point3, -6, 0);
point5.translate(-6, 0);
point7.translate(-6, 0);
}
else if (j == num2 - 1)
{
point2 = axis.translate(point2, 6, 0);
point4 = axis.translate(point4, 6, 0);
point6.translate(6, 0);
point8.translate(6, 0);
}
else if (i == 0)
{
point = axis.translate(point, 0, -6);
point2 = axis.translate(point2, 0, -6);
point5.translate(0, -6);
point6.translate(0, -6);
}
else if (i == num2 - 1)
{
point3 = axis.translate(point3, 0, 6);
point4 = axis.translate(point4, 0, 6);
point7.translate(0, 6);
point8.translate(0, 6);
}
if (j == 0)
{
point6.translate(1, 0);
point8.translate(1, 0);
}
else
{
point5.translate(-1, 0);
point7.translate(-1, 0);
}
if (i == 0)
{
point7.translate(0, 1);
point8.translate(0, 1);
}
else
{
point5.translate(0, -1);
point6.translate(0, -1);
}
int num3 = point6.X - point5.X;
int num4 = point7.Y - point5.Y;
if (version < 7)
{
num3 += 3;
num4 += 3;
}
modulePitch.top = getAreaModulePitch(point, point2, num3 - 1);
modulePitch.left = getAreaModulePitch(point, point3, num4 - 1);
modulePitch.bottom = getAreaModulePitch(point3, point4, num3 - 1);
modulePitch.right = getAreaModulePitch(point2, point4, num4 - 1);
line.setP1(point);
line2.setP1(point);
line.setP2(point3);
line2.setP2(point2);
samplingGrid.initGrid(j, i, num3, num4);
for (int k = 0; k < num3; k++)
{
Line line3 = new Line(line.getP1(), line.getP2());
axis.Origin = line3.getP1();
axis.ModulePitch = modulePitch.top;
line3.setP1(axis.translate(k, 0));
axis.Origin = line3.getP2();
axis.ModulePitch = modulePitch.bottom;
line3.setP2(axis.translate(k, 0));
samplingGrid.setXLine(j, i, k, line3);
}
for (int k = 0; k < num4; k++)
{
Line line4 = new Line(line2.getP1(), line2.getP2());
axis.Origin = line4.getP1();
axis.ModulePitch = modulePitch.left;
line4.setP1(axis.translate(0, k));
axis.Origin = line4.getP2();
axis.ModulePitch = modulePitch.right;
line4.setP2(axis.translate(0, k));
samplingGrid.setYLine(j, i, k, line4);
}
}
}
return samplingGrid;
}
internal virtual int getAreaModulePitch(Point start, Point end, int logicalDistance)
{
Line line = new Line(start, end);
int length = line.Length;
return (length << DECIMAL_POINT) / logicalDistance;
}
internal virtual bool[][] getQRCodeMatrix(bool[][] image, SamplingGrid gridLines)
{
int totalWidth = gridLines.TotalWidth;
canvas.println("gridSize=" + totalWidth);
Point point = null;
bool[][] array = new bool[totalWidth][];
for (int i = 0; i < totalWidth; i++)
{
array[i] = new bool[totalWidth];
}
for (int j = 0; j < gridLines.getHeight(); j++)
{
for (int k = 0; k < gridLines.getWidth(); k++)
{
ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10));
for (int l = 0; l < gridLines.getHeight(k, j); l++)
{
for (int m = 0; m < gridLines.getWidth(k, j); m++)
{
int x = gridLines.getXLine(k, j, m).getP1().X;
int y = gridLines.getXLine(k, j, m).getP1().Y;
int x2 = gridLines.getXLine(k, j, m).getP2().X;
int y2 = gridLines.getXLine(k, j, m).getP2().Y;
int x3 = gridLines.getYLine(k, j, l).getP1().X;
int y3 = gridLines.getYLine(k, j, l).getP1().Y;
int x4 = gridLines.getYLine(k, j, l).getP2().X;
int y4 = gridLines.getYLine(k, j, l).getP2().Y;
int num = (y2 - y) * (x3 - x4) - (y4 - y3) * (x - x2);
int num2 = (x * y2 - x2 * y) * (x3 - x4) - (x3 * y4 - x4 * y3) * (x - x2);
int num3 = (x3 * y4 - x4 * y3) * (y2 - y) - (x * y2 - x2 * y) * (y4 - y3);
array[gridLines.getX(k, m)][gridLines.getY(j, l)] = image[num2 / num][num3 / num];
if (j == gridLines.getHeight() - 1 && k == gridLines.getWidth() - 1 && l == gridLines.getHeight(k, j) - 1 && m == gridLines.getWidth(k, j) - 1)
{
point = new Point(num2 / num, num3 / num);
}
}
}
}
}
if (point.X > image.Length - 1 || point.Y > image[0].Length - 1)
{
throw new IndexOutOfRangeException("Sampling grid pointed out of image");
}
canvas.drawPoint(point, Color_Fields.BLUE);
return array;
}
}