From 7e7e0b8379c4bdcf3e16cd2298afe49f03fefdfb Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Wed, 22 Aug 2018 18:43:03 +0000 Subject: Change in/out params in CBC_PDF417Writer::Encode to only out. The value passed was always 0. This also prevented the scaling from being executed, so that can be removed. Change-Id: I143a9ed31b231d3b9fa297b0bf9dcc0fa6072889 Reviewed-on: https://pdfium-review.googlesource.com/40990 Reviewed-by: Lei Zhang Reviewed-by: Ryan Harrison Commit-Queue: Henrique Nakashima --- fxbarcode/cbc_pdf417i.cpp | 6 +++--- fxbarcode/pdf417/BC_PDF417Writer.cpp | 41 ++++++++++++------------------------ fxbarcode/pdf417/BC_PDF417Writer.h | 4 ++-- 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 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 +#include #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 originalScale = barcodeMatrix->getMatrix(); - int32_t width = outWidth; - int32_t height = outHeight; - outWidth = barcodeMatrix->getWidth(); - outHeight = barcodeMatrix->getHeight(); + std::vector 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; -- cgit v1.2.3