void KisAsyncMergerTest::debugObligeChild() { const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(0, 640, 441, colorSpace, "merger test"); QImage sourceImage1(QString(FILES_DATA_DIR) + QDir::separator() + "hakonepa.png"); KisPaintDeviceSP device1 = new KisPaintDevice(colorSpace); device1->convertFromQImage(sourceImage1, 0, 0, 0); KisLayerSP paintLayer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, device1); KisLayerSP groupLayer = new KisGroupLayer(image, "group", OPACITY_OPAQUE_U8); image->addNode(groupLayer, image->rootLayer()); image->addNode(paintLayer1, groupLayer); QRect testRect1(0,0,640,441); QRect cropRect(image->bounds()); KisMergeWalker walker(cropRect); KisAsyncMerger merger; walker.collectRects(paintLayer1, testRect1); merger.startMerge(walker); KisLayerSP rootLayer = image->rootLayer(); QVERIFY(rootLayer->original() == groupLayer->projection()); QVERIFY(groupLayer->original() == paintLayer1->projection()); }
bool ASM_Gaze_Tracker::calculatePupilCenter(){ Mat leftEyeImg,rightEyeImg,cropped; if (isTrackingSuccess == false) { return false; } canthusPts = vector<Point2f>(tracker.points.begin(),tracker.points.begin()+4); nosePts = vector<Point2f>(tracker.points.begin()+4,tracker.points.begin()+6); if (canthusPts[2].x < canthusPts[0].x && canthusPts[0].x < canthusPts[1].x && canthusPts[1].x < canthusPts[3].x) { } else { return false; } eyePairTileAngle = calculateEyePairTileAngle(canthusPts); glabellaPoint= caculateEyePairCenter(canthusPts); rotationMatrix = getRotationMatrix2D(glabellaPoint, eyePairTileAngle, 1.0); Mat Mback = getRotationMatrix2D(glabellaPoint, -eyePairTileAngle, 1.0); vector<Point2f> rotatedCanthusPts = rotatePointsByRotationMatrix(canthusPts, rotationMatrix); vector<Point2f> rotatedNosePts = rotatePointsByRotationMatrix(nosePts, rotationMatrix); float eyePairRectWidth =abs(rotatedCanthusPts[2].x - rotatedCanthusPts[3].x)+1; Size2f eyePairRectSize(eyePairRectWidth,eyePairRectWidth/7); Rect cropRect(Point2f(glabellaPoint.x-eyePairRectWidth/2,glabellaPoint.y -eyePairRectWidth/14.0f),eyePairRectSize); warpAffine(im, rotated_img, rotationMatrix, im.size(),CV_INTER_LINEAR); getRectSubPix(rotated_img, eyePairRectSize, glabellaPoint, cropped); Rect leftEyeRect = Rect(0,0,rotatedCanthusPts[0].x-rotatedCanthusPts[2].x,eyePairRectSize.height); Rect rightEyeRect = Rect(rotatedCanthusPts[1].x-rotatedCanthusPts[2].x,0,rotatedCanthusPts[3].x-rotatedCanthusPts[1].x,eyePairRectSize.height); if (leftEyeRect.area() < 50 || rightEyeRect.area()< 50) { return false; } Point2f leftEyeCenter, rightEyeCenter; // findEyeCenterByColorSegmentation(cropped(leftEyeRect), leftEyeCenter); // findEyeCenterByColorSegmentation(cropped(rightEyeRect), rightEyeCenter); // cout<<"debug"<<endl; boost::thread leftEyeThread(findEyeCenterByColorSegmentation, cropped(leftEyeRect), boost::ref(leftEyeCenter), 0.4,3,3,5); boost::thread rightEyeThread(findEyeCenterByColorSegmentation, cropped(rightEyeRect), boost::ref(rightEyeCenter), 0.4,3,3,5); leftEyeThread.join(); rightEyeThread.join(); leftEyeCenter += Point2f(leftEyeRect.tl().x,leftEyeRect.tl().y); leftEyeCenter += Point2f(cropRect.tl().x, cropRect.tl().y); rightEyeCenter += Point2f(rightEyeRect.tl().x,rightEyeRect.tl().y); rightEyeCenter += Point2f(cropRect.tl().x,cropRect.tl().y); leftEyePoint= rotatePointByRotationMatrix(leftEyeCenter, Mback); rightEyePoint= rotatePointByRotationMatrix(rightEyeCenter, Mback); isTrackingSuccess = true; return true; }
void onDraw(SkCanvas* canvas) override { void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = { draw_bitmap, draw_path, draw_paint, draw_text }; sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(SkIntToScalar(-10), SkIntToScalar(-10), nullptr)); sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Make(cf, std::move(offset))); sk_sp<SkImageFilter> erodeX(SkErodeImageFilter::Make(8, 0, nullptr, &cropRect)); sk_sp<SkImageFilter> erodeY(SkErodeImageFilter::Make(0, 8, nullptr, &cropRect)); sk_sp<SkImageFilter> filters[] = { nullptr, SkColorFilterImageFilter::Make(cf, nullptr, &cropRect), SkBlurImageFilter::Make(0.0f, 0.0f, nullptr, &cropRect), SkBlurImageFilter::Make(1.0f, 1.0f, nullptr, &cropRect), SkBlurImageFilter::Make(8.0f, 0.0f, nullptr, &cropRect), SkBlurImageFilter::Make(0.0f, 8.0f, nullptr, &cropRect), SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &cropRect), SkErodeImageFilter::Make(1, 1, nullptr, &cropRect), SkErodeImageFilter::Make(8, 0, std::move(erodeY), &cropRect), SkErodeImageFilter::Make(0, 8, std::move(erodeX), &cropRect), SkErodeImageFilter::Make(8, 8, nullptr, &cropRect), SkMergeImageFilter::Make(nullptr, std::move(cfOffset), SkXfermode::kSrcOver_Mode, &cropRect), SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect), SkColorFilterImageFilter::Make(cf, nullptr, &bogusRect), }; SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); SkScalar MARGIN = SkIntToScalar(16); SkScalar DX = r.width() + MARGIN; SkScalar DY = r.height() + MARGIN; canvas->translate(MARGIN, MARGIN); for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) { canvas->save(); for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { SkPaint paint; canvas->drawBitmap(fCheckerboard, 0, 0); drawProc[j](canvas, r, filters[i]); canvas->translate(0, DY); } canvas->restore(); canvas->translate(DX, 0); } }
void ImageEditorScene::updateBorderRects() { if (not isImageLoaded()) return; // Top m_border_rects[0]->setRect(QRectF(scaledImageRect().topLeft(), QPointF(scaledImageRect().right(), m_crop_position.y()))); // Left m_border_rects[1]->setRect(QRectF(QPointF(0, cropRect().top()+1), cropRect().bottomLeft() - QPointF(0, 1))); // Bottom m_border_rects[2]->setRect(QRectF(QPointF(0, cropRect().bottom()), scaledImageRect().bottomRight())); // Right m_border_rects[3]->setRect(QRectF(QPointF(cropRect().right(), cropRect().top()+1), QPointF(scaledImageRect().right(), cropRect().bottom())- QPointF(0, 1))); }
SkImageFilter* SkRectShaderImageFilter::Create(SkShader* s, const SkRect& rect) { SkASSERT(s); uint32_t flags = CropRect::kHasAll_CropEdge; if (rect.width() == 0 || rect.height() == 0) { flags = 0x0; } CropRect cropRect(rect, flags); return s ? new SkRectShaderImageFilter(s, &cropRect) : nullptr; }
SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, const SkRect& rect) { SkASSERT(s); uint32_t flags = CropRect::kHasAll_CropEdge; if (rect.width() == 0 || rect.height() == 0) { flags = 0x0; } CropRect cropRect(rect, flags); return s ? SkNEW_ARGS(SkRectShaderImageFilter, (s, &cropRect)) : NULL; }
virtual void onDraw(SkCanvas* canvas) override { void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text }; SkAutoTUnref<SkColorFilter> cf( SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create( SkIntToScalar(-10), SkIntToScalar(-10))); SkAutoTUnref<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf.get(), offset.get())); SkAutoTUnref<SkImageFilter> erodeX(SkErodeImageFilter::Create(8, 0, NULL, &cropRect)); SkAutoTUnref<SkImageFilter> erodeY(SkErodeImageFilter::Create(0, 8, NULL, &cropRect)); SkImageFilter* filters[] = { NULL, SkColorFilterImageFilter::Create(cf.get(), NULL, &cropRect), SkBlurImageFilter::Create(1.0f, 1.0f, NULL, &cropRect), SkBlurImageFilter::Create(8.0f, 0.0f, NULL, &cropRect), SkBlurImageFilter::Create(0.0f, 8.0f, NULL, &cropRect), SkBlurImageFilter::Create(8.0f, 8.0f, NULL, &cropRect), SkErodeImageFilter::Create(1, 1, NULL, &cropRect), SkErodeImageFilter::Create(8, 0, erodeY, &cropRect), SkErodeImageFilter::Create(0, 8, erodeX, &cropRect), SkErodeImageFilter::Create(8, 8, NULL, &cropRect), SkMergeImageFilter::Create(NULL, cfOffset.get(), SkXfermode::kSrcOver_Mode, &cropRect), SkBlurImageFilter::Create(8.0f, 8.0f, NULL, &bogusRect), SkColorFilterImageFilter::Create(cf.get(), NULL, &bogusRect), }; SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); SkScalar MARGIN = SkIntToScalar(16); SkScalar DX = r.width() + MARGIN; SkScalar DY = r.height() + MARGIN; canvas->translate(MARGIN, MARGIN); for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) { canvas->save(); for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { SkPaint paint; canvas->drawBitmap(fCheckerboard, 0, 0); drawProc[j](canvas, r, filters[i]); canvas->translate(0, DY); } canvas->restore(); canvas->translate(DX, 0); } for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { SkSafeUnref(filters[j]); } }
bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { if (cropRect().isLargest()) { if (filter) { *filter = fColorFilter; fColorFilter->ref(); } return true; } return false; }
bool photoController::crop(const cv::Mat &cv_img) { START_CHRONOMETER(); cv::Size img_size = cv_img.size(); int height = (int)(img_size.width * VIDEO_PROPORTION); cv::Rect cropRect(0, (img_size.height - height)/2, 1920, height); cv::Mat cropped = cv_img(cropRect); cv::Size raw_size = cropped.size(); DEBUG_PRINTF(V_MESSAGE, "crop() cv::Mat total=%u width=%d height=%d refcount=%d\n", cropped.total(), raw_size.width, raw_size.height, (int)(void*)cropped.refcount); STOP_CHRONOMETER("Frame crop"); bool result = resize(cropped); cropped.release(); return result; }
void onDraw(SkCanvas* canvas) override { void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = { draw_bitmap, draw_path, draw_paint, draw_text }; sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA, SkBlendMode::kSrcIn)); sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr)); SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); sk_sp<SkImageFilter> filters[] = { nullptr, SkDropShadowImageFilter::Make(7.0f, 0.0f, 0.0f, 3.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr), SkDropShadowImageFilter::Make(0.0f, 7.0f, 3.0f, 0.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr), SkDropShadowImageFilter::Make(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr), SkDropShadowImageFilter::Make(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, std::move(cfif)), SkDropShadowImageFilter::Make(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr, &cropRect), SkDropShadowImageFilter::Make(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr, &bogusRect), SkDropShadowImageFilter::Make(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode, nullptr), }; SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); SkScalar MARGIN = SkIntToScalar(16); SkScalar DX = r.width() + MARGIN; SkScalar DY = r.height() + MARGIN; canvas->translate(MARGIN, MARGIN); for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) { canvas->save(); for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { drawProc[j](canvas, r, filters[i]); canvas->translate(0, DY); } canvas->restore(); canvas->translate(DX, 0); } }
SkImageFilter* SkTileImageFilter::Create(const SkRect& srcRect, const SkRect& dstRect, SkImageFilter* input) { if (!SkIsValidRect(srcRect) || !SkIsValidRect(dstRect)) { return nullptr; } if (srcRect.width() == dstRect.width() && srcRect.height() == dstRect.height()) { SkRect ir = dstRect; if (!ir.intersect(srcRect)) { return SkSafeRef(input); } CropRect cropRect(ir); return SkOffsetImageFilter::Create(dstRect.x() - srcRect.x(), dstRect.y() - srcRect.y(), input, &cropRect); } return new SkTileImageFilter(srcRect, dstRect, input); }
sk_sp<SkImageFilter> SkTileImageFilter::Make(const SkRect& srcRect, const SkRect& dstRect, sk_sp<SkImageFilter> input) { if (!SkIsValidRect(srcRect) || !SkIsValidRect(dstRect)) { return nullptr; } if (srcRect.width() == dstRect.width() && srcRect.height() == dstRect.height()) { SkRect ir = dstRect; if (!ir.intersect(srcRect)) { return input; } CropRect cropRect(ir); return SkOffsetImageFilter::Make(dstRect.x() - srcRect.x(), dstRect.y() - srcRect.y(), std::move(input), &cropRect); } return sk_sp<SkImageFilter>(new SkTileImageFilter(srcRect, dstRect, std::move(input))); }
virtual void onDraw(SkCanvas* canvas) { void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text }; SkAutoTUnref<SkColorFilter> cf( SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode)); SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get())); SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); SkImageFilter* filters[] = { NULL, new SkDropShadowImageFilter(7.0f, 0.0f, 0.0f, 3.0f, SK_ColorBLUE), new SkDropShadowImageFilter(0.0f, 7.0f, 3.0f, 0.0f, SK_ColorBLUE), new SkDropShadowImageFilter(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE), new SkDropShadowImageFilter(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, cfif), new SkDropShadowImageFilter(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, NULL, &cropRect), new SkDropShadowImageFilter(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE, NULL, &bogusRect), }; SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); SkScalar MARGIN = SkIntToScalar(16); SkScalar DX = r.width() + MARGIN; SkScalar DY = r.height() + MARGIN; canvas->translate(MARGIN, MARGIN); for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) { canvas->save(); for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { drawProc[j](canvas, r, filters[i]); canvas->translate(0, DY); } canvas->restore(); canvas->translate(DX, 0); } for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { SkSafeUnref(filters[j]); } }
void KisAsyncMergerTest::testSubgraphingWithoutUpdatingParent() { const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(0, 128, 128, colorSpace, "clones test"); KisPaintDeviceSP device1 = new KisPaintDevice(colorSpace); device1->fill(image->bounds(), KoColor(Qt::white, colorSpace)); KisLayerSP paintLayer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, device1); KisPaintDeviceSP device2 = new KisPaintDevice(colorSpace); device2->fill(image->bounds(), KoColor(Qt::black, colorSpace)); KisLayerSP paintLayer2 = new KisPaintLayer(image, "paint2", 128, device2); image->addNode(paintLayer1, image->rootLayer()); image->addNode(paintLayer2, image->rootLayer()); image->initialRefreshGraph(); QImage refImage(QString(FILES_DATA_DIR) + QDir::separator() + "subgraphing_without_updating.png"); { QImage resultImage = image->projection()->convertToQImage(0); QCOMPARE(resultImage, refImage); } QRect cropRect(image->bounds()); KisRefreshSubtreeWalker walker(cropRect); KisAsyncMerger merger; walker.collectRects(paintLayer2, image->bounds()); merger.startMerge(walker); { QImage resultImage = image->projection()->convertToQImage(0); QCOMPARE(resultImage, refImage); } }
virtual void onDraw(SkCanvas* canvas) { if (!fOnce) { make_bitmap(); fOnce = true; } struct { int fWidth, fHeight; int fRadiusX, fRadiusY; } samples[] = { { 140, 140, 0, 0 }, { 140, 140, 0, 2 }, { 140, 140, 2, 0 }, { 140, 140, 2, 2 }, { 24, 24, 25, 25 }, }; SkPaint paint; SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(25, 20, 100, 80)); for (unsigned j = 0; j < 4; ++j) { for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) { const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : NULL; if (j & 0x01) { paint.setImageFilter(SkErodeImageFilter::Create( samples[i].fRadiusX, samples[i].fRadiusY, NULL, cr))->unref(); } else { paint.setImageFilter(SkDilateImageFilter::Create( samples[i].fRadiusX, samples[i].fRadiusY, NULL, cr))->unref(); } drawClippedBitmap(canvas, paint, i * 140, j * 140); } } }
DEF_SIMPLE_GM_BG(imagemagnifier_cropped, canvas, WIDTH_HEIGHT, WIDTH_HEIGHT, SK_ColorBLACK) { sk_sp<SkImage> image(make_img()); sk_sp<SkImageFilter> imageSource(SkImageSource::Make(std::move(image))); SkRect srcRect = SkRect::MakeWH(SkIntToScalar(WIDTH_HEIGHT-32), SkIntToScalar(WIDTH_HEIGHT-32)); srcRect.inset(64.0f, 64.0f); static const SkScalar kInset = 64.0f; // Crop out a 16 pixel ring around the result const SkRect rect = SkRect::MakeXYWH(16, 16, WIDTH_HEIGHT-32, WIDTH_HEIGHT-32); SkImageFilter::CropRect cropRect(rect); SkPaint filterPaint; filterPaint.setImageFilter(SkMagnifierImageFilter::Make(srcRect, kInset, std::move(imageSource), &cropRect)); canvas->saveLayer(nullptr, &filterPaint); canvas->restore(); }
void PictureShape::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintContext) { Q_UNUSED(paintContext); QRectF viewRect = converter.documentToView(QRectF(QPointF(0,0), size())); if (imageData() == 0) { painter.fillRect(viewRect, QColor(Qt::gray)); return; } painter.save(); applyConversion(painter, converter); paintBorder(painter, converter); painter.restore(); QSize pixmapSize = calcOptimalPixmapSize(viewRect.size(), imageData()->image().size()); // Normalize the clipping rect if it isn't already done. m_clippingRect.normalize(imageData()->imageSize()); // Handle style:mirror, i.e. mirroring horizontally and/or vertically. // // NOTE: At this time we don't handle HorizontalOnEven // and HorizontalOnOdd, which have to know which // page they are on. In those cases we treat it as // no horizontal mirroring at all. bool doFlip = false; QSizeF shapeSize = size(); QSizeF viewSize = converter.documentToView(shapeSize); qreal midpointX = 0.0; qreal midpointY = 0.0; qreal scaleX = 1.0; qreal scaleY = 1.0; if (m_mirrorMode & MirrorHorizontal) { midpointX = viewSize.width() / qreal(2.0); scaleX = -1.0; doFlip = true; } if (m_mirrorMode & MirrorVertical) { midpointY = viewSize.height() / qreal(2.0); scaleY = -1.0; doFlip = true; } if (doFlip) { QTransform outputTransform = painter.transform(); QTransform worldTransform = QTransform(); //kDebug(31000) << "Flipping" << midpointX << midpointY << scaleX << scaleY; worldTransform.translate(midpointX, midpointY); worldTransform.scale(scaleX, scaleY); worldTransform.translate(-midpointX, -midpointY); //kDebug(31000) << "After flipping for window" << worldTransform; QTransform newTransform = worldTransform * outputTransform; painter.setWorldTransform(newTransform); } // Paint the image as prepared in waitUntilReady() if (!m_printQualityImage.isNull() && pixmapSize != m_printQualityRequestedSize) { QSizeF imageSize = m_printQualityImage.size(); QRectF cropRect( imageSize.width() * m_clippingRect.left, imageSize.height() * m_clippingRect.top, imageSize.width() * m_clippingRect.width(), imageSize.height() * m_clippingRect.height() ); painter.drawImage(viewRect, m_printQualityImage, cropRect); m_printQualityImage = QImage(); // free memory } else { QPixmap pixmap; QString key(generate_key(imageData()->key(), pixmapSize)); // If the required pixmap is not in the cache // launch a task in a background thread that scales // the source image to the required size if (!QPixmapCache::find(key, &pixmap)) { QThreadPool::globalInstance()->start(new _Private::PixmapScaler(this, pixmapSize)); painter.fillRect(viewRect, QColor(Qt::gray)); // just paint a gray rect as long as we don't have the required pixmap } else { QRectF cropRect( pixmapSize.width() * m_clippingRect.left, pixmapSize.height() * m_clippingRect.top, pixmapSize.width() * m_clippingRect.width(), pixmapSize.height() * m_clippingRect.height() ); painter.drawPixmap(viewRect, pixmap, cropRect); } } }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmaps(); fInitialized = true; } canvas->clear(0x00000000); SkPaint paint; SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unref(); drawClippedBitmap(canvas, 0, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unref(); drawClippedBitmap(canvas, 100, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unref(); drawClippedBitmap(canvas, 200, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ))->unref(); drawClippedBitmap(canvas, 300, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ))->unref(); drawClippedBitmap(canvas, 400, 0, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 0, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 100, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 200, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 300, 100, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 400, 100, paint); SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 0, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 100, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 200, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 300, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 400, 200, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 0, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 100, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 200, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 300, 300, paint); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, NULL, &cropRect))->unref(); drawClippedBitmap(canvas, 400, 300, paint); // Tests for images of different sizes displ.reset(SkBitmapSource::Create(fSmall)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 0, 400, paint); displ.reset(SkBitmapSource::Create(fLarge)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 100, 400, paint); displ.reset(SkBitmapSource::Create(fLargeW)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 200, 400, paint); displ.reset(SkBitmapSource::Create(fLargeH)); paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref(); drawClippedBitmap(canvas, 300, 400, paint); // Test for no given displacement input. In this case, both displacement // and color should use the same bitmap, given to SkCanvas::drawBitmap() // as an input argument. paint.setImageFilter(SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, NULL))->unref(); drawClippedBitmap(canvas, 400, 400, paint); }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); fInitialized = true; } canvas->clear(0xFF101010); SkPaint checkPaint; checkPaint.setColor(0xFF202020); for (int y = 0; y < HEIGHT; y += 16) { for (int x = 0; x < WIDTH; x += 16) { canvas->save(); canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint); canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint); canvas->restore(); } } SkPoint3 pointLocation(0, 0, SkIntToScalar(10)); SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225)); SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); SkPoint3 distantDirection(SkScalarMul(SkScalarCos(azimuthRad), SkScalarCos(elevationRad)), SkScalarMul(SkScalarSin(azimuthRad), SkScalarCos(elevationRad)), SkScalarSin(elevationRad)); SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToScalar(20)); SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0); SkScalar spotExponent = SK_Scalar1; SkScalar cutoffAngle = SkIntToScalar(15); SkScalar kd = SkIntToScalar(2); SkScalar ks = SkIntToScalar(1); SkScalar shininess = SkIntToScalar(8); SkScalar surfaceScale = SkIntToScalar(1); SkColor white(0xFFFFFFFF); SkPaint paint; SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); int y = 0; for (int i = 0; i < 2; i++) { const SkImageFilter::CropRect* cr = (i == 0) ? NULL : &cropRect; paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 0, y); paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection, white, surfaceScale, kd, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 110, y); paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 220, y); y += 110; paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 0, y); paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 110, y); paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shininess, NULL, cr))->unref(); drawClippedBitmap(canvas, paint, 220, y); y += 110; } }
void onDraw(SkCanvas* canvas) override { SkImageFilter::CropRect cropRect( SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); sk_sp<SkImage> gradientCircle(MakeGradientCircle(64, 64)); SkBitmap checkerboard; MakeCheckerboard(&checkerboard); sk_sp<SkImageFilter> gradientCircleSource(SkImageSource::Make(std::move(gradientCircle))); sk_sp<SkImageFilter> noopCropped(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect)); // This color matrix saturates the green component but only partly increases the opacity. // For the opaque checkerboard, the opacity boost doesn't matter but it does impact the // area outside the checkerboard. SkScalar matrix[20] = { 1, 0, 0, 0, 0, 0, 1, 0, 0, 255, 0, 0, 1, 0, 0, 0, 0, 0, 1, 32 }; sk_sp<SkColorFilter> cfAlphaTrans(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); SkScalar MARGIN = SkIntToScalar(12); SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); SkScalar kd = SkIntToScalar(2); SkScalar surfaceScale = SkIntToScalar(1); SkIRect bounds; r.roundOut(&bounds); SkPaint paint; canvas->translate(MARGIN, MARGIN); for (int outset = -15; outset <= 20; outset += 5) { canvas->save(); SkRect rect = cropRect.rect(); rect.outset(SkIntToScalar(outset), SkIntToScalar(outset)); SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasAll_CropEdge); Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Make(cfAlphaTrans, noopCropped, &bigRect)); Draw(canvas, checkerboard, rect, SkBlurImageFilter::Make(0.3f, 0.3f, noopCropped, &bigRect)); Draw(canvas, checkerboard, rect, SkBlurImageFilter::Make(8.0f, 8.0f, noopCropped, &bigRect)); Draw(canvas, checkerboard, rect, SkDilateImageFilter::Make(2, 2, noopCropped, &bigRect)); Draw(canvas, checkerboard, rect, SkErodeImageFilter::Make(2, 2, noopCropped, &bigRect)); Draw(canvas, checkerboard, rect, SkDropShadowImageFilter::Make( SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(3), SkIntToScalar(3), SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, noopCropped, &bigRect)); Draw(canvas, checkerboard, rect, SkDisplacementMapEffect::Make(SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kR_ChannelSelectorType, SkIntToScalar(12), gradientCircleSource, noopCropped, &bigRect)); Draw(canvas, checkerboard, rect, SkOffsetImageFilter::Make(SkIntToScalar(-8), SkIntToScalar(16), noopCropped, &bigRect)); Draw(canvas, checkerboard, rect, SkLightingImageFilter::MakePointLitDiffuse(pointLocation, SK_ColorWHITE, surfaceScale, kd, noopCropped, &bigRect)); canvas->restore(); canvas->translate(0, SkIntToScalar(80)); } }
void KisAsyncMergerTest::testFullRefreshWithClones() { const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(0, 128, 128, colorSpace, "clones test"); KisPaintDeviceSP device1 = new KisPaintDevice(colorSpace); device1->fill(image->bounds(), KoColor( Qt::white, colorSpace)); KisFilterSP filter = KisFilterRegistry::instance()->value("invert"); Q_ASSERT(filter); KisFilterConfiguration *configuration = filter->defaultConfiguration(0); Q_ASSERT(configuration); KisLayerSP paintLayer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, device1); KisFilterMaskSP invertMask1 = new KisFilterMask(); invertMask1->initSelection(0, paintLayer1); invertMask1->setFilter(configuration); KisLayerSP cloneLayer1 = new KisCloneLayer(paintLayer1, image, "clone_of_1", OPACITY_OPAQUE_U8); /** * The clone layer must have a projection to allow us * to read what it got from its source. Just shift it. */ cloneLayer1->setX(10); cloneLayer1->setY(10); image->addNode(cloneLayer1, image->rootLayer()); image->addNode(paintLayer1, image->rootLayer()); image->addNode(invertMask1, paintLayer1); QRect cropRect(image->bounds()); KisFullRefreshWalker walker(cropRect); KisAsyncMerger merger; walker.collectRects(image->rootLayer(), image->bounds()); merger.startMerge(walker); // Wait for additional jobs generated by the clone are finished image->waitForDone(); QRect filledRect(10, 10, image->width() - cloneLayer1->x(), image->height() - cloneLayer1->y()); const int pixelSize = device1->pixelSize(); const int numPixels = filledRect.width() * filledRect.height(); QByteArray bytes(numPixels * pixelSize, 13); cloneLayer1->projection()->readBytes((quint8*)bytes.data(), filledRect); KoColor desiredPixel(Qt::black, colorSpace); quint8 *srcPtr = (quint8*)bytes.data(); quint8 *dstPtr = desiredPixel.data(); for(int i = 0; i < numPixels; i++) { if(memcmp(srcPtr, dstPtr, pixelSize)) { qDebug() << "expected:" << dstPtr[0] << dstPtr[1] << dstPtr[2] << dstPtr[3]; qDebug() << "result: " << srcPtr[0] << srcPtr[1] << srcPtr[2] << srcPtr[3]; QFAIL("Failed to compare pixels"); } srcPtr += pixelSize; } }
void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); { sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage)); sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkBlendMode::kSrcIn)); sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource))); sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur)); sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Make(std::move(cf), std::move(erode))); sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color, SkBlendMode::kSrcOver)); SkPaint paint; paint.setImageFilter(std::move(merge)); canvas->drawPaint(paint); canvas->translate(SkIntToScalar(100), 0); } { sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr)); SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, 0.5f, 0 }; sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter), std::move(morph))); SkPaint paint; paint.setImageFilter(SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver, std::move(colorMorph))); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } { SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, 0, 0, 0.5f, 0 }; sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF), nullptr)); sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(10.0f, 10.f, matrixFilter)); SkPaint paint; paint.setImageFilter( SkXfermodeImageFilter::MakeArithmetic(0, 1, 1, 0, true, std::move(matrixFilter), std::move(offsetFilter), nullptr)); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } { sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(SkIntToScalar(10), SkIntToScalar(10), nullptr)); SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100))); SkPaint paint; paint.setImageFilter( SkXfermodeImageFilter::Make(SkBlendMode::kSrcIn, std::move(blur), nullptr, &cropRect)); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } { // Dilate -> matrix convolution. // This tests that a filter using asFragmentProcessor (matrix // convolution) correctly handles a non-zero source offset // (supplied by the dilate). sk_sp<SkImageFilter> dilate(SkDilateImageFilter::Make(5, 5, nullptr)); SkScalar kernel[9] = { SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), SkIntToScalar(-1), SkIntToScalar( 7 ), SkIntToScalar(-1), SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), }; SkISize kernelSize = SkISize::Make(3, 3); SkScalar gain = 1.0f, bias = SkIntToScalar(0); SkIPoint kernelOffset = SkIPoint::Make(1, 1); auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode; bool convolveAlpha = false; sk_sp<SkImageFilter> convolve(SkMatrixConvolutionImageFilter::Make(kernelSize, kernel, gain, bias, kernelOffset, tileMode, convolveAlpha, std::move(dilate))); SkPaint paint; paint.setImageFilter(std::move(convolve)); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } { // Test that crop offsets are absolute, not relative to the parent's crop rect. sk_sp<SkColorFilter> cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkBlendMode::kSrcIn)); sk_sp<SkColorFilter> cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkBlendMode::kSrcIn)); SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(80), SkIntToScalar(80))); SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(60), SkIntToScalar(60))); sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Make(std::move(cf1), nullptr, &outerRect)); sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Make(std::move(cf2), std::move(color1), &innerRect)); SkPaint paint; paint.setImageFilter(std::move(color2)); paint.setColor(SK_ColorRED); canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); canvas->translate(SkIntToScalar(100), 0); } }
bool FPScreenMirror::process() { if (!initialized) { reinitialize(); return false; } if (!captureWindowHDC || !currentProcessHWND) { return false; } /* if (keyboardWidth < 1 || keyboardHeight < 1) { return false; } */ PerformanceStart(); // get window bitmap as Mat screenshotMat RECT targetRect; GetWindowRect(currentProcessHWND, &targetRect); int clientWidth = targetRect.right - targetRect.left; // -offsetLeft - offsetRight; int clientHeight = targetRect.bottom - targetRect.top; // -offsetTop - offsetBottom; if ((targetRect.left < 0 && targetRect.top < 0 && targetRect.right < 0 && targetRect.bottom < 0) || clientWidth < 0 || clientHeight < 0) { PerformanceStop(); return false; } Mat* screenshotRaw = ImageFilterMat::hdc2mat(captureWindowHDC, 0, 0, clientWidth, clientHeight); if (screenshotRaw == NULL) { PerformanceStop(); delete screenshotRaw; return false; } Mat4b screenshotMat = (Mat4b)*screenshotRaw; cv::Rect cropRect(cutLeft, cutTop, screenshotMat.cols - cutLeft - cutRight, screenshotMat.rows - cutTop - cutBottom); screenshotMat = Mat(screenshotMat, cropRect); blur(screenshotMat, screenshotMat, cv::Size(20, 20)); resize(screenshotMat, screenshotMat, cv::Size(targetWidth, targetHeight), 2, 2, INTER_CUBIC); // ImageFilterMat::incSaturation(screenshotMat, 50, (float)0.7); LEDController::getInstance()->initializeFrame(); Mat4b keyboardMat = Mat4b(*keyboardFx); // draw Keyboard vector<CorsairLedPosition>::iterator it = allKeys.begin(); it = allKeys.begin(); for (; it != allKeys.end(); ) { cv::Rect keyRect( (int)floor((float)(it->left*keyboardZoomFactor + offsetLeft)*uiZoom * offsetScaleX), (int)floor((float)(it->top*keyboardZoomFactor + offsetTop)*uiZoom* offsetScaleY), (int)floor((float)it->width*keyboardZoomFactor*uiZoom * offsetScaleX), (int)floor((float)it->height*keyboardZoomFactor*uiZoom* offsetScaleY)); int overScanX = (int)keyRect.x - overscan; if (overScanX < 0) overScanX = 0; int overScanY = (int)keyRect.y - overscan; if (overScanY < 0) overScanY = 0; int overScanW = (int)keyRect.width + overscan * 2; if (overScanX + overScanW > keyboardMat.cols) overScanW = keyboardMat.cols - overScanX; int overScanH = (int)keyRect.height + overscan * 2; if (overScanY + overScanH > keyboardMat.rows) overScanH = keyboardMat.rows - overScanY; cv::Rect colorDetectionRect(overScanX, overScanY, overScanW, overScanH); try { Mat4b keyMat = Mat(screenshotMat, colorDetectionRect); resize(keyMat, keyMat, cv::Size(1, 1), 0, 0, INTER_CUBIC); Vec4b color = keyMat.at<Vec4b>(0, 0); LEDController::getInstance()->setKey(it->ledId, color[2], color[1], color[0]); cv::rectangle(keyboardMat, keyRect, Scalar(color[0], color[1], color[2], 255), CV_FILLED, 8, 0); cv::rectangle(keyboardMat, keyRect, Scalar(255, 255, 255, 128), 1, 8, 0); // cv::rectangle(keyboardMat, colorDetectionRect, Scalar(0, 0, 255, 128), 1, 8, 0); } catch (...) { // ups... } ++it; } LEDController::getInstance()->updateFrame(); // copy background to UI getBackgroundMat()->copyTo(drawUI); // ImageFilterMat::addAlphaMask(&screenshotMat, mask); ImageFilterMat::overlayImage(&drawUI, &screenshotMat, cv::Point(targetX, targetY)); resize(keyboardMat, keyboardMat, cv::Size(targetWidth, targetHeight)); ImageFilterMat::overlayImage(&drawUI, &keyboardMat, cv::Point(targetX, targetY)); PerformanceDraw(getBackgroundMat()->cols - 130, 20); drawToWindow(&drawUI); // throwing away pointer, so opencv releases memory delete screenshotRaw; PerformanceStop(); return true; }
void KisAsyncMergerTest::testMerger() { const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(0, 640, 441, colorSpace, "merger test"); QImage sourceImage1(QString(FILES_DATA_DIR) + QDir::separator() + "hakonepa.png"); QImage sourceImage2(QString(FILES_DATA_DIR) + QDir::separator() + "inverted_hakonepa.png"); QImage referenceProjection(QString(FILES_DATA_DIR) + QDir::separator() + "merged_hakonepa.png"); KisPaintDeviceSP device1 = new KisPaintDevice(colorSpace); KisPaintDeviceSP device2 = new KisPaintDevice(colorSpace); device1->convertFromQImage(sourceImage1, 0, 0, 0); device2->convertFromQImage(sourceImage2, 0, 0, 0); KisFilterSP filter = KisFilterRegistry::instance()->value("blur"); Q_ASSERT(filter); KisFilterConfiguration *configuration = filter->defaultConfiguration(0); Q_ASSERT(configuration); KisLayerSP paintLayer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, device1); KisLayerSP paintLayer2 = new KisPaintLayer(image, "paint2", OPACITY_OPAQUE_U8, device2); KisLayerSP groupLayer = new KisGroupLayer(image, "group", 200/*OPACITY_OPAQUE*/); KisLayerSP blur1 = new KisAdjustmentLayer(image, "blur1", configuration, 0); image->addNode(paintLayer1, image->rootLayer()); image->addNode(groupLayer, image->rootLayer()); image->addNode(paintLayer2, groupLayer); image->addNode(blur1, groupLayer); QRect testRect1(0,0,100,441); QRect testRect2(100,0,400,441); QRect testRect3(500,0,140,441); QRect testRect4(580,381,40,40); QRect cropRect(image->bounds()); KisMergeWalker walker(cropRect); KisAsyncMerger merger; walker.collectRects(paintLayer2, testRect1); merger.startMerge(walker); walker.collectRects(paintLayer2, testRect2); merger.startMerge(walker); walker.collectRects(paintLayer2, testRect3); merger.startMerge(walker); walker.collectRects(paintLayer2, testRect4); merger.startMerge(walker); // Old style merging: has artefacts at x=100 and x=500 // And should be turned on inside KisLayer /* paintLayer2->setDirty(testRect1); QTest::qSleep(3000); paintLayer2->setDirty(testRect2); QTest::qSleep(3000); paintLayer2->setDirty(testRect3); QTest::qSleep(3000); paintLayer2->setDirty(testRect4); QTest::qSleep(3000); */ KisLayerSP rootLayer = image->rootLayer(); QVERIFY(rootLayer->exactBounds() == image->bounds()); QImage resultProjection = rootLayer->projection()->convertToQImage(0); resultProjection.save(QString(FILES_OUTPUT_DIR) + QDir::separator() + "actual_merge_result.png"); QPoint pt; QVERIFY(TestUtil::compareQImages(pt, resultProjection, referenceProjection, 1)); }
void onDraw(SkCanvas* canvas) override { SkAutoTUnref<SkColorFilter> cf( SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); SkImageFilter::CropRect cropRect( SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); sk_sp<SkImage> gradientCircle(MakeGradientCircle(64, 64)); SkBitmap checkerboard; MakeCheckerboard(&checkerboard); SkAutoTUnref<SkImageFilter> gradientCircleSource( SkImageSource::Create(gradientCircle.get())); SkAutoTUnref<SkImageFilter> noopCropped( SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect)); SkScalar sk255 = SkIntToScalar(255); SkScalar matrix[20] = { 1, 0, 0, 0, 0, 0, 1, 0, 0, sk255, 0, 0, 1, 0, 0, 0, 0, 0, 0, sk255 }; SkAutoTUnref<SkColorFilter> cfAlphaTrans(SkColorMatrixFilter::Create(matrix)); SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); SkScalar MARGIN = SkIntToScalar(12); SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); SkScalar kd = SkIntToScalar(2); SkScalar surfaceScale = SkIntToScalar(1); SkIRect bounds; r.roundOut(&bounds); SkPaint paint; canvas->translate(MARGIN, MARGIN); for (int outset = -15; outset <= 20; outset += 5) { canvas->save(); SkRect rect = cropRect.rect(); rect.outset(SkIntToScalar(outset), SkIntToScalar(outset)); SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasAll_CropEdge); Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create( cfAlphaTrans, noopCropped.get(), &bigRect)); Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create( 0.3f, 0.3f, noopCropped.get(), &bigRect)); Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create( 8.0f, 8.0f, noopCropped.get(), &bigRect)); Draw(canvas, checkerboard, rect, SkDilateImageFilter::Create( 2, 2, noopCropped.get(), &bigRect)); Draw(canvas, checkerboard, rect, SkErodeImageFilter::Create( 2, 2, noopCropped.get(), &bigRect)); Draw(canvas, checkerboard, rect, SkDropShadowImageFilter::Create( SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(3), SkIntToScalar(3), SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, noopCropped.get(), &bigRect)); Draw(canvas, checkerboard, rect, SkDisplacementMapEffect::Create( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kR_ChannelSelectorType, SkIntToScalar(12), gradientCircleSource.get(), noopCropped.get(), &bigRect)); Draw(canvas, checkerboard, rect, SkOffsetImageFilter::Create( SkIntToScalar(-8), SkIntToScalar(16), noopCropped.get(), &bigRect)); Draw(canvas, checkerboard, rect, SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, surfaceScale, kd, noopCropped.get(), &bigRect)); canvas->restore(); canvas->translate(0, SkIntToScalar(80)); } }
QPixmap coverPixmap(const QString &coverPath, QSize sz) { return QPixmap::fromImage(cropRect(QImage(coverPath), sz)); }