From b0e0f73aa384eda0f2de3cca52fb536e865e0bbf Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 6 May 2015 15:03:45 +0300 Subject: [PATCH] QImage supports a maximum of 32768x32768 px images. --HG-- branch : develop --- src/app/dialogs/app/dialoglayoutsettings.cpp | 25 ++++++++++---- src/app/tablewindow.cpp | 26 +++++++++----- src/libs/vlayout/vlayoutdef.h | 11 +++--- src/libs/vlayout/vlayoutpaper.cpp | 2 ++ src/libs/vlayout/vposition.cpp | 36 ++++++++++++++++---- src/libs/vlayout/vposition.h | 2 ++ src/utils/def.h | 8 +++++ 7 files changed, 85 insertions(+), 25 deletions(-) diff --git a/src/app/dialogs/app/dialoglayoutsettings.cpp b/src/app/dialogs/app/dialoglayoutsettings.cpp index 06acfc1ff..f8012c286 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.cpp +++ b/src/app/dialogs/app/dialoglayoutsettings.cpp @@ -218,9 +218,14 @@ void DialogLayoutSettings::SetAutoCrop(bool autoCrop) void DialogLayoutSettings::TemplateSelected() { const QSizeF size = Template(); + + oldPaperUnit = PaperUnit(); + ui->doubleSpinBoxPaperWidth->setMaximum(qApp->fromPixel(QIMAGE_MAX, oldPaperUnit)); + ui->doubleSpinBoxPaperHeight->setMaximum(qApp->fromPixel(QIMAGE_MAX, oldPaperUnit)); + ui->doubleSpinBoxPaperWidth->setValue(size.width()); ui->doubleSpinBoxPaperHeight->setValue(size.height()); - oldPaperUnit = PaperUnit(); + CorrectPaperDecimals(); PaperSizeChanged(); } @@ -231,6 +236,10 @@ void DialogLayoutSettings::ConvertPaperSize() const Unit paperUnit = PaperUnit(); const qreal width = ui->doubleSpinBoxPaperWidth->value(); const qreal height = ui->doubleSpinBoxPaperHeight->value(); + + ui->doubleSpinBoxPaperWidth->setMaximum(qApp->fromPixel(QIMAGE_MAX, paperUnit)); + ui->doubleSpinBoxPaperHeight->setMaximum(qApp->fromPixel(QIMAGE_MAX, paperUnit)); + ui->doubleSpinBoxPaperWidth->setValue(VAbstractMeasurements::UnitConvertor(width, oldPaperUnit, paperUnit)); ui->doubleSpinBoxPaperHeight->setValue(VAbstractMeasurements::UnitConvertor(height, oldPaperUnit, paperUnit)); oldPaperUnit = paperUnit; @@ -244,6 +253,10 @@ void DialogLayoutSettings::ConvertLayoutSize() const Unit unit = LayoutUnit(); const qreal layoutWidth = ui->doubleSpinBoxLayoutWidth->value(); const qreal shift = ui->doubleSpinBoxShift->value(); + + ui->doubleSpinBoxLayoutWidth->setMaximum(qApp->fromPixel(QIMAGE_MAX, unit)); + ui->doubleSpinBoxShift->setMaximum(qApp->fromPixel(QIMAGE_MAX, unit)); + ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(layoutWidth, oldLayoutUnit, unit)); ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(shift, oldLayoutUnit, unit)); oldLayoutUnit = unit; @@ -425,27 +438,27 @@ QSizeF DialogLayoutSettings::Template() case PaperSizeTemplate::Roll24in: SetAutoCrop(true); width = VAbstractMeasurements::UnitConvertor(24, Unit::Inch, paperUnit); - height = VAbstractMeasurements::UnitConvertor(6000, Unit::Inch, paperUnit); + height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll30in: SetAutoCrop(true); width = VAbstractMeasurements::UnitConvertor(30, Unit::Inch, paperUnit); - height = VAbstractMeasurements::UnitConvertor(6000, Unit::Inch, paperUnit); + height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll36in: SetAutoCrop(true); width = VAbstractMeasurements::UnitConvertor(36, Unit::Inch, paperUnit); - height = VAbstractMeasurements::UnitConvertor(6000, Unit::Inch, paperUnit); + height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll42in: SetAutoCrop(true); width = VAbstractMeasurements::UnitConvertor(42, Unit::Inch, paperUnit); - height = VAbstractMeasurements::UnitConvertor(6000, Unit::Inch, paperUnit); + height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll44in: SetAutoCrop(true); width = VAbstractMeasurements::UnitConvertor(44, Unit::Inch, paperUnit); - height = VAbstractMeasurements::UnitConvertor(6000, Unit::Inch, paperUnit); + height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); default: break; diff --git a/src/app/tablewindow.cpp b/src/app/tablewindow.cpp index 072ddf29c..1dc29d50e 100644 --- a/src/app/tablewindow.cpp +++ b/src/app/tablewindow.cpp @@ -746,15 +746,23 @@ QIcon TableWindow::ScenePreview(int i) const const QRectF r = paper->rect(); // Create the image with the exact size of the shrunk scene image = QImage(QSize(static_cast(r.width()), static_cast(r.height())), QImage::Format_RGB32); - image.fill(Qt::white); - QPainter painter(&image); - painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, - Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - scenes.at(i)->render(&painter); - painter.end(); + + if (not image.isNull()) + { + image.fill(Qt::white); + QPainter painter(&image); + painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + scenes.at(i)->render(&painter); + painter.end(); + } + else + { + qWarning()<<"Cannot create image. Size too big"; + } } else { diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index 4b2a0347c..fa2bfc845 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -46,6 +46,9 @@ enum class BestFrom : char Combine = 1 }; +/* Warning! Debugging doesn't work stable in debug mode. If you need big allocation use release mode. Or disable + * Address Sanitizer. See page https://bitbucket.org/dismine/valentina/wiki/developers/Address_Sanitizer + */ //#define LAYOUT_DEBUG // Enable debug mode // This block help rule debug mode. Don't turn all options at the same time! @@ -57,11 +60,11 @@ enum class BestFrom : char // Debugging # define SHOW_CANDIDATE // Show each position -# define SHOW_ROTATION // For each position show rotation part -# define SHOW_COMBINE // For each position show edge combine part -# define SHOW_MIRROR // For each position show mirror part +//# define SHOW_ROTATION // For each position show rotation part +//# define SHOW_COMBINE // For each position show edge combine part +//# define SHOW_MIRROR // For each position show mirror part //# define SHOW_CANDIDATE_BEST // For only correct positions that pass checks -//# define SHOW_BEST // Show only best position for workpiece +# define SHOW_BEST // Show only best position for workpiece #endif//LAYOUT_DEBUG #endif // VLAYOUTDEF_H diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 68c59c032..f8c008517 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -186,6 +186,8 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop) thread_pool->setExpiryTimeout(1000); QVector threads; + QCoreApplication::processEvents(); + for (int j=1; j <= d->globalContour.EdgesCount(); ++j) { for (int i=1; i<= detail.EdgesCount(); i++) diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 42cd56952..e05998e7f 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "vposition.h" +#include "../../utils/def.h" #include #include @@ -37,6 +38,7 @@ #include #include #include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../../utils/vmath.h" #else @@ -149,33 +151,42 @@ VBestSquare VPosition::getBestResult() const void VPosition::DrawDebug(const VContour &contour, const VLayoutDetail &detail, int frame, quint32 paperIndex, int detailsCount, const QVector &details) { - QImage frameImage(contour.GetWidth()*2, contour.GetHeight()*2, QImage::Format_RGB32); + const int biasWidth = Bias(contour.GetWidth(), QIMAGE_MAX); + const int biasHeight = Bias(contour.GetHeight(), QIMAGE_MAX); + + QImage frameImage(contour.GetWidth()+biasWidth, contour.GetHeight()+biasHeight, QImage::Format_RGB32); + + if (frameImage.isNull()) + { + return; + } + frameImage.fill(Qt::white); QPainter paint; paint.begin(&frameImage); paint.setPen(QPen(Qt::darkRed, 15, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); - paint.drawRect(QRectF(contour.GetWidth()/2, contour.GetHeight()/2, contour.GetWidth(), contour.GetHeight())); + paint.drawRect(QRectF(biasWidth/2, biasHeight/2, contour.GetWidth(), contour.GetHeight())); paint.setPen(QPen(Qt::black, 6, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); QPainterPath p; if (contour.GetContour().isEmpty()) { p = DrawContour(contour.CutEdge(QLineF(0, 0, contour.GetWidth(), 0))); - p.translate(contour.GetWidth()/2, contour.GetHeight()/2); + p.translate(biasWidth/2, biasHeight/2); paint.drawPath(p); } else { p = DrawContour(contour.GetContour()); - p.translate(contour.GetWidth()/2, contour.GetHeight()/2); + p.translate(biasWidth/2, biasHeight/2); paint.drawPath(p); } #ifdef SHOW_CANDIDATE paint.setPen(QPen(Qt::darkGreen, 6, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p = DrawContour(detail.GetLayoutAllowencePoints()); - p.translate(contour.GetWidth()/2, contour.GetHeight()/2); + p.translate(biasWidth/2, biasHeight/2); paint.drawPath(p); #else Q_UNUSED(detail) @@ -185,7 +196,7 @@ void VPosition::DrawDebug(const VContour &contour, const VLayoutDetail &detail, #ifdef ARRANGED_DETAILS paint.setPen(QPen(Qt::blue, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p = DrawDetails(details); - p.translate(contour.GetWidth()/2, contour.GetHeight()/2); + p.translate(biasWidth/2, biasHeight/2); paint.drawPath(p); #else Q_UNUSED(details) @@ -197,6 +208,19 @@ void VPosition::DrawDebug(const VContour &contour, const VLayoutDetail &detail, frameImage.save (path); } +//--------------------------------------------------------------------------------------------------------------------- +int VPosition::Bias(int length, int maxLength) +{ + if (length < maxLength && length*2 < maxLength) + { + return length; + } + else + { + return maxLength-length; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutDetail &detail, int globalI, int detJ, BestFrom type) diff --git a/src/libs/vlayout/vposition.h b/src/libs/vlayout/vposition.h index ad7f16c0a..aac2fdb7e 100644 --- a/src/libs/vlayout/vposition.h +++ b/src/libs/vlayout/vposition.h @@ -68,6 +68,8 @@ public: static void DrawDebug(const VContour &contour, const VLayoutDetail &detail, int frame, quint32 paperIndex, int detailsCount, const QVector &details = QVector()); + static int Bias(int length, int maxLength); + private: Q_DISABLE_COPY(VPosition) VBestSquare bestResult; diff --git a/src/utils/def.h b/src/utils/def.h index cd02e81c2..daf5257ed 100644 --- a/src/utils/def.h +++ b/src/utils/def.h @@ -32,6 +32,14 @@ #include #include +/* QImage supports a maximum of 32768x32768 px images (signed short). + * This follows from the condition: width * height * colordepth < INT_MAX (4 billion) -> 32768 * 32768 * 4 = 4 billion. + * The second condition is of course that malloc is able to allocate the requested memory. + * + * If you really need bigger images you will have to use another wrapper or split into multiple QImage's. + */ +#define QIMAGE_MAX 32768 + /* * This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow * you to continue afterwards should you choose to.