remove obsolete files

git-svn-id: https://zxing.googlecode.com/svn/trunk@2559 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
bruceallenfb@gmail.com 2013-01-18 22:05:20 +00:00
parent 7616c4d06d
commit cc5706a72c
15 changed files with 0 additions and 1847 deletions

View file

@ -1,215 +0,0 @@
//
// In order to convert some functionality to Visual C#, the Java Language Conversion Assistant
// creates "support classes" that duplicate the original functionality.
//
// Support classes replicate the functionality of the original code, but in some cases they are
// substantially different architecturally. Although every effort is made to preserve the
// original architecture of the application in the converted project, the user should be aware that
// the primary goal of these support classes is to replicate functionality, and that at times
// the architecture of the resulting solution may differ somewhat.
//
using System;
/// <summary>
/// Contains conversion support elements such as classes, interfaces and static methods.
/// </summary>
public class SupportClass
{
/// <summary>
/// Converts an array of sbytes to an array of bytes
/// </summary>
/// <param name="sbyteArray">The array of sbytes to be converted</param>
/// <returns>The new array of bytes</returns>
public static byte[] ToByteArray(sbyte[] sbyteArray)
{
byte[] byteArray = null;
if (sbyteArray != null)
{
byteArray = new byte[sbyteArray.Length];
for(int index=0; index < sbyteArray.Length; index++)
byteArray[index] = (byte) sbyteArray[index];
}
return byteArray;
}
/// <summary>
/// Converts a string to an array of bytes
/// </summary>
/// <param name="sourceString">The string to be converted</param>
/// <returns>The new array of bytes</returns>
public static byte[] ToByteArray(System.String sourceString)
{
return System.Text.UTF8Encoding.UTF8.GetBytes(sourceString);
}
/// <summary>
/// Converts a array of object-type instances to a byte-type array.
/// </summary>
/// <param name="tempObjectArray">Array to convert.</param>
/// <returns>An array of byte type elements.</returns>
public static byte[] ToByteArray(System.Object[] tempObjectArray)
{
byte[] byteArray = null;
if (tempObjectArray != null)
{
byteArray = new byte[tempObjectArray.Length];
for (int index = 0; index < tempObjectArray.Length; index++)
byteArray[index] = (byte)tempObjectArray[index];
}
return byteArray;
}
/*******************************/
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
/// <param name="number">Number to operate on</param>
/// <param name="bits">Ammount of bits to shift</param>
/// <returns>The resulting number from the shift operation</returns>
public static int URShift(int number, int bits)
{
if ( number >= 0)
return number >> bits;
else
return (number >> bits) + (2 << ~bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
/// <param name="number">Number to operate on</param>
/// <param name="bits">Ammount of bits to shift</param>
/// <returns>The resulting number from the shift operation</returns>
public static int URShift(int number, long bits)
{
return URShift(number, (int)bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
/// <param name="number">Number to operate on</param>
/// <param name="bits">Ammount of bits to shift</param>
/// <returns>The resulting number from the shift operation</returns>
public static long URShift(long number, int bits)
{
if ( number >= 0)
return number >> bits;
else
return (number >> bits) + (2L << ~bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
/// <param name="number">Number to operate on</param>
/// <param name="bits">Ammount of bits to shift</param>
/// <returns>The resulting number from the shift operation</returns>
public static long URShift(long number, long bits)
{
return URShift(number, (int)bits);
}
/*******************************/
/// <summary>
/// This method returns the literal value received
/// </summary>
/// <param name="literal">The literal to return</param>
/// <returns>The received value</returns>
public static long Identity(long literal)
{
return literal;
}
/// <summary>
/// This method returns the literal value received
/// </summary>
/// <param name="literal">The literal to return</param>
/// <returns>The received value</returns>
public static ulong Identity(ulong literal)
{
return literal;
}
/// <summary>
/// This method returns the literal value received
/// </summary>
/// <param name="literal">The literal to return</param>
/// <returns>The received value</returns>
public static float Identity(float literal)
{
return literal;
}
/// <summary>
/// This method returns the literal value received
/// </summary>
/// <param name="literal">The literal to return</param>
/// <returns>The received value</returns>
public static double Identity(double literal)
{
return literal;
}
/*******************************/
/// <summary>
/// Copies an array of chars obtained from a String into a specified array of chars
/// </summary>
/// <param name="sourceString">The String to get the chars from</param>
/// <param name="sourceStart">Position of the String to start getting the chars</param>
/// <param name="sourceEnd">Position of the String to end getting the chars</param>
/// <param name="destinationArray">Array to return the chars</param>
/// <param name="destinationStart">Position of the destination array of chars to start storing the chars</param>
/// <returns>An array of chars</returns>
public static void GetCharsFromString(System.String sourceString, int sourceStart, int sourceEnd, char[] destinationArray, int destinationStart)
{
int sourceCounter;
int destinationCounter;
sourceCounter = sourceStart;
destinationCounter = destinationStart;
while (sourceCounter < sourceEnd)
{
destinationArray[destinationCounter] = (char) sourceString[sourceCounter];
sourceCounter++;
destinationCounter++;
}
}
/*******************************/
/// <summary>
/// Sets the capacity for the specified ArrayList
/// </summary>
/// <param name="vector">The ArrayList which capacity will be set</param>
/// <param name="newCapacity">The new capacity value</param>
public static void SetCapacity(System.Collections.ArrayList vector, int newCapacity)
{
if (newCapacity > vector.Count)
vector.AddRange(new Array[newCapacity-vector.Count]);
else if (newCapacity < vector.Count)
vector.RemoveRange(newCapacity, vector.Count - newCapacity);
vector.Capacity = newCapacity;
}
/*******************************/
/// <summary>
/// Receives a byte array and returns it transformed in an sbyte array
/// </summary>
/// <param name="byteArray">Byte array to process</param>
/// <returns>The transformed array</returns>
public static sbyte[] ToSByteArray(byte[] byteArray)
{
sbyte[] sbyteArray = null;
if (byteArray != null)
{
sbyteArray = new sbyte[byteArray.Length];
for(int index=0; index < byteArray.Length; index++)
sbyteArray[index] = (sbyte) byteArray[index];
}
return sbyteArray;
}
}

View file

@ -1,54 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
using ResultParser = com.google.zxing.client.result.ResultParser;
namespace com.google.zxing.client.result.optional
{
/// <summary> <p>Superclass for classes encapsulating results in the NDEF format.
/// See <a href="http://www.nfc-forum.org/specs/">http://www.nfc-forum.org/specs/</a>.</p>
///
/// <p>This code supports a limited subset of NDEF messages, ones that are plausibly
/// useful in 2D barcode formats. This generally includes 1-record messages, no chunking,
/// "short record" syntax, no ID field.</p>
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
abstract class AbstractNDEFResultParser:ResultParser
{
internal static System.String bytesToString(sbyte[] bytes, int offset, int length, System.String encoding)
{
try
{
System.String tempStr;
//UPGRADE_TODO: The differences in the Format of parameters for constructor 'java.lang.String.String' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
tempStr = System.Text.Encoding.GetEncoding(encoding).GetString(SupportClass.ToByteArray(bytes));
return new System.String(tempStr.ToCharArray(), offset, length);
}
catch (System.IO.IOException uee)
{
// This should only be used when 'encoding' is an encoding that must necessarily
// be supported by the JVM, like UTF-8
//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
throw new System.SystemException("Platform does not support required encoding: " + uee);
}
}
}
}

View file

@ -1,118 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
namespace com.google.zxing.client.result.optional
{
/// <summary> <p>Represents a record in an NDEF message. This class only supports certain types
/// of records -- namely, non-chunked records, where ID length is omitted, and only
/// "short records".</p>
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
sealed class NDEFRecord
{
internal bool MessageBegin
{
get
{
return (header & 0x80) != 0;
}
}
internal bool MessageEnd
{
get
{
return (header & 0x40) != 0;
}
}
internal System.String Type
{
get
{
return type;
}
}
internal sbyte[] Payload
{
get
{
return payload;
}
}
internal int TotalRecordLength
{
get
{
return totalRecordLength;
}
}
private const int SUPPORTED_HEADER_MASK = 0x3F; // 0 0 1 1 1 111 (the bottom 6 bits matter)
private const int SUPPORTED_HEADER = 0x11; // 0 0 0 1 0 001
public const System.String TEXT_WELL_KNOWN_TYPE = "T";
public const System.String URI_WELL_KNOWN_TYPE = "U";
public const System.String SMART_POSTER_WELL_KNOWN_TYPE = "Sp";
public const System.String ACTION_WELL_KNOWN_TYPE = "act";
//UPGRADE_NOTE: Final was removed from the declaration of 'header '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int header;
//UPGRADE_NOTE: Final was removed from the declaration of 'type '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private System.String type;
//UPGRADE_NOTE: Final was removed from the declaration of 'payload '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private sbyte[] payload;
//UPGRADE_NOTE: Final was removed from the declaration of 'totalRecordLength '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int totalRecordLength;
private NDEFRecord(int header, System.String type, sbyte[] payload, int totalRecordLength)
{
this.header = header;
this.type = type;
this.payload = payload;
this.totalRecordLength = totalRecordLength;
}
internal static NDEFRecord readRecord(sbyte[] bytes, int offset)
{
int header = bytes[offset] & 0xFF;
// Does header match what we support in the bits we care about?
// XOR figures out where we differ, and if any of those are in the mask, fail
if (((header ^ SUPPORTED_HEADER) & SUPPORTED_HEADER_MASK) != 0)
{
return null;
}
int typeLength = bytes[offset + 1] & 0xFF;
int payloadLength = bytes[offset + 2] & 0xFF;
System.String type = AbstractNDEFResultParser.bytesToString(bytes, offset + 3, typeLength, "US-ASCII");
sbyte[] payload = new sbyte[payloadLength];
Array.Copy(bytes, offset + 3 + typeLength, payload, 0, payloadLength);
return new NDEFRecord(header, type, payload, 3 + typeLength + payloadLength);
}
}
}

View file

@ -1,87 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
using ParsedResult = com.google.zxing.client.result.ParsedResult;
using ParsedResultType = com.google.zxing.client.result.ParsedResultType;
namespace com.google.zxing.client.result.optional
{
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
public sealed class NDEFSmartPosterParsedResult:ParsedResult
{
public System.String Title
{
get
{
return title;
}
}
public System.String URI
{
get
{
return uri;
}
}
public int Action
{
get
{
return action;
}
}
override public System.String DisplayResult
{
get
{
if (title == null)
{
return uri;
}
else
{
return title + '\n' + uri;
}
}
}
public const int ACTION_UNSPECIFIED = - 1;
public const int ACTION_DO = 0;
public const int ACTION_SAVE = 1;
public const int ACTION_OPEN = 2;
//UPGRADE_NOTE: Final was removed from the declaration of 'title '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private System.String title;
//UPGRADE_NOTE: Final was removed from the declaration of 'uri '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private System.String uri;
//UPGRADE_NOTE: Final was removed from the declaration of 'action '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int action;
internal NDEFSmartPosterParsedResult(int action, System.String uri, System.String title):base(ParsedResultType.NDEF_SMART_POSTER)
{
this.action = action;
this.uri = uri;
this.title = title;
}
}
}

View file

@ -1,96 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
using Result = com.google.zxing.Result;
namespace com.google.zxing.client.result.optional
{
/// <summary> <p>Recognizes an NDEF message that encodes information according to the
/// "Smart Poster Record Type Definition" specification.</p>
///
/// <p>This actually only supports some parts of the Smart Poster format: title,
/// URI, and action records. Icon records are not supported because the size
/// of these records are infeasibly large for barcodes. Size and type records
/// are not supported. Multiple titles are not supported.</p>
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
sealed class NDEFSmartPosterResultParser:AbstractNDEFResultParser
{
public static NDEFSmartPosterParsedResult parse(Result result)
{
sbyte[] bytes = result.RawBytes;
if (bytes == null)
{
return null;
}
NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0);
// Yes, header record starts and ends a message
if (headerRecord == null || !headerRecord.MessageBegin || !headerRecord.MessageEnd)
{
return null;
}
if (!headerRecord.Type.Equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE))
{
return null;
}
int offset = 0;
int recordNumber = 0;
NDEFRecord ndefRecord = null;
sbyte[] payload = headerRecord.Payload;
int action = NDEFSmartPosterParsedResult.ACTION_UNSPECIFIED;
System.String title = null;
System.String uri = null;
while (offset < payload.Length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null)
{
if (recordNumber == 0 && !ndefRecord.MessageBegin)
{
return null;
}
System.String type = ndefRecord.Type;
if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.Equals(type))
{
System.String[] languageText = NDEFTextResultParser.decodeTextPayload(ndefRecord.Payload);
title = languageText[1];
}
else if (NDEFRecord.URI_WELL_KNOWN_TYPE.Equals(type))
{
uri = NDEFURIResultParser.decodeURIPayload(ndefRecord.Payload);
}
else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.Equals(type))
{
action = ndefRecord.Payload[0];
}
recordNumber++;
offset += ndefRecord.TotalRecordLength;
}
if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.MessageEnd))
{
return null;
}
return new NDEFSmartPosterParsedResult(action, uri, title);
}
}
}

