diff options
author | Bo Xu <bo_xu@foxitsoftware.com> | 2015-01-09 17:27:21 -0800 |
---|---|---|
committer | Bo Xu <bo_xu@foxitsoftware.com> | 2015-01-09 17:27:21 -0800 |
commit | a902979f7c6a39fbdd8e9fc1b2ce00553b655eeb (patch) | |
tree | 854a51dbf1577ee8493db769ba7c8ab07cc72140 /xfa/src/fxbarcode/common | |
parent | 5f21e9ddd181fc344f8d6070351858f98a25547e (diff) | |
download | pdfium-a902979f7c6a39fbdd8e9fc1b2ce00553b655eeb.tar.xz |
Organize barcode codes into modules.
Previously all the files in barcode are lumped together.
The naming of some files are inconsistent,
leading to difficult understanding of the structure.
Now files are grouped based on different barcode type like in zxing.
This also matches what it looks like in other xfa folders.
The file names in each folder could be further modified to be consistent.
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/842043002
Diffstat (limited to 'xfa/src/fxbarcode/common')
30 files changed, 2438 insertions, 0 deletions
diff --git a/xfa/src/fxbarcode/common/BC_CommonBitArray.cpp b/xfa/src/fxbarcode/common/BC_CommonBitArray.cpp new file mode 100644 index 0000000000..6263affbe8 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonBitArray.cpp @@ -0,0 +1,124 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "BC_CommonBitArray.h"
+CBC_CommonBitArray::CBC_CommonBitArray(CBC_CommonBitArray* array)
+{
+ m_size = array->GetSize();
+ m_bits.Copy(array->GetBits());
+}
+CBC_CommonBitArray::CBC_CommonBitArray()
+{
+ m_bits.SetSize(1);
+ m_size = 0;
+}
+CBC_CommonBitArray::CBC_CommonBitArray(FX_INT32 size)
+{
+ m_bits.SetSize((size + 31) >> 5);
+ m_size = size;
+}
+CBC_CommonBitArray::~CBC_CommonBitArray()
+{
+ m_size = 0;
+}
+FX_INT32 CBC_CommonBitArray::GetSize()
+{
+ return m_size;
+}
+CFX_Int32Array& CBC_CommonBitArray::GetBits()
+{
+ return m_bits;
+}
+FX_INT32 CBC_CommonBitArray::GetSizeInBytes()
+{
+ return (m_size + 7) >> 3;
+}
+FX_BOOL CBC_CommonBitArray::Get(FX_INT32 i)
+{
+ return (m_bits[i >> 5] & (1 << (i & 0x1f))) != 0;
+}
+void CBC_CommonBitArray::Set(FX_INT32 i)
+{
+ m_bits[i >> 5] |= 1 << (i & 0x1F);
+}
+void CBC_CommonBitArray::Flip(FX_INT32 i)
+{
+ m_bits[i >> 5] ^= 1 << (i & 0x1F);
+}
+void CBC_CommonBitArray::SetBulk(FX_INT32 i, FX_INT32 newBits)
+{
+ m_bits[i >> 5] = newBits;
+}
+void CBC_CommonBitArray::Clear()
+{
+ FXSYS_memset32(&m_bits[0], 0x00, m_bits.GetSize() * sizeof(FX_INT32));
+}
+FX_BOOL CBC_CommonBitArray::IsRange(FX_INT32 start, FX_INT32 end, FX_BOOL value, FX_INT32 &e)
+{
+ if (end < start) {
+ e = BCExceptionEndLessThanStart;
+ return FALSE;
+ }
+ if (end == start) {
+ return TRUE;
+ }
+ end--;
+ FX_INT32 firstInt = start >> 5;
+ FX_INT32 lastInt = end >> 5;
+ FX_INT32 i;
+ for (i = firstInt; i <= lastInt; i++) {
+ FX_INT32 firstBit = i > firstInt ? 0 : start & 0x1F;
+ FX_INT32 lastBit = i < lastInt ? 31 : end & 0x1F;
+ FX_INT32 mask;
+ if (firstBit == 0 && lastBit == 31) {
+ mask = -1;
+ } else {
+ mask = 0;
+ for (FX_INT32 j = firstBit; j <= lastBit; j++) {
+ mask |= 1 << j;
+ }
+ }
+ if ((m_bits[i] & mask) != (value ? mask : 0)) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+FX_INT32* CBC_CommonBitArray::GetBitArray()
+{
+ return &m_bits[0];
+}
+void CBC_CommonBitArray::Reverse()
+{
+ FX_INT32* newBits = FX_Alloc(FX_INT32, m_bits.GetSize());
+ FXSYS_memset32(newBits, 0x00, m_bits.GetSize() * sizeof(FX_INT32));
+ FX_INT32 size = m_size;
+ FX_INT32 i;
+ for (i = 0; i < size; i++) {
+ if (Get(size - i - 1)) {
+ newBits[i >> 5] |= 1 << (i & 0x1F);
+ }
+ }
+ FXSYS_memcpy32(&m_bits[0], newBits, m_bits.GetSize() * sizeof(FX_INT32));
+ FX_Free(newBits);
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonBitArray.h b/xfa/src/fxbarcode/common/BC_CommonBitArray.h new file mode 100644 index 0000000000..484d87d5a7 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonBitArray.h @@ -0,0 +1,32 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONBITARRAY_H_
+#define _BC_COMMONBITARRAY_H_
+class CBC_CommonBitArray;
+class CBC_CommonBitArray : public CFX_Object
+{
+public:
+ CBC_CommonBitArray(CBC_CommonBitArray* array);
+ CBC_CommonBitArray(FX_INT32 size);
+ CBC_CommonBitArray();
+ virtual ~CBC_CommonBitArray();
+ FX_INT32 GetSize();
+ CFX_Int32Array& GetBits();
+ FX_INT32 GetSizeInBytes();
+ FX_BOOL Get(FX_INT32 i);
+ void Set(FX_INT32 i);
+ void Flip(FX_INT32 i);
+ void SetBulk(FX_INT32 i, FX_INT32 newBits);
+ FX_BOOL IsRange(FX_INT32 start, FX_INT32 end, FX_BOOL value, FX_INT32 &e);
+ FX_INT32 *GetBitArray();
+ void Reverse();
+ void Clear();
+private:
+ FX_INT32 m_size;
+ CFX_Int32Array m_bits;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp b/xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp new file mode 100644 index 0000000000..df24d1dabb --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonBitMatrix.cpp @@ -0,0 +1,161 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "BC_CommonBitArray.h"
+#include "BC_CommonBitMatrix.h"
+CBC_CommonBitMatrix::CBC_CommonBitMatrix()
+{
+ m_width = 0;
+ m_height = 0;
+ m_rowSize = 0;
+ m_bits = NULL;
+}
+void CBC_CommonBitMatrix::Init(FX_INT32 dimension)
+{
+ m_width = dimension;
+ m_height = dimension;
+ FX_INT32 rowSize = (m_height + 31) >> 5;
+ m_rowSize = rowSize;
+ m_bits = FX_Alloc(FX_INT32, m_rowSize * m_height);
+ FXSYS_memset32(m_bits, 0, m_rowSize * m_height * sizeof(FX_INT32));
+}
+void CBC_CommonBitMatrix::Init(FX_INT32 width, FX_INT32 height)
+{
+ m_width = width;
+ m_height = height;
+ FX_INT32 rowSize = (width + 31) >> 5;
+ m_rowSize = rowSize;
+ m_bits = FX_Alloc(FX_INT32, m_rowSize * m_height);
+ FXSYS_memset32(m_bits, 0, m_rowSize * m_height * sizeof(FX_INT32));
+}
+CBC_CommonBitMatrix::~CBC_CommonBitMatrix()
+{
+ if (m_bits != NULL) {
+ FX_Free(m_bits);
+ }
+ m_bits = NULL;
+ m_height = m_width = m_rowSize = 0;
+}
+FX_BOOL CBC_CommonBitMatrix::Get(FX_INT32 x, FX_INT32 y)
+{
+ FX_INT32 offset = y * m_rowSize + (x >> 5);
+ if (offset >= m_rowSize * m_height || offset < 0) {
+ return false;
+ }
+ return ((((FX_DWORD)m_bits[offset]) >> (x & 0x1f)) & 1) != 0;
+}
+FX_INT32* CBC_CommonBitMatrix::GetBits()
+{
+ return m_bits;
+}
+void CBC_CommonBitMatrix::Set(FX_INT32 x, FX_INT32 y)
+{
+ FX_INT32 offset = y * m_rowSize + (x >> 5);
+ if (offset >= m_rowSize * m_height || offset < 0) {
+ return;
+ }
+ m_bits[offset] |= 1 << (x & 0x1f);
+}
+void CBC_CommonBitMatrix::Flip(FX_INT32 x, FX_INT32 y)
+{
+ FX_INT32 offset = y * m_rowSize + (x >> 5);
+ m_bits[offset] ^= 1 << (x & 0x1f);
+}
+void CBC_CommonBitMatrix::Clear()
+{
+ FXSYS_memset32(m_bits, 0, m_rowSize * m_height * sizeof(FX_INT32));
+}
+void CBC_CommonBitMatrix::SetRegion(FX_INT32 left, FX_INT32 top, FX_INT32 width, FX_INT32 height, FX_INT32 &e)
+{
+ if (top < 0 || left < 0) {
+ e = BCExceptionLeftAndTopMustBeNonnegative;
+ return;
+ }
+ if (height < 1 || width < 1) {
+ e = BCExceptionHeightAndWidthMustBeAtLeast1;
+ return;
+ }
+ FX_INT32 right = left + width;
+ FX_INT32 bottom = top + height;
+ if (m_height < bottom || m_width < right) {
+ e = BCExceptionRegionMustFitInsideMatrix;
+ return;
+ }
+ FX_INT32 y;
+ for (y = top; y < bottom; y++) {
+ FX_INT32 offset = y * m_rowSize;
+ FX_INT32 x;
+ for (x = left; x < right; x++) {
+ m_bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
+ }
+ }
+}
+CBC_CommonBitArray* CBC_CommonBitMatrix::GetRow(FX_INT32 y, CBC_CommonBitArray* row)
+{
+ CBC_CommonBitArray* rowArray = NULL;
+ if (row == NULL || row->GetSize() < m_width) {
+ rowArray = FX_NEW CBC_CommonBitArray(m_width);
+ } else {
+ rowArray = FX_NEW CBC_CommonBitArray(row);
+ }
+ FX_INT32 offset = y * m_rowSize;
+ FX_INT32 x;
+ for (x = 0; x < m_rowSize; x++) {
+ rowArray->SetBulk(x << 5, m_bits[offset + x]);
+ }
+ return rowArray;
+}
+void CBC_CommonBitMatrix::SetRow(FX_INT32 y, CBC_CommonBitArray* row)
+{
+ FX_INT32 l = y * m_rowSize;
+ for (FX_INT32 i = 0; i < m_rowSize; i++) {
+ m_bits[l] = row->GetBitArray()[i];
+ l++;
+ }
+}
+void CBC_CommonBitMatrix::SetCol(FX_INT32 y, CBC_CommonBitArray* col)
+{
+ for (FX_INT32 i = 0; i < col->GetBits().GetSize(); i++) {
+ m_bits[i * m_rowSize + y] = col->GetBitArray()[i];
+ }
+}
+FX_INT32 CBC_CommonBitMatrix::GetWidth()
+{
+ return m_width;
+}
+FX_INT32 CBC_CommonBitMatrix::GetHeight()
+{
+ return m_height;
+}
+FX_INT32 CBC_CommonBitMatrix::GetRowSize()
+{
+ return m_rowSize;
+}
+FX_INT32 CBC_CommonBitMatrix::GetDimension(FX_INT32 &e)
+{
+ if (m_width != m_height) {
+ e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix;
+ return 0;
+ }
+ return m_width;
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonBitMatrix.h b/xfa/src/fxbarcode/common/BC_CommonBitMatrix.h new file mode 100644 index 0000000000..f69d7a0e33 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonBitMatrix.h @@ -0,0 +1,38 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONBITMATRIX_H_
+#define _BC_COMMONBITMATRIX_H_
+class CBC_CommonBitArray;
+class CBC_CommonBitMatrix;
+class CBC_CommonBitMatrix : public CFX_Object
+{
+public:
+ CBC_CommonBitMatrix();
+ virtual ~CBC_CommonBitMatrix();
+ FX_BOOL Get(FX_INT32 x, FX_INT32 y);
+ void Set(FX_INT32 x, FX_INT32 y);
+ void Flip(FX_INT32 x, FX_INT32 y);
+ void Clear();
+ void SetRegion(FX_INT32 left, FX_INT32 top, FX_INT32 width, FX_INT32 height, FX_INT32 &e);
+ CBC_CommonBitArray* GetRow(FX_INT32 y, CBC_CommonBitArray* row);
+ void SetRow(FX_INT32 y, CBC_CommonBitArray* row);
+ CBC_CommonBitArray* GetCol(FX_INT32 y, CBC_CommonBitArray* row);
+ void SetCol(FX_INT32 y, CBC_CommonBitArray* col);
+ FX_INT32 GetWidth();
+ FX_INT32 GetHeight();
+ FX_INT32 GetRowSize();
+ FX_INT32 GetDimension(FX_INT32 &e);
+ virtual void Init(FX_INT32 dimension);
+ virtual void Init(FX_INT32 width, FX_INT32 height);
+ FX_INT32* GetBits();
+private:
+ FX_INT32 m_width;
+ FX_INT32 m_height;
+ FX_INT32 m_rowSize;
+ FX_INT32* m_bits;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_CommonBitSource.cpp b/xfa/src/fxbarcode/common/BC_CommonBitSource.cpp new file mode 100644 index 0000000000..b71848a60c --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonBitSource.cpp @@ -0,0 +1,76 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "BC_CommonBitSource.h"
+CBC_CommonBitSource::CBC_CommonBitSource(CFX_ByteArray* bytes)
+{
+ m_bytes.Copy((*bytes));
+ m_bitOffset = 0;
+ m_byteOffset = 0;
+}
+CBC_CommonBitSource::~CBC_CommonBitSource()
+{
+}
+FX_INT32 CBC_CommonBitSource::ReadBits(FX_INT32 numBits, FX_INT32 &e)
+{
+ if (numBits < 1 || numBits > 32) {
+ e = BCExceptionIllegalArgument;
+ return 0;
+ }
+ FX_INT32 result = 0;
+ if (m_bitOffset > 0) {
+ FX_INT32 bitsLeft = 8 - m_bitOffset;
+ FX_INT32 toRead = numBits < bitsLeft ? numBits : bitsLeft;
+ FX_INT32 bitsToNotRead = bitsLeft - toRead;
+ FX_INT32 mask = (0xff >> (8 - toRead)) << bitsToNotRead;
+ result = (m_bytes[m_byteOffset] & mask) >> bitsToNotRead;
+ numBits -= toRead;
+ m_bitOffset += toRead;
+ if (m_bitOffset == 8) {
+ m_bitOffset = 0;
+ m_byteOffset++;
+ }
+ }
+ if (numBits > 0) {
+ while(numBits >= 8) {
+ result = (result << 8) | (m_bytes[m_byteOffset] & 0xff);
+ m_byteOffset++;
+ numBits -= 8;
+ }
+ if (numBits > 0) {
+ FX_INT32 bitsToNotRead = 8 - numBits;
+ FX_INT32 mask = (0xff >> bitsToNotRead) << bitsToNotRead;
+ result = (result << numBits) | ((m_bytes[m_byteOffset] & mask) >> bitsToNotRead);
+ m_bitOffset += numBits;
+ }
+ }
+ return result;
+}
+FX_INT32 CBC_CommonBitSource::Available()
+{
+ return 8 * (m_bytes.GetSize() - m_byteOffset) - m_bitOffset;
+}
+FX_INT32 CBC_CommonBitSource::getByteOffset()
+{
+ return m_byteOffset;
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonBitSource.h b/xfa/src/fxbarcode/common/BC_CommonBitSource.h new file mode 100644 index 0000000000..53891cf671 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonBitSource.h @@ -0,0 +1,23 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONBITSOURCE_H_
+#define _BC_COMMONBITSOURCE_H_
+class CBC_CommonBitSource;
+class CBC_CommonBitSource : public CFX_Object
+{
+public:
+ CBC_CommonBitSource(CFX_ByteArray *bytes);
+ virtual ~CBC_CommonBitSource();
+ FX_INT32 ReadBits(FX_INT32 numBits, FX_INT32 &e);
+ FX_INT32 Available();
+ FX_INT32 getByteOffset();
+private:
+ CFX_ByteArray m_bytes;
+ FX_INT32 m_byteOffset;
+ FX_INT32 m_bitOffset;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp b/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp new file mode 100644 index 0000000000..99e97d38d8 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonByteArray.cpp @@ -0,0 +1,114 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "BC_CommonByteArray.h"
+CBC_CommonByteArray::CBC_CommonByteArray()
+{
+ m_bytes = NULL;
+ m_size = 0;
+ m_index = 0;
+}
+CBC_CommonByteArray::CBC_CommonByteArray(FX_INT32 size)
+{
+ m_size = size;
+ m_bytes = FX_Alloc(FX_BYTE, size);
+ FXSYS_memset32(m_bytes, 0, size);
+ m_index = 0;
+}
+CBC_CommonByteArray::CBC_CommonByteArray(FX_BYTE* byteArray, FX_INT32 size)
+{
+ m_size = size;
+ m_bytes = FX_Alloc(FX_BYTE, size);
+ FXSYS_memcpy32(m_bytes, byteArray, size);
+ m_index = size;
+}
+CBC_CommonByteArray::~CBC_CommonByteArray()
+{
+ if ( m_bytes != NULL) {
+ FX_Free( m_bytes );
+ m_bytes = NULL;
+ }
+ m_index = 0;
+ m_size = 0;
+}
+FX_INT32 CBC_CommonByteArray::At(FX_INT32 index)
+{
+ return m_bytes[index] & 0xff;
+}
+void CBC_CommonByteArray::Set(FX_INT32 index, FX_INT32 value)
+{
+ m_bytes[index] = (FX_BYTE) value;
+}
+FX_INT32 CBC_CommonByteArray::Size()
+{
+ return m_size;
+}
+FX_BOOL CBC_CommonByteArray::IsEmpty()
+{
+ return m_size == 0;
+}
+void CBC_CommonByteArray::AppendByte(FX_INT32 value)
+{
+ if (m_size == 0 || m_index >= m_size) {
+ FX_INT32 newSize = FX_MAX(32, m_size << 1);
+ Reserve(newSize);
+ }
+ m_bytes[m_index] = (FX_BYTE)value;
+ m_index++;
+}
+void CBC_CommonByteArray::Reserve(FX_INT32 capacity)
+{
+ if (m_bytes == NULL || m_size < capacity) {
+ FX_BYTE *newArray = FX_Alloc(FX_BYTE, capacity);
+ FXSYS_memset32(newArray, 0, capacity);
+ if (m_bytes != NULL) {
+ FXSYS_memcpy32(newArray, m_bytes, m_size);
+ FX_Free( m_bytes );
+ }
+ m_bytes = newArray;
+ m_size = capacity;
+ }
+}
+void CBC_CommonByteArray::Set(FX_BYTE* source, FX_INT32 offset, FX_INT32 count)
+{
+ if (m_bytes != NULL) {
+ FX_Free( m_bytes );
+ }
+ m_bytes = FX_Alloc(FX_BYTE, count);
+ m_size = count;
+ FXSYS_memcpy32(m_bytes, source + offset, count);
+ m_index = count;
+}
+void CBC_CommonByteArray::Set(CFX_ByteArray* source, FX_INT32 offset, FX_INT32 count)
+{
+ if (m_bytes != NULL) {
+ FX_Free( m_bytes );
+ }
+ m_bytes = FX_Alloc(FX_BYTE, count);
+ m_size = count;
+ FX_INT32 i;
+ for(i = 0; i < count; i++) {
+ m_bytes[i] = source->operator [](i + offset);
+ }
+ m_index = m_size;
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonByteArray.h b/xfa/src/fxbarcode/common/BC_CommonByteArray.h new file mode 100644 index 0000000000..fe0a67ffd1 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonByteArray.h @@ -0,0 +1,30 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONBYTEARRAY_H_
+#define _BC_COMMONBYTEARRAY_H_
+class CBC_CommonByteArray;
+class CBC_CommonByteArray : public CFX_Object
+{
+private:
+ FX_INT32 m_size;
+ FX_INT32 m_index;
+ FX_BYTE* m_bytes;
+public:
+ CBC_CommonByteArray();
+ CBC_CommonByteArray(FX_INT32 size);
+ CBC_CommonByteArray(FX_BYTE* byteArray, FX_INT32 size);
+ virtual ~CBC_CommonByteArray();
+ FX_INT32 At(FX_INT32 index);
+ void Set(FX_INT32 index, FX_INT32 value);
+ FX_INT32 Size();
+ FX_BOOL IsEmpty();
+ void AppendByte(FX_INT32 value);
+ void Reserve(FX_INT32 capacity);
+ void Set(FX_BYTE* source, FX_INT32 offset, FX_INT32 count);
+ void Set(CFX_ByteArray* source, FX_INT32 offset, FX_INT32 count);
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp b/xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp new file mode 100644 index 0000000000..27c8615bf9 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonByteMatrix.cpp @@ -0,0 +1,76 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "BC_CommonByteMatrix.h"
+CBC_CommonByteMatrix::CBC_CommonByteMatrix(FX_INT32 width, FX_INT32 height)
+{
+ m_height = height;
+ m_width = width;
+ m_bytes = NULL;
+}
+void CBC_CommonByteMatrix::Init()
+{
+ m_bytes = FX_Alloc(FX_BYTE, m_height * m_width);
+ FXSYS_memset8(m_bytes, 0xff, m_height * m_width);
+}
+CBC_CommonByteMatrix::~CBC_CommonByteMatrix()
+{
+ if(m_bytes != NULL) {
+ FX_Free(m_bytes);
+ m_bytes = NULL;
+ }
+}
+FX_INT32 CBC_CommonByteMatrix::GetHeight()
+{
+ return m_height;
+}
+FX_INT32 CBC_CommonByteMatrix::GetWidth()
+{
+ return m_width;
+}
+FX_BYTE CBC_CommonByteMatrix::Get(FX_INT32 x, FX_INT32 y)
+{
+ return m_bytes[y * m_width + x];
+}
+void CBC_CommonByteMatrix::Set(FX_INT32 x, FX_INT32 y, FX_INT32 value)
+{
+ m_bytes[y * m_width + x] = (FX_BYTE)value;
+}
+void CBC_CommonByteMatrix::Set(FX_INT32 x, FX_INT32 y, FX_BYTE value)
+{
+ m_bytes[y * m_width + x] = value;
+}
+void CBC_CommonByteMatrix::clear(FX_BYTE value)
+{
+ FX_INT32 y;
+ for(y = 0; y < m_height; y++) {
+ FX_INT32 x;
+ for(x = 0; x < m_width; x++) {
+ m_bytes[y * m_width + x] = value;
+ }
+ }
+}
+FX_BYTE* CBC_CommonByteMatrix::GetArray()
+{
+ return m_bytes;
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonByteMatrix.h b/xfa/src/fxbarcode/common/BC_CommonByteMatrix.h new file mode 100644 index 0000000000..3d831d1911 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonByteMatrix.h @@ -0,0 +1,29 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONBYTEMATRIX_H_
+#define _BC_COMMONBYTEMATRIX_H_
+class CBC_CommonByteMatrix;
+class CBC_CommonByteMatrix : public CFX_Object
+{
+public:
+ CBC_CommonByteMatrix(FX_INT32 width, FX_INT32 height);
+ virtual ~CBC_CommonByteMatrix();
+ FX_INT32 GetHeight();
+ FX_INT32 GetWidth();
+ FX_BYTE Get(FX_INT32 x, FX_INT32 y);
+ FX_BYTE* GetArray();
+
+ void Set(FX_INT32 x, FX_INT32 y, FX_INT32 value);
+ void Set(FX_INT32 x, FX_INT32 y, FX_BYTE value);
+ void clear(FX_BYTE value);
+ virtual void Init();
+private:
+ FX_BYTE *m_bytes;
+ FX_INT32 m_width;
+ FX_INT32 m_height;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_CommonCharacterSetECI.cpp b/xfa/src/fxbarcode/common/BC_CommonCharacterSetECI.cpp new file mode 100644 index 0000000000..2909704796 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonCharacterSetECI.cpp @@ -0,0 +1,50 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "BC_CommonECI.h"
+#include "BC_CommonCharacterSetECI.h"
+void CBC_CommonCharacterSetECI::initialize()
+{
+}
+CBC_CommonCharacterSetECI::CBC_CommonCharacterSetECI(FX_INT32 value, CFX_ByteString encodingName):
+ CBC_CommonECI(value), m_encodingName(encodingName)
+{
+}
+CBC_CommonCharacterSetECI::~CBC_CommonCharacterSetECI()
+{
+}
+CFX_ByteString CBC_CommonCharacterSetECI::GetEncodingName()
+{
+ return m_encodingName;
+}
+void CBC_CommonCharacterSetECI::AddCharacterSet(FX_INT32 value, CFX_ByteString encodingName)
+{
+}
+CBC_CommonCharacterSetECI* CBC_CommonCharacterSetECI::GetCharacterSetECIByValue(FX_INT32 value)
+{
+ return NULL;
+}
+CBC_CommonCharacterSetECI* CBC_CommonCharacterSetECI::GetCharacterSetECIByName(const CFX_ByteString& name)
+{
+ return NULL;
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonCharacterSetECI.h b/xfa/src/fxbarcode/common/BC_CommonCharacterSetECI.h new file mode 100644 index 0000000000..1e9f9a433f --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonCharacterSetECI.h @@ -0,0 +1,25 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONCHARACTERSETECI_H_
+#define _BC_COMMONCHARACTERSETECI_H_
+class CBC_CommonECI;
+class CBC_CommonCharacterSetECI;
+class CBC_CommonCharacterSetECI : public CBC_CommonECI
+{
+public:
+ CBC_CommonCharacterSetECI(FX_INT32 value, CFX_ByteString encodingName);
+ virtual ~CBC_CommonCharacterSetECI();
+ CFX_ByteString GetEncodingName();
+ static void AddCharacterSet(FX_INT32 value, CFX_ByteString encodingName);
+ FX_INT32 GetValue();
+ static CBC_CommonCharacterSetECI* GetCharacterSetECIByValue(FX_INT32 value);
+ static CBC_CommonCharacterSetECI* GetCharacterSetECIByName(const CFX_ByteString& name);
+private:
+ CFX_ByteString m_encodingName;
+ static void initialize();
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_CommonDecoderResult.cpp b/xfa/src/fxbarcode/common/BC_CommonDecoderResult.cpp new file mode 100644 index 0000000000..d0c55734db --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonDecoderResult.cpp @@ -0,0 +1,79 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "../qrcode/BC_QRCoderErrorCorrectionLevel.h"
+#include "../pdf417/BC_PDF417ResultMetadata.h"
+#include "BC_CommonDecoderResult.h"
+CBC_CommonDecoderResult::CBC_CommonDecoderResult()
+{
+}
+void CBC_CommonDecoderResult::Init(const CFX_ByteArray &rawBytes, const CFX_ByteString &text, const CFX_Int32Array &byteSegments, CBC_QRCoderErrorCorrectionLevel* ecLevel, FX_INT32 &e)
+{
+ if(text.IsEmpty()) {
+ e = BCExceptionIllegalArgument;
+ return;
+ }
+ m_rawBytes.Copy(rawBytes);
+ m_text = text;
+ m_byteSegments.Copy(byteSegments);
+ m_ecLevel = ecLevel;
+ m_other = NULL;
+}
+void CBC_CommonDecoderResult::Init(const CFX_ByteArray &rawBytes, const CFX_ByteString &text, const CFX_PtrArray &byteSegments, const CFX_ByteString &ecLevel, FX_INT32 &e)
+{
+ if(text.IsEmpty()) {
+ e = BCExceptionIllegalArgument;
+ return;
+ }
+ m_rawBytes.Copy(rawBytes);
+ m_text = text;
+ m_pdf417byteSegments.Copy(byteSegments);
+ m_pdf417ecLevel = ecLevel;
+ m_other = NULL;
+}
+void CBC_CommonDecoderResult::setOther(CBC_PDF417ResultMetadata* other)
+{
+ m_other = other;
+}
+CBC_CommonDecoderResult::~CBC_CommonDecoderResult()
+{
+ if (m_other != NULL) {
+ delete m_other;
+ }
+}
+const CFX_ByteArray& CBC_CommonDecoderResult::GetRawBytes()
+{
+ return m_rawBytes;
+}
+const CFX_Int32Array& CBC_CommonDecoderResult::GetByteSegments()
+{
+ return m_byteSegments;
+}
+const CFX_ByteString& CBC_CommonDecoderResult::GetText()
+{
+ return m_text;
+}
+CBC_QRCoderErrorCorrectionLevel* CBC_CommonDecoderResult::GetECLevel()
+{
+ return m_ecLevel;
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonDecoderResult.h b/xfa/src/fxbarcode/common/BC_CommonDecoderResult.h new file mode 100644 index 0000000000..808203bd01 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonDecoderResult.h @@ -0,0 +1,33 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONDECODERRESULT_H_
+#define _BC_COMMONDECODERRESULT_H_
+class CBC_QRCoderErrorCorrectionLevel;
+class CBC_PDF417ResultMetadata;
+class CBC_CommonDecoderResult;
+class CBC_CommonDecoderResult : public CFX_Object
+{
+public:
+ CBC_CommonDecoderResult();
+ virtual ~CBC_CommonDecoderResult();
+ const CFX_ByteArray& GetRawBytes();
+ const CFX_ByteString& GetText();
+ const CFX_Int32Array& GetByteSegments();
+ CBC_QRCoderErrorCorrectionLevel* GetECLevel();
+ virtual void Init(const CFX_ByteArray &rawBytes, const CFX_ByteString &text, const CFX_Int32Array &byteSegments, CBC_QRCoderErrorCorrectionLevel* ecLevel, FX_INT32 &e);
+ virtual void Init(const CFX_ByteArray &rawBytes, const CFX_ByteString &text, const CFX_PtrArray &byteSegments, const CFX_ByteString &ecLevel, FX_INT32 &e);
+ void setOther(CBC_PDF417ResultMetadata* other);
+private:
+ CFX_ByteArray m_rawBytes;
+ CFX_ByteString m_text;
+ CFX_Int32Array m_byteSegments;
+ CFX_PtrArray m_pdf417byteSegments;
+ CBC_QRCoderErrorCorrectionLevel* m_ecLevel;
+ CFX_ByteString m_pdf417ecLevel;
+ CBC_PDF417ResultMetadata* m_other;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_CommonECI.cpp b/xfa/src/fxbarcode/common/BC_CommonECI.cpp new file mode 100644 index 0000000000..5aa64095f7 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonECI.cpp @@ -0,0 +1,46 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "BC_CommonECI.h"
+#include "BC_CommonCharacterSetECI.h"
+CBC_CommonECI::CBC_CommonECI(FX_INT32 value)
+{
+ m_value = value;
+}
+CBC_CommonECI::~CBC_CommonECI()
+{
+}
+FX_INT32 CBC_CommonECI::GetValue()
+{
+ return m_value;
+}
+CBC_CommonECI* CBC_CommonECI::GetEICByValue(FX_INT32 value, FX_INT32 &e)
+{
+ if(value < 0 || value > 999999) {
+ e = BCExceptionBadECI;
+ return NULL;
+ }
+ if(value < 900) {
+ }
+ return NULL;
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonECI.h b/xfa/src/fxbarcode/common/BC_CommonECI.h new file mode 100644 index 0000000000..3907066066 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonECI.h @@ -0,0 +1,21 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONECI_H_
+#define _BC_COMMONECI_H_
+class CBC_CommonECI;
+class CBC_CommonECI : public CFX_Object
+{
+public:
+ CBC_CommonECI(FX_INT32 value);
+ virtual ~CBC_CommonECI();
+
+ FX_INT32 GetValue();
+ static CBC_CommonECI* GetEICByValue(FX_INT32 value, FX_INT32 &e);
+private:
+ FX_INT32 m_value;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_CommonPerspectiveTransform.cpp b/xfa/src/fxbarcode/common/BC_CommonPerspectiveTransform.cpp new file mode 100644 index 0000000000..cb59d99cdf --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonPerspectiveTransform.cpp @@ -0,0 +1,125 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../barcode.h"
+#include "BC_CommonPerspectiveTransform.h"
+CBC_CommonPerspectiveTransform::CBC_CommonPerspectiveTransform(FX_FLOAT a11, FX_FLOAT a21, FX_FLOAT a31,
+ FX_FLOAT a12, FX_FLOAT a22, FX_FLOAT a32,
+ FX_FLOAT a13, FX_FLOAT a23, FX_FLOAT a33) :
+ m_a11(a11), m_a21(a21), m_a31(a31),
+ m_a12(a12), m_a22(a22), m_a32(a32),
+ m_a13(a13), m_a23(a23), m_a33(a33)
+{
+}
+CBC_CommonPerspectiveTransform::~CBC_CommonPerspectiveTransform()
+{
+}
+CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::QuadrilateralToQuadrilateral(FX_FLOAT x0, FX_FLOAT y0,
+ FX_FLOAT x1, FX_FLOAT y1,
+ FX_FLOAT x2, FX_FLOAT y2,
+ FX_FLOAT x3, FX_FLOAT y3,
+ FX_FLOAT x0p, FX_FLOAT y0p,
+ FX_FLOAT x1p, FX_FLOAT y1p,
+ FX_FLOAT x2p, FX_FLOAT y2p,
+ FX_FLOAT x3p, FX_FLOAT y3p)
+{
+ CBC_AutoPtr<CBC_CommonPerspectiveTransform> qToS(QuadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3));
+ CBC_AutoPtr<CBC_CommonPerspectiveTransform> sToQ(SquareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p));
+ return sToQ->Times(*(qToS.get()));
+}
+void CBC_CommonPerspectiveTransform::TransformPoints(CFX_FloatArray *points)
+{
+ FX_INT32 max = points->GetSize();
+ FX_FLOAT a11 = m_a11;
+ FX_FLOAT a12 = m_a12;
+ FX_FLOAT a13 = m_a13;
+ FX_FLOAT a21 = m_a21;
+ FX_FLOAT a22 = m_a22;
+ FX_FLOAT a23 = m_a23;
+ FX_FLOAT a31 = m_a31;
+ FX_FLOAT a32 = m_a32;
+ FX_FLOAT a33 = m_a33;
+ FX_INT32 i;
+ for (i = 0; i < max; i += 2) {
+ FX_FLOAT x = (*points)[i];
+ FX_FLOAT y = (*points)[i + 1];
+ FX_FLOAT denominator = a13 * x + a23 * y + a33;
+ (*points)[i] = (a11 * x + a21 * y + a31) / denominator;
+ (*points)[i + 1] = (a12 * x + a22 * y + a32) / denominator;
+ }
+}
+CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::SquareToQuadrilateral(FX_FLOAT x0, FX_FLOAT y0,
+ FX_FLOAT x1, FX_FLOAT y1,
+ FX_FLOAT x2, FX_FLOAT y2,
+ FX_FLOAT x3, FX_FLOAT y3)
+{
+ FX_FLOAT dy2 = y3 - y2;
+ FX_FLOAT dy3 = y0 - y1 + y2 - y3;
+ if ((dy2 == 0.0f) && (dy3 == 0.0f)) {
+ return FX_NEW CBC_CommonPerspectiveTransform(x1 - x0, x2 - x1, x0,
+ y1 - y0, y2 - y1, y0,
+ 0.0f, 0.0f, 1.0f);
+ } else {
+ FX_FLOAT dx1 = x1 - x2;
+ FX_FLOAT dx2 = x3 - x2;
+ FX_FLOAT dx3 = x0 - x1 + x2 - x3;
+ FX_FLOAT dy1 = y1 - y2;
+ FX_FLOAT denominator = dx1 * dy2 - dx2 * dy1;
+ FX_FLOAT a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
+ FX_FLOAT a23 = (dx1 * dy3 - dx3 * dy1) / denominator;
+ return FX_NEW CBC_CommonPerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0,
+ y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0,
+ a13, a23, 1.0f);
+ }
+}
+CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::QuadrilateralToSquare(FX_FLOAT x0, FX_FLOAT y0,
+ FX_FLOAT x1, FX_FLOAT y1,
+ FX_FLOAT x2, FX_FLOAT y2,
+ FX_FLOAT x3, FX_FLOAT y3)
+{
+ CBC_AutoPtr<CBC_CommonPerspectiveTransform> temp1(SquareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3));
+ return temp1->BuildAdjoint();
+}
+CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::BuildAdjoint()
+{
+ return FX_NEW CBC_CommonPerspectiveTransform(m_a22 * m_a33 - m_a23 * m_a32,
+ m_a23 * m_a31 - m_a21 * m_a33,
+ m_a21 * m_a32 - m_a22 * m_a31,
+ m_a13 * m_a32 - m_a12 * m_a33,
+ m_a11 * m_a33 - m_a13 * m_a31,
+ m_a12 * m_a31 - m_a11 * m_a32,
+ m_a12 * m_a23 - m_a13 * m_a22,
+ m_a13 * m_a21 - m_a11 * m_a23,
+ m_a11 * m_a22 - m_a12 * m_a21);
+}
+CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::Times(CBC_CommonPerspectiveTransform &other)
+{
+ return FX_NEW CBC_CommonPerspectiveTransform(m_a11 * other.m_a11 + m_a21 * other.m_a12 + m_a31 * other.m_a13,
+ m_a11 * other.m_a21 + m_a21 * other.m_a22 + m_a31 * other.m_a23,
+ m_a11 * other.m_a31 + m_a21 * other.m_a32 + m_a31 * other.m_a33,
+ m_a12 * other.m_a11 + m_a22 * other.m_a12 + m_a32 * other.m_a13,
+ m_a12 * other.m_a21 + m_a22 * other.m_a22 + m_a32 * other.m_a23,
+ m_a12 * other.m_a31 + m_a22 * other.m_a32 + m_a32 * other.m_a33,
+ m_a13 * other.m_a11 + m_a23 * other.m_a12 + m_a33 * other.m_a13,
+ m_a13 * other.m_a21 + m_a23 * other.m_a22 + m_a33 * other.m_a23,
+ m_a13 * other.m_a31 + m_a23 * other.m_a32 + m_a33 * other.m_a33);
+}
diff --git a/xfa/src/fxbarcode/common/BC_CommonPerspectiveTransform.h b/xfa/src/fxbarcode/common/BC_CommonPerspectiveTransform.h new file mode 100644 index 0000000000..5c42a1a6a7 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_CommonPerspectiveTransform.h @@ -0,0 +1,39 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_COMMONPERSPECTIVETRANSFORM_H_
+#define _BC_COMMONPERSPECTIVETRANSFORM_H_
+class CBC_CommonPerspectiveTransform;
+class CBC_CommonPerspectiveTransform : public CFX_Object
+{
+public:
+ CBC_CommonPerspectiveTransform(FX_FLOAT a11, FX_FLOAT a21, FX_FLOAT a31,
+ FX_FLOAT a12, FX_FLOAT a22, FX_FLOAT a32,
+ FX_FLOAT a13, FX_FLOAT a23, FX_FLOAT a33);
+ virtual ~CBC_CommonPerspectiveTransform();
+ static CBC_CommonPerspectiveTransform *QuadrilateralToQuadrilateral(FX_FLOAT x0, FX_FLOAT y0,
+ FX_FLOAT x1, FX_FLOAT y1,
+ FX_FLOAT x2, FX_FLOAT y2,
+ FX_FLOAT x3, FX_FLOAT y3,
+ FX_FLOAT x0p, FX_FLOAT y0p,
+ FX_FLOAT x1p, FX_FLOAT y1p,
+ FX_FLOAT x2p, FX_FLOAT y2p,
+ FX_FLOAT x3p, FX_FLOAT y3p);
+ static CBC_CommonPerspectiveTransform *SquareToQuadrilateral(FX_FLOAT x0, FX_FLOAT y0,
+ FX_FLOAT x1, FX_FLOAT y1,
+ FX_FLOAT x2, FX_FLOAT y2,
+ FX_FLOAT x3, FX_FLOAT y3);
+ static CBC_CommonPerspectiveTransform *QuadrilateralToSquare(FX_FLOAT x0, FX_FLOAT y0,
+ FX_FLOAT x1, FX_FLOAT y1,
+ FX_FLOAT x2, FX_FLOAT y2,
+ FX_FLOAT x3, FX_FLOAT y3);
+ CBC_CommonPerspectiveTransform *BuildAdjoint();
+ CBC_CommonPerspectiveTransform *Times(CBC_CommonPerspectiveTransform &other);
+ void TransformPoints(CFX_FloatArray *points);
+private:
+ FX_FLOAT m_a11, m_a12, m_a13, m_a21, m_a22, m_a23, m_a31, m_a32, m_a33;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp b/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp new file mode 100644 index 0000000000..7ef1671d98 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp @@ -0,0 +1,169 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2009 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.
+ */
+
+#include "../barcode.h"
+#include "../BC_Binarizer.h"
+#include "../BC_LuminanceSource.h"
+#include "BC_CommonBitMatrix.h"
+#include "BC_CommonBitArray.h"
+#include "BC_GlobalHistogramBinarizer.h"
+const FX_INT32 LUMINANCE_BITS = 5;
+const FX_INT32 LUMINANCE_SHIFT = 8 - LUMINANCE_BITS;
+const FX_INT32 LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
+CBC_GlobalHistogramBinarizer::CBC_GlobalHistogramBinarizer(CBC_LuminanceSource *source): CBC_Binarizer(source)
+{
+}
+CBC_GlobalHistogramBinarizer::~CBC_GlobalHistogramBinarizer()
+{
+}
+CBC_CommonBitArray *CBC_GlobalHistogramBinarizer::GetBlackRow(FX_INT32 y, CBC_CommonBitArray *row, FX_INT32 &e)
+{
+ CBC_LuminanceSource *source = GetLuminanceSource();
+ FX_INT32 width = source->GetWidth();
+ CBC_AutoPtr<CBC_CommonBitArray> result(FX_NEW CBC_CommonBitArray(width));
+ InitArrays(width);
+ CFX_ByteArray *localLuminances = source->GetRow(y, m_luminance, e);
+ if (e != BCExceptionNO) {
+ return result.release();
+ }
+ CFX_Int32Array localBuckets;
+ localBuckets.Copy(m_buckets);
+ FX_INT32 x;
+ for (x = 0; x < width; x++) {
+ FX_INT32 pixel = (*localLuminances)[x] & 0xff;
+ localBuckets[pixel >> LUMINANCE_SHIFT]++;
+ }
+ FX_INT32 blackPoint = EstimateBlackPoint(localBuckets, e);
+ if (e != BCExceptionNO) {
+ return result.release();
+ }
+ FX_INT32 left = (*localLuminances)[0] & 0xff;
+ FX_INT32 center = (*localLuminances)[1] & 0xff;
+ for (x = 1; x < width - 1; x++) {
+ FX_INT32 right = (*localLuminances)[x + 1] & 0xff;
+ FX_INT32 luminance = ((center << 2) - left - right) >> 1;
+ if (luminance < blackPoint) {
+ result->Set(x);
+ }
+ left = center;
+ center = right;
+ }
+ return result.release();
+}
+CBC_CommonBitMatrix *CBC_GlobalHistogramBinarizer::GetBlackMatrix(FX_INT32 &e)
+{
+ CBC_LuminanceSource *source = GetLuminanceSource();
+ FX_INT32 width = source->GetWidth();
+ FX_INT32 height = source->GetHeight();
+ CBC_CommonBitMatrix *BitMatrixTemp = FX_NEW CBC_CommonBitMatrix();
+ BitMatrixTemp->Init(width, height);
+ CBC_AutoPtr<CBC_CommonBitMatrix> matrix(BitMatrixTemp);
+ InitArrays(width);
+ CFX_Int32Array localBuckets;
+ localBuckets.Copy(m_buckets);
+ FX_INT32 y;
+ for (y = 1; y < 5; y++) {
+ FX_INT32 row = height * y / 5;
+ CFX_ByteArray *localLuminances = source->GetRow(row, m_luminance, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ FX_INT32 right = (width << 2) / 5;
+ FX_INT32 x;
+ for (x = width / 5; x < right; x++) {
+ FX_INT32 pixel = (*localLuminances)[x] & 0xff;
+ localBuckets[pixel >> LUMINANCE_SHIFT]++;
+ }
+ }
+ FX_INT32 blackPoint = EstimateBlackPoint(localBuckets, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CFX_ByteArray> localLuminances(source->GetMatrix());
+ for (y = 0; y < height; y++) {
+ FX_INT32 offset = y * width;
+ for (FX_INT32 x = 0; x < width; x++) {
+ FX_INT32 pixel = (*localLuminances)[offset + x] & 0xff;
+ if (pixel < blackPoint) {
+ matrix->Set(x, y);
+ }
+ }
+ }
+ return matrix.release();
+}
+void CBC_GlobalHistogramBinarizer::InitArrays(FX_INT32 luminanceSize)
+{
+ if(m_luminance.GetSize() < luminanceSize) {
+ m_luminance.SetSize(luminanceSize);
+ }
+ if(m_buckets.GetSize() <= 0) {
+ m_buckets.SetSize(LUMINANCE_BUCKETS);
+ } else {
+ FX_INT32 x;
+ for(x = 0; x < LUMINANCE_BUCKETS; x++) {
+ m_buckets[x] = 0;
+ }
+ }
+}
+FX_INT32 CBC_GlobalHistogramBinarizer::EstimateBlackPoint(CFX_Int32Array &buckets, FX_INT32 &e)
+{
+ FX_INT32 numBuckets = buckets.GetSize();
+ FX_INT32 maxBucketCount = 0;
+ FX_INT32 firstPeak = 0;
+ FX_INT32 firstPeakSize = 0;
+ FX_INT32 x;
+ for (x = 0; x < numBuckets; x++) {
+ if (buckets[x] > firstPeakSize) {
+ firstPeak = x;
+ firstPeakSize = buckets[x];
+ }
+ if (buckets[x] > maxBucketCount) {
+ maxBucketCount = buckets[x];
+ }
+ }
+ FX_INT32 secondPeak = 0;
+ FX_INT32 secondPeakScore = 0;
+ for (x = 0; x < numBuckets; x++) {
+ FX_INT32 distanceToBiggest = x - firstPeak;
+ FX_INT32 score = buckets[x] * distanceToBiggest * distanceToBiggest;
+ if (score > secondPeakScore) {
+ secondPeak = x;
+ secondPeakScore = score;
+ }
+ }
+ if (firstPeak > secondPeak) {
+ FX_INT32 temp = firstPeak;
+ firstPeak = secondPeak;
+ secondPeak = temp;
+ }
+ if (secondPeak - firstPeak <= numBuckets >> 4) {
+ e = BCExceptionRead;
+ return 0;
+ }
+ FX_INT32 bestValley = secondPeak - 1;
+ FX_INT32 bestValleyScore = -1;
+ for (x = secondPeak - 1; x > firstPeak; x--) {
+ FX_INT32 fromFirst = x - firstPeak;
+ FX_INT32 score = fromFirst * fromFirst * (secondPeak - x) * (maxBucketCount - buckets[x]);
+ if (score > bestValleyScore) {
+ bestValley = x;
+ bestValleyScore = score;
+ }
+ }
+ return bestValley << LUMINANCE_SHIFT;
+}
diff --git a/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.h b/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.h new file mode 100644 index 0000000000..ef084c075e --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.h @@ -0,0 +1,28 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_GLOBALHISTOGRAMBINARIZER_H_
+#define _BC_GLOBALHISTOGRAMBINARIZER_H_
+class CBC_CommonBinarizer;
+class CBC_CommonBitArray;
+class CBC_CommonBitMatrix;
+class CBC_LuminanceSource;
+class CBC_GlobalHistogramBinarizer;
+class CBC_GlobalHistogramBinarizer : public CBC_Binarizer
+{
+public:
+ CBC_GlobalHistogramBinarizer(CBC_LuminanceSource *source);
+ virtual ~CBC_GlobalHistogramBinarizer();
+
+ void InitArrays(FX_INT32 luminanceSize);
+ CBC_CommonBitMatrix *GetBlackMatrix(FX_INT32 &e);
+ CBC_CommonBitArray *GetBlackRow(FX_INT32 y, CBC_CommonBitArray *row, FX_INT32 &e);
+ static FX_INT32 EstimateBlackPoint(CFX_Int32Array &buckets, FX_INT32 &e);
+private:
+ CFX_ByteArray m_luminance;
+ CFX_Int32Array m_buckets;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.cpp b/xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.cpp new file mode 100644 index 0000000000..8bc93136ca --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.cpp @@ -0,0 +1,244 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2010 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.
+ */
+
+#include "../barcode.h"
+#include "BC_WhiteRectangleDetector.h"
+#include "BC_CommonBitMatrix.h"
+#include "../BC_ResultPoint.h"
+const FX_INT32 CBC_WhiteRectangleDetector::INIT_SIZE = 30;
+const FX_INT32 CBC_WhiteRectangleDetector::CORR = 1;
+CBC_WhiteRectangleDetector::CBC_WhiteRectangleDetector(CBC_CommonBitMatrix *image)
+{
+ m_image = image;
+ m_height = image->GetHeight();
+ m_width = image->GetWidth();
+ m_leftInit = (m_width - INIT_SIZE) >> 1;
+ m_rightInit = (m_width + INIT_SIZE) >> 1;
+ m_upInit = (m_height - INIT_SIZE) >> 1;
+ m_downInit = (m_height + INIT_SIZE) >> 1;
+}
+void CBC_WhiteRectangleDetector::Init(FX_INT32 &e)
+{
+ if (m_upInit < 0 || m_leftInit < 0 || m_downInit >= m_height || m_rightInit >= m_width) {
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+}
+CBC_WhiteRectangleDetector::CBC_WhiteRectangleDetector(CBC_CommonBitMatrix *image, FX_INT32 initSize, FX_INT32 x, FX_INT32 y)
+{
+ m_image = image;
+ m_height = image->GetHeight();
+ m_width = image->GetWidth();
+ FX_INT32 halfsize = initSize >> 1;
+ m_leftInit = x - halfsize;
+ m_rightInit = x + halfsize;
+ m_upInit = y - halfsize;
+ m_downInit = y + halfsize;
+}
+CBC_WhiteRectangleDetector::~CBC_WhiteRectangleDetector()
+{
+}
+CFX_PtrArray *CBC_WhiteRectangleDetector::Detect(FX_INT32 &e)
+{
+ FX_INT32 left = m_leftInit;
+ FX_INT32 right = m_rightInit;
+ FX_INT32 up = m_upInit;
+ FX_INT32 down = m_downInit;
+ FX_BOOL sizeExceeded = FALSE;
+ FX_BOOL aBlackPointFoundOnBorder = TRUE;
+ FX_BOOL atLeastOneBlackPointFoundOnBorder = FALSE;
+ while (aBlackPointFoundOnBorder) {
+ aBlackPointFoundOnBorder = FALSE;
+ FX_BOOL rightBorderNotWhite = TRUE;
+ while (rightBorderNotWhite && right < m_width) {
+ rightBorderNotWhite = ContainsBlackPoint(up, down, right, FALSE);
+ if (rightBorderNotWhite) {
+ right++;
+ aBlackPointFoundOnBorder = TRUE;
+ }
+ }
+ if (right >= m_width) {
+ sizeExceeded = TRUE;
+ break;
+ }
+ FX_BOOL bottomBorderNotWhite = TRUE;
+ while (bottomBorderNotWhite && down < m_height) {
+ bottomBorderNotWhite = ContainsBlackPoint(left, right, down, TRUE);
+ if (bottomBorderNotWhite) {
+ down++;
+ aBlackPointFoundOnBorder = TRUE;
+ }
+ }
+ if (down >= m_height) {
+ sizeExceeded = TRUE;
+ break;
+ }
+ FX_BOOL leftBorderNotWhite = TRUE;
+ while (leftBorderNotWhite && left >= 0) {
+ leftBorderNotWhite = ContainsBlackPoint(up, down, left, FALSE);
+ if (leftBorderNotWhite) {
+ left--;
+ aBlackPointFoundOnBorder = TRUE;
+ }
+ }
+ if (left < 0) {
+ sizeExceeded = TRUE;
+ break;
+ }
+ FX_BOOL topBorderNotWhite = TRUE;
+ while (topBorderNotWhite && up >= 0) {
+ topBorderNotWhite = ContainsBlackPoint(left, right, up, TRUE);
+ if (topBorderNotWhite) {
+ up--;
+ aBlackPointFoundOnBorder = TRUE;
+ }
+ }
+ if (up < 0) {
+ sizeExceeded = TRUE;
+ break;
+ }
+ if (aBlackPointFoundOnBorder) {
+ atLeastOneBlackPointFoundOnBorder = TRUE;
+ }
+ }
+ if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) {
+ FX_INT32 maxSize = right - left;
+ CBC_AutoPtr<CBC_ResultPoint> z(NULL);
+ for (FX_INT32 i = 1; i < maxSize; i++) {
+ z = CBC_AutoPtr<CBC_ResultPoint>(GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(down - i), (FX_FLOAT)(left + i), (FX_FLOAT)(down)) );
+ if (z.get() != NULL) {
+ break;
+ }
+ }
+ if (z.get() == NULL) {
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CBC_AutoPtr<CBC_ResultPoint> t(NULL);
+ for (FX_INT32 j = 1; j < maxSize; j++) {
+ t = CBC_AutoPtr<CBC_ResultPoint>(GetBlackPointOnSegment((FX_FLOAT)left, (FX_FLOAT)(up + j), (FX_FLOAT)(left + j), (FX_FLOAT)up));
+ if (t.get() != NULL) {
+ break;
+ }
+ }
+ if (t.get() == NULL) {
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CBC_AutoPtr<CBC_ResultPoint> x(NULL);
+ for (FX_INT32 k = 1; k < maxSize; k++) {
+ x = CBC_AutoPtr<CBC_ResultPoint>(GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(up + k), (FX_FLOAT)(right - k), (FX_FLOAT)up));
+ if (x.get() != NULL) {
+ break;
+ }
+ }
+ if (x.get() == NULL) {
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CBC_AutoPtr<CBC_ResultPoint> y(NULL);
+ for (FX_INT32 m = 1; m < maxSize; m++) {
+ y = CBC_AutoPtr<CBC_ResultPoint>(GetBlackPointOnSegment((FX_FLOAT)right, (FX_FLOAT)(down - m), (FX_FLOAT)(right - m), (FX_FLOAT) down));
+ if (y.get() != NULL) {
+ break;
+ }
+ }
+ if (y.get() == NULL) {
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ return CenterEdges(y.get(), z.get(), x.get(), t.get());
+ } else {
+ e = BCExceptionNotFound;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ return NULL;
+}
+FX_INT32 CBC_WhiteRectangleDetector::Round(FX_FLOAT d)
+{
+ return (FX_INT32) (d + 0.5f);
+}
+CBC_ResultPoint *CBC_WhiteRectangleDetector::GetBlackPointOnSegment(FX_FLOAT aX, FX_FLOAT aY, FX_FLOAT bX, FX_FLOAT bY)
+{
+ FX_INT32 dist = DistanceL2(aX, aY, bX, bY);
+ float xStep = (bX - aX) / dist;
+ float yStep = (bY - aY) / dist;
+ for (FX_INT32 i = 0; i < dist; i++) {
+ FX_INT32 x = Round(aX + i * xStep);
+ FX_INT32 y = Round(aY + i * yStep);
+ if (m_image->Get(x, y)) {
+ return FX_NEW CBC_ResultPoint((FX_FLOAT)x, (FX_FLOAT) y);
+ }
+ }
+ return NULL;
+}
+FX_INT32 CBC_WhiteRectangleDetector::DistanceL2(FX_FLOAT aX, FX_FLOAT aY, FX_FLOAT bX, FX_FLOAT bY)
+{
+ float xDiff = aX - bX;
+ float yDiff = aY - bY;
+ return Round((float)sqrt(xDiff * xDiff + yDiff * yDiff));
+}
+CFX_PtrArray *CBC_WhiteRectangleDetector::CenterEdges(CBC_ResultPoint *y, CBC_ResultPoint *z, CBC_ResultPoint *x, CBC_ResultPoint *t)
+{
+ float yi = y->GetX();
+ float yj = y->GetY();
+ float zi = z->GetX();
+ float zj = z->GetY();
+ float xi = x->GetX();
+ float xj = x->GetY();
+ float ti = t->GetX();
+ float tj = t->GetY();
+ if (yi < m_width / 2) {
+ CFX_PtrArray *result = FX_NEW CFX_PtrArray;
+ result->SetSize(4);
+ (*result)[0] = FX_NEW CBC_ResultPoint(ti - CORR, tj + CORR);
+ (*result)[1] = FX_NEW CBC_ResultPoint(zi + CORR, zj + CORR);
+ (*result)[2] = FX_NEW CBC_ResultPoint(xi - CORR, xj - CORR);
+ (*result)[3] = FX_NEW CBC_ResultPoint(yi + CORR, yj - CORR);
+ return result;
+ } else {
+ CFX_PtrArray *result = FX_NEW CFX_PtrArray;
+ result->SetSize(4);
+ (*result)[0] = FX_NEW CBC_ResultPoint(ti + CORR, tj + CORR);
+ (*result)[1] = FX_NEW CBC_ResultPoint(zi + CORR, zj - CORR);
+ (*result)[2] = FX_NEW CBC_ResultPoint(xi - CORR, xj + CORR);
+ (*result)[3] = FX_NEW CBC_ResultPoint(yi - CORR, yj - CORR);
+ return result;
+ }
+}
+FX_BOOL CBC_WhiteRectangleDetector::ContainsBlackPoint(FX_INT32 a, FX_INT32 b, FX_INT32 fixed, FX_BOOL horizontal)
+{
+ if (horizontal) {
+ for (FX_INT32 x = a; x <= b; x++) {
+ if (m_image->Get(x, fixed)) {
+ return TRUE;
+ }
+ }
+ } else {
+ for (FX_INT32 y = a; y <= b; y++) {
+ if (m_image->Get(fixed, y)) {
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
diff --git a/xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.h b/xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.h new file mode 100644 index 0000000000..83d91ced92 --- /dev/null +++ b/xfa/src/fxbarcode/common/BC_WhiteRectangleDetector.h @@ -0,0 +1,38 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_WHITERECTANLEDETECTOR_H_
+#define _BC_WHITERECTANLEDETECTOR_H_
+class CBC_CommonBitMatrix;
+class CBC_ResultPoint;
+class CBC_WhiteRectangleDetector;
+class CBC_WhiteRectangleDetector : public CFX_Object
+{
+public:
+ CBC_WhiteRectangleDetector(CBC_CommonBitMatrix *image);
+ CBC_WhiteRectangleDetector(CBC_CommonBitMatrix *image, FX_INT32 initSize, FX_INT32 x, FX_INT32 y);
+ virtual ~CBC_WhiteRectangleDetector();
+ CFX_PtrArray *Detect(FX_INT32 &e);
+ virtual void Init(FX_INT32 &e);
+private:
+ FX_INT32 Round(float d);
+ CBC_ResultPoint *GetBlackPointOnSegment(FX_FLOAT aX, FX_FLOAT aY, FX_FLOAT bX, FX_FLOAT bY);
+ FX_INT32 DistanceL2(FX_FLOAT aX, FX_FLOAT aY, FX_FLOAT bX, FX_FLOAT bY);
+ CFX_PtrArray *CenterEdges(CBC_ResultPoint *y, CBC_ResultPoint *z,
+ CBC_ResultPoint *x, CBC_ResultPoint *t);
+ FX_BOOL ContainsBlackPoint(FX_INT32 a, FX_INT32 b, FX_INT32 fixed, FX_BOOL horizontal);
+ const static FX_INT32 INIT_SIZE;
+ const static FX_INT32 CORR;
+
+ CBC_CommonBitMatrix *m_image;
+ FX_INT32 m_height;
+ FX_INT32 m_width;
+ FX_INT32 m_leftInit;
+ FX_INT32 m_rightInit;
+ FX_INT32 m_downInit;
+ FX_INT32 m_upInit;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp new file mode 100644 index 0000000000..1fc8b6685a --- /dev/null +++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp @@ -0,0 +1,100 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../../barcode.h"
+#include "BC_ReedSolomonGF256.h"
+#include "BC_ReedSolomonGF256Poly.h"
+#include "BC_ReedSolomon.h"
+CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field)
+{
+ m_field = field;
+}
+void CBC_ReedSolomonEncoder::Init()
+{
+ m_cachedGenerators.Add(FX_NEW CBC_ReedSolomonGF256Poly(m_field, 1));
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(FX_INT32 degree, FX_INT32 &e)
+{
+ if(degree >= m_cachedGenerators.GetSize()) {
+ CBC_ReedSolomonGF256Poly* lastGenerator = (CBC_ReedSolomonGF256Poly*)(m_cachedGenerators[m_cachedGenerators.GetSize() - 1]);
+ for(FX_INT32 d = m_cachedGenerators.GetSize(); d <= degree; d++) {
+ CFX_Int32Array temp;
+ temp.Add(1);
+ temp.Add(m_field->Exp(d - 1));
+ CBC_ReedSolomonGF256Poly temp_poly;
+ temp_poly.Init(m_field, &temp, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_ReedSolomonGF256Poly* nextGenerator = lastGenerator->Multiply(&temp_poly, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ m_cachedGenerators.Add(nextGenerator);
+ lastGenerator = nextGenerator;
+ }
+ }
+ return (CBC_ReedSolomonGF256Poly*)(m_cachedGenerators[degree]);
+}
+void CBC_ReedSolomonEncoder::Encode(CFX_Int32Array *toEncode, FX_INT32 ecBytes, FX_INT32 &e)
+{
+ if(ecBytes == 0) {
+ e = BCExceptionNoCorrectionBytes;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ FX_INT32 dataBytes = toEncode->GetSize() - ecBytes;
+ if(dataBytes <= 0) {
+ e = BCExceptionNoDataBytesProvided;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CFX_Int32Array infoCoefficients;
+ infoCoefficients.SetSize(dataBytes);
+ for(FX_INT32 x = 0; x < dataBytes; x++) {
+ infoCoefficients[x] = toEncode->operator [](x);
+ }
+ CBC_ReedSolomonGF256Poly info;
+ info.Init(m_field, &infoCoefficients, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_ReedSolomonGF256Poly* rsg = info.MultiplyByMonomial(ecBytes, 1, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> infoTemp(rsg);
+ CFX_PtrArray *pa = infoTemp->Divide(generator, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_AutoPtr<CFX_PtrArray > temp(pa);
+ CBC_ReedSolomonGF256Poly* remainder = (CBC_ReedSolomonGF256Poly*)(temp->operator [](1));
+ CFX_Int32Array* coefficients = remainder->GetCoefficients();
+ FX_INT32 numZeroCoefficients = ecBytes - coefficients->GetSize();
+ for(FX_INT32 i = 0; i < numZeroCoefficients; i++) {
+ (*toEncode)[dataBytes + i] = 0;
+ }
+ for(FX_INT32 y = 0; y < coefficients->GetSize(); y++) {
+ (*toEncode)[dataBytes + numZeroCoefficients + y] =
+ coefficients->operator [](y);
+ }
+ for (FX_INT32 k = 0; k < temp->GetSize(); k++) {
+ delete (CBC_ReedSolomonGF256Poly*)(*temp)[k];
+ }
+}
+CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder()
+{
+ for (FX_INT32 i = 0; i < m_cachedGenerators.GetSize(); i++) {
+ delete (CBC_ReedSolomonGF256Poly*)m_cachedGenerators[i];
+ }
+}
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.h b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.h new file mode 100644 index 0000000000..2950b8f315 --- /dev/null +++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.h @@ -0,0 +1,25 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_READSOLOMON_H_
+#define _BC_READSOLOMON_H_
+class CBC_ReedSolomonGF256;
+class CBC_ReedSolomonGF256Poly;
+class CBC_ReedSolomonEncoder;
+class CBC_ReedSolomonEncoder : public CFX_Object
+{
+private:
+ CBC_ReedSolomonGF256* m_field;
+ CFX_PtrArray m_cachedGenerators;
+ CBC_ReedSolomonGF256Poly* BuildGenerator(FX_INT32 degree, FX_INT32 &e);
+public:
+ CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256 * field);
+ virtual ~CBC_ReedSolomonEncoder();
+
+ void Encode(CFX_Int32Array *toEncode, FX_INT32 ecBytes, FX_INT32 &e);
+ virtual void Init();
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp new file mode 100644 index 0000000000..3cb5e7762f --- /dev/null +++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.cpp @@ -0,0 +1,224 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../../barcode.h"
+#include "BC_ReedSolomonGF256.h"
+#include "BC_ReedSolomonGF256Poly.h"
+#include "BC_ReedSolomonDecoder.h"
+CBC_ReedSolomonDecoder::CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256* field)
+{
+ m_field = field;
+}
+CBC_ReedSolomonDecoder::~CBC_ReedSolomonDecoder()
+{
+}
+void CBC_ReedSolomonDecoder::Decode(CFX_Int32Array* received, FX_INT32 twoS, FX_INT32 &e)
+{
+ CBC_ReedSolomonGF256Poly poly;
+ poly.Init(m_field, received, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CFX_Int32Array syndromeCoefficients;
+ syndromeCoefficients.SetSize(twoS);
+ FX_BOOL dataMatrix = FALSE;
+ FX_BOOL noError = TRUE;
+ for (FX_INT32 i = 0; i < twoS; i++) {
+ FX_INT32 eval = poly.EvaluateAt(m_field->Exp(dataMatrix ? i + 1 : i));
+ syndromeCoefficients[twoS - 1 - i] = eval;
+ if (eval != 0) {
+ noError = FALSE;
+ }
+ }
+ if(noError) {
+ return;
+ }
+ CBC_ReedSolomonGF256Poly syndrome;
+ syndrome.Init(m_field, &syndromeCoefficients, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_ReedSolomonGF256Poly* rsg = m_field->BuildMonomial(twoS, 1, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsg);
+ CFX_PtrArray* pa = RunEuclideanAlgorithm(temp.get(), &syndrome, twoS, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_AutoPtr<CFX_PtrArray > sigmaOmega(pa);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sigma((CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[0]);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> omega((CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[1]);
+ CFX_Int32Array* ia1 = FindErrorLocations(sigma.get(), e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_AutoPtr<CFX_Int32Array > errorLocations(ia1);
+ CFX_Int32Array* ia2 = FindErrorMagnitudes(omega.get(), errorLocations.get(), dataMatrix, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ CBC_AutoPtr<CFX_Int32Array > errorMagnitudes(ia2);
+ for (FX_INT32 k = 0; k < errorLocations->GetSize(); k++) {
+ FX_INT32 position = received->GetSize() - 1 - m_field->Log((*errorLocations)[k], e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ if(position < 0) {
+ e = BCExceptionBadErrorLocation;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ (*received)[position] = CBC_ReedSolomonGF256::AddOrSubtract((*received)[position], (*errorMagnitudes)[k]);
+ }
+}
+CFX_PtrArray *CBC_ReedSolomonDecoder::RunEuclideanAlgorithm(CBC_ReedSolomonGF256Poly* a, CBC_ReedSolomonGF256Poly* b, FX_INT32 R, FX_INT32 &e)
+{
+ if (a->GetDegree() < b->GetDegree()) {
+ CBC_ReedSolomonGF256Poly* temp = a;
+ a = b;
+ b = temp;
+ }
+ CBC_ReedSolomonGF256Poly* rsg1 = a->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rLast(rsg1);
+ CBC_ReedSolomonGF256Poly* rsg2 = b->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> r(rsg2);
+ CBC_ReedSolomonGF256Poly* rsg3 = m_field->GetOne()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sLast(rsg3);
+ CBC_ReedSolomonGF256Poly* rsg4 = m_field->GetZero()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> s(rsg4);
+ CBC_ReedSolomonGF256Poly* rsg5 = m_field->GetZero()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> tLast(rsg5);
+ CBC_ReedSolomonGF256Poly* rsg6 = m_field->GetOne()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> t(rsg6);
+ while (r->GetDegree() >= R / 2) {
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rLastLast = rLast;
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sLastLast = sLast;
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> tLastlast = tLast;
+ rLast = r;
+ sLast = s;
+ tLast = t;
+ if (rLast->IsZero()) {
+ e = BCExceptionR_I_1IsZero;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CBC_ReedSolomonGF256Poly* rsg7 = rLastLast->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> rTemp(rsg7);
+ r = rTemp;
+ CBC_ReedSolomonGF256Poly* rsg8 = m_field->GetZero()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> q(rsg8);
+ FX_INT32 denominatorLeadingTerm = rLast->GetCoefficients(rLast->GetDegree());
+ FX_INT32 dltInverse = m_field->Inverse(denominatorLeadingTerm, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ while (r->GetDegree() >= rLast->GetDegree() && !(r->IsZero())) {
+ FX_INT32 degreeDiff = r->GetDegree() - rLast->GetDegree();
+ FX_INT32 scale = m_field->Multiply(r->GetCoefficients(r->GetDegree()), dltInverse);
+ CBC_ReedSolomonGF256Poly* rsgp1 = m_field->BuildMonomial(degreeDiff, scale, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> build(rsgp1);
+ CBC_ReedSolomonGF256Poly* rsgp2 = q->AddOrSubtract(build.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsgp2);
+ q = temp;
+ CBC_ReedSolomonGF256Poly* rsgp3 = rLast->MultiplyByMonomial(degreeDiff, scale, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> multiply(rsgp3);
+ CBC_ReedSolomonGF256Poly* rsgp4 = r->AddOrSubtract(multiply.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp3(rsgp4);
+ r = temp3;
+ }
+ CBC_ReedSolomonGF256Poly* rsg9 = q->Multiply(sLast.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp1(rsg9);
+ CBC_ReedSolomonGF256Poly* rsg10 = temp1->AddOrSubtract(sLastLast.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp2(rsg10);
+ s = temp2;
+ CBC_ReedSolomonGF256Poly* rsg11 = q->Multiply(tLast.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp5(rsg11);
+ CBC_ReedSolomonGF256Poly* rsg12 = temp5->AddOrSubtract(tLastlast.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp6(rsg12);
+ t = temp6;
+ }
+ FX_INT32 sigmaTildeAtZero = t->GetCoefficients(0);
+ if (sigmaTildeAtZero == 0) {
+ e = BCExceptionIsZero;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ FX_INT32 inverse = m_field->Inverse(sigmaTildeAtZero, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_ReedSolomonGF256Poly* rsg13 = t->Multiply(inverse, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sigma(rsg13);
+ CBC_ReedSolomonGF256Poly* rsg14 = r->Multiply(inverse, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> omega(rsg14);
+ CFX_PtrArray *temp = FX_NEW CFX_PtrArray;
+ temp->Add(sigma.release());
+ temp->Add(omega.release());
+ return temp;
+}
+CFX_Int32Array *CBC_ReedSolomonDecoder::FindErrorLocations(CBC_ReedSolomonGF256Poly* errorLocator, FX_INT32 &e)
+{
+ FX_INT32 numErrors = errorLocator->GetDegree();
+ if (numErrors == 1) {
+ CBC_AutoPtr<CFX_Int32Array > temp(FX_NEW CFX_Int32Array);
+ temp->Add(errorLocator->GetCoefficients(1));
+ return temp.release();
+ }
+ CFX_Int32Array *tempT = FX_NEW CFX_Int32Array;
+ tempT->SetSize(numErrors);
+ CBC_AutoPtr<CFX_Int32Array > result(tempT);
+ FX_INT32 ie = 0;
+ for (FX_INT32 i = 1; i < 256 && ie < numErrors; i++) {
+ if(errorLocator->EvaluateAt(i) == 0) {
+ (*result)[ie] = m_field->Inverse(i, ie);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ ie++;
+ }
+ }
+ if (ie != numErrors) {
+ e = BCExceptionDegreeNotMatchRoots;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ return result.release();
+}
+CFX_Int32Array *CBC_ReedSolomonDecoder::FindErrorMagnitudes(CBC_ReedSolomonGF256Poly* errorEvaluator, CFX_Int32Array* errorLocations, FX_BOOL dataMatrix, FX_INT32 &e)
+{
+ FX_INT32 s = errorLocations->GetSize();
+ CFX_Int32Array * temp = FX_NEW CFX_Int32Array;
+ temp->SetSize(s);
+ CBC_AutoPtr<CFX_Int32Array > result(temp);
+ for (FX_INT32 i = 0; i < s; i++) {
+ FX_INT32 xiInverse = m_field->Inverse(errorLocations->operator [](i), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ FX_INT32 denominator = 1;
+ for(FX_INT32 j = 0; j < s; j++) {
+ if(i != j) {
+ denominator = m_field->Multiply(denominator,
+ CBC_ReedSolomonGF256::AddOrSubtract(1, m_field->Multiply(errorLocations->operator [](j), xiInverse)));
+ }
+ }
+ FX_INT32 temp = m_field->Inverse(denominator, temp);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ (*result)[i] = m_field->Multiply(errorEvaluator->EvaluateAt(xiInverse),
+ temp);
+ }
+ return result.release();
+}
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h new file mode 100644 index 0000000000..c1dd0f03f5 --- /dev/null +++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h @@ -0,0 +1,24 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_REEDSOLOMONDECODER_H_
+#define _BC_REEDSOLOMONDECODER_H_
+class CBC_ReedSolomonGF256;
+class CBC_ReedSolomonGF256Poly;
+class CBC_ReedSolomonDecoder;
+class CBC_ReedSolomonDecoder : public CFX_Object
+{
+private:
+ CBC_ReedSolomonGF256 * m_field;
+public:
+ CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256 * field);
+ virtual ~CBC_ReedSolomonDecoder();
+ void Decode(CFX_Int32Array* received, FX_INT32 twoS, FX_INT32 &e);
+ CFX_PtrArray* RunEuclideanAlgorithm(CBC_ReedSolomonGF256Poly* a, CBC_ReedSolomonGF256Poly* b, FX_INT32 R, FX_INT32 &e);
+ CFX_Int32Array* FindErrorLocations(CBC_ReedSolomonGF256Poly* errorLocator, FX_INT32 &e);
+ CFX_Int32Array* FindErrorMagnitudes(CBC_ReedSolomonGF256Poly* errorEvaluator, CFX_Int32Array* errorLocations, FX_BOOL dataMatrix, FX_INT32 &e);
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp new file mode 100644 index 0000000000..bb045ac24c --- /dev/null +++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp @@ -0,0 +1,140 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../../barcode.h"
+#include "BC_ReedSolomonGF256Poly.h"
+#include "BC_ReedSolomonGF256.h"
+CBC_ReedSolomonGF256 *CBC_ReedSolomonGF256::QRCodeFild = NULL;
+CBC_ReedSolomonGF256 *CBC_ReedSolomonGF256::DataMatrixField = NULL;
+void CBC_ReedSolomonGF256::Initialize()
+{
+ QRCodeFild = FX_NEW CBC_ReedSolomonGF256(0x011D);
+ QRCodeFild->Init();
+ DataMatrixField = FX_NEW CBC_ReedSolomonGF256(0x012D);
+ DataMatrixField->Init();
+}
+void CBC_ReedSolomonGF256::Finalize()
+{
+ if (QRCodeFild) {
+ delete QRCodeFild;
+ }
+ QRCodeFild = NULL;
+ if (DataMatrixField) {
+ delete DataMatrixField;
+ }
+ DataMatrixField = NULL;
+}
+CBC_ReedSolomonGF256::CBC_ReedSolomonGF256(FX_INT32 primitive)
+{
+ FX_INT32 x = 1;
+ for(FX_INT32 j = 0; j < 256; j++) {
+ m_expTable[j] = x;
+ x <<= 1;
+ if(x >= 0x100) {
+ x ^= primitive;
+ }
+ }
+ for(FX_INT32 i = 0; i < 255; i++) {
+ m_logTable[m_expTable[i]] = i;
+ }
+ m_logTable[0] = 0;
+}
+void CBC_ReedSolomonGF256::Init()
+{
+ m_zero = FX_NEW CBC_ReedSolomonGF256Poly(this, 0);
+ m_one = FX_NEW CBC_ReedSolomonGF256Poly(this, 1);
+}
+CBC_ReedSolomonGF256::~CBC_ReedSolomonGF256()
+{
+ if(m_zero != NULL) {
+ delete m_zero;
+ m_zero = NULL;
+ }
+ if(m_one != NULL) {
+ delete m_one;
+ m_one = NULL;
+ }
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetZero()
+{
+ return m_zero;
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::GetOne()
+{
+ return m_one;
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256::BuildMonomial(FX_INT32 degree, FX_INT32 coefficient, FX_INT32 &e)
+{
+ if(degree < 0) {
+ e = BCExceptionDegreeIsNegative;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ if(coefficient == 0) {
+ CBC_ReedSolomonGF256Poly* temp = m_zero->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+ }
+ CFX_Int32Array coefficients;
+ coefficients.SetSize(degree + 1);
+ coefficients[0] = coefficient;
+ CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(this, &coefficients, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+}
+FX_INT32 CBC_ReedSolomonGF256::AddOrSubtract(FX_INT32 a, FX_INT32 b)
+{
+ return a ^ b;
+}
+FX_INT32 CBC_ReedSolomonGF256::Exp(FX_INT32 a)
+{
+ return m_expTable[a];
+}
+FX_INT32 CBC_ReedSolomonGF256::Log(FX_INT32 a, FX_INT32 &e)
+{
+ if(a == 0) {
+ e = BCExceptionAIsZero;
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ }
+ return m_logTable[a];
+}
+FX_INT32 CBC_ReedSolomonGF256::Inverse(FX_INT32 a, FX_INT32 &e)
+{
+ if(a == 0) {
+ e = BCExceptionAIsZero;
+ BC_EXCEPTION_CHECK_ReturnValue(e, 0);
+ }
+ return m_expTable[255 - m_logTable[a]];
+}
+FX_INT32 CBC_ReedSolomonGF256::Multiply(FX_INT32 a, FX_INT32 b)
+{
+ if(a == 0 || b == 0) {
+ return 0;
+ }
+ if(a == 1) {
+ return b;
+ }
+ if(b == 1) {
+ return a;
+ }
+ return m_expTable[(m_logTable[a] + m_logTable[b]) % 255];
+}
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h new file mode 100644 index 0000000000..1687b95e09 --- /dev/null +++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h @@ -0,0 +1,35 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_REEDSOLOMONGF256_H_
+#define _BC_REEDSOLOMONGF256_H_
+class CBC_ReedSolomonGF256Poly;
+class CBC_ReedSolomonGF256;
+class CBC_ReedSolomonGF256 : public CFX_Object
+{
+public:
+ static void Initialize();
+ static void Finalize();
+ static CBC_ReedSolomonGF256 *QRCodeFild;
+ static CBC_ReedSolomonGF256 *DataMatrixField;
+ CBC_ReedSolomonGF256(FX_INT32 primitive);
+ virtual ~CBC_ReedSolomonGF256();
+ CBC_ReedSolomonGF256Poly* GetZero();
+ CBC_ReedSolomonGF256Poly* GetOne();
+ CBC_ReedSolomonGF256Poly* BuildMonomial(FX_INT32 degree, FX_INT32 coefficient, FX_INT32 &e);
+ static FX_INT32 AddOrSubtract(FX_INT32 a, FX_INT32 b);
+ FX_INT32 Exp(FX_INT32 a);
+ FX_INT32 Log(FX_INT32 a, FX_INT32 &e);
+ FX_INT32 Inverse(FX_INT32 a, FX_INT32 &e);
+ FX_INT32 Multiply(FX_INT32 a, FX_INT32 b);
+ virtual void Init();
+private:
+ FX_INT32 m_expTable[256];
+ FX_INT32 m_logTable[256];
+ CBC_ReedSolomonGF256Poly *m_zero;
+ CBC_ReedSolomonGF256Poly *m_one;
+};
+#endif
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp new file mode 100644 index 0000000000..6476e4cf80 --- /dev/null +++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp @@ -0,0 +1,257 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * 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.
+ */
+
+#include "../../barcode.h"
+#include "BC_ReedSolomonGF256.h"
+#include "BC_ReedSolomonGF256Poly.h"
+CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, FX_INT32 coefficients)
+{
+ if(field == NULL) {
+ return;
+ }
+ m_field = field;
+ m_coefficients.Add(coefficients);
+}
+CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly()
+{
+ m_field = NULL;
+}
+void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, CFX_Int32Array* coefficients, FX_INT32 &e)
+{
+ if(coefficients == NULL || coefficients->GetSize() == 0) {
+ e = BCExceptionCoefficientsSizeIsNull;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ m_field = field;
+ FX_INT32 coefficientsLength = coefficients->GetSize();
+ if((coefficientsLength > 1 && (*coefficients)[0] == 0)) {
+ FX_INT32 firstNonZero = 1;
+ while((firstNonZero < coefficientsLength) && ((*coefficients)[firstNonZero] == 0)) {
+ firstNonZero++;
+ }
+ if(firstNonZero == coefficientsLength) {
+ m_coefficients.Copy( *(m_field->GetZero()->GetCoefficients()));
+ } else {
+ m_coefficients.SetSize(coefficientsLength - firstNonZero);
+ for(FX_INT32 i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) {
+ m_coefficients[j] = coefficients->operator [](i);
+ }
+ }
+ } else {
+ m_coefficients.Copy(*coefficients);
+ }
+}
+CFX_Int32Array* CBC_ReedSolomonGF256Poly::GetCoefficients()
+{
+ return &m_coefficients;
+}
+FX_INT32 CBC_ReedSolomonGF256Poly::GetDegree()
+{
+ return m_coefficients.GetSize() - 1;
+}
+FX_BOOL CBC_ReedSolomonGF256Poly::IsZero()
+{
+ return m_coefficients[0] == 0;
+}
+FX_INT32 CBC_ReedSolomonGF256Poly::GetCoefficients(FX_INT32 degree)
+{
+ return m_coefficients[m_coefficients.GetSize() - 1 - degree];
+}
+FX_INT32 CBC_ReedSolomonGF256Poly::EvaluateAt(FX_INT32 a)
+{
+ if(a == 0) {
+ return GetCoefficients(0);
+ }
+ FX_INT32 size = m_coefficients.GetSize();
+ if(a == 1) {
+ FX_INT32 result = 0;
+ for(FX_INT32 i = 0; i < size; i++) {
+ result = CBC_ReedSolomonGF256::AddOrSubtract(result, m_coefficients[i]);
+ }
+ return result;
+ }
+ FX_INT32 result = m_coefficients[0];
+ for(FX_INT32 j = 1; j < size; j++) {
+ result = CBC_ReedSolomonGF256::AddOrSubtract(
+ m_field->Multiply(a, result),
+ m_coefficients[j]);
+ }
+ return result;
+}
+CBC_ReedSolomonGF256Poly *CBC_ReedSolomonGF256Poly::Clone(FX_INT32 &e)
+{
+ CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &m_coefficients, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract(CBC_ReedSolomonGF256Poly* other, FX_INT32 &e)
+{
+ if(IsZero()) {
+ return other->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ if(other->IsZero()) {
+ return this->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CFX_Int32Array smallerCoefficients;
+ smallerCoefficients.Copy(m_coefficients);
+ CFX_Int32Array largerCoefficients;
+ largerCoefficients.Copy( *(other->GetCoefficients()));
+ if(smallerCoefficients.GetSize() > largerCoefficients.GetSize()) {
+ CFX_Int32Array temp;
+ temp.Copy(smallerCoefficients);
+ smallerCoefficients.Copy(largerCoefficients);
+ largerCoefficients.Copy(temp);
+ }
+ CFX_Int32Array sumDiff;
+ sumDiff.SetSize(largerCoefficients.GetSize() );
+ FX_INT32 lengthDiff = largerCoefficients.GetSize() - smallerCoefficients.GetSize();
+ for(FX_INT32 i = 0; i < lengthDiff; i++) {
+ sumDiff[i] = largerCoefficients[i];
+ }
+ for(FX_INT32 j = lengthDiff; j < largerCoefficients.GetSize(); j++) {
+ sumDiff[j] = (CBC_ReedSolomonGF256::AddOrSubtract(smallerCoefficients[j - lengthDiff],
+ largerCoefficients[j]));
+ }
+ CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &sumDiff, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(CBC_ReedSolomonGF256Poly* other, FX_INT32 &e)
+{
+ if(IsZero() || other->IsZero()) {
+ CBC_ReedSolomonGF256Poly *temp = m_field->GetZero()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+ }
+ CFX_Int32Array aCoefficients ;
+ aCoefficients.Copy(m_coefficients);
+ FX_INT32 aLength = m_coefficients.GetSize();
+ CFX_Int32Array bCoefficients;
+ bCoefficients.Copy(*(other->GetCoefficients()));
+ FX_INT32 bLength = other->GetCoefficients()->GetSize();
+ CFX_Int32Array product;
+ product.SetSize(aLength + bLength - 1);
+ for(FX_INT32 i = 0; i < aLength; i++) {
+ FX_INT32 aCoeff = m_coefficients[i];
+ for(FX_INT32 j = 0; j < bLength; j++) {
+ product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract(
+ product[i + j],
+ m_field->Multiply(aCoeff, other->GetCoefficients()->operator [](j)));
+ }
+ }
+ CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &product, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(FX_INT32 scalar, FX_INT32 &e)
+{
+ if(scalar == 0) {
+ CBC_ReedSolomonGF256Poly *temp = m_field->GetZero()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+ }
+ if(scalar == 1) {
+ return this->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ FX_INT32 size = m_coefficients.GetSize();
+ CFX_Int32Array product;
+ product.SetSize(size);
+ for(FX_INT32 i = 0; i < size; i++) {
+ product[i] = m_field->Multiply(m_coefficients[i], scalar);
+ }
+ CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &product, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+}
+CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial(FX_INT32 degree, FX_INT32 coefficient, FX_INT32 &e)
+{
+ if(degree < 0) {
+ e = BCExceptionDegreeIsNegative;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ if(coefficient == 0) {
+ CBC_ReedSolomonGF256Poly *temp = m_field->GetZero()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+ }
+ FX_INT32 size = m_coefficients.GetSize();
+ CFX_Int32Array product;
+ product.SetSize(size + degree);
+ for(FX_INT32 i = 0; i < size; i++) {
+ product[i] = (m_field->Multiply(m_coefficients[i], coefficient));
+ }
+ CBC_ReedSolomonGF256Poly *temp = FX_NEW CBC_ReedSolomonGF256Poly();
+ temp->Init(m_field, &product, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return temp;
+}
+CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly *other, FX_INT32 &e)
+{
+ if(other->IsZero()) {
+ e = BCExceptionDivideByZero;
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ }
+ CBC_ReedSolomonGF256Poly* rsg1 = m_field->GetZero()->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> quotient(rsg1);
+ CBC_ReedSolomonGF256Poly* rsg2 = this->Clone(e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> remainder(rsg2);
+ FX_INT32 denominatorLeadingTerm = other->GetCoefficients(other->GetDegree());
+ FX_INT32 inverseDenominatorLeadingTeam = m_field->Inverse(denominatorLeadingTerm, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ FX_BOOL bFirst = TRUE;
+ while(remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) {
+ FX_INT32 degreeDifference = remainder->GetDegree() - other->GetDegree();
+ FX_INT32 scale = m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())),
+ inverseDenominatorLeadingTeam);
+ CBC_ReedSolomonGF256Poly* rsg3 = other->MultiplyByMonomial(degreeDifference, scale, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> term(rsg3);
+ CBC_ReedSolomonGF256Poly* rsg4 = m_field->BuildMonomial(degreeDifference, scale, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> iteratorQuotient(rsg4);
+ CBC_ReedSolomonGF256Poly* rsg5 = quotient->AddOrSubtract(iteratorQuotient.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsg5);
+ quotient = temp;
+ CBC_ReedSolomonGF256Poly* rsg6 = remainder->AddOrSubtract(term.get(), e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp1(rsg6);
+ remainder = temp1;
+ }
+ CFX_PtrArray* tempPtrA = FX_NEW CFX_PtrArray;
+ tempPtrA->Add(quotient.release());
+ tempPtrA->Add(remainder.release());
+ return tempPtrA;
+}
+CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly()
+{
+ m_coefficients.RemoveAll();
+}
diff --git a/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h new file mode 100644 index 0000000000..a6db24e231 --- /dev/null +++ b/xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h @@ -0,0 +1,33 @@ +// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _BC_READSOLOMONGF256POLY_H_
+#define _BC_READSOLOMONGF256POLY_H_
+class CBC_ReedSolomonGF256;
+class CBC_ReedSolomonGF256Poly;
+class CBC_ReedSolomonGF256Poly : public CFX_Object
+{
+public:
+ CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, FX_INT32 coefficients);
+ CBC_ReedSolomonGF256Poly();
+ virtual ~CBC_ReedSolomonGF256Poly();
+ FX_INT32 GetCoefficients(FX_INT32 degree);
+ CFX_Int32Array* GetCoefficients();
+ FX_INT32 GetDegree();
+ FX_BOOL IsZero();
+ FX_INT32 EvaluateAt(FX_INT32 a);
+ CBC_ReedSolomonGF256Poly* AddOrSubtract(CBC_ReedSolomonGF256Poly* other, FX_INT32 &e);
+ CBC_ReedSolomonGF256Poly* Multiply(CBC_ReedSolomonGF256Poly* other, FX_INT32 &e);
+ CBC_ReedSolomonGF256Poly* Multiply(FX_INT32 scalar, FX_INT32 &e);
+ CBC_ReedSolomonGF256Poly* MultiplyByMonomial(FX_INT32 degree, FX_INT32 coefficient, FX_INT32 &e);
+ CFX_PtrArray* Divide(CBC_ReedSolomonGF256Poly *other, FX_INT32 &e);
+ CBC_ReedSolomonGF256Poly* Clone(FX_INT32 &e);
+ virtual void Init(CBC_ReedSolomonGF256* field, CFX_Int32Array* coefficients, FX_INT32 &e);
+private:
+ CBC_ReedSolomonGF256* m_field;
+ CFX_Int32Array m_coefficients;
+};
+#endif
|