| 54 | } |
| 55 | |
| 56 | static 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 | |
| 92 | Valdi::Result<ImageInfo> getImageInfo(const Valdi::StringBox& imageFilePath) { |
| 93 | auto imageSize = processImage<std::pair<int, int>>( |
no test coverage detected