Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor all code to use QSharePointer and std::vector #205

Merged
merged 18 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CameraImageWrapper::Factory now returns QSharedPointer instead of Raw…
… Pointer

resolves #76
  • Loading branch information
ftylitak committed Aug 7, 2021
commit 63d427243e60775e5d10df723afc46435eb5f6a2
6 changes: 3 additions & 3 deletions src/CameraImageWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CameraImageWrapper::~CameraImageWrapper()
{
}

CameraImageWrapper *CameraImageWrapper::Factory(const QImage &sourceImage, int maxWidth, int maxHeight, bool smoothTransformation)
QSharedPointer<CameraImageWrapper> CameraImageWrapper::Factory(const QImage &sourceImage, int maxWidth, int maxHeight, bool smoothTransformation)
{
if((maxWidth != -1 && sourceImage.width() > maxWidth) || (maxHeight != -1 && sourceImage.height() > maxHeight))
{
Expand All @@ -95,10 +95,10 @@ CameraImageWrapper *CameraImageWrapper::Factory(const QImage &sourceImage, int m
maxHeight != -1 ? maxHeight : sourceImage.height(),
Qt::KeepAspectRatio,
smoothTransformation ? Qt::SmoothTransformation : Qt::FastTransformation);
return new CameraImageWrapper(image);
return QSharedPointer<CameraImageWrapper>(new CameraImageWrapper(image));
}
else
return new CameraImageWrapper(sourceImage);
return QSharedPointer<CameraImageWrapper>(new CameraImageWrapper(sourceImage));
}

QSharedPointer<std::vector<QSharedPointer<std::vector<zxing::byte>>>> CameraImageWrapper::getOriginalImage()
Expand Down
2 changes: 1 addition & 1 deletion src/CameraImageWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CameraImageWrapper : public LuminanceSource
CameraImageWrapper(CameraImageWrapper& otherInstance);
~CameraImageWrapper();

static CameraImageWrapper* Factory(const QImage& image, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation=false);
static QSharedPointer<CameraImageWrapper> Factory(const QImage& image, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation=false);

QSharedPointer<std::vector<QSharedPointer<std::vector<zxing::byte>> > > getOriginalImage();
QSharedPointer<GreyscaleLuminanceSource> getDelegate() { return delegate; }
Expand Down
5 changes: 2 additions & 3 deletions src/QZXing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
return "";
}

CameraImageWrapper *ciw = ZXING_NULLPTR;
QSharedPointer<CameraImageWrapper> ciw;

if ((maxWidth > 0) || (maxHeight > 0))
ciw = CameraImageWrapper::Factory(image, maxWidth, maxHeight, smoothTransformation);
Expand All @@ -434,7 +434,7 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo

QString errorMessage = "Unknown";

QSharedPointer<LuminanceSource> imageRefOriginal = QSharedPointer<LuminanceSource>(ciw);
QSharedPointer<LuminanceSource> imageRefOriginal = ciw;
QSharedPointer<LuminanceSource> imageRef = imageRefOriginal;
QSharedPointer<GlobalHistogramBinarizer> binz;
QSharedPointer<BinaryBitmap> bb;
Expand Down Expand Up @@ -527,7 +527,6 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
int fmt = res->getBarcodeFormat().value;
decodedFormat = decoderFormatToString(1<<fmt);
charSet_ = QString::fromStdString(res->getCharSet());
qDebug() << "charSet_: " << charSet_;
if (!charSet_.isEmpty()) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QTextCodec *codec = QTextCodec::codecForName(res->getCharSet().c_str());
Expand Down