diff options
-rw-r--r-- | docs/SkIRect_Reference.bmh | 35 | ||||
-rw-r--r-- | include/core/SkRect.h | 19 | ||||
-rw-r--r-- | src/core/SkImageFilter.cpp | 5 | ||||
-rw-r--r-- | src/effects/SkMatrixConvolutionImageFilter.cpp | 8 |
4 files changed, 60 insertions, 7 deletions
diff --git a/docs/SkIRect_Reference.bmh b/docs/SkIRect_Reference.bmh index 4fcb26a48c..23905754af 100644 --- a/docs/SkIRect_Reference.bmh +++ b/docs/SkIRect_Reference.bmh @@ -1041,6 +1041,41 @@ describes an area: fLeft is less than fRight, and fTop is less than fBottom. # ------------------------------------------------------------------------------ +#Method void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB) + +#In Inset_Outset_Offset +#Line # moves the sides independently relative to their original locations ## +Adjusts IRect by adding dL to fLeft, dT to fTop, dR to fRight, and fB to fBottom. + +If dL is positive, narrows IRect on the left. If negative, widens it on the left. +If dT is positive, shrinks IRect on the top. If negative, lengthens it on the top. +If dR is positive, narrows IRect on the right. If negative, widens it on the right. +If dB is positive, shrinks IRect on the bottom. If negative, lengthens it on the bottom. + +The resulting IRect is not checked for validity. Thus, if the resulting IRect left is +greater than right, the IRect will be considered empty. Call sort() after this call +if that is not the desired behavior. + +#Param dL offset added to fLeft ## +#Param dT offset added to fTop ## +#Param dR offset added to fRight ## +#Param dB offset added to fBottom ## + +#Example + SkIRect rect = { 8, 11, 19, 22 }; + rect.adjust(2, -1, 1, -2); + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +#StdOut +rect: 10, 10, 20, 20 +## +## + +#SeeAlso inset outset + +## + +# ------------------------------------------------------------------------------ + #Method bool contains(int32_t x, int32_t y) const #In Intersection diff --git a/include/core/SkRect.h b/include/core/SkRect.h index d4a9c05c68..7b8e0032e5 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -413,6 +413,25 @@ struct SK_API SkIRect { */ void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); } + /** Adjust SkIRect by adding dL to fLeft, dT to fTop, dR to fRight and fB to fBottom. + + If dL is positive, narrows SkIRect on the left. If negative, widens it on the left. + If dT is positive, shrinks SkIRect on the top. If negative, lengthens it on the top. + If dR is positive, narrows SkIRect on the right. If negative, widens it on the right. + If dB is positive, shrinks SkIRect on the bottom. If negative, lengthens it on the bottom. + + @param dL offset added to fLeft + @param dT offset added to fTop + @param dR offset added to fRight + @param dB offset added to fBottom + */ + void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB) { + fLeft = Sk32_sat_add(fLeft, dL); + fTop = Sk32_sat_add(fTop, dT); + fRight = Sk32_sat_add(fRight, dR); + fBottom = Sk32_sat_add(fBottom, dB); + } + /** Returns true if: fLeft <= x < fRight && fTop <= y < fBottom. Returns false if SkIRect is empty. diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 59715d99e9..aabfef09bb 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -505,9 +505,8 @@ SkIRect SkImageFilter::DetermineRepeatedSrcBound(const SkIRect& srcBounds, const SkISize& filterSize, const SkIRect& originalSrcBounds) { SkIRect tmp = srcBounds; - tmp.fRight = Sk32_sat_add(tmp.fRight, filterSize.fWidth); - tmp.fBottom = Sk32_sat_add(tmp.fBottom, filterSize.fHeight); - tmp.offset(-filterOffset.fX, -filterOffset.fY); + tmp.adjust(-filterOffset.fX, -filterOffset.fY, + filterSize.fWidth - filterOffset.fX, filterSize.fHeight - filterOffset.fY); if (tmp.fLeft < originalSrcBounds.fLeft || tmp.fRight > originalSrcBounds.fRight) { tmp.fLeft = originalSrcBounds.fLeft; diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index 2c695e7685..2119a8b108 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -452,12 +452,12 @@ SkIRect SkMatrixConvolutionImageFilter::onFilterNodeBounds(const SkIRect& src, c SkIRect dst = src; int w = fKernelSize.width() - 1, h = fKernelSize.height() - 1; - dst.fRight = Sk32_sat_add(dst.fRight, w); - dst.fBottom = Sk32_sat_add(dst.fBottom, h); + if (kReverse_MapDirection == dir) { - dst.offset(-fKernelOffset); + dst.adjust(-fKernelOffset.fX, -fKernelOffset.fY, + w - fKernelOffset.fX, h - fKernelOffset.fY); } else { - dst.offset(fKernelOffset - SkIPoint::Make(w, h)); + dst.adjust(fKernelOffset.fX - w, fKernelOffset.fY - h, fKernelOffset.fX, fKernelOffset.fY); } return dst; } |