diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2018-08-22 18:43:03 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-08-22 18:43:03 +0000 |
commit | 7e7e0b8379c4bdcf3e16cd2298afe49f03fefdfb (patch) | |
tree | b4557cc0b6c792295da48431f80cb3a510fc0861 /fxbarcode | |
parent | 0928bc5aba36e47ef5c330cb1157d351bd1e72ab (diff) | |
download | pdfium-7e7e0b8379c4bdcf3e16cd2298afe49f03fefdfb.tar.xz |
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 <thestig@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fxbarcode')
-rw-r--r-- | fxbarcode/cbc_pdf417i.cpp | 6 | ||||
-rw-r--r-- | fxbarcode/pdf417/BC_PDF417Writer.cpp | 41 | ||||
-rw-r--r-- | 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<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; |