MCPcopy Create free account
hub / github.com/Snapchat/Valdi / clipImageToCircle

Function clipImageToCircle

libs/image_toolbox/src/image_toolbox/ImageToolbox.cpp:56–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56static Valdi::Result<Ref<Image>> clipImageToCircle(const Ref<Image>& image) {
57 auto width = image->width();
58 auto height = image->height();
59
60 DrawingContext drawingContext(width, height);
61
62 Path clipPath;
63 clipPath.addOval(Rect::makeXYWH(0, 0, width, height), true);
64 drawingContext.clipPath(clipPath);
65
66 auto imageRect = Rect::makeXYWH(0, 0, image->width(), image->height());
67 auto targetRect = Rect::makeXYWH(0, 0, width, height);
68 drawingContext.drawImage(*image, imageRect, targetRect, nullptr);
69
70 auto displayList = Valdi::makeShared<DisplayList>(Size(width, height), TimePoint(0.0));
71 displayList->appendLayerContent(drawingContext.finish(), 1.0);
72
73 BitmapGraphicsContext bitmapContext;
74 auto surface = bitmapContext.createBitmapSurface(
75 Valdi::BitmapInfo(width, height, Valdi::ColorTypeRGBA8888, Valdi::AlphaTypePremul, 0));
76
77 auto canvas = surface->prepareCanvas();
78 if (!canvas) {
79 return canvas.moveError();
80 }
81
82 displayList->draw(canvas.value(), kDisplayListAllPlaneIndexes, true);
83
84 auto snapshot = canvas.value().snapshot();
85 if (!snapshot) {
86 return snapshot.moveError();
87 }
88
89 return snapshot.moveValue();
90}
91
92Valdi::Result<ImageInfo> getImageInfo(const Valdi::StringBox& imageFilePath) {
93 auto imageSize = processImage<std::pair<int, int>>(

Callers 1

convertImageFunction · 0.85

Calls 15

addOvalMethod · 0.80
clipPathMethod · 0.80
drawImageMethod · 0.80
appendLayerContentMethod · 0.80
createBitmapSurfaceMethod · 0.80
drawMethod · 0.65
valueMethod · 0.65
SizeFunction · 0.50
TimePointClass · 0.50
BitmapInfoClass · 0.50
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected