本文整理汇总了C++中KisCoordinatesConverter类的典型用法代码示例。如果您正苦于以下问题:C++ KisCoordinatesConverter类的具体用法?C++ KisCoordinatesConverter怎么用?C++ KisCoordinatesConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KisCoordinatesConverter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testMirroring
void KisCoordinatesConverterTest::testMirroring()
{
KisImageSP image;
KisCoordinatesConverter converter;
initImage(&image, &converter);
QSize widgetSize(500,400);
QSize flakeSize(1000,1000);
QRectF testRect(300, 100, 200, 200);
converter.setImage(image);
converter.setDocumentOffset(QPoint(200,100));
converter.setCanvasWidgetSize(widgetSize);
QTransform imageToWidget;
QTransform documentToWidget;
QTransform flakeToWidget;
QTransform viewportToWidget;
converter.mirror(converter.imageCenterInWidgetPixel(), true, false);
converter.setZoom(1.);
// image pixels == flake pixels
QRectF viewportRect = converter.imageToViewport(testRect);
QRectF widgetRect = converter.viewportToWidget(viewportRect);
QCOMPARE(widgetRect, QRectF(300,0,200,200));
QCOMPARE(viewportRect, QRectF(0,0,200,200));
QRectF roundTrip = converter.viewportToWidget(widgetRect);
QCOMPARE(roundTrip, viewportRect);
}
示例2: qimage
void KisPrescaledProjectionTest::testScalingUndeferredSmoothing()
{
// Set up a nice image
QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "lena.png");
// Undo adapter not necessary
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisImageSP image = new KisImage(0, qimage.width(), qimage.height(), cs, "projection test");
// 300 dpi recalculated to pixels per point (of which there are 72
// to the inch)
image->setResolution(100, 100);
KisPaintLayerSP layer = new KisPaintLayer(image, "test", OPACITY_OPAQUE_U8, cs);
image->addNode(layer.data(), image->rootLayer(), 0);
layer->paintDevice()->convertFromQImage(qimage, 0);
KisPrescaledProjection projection;
KisCoordinatesConverter converter;
converter.setImage(image);
projection.setCoordinatesConverter(&converter);
projection.setMonitorProfile(0,
KoColorConversionTransformation::internalRenderingIntent(),
KoColorConversionTransformation::internalConversionFlags());
projection.setImage(image);
testProjectionScenario(projection, &converter, "120dpi");
}
示例3: testRotation
void KisCoordinatesConverterTest::testRotation()
{
KisImageSP image;
KisCoordinatesConverter converter;
initImage(&image, &converter);
QSize widgetSize(1000,500);
QRectF testRect(800, 100, 300, 300);
converter.setImage(image);
converter.setDocumentOffset(QPoint(0,0));
converter.setCanvasWidgetSize(widgetSize);
converter.rotate(converter.widgetCenterPoint(), 30);
converter.setZoom(1.);
QTransform viewportToWidget = converter.viewportToWidgetTransform();
QRectF boundingRect = viewportToWidget.mapRect(testRect);
QRectF directRect = converter.viewportToWidget(testRect);
QCOMPARE(boundingRect, directRect);
QRectF referenceRect(QPointF(742.82,53.5898), QSizeF(409.808,409.808));
#define FUZZY(a,b) ((a)-(b) < 0.01)
QVERIFY(FUZZY(boundingRect.top(), referenceRect.top()));
QVERIFY(FUZZY(boundingRect.left(), referenceRect.left()));
QVERIFY(FUZZY(boundingRect.width(), referenceRect.width()));
QVERIFY(FUZZY(boundingRect.height(), referenceRect.height()));
}
示例4: referenceImage
void KisPrescaledProjectionTest::benchmarkUpdate()
{
QImage referenceImage(QString(FILES_DATA_DIR) + QDir::separator() + "lena.png");
QRect imageRect = QRect(QPoint(0,0), referenceImage.size());
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisImageSP image = new KisImage(0, imageRect.width(), imageRect.height(), cs, "projection test");
// set up 300dpi
image->setResolution(300 / 72 , 300 / 72);
KisPaintLayerSP layer = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, cs);
layer->paintDevice()->convertFromQImage(referenceImage, 0);
image->addNode(layer, image->rootLayer(), 0);
KisPrescaledProjection projection;
KisCoordinatesConverter converter;
converter.setImage(image);
projection.setCoordinatesConverter(&converter);
projection.setMonitorProfile(0,
KoColorConversionTransformation::internalRenderingIntent(),
KoColorConversionTransformation::internalConversionFlags());
projection.setImage(image);
// Emulate "Use same aspect as pixels"
converter.setResolution(image->xRes(), image->yRes());
converter.setZoom(1.0);
KisUpdateInfoSP info = projection.updateCache(image->bounds());
projection.recalculateCache(info);
QCOMPARE(imageRect, QRect(0,0,512,512));
QRect dirtyRect(0,0,20,20);
const qint32 numShifts = 25;
const QPoint offset(dirtyRect.width(),dirtyRect.height());
//CALLGRIND_START_INSTRUMENTATION;
QBENCHMARK {
for(qint32 i = 0; i < numShifts; i++) {
KisUpdateInfoSP tempInfo = projection.updateCache(dirtyRect);
projection.recalculateCache(tempInfo);
dirtyRect.translate(offset);
}
}
//CALLGRIND_STOP_INSTRUMENTATION;
}
示例5: testImageCropping
void KisCoordinatesConverterTest::testImageCropping()
{
KisImageSP image;
KisCoordinatesConverter converter;
initImage(&image, &converter);
converter.setImage(image);
converter.setDocumentOffset(QPoint(0,0));
converter.setCanvasWidgetSize(QSize(500,500));
converter.setZoom(1.);
// we do NOT crop here
QCOMPARE(converter.viewportToImage(QRectF(900,900,200,200)),
QRectF(900,900,200,200));
}
示例6: testConversion
void KisCoordinatesConverterTest::testConversion()
{
KisImageSP image;
KisCoordinatesConverter converter;
initImage(&image, &converter);
converter.setImage(image);
converter.setDocumentOffset(QPoint(20,20));
converter.setCanvasWidgetSize(QSize(500,500));
converter.setZoom(1.);
QRectF testRect(100,100,100,100);
QCOMPARE(converter.imageToViewport(testRect), QRectF(80,80,100,100));
QCOMPARE(converter.viewportToImage(testRect), QRectF(120,120,100,100));
QCOMPARE(converter.widgetToViewport(testRect), QRectF(100,100,100,100));
QCOMPARE(converter.viewportToWidget(testRect), QRectF(100,100,100,100));
QCOMPARE(converter.widgetToDocument(testRect), QRectF(1.20,1.20,1,1));
QCOMPARE(converter.documentToWidget(testRect), QRectF(9980,9980,10000,10000));
QCOMPARE(converter.imageToDocument(testRect), QRectF(1,1,1,1));
QCOMPARE(converter.documentToImage(testRect), QRectF(10000,10000,10000,10000));
converter.setZoom(0.5);
QCOMPARE(converter.imageToViewport(testRect), QRectF(30,30,50,50));
QCOMPARE(converter.viewportToImage(testRect), QRectF(240,240,200,200));
QCOMPARE(converter.widgetToViewport(testRect), QRectF(100,100,100,100));
QCOMPARE(converter.viewportToWidget(testRect), QRectF(100,100,100,100));
QCOMPARE(converter.widgetToDocument(testRect), QRectF(2.4,2.4,2,2));
QCOMPARE(converter.documentToWidget(testRect), QRectF(4980,4980,5000,5000));
QCOMPARE(converter.imageToDocument(testRect), QRectF(1,1,1,1));
QCOMPARE(converter.documentToImage(testRect), QRectF(10000,10000,10000,10000));
}
示例7: testConsistency
void KisCoordinatesConverterTest::testConsistency()
{
KisImageSP image;
KisCoordinatesConverter converter;
initImage(&image, &converter);
converter.setImage(image);
converter.setDocumentOffset(QPoint(20,30));
converter.setCanvasWidgetSize(QSize(500,500));
QRectF testRect(100,100,100,100);
QTransform imageToWidget;
QTransform documentToWidget;
QTransform viewportToWidget;
converter.setZoom(0.5);
imageToWidget = converter.imageToWidgetTransform();
documentToWidget = converter.documentToWidgetTransform();
viewportToWidget = converter.viewportToWidgetTransform();
QRectF fromImage = converter.viewportToWidget(converter.imageToViewport(testRect));
QRectF fromDocument = converter.documentToWidget(testRect);
QRectF fromViewport = converter.viewportToWidget(testRect);
CHECK_TRANSFORM(imageToWidget, testRect, fromImage);
CHECK_TRANSFORM(documentToWidget, testRect, fromDocument);
CHECK_TRANSFORM(viewportToWidget, testRect, fromViewport);
}
示例8: testTransformations
void KisCoordinatesConverterTest::testTransformations()
{
KisImageSP image;
KisCoordinatesConverter converter;
initImage(&image, &converter);
converter.setImage(image);
converter.setDocumentOffset(QPoint(20,30));
converter.setCanvasWidgetSize(QSize(500,500));
QRectF testRect(100,100,100,100);
QTransform imageToWidget;
QTransform documentToWidget;
QTransform flakeToWidget;
QTransform viewportToWidget;
converter.setZoom(1.);
imageToWidget = converter.imageToWidgetTransform();
documentToWidget = converter.documentToWidgetTransform();
flakeToWidget = converter.flakeToWidgetTransform();
viewportToWidget = converter.viewportToWidgetTransform();
CHECK_TRANSFORM(imageToWidget, testRect, QRectF(80,70,100,100));
CHECK_TRANSFORM(documentToWidget, testRect, QRectF(9980,9970,10000,10000));
CHECK_TRANSFORM(flakeToWidget, testRect, QRectF(80,70,100,100));
CHECK_TRANSFORM(viewportToWidget, testRect, QRectF(100,100,100,100));
converter.setZoom(0.5);
imageToWidget = converter.imageToWidgetTransform();
documentToWidget = converter.documentToWidgetTransform();
flakeToWidget = converter.flakeToWidgetTransform();
viewportToWidget = converter.viewportToWidgetTransform();
CHECK_TRANSFORM(imageToWidget, testRect, QRectF(30,20,50,50));
CHECK_TRANSFORM(documentToWidget, testRect, QRectF(4980,4970,5000,5000));
CHECK_TRANSFORM(flakeToWidget, testRect, QRectF(80,70,100,100));
CHECK_TRANSFORM(viewportToWidget, testRect, QRectF(100,100,100,100));
}
示例9: canvas
void KisQPainterCanvas::paintEvent(QPaintEvent * ev)
{
KisImageWSP image = canvas()->image();
if (image == 0) return;
setAutoFillBackground(false);
if (m_buffer.size() != size()) {
m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
}
QPainter gc(&m_buffer);
// we double buffer, so we paint on an image first, then from the image onto the canvas,
// so copy the clip region since otherwise we're filling the whole buffer every time with
// the background color _and_ the transparent squares.
gc.setClipRegion(ev->region());
KisCoordinatesConverter *converter = coordinatesConverter();
QTransform imageTransform = converter->viewportToWidgetTransform();
gc.save();
gc.setCompositionMode(QPainter::CompositionMode_Source);
gc.fillRect(QRect(QPoint(0, 0), size()), borderColor());
QTransform checkersTransform;
QPointF brushOrigin;
QPolygonF polygon;
converter->getQPainterCheckersInfo(&checkersTransform, &brushOrigin, &polygon);
gc.setPen(Qt::NoPen);
gc.setBrush(m_d->checkBrush);
gc.setBrushOrigin(brushOrigin);
gc.setTransform(checkersTransform);
gc.drawPolygon(polygon);
gc.setTransform(imageTransform);
gc.setRenderHint(QPainter::SmoothPixmapTransform, true);
QRectF viewportRect = converter->widgetToViewport(ev->rect());
gc.setCompositionMode(QPainter::CompositionMode_SourceOver);
gc.drawImage(viewportRect, m_d->prescaledProjection->prescaledQImage(),
viewportRect);
gc.restore();
#ifdef DEBUG_REPAINT
QColor color = QColor(random() % 255, random() % 255, random() % 255, 150);
gc.fillRect(ev->rect(), color);
#endif
drawDecorations(gc, ev->rect());
gc.end();
QPainter painter(this);
painter.drawImage(ev->rect(), m_buffer, ev->rect());
}
示例10: glEnable
void KisOpenGLCanvas2::drawImage()
{
if (!d->displayShader) {
return;
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
KisCoordinatesConverter *converter = coordinatesConverter();
d->displayShader->bind();
QMatrix4x4 projectionMatrix;
projectionMatrix.setToIdentity();
projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL);
// Set view/projection matrices
QMatrix4x4 modelMatrix(coordinatesConverter()->imageToWidgetTransform());
modelMatrix.optimize();
modelMatrix = projectionMatrix * modelMatrix;
d->displayShader->setUniformValue(d->displayShader->location(Uniform::ModelViewProjection), modelMatrix);
QMatrix4x4 textureMatrix;
textureMatrix.setToIdentity();
d->displayShader->setUniformValue(d->displayShader->location(Uniform::TextureMatrix), textureMatrix);
QRectF widgetRect(0,0, width(), height());
QRectF widgetRectInImagePixels = converter->documentToImage(converter->widgetToDocument(widgetRect));
qreal scaleX, scaleY;
converter->imageScale(&scaleX, &scaleY);
d->displayShader->setUniformValue(d->displayShader->location(Uniform::ViewportScale), (GLfloat) scaleX);
d->displayShader->setUniformValue(d->displayShader->location(Uniform::TexelSize), (GLfloat) d->openGLImageTextures->texelSize());
QRect ir = d->openGLImageTextures->storedImageBounds();
QRect wr = widgetRectInImagePixels.toAlignedRect();
if (!d->wrapAroundMode) {
// if we don't want to paint wrapping images, just limit the
// processing area, and the code will handle all the rest
wr &= ir;
}
int firstColumn = d->xToColWithWrapCompensation(wr.left(), ir);
int lastColumn = d->xToColWithWrapCompensation(wr.right(), ir);
int firstRow = d->yToRowWithWrapCompensation(wr.top(), ir);
int lastRow = d->yToRowWithWrapCompensation(wr.bottom(), ir);
int minColumn = d->openGLImageTextures->xToCol(ir.left());
int maxColumn = d->openGLImageTextures->xToCol(ir.right());
int minRow = d->openGLImageTextures->yToRow(ir.top());
int maxRow = d->openGLImageTextures->yToRow(ir.bottom());
int imageColumns = maxColumn - minColumn + 1;
int imageRows = maxRow - minRow + 1;
for (int col = firstColumn; col <= lastColumn; col++) {
for (int row = firstRow; row <= lastRow; row++) {
int effectiveCol = col;
int effectiveRow = row;
QPointF tileWrappingTranslation;
if (effectiveCol > maxColumn || effectiveCol < minColumn) {
int translationStep = floor(qreal(col) / imageColumns);
int originCol = translationStep * imageColumns;
effectiveCol = col - originCol;
tileWrappingTranslation.rx() = translationStep * ir.width();
}
if (effectiveRow > maxRow || effectiveRow < minRow) {
int translationStep = floor(qreal(row) / imageRows);
int originRow = translationStep * imageRows;
effectiveRow = row - originRow;
tileWrappingTranslation.ry() = translationStep * ir.height();
}
KisTextureTile *tile =
d->openGLImageTextures->getTextureTileCR(effectiveCol, effectiveRow);
if (!tile) {
warnUI << "OpenGL: Trying to paint texture tile but it has not been created yet.";
continue;
}
/*
* We create a float rect here to workaround Qt's
* "history reasons" in calculation of right()
* and bottom() coordinates of integer rects.
*/
QRectF textureRect(tile->tileRectInTexturePixels());
QRectF modelRect(tile->tileRectInImagePixels().translated(tileWrappingTranslation.x(), tileWrappingTranslation.y()));
//Setup the geometry for rendering
if (KisOpenGL::hasOpenGL3()) {
rectToVertices(d->vertices, modelRect);
d->quadBuffers[0].bind();
d->quadBuffers[0].write(0, d->vertices, 3 * 6 * sizeof(float));
//.........这里部分代码省略.........
示例11: coordinatesConverter
void KisOpenGLCanvas2::drawCheckers()
{
if (!d->checkerShader) {
return;
}
KisCoordinatesConverter *converter = coordinatesConverter();
QTransform textureTransform;
QTransform modelTransform;
QRectF textureRect;
QRectF modelRect;
QRectF viewportRect = !d->wrapAroundMode ?
converter->imageRectInViewportPixels() :
converter->widgetToViewport(this->rect());
converter->getOpenGLCheckersInfo(viewportRect,
&textureTransform, &modelTransform, &textureRect, &modelRect, d->scrollCheckers);
textureTransform *= QTransform::fromScale(d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE,
d->checkSizeScale / KisOpenGLImageTextures::BACKGROUND_TEXTURE_SIZE);
if (!d->checkerShader->bind()) {
qWarning() << "Could not bind checker shader";
return;
}
QMatrix4x4 projectionMatrix;
projectionMatrix.setToIdentity();
projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, FAR_VAL);
// Set view/projection matrices
QMatrix4x4 modelMatrix(modelTransform);
modelMatrix.optimize();
modelMatrix = projectionMatrix * modelMatrix;
d->checkerShader->setUniformValue(d->checkerShader->location(Uniform::ModelViewProjection), modelMatrix);
QMatrix4x4 textureMatrix(textureTransform);
d->checkerShader->setUniformValue(d->checkerShader->location(Uniform::TextureMatrix), textureMatrix);
//Setup the geometry for rendering
if (KisOpenGL::hasOpenGL3()) {
rectToVertices(d->vertices, modelRect);
d->quadBuffers[0].bind();
d->quadBuffers[0].write(0, d->vertices, 3 * 6 * sizeof(float));
rectToTexCoords(d->texCoords, textureRect);
d->quadBuffers[1].bind();
d->quadBuffers[1].write(0, d->texCoords, 2 * 6 * sizeof(float));
}
else {
rectToVertices(d->vertices, modelRect);
d->checkerShader->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
d->checkerShader->setAttributeArray(PROGRAM_VERTEX_ATTRIBUTE, d->vertices);
rectToTexCoords(d->texCoords, textureRect);
d->checkerShader->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
d->checkerShader->setAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE, d->texCoords);
}
// render checkers
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, d->openGLImageTextures->checkerTexture());
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindTexture(GL_TEXTURE_2D, 0);
d->checkerShader->release();
glBindBuffer(GL_ARRAY_BUFFER, 0);
}