View file

@ -1,65 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
using Result = com.google.zxing.Result;
using TextParsedResult = com.google.zxing.client.result.TextParsedResult;
namespace com.google.zxing.client.result.optional
{
/// <summary> Recognizes an NDEF message that encodes text according to the
/// "Text Record Type Definition" specification.
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
sealed class NDEFTextResultParser:AbstractNDEFResultParser
{
public static TextParsedResult parse(Result result)
{
sbyte[] bytes = result.RawBytes;
if (bytes == null)
{
return null;
}
NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);
if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd)
{
return null;
}
if (!ndefRecord.Type.Equals(NDEFRecord.TEXT_WELL_KNOWN_TYPE))
{
return null;
}
System.String[] languageText = decodeTextPayload(ndefRecord.Payload);
return new TextParsedResult(languageText[0], languageText[1]);
}
internal static System.String[] decodeTextPayload(sbyte[] payload)
{
sbyte statusByte = payload[0];
bool isUTF16 = (statusByte & 0x80) != 0;
int languageLength = statusByte & 0x1F;
// language is always ASCII-encoded:
System.String language = bytesToString(payload, 1, languageLength, "US-ASCII");
System.String encoding = isUTF16?"UTF-16":"UTF-8";
System.String text = bytesToString(payload, 1 + languageLength, payload.Length - languageLength - 1, encoding);
return new System.String[]{language, text};
}
}
}

