bool UndoCache::putData(int level, const DImg& img) const { QFile file(d->cacheFile(level)); KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(d->cacheDir); unsigned long fspace = (unsigned long)(info.available()/1024.0/1024.0); kDebug() << "Free space available in Editor cache [" << d->cacheDir << "] in Mbytes: " << fspace; if (file.exists() || !file.open(QIODevice::WriteOnly) || fspace < 1024) // Check if free space is over 1 Gb to put data in cache. { return false; } QDataStream ds(&file); ds << img.width(); ds << img.height(); ds << img.sixteenBit(); ds << img.hasAlpha(); QByteArray ba((const char*)img.bits(), img.numBytes()); ds << ba; file.close(); d->cachedLevels << level; return true; }
void UndoManager::getSnapshot(int index, DImg* const img) const { DImg data = d->undoCache->getData(index); // Pass ownership of buffer. If data is null, img will be null img->putImageData(data.width(), data.height(), data.sixteenBit(), data.hasAlpha(), data.bits(), true); }
void BorderFilter::solid2(DImg& src, DImg& dest, const DColor& fg, int borderWidth) { dest = DImg(src.width() + borderWidth * 2, src.height() + borderWidth * 2, src.sixteenBit(), src.hasAlpha()); dest.fill(fg); dest.bitBltImage(&src, borderWidth, borderWidth); }
void BorderFilter::solid(DImg& src, DImg& dest, const DColor& fg, int borderWidth) { if (d->settings.orgWidth > d->settings.orgHeight) { int height = src.height() + borderWidth * 2; dest = DImg((int)(height * d->orgRatio), height, src.sixteenBit(), src.hasAlpha()); dest.fill(fg); dest.bitBltImage(&src, (dest.width() - src.width()) / 2, borderWidth); } else { int width = src.width() + borderWidth * 2; dest = DImg(width, (int)(width / d->orgRatio), src.sixteenBit(), src.hasAlpha()); dest.fill(fg); dest.bitBltImage(&src, borderWidth, (dest.height() - src.height()) / 2); } }
void BorderFilter::bevel2(DImg& src, DImg& dest, const DColor& topColor, const DColor& btmColor, int borderWidth) { int x, y; int wc; dest = DImg(src.width() + borderWidth * 2, src.height() + borderWidth * 2, src.sixteenBit(), src.hasAlpha()); // top for (y = 0, wc = (int)dest.width() - 1; y < borderWidth; ++y, --wc) { for (x = 0; x < wc; ++x) { dest.setPixelColor(x, y, topColor); } for (; x < (int)dest.width(); ++x) { dest.setPixelColor(x, y, btmColor); } } // left and right for (; y < (int)dest.height() - borderWidth; ++y) { for (x = 0; x < borderWidth; ++x) { dest.setPixelColor(x, y, topColor); } for (x = (int)dest.width() - 1; x > (int)dest.width() - borderWidth - 1; --x) { dest.setPixelColor(x, y, btmColor); } } // bottom for (wc = borderWidth; y < (int)dest.height(); ++y, --wc) { for (x = 0; x < wc; ++x) { dest.setPixelColor(x, y, topColor); } for (; x < (int)dest.width(); ++x) { dest.setPixelColor(x, y, btmColor); } } dest.bitBltImage(&src, borderWidth, borderWidth); }
void BCGFilter::applyBCG(DImg& image) { if (image.isNull()) { return; } applyBCG(image.bits(), image.width(), image.height(), image.sixteenBit()); }
void BWSepiaFilter::applyToneFilter(DImg& img, TonalityContainer& settings) { // Value to multiply RGB 8 bits component of mask used by TonalityFilter. int mul = img.sixteenBit() ? 255 : 1; settings.redMask = settings.redMask * mul; settings.greenMask = settings.greenMask * mul; settings.blueMask = settings.blueMask * mul; TonalityFilter tone(&img, 0L, settings); tone.startFilterDirectly(); img.putImageData(tone.getTargetImage().bits()); }
void RawImport::setPreviewImage() { // Preserve metadata from loaded image, and take post-processed image data d->postProcessedImage = d->previewWidget->demosaicedImage().copyMetaData(); DImg data = filter()->getTargetImage(); d->postProcessedImage.putImageData(data.width(), data.height(), data.sixteenBit(), data.hasAlpha(), data.stripImageData(), false); d->previewWidget->setPostProcessedImage(d->postProcessedImage); d->settingsBox->setPostProcessedImage(d->postProcessedImage); EditorToolIface::editorToolIface()->setToolStopProgress(); setBusy(false); }
void BorderFilter::pattern(DImg& src, DImg& dest, int borderWidth, const DColor& firstColor, const DColor& secondColor, int firstWidth, int secondWidth) { // Original image with the first solid border around. DImg tmp; solid(src, tmp, firstColor, firstWidth); // Border tiled image using pattern with second solid border around. int width, height; if (d->settings.orgWidth > d->settings.orgHeight) { height = tmp.height() + borderWidth * 2; width = (int)(height * d->orgRatio); } else { width = tmp.width() + borderWidth * 2; height = (int)(width / d->orgRatio); } DImg tmp2(width, height, tmp.sixteenBit(), tmp.hasAlpha()); qCDebug(DIGIKAM_DIMG_LOG) << "Border File:" << d->settings.borderPath; DImg border(d->settings.borderPath); if (border.isNull()) { return; } border.convertToDepthOfImage(&tmp2); for (int x = 0 ; x < width ; x += border.width()) { for (int y = 0 ; y < height ; y += border.height()) { tmp2.bitBltImage(&border, x, y); } } solid(tmp2, dest, secondColor, secondWidth); // Merge both images to one. if (d->settings.orgWidth > d->settings.orgHeight) { dest.bitBltImage(&tmp, (dest.width() - tmp.width()) / 2, borderWidth); } else { dest.bitBltImage(&tmp, borderWidth, (dest.height() - tmp.height()) / 2); } }
void BorderFilter::Private::setup(const DImg& m_orgImage) { solidColor = DColor(settings.solidColor, m_orgImage.sixteenBit()); niepceBorderColor = DColor(settings.niepceBorderColor, m_orgImage.sixteenBit()); niepceLineColor = DColor(settings.niepceLineColor, m_orgImage.sixteenBit()); bevelUpperLeftColor = DColor(settings.bevelUpperLeftColor, m_orgImage.sixteenBit()); bevelLowerRightColor = DColor(settings.bevelLowerRightColor, m_orgImage.sixteenBit()); decorativeFirstColor = DColor(settings.decorativeFirstColor, m_orgImage.sixteenBit()); decorativeSecondColor = DColor(settings.decorativeSecondColor, m_orgImage.sixteenBit()); if (settings.preserveAspectRatio) { orgRatio = (float)settings.orgWidth / (float)settings.orgHeight; int size = qMin(m_orgImage.height(), m_orgImage.width()); borderMainWidth = (int)(size * settings.borderPercent); border2ndWidth = (int)(size * 0.005); // Clamp internal border with to 1 pixel to be visible with small image. if (border2ndWidth < 1) { border2ndWidth = 1; } } }
QImage DImg::copyQImage(int x, int y, int w, int h) const { if (isNull()) { return QImage(); } DImg img = copy(x, y, w, h); if (img.sixteenBit()) { img.convertDepth(32); } return img.copyQImage(); }
TransformDescription IccTransform::getDescription(const DImg& image) { TransformDescription description; description.inputProfile = d->effectiveInputProfile(); description.outputProfile = d->outputProfile; description.intent = renderingIntentToLcmsIntent(d->intent); if (d->useBPC) { description.transformFlags |= cmsFLAGS_WHITEBLACKCOMPENSATION; } LcmsLock lock; // Do not use TYPE_BGR_ - this implies 3 bytes per pixel, but even if !image.hasAlpha(), // our image data has 4 bytes per pixel with the fourth byte filled with 0xFF. if (image.sixteenBit()) { /* switch (dkCmsGetColorSpace(description.inputProfile)) { case icSigGrayData: description.inputFormat = TYPE_GRAYA_16; break; case icSigCmykData: description.inputFormat = TYPE_CMYK_16; break; default: description.inputFormat = TYPE_BGRA_16; } */ // A Dimg is always BGRA, converted by the loader description.inputFormat = TYPE_BGRA_16; description.outputFormat = TYPE_BGRA_16; } else { description.inputFormat = TYPE_BGRA_8; description.outputFormat = TYPE_BGRA_8; } return description; }
void ImageIface::setSelection(const QString& caller, const FilterAction& action, const DImg& img) { if (img.hasAlpha() != originalHasAlpha() || img.sixteenBit() != originalSixteenBit() || img.size() != selectionRect().size() ) { kDebug() << "Properties of image to overwrite selection differs than original image"; return; } if (img.isNull()) { kDebug() << "No image data to handle"; return; } d->core->putImgSelection(caller, action, img); }
void BorderFilter::pattern2(DImg& src, DImg& dest, int borderWidth, const DColor& firstColor, const DColor& secondColor, int firstWidth, int secondWidth) { // Border tile. int w = d->settings.orgWidth + borderWidth * 2; int h = d->settings.orgHeight + borderWidth * 2; qCDebug(DIGIKAM_DIMG_LOG) << "Border File:" << d->settings.borderPath; DImg border(d->settings.borderPath); if (border.isNull()) { return; } DImg borderImg(w, h, src.sixteenBit(), src.hasAlpha()); border.convertToDepthOfImage(&borderImg); for (int x = 0 ; x < w ; x += border.width()) { for (int y = 0 ; y < h ; y += border.height()) { borderImg.bitBltImage(&border, x, y); } } // First line around the pattern tile. DImg tmp = borderImg.smoothScale(src.width() + borderWidth * 2, src.height() + borderWidth * 2); solid2(tmp, dest, firstColor, firstWidth); // Second line around original image. tmp.reset(); solid2(src, tmp, secondColor, secondWidth); // Copy original image. dest.bitBltImage(&tmp, borderWidth, borderWidth); }
void ImageIface::setPreview(const DImg& img) { if (img.hasAlpha() != previewHasAlpha() || img.sixteenBit() != previewSixteenBit() ) { kDebug() << "Properties of image differs than preview"; return; } uchar* const data = img.bits(); if (!data) { kDebug() << "No preview image data to handle"; return; } d->targetPreviewImage.detach(); d->targetPreviewImage.putImageData(data); }
SharpenFilter::SharpenFilter(DImgThreadedFilter* const parentFilter, const DImg& orgImage, const DImg& destImage, int progressBegin, int progressEnd, double radius, double sigma) : DImgThreadedFilter(parentFilter, orgImage, destImage, progressBegin, progressEnd, parentFilter->filterName() + QLatin1String(": Sharpen")) { m_radius = radius; m_sigma = sigma; // We need to provide support for orgImage == destImage. // The algorithm does not support this out of the box, so use a temporary. if (orgImage.bits() == destImage.bits()) { m_destImage = DImg(destImage.width(), destImage.height(), destImage.sixteenBit()); } filterImage(); if (orgImage.bits() == destImage.bits()) { memcpy(destImage.bits(), m_destImage.bits(), m_destImage.numBytes()); } }
void HSLFilter::applyHSL(DImg& image) { if (image.isNull()) { return; } bool sixteenBit = image.sixteenBit(); uint numberOfPixels = image.numPixels(); int progress; int hue, sat, lig; double vib = d->settings.vibrance; DColor color; if (sixteenBit) // 16 bits image. { unsigned short* data = (unsigned short*) image.bits(); for (uint i=0; runningFlag() && (i<numberOfPixels); ++i) { color = DColor(data[2], data[1], data[0], 0, sixteenBit); // convert RGB to HSL color.getHSL(&hue, &sat, &lig); // convert HSL to RGB color.setHSL(d->htransfer16[hue], vibranceBias(d->stransfer16[sat], hue, vib, sixteenBit), d->ltransfer16[lig], sixteenBit); data[2] = color.red(); data[1] = color.green(); data[0] = color.blue(); data += 4; progress = (int)(((double)i * 100.0) / numberOfPixels); if ( progress%5 == 0 ) { postProgress( progress ); } } } else // 8 bits image. { uchar* data = image.bits(); for (uint i=0; runningFlag() && (i<numberOfPixels); ++i) { color = DColor(data[2], data[1], data[0], 0, sixteenBit); // convert RGB to HSL color.getHSL(&hue, &sat, &lig); // convert HSL to RGB color.setHSL(d->htransfer[hue], vibranceBias(d->stransfer[sat],hue,vib,sixteenBit), d->ltransfer[lig], sixteenBit); data[2] = color.red(); data[1] = color.green(); data[0] = color.blue(); data += 4; progress = (int)(((double)i * 100.0) / numberOfPixels); if ( progress%5 == 0 ) { postProgress( progress ); } } } }
void RawSettingsBox::setDemosaicedImage(DImg& img) { d->curveWidget->stopHistogramComputation(); d->curveWidget->updateData(img.bits(), img.width(), img.height(), img.sixteenBit()); }
void RawSettingsBox::setPostProcessedImage(DImg& img) { histogramBox()->histogram()->stopHistogramComputation(); histogramBox()->histogram()->updateData(img.bits(), img.width(), img.height(), img.sixteenBit()); }
/** Take data from image, draw text at x|y with specified parameters. If destPainter is null, draw to image, if destPainter is not null, draw directly using the painter. Returns modified area of image. */ QRect InsertTextWidget::composeImage(DImg* const image, QPainter* const destPainter, int x, int y, QFont font, float pointSize, int textRotation, QColor textColor, int textOpacity, int alignMode, const QString& textString, bool transparentBackground, QColor backgroundColor, BorderMode borderMode, int borderWidth, int spacing, float fontScale) { /* The problem we have to solve is that we have no pixel access to font rendering, we have to let Qt do the drawing. On the other hand we need to support 16 bit, which cannot be done with QPixmap. The current solution cuts out the text area, lets Qt do its drawing, converts back and blits to original. */ int maxWidth, maxHeight; if (x == -1 && y == -1) { maxWidth = image->width(); maxHeight = image->height(); } else { maxWidth = image->width() - x; maxHeight = image->height() - y; } fontScale = qMax(0.01f, fontScale); // find out size of the area that we are drawing to font.setPointSizeF(pointSize); QFontMetrics fontMt(font); QRect fontRect = fontMt.boundingRect(0, 0, qRound(maxWidth / fontScale), qRound(maxHeight / fontScale), alignMode, textString); fontRect.setWidth(qRound(fontRect.width() * fontScale)); fontRect.setHeight(qRound(fontRect.height() * fontScale)); if (!fontRect.isValid()) { return QRect(); } int fontWidth, fontHeight; switch (textRotation) { case ROTATION_NONE: case ROTATION_180: default: fontWidth = fontRect.width(); fontHeight = fontRect.height(); break; case ROTATION_90: case ROTATION_270: fontWidth = fontRect.height(); fontHeight = fontRect.width(); break; } // x, y == -1 means that we have to find a good initial position for the text here if (x == -1 && y == -1) { int boxWidth = fontWidth + 2 * borderWidth + 2 * spacing; int boxHeight = fontHeight + 2 * borderWidth + 2 * spacing; // was a valid position hint stored from last use? if (d->positionHint.isValid()) { // We assume that people tend to orient text along the edges, // so we do some guessing so that positions such as "in the lower right corner" // will be remembered across different image sizes. // get relative positions float fromTop = (float)d->positionHint.top() / 10000.0; float fromBottom = 1.0 - (float)d->positionHint.bottom() / 10000.0; float fromLeft = (float)d->positionHint.left() / 10000.0; float fromRight = 1.0 - (float)d->positionHint.right() / 10000.0; // calculate horizontal position if (fromLeft < fromRight) { x = qRound(fromLeft * maxWidth); // we are placing from the smaller distance, // so if now the larger distance is actually too small, // fall back to standard placement, nothing to lose. if (x + boxWidth > maxWidth) { x = qMax( (maxWidth - boxWidth) / 2, 0); } } else { x = maxWidth - qRound(fromRight * maxWidth) - boxWidth; if ( x < 0 ) { x = qMax( (maxWidth - boxWidth) / 2, 0); } } // calculate vertical position if (fromTop < fromBottom) { y = qRound(fromTop * maxHeight); if (y + boxHeight > maxHeight) { y = qMax( (maxHeight - boxHeight) / 2, 0); } } else { y = maxHeight - qRound(fromBottom * maxHeight) - boxHeight; if ( y < 0 ) { y = qMax( (maxHeight - boxHeight) / 2, 0); } } if (! QRect(x, y, boxWidth, boxHeight). intersects(QRect(0, 0, maxWidth, maxHeight)) ) { // emergency fallback - nothing is visible x = qMax( (maxWidth - boxWidth) / 2, 0); y = qMax( (maxHeight - boxHeight) / 2, 0); } // invalidate position hint, use only once d->positionHint = QRect(); } else { // use standard position x = qMax( (maxWidth - boxWidth) / 2, 0); y = qMax( (maxHeight - boxHeight) / 2, 0); } } // create a rectangle relative to image QRect drawRect( x, y, fontWidth + 2 * borderWidth + 2 * spacing, fontHeight + 2 * borderWidth + 2 * spacing); // create a rectangle relative to textArea, excluding the border QRect textAreaBackgroundRect( borderWidth, borderWidth, fontWidth + 2 * spacing, fontHeight + 2 * spacing); // create a rectangle relative to textArea, excluding the border and spacing QRect textAreaTextRect( borderWidth + spacing, borderWidth + spacing, fontWidth, fontHeight ); // create a rectangle relative to textArea, including the border, // for drawing the rectangle, taking into account that the width of the QPen goes in and out in equal parts QRect textAreaDrawRect( borderWidth / 2, borderWidth / 2, fontWidth + borderWidth + 2 * spacing, fontHeight + borderWidth + 2 * spacing ); // cut out the text area DImg textArea = image->copy(drawRect); if (textArea.isNull()) { return QRect(); } // compose semi-transparent background over textArea DColorComposer* composer = DColorComposer::getComposer(DColorComposer::PorterDuffNone); if (transparentBackground) { DImg transparentLayer(textAreaBackgroundRect.width(), textAreaBackgroundRect.height(), textArea.sixteenBit(), true); DColor transparent(backgroundColor); transparent.setAlpha(d->transparency); if (image->sixteenBit()) { transparent.convertToSixteenBit(); } transparentLayer.fill(transparent); textArea.bitBlendImage(composer, &transparentLayer, 0, 0, transparentLayer.width(), transparentLayer.height(), textAreaBackgroundRect.x(), textAreaBackgroundRect.y()); } DImg textNotDrawn; if (textArea.sixteenBit()) { textNotDrawn = textArea.copy(); textNotDrawn.convertToEightBit(); } else { textNotDrawn = textArea; } // We have no direct pixel access to font rendering, so now we need to use Qt/X11 for the drawing // convert text area to pixmap QPixmap pixmap; if (destPainter) { // We working on tool preview, deal with CM as well pixmap = d->iface->convertToPixmap(textNotDrawn); } else { // We working on target image. Do no apply double CM adjustment here. pixmap = textNotDrawn.convertToPixmap(); } int fontScaleWidth = qRound(fontWidth / fontScale); int fontScaleHeight = qRound(fontHeight / fontScale); QPixmap textPixmap(fontScaleWidth, fontScaleHeight); textPixmap.fill(Qt::transparent); QPainter tp(&textPixmap); tp.setOpacity((qreal)textOpacity / 100.0); tp.setPen(QPen(textColor, 1)); tp.setFont(font); switch (textRotation) { case ROTATION_NONE: tp.drawText(0, 0, fontScaleWidth, fontScaleHeight, alignMode, textString); break; case ROTATION_90: tp.translate(fontScaleWidth, 0); tp.rotate(90.0); tp.drawText(0, 0, fontScaleHeight, fontScaleWidth, alignMode, textString); break; case ROTATION_180: tp.translate(fontScaleWidth, fontScaleHeight); tp.rotate(180.0); tp.drawText(0, 0, fontScaleWidth, fontScaleHeight, alignMode, textString); break; case ROTATION_270: tp.translate(0, fontScaleHeight); tp.rotate(270.0); tp.drawText(0, 0, fontScaleHeight, fontScaleWidth, alignMode, textString); break; } tp.end(); // paint on pixmap QPainter p(&pixmap); p.drawPixmap(textAreaTextRect, textPixmap.scaled(fontWidth, fontHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); // Drawing rectangle around text. if (borderMode == BORDER_NORMAL) // Decorative border using text color. { p.setPen( QPen(textColor, borderWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin) ) ; p.drawRect(textAreaDrawRect); } else if (borderMode == BORDER_SUPPORT) // Make simple dot line border to help user. { p.setPen(QPen(Qt::white, 1, Qt::SolidLine)); p.drawRect(textAreaDrawRect); p.setPen(QPen(Qt::red, 1, Qt::DotLine)); p.drawRect(textAreaDrawRect); } p.end(); if (!destPainter) { // convert to QImage, then to DImg QImage pixmapImage = pixmap.toImage(); DImg textDrawn(pixmapImage.width(), pixmapImage.height(), false, true, pixmapImage.bits()); // This does not work: during the conversion, colors are altered significantly (diffs of 1 to 10 in each component), // so we cannot find out which pixels have actually been touched. /* // Compare the result of drawing with the previous version. // Set all unchanged pixels to transparent DColor color, ncolor; uchar *ptr, *nptr; ptr = textDrawn.bits(); nptr = textNotDrawn.bits(); int bytesDepth = textDrawn.bytesDepth(); int numPixels = textDrawn.width() * textDrawn.height(); for (int i = 0; i < numPixels; ++i, ptr+= bytesDepth, nptr += bytesDepth) { color.setColor(ptr, false); ncolor.setColor(nptr, false); if ( color.red() == ncolor.red() && color.green() == ncolor.green() && color.blue() == ncolor.blue()) { color.setAlpha(0); color.setPixel(ptr); } } // convert to 16 bit if needed */ textDrawn.convertToDepthOfImage(&textArea); // now compose to original: only pixels affected by drawing text and border are changed, not whole area textArea.bitBlendImage(composer, &textDrawn, 0, 0, textDrawn.width(), textDrawn.height(), 0, 0); // copy result to original image image->bitBltImage(&textArea, drawRect.x(), drawRect.y()); } else { destPainter->drawPixmap(drawRect.x(), drawRect.y(), pixmap, 0, 0, pixmap.width(), pixmap.height()); } delete composer; return drawRect; }
bool UndoManager::putImageDataAndHistory(DImg* const img, int stepsBack) const { if (stepsBack <= 0 || stepsBack > d->undoActions.size()) { return false; } /* * We need to find a snapshot, for the state the given number of steps back. * 0 steps back is the current state of the EditorCore. * 1 step back is the snapshot of the last undo action, at d->undoActions.size() - 1. * The next problem is that if the corresponding action is reversible, * we do not have a snapshot, but need to walk forward to the first snapshot (or current * state), then apply the reversible steps. */ int step = d->undoActions.size() - stepsBack; int snapshot; for (snapshot = step; snapshot < d->undoActions.size(); ++snapshot) { if (dynamic_cast<UndoActionIrreversible*>(d->undoActions.at(snapshot))) { break; } } if (snapshot == step) { getSnapshot(step, img); } else { DImg reverting; // Get closest available snapshot if (snapshot < d->undoActions.size()) { getSnapshot(snapshot, &reverting); } else { reverting = d->core->getImg()->copyImageData(); } // revert reversible actions, until reaching desired step for (; snapshot > step; snapshot--) { UndoActionReversible* const reversible = dynamic_cast<UndoActionReversible*>(d->undoActions.at(snapshot - 1)); if (!reversible) // would be a bug { continue; } reversible->getReverseFilter().apply(reverting); } img->putImageData(reverting.width(), reverting.height(), reverting.sixteenBit(), reverting.hasAlpha(), reverting.stripImageData(), false); } // adjust history UndoAction* const action = d->undoActions.at(step); UndoMetadataContainer dataBeforeStep = action->getMetadata(); dataBeforeStep.toImage(*img); return true; }
void BorderFilter::bevel(DImg& src, DImg& dest, const DColor& topColor, const DColor& btmColor, int borderWidth) { int width, height; if (d->settings.orgWidth > d->settings.orgHeight) { height = src.height() + borderWidth * 2; width = (int)(height * d->orgRatio); } else { width = src.width() + borderWidth * 2; height = (int)(width / d->orgRatio); } dest = DImg(width, height, src.sixteenBit(), src.hasAlpha()); dest.fill(topColor); QPolygon btTriangle(3); btTriangle.setPoint(0, width, 0); btTriangle.setPoint(1, 0, height); btTriangle.setPoint(2, width, height); QRegion btRegion(btTriangle); // paint upper right corner QPoint upperRightCorner((width - ((width - src.width()) / 2) - 2), ((0 + (height - src.height())) / 2 + 2) ); for (int x = upperRightCorner.x(); x < width; ++x) { for (int y = 0; y < upperRightCorner.y(); ++y) { if (btRegion.contains(QPoint(x, y))) { dest.setPixelColor(x, y, btmColor); } } } // paint right border for (int x = upperRightCorner.x(); x < width; ++x) { for (int y = upperRightCorner.y(); y < height; ++y) { dest.setPixelColor(x, y, btmColor); } } // paint lower left corner QPoint lowerLeftCorner((0 + ((width - src.width()) / 2) + 2), (height - ((height - src.height()) / 2) - 2) ); for (int x = 0; x < lowerLeftCorner.x(); ++x) { for (int y = lowerLeftCorner.y(); y < height; ++y) { if (btRegion.contains(QPoint(x, y))) { dest.setPixelColor(x, y, btmColor); } } } // paint bottom border for (int x = lowerLeftCorner.x(); x < width; ++x) { for (int y = lowerLeftCorner.y(); y < height; ++y) { dest.setPixelColor(x, y, btmColor); } } if (d->settings.orgWidth > d->settings.orgHeight) { dest.bitBltImage(&src, (dest.width() - src.width()) / 2, borderWidth); } else { dest.bitBltImage(&src, borderWidth, (dest.height() - src.height()) / 2); } }