OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // | 75 // |
76 // scaledSrcRect = srcRect * (approximateScaleX, approximateScaleY) | 76 // scaledSrcRect = srcRect * (approximateScaleX, approximateScaleY) |
77 // enclosingScaledSrcRect = enclosingIntRect(scaledSrcRect) | 77 // enclosingScaledSrcRect = enclosingIntRect(scaledSrcRect) |
78 // | 78 // |
79 // Finally we extract the scaled image fragment using | 79 // Finally we extract the scaled image fragment using |
80 // (scaledImageSize, enclosingScaledSrcRect). | 80 // (scaledImageSize, enclosingScaledSrcRect). |
81 // | 81 // |
82 SkBitmap NativeImageSkia::extractScaledImageFragment(const SkRect& srcRect, floa
t scaleX, float scaleY, SkRect* scaledSrcRect) const | 82 SkBitmap NativeImageSkia::extractScaledImageFragment(const SkRect& srcRect, floa
t scaleX, float scaleY, SkRect* scaledSrcRect) const |
83 { | 83 { |
84 SkISize imageSize = SkISize::Make(bitmap().width(), bitmap().height()); | 84 SkISize imageSize = SkISize::Make(bitmap().width(), bitmap().height()); |
85 SkISize scaledImageSize = SkISize::Make(clampToInteger(roundf(imageSize.widt
h() * scaleX)), | 85 SkISize scaledImageSize = SkISize::Make(clampTo<int>(roundf(imageSize.width(
) * scaleX)), |
86 clampToInteger(roundf(imageSize.height() * scaleY))); | 86 clampTo<int>(roundf(imageSize.height() * scaleY))); |
87 | 87 |
88 SkRect imageRect = SkRect::MakeWH(imageSize.width(), imageSize.height()); | 88 SkRect imageRect = SkRect::MakeWH(imageSize.width(), imageSize.height()); |
89 SkRect scaledImageRect = SkRect::MakeWH(scaledImageSize.width(), scaledImage
Size.height()); | 89 SkRect scaledImageRect = SkRect::MakeWH(scaledImageSize.width(), scaledImage
Size.height()); |
90 | 90 |
91 SkMatrix scaleTransform; | 91 SkMatrix scaleTransform; |
92 scaleTransform.setRectToRect(imageRect, scaledImageRect, SkMatrix::kFill_Sca
leToFit); | 92 scaleTransform.setRectToRect(imageRect, scaledImageRect, SkMatrix::kFill_Sca
leToFit); |
93 scaleTransform.mapRect(scaledSrcRect, srcRect); | 93 scaleTransform.mapRect(scaledSrcRect, srcRect); |
94 | 94 |
95 scaledSrcRect->intersect(scaledImageRect); | 95 scaledSrcRect->intersect(scaledImageRect); |
96 SkIRect enclosingScaledSrcRect = enclosingIntRect(*scaledSrcRect); | 96 SkIRect enclosingScaledSrcRect = enclosingIntRect(*scaledSrcRect); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca
ledImageSubset) | 369 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca
ledImageSubset) |
370 { | 370 { |
371 if (!scaledImageSubset.contains(otherScaledImageSubset)) | 371 if (!scaledImageSubset.contains(otherScaledImageSubset)) |
372 return SkIRect::MakeEmpty(); | 372 return SkIRect::MakeEmpty(); |
373 SkIRect subsetRect = otherScaledImageSubset; | 373 SkIRect subsetRect = otherScaledImageSubset; |
374 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); | 374 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); |
375 return subsetRect; | 375 return subsetRect; |
376 } | 376 } |
377 | 377 |
378 } // namespace blink | 378 } // namespace blink |
OLD | NEW |