View file

@ -1,68 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
using Result = com.google.zxing.Result;
using URIParsedResult = com.google.zxing.client.result.URIParsedResult;
namespace com.google.zxing.client.result.optional
{
/// <summary> Recognizes an NDEF message that encodes a URI according to the
/// "URI Record Type Definition" specification.
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
sealed class NDEFURIResultParser:AbstractNDEFResultParser
{
//UPGRADE_NOTE: Final was removed from the declaration of 'URI_PREFIXES'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private static readonly System.String[] URI_PREFIXES = new System.String[]{null, "http://www.", "https://www.", "http://", "https://", "tel:", "mailto:", "ftp://anonymous:anonymous@", "ftp://ftp.", "ftps://", "sftp://", "smb://", "nfs://", "ftp://", "dav://", "news:", "telnet://", "imap:", "rtsp://", "urn:", "pop:", "sip:", "sips:", "tftp:", "btspp://", "btl2cap://", "btgoep://", "tcpobex://", "irdaobex://", "file://", "urn:epc:id:", "urn:epc:tag:", "urn:epc:pat:", "urn:epc:raw:", "urn:epc:", "urn:nfc:"};
public static URIParsedResult parse(Result result)
{
sbyte[] bytes = result.RawBytes;
if (bytes == null)
{
return null;
}
NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);
if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd)
{
return null;
}
if (!ndefRecord.Type.Equals(NDEFRecord.URI_WELL_KNOWN_TYPE))
{
return null;
}
System.String fullURI = decodeURIPayload(ndefRecord.Payload);
return new URIParsedResult(fullURI, null);
}
internal static System.String decodeURIPayload(sbyte[] payload)
{
int identifierCode = payload[0] & 0xFF;
System.String prefix = null;
if (identifierCode < URI_PREFIXES.Length)
{
prefix = URI_PREFIXES[identifierCode];
}
System.String restOfURI = bytesToString(payload, 1, payload.Length - 1, "UTF-8");
return prefix == null?restOfURI:prefix + restOfURI;
}
}
}

View file

@ -1,116 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
namespace com.google.zxing.common
{
/// <summary> This class implements an array of unsigned bytes.
///
/// </summary>
/// <author> dswitkin@google.com (Daniel Switkin)
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
public sealed class ByteArray
{
public bool Empty
{
get
{
return size_Renamed_Field == 0;
}
}
private const int INITIAL_SIZE = 32;
private sbyte[] bytes;
private int size_Renamed_Field;
public ByteArray()
{
bytes = null;
size_Renamed_Field = 0;
}
public ByteArray(int size)
{
bytes = new sbyte[size];
this.size_Renamed_Field = size;
}
public ByteArray(sbyte[] byteArray)
{
bytes = byteArray;
size_Renamed_Field = bytes.Length;
}
/// <summary> Access an unsigned byte at location index.</summary>
/// <param name="index">The index in the array to access.
/// </param>
/// <returns> The unsigned value of the byte as an int.
/// </returns>
public int at(int index)
{
return bytes[index] & 0xff;
}
public void set_Renamed(int index, int value_Renamed)
{
bytes[index] = (sbyte) value_Renamed;
}
public int size()
{
return size_Renamed_Field;
}
public void appendByte(int value_Renamed)
{
if (size_Renamed_Field == 0 || size_Renamed_Field >= bytes.Length)
{
int newSize = System.Math.Max(INITIAL_SIZE, size_Renamed_Field << 1);
reserve(newSize);
}
bytes[size_Renamed_Field] = (sbyte) value_Renamed;
size_Renamed_Field++;
}
public void reserve(int capacity)
{
if (bytes == null || bytes.Length < capacity)
{
sbyte[] newArray = new sbyte[capacity];
if (bytes != null)
{
Array.Copy(bytes, 0, newArray, 0, bytes.Length);
}
bytes = newArray;
}
}
// Copy count bytes from array source starting at offset.
public void set_Renamed(sbyte[] source, int offset, int count)
{
bytes = new sbyte[count];
size_Renamed_Field = count;
for (int x = 0; x < count; x++)
{
bytes[x] = source[offset + x];
}
}
}
}

View file

@ -1,176 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
using System.Drawing.Imaging;
using System.Drawing;
using System.Runtime.InteropServices;
namespace com.google.zxing.common
{
/// <summary> A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a
/// unsigned container, it's up to you to do byteValue & 0xff at each location.
///
/// JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned
/// -1, 0, and 1, I'm going to use less memory and go with bytes.
///
/// </summary>
/// <author> dswitkin@google.com (Daniel Switkin)
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
public sealed class ByteMatrix
{
public int Height
{
get
{
return height;
}
}
public int Width
{
get
{
return width;
}
}
public sbyte[][] Array
{
get
{
return bytes;
}
}
//UPGRADE_NOTE: Final was removed from the declaration of 'bytes '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private sbyte[][] bytes;
//UPGRADE_NOTE: Final was removed from the declaration of 'width '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int width;
//UPGRADE_NOTE: Final was removed from the declaration of 'height '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int height;
public ByteMatrix(int width, int height)
{
bytes = new sbyte[height][];
for (int i = 0; i < height; i++)
{
bytes[i] = new sbyte[width];
}
this.width = width;
this.height = height;
}
public sbyte get_Renamed(int x, int y)
{
return bytes[y][x];
}
public void set_Renamed(int x, int y, sbyte value_Renamed)
{
bytes[y][x] = value_Renamed;
}
public void set_Renamed(int x, int y, int value_Renamed)
{
bytes[y][x] = (sbyte) value_Renamed;
}
public void clear(sbyte value_Renamed)
{
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
bytes[y][x] = value_Renamed;
}
}
}
public override System.String ToString()
{
System.Text.StringBuilder result = new System.Text.StringBuilder(2 * width * height + 2);
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
switch (bytes[y][x])
{
case 0:
result.Append(" 0");
break;
case 1:
result.Append(" 1");
break;
default:
result.Append(" ");
break;
}
}
result.Append('\n');
}
return result.ToString();
}
/// <summary>
/// Converts this ByteMatrix to a black and white bitmap.
/// </summary>
/// <returns>A black and white bitmap converted from this ByteMatrix.</returns>
public Bitmap ToBitmap()
{
const byte BLACK = 0;
const byte WHITE = 255;
sbyte[][] array = this.Array;
int width = this.Width;
int height = this.Height;
//Here create the Bitmap to the known height, width and format
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
//Create a BitmapData and Lock all pixels to be written
BitmapData bmpData =
bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.WriteOnly, bmp.PixelFormat);
// If you wanted to support formats other than 8bpp, you should use Bitmap.GetPixelFormatSize(bmp.PixelFormat) to adjust the array size
byte[] pixels = new byte[bmpData.Stride * height];
int iPixelsCounter = 0;
for (int y = 0; y < height; y++)
{
int offset = y * width;
for (int x = 0; x < width; x++)
{
pixels[iPixelsCounter++] = array[y][x] == BLACK ? BLACK : WHITE;
}
iPixelsCounter += bmpData.Stride - width;
}
//Copy the data from the byte array into BitmapData.Scan0
System.Runtime.InteropServices.Marshal.Copy(pixels, 0, bmpData.Scan0, pixels.Length);
//Unlock the pixels
bmp.UnlockBits(bmpData);
//Return the bitmap
return bmp;
}
}
}

View file

@ -1,60 +0,0 @@
/*
* 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.
*/
using System;
namespace com.google.zxing.common
{
/// <summary> <p>This is basically a substitute for <code>java.util.Collections</code>, which is not
/// present in MIDP 2.0 / CLDC 1.1.</p>
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
public sealed class Collections
{
private Collections()
{
}
/// <summary> Sorts its argument (destructively) using insert sort; in the context of this package
/// insertion sort is simple and efficient given its relatively small inputs.
///
/// </summary>
/// <param name="vector">vector to sort
/// </param>
/// <param name="comparator">comparator to define sort ordering
/// </param>
public static void insertionSort(System.Collections.ArrayList vector, Comparator comparator)
{
int max = vector.Count;
for (int i = 1; i < max; i++)
{
System.Object value_Renamed = vector[i];
int j = i - 1;
System.Object valueB;
while (j >= 0 && comparator.compare((valueB = vector[j]), value_Renamed) > 0)
{
vector[j + 1] = valueB;
j--;
}
vector[j + 1] = value_Renamed;
}
}
}
}

View file

@ -1,28 +0,0 @@
/*
* 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.
*/
using System;
namespace com.google.zxing.common
{
/// <summary> This is merely a clone of <code>Comparator</code> since it is not available in
/// CLDC 1.1 / MIDP 2.0.
/// </summary>
public interface Comparator
{
int compare(System.Object o1, System.Object o2);
}
}

View file

@ -1,66 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
namespace com.google.zxing.common
{
/// <summary> Superclass of classes encapsulating types ECIs, according to "Extended Channel Interpretations"
/// 5.3 of ISO 18004.
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
public abstract class ECI
{
virtual public int Value
{
get
{
return value_Renamed;
}
}
//UPGRADE_NOTE: Final was removed from the declaration of 'value '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int value_Renamed;
internal ECI(int value_Renamed)
{
this.value_Renamed = value_Renamed;
}
/// <param name="value">ECI value
/// </param>
/// <returns> {@link ECI} representing ECI of given value, or null if it is legal but unsupported
/// </returns>
/// <throws> IllegalArgumentException if ECI value is invalid </throws>
public static ECI getECIByValue(int value_Renamed)
{
if (value_Renamed < 0 || value_Renamed > 999999)
{
throw new System.ArgumentException("Bad ECI value: " + value_Renamed);
}
if (value_Renamed < 900)
{
// Character set ECIs use 000000 - 000899
return CharacterSetECI.getCharacterSetECIByValue(value_Renamed);
}
return null;
}
}
}

View file

@ -1,174 +0,0 @@
/*
* 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.
*/
using System;
namespace com.google.zxing.common.reedsolomon
{
/// <summary> <p>This class contains utility methods for performing mathematical operations over
/// the Galois Field GF(256). Operations use a given primitive polynomial in calculations.</p>
///
/// <p>Throughout this package, elements of GF(256) are represented as an <code>int</code>
/// for convenience and speed (but at the cost of memory).
/// Only the bottom 8 bits are really used.</p>
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
public sealed class GF256
{
internal GF256Poly Zero
{
get
{
return zero;
}
}
internal GF256Poly One
{
get
{
return one;
}
}
//UPGRADE_NOTE: Final was removed from the declaration of 'QR_CODE_FIELD '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
public static readonly GF256 QR_CODE_FIELD = new GF256(0x011D); // x^8 + x^4 + x^3 + x^2 + 1
//UPGRADE_NOTE: Final was removed from the declaration of 'DATA_MATRIX_FIELD '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
public static readonly GF256 DATA_MATRIX_FIELD = new GF256(0x012D); // x^8 + x^5 + x^3 + x^2 + 1
//UPGRADE_NOTE: Final was removed from the declaration of 'expTable '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int[] expTable;
//UPGRADE_NOTE: Final was removed from the declaration of 'logTable '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int[] logTable;
//UPGRADE_NOTE: Final was removed from the declaration of 'zero '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private GF256Poly zero;
//UPGRADE_NOTE: Final was removed from the declaration of 'one '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private GF256Poly one;
/// <summary> Create a representation of GF(256) using the given primitive polynomial.
///
/// </summary>
/// <param name="primitive">irreducible polynomial whose coefficients are represented by
/// the bits of an int, where the least-significant bit represents the constant
/// coefficient
/// </param>
private GF256(int primitive)
{
expTable = new int[256];
logTable = new int[256];
int x = 1;
for (int i = 0; i < 256; i++)
{
expTable[i] = x;
x <<= 1; // x = x * 2; we're assuming the generator alpha is 2
if (x >= 0x100)
{
x ^= primitive;
}
}
for (int i = 0; i < 255; i++)
{
logTable[expTable[i]] = i;
}
// logTable[0] == 0 but this should never be used
zero = new GF256Poly(this, new int[]{0});
one = new GF256Poly(this, new int[]{1});
}
/// <returns> the monomial representing coefficient * x^degree
/// </returns>
internal GF256Poly buildMonomial(int degree, int coefficient)
{
if (degree < 0)
{
throw new System.ArgumentException();
}
if (coefficient == 0)
{
return zero;
}
int[] coefficients = new int[degree + 1];
coefficients[0] = coefficient;
return new GF256Poly(this, coefficients);
}
/// <summary> Implements both addition and subtraction -- they are the same in GF(256).
///
/// </summary>
/// <returns> sum/difference of a and b
/// </returns>
internal static int addOrSubtract(int a, int b)
{
return a ^ b;
}
/// <returns> 2 to the power of a in GF(256)
/// </returns>
internal int exp(int a)
{
return expTable[a];
}
/// <returns> base 2 log of a in GF(256)
/// </returns>
internal int log(int a)
{
if (a == 0)
{
throw new System.ArgumentException();
}
return logTable[a];
}
/// <returns> multiplicative inverse of a
/// </returns>
internal int inverse(int a)
{
if (a == 0)
{
throw new System.ArithmeticException();
}
return expTable[255 - logTable[a]];
}
/// <param name="a">
/// </param>
/// <param name="b">
/// </param>
/// <returns> product of a and b in GF(256)
/// </returns>
internal int multiply(int a, int b)
{
if (a == 0 || b == 0)
{
return 0;
}
if (a == 1)
{
return b;
}
if (b == 1)
{
return a;
}
return expTable[(logTable[a] + logTable[b]) % 255];
}
}
}

View file

@ -1,328 +0,0 @@
/*
* 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.
*/
using System;
namespace com.google.zxing.common.reedsolomon
{
/// <summary> <p>Represents a polynomial whose coefficients are elements of GF(256).
/// Instances of this class are immutable.</p>
///
/// <p>Much credit is due to William Rucklidge since portions of this code are an indirect
/// port of his C++ Reed-Solomon implementation.</p>
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
sealed class GF256Poly
{
internal int[] Coefficients
{
get
{
return coefficients;
}
}
/// <returns> degree of this polynomial
/// </returns>
internal int Degree
{
get
{
return coefficients.Length - 1;
}
}
/// <returns> true iff this polynomial is the monomial "0"
/// </returns>
internal bool Zero
{
get
{
return coefficients[0] == 0;
}
}
//UPGRADE_NOTE: Final was removed from the declaration of 'field '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private GF256 field;
//UPGRADE_NOTE: Final was removed from the declaration of 'coefficients '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
private int[] coefficients;
/// <param name="field">the {@link GF256} instance representing the field to use
/// to perform computations
/// </param>
/// <param name="coefficients">coefficients as ints representing elements of GF(256), arranged
/// from most significant (highest-power term) coefficient to least significant
/// </param>
/// <throws> IllegalArgumentException if argument is null or empty, </throws>
/// <summary> or if leading coefficient is 0 and this is not a
/// constant polynomial (that is, it is not the monomial "0")
/// </summary>
internal GF256Poly(GF256 field, int[] coefficients)
{
if (coefficients == null || coefficients.Length == 0)
{
throw new System.ArgumentException();
}
this.field = field;
int coefficientsLength = coefficients.Length;
if (coefficientsLength > 1 && coefficients[0] == 0)
{
// Leading term must be non-zero for anything except the constant polynomial "0"
int firstNonZero = 1;
while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0)
{
firstNonZero++;
}
if (firstNonZero == coefficientsLength)
{
this.coefficients = field.Zero.coefficients;
}
else
{
this.coefficients = new int[coefficientsLength - firstNonZero];
Array.Copy(coefficients, firstNonZero, this.coefficients, 0, this.coefficients.Length);
}
}
else
{
this.coefficients = coefficients;
}
}
/// <returns> coefficient of x^degree term in this polynomial
/// </returns>
internal int getCoefficient(int degree)
{
return coefficients[coefficients.Length - 1 - degree];
}
/// <returns> evaluation of this polynomial at a given point
/// </returns>
internal int evaluateAt(int a)
{
if (a == 0)
{
// Just return the x^0 coefficient
return getCoefficient(0);
}
int size = coefficients.Length;
if (a == 1)
{
// Just the sum of the coefficients
int result = 0;
for (int i = 0; i < size; i++)
{
result = GF256.addOrSubtract(result, coefficients[i]);
}
return result;
}
int result2 = coefficients[0];
for (int i = 1; i < size; i++)
{
result2 = GF256.addOrSubtract(field.multiply(a, result2), coefficients[i]);
}
return result2;
}
internal GF256Poly addOrSubtract(GF256Poly other)
{
if (!field.Equals(other.field))
{
throw new System.ArgumentException("GF256Polys do not have same GF256 field");
}
if (Zero)
{
return other;
}
if (other.Zero)
{
return this;
}
int[] smallerCoefficients = this.coefficients;
int[] largerCoefficients = other.coefficients;
if (smallerCoefficients.Length > largerCoefficients.Length)
{
int[] temp = smallerCoefficients;
smallerCoefficients = largerCoefficients;
largerCoefficients = temp;
}
int[] sumDiff = new int[largerCoefficients.Length];
int lengthDiff = largerCoefficients.Length - smallerCoefficients.Length;
// Copy high-order terms only found in higher-degree polynomial's coefficients
Array.Copy(largerCoefficients, 0, sumDiff, 0, lengthDiff);
for (int i = lengthDiff; i < largerCoefficients.Length; i++)
{
sumDiff[i] = GF256.addOrSubtract(smallerCoefficients[i - lengthDiff], largerCoefficients[i]);
}
return new GF256Poly(field, sumDiff);
}
internal GF256Poly multiply(GF256Poly other)
{
if (!field.Equals(other.field))
{
throw new System.ArgumentException("GF256Polys do not have same GF256 field");
}
if (Zero || other.Zero)
{
return field.Zero;
}
int[] aCoefficients = this.coefficients;
int aLength = aCoefficients.Length;
int[] bCoefficients = other.coefficients;
int bLength = bCoefficients.Length;
int[] product = new int[aLength + bLength - 1];
for (int i = 0; i < aLength; i++)
{
int aCoeff = aCoefficients[i];
for (int j = 0; j < bLength; j++)
{
product[i + j] = GF256.addOrSubtract(product[i + j], field.multiply(aCoeff, bCoefficients[j]));
}
}
return new GF256Poly(field, product);
}
internal GF256Poly multiply(int scalar)
{
if (scalar == 0)
{
return field.Zero;
}
if (scalar == 1)
{
return this;
}
int size = coefficients.Length;
int[] product = new int[size];
for (int i = 0; i < size; i++)
{
product[i] = field.multiply(coefficients[i], scalar);
}
return new GF256Poly(field, product);
}
internal GF256Poly multiplyByMonomial(int degree, int coefficient)
{
if (degree < 0)
{
throw new System.ArgumentException();
}
if (coefficient == 0)
{
return field.Zero;
}
int size = coefficients.Length;
int[] product = new int[size + degree];
for (int i = 0; i < size; i++)
{
product[i] = field.multiply(coefficients[i], coefficient);
}
return new GF256Poly(field, product);
}
internal GF256Poly[] divide(GF256Poly other)
{
if (!field.Equals(other.field))
{
throw new System.ArgumentException("GF256Polys do not have same GF256 field");
}
if (other.Zero)
{
throw new System.ArgumentException("Divide by 0");
}
GF256Poly quotient = field.Zero;
GF256Poly remainder = this;
int denominatorLeadingTerm = other.getCoefficient(other.Degree);
int inverseDenominatorLeadingTerm = field.inverse(denominatorLeadingTerm);
while (remainder.Degree >= other.Degree && !remainder.Zero)
{
int degreeDifference = remainder.Degree - other.Degree;
int scale = field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm);
GF256Poly term = other.multiplyByMonomial(degreeDifference, scale);
GF256Poly iterationQuotient = field.buildMonomial(degreeDifference, scale);
quotient = quotient.addOrSubtract(iterationQuotient);
remainder = remainder.addOrSubtract(term);
}
return new GF256Poly[]{quotient, remainder};
}
public override System.String ToString()
{
System.Text.StringBuilder result = new System.Text.StringBuilder(8 * Degree);
for (int degree = Degree; degree >= 0; degree--)
{
int coefficient = getCoefficient(degree);
if (coefficient != 0)
{
if (coefficient < 0)
{
result.Append(" - ");
coefficient = - coefficient;
}
else
{
if (result.Length > 0)
{
result.Append(" + ");
}
}
if (degree == 0 || coefficient != 1)
{
int alphaPower = field.log(coefficient);
if (alphaPower == 0)
{
result.Append('1');
}
else if (alphaPower == 1)
{
result.Append('a');
}
else
{
result.Append("a^");
result.Append(alphaPower);
}
}
if (degree != 0)
{
if (degree == 1)
{
result.Append('x');
}
else
{
result.Append("x^");
result.Append(degree);
}
}
}
}
return result.ToString();
}
}
}

