mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
A few inspection cleanups
git-svn-id: https://zxing.googlecode.com/svn/trunk@2660 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
cdd033e582
commit
96c8b2a8b6
|
@ -326,10 +326,9 @@ final class QRCodeEncoder {
|
||||||
hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
|
hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
|
||||||
hints.put(EncodeHintType.CHARACTER_SET, encoding);
|
hints.put(EncodeHintType.CHARACTER_SET, encoding);
|
||||||
}
|
}
|
||||||
MultiFormatWriter writer = new MultiFormatWriter();
|
|
||||||
BitMatrix result;
|
BitMatrix result;
|
||||||
try {
|
try {
|
||||||
result = writer.encode(contentsToEncode, format, dimension, dimension, hints);
|
result = new MultiFormatWriter().encode(contentsToEncode, format, dimension, dimension, hints);
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
// Unsupported format
|
// Unsupported format
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -34,19 +34,6 @@ public final class BenchmarkActivity extends Activity {
|
||||||
private TextView textView;
|
private TextView textView;
|
||||||
private Thread benchmarkThread;
|
private Thread benchmarkThread;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
|
|
||||||
setContentView(R.layout.benchmark);
|
|
||||||
|
|
||||||
runBenchmarkButton = (Button) findViewById(R.id.benchmark_run);
|
|
||||||
runBenchmarkButton.setOnClickListener(runBenchmark);
|
|
||||||
textView = (TextView) findViewById(R.id.benchmark_help);
|
|
||||||
|
|
||||||
benchmarkThread = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Button.OnClickListener runBenchmark = new Button.OnClickListener() {
|
private final Button.OnClickListener runBenchmark = new Button.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -59,22 +46,10 @@ public final class BenchmarkActivity extends Activity {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final Handler handler = new Handler() {
|
private final Handler handler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
switch (message.what) {
|
if (message.what == R.id.benchmark_done) {
|
||||||
case R.id.benchmark_done:
|
|
||||||
handleBenchmarkDone(message);
|
|
||||||
benchmarkThread = null;
|
|
||||||
runBenchmarkButton.setEnabled(true);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void handleBenchmarkDone(Message message) {
|
|
||||||
Iterable<BenchmarkItem> items = (Iterable<BenchmarkItem>) message.obj;
|
Iterable<BenchmarkItem> items = (Iterable<BenchmarkItem>) message.obj;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int time = 0;
|
int time = 0;
|
||||||
|
@ -88,6 +63,27 @@ public final class BenchmarkActivity extends Activity {
|
||||||
String totals = "TOTAL: Decoded " + count + " images in " + time + " us";
|
String totals = "TOTAL: Decoded " + count + " images in " + time + " us";
|
||||||
Log.v(TAG, totals);
|
Log.v(TAG, totals);
|
||||||
textView.setText(totals + "\n\n" + getString(R.string.benchmark_help));
|
textView.setText(totals + "\n\n" + getString(R.string.benchmark_help));
|
||||||
|
benchmarkThread = null;
|
||||||
|
runBenchmarkButton.setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Handler getHandler() {
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle icicle) {
|
||||||
|
super.onCreate(icicle);
|
||||||
|
|
||||||
|
setContentView(R.layout.benchmark);
|
||||||
|
|
||||||
|
runBenchmarkButton = (Button) findViewById(R.id.benchmark_run);
|
||||||
|
runBenchmarkButton.setOnClickListener(runBenchmark);
|
||||||
|
textView = (TextView) findViewById(R.id.benchmark_help);
|
||||||
|
|
||||||
|
benchmarkThread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ final class BenchmarkThread implements Runnable {
|
||||||
|
|
||||||
List<BenchmarkItem> items = new ArrayList<BenchmarkItem>();
|
List<BenchmarkItem> items = new ArrayList<BenchmarkItem>();
|
||||||
walkTree(path, items);
|
walkTree(path, items);
|
||||||
Message message = Message.obtain(activity.handler, R.id.benchmark_done);
|
Message message = Message.obtain(activity.getHandler(), R.id.benchmark_done);
|
||||||
message.obj = items;
|
message.obj = items;
|
||||||
message.sendToTarget();
|
message.sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,26 +164,26 @@ public final class Detector {
|
||||||
float ratio = (2 * nbLayers + (nbLayers > 4 ? 1 : 0) + (nbLayers - 4) / 8)
|
float ratio = (2 * nbLayers + (nbLayers > 4 ? 1 : 0) + (nbLayers - 4) / 8)
|
||||||
/ (2.0f * nbCenterLayers);
|
/ (2.0f * nbCenterLayers);
|
||||||
|
|
||||||
int dx = bullEyeCornerPoints[0].x-bullEyeCornerPoints[2].x;
|
int dx = bullEyeCornerPoints[0].getX() - bullEyeCornerPoints[2].getX();
|
||||||
dx+=dx>0?1:-1;
|
dx+=dx>0?1:-1;
|
||||||
int dy = bullEyeCornerPoints[0].y-bullEyeCornerPoints[2].y;
|
int dy = bullEyeCornerPoints[0].getY() - bullEyeCornerPoints[2].getY();
|
||||||
dy+=dy>0?1:-1;
|
dy+=dy>0?1:-1;
|
||||||
|
|
||||||
int targetcx = MathUtils.round(bullEyeCornerPoints[2].x - ratio * dx);
|
int targetcx = MathUtils.round(bullEyeCornerPoints[2].getX() - ratio * dx);
|
||||||
int targetcy = MathUtils.round(bullEyeCornerPoints[2].y - ratio * dy);
|
int targetcy = MathUtils.round(bullEyeCornerPoints[2].getY() - ratio * dy);
|
||||||
|
|
||||||
int targetax = MathUtils.round(bullEyeCornerPoints[0].x + ratio * dx);
|
int targetax = MathUtils.round(bullEyeCornerPoints[0].getX() + ratio * dx);
|
||||||
int targetay = MathUtils.round(bullEyeCornerPoints[0].y + ratio * dy);
|
int targetay = MathUtils.round(bullEyeCornerPoints[0].getY() + ratio * dy);
|
||||||
|
|
||||||
dx = bullEyeCornerPoints[1].x-bullEyeCornerPoints[3].x;
|
dx = bullEyeCornerPoints[1].getX() - bullEyeCornerPoints[3].getX();
|
||||||
dx+=dx>0?1:-1;
|
dx+=dx>0?1:-1;
|
||||||
dy = bullEyeCornerPoints[1].y-bullEyeCornerPoints[3].y;
|
dy = bullEyeCornerPoints[1].getY() - bullEyeCornerPoints[3].getY();
|
||||||
dy+=dy>0?1:-1;
|
dy+=dy>0?1:-1;
|
||||||
|
|
||||||
int targetdx = MathUtils.round(bullEyeCornerPoints[3].x - ratio * dx);
|
int targetdx = MathUtils.round(bullEyeCornerPoints[3].getX() - ratio * dx);
|
||||||
int targetdy = MathUtils.round(bullEyeCornerPoints[3].y - ratio * dy);
|
int targetdy = MathUtils.round(bullEyeCornerPoints[3].getY() - ratio * dy);
|
||||||
int targetbx = MathUtils.round(bullEyeCornerPoints[1].x + ratio * dx);
|
int targetbx = MathUtils.round(bullEyeCornerPoints[1].getX() + ratio * dx);
|
||||||
int targetby = MathUtils.round(bullEyeCornerPoints[1].y+ratio*dy);
|
int targetby = MathUtils.round(bullEyeCornerPoints[1].getY() +ratio*dy);
|
||||||
|
|
||||||
if (!isValid(targetax, targetay) ||
|
if (!isValid(targetax, targetay) ||
|
||||||
!isValid(targetbx, targetby) ||
|
!isValid(targetbx, targetby) ||
|
||||||
|
@ -299,20 +299,20 @@ public final class Detector {
|
||||||
|
|
||||||
float ratio = 0.75f*2/(2*nbCenterLayers-3);
|
float ratio = 0.75f*2/(2*nbCenterLayers-3);
|
||||||
|
|
||||||
int dx = pina.x-pinc.x;
|
int dx = pina.getX() - pinc.getX();
|
||||||
int dy = pina.y-pinc.y;
|
int dy = pina.getY() - pinc.getY();
|
||||||
int targetcx = MathUtils.round(pinc.x-ratio*dx);
|
int targetcx = MathUtils.round(pinc.getX() -ratio*dx);
|
||||||
int targetcy = MathUtils.round(pinc.y-ratio*dy);
|
int targetcy = MathUtils.round(pinc.getY() -ratio*dy);
|
||||||
int targetax = MathUtils.round(pina.x+ratio*dx);
|
int targetax = MathUtils.round(pina.getX() +ratio*dx);
|
||||||
int targetay = MathUtils.round(pina.y+ratio*dy);
|
int targetay = MathUtils.round(pina.getY() +ratio*dy);
|
||||||
|
|
||||||
dx = pinb.x-pind.x;
|
dx = pinb.getX() - pind.getX();
|
||||||
dy = pinb.y-pind.y;
|
dy = pinb.getY() - pind.getY();
|
||||||
|
|
||||||
int targetdx = MathUtils.round(pind.x-ratio*dx);
|
int targetdx = MathUtils.round(pind.getX() -ratio*dx);
|
||||||
int targetdy = MathUtils.round(pind.y-ratio*dy);
|
int targetdy = MathUtils.round(pind.getY() -ratio*dy);
|
||||||
int targetbx = MathUtils.round(pinb.x+ratio*dx);
|
int targetbx = MathUtils.round(pinb.getX() +ratio*dx);
|
||||||
int targetby = MathUtils.round(pinb.y+ratio*dy);
|
int targetby = MathUtils.round(pinb.getY() +ratio*dy);
|
||||||
|
|
||||||
if (!isValid(targetax, targetay) ||
|
if (!isValid(targetax, targetay) ||
|
||||||
!isValid(targetbx, targetby) ||
|
!isValid(targetbx, targetby) ||
|
||||||
|
@ -484,11 +484,11 @@ public final class Detector {
|
||||||
boolean[] res = new boolean[size];
|
boolean[] res = new boolean[size];
|
||||||
float d = distance(p1,p2);
|
float d = distance(p1,p2);
|
||||||
float moduleSize = d/(size-1);
|
float moduleSize = d/(size-1);
|
||||||
float dx = moduleSize*(p2.x - p1.x)/d;
|
float dx = moduleSize*(p2.getX() - p1.getX())/d;
|
||||||
float dy = moduleSize*(p2.y - p1.y)/d;
|
float dy = moduleSize*(p2.getY() - p1.getY())/d;
|
||||||
|
|
||||||
float px = p1.x;
|
float px = p1.getX();
|
||||||
float py = p1.y;
|
float py = p1.getY();
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
res[i] = image.get(MathUtils.round(px), MathUtils.round(py));
|
res[i] = image.get(MathUtils.round(px), MathUtils.round(py));
|
||||||
|
@ -510,10 +510,10 @@ public final class Detector {
|
||||||
|
|
||||||
int corr = 3;
|
int corr = 3;
|
||||||
|
|
||||||
p1 = new Point(p1.x-corr, p1.y+corr);
|
p1 = new Point(p1.getX() -corr, p1.getY() +corr);
|
||||||
p2 = new Point(p2.x-corr, p2.y-corr);
|
p2 = new Point(p2.getX() -corr, p2.getY() -corr);
|
||||||
p3 = new Point(p3.x+corr, p3.y-corr);
|
p3 = new Point(p3.getX() +corr, p3.getY() -corr);
|
||||||
p4 = new Point(p4.x+corr, p4.y+corr);
|
p4 = new Point(p4.getX() +corr, p4.getY() +corr);
|
||||||
|
|
||||||
int cInit = getColor(p4, p1);
|
int cInit = getColor(p4, p1);
|
||||||
|
|
||||||
|
@ -546,14 +546,14 @@ public final class Detector {
|
||||||
*/
|
*/
|
||||||
private int getColor(Point p1, Point p2) {
|
private int getColor(Point p1, Point p2) {
|
||||||
float d = distance(p1,p2);
|
float d = distance(p1,p2);
|
||||||
float dx = (p2.x - p1.x)/d;
|
float dx = (p2.getX() - p1.getX())/d;
|
||||||
float dy = (p2.y - p1.y)/d;
|
float dy = (p2.getY() - p1.getY())/d;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
float px = p1.x;
|
float px = p1.getX();
|
||||||
float py = p1.y;
|
float py = p1.getY();
|
||||||
|
|
||||||
boolean colorModel = image.get(p1.x, p1.y);
|
boolean colorModel = image.get(p1.getX(), p1.getY());
|
||||||
|
|
||||||
for (int i = 0; i < d; i++) {
|
for (int i = 0; i < d; i++) {
|
||||||
px+=dx;
|
px+=dx;
|
||||||
|
@ -576,8 +576,8 @@ public final class Detector {
|
||||||
* Gets the coordinate of the first point with a different color in the given direction
|
* Gets the coordinate of the first point with a different color in the given direction
|
||||||
*/
|
*/
|
||||||
private Point getFirstDifferent(Point init, boolean color, int dx, int dy) {
|
private Point getFirstDifferent(Point init, boolean color, int dx, int dy) {
|
||||||
int x = init.x+dx;
|
int x = init.getX() +dx;
|
||||||
int y = init.y+dy;
|
int y = init.getY() +dy;
|
||||||
|
|
||||||
while(isValid(x,y) && image.get(x,y) == color) {
|
while(isValid(x,y) && image.get(x,y) == color) {
|
||||||
x+=dx;
|
x+=dx;
|
||||||
|
@ -605,21 +605,29 @@ public final class Detector {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float distance(Point a, Point b) {
|
private static float distance(Point a, Point b) {
|
||||||
return MathUtils.distance(a.x, a.y, b.x, b.y);
|
return MathUtils.distance(a.getX(), a.getY(), b.getX(), b.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Point {
|
static final class Point {
|
||||||
final int x;
|
private final int x;
|
||||||
final int y;
|
private final int y;
|
||||||
|
|
||||||
ResultPoint toResultPoint() {
|
ResultPoint toResultPoint() {
|
||||||
return new ResultPoint(x, y);
|
return new ResultPoint(getX(), getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
Point(int x, int y) {
|
Point(int x, int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -524,9 +524,7 @@ public final class LinesSampler {
|
||||||
return rowCount;
|
return rowCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class VoteResult {
|
||||||
|
|
||||||
private static class VoteResult {
|
|
||||||
private boolean indecisive;
|
private boolean indecisive;
|
||||||
private int vote;
|
private int vote;
|
||||||
boolean isIndecisive() {
|
boolean isIndecisive() {
|
||||||
|
|
|
@ -84,25 +84,19 @@ public final class BitVectorTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAppendBits() {
|
public void testAppendBits() {
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
BitArray v = new BitArray();
|
||||||
v.appendBits(0x1, 1);
|
v.appendBits(0x1, 1);
|
||||||
assertEquals(1, v.getSize());
|
assertEquals(1, v.getSize());
|
||||||
assertEquals(0x80000000L, getUnsignedInt(v, 0));
|
assertEquals(0x80000000L, getUnsignedInt(v, 0));
|
||||||
}
|
v = new BitArray();
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
|
||||||
v.appendBits(0xff, 8);
|
v.appendBits(0xff, 8);
|
||||||
assertEquals(8, v.getSize());
|
assertEquals(8, v.getSize());
|
||||||
assertEquals(0xff000000L, getUnsignedInt(v, 0));
|
assertEquals(0xff000000L, getUnsignedInt(v, 0));
|
||||||
}
|
v = new BitArray();
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
|
||||||
v.appendBits(0xff7, 12);
|
v.appendBits(0xff7, 12);
|
||||||
assertEquals(12, v.getSize());
|
assertEquals(12, v.getSize());
|
||||||
assertEquals(0xff700000L, getUnsignedInt(v, 0));
|
assertEquals(0xff700000L, getUnsignedInt(v, 0));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNumBytes() {
|
public void testNumBytes() {
|
||||||
|
|
|
@ -173,53 +173,42 @@ public final class EncoderTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAppendLengthInfo() throws WriterException {
|
public void testAppendLengthInfo() throws WriterException {
|
||||||
{
|
|
||||||
BitArray bits = new BitArray();
|
BitArray bits = new BitArray();
|
||||||
Encoder.appendLengthInfo(1, // 1 letter (1/1).
|
Encoder.appendLengthInfo(1, // 1 letter (1/1).
|
||||||
Version.getVersionForNumber(1),
|
Version.getVersionForNumber(1),
|
||||||
Mode.NUMERIC,
|
Mode.NUMERIC,
|
||||||
bits);
|
bits);
|
||||||
assertEquals(" ........ .X", bits.toString()); // 10 bits.
|
assertEquals(" ........ .X", bits.toString()); // 10 bits.
|
||||||
}
|
bits = new BitArray();
|
||||||
{
|
|
||||||
BitArray bits = new BitArray();
|
|
||||||
Encoder.appendLengthInfo(2, // 2 letters (2/1).
|
Encoder.appendLengthInfo(2, // 2 letters (2/1).
|
||||||
Version.getVersionForNumber(10),
|
Version.getVersionForNumber(10),
|
||||||
Mode.ALPHANUMERIC,
|
Mode.ALPHANUMERIC,
|
||||||
bits);
|
bits);
|
||||||
assertEquals(" ........ .X.", bits.toString()); // 11 bits.
|
assertEquals(" ........ .X.", bits.toString()); // 11 bits.
|
||||||
}
|
bits = new BitArray();
|
||||||
{
|
|
||||||
BitArray bits = new BitArray();
|
|
||||||
Encoder.appendLengthInfo(255, // 255 letter (255/1).
|
Encoder.appendLengthInfo(255, // 255 letter (255/1).
|
||||||
Version.getVersionForNumber(27),
|
Version.getVersionForNumber(27),
|
||||||
Mode.BYTE,
|
Mode.BYTE,
|
||||||
bits);
|
bits);
|
||||||
assertEquals(" ........ XXXXXXXX", bits.toString()); // 16 bits.
|
assertEquals(" ........ XXXXXXXX", bits.toString()); // 16 bits.
|
||||||
}
|
bits = new BitArray();
|
||||||
{
|
|
||||||
BitArray bits = new BitArray();
|
|
||||||
Encoder.appendLengthInfo(512, // 512 letters (1024/2).
|
Encoder.appendLengthInfo(512, // 512 letters (1024/2).
|
||||||
Version.getVersionForNumber(40),
|
Version.getVersionForNumber(40),
|
||||||
Mode.KANJI,
|
Mode.KANJI,
|
||||||
bits);
|
bits);
|
||||||
assertEquals(" ..X..... ....", bits.toString()); // 12 bits.
|
assertEquals(" ..X..... ....", bits.toString()); // 12 bits.
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAppendBytes() throws WriterException {
|
public void testAppendBytes() throws WriterException {
|
||||||
{
|
|
||||||
// Should use appendNumericBytes.
|
// Should use appendNumericBytes.
|
||||||
// 1 = 01 = 0001 in 4 bits.
|
// 1 = 01 = 0001 in 4 bits.
|
||||||
BitArray bits = new BitArray();
|
BitArray bits = new BitArray();
|
||||||
Encoder.appendBytes("1", Mode.NUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
Encoder.appendBytes("1", Mode.NUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
||||||
assertEquals(" ...X" , bits.toString());
|
assertEquals(" ...X" , bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// Should use appendAlphanumericBytes.
|
// Should use appendAlphanumericBytes.
|
||||||
// A = 10 = 0xa = 001010 in 6 bits
|
// A = 10 = 0xa = 001010 in 6 bits
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendBytes("A", Mode.ALPHANUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
Encoder.appendBytes("A", Mode.ALPHANUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
||||||
assertEquals(" ..X.X." , bits.toString());
|
assertEquals(" ..X.X." , bits.toString());
|
||||||
// Lower letters such as 'a' cannot be encoded in MODE_ALPHANUMERIC.
|
// Lower letters such as 'a' cannot be encoded in MODE_ALPHANUMERIC.
|
||||||
|
@ -228,67 +217,48 @@ public final class EncoderTestCase extends Assert {
|
||||||
} catch (WriterException we) {
|
} catch (WriterException we) {
|
||||||
// good
|
// good
|
||||||
}
|
}
|
||||||
}
|
|
||||||
{
|
|
||||||
// Should use append8BitBytes.
|
// Should use append8BitBytes.
|
||||||
// 0x61, 0x62, 0x63
|
// 0x61, 0x62, 0x63
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendBytes("abc", Mode.BYTE, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
Encoder.appendBytes("abc", Mode.BYTE, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
||||||
assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
|
assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
|
||||||
// Anything can be encoded in QRCode.MODE_8BIT_BYTE.
|
// Anything can be encoded in QRCode.MODE_8BIT_BYTE.
|
||||||
Encoder.appendBytes("\0", Mode.BYTE, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
Encoder.appendBytes("\0", Mode.BYTE, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
||||||
}
|
|
||||||
{
|
|
||||||
// Should use appendKanjiBytes.
|
// Should use appendKanjiBytes.
|
||||||
// 0x93, 0x5f
|
// 0x93, 0x5f
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendBytes(shiftJISString(new byte[] {(byte)0x93,0x5f}), Mode.KANJI, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
Encoder.appendBytes(shiftJISString(new byte[] {(byte)0x93,0x5f}), Mode.KANJI, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
||||||
assertEquals(" .XX.XX.. XXXXX", bits.toString());
|
assertEquals(" .XX.XX.. XXXXX", bits.toString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTerminateBits() throws WriterException {
|
public void testTerminateBits() throws WriterException {
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
BitArray v = new BitArray();
|
||||||
Encoder.terminateBits(0, v);
|
Encoder.terminateBits(0, v);
|
||||||
assertEquals("", v.toString());
|
assertEquals("", v.toString());
|
||||||
}
|
v = new BitArray();
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
|
||||||
Encoder.terminateBits(1, v);
|
Encoder.terminateBits(1, v);
|
||||||
assertEquals(" ........", v.toString());
|
assertEquals(" ........", v.toString());
|
||||||
}
|
v = new BitArray();
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
|
||||||
v.appendBits(0, 3); // Append 000
|
v.appendBits(0, 3); // Append 000
|
||||||
Encoder.terminateBits(1, v);
|
Encoder.terminateBits(1, v);
|
||||||
assertEquals(" ........", v.toString());
|
assertEquals(" ........", v.toString());
|
||||||
}
|
v = new BitArray();
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
|
||||||
v.appendBits(0, 5); // Append 00000
|
v.appendBits(0, 5); // Append 00000
|
||||||
Encoder.terminateBits(1, v);
|
Encoder.terminateBits(1, v);
|
||||||
assertEquals(" ........", v.toString());
|
assertEquals(" ........", v.toString());
|
||||||
}
|
v = new BitArray();
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
|
||||||
v.appendBits(0, 8); // Append 00000000
|
v.appendBits(0, 8); // Append 00000000
|
||||||
Encoder.terminateBits(1, v);
|
Encoder.terminateBits(1, v);
|
||||||
assertEquals(" ........", v.toString());
|
assertEquals(" ........", v.toString());
|
||||||
}
|
v = new BitArray();
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
|
||||||
Encoder.terminateBits(2, v);
|
Encoder.terminateBits(2, v);
|
||||||
assertEquals(" ........ XXX.XX..", v.toString());
|
assertEquals(" ........ XXX.XX..", v.toString());
|
||||||
}
|
v = new BitArray();
|
||||||
{
|
|
||||||
BitArray v = new BitArray();
|
|
||||||
v.appendBits(0, 1); // Append 0
|
v.appendBits(0, 1); // Append 0
|
||||||
Encoder.terminateBits(3, v);
|
Encoder.terminateBits(3, v);
|
||||||
assertEquals(" ........ XXX.XX.. ...X...X", v.toString());
|
assertEquals(" ........ XXX.XX.. ...X...X", v.toString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetNumDataBytesAndNumECBytesForBlockID() throws WriterException {
|
public void testGetNumDataBytesAndNumECBytesForBlockID() throws WriterException {
|
||||||
|
@ -329,7 +299,6 @@ public final class EncoderTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInterleaveWithECBytes() throws WriterException {
|
public void testInterleaveWithECBytes() throws WriterException {
|
||||||
{
|
|
||||||
byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
|
byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
|
||||||
BitArray in = new BitArray();
|
BitArray in = new BitArray();
|
||||||
for (byte dataByte: dataBytes) {
|
for (byte dataByte: dataBytes) {
|
||||||
|
@ -350,10 +319,8 @@ public final class EncoderTestCase extends Assert {
|
||||||
for (int x = 0; x < expected.length; x++) {
|
for (int x = 0; x < expected.length; x++) {
|
||||||
assertEquals(expected[x], outArray[x]);
|
assertEquals(expected[x], outArray[x]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Numbers are from http://www.swetake.com/qr/qr8.html
|
// Numbers are from http://www.swetake.com/qr/qr8.html
|
||||||
{
|
dataBytes = new byte[] {
|
||||||
byte[] dataBytes = {
|
|
||||||
67, 70, 22, 38, 54, 70, 86, 102, 118, (byte)134, (byte)150, (byte)166, (byte)182,
|
67, 70, 22, 38, 54, 70, 86, 102, 118, (byte)134, (byte)150, (byte)166, (byte)182,
|
||||||
(byte)198, (byte)214, (byte)230, (byte)247, 7, 23, 39, 55, 71, 87, 103, 119, (byte)135,
|
(byte)198, (byte)214, (byte)230, (byte)247, 7, 23, 39, 55, 71, 87, 103, 119, (byte)135,
|
||||||
(byte)151, (byte)166, 22, 38, 54, 70, 86, 102, 118, (byte)134, (byte)150, (byte)166,
|
(byte)151, (byte)166, 22, 38, 54, 70, 86, 102, 118, (byte)134, (byte)150, (byte)166,
|
||||||
|
@ -361,13 +328,13 @@ public final class EncoderTestCase extends Assert {
|
||||||
(byte)135, (byte)151, (byte)160, (byte)236, 17, (byte)236, 17, (byte)236, 17, (byte)236,
|
(byte)135, (byte)151, (byte)160, (byte)236, 17, (byte)236, 17, (byte)236, 17, (byte)236,
|
||||||
17
|
17
|
||||||
};
|
};
|
||||||
BitArray in = new BitArray();
|
in = new BitArray();
|
||||||
for (byte dataByte: dataBytes) {
|
for (byte dataByte: dataBytes) {
|
||||||
in.appendBits(dataByte, 8);
|
in.appendBits(dataByte, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
BitArray out = Encoder.interleaveWithECBytes(in, 134, 62, 4);
|
out = Encoder.interleaveWithECBytes(in, 134, 62, 4);
|
||||||
byte[] expected = {
|
expected = new byte[] {
|
||||||
// Data bytes.
|
// Data bytes.
|
||||||
67, (byte)230, 54, 55, 70, (byte)247, 70, 71, 22, 7, 86, 87, 38, 23, 102, 103, 54, 39,
|
67, (byte)230, 54, 55, 70, (byte)247, 70, 71, 22, 7, 86, 87, 38, 23, 102, 103, 54, 39,
|
||||||
118, 119, 70, 55, (byte)134, (byte)135, 86, 71, (byte)150, (byte)151, 102, 87, (byte)166,
|
118, 119, 70, 55, (byte)134, (byte)135, 86, 71, (byte)150, (byte)151, 102, 87, (byte)166,
|
||||||
|
@ -385,75 +352,55 @@ public final class EncoderTestCase extends Assert {
|
||||||
(byte)187, 49, (byte)156, (byte)214,
|
(byte)187, 49, (byte)156, (byte)214,
|
||||||
};
|
};
|
||||||
assertEquals(expected.length, out.getSizeInBytes());
|
assertEquals(expected.length, out.getSizeInBytes());
|
||||||
byte[] outArray = new byte[expected.length];
|
outArray = new byte[expected.length];
|
||||||
out.toBytes(0, outArray, 0, expected.length);
|
out.toBytes(0, outArray, 0, expected.length);
|
||||||
for (int x = 0; x < expected.length; x++) {
|
for (int x = 0; x < expected.length; x++) {
|
||||||
assertEquals(expected[x], outArray[x]);
|
assertEquals(expected[x], outArray[x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAppendNumericBytes() {
|
public void testAppendNumericBytes() {
|
||||||
{
|
|
||||||
// 1 = 01 = 0001 in 4 bits.
|
// 1 = 01 = 0001 in 4 bits.
|
||||||
BitArray bits = new BitArray();
|
BitArray bits = new BitArray();
|
||||||
Encoder.appendNumericBytes("1", bits);
|
Encoder.appendNumericBytes("1", bits);
|
||||||
assertEquals(" ...X" , bits.toString());
|
assertEquals(" ...X" , bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// 12 = 0xc = 0001100 in 7 bits.
|
// 12 = 0xc = 0001100 in 7 bits.
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendNumericBytes("12", bits);
|
Encoder.appendNumericBytes("12", bits);
|
||||||
assertEquals(" ...XX.." , bits.toString());
|
assertEquals(" ...XX.." , bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// 123 = 0x7b = 0001111011 in 10 bits.
|
// 123 = 0x7b = 0001111011 in 10 bits.
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendNumericBytes("123", bits);
|
Encoder.appendNumericBytes("123", bits);
|
||||||
assertEquals(" ...XXXX. XX" , bits.toString());
|
assertEquals(" ...XXXX. XX" , bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// 1234 = "123" + "4" = 0001111011 + 0100
|
// 1234 = "123" + "4" = 0001111011 + 0100
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendNumericBytes("1234", bits);
|
Encoder.appendNumericBytes("1234", bits);
|
||||||
assertEquals(" ...XXXX. XX.X.." , bits.toString());
|
assertEquals(" ...XXXX. XX.X.." , bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// Empty.
|
// Empty.
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendNumericBytes("", bits);
|
Encoder.appendNumericBytes("", bits);
|
||||||
assertEquals("" , bits.toString());
|
assertEquals("" , bits.toString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAppendAlphanumericBytes() throws WriterException {
|
public void testAppendAlphanumericBytes() throws WriterException {
|
||||||
{
|
|
||||||
// A = 10 = 0xa = 001010 in 6 bits
|
// A = 10 = 0xa = 001010 in 6 bits
|
||||||
BitArray bits = new BitArray();
|
BitArray bits = new BitArray();
|
||||||
Encoder.appendAlphanumericBytes("A", bits);
|
Encoder.appendAlphanumericBytes("A", bits);
|
||||||
assertEquals(" ..X.X." , bits.toString());
|
assertEquals(" ..X.X." , bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// AB = 10 * 45 + 11 = 461 = 0x1cd = 00111001101 in 11 bits
|
// AB = 10 * 45 + 11 = 461 = 0x1cd = 00111001101 in 11 bits
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendAlphanumericBytes("AB", bits);
|
Encoder.appendAlphanumericBytes("AB", bits);
|
||||||
assertEquals(" ..XXX..X X.X", bits.toString());
|
assertEquals(" ..XXX..X X.X", bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// ABC = "AB" + "C" = 00111001101 + 001100
|
// ABC = "AB" + "C" = 00111001101 + 001100
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendAlphanumericBytes("ABC", bits);
|
Encoder.appendAlphanumericBytes("ABC", bits);
|
||||||
assertEquals(" ..XXX..X X.X..XX. ." , bits.toString());
|
assertEquals(" ..XXX..X X.X..XX. ." , bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// Empty.
|
// Empty.
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.appendAlphanumericBytes("", bits);
|
Encoder.appendAlphanumericBytes("", bits);
|
||||||
assertEquals("" , bits.toString());
|
assertEquals("" , bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// Invalid data.
|
// Invalid data.
|
||||||
try {
|
try {
|
||||||
Encoder.appendAlphanumericBytes("abc", new BitArray());
|
Encoder.appendAlphanumericBytes("abc", new BitArray());
|
||||||
|
@ -461,23 +408,18 @@ public final class EncoderTestCase extends Assert {
|
||||||
// good
|
// good
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAppend8BitBytes() throws WriterException {
|
public void testAppend8BitBytes() throws WriterException {
|
||||||
{
|
|
||||||
// 0x61, 0x62, 0x63
|
// 0x61, 0x62, 0x63
|
||||||
BitArray bits = new BitArray();
|
BitArray bits = new BitArray();
|
||||||
Encoder.append8BitBytes("abc", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
Encoder.append8BitBytes("abc", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
||||||
assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
|
assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
|
||||||
}
|
|
||||||
{
|
|
||||||
// Empty.
|
// Empty.
|
||||||
BitArray bits = new BitArray();
|
bits = new BitArray();
|
||||||
Encoder.append8BitBytes("", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
Encoder.append8BitBytes("", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
|
||||||
assertEquals("", bits.toString());
|
assertEquals("", bits.toString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Numbers are from page 21 of JISX0510:2004
|
// Numbers are from page 21 of JISX0510:2004
|
||||||
@Test
|
@Test
|
||||||
|
@ -493,7 +435,6 @@ public final class EncoderTestCase extends Assert {
|
||||||
// http://www.swetake.com/qr/qr9.html
|
// http://www.swetake.com/qr/qr9.html
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateECBytes() {
|
public void testGenerateECBytes() {
|
||||||
{
|
|
||||||
byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
|
byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
|
||||||
byte[] ecBytes = Encoder.generateECBytes(dataBytes, 17);
|
byte[] ecBytes = Encoder.generateECBytes(dataBytes, 17);
|
||||||
int[] expected = {
|
int[] expected = {
|
||||||
|
@ -503,24 +444,20 @@ public final class EncoderTestCase extends Assert {
|
||||||
for (int x = 0; x < expected.length; x++) {
|
for (int x = 0; x < expected.length; x++) {
|
||||||
assertEquals(expected[x], ecBytes[x] & 0xFF);
|
assertEquals(expected[x], ecBytes[x] & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
dataBytes = new byte[] {67, 70, 22, 38, 54, 70, 86, 102, 118,
|
||||||
{
|
|
||||||
byte[] dataBytes = {67, 70, 22, 38, 54, 70, 86, 102, 118,
|
|
||||||
(byte)134, (byte)150, (byte)166, (byte)182, (byte)198, (byte)214};
|
(byte)134, (byte)150, (byte)166, (byte)182, (byte)198, (byte)214};
|
||||||
byte[] ecBytes = Encoder.generateECBytes(dataBytes, 18);
|
ecBytes = Encoder.generateECBytes(dataBytes, 18);
|
||||||
int[] expected = {
|
expected = new int[] {
|
||||||
175, 80, 155, 64, 178, 45, 214, 233, 65, 209, 12, 155, 117, 31, 140, 214, 27, 187
|
175, 80, 155, 64, 178, 45, 214, 233, 65, 209, 12, 155, 117, 31, 140, 214, 27, 187
|
||||||
};
|
};
|
||||||
assertEquals(expected.length, ecBytes.length);
|
assertEquals(expected.length, ecBytes.length);
|
||||||
for (int x = 0; x < expected.length; x++) {
|
for (int x = 0; x < expected.length; x++) {
|
||||||
assertEquals(expected[x], ecBytes[x] & 0xFF);
|
assertEquals(expected[x], ecBytes[x] & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
{
|
|
||||||
// High-order zero coefficient case.
|
// High-order zero coefficient case.
|
||||||
byte[] dataBytes = {32, 49, (byte)205, 69, 42, 20, 0, (byte)236, 17};
|
dataBytes = new byte[] {32, 49, (byte)205, 69, 42, 20, 0, (byte)236, 17};
|
||||||
byte[] ecBytes = Encoder.generateECBytes(dataBytes, 17);
|
ecBytes = Encoder.generateECBytes(dataBytes, 17);
|
||||||
int[] expected = {
|
expected = new int[] {
|
||||||
0, 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213
|
0, 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213
|
||||||
};
|
};
|
||||||
assertEquals(expected.length, ecBytes.length);
|
assertEquals(expected.length, ecBytes.length);
|
||||||
|
@ -528,7 +465,6 @@ public final class EncoderTestCase extends Assert {
|
||||||
assertEquals(expected[x], ecBytes[x] & 0xFF);
|
assertEquals(expected[x], ecBytes[x] & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBugInBitVectorNumBytes() throws WriterException {
|
public void testBugInBitVectorNumBytes() throws WriterException {
|
||||||
|
|
|
@ -23,21 +23,18 @@ import org.junit.Test;
|
||||||
* @author satorux@google.com (Satoru Takabayashi) - creator
|
* @author satorux@google.com (Satoru Takabayashi) - creator
|
||||||
* @author mysen@google.com (Chris Mysen) - ported from C++
|
* @author mysen@google.com (Chris Mysen) - ported from C++
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class MaskUtilTestCase extends Assert {
|
public final class MaskUtilTestCase extends Assert {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyMaskPenaltyRule1() {
|
public void testApplyMaskPenaltyRule1() {
|
||||||
{
|
|
||||||
ByteMatrix matrix = new ByteMatrix(4, 1);
|
ByteMatrix matrix = new ByteMatrix(4, 1);
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(1, 0, 0);
|
matrix.set(1, 0, 0);
|
||||||
matrix.set(2, 0, 0);
|
matrix.set(2, 0, 0);
|
||||||
matrix.set(3, 0, 0);
|
matrix.set(3, 0, 0);
|
||||||
assertEquals(0, MaskUtil.applyMaskPenaltyRule1(matrix));
|
assertEquals(0, MaskUtil.applyMaskPenaltyRule1(matrix));
|
||||||
}
|
// Horizontal.
|
||||||
{ // Horizontal.
|
matrix = new ByteMatrix(6, 1);
|
||||||
ByteMatrix matrix = new ByteMatrix(6, 1);
|
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(1, 0, 0);
|
matrix.set(1, 0, 0);
|
||||||
matrix.set(2, 0, 0);
|
matrix.set(2, 0, 0);
|
||||||
|
@ -47,9 +44,8 @@ public final class MaskUtilTestCase extends Assert {
|
||||||
assertEquals(3, MaskUtil.applyMaskPenaltyRule1(matrix));
|
assertEquals(3, MaskUtil.applyMaskPenaltyRule1(matrix));
|
||||||
matrix.set(5, 0, 0);
|
matrix.set(5, 0, 0);
|
||||||
assertEquals(4, MaskUtil.applyMaskPenaltyRule1(matrix));
|
assertEquals(4, MaskUtil.applyMaskPenaltyRule1(matrix));
|
||||||
}
|
// Vertical.
|
||||||
{ // Vertical.
|
matrix = new ByteMatrix(1, 6);
|
||||||
ByteMatrix matrix = new ByteMatrix(1, 6);
|
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(0, 1, 0);
|
matrix.set(0, 1, 0);
|
||||||
matrix.set(0, 2, 0);
|
matrix.set(0, 2, 0);
|
||||||
|
@ -60,33 +56,25 @@ public final class MaskUtilTestCase extends Assert {
|
||||||
matrix.set(0, 5, 0);
|
matrix.set(0, 5, 0);
|
||||||
assertEquals(4, MaskUtil.applyMaskPenaltyRule1(matrix));
|
assertEquals(4, MaskUtil.applyMaskPenaltyRule1(matrix));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyMaskPenaltyRule2() {
|
public void testApplyMaskPenaltyRule2() {
|
||||||
{
|
|
||||||
ByteMatrix matrix = new ByteMatrix(1, 1);
|
ByteMatrix matrix = new ByteMatrix(1, 1);
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
assertEquals(0, MaskUtil.applyMaskPenaltyRule2(matrix));
|
assertEquals(0, MaskUtil.applyMaskPenaltyRule2(matrix));
|
||||||
}
|
matrix = new ByteMatrix(2, 2);
|
||||||
{
|
|
||||||
ByteMatrix matrix = new ByteMatrix(2, 2);
|
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(1, 0, 0);
|
matrix.set(1, 0, 0);
|
||||||
matrix.set(0, 1, 0);
|
matrix.set(0, 1, 0);
|
||||||
matrix.set(1, 1, 1);
|
matrix.set(1, 1, 1);
|
||||||
assertEquals(0, MaskUtil.applyMaskPenaltyRule2(matrix));
|
assertEquals(0, MaskUtil.applyMaskPenaltyRule2(matrix));
|
||||||
}
|
matrix = new ByteMatrix(2, 2);
|
||||||
{
|
|
||||||
ByteMatrix matrix = new ByteMatrix(2, 2);
|
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(1, 0, 0);
|
matrix.set(1, 0, 0);
|
||||||
matrix.set(0, 1, 0);
|
matrix.set(0, 1, 0);
|
||||||
matrix.set(1, 1, 0);
|
matrix.set(1, 1, 0);
|
||||||
assertEquals(3, MaskUtil.applyMaskPenaltyRule2(matrix));
|
assertEquals(3, MaskUtil.applyMaskPenaltyRule2(matrix));
|
||||||
}
|
matrix = new ByteMatrix(3, 3);
|
||||||
{
|
|
||||||
ByteMatrix matrix = new ByteMatrix(3, 3);
|
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(1, 0, 0);
|
matrix.set(1, 0, 0);
|
||||||
matrix.set(2, 0, 0);
|
matrix.set(2, 0, 0);
|
||||||
|
@ -99,11 +87,9 @@ public final class MaskUtilTestCase extends Assert {
|
||||||
// Four instances of 2x2 blocks.
|
// Four instances of 2x2 blocks.
|
||||||
assertEquals(3 * 4, MaskUtil.applyMaskPenaltyRule2(matrix));
|
assertEquals(3 * 4, MaskUtil.applyMaskPenaltyRule2(matrix));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyMaskPenaltyRule3() {
|
public void testApplyMaskPenaltyRule3() {
|
||||||
{
|
|
||||||
// Horizontal 00001011101.
|
// Horizontal 00001011101.
|
||||||
ByteMatrix matrix = new ByteMatrix(11, 1);
|
ByteMatrix matrix = new ByteMatrix(11, 1);
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
|
@ -118,10 +104,8 @@ public final class MaskUtilTestCase extends Assert {
|
||||||
matrix.set(9, 0, 0);
|
matrix.set(9, 0, 0);
|
||||||
matrix.set(10, 0, 1);
|
matrix.set(10, 0, 1);
|
||||||
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
||||||
}
|
|
||||||
{
|
|
||||||
// Horizontal 10111010000.
|
// Horizontal 10111010000.
|
||||||
ByteMatrix matrix = new ByteMatrix(11, 1);
|
matrix = new ByteMatrix(11, 1);
|
||||||
matrix.set(0, 0, 1);
|
matrix.set(0, 0, 1);
|
||||||
matrix.set(1, 0, 0);
|
matrix.set(1, 0, 0);
|
||||||
matrix.set(2, 0, 1);
|
matrix.set(2, 0, 1);
|
||||||
|
@ -134,10 +118,8 @@ public final class MaskUtilTestCase extends Assert {
|
||||||
matrix.set(9, 0, 0);
|
matrix.set(9, 0, 0);
|
||||||
matrix.set(10, 0, 0);
|
matrix.set(10, 0, 0);
|
||||||
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
||||||
}
|
|
||||||
{
|
|
||||||
// Vertical 00001011101.
|
// Vertical 00001011101.
|
||||||
ByteMatrix matrix = new ByteMatrix(1, 11);
|
matrix = new ByteMatrix(1, 11);
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(0, 1, 0);
|
matrix.set(0, 1, 0);
|
||||||
matrix.set(0, 2, 0);
|
matrix.set(0, 2, 0);
|
||||||
|
@ -150,10 +132,8 @@ public final class MaskUtilTestCase extends Assert {
|
||||||
matrix.set(0, 9, 0);
|
matrix.set(0, 9, 0);
|
||||||
matrix.set(0, 10, 1);
|
matrix.set(0, 10, 1);
|
||||||
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
||||||
}
|
|
||||||
{
|
|
||||||
// Vertical 10111010000.
|
// Vertical 10111010000.
|
||||||
ByteMatrix matrix = new ByteMatrix(1, 11);
|
matrix = new ByteMatrix(1, 11);
|
||||||
matrix.set(0, 0, 1);
|
matrix.set(0, 0, 1);
|
||||||
matrix.set(0, 1, 0);
|
matrix.set(0, 1, 0);
|
||||||
matrix.set(0, 2, 1);
|
matrix.set(0, 2, 1);
|
||||||
|
@ -167,26 +147,20 @@ public final class MaskUtilTestCase extends Assert {
|
||||||
matrix.set(0, 10, 0);
|
matrix.set(0, 10, 0);
|
||||||
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyMaskPenaltyRule4() {
|
public void testApplyMaskPenaltyRule4() {
|
||||||
{
|
|
||||||
// Dark cell ratio = 0%
|
// Dark cell ratio = 0%
|
||||||
ByteMatrix matrix = new ByteMatrix(1, 1);
|
ByteMatrix matrix = new ByteMatrix(1, 1);
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
assertEquals(100, MaskUtil.applyMaskPenaltyRule4(matrix));
|
assertEquals(100, MaskUtil.applyMaskPenaltyRule4(matrix));
|
||||||
}
|
|
||||||
{
|
|
||||||
// Dark cell ratio = 5%
|
// Dark cell ratio = 5%
|
||||||
ByteMatrix matrix = new ByteMatrix(2, 1);
|
matrix = new ByteMatrix(2, 1);
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(0, 0, 1);
|
matrix.set(0, 0, 1);
|
||||||
assertEquals(0, MaskUtil.applyMaskPenaltyRule4(matrix));
|
assertEquals(0, MaskUtil.applyMaskPenaltyRule4(matrix));
|
||||||
}
|
|
||||||
{
|
|
||||||
// Dark cell ratio = 66.67%
|
// Dark cell ratio = 66.67%
|
||||||
ByteMatrix matrix = new ByteMatrix(6, 1);
|
matrix = new ByteMatrix(6, 1);
|
||||||
matrix.set(0, 0, 0);
|
matrix.set(0, 0, 0);
|
||||||
matrix.set(1, 0, 1);
|
matrix.set(1, 0, 1);
|
||||||
matrix.set(2, 0, 1);
|
matrix.set(2, 0, 1);
|
||||||
|
@ -195,14 +169,11 @@ public final class MaskUtilTestCase extends Assert {
|
||||||
matrix.set(5, 0, 0);
|
matrix.set(5, 0, 0);
|
||||||
assertEquals(30, MaskUtil.applyMaskPenaltyRule4(matrix));
|
assertEquals(30, MaskUtil.applyMaskPenaltyRule4(matrix));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean TestGetDataMaskBitInternal(int maskPattern,
|
private static boolean TestGetDataMaskBitInternal(int maskPattern, int[][] expected) {
|
||||||
int[][] expected) {
|
|
||||||
for (int x = 0; x < 6; ++x) {
|
for (int x = 0; x < 6; ++x) {
|
||||||
for (int y = 0; y < 6; ++y) {
|
for (int y = 0; y < 6; ++y) {
|
||||||
if ((expected[y][x] == 1) !=
|
if ((expected[y][x] == 1) != MaskUtil.getDataMaskBit(maskPattern, x, y)) {
|
||||||
MaskUtil.getDataMaskBit(maskPattern, x, y)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue