15std::vector<double> NinePatchConverter::InitSlices(
double img0,
21 auto imageDim = img1 - img0;
22 auto destDim = dst1 - dst0;
24 if (imageDim == destDim) {
27 return {img0, dst0, img1, dst1};
30 auto edge0Dim = imgC0 - img0;
31 auto edge1Dim = img1 - imgC1;
32 auto edgesDim = edge0Dim + edge1Dim;
34 if (edgesDim >= destDim) {
38 auto dstC = dst0 + destDim * edge0Dim / edgesDim;
41 img0, dst0, imgC0, dstC,
42 imgC1, dstC, img1, dst1,
49 auto dstC0 = dst0 + edge0Dim;
50 auto dstC1 = dst1 - edge1Dim;
53 img0, dst0, imgC0, dstC0,
54 imgC0, dstC0, imgC1, dstC1,
55 imgC1, dstC1, img1, dst1,
69 auto image_size =
image->GetSize();
70 auto hSlices = InitSlices(0,
center.GetLeft(),
center.GetRight(),
71 image_size.width, dst.GetLeft(), dst.GetRight());
72 auto vSlices = InitSlices(0,
center.GetTop(),
center.GetBottom(),
73 image_size.height, dst.GetTop(), dst.GetBottom());
75 for (
size_t yi = 0; yi < vSlices.size(); yi += 4) {
76 auto srcY0 = vSlices[yi];
77 auto dstY0 = vSlices[yi + 1];
78 auto srcY1 = vSlices[yi + 2];
79 auto dstY1 = vSlices[yi + 3];
80 for (
size_t xi = 0; xi < hSlices.size(); xi += 4) {
81 auto srcX0 = hSlices[xi];
82 auto dstX0 = hSlices[xi + 1];
83 auto srcX1 = hSlices[xi + 2];
84 auto dstX1 = hSlices[xi + 3];
static SkScalar center(float pos0, float pos1)
void DrawImageRect(const std::shared_ptr< Image > &image, Rect source, Rect dest, const Paint &paint, SamplerDescriptor sampler={}, SourceRectConstraint src_rect_constraint=SourceRectConstraint::kFast)
void DrawNinePatch(const std::shared_ptr< Image > &image, Rect center, Rect dst, const SamplerDescriptor &sampler, CanvasType *canvas, Paint *paint)
@ kStrict
Sample only within the source rectangle. May be slower.
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)