| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmapScaler.h" | 8 #include "SkBitmapScaler.h" |
| 9 #include "SkBitmapFilter.h" | 9 #include "SkBitmapFilter.h" |
| 10 #include "SkConvolver.h" | 10 #include "SkConvolver.h" |
| 11 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
| 12 #include "SkPixmap.h" | 12 #include "SkPixmap.h" |
| 13 #include "SkRect.h" | 13 #include "SkRect.h" |
| 14 #include "SkScalar.h" | 14 #include "SkScalar.h" |
| 15 #include "SkTArray.h" | 15 #include "SkTArray.h" |
| 16 | 16 |
| 17 // SkResizeFilter --------------------------------------------------------------
-- | 17 // SkResizeFilter --------------------------------------------------------------
-- |
| 18 | 18 |
| 19 // Encapsulates computation and storage of the filters required for one complete | 19 // Encapsulates computation and storage of the filters required for one complete |
| 20 // resize operation. | 20 // resize operation. |
| 21 class SkResizeFilter { | 21 class SkResizeFilter { |
| 22 public: | 22 public: |
| 23 SkResizeFilter(SkBitmapScaler::ResizeMethod method, | 23 SkResizeFilter(SkBitmapScaler::ResizeMethod method, |
| 24 int srcFullWidth, int srcFullHeight, | 24 int srcFullWidth, int srcFullHeight, |
| 25 float destWidth, float destHeight, | 25 float destWidth, float destHeight, |
| 26 const SkRect& destSubset, | 26 const SkRect& destSubset, |
| 27 const SkConvolutionProcs& convolveProcs); | 27 const SkConvolutionProcs& convolveProcs); |
| 28 ~SkResizeFilter() { | 28 ~SkResizeFilter() { delete fBitmapFilter; } |
| 29 SkDELETE( fBitmapFilter ); | |
| 30 } | |
| 31 | 29 |
| 32 // Returns the filled filter values. | 30 // Returns the filled filter values. |
| 33 const SkConvolutionFilter1D& xFilter() { return fXFilter; } | 31 const SkConvolutionFilter1D& xFilter() { return fXFilter; } |
| 34 const SkConvolutionFilter1D& yFilter() { return fYFilter; } | 32 const SkConvolutionFilter1D& yFilter() { return fYFilter; } |
| 35 | 33 |
| 36 private: | 34 private: |
| 37 | 35 |
| 38 SkBitmapFilter* fBitmapFilter; | 36 SkBitmapFilter* fBitmapFilter; |
| 39 | 37 |
| 40 // Computes one set of filters either horizontally or vertically. The caller | 38 // Computes one set of filters either horizontally or vertically. The caller |
| (...skipping 22 matching lines...) Expand all Loading... |
| 63 float destWidth, float destHeight, | 61 float destWidth, float destHeight, |
| 64 const SkRect& destSubset, | 62 const SkRect& destSubset, |
| 65 const SkConvolutionProcs& convolveProcs) { | 63 const SkConvolutionProcs& convolveProcs) { |
| 66 | 64 |
| 67 // method will only ever refer to an "algorithm method". | 65 // method will only ever refer to an "algorithm method". |
| 68 SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) && | 66 SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) && |
| 69 (method <= SkBitmapScaler::RESIZE_LAST_ALGORITHM_METHOD)); | 67 (method <= SkBitmapScaler::RESIZE_LAST_ALGORITHM_METHOD)); |
| 70 | 68 |
| 71 switch(method) { | 69 switch(method) { |
| 72 case SkBitmapScaler::RESIZE_BOX: | 70 case SkBitmapScaler::RESIZE_BOX: |
| 73 fBitmapFilter = SkNEW(SkBoxFilter); | 71 fBitmapFilter = new SkBoxFilter; |
| 74 break; | 72 break; |
| 75 case SkBitmapScaler::RESIZE_TRIANGLE: | 73 case SkBitmapScaler::RESIZE_TRIANGLE: |
| 76 fBitmapFilter = SkNEW(SkTriangleFilter); | 74 fBitmapFilter = new SkTriangleFilter; |
| 77 break; | 75 break; |
| 78 case SkBitmapScaler::RESIZE_MITCHELL: | 76 case SkBitmapScaler::RESIZE_MITCHELL: |
| 79 fBitmapFilter = SkNEW_ARGS(SkMitchellFilter, (1.f/3.f, 1.f/3.f)); | 77 fBitmapFilter = new SkMitchellFilter(1.f / 3.f, 1.f / 3.f); |
| 80 break; | 78 break; |
| 81 case SkBitmapScaler::RESIZE_HAMMING: | 79 case SkBitmapScaler::RESIZE_HAMMING: |
| 82 fBitmapFilter = SkNEW(SkHammingFilter); | 80 fBitmapFilter = new SkHammingFilter; |
| 83 break; | 81 break; |
| 84 case SkBitmapScaler::RESIZE_LANCZOS3: | 82 case SkBitmapScaler::RESIZE_LANCZOS3: |
| 85 fBitmapFilter = SkNEW(SkLanczosFilter); | 83 fBitmapFilter = new SkLanczosFilter; |
| 86 break; | 84 break; |
| 87 default: | 85 default: |
| 88 // NOTREACHED: | 86 // NOTREACHED: |
| 89 fBitmapFilter = SkNEW_ARGS(SkMitchellFilter, (1.f/3.f, 1.f/3.f)); | 87 fBitmapFilter = new SkMitchellFilter(1.f / 3.f, 1.f / 3.f); |
| 90 break; | 88 break; |
| 91 } | 89 } |
| 92 | 90 |
| 93 | 91 |
| 94 float scaleX = destWidth / srcFullWidth; | 92 float scaleX = destWidth / srcFullWidth; |
| 95 float scaleY = destHeight / srcFullHeight; | 93 float scaleY = destHeight / srcFullHeight; |
| 96 | 94 |
| 97 this->computeFilters(srcFullWidth, destSubset.fLeft, destSubset.width(), | 95 this->computeFilters(srcFullWidth, destSubset.fLeft, destSubset.width(), |
| 98 scaleX, &fXFilter, convolveProcs); | 96 scaleX, &fXFilter, convolveProcs); |
| 99 if (srcFullWidth == srcFullHeight && | 97 if (srcFullWidth == srcFullHeight && |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 static_cast<int>(result.rowBytes()), | 303 static_cast<int>(result.rowBytes()), |
| 306 static_cast<unsigned char*>(result.getPixels()), | 304 static_cast<unsigned char*>(result.getPixels()), |
| 307 convolveProcs, true); | 305 convolveProcs, true); |
| 308 | 306 |
| 309 *resultPtr = result; | 307 *resultPtr = result; |
| 310 resultPtr->lockPixels(); | 308 resultPtr->lockPixels(); |
| 311 SkASSERT(resultPtr->getPixels()); | 309 SkASSERT(resultPtr->getPixels()); |
| 312 return true; | 310 return true; |
| 313 } | 311 } |
| 314 | 312 |
| OLD | NEW |