View file

@ -1,196 +0,0 @@
/*
* Copyright 2008 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.
*/
using System;
namespace com.google.zxing.qrcode.encoder
{
/// <summary> JAVAPORT: This should be combined with BitArray in the future, although that class is not yet
/// dynamically resizeable. This implementation is reasonable but there is a lot of function calling
/// in loops I'd like to get rid of.
///
/// </summary>
/// <author> satorux@google.com (Satoru Takabayashi) - creator
/// </author>
/// <author> dswitkin@google.com (Daniel Switkin) - ported from C++
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
public sealed class BitVector
{
public sbyte[] Array
{
// Callers should not assume that array.length is the exact number of bytes needed to hold
// sizeInBits - it will typically be larger for efficiency.
get
{
return array;
}
}
private int sizeInBits;
private sbyte[] array;
// For efficiency, start out with some room to work.
private const int DEFAULT_SIZE_IN_BYTES = 32;
public BitVector()
{
sizeInBits = 0;
array = new sbyte[DEFAULT_SIZE_IN_BYTES];
}
// Return the bit value at "index".
public int at(int index)
{
if (index < 0 || index >= sizeInBits)
{
throw new System.ArgumentException("Bad index: " + index);
}
int value_Renamed = array[index >> 3] & 0xff;
return (value_Renamed >> (7 - (index & 0x7))) & 1;
}
// Return the number of bits in the bit vector.
public int size()
{
return sizeInBits;
}
// Return the number of bytes in the bit vector.
public int sizeInBytes()
{
return (sizeInBits + 7) >> 3;
}
// Append one bit to the bit vector.
public void appendBit(int bit)
{
if (!(bit == 0 || bit == 1))
{
throw new System.ArgumentException("Bad bit");
}
int numBitsInLastByte = sizeInBits & 0x7;
// We'll expand array if we don't have bits in the last byte.
if (numBitsInLastByte == 0)
{
appendByte(0);
sizeInBits -= 8;
}
// Modify the last byte.
array[sizeInBits >> 3] |= (sbyte) ((bit << (7 - numBitsInLastByte)));
++sizeInBits;
}
// Append "numBits" bits in "value" to the bit vector.
// REQUIRES: 0<= numBits <= 32.
//
// Examples:
// - appendBits(0x00, 1) adds 0.
// - appendBits(0x00, 4) adds 0000.
// - appendBits(0xff, 8) adds 11111111.
public void appendBits(int value_Renamed, int numBits)
{
if (numBits < 0 || numBits > 32)
{
throw new System.ArgumentException("Num bits must be between 0 and 32");
}
int numBitsLeft = numBits;
while (numBitsLeft > 0)
{
// Optimization for byte-oriented appending.
if ((sizeInBits & 0x7) == 0 && numBitsLeft >= 8)
{
int newByte = (value_Renamed >> (numBitsLeft - 8)) & 0xff;
appendByte(newByte);
numBitsLeft -= 8;
}
else
{
int bit = (value_Renamed >> (numBitsLeft - 1)) & 1;
appendBit(bit);
--numBitsLeft;
}
}
}
// Append "bits".
public void appendBitVector(BitVector bits)
{
int size = bits.size();
for (int i = 0; i < size; ++i)
{
appendBit(bits.at(i));
}
}
// Modify the bit vector by XOR'ing with "other"
public void xor(BitVector other)
{
if (sizeInBits != other.size())
{
throw new System.ArgumentException("BitVector sizes don't match");
}
int sizeInBytes = (sizeInBits + 7) >> 3;
for (int i = 0; i < sizeInBytes; ++i)
{
// The last byte could be incomplete (i.e. not have 8 bits in
// it) but there is no problem since 0 XOR 0 == 0.
array[i] ^= other.array[i];
}
}
// Return String like "01110111" for debugging.
public override System.String ToString()
{
System.Text.StringBuilder result = new System.Text.StringBuilder(sizeInBits);
for (int i = 0; i < sizeInBits; ++i)
{
if (at(i) == 0)
{
result.Append('0');
}
else if (at(i) == 1)
{
result.Append('1');
}
else
{
throw new System.ArgumentException("Byte isn't 0 or 1");
}
}
return result.ToString();
}
// Add a new byte to the end, possibly reallocating and doubling the size of the array if we've
// run out of room.
private void appendByte(int value_Renamed)
{
if ((sizeInBits >> 3) == array.Length)
{
sbyte[] newArray = new sbyte[(array.Length << 1)];
// Redivivus.in Java to c# Porting update
// 30/01/2010
// added namespace system
System.Array.Copy(array, 0, newArray, 0, array.Length);
array = newArray;
}
array[sizeInBits >> 3] = (sbyte) value_Renamed;
sizeInBits += 8;
}
}
}