QImage supports a maximum of 32768x32768 px images.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-05-06 15:03:45 +03:00
parent 9aa2eb79dc
commit b0e0f73aa3
7 changed files with 85 additions and 25 deletions

View File

@ -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;

View File

@ -746,6 +746,9 @@ 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<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_RGB32);
if (not image.isNull())
{
image.fill(Qt::white);
QPainter painter(&image);
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
@ -757,6 +760,11 @@ QIcon TableWindow::ScenePreview(int i) const
painter.end();
}
else
{
qWarning()<<"Cannot create image. Size too big";
}
}
else
{
image = QImage(QSize(101, 146), QImage::Format_RGB32);
image.fill(Qt::white);

View File

@ -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

View File

@ -186,6 +186,8 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop)
thread_pool->setExpiryTimeout(1000);
QVector<VPosition *> threads;
QCoreApplication::processEvents();
for (int j=1; j <= d->globalContour.EdgesCount(); ++j)
{
for (int i=1; i<= detail.EdgesCount(); i++)

View File

@ -27,6 +27,7 @@
*************************************************************************/
#include "vposition.h"
#include "../../utils/def.h"
#include <QPointF>
#include <QRectF>
@ -37,6 +38,7 @@
#include <QPainter>
#include <QCoreApplication>
#include <QDir>
#include <QtWidgets>
#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<VLayoutDetail> &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)

View File

@ -68,6 +68,8 @@ public:
static void DrawDebug(const VContour &contour, const VLayoutDetail &detail, int frame, quint32 paperIndex,
int detailsCount, const QVector<VLayoutDetail> &details = QVector<VLayoutDetail>());
static int Bias(int length, int maxLength);
private:
Q_DISABLE_COPY(VPosition)
VBestSquare bestResult;

View File

@ -32,6 +32,14 @@
#include <csignal>
#include <QtGlobal>
/* 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.