Saturday, March 8, 2014

Recent studies of the two-dimensional code, but do not know what this is what he's algorithm ZXing


I use ZXing on Android open source project based on online teaching made a two-dimensional picture of the code generation process, but when you call to BitMatrix, I do not understand what this is algorithm, the algorithm can tell me what what, I found his Source code

/ *
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* Distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* Limitations under the License.
* /

package com.google.zxing.common;

/ **
*

Represents a 2D matrix of bits. In function arguments below, and throughout the common
* Module, x is the column position, and y is the row position. The ordering is always x, y.
* The origin is at the top-left.


*
*

Internally the bits are represented in a 1-D array of 32-bit ints. However, each row begins
* With a new int. This is done intentionally so that we can copy out a row into a BitArray very
* Efficiently.


*
*

The ordering of bits is row-major. Within each int, the least significant bits are used first,
* Meaning they represent lower x values. This is compatible with BitArray's implementation.


*
* @ Author Sean Owen
* @ Author dswitkin@google.com (Daniel Switkin)
* /
public final class BitMatrix {

/ / TODO: Just like BitArray, these need to be public so ProGuard can inline them
.public final int width;
public final int height;
public final int rowSize;
public final int [] bits;

/ / A helper to construct a square matrix.
public BitMatrix (int dimension) {
this (dimension, dimension);
}

public BitMatrix (int width, int height) {
if (width <1 | | height <1) {
throw new IllegalArgumentException ("Both dimensions must be greater than 0");
}
this.width = width;
this.height = height;
int rowSize = width >> 5;
if ((width & 0x1f)! = 0) {
rowSize + +;
}
this.rowSize = rowSize;
bits = new int [rowSize * height];
}

/ **
*

Gets the requested bit, where true means black.


*
* @ Param x The horizontal component (ie which column)
* @ Param y The vertical component (ie which row)
* @ Return value of given bit in matrix
* /
public boolean get (int x, int y) {
int offset = y * rowSize + (x >> 5);
return ((bits [offset] >>> (x & 0x1f)) & 1) = 0;!
}

/ **
*

Sets the given bit to true.


*
* @ Param x The horizontal component (ie which column)
* @ Param y The vertical component (ie which row)
* /
public void set (int x, int y) {
int offset = y * rowSize + (x >> 5);
bits [offset] | = 1 << (x & 0x1f);
}

/ **
*

Flips the given bit.


*
* @ Param x The horizontal component (ie which column)
* @ Param y The vertical component (ie which row)
* /
public void flip (int x, int y) {
int offset = y * rowSize + (x >> 5);
bits [offset] ^ = 1 << (x & 0x1f);
}

/ **
* Clears all bits (sets to false).
* /
public void clear () {
int max = bits.length;
for (int i = 0; i bits [i] = 0;
}
}

/ **
*

Sets a square region of the bit matrix to true.


*
* @ Param left The horizontal position to begin at (inclusive)
* @ Param top The vertical position to begin at (inclusive)
* @ Param width The width of the region
* @ Param height The height of the region
* /
public void setRegion (int left, int top, int width, int height) {
if (top <0 | | left <0) {
throw new IllegalArgumentException ("Left and top must be nonnegative");
}
if (height <1 | | width <1) {
throw new IllegalArgumentException ("Height and width must be at least 1");
}
int right = left + width;
int bottom = top + height;
if (bottom> this.height | | right> this.width) {
throw new IllegalArgumentException ("The region must fit inside the matrix");
}
for (int y = top; y int offset = y * rowSize;
for (int x = left; x bits [offset + (x >> 5)] | = 1 << (x & 0x1f);
}
}
}

/ **
* A fast method to retrieve one row of data from the matrix as a BitArray.
*
* @ Param y The row to retrieve
* @ Param row An optional caller-allocated BitArray, will be allocated if null or too small
* @ Return The resulting BitArray - this reference should always be used even when passing
* Your own row
* /
BitArray getRow (int y, BitArray row) {
if (row == null | | row.getSize () row = new BitArray (width);
}
int offset = y * rowSize;
for (int x = 0; x row.setBulk (x * 32, bits [offset + x]);
}
return row;
}

/ **
* @ Return The width of the matrix
* /
public int getWidth () {
return width;
}

/ **
* @ Return The height of the matrix
* /
public int getHeight () {
return height;
}

/ **
* This method is for compatibility with older code. It's only logical to call if the matrix
* Is square, so I'm throwing if that's not the case.
*
* @ Return row / column dimension of this matrix
* /
public int getDimension () {
if (width! = height) {
throw new RuntimeException ("Can't call getDimension () on a non-square matrix");
}
return width;
}

public String toString () {
StringBuffer result = new StringBuffer (height * (width + 1));
for (int y = 0; y for (int x = 0; x result.append (? get (x, y) "X": "");
}
result.append ('\ n');
}
return result.toString ();
}

}
Hide details
Change log
r979 by dswitkin on Jun 23, 2009 Diff
Added a clear () method to BitMatrix.
Go to:
Project members, sign in to write a code review
Older revisions
r978 by dswitkin on Jun 22, 2009 Diff
r977 by dswitkin on Jun 22, 2009 Diff
r976 by srowen on Jun 22, 2009 Diff
All revisions of this file
File info
Size: 5851 bytes, 190 lines
View raw file
File properties
svn: executable
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
No need to study this stuff so well, will be used on the line, one generated images, the second is decoded picture.
In fact, according to some rule changes to information about, and then converted into a binary, black and white points arranged on the graph.
Reply:
Hello, thank you to answer me, but I still want to know. . . This code generates code which both pictures have decoded code?
Reply:
Dude, I recently also studying this, do not know what algorithm, you do not know of? ZXing This code is written too Niubi it!
Reply:
Dude, everyone share what I now get this, to get him to go inside the STM32 microcontroller, but as long as the generated image, without decoding, reading a few days, headache, no entry, please exchange it together. QQ1732158020
Reply:
tcmakebest brothers, have generated binary data encapsulated function? Can you give one.

No comments:

Post a Comment