summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxbarcode/cbc_pdf417i.cpp6
-rw-r--r--fxbarcode/pdf417/BC_PDF417Writer.cpp41
-rw-r--r--fxbarcode/pdf417/BC_PDF417Writer.h4
3 files changed, 18 insertions, 33 deletions
diff --git a/fxbarcode/cbc_pdf417i.cpp b/fxbarcode/cbc_pdf417i.cpp
index 4e7e063a44..0bb632ee2f 100644
--- a/fxbarcode/cbc_pdf417i.cpp
+++ b/fxbarcode/cbc_pdf417i.cpp
@@ -41,11 +41,11 @@ void CBC_PDF417I::SetTruncated(bool truncated) {
}
bool CBC_PDF417I::Encode(const WideStringView& contents) {
- int32_t outWidth = 0;
- int32_t outHeight = 0;
+ int32_t outWidth;
+ int32_t outHeight;
auto* pWriter = GetPDF417Writer();
std::unique_ptr<uint8_t, FxFreeDeleter> data(
- pWriter->Encode(WideString(contents), outWidth, outHeight));
+ pWriter->Encode(WideString(contents), &outWidth, &outHeight));
if (!data)
return false;
return pWriter->RenderResult(data.get(), outWidth, outHeight);
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.cpp b/fxbarcode/pdf417/BC_PDF417Writer.cpp
index ca96f69926..5cf9037601 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer.cpp
@@ -23,6 +23,7 @@
#include "fxbarcode/pdf417/BC_PDF417Writer.h"
#include <algorithm>
+#include <utility>
#include "fxbarcode/BC_TwoDimWriter.h"
#include "fxbarcode/common/BC_CommonBitArray.h"
@@ -49,8 +50,8 @@ void CBC_PDF417Writer::SetTruncated(bool truncated) {
}
uint8_t* CBC_PDF417Writer::Encode(const WideString& contents,
- int32_t& outWidth,
- int32_t& outHeight) {
+ int32_t* outWidth,
+ int32_t* outHeight) {
CBC_PDF417 encoder;
int32_t col = (m_Width / m_ModuleWidth - 69) / 17;
int32_t row = m_Height / (m_ModuleWidth * 20);
@@ -64,34 +65,18 @@ uint8_t* CBC_PDF417Writer::Encode(const WideString& contents,
return nullptr;
CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix();
- std::vector<uint8_t> originalScale = barcodeMatrix->getMatrix();
- int32_t width = outWidth;
- int32_t height = outHeight;
- outWidth = barcodeMatrix->getWidth();
- outHeight = barcodeMatrix->getHeight();
+ std::vector<uint8_t> matrixData = barcodeMatrix->getMatrix();
+ int32_t matrixWidth = barcodeMatrix->getWidth();
+ int32_t matrixHeight = barcodeMatrix->getHeight();
- bool rotated = false;
- if ((height > width) ^ (outWidth < outHeight)) {
- rotateArray(originalScale, outHeight, outWidth);
- rotated = true;
- int32_t temp = outHeight;
- outHeight = outWidth;
- outWidth = temp;
+ if (matrixWidth < matrixHeight) {
+ rotateArray(matrixData, matrixHeight, matrixWidth);
+ std::swap(matrixWidth, matrixHeight);
}
- int32_t scaleX = width / outWidth;
- int32_t scaleY = height / outHeight;
- int32_t scale = std::min(scaleX, scaleY);
- if (scale > 1) {
- originalScale = barcodeMatrix->getScaledMatrix(scale);
- if (rotated) {
- rotateArray(originalScale, outHeight, outWidth);
- int32_t temp = outHeight;
- outHeight = outWidth;
- outWidth = temp;
- }
- }
- uint8_t* result = FX_Alloc2D(uint8_t, outHeight, outWidth);
- memcpy(result, originalScale.data(), outHeight * outWidth);
+ uint8_t* result = FX_Alloc2D(uint8_t, matrixHeight, matrixWidth);
+ memcpy(result, matrixData.data(), matrixHeight * matrixWidth);
+ *outWidth = matrixWidth;
+ *outHeight = matrixHeight;
return result;
}
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.h b/fxbarcode/pdf417/BC_PDF417Writer.h
index ef5961653e..1bb3a27d06 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.h
+++ b/fxbarcode/pdf417/BC_PDF417Writer.h
@@ -19,8 +19,8 @@ class CBC_PDF417Writer : public CBC_TwoDimWriter {
~CBC_PDF417Writer() override;
uint8_t* Encode(const WideString& contents,
- int32_t& outWidth,
- int32_t& outHeight);
+ int32_t* outWidth,
+ int32_t* outHeight);
// CBC_TwoDimWriter
bool SetErrorCorrectionLevel(int32_t level) override;