| 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" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 return SkBitmapScaler::RESIZE_LANCZOS3; | 244 return SkBitmapScaler::RESIZE_LANCZOS3; |
| 245 #else | 245 #else |
| 246 return SkBitmapScaler::RESIZE_MITCHELL; | 246 return SkBitmapScaler::RESIZE_MITCHELL; |
| 247 #endif | 247 #endif |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeM
ethod method, | 251 bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeM
ethod method, |
| 252 float destWidth, float destHeight, | 252 float destWidth, float destHeight, |
| 253 SkBitmap::Allocator* allocator) { | 253 SkBitmap::Allocator* allocator) { |
| 254 if (NULL == source.addr() || source.colorType() != kN32_SkColorType || | 254 if (nullptr == source.addr() || source.colorType() != kN32_SkColorType || |
| 255 source.width() < 1 || source.height() < 1) | 255 source.width() < 1 || source.height() < 1) |
| 256 { | 256 { |
| 257 return false; | 257 return false; |
| 258 } | 258 } |
| 259 | 259 |
| 260 if (destWidth < 1 || destHeight < 1) { | 260 if (destWidth < 1 || destHeight < 1) { |
| 261 // todo: seems like we could handle negative dstWidth/Height, since that | 261 // todo: seems like we could handle negative dstWidth/Height, since that |
| 262 // is just a negative scale (flip) | 262 // is just a negative scale (flip) |
| 263 return false; | 263 return false; |
| 264 } | 264 } |
| 265 | 265 |
| 266 SkConvolutionProcs convolveProcs= { 0, NULL, NULL, NULL, NULL }; | 266 SkConvolutionProcs convolveProcs= { 0, nullptr, nullptr, nullptr, nullptr }; |
| 267 PlatformConvolutionProcs(&convolveProcs); | 267 PlatformConvolutionProcs(&convolveProcs); |
| 268 | 268 |
| 269 SkRect destSubset = { 0, 0, destWidth, destHeight }; | 269 SkRect destSubset = { 0, 0, destWidth, destHeight }; |
| 270 | 270 |
| 271 // Ensure that the ResizeMethod enumeration is sound. | 271 // Ensure that the ResizeMethod enumeration is sound. |
| 272 SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) && | 272 SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) && |
| 273 (method <= RESIZE_LAST_QUALITY_METHOD)) || | 273 (method <= RESIZE_LAST_QUALITY_METHOD)) || |
| 274 ((RESIZE_FIRST_ALGORITHM_METHOD <= method) && | 274 ((RESIZE_FIRST_ALGORITHM_METHOD <= method) && |
| 275 (method <= RESIZE_LAST_ALGORITHM_METHOD))); | 275 (method <= RESIZE_LAST_ALGORITHM_METHOD))); |
| 276 | 276 |
| 277 method = ResizeMethodToAlgorithmMethod(method); | 277 method = ResizeMethodToAlgorithmMethod(method); |
| 278 | 278 |
| 279 // Check that we deal with an "algorithm methods" from this point onward. | 279 // Check that we deal with an "algorithm methods" from this point onward. |
| 280 SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) && | 280 SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) && |
| 281 (method <= SkBitmapScaler::RESIZE_LAST_ALGORITHM_METHOD)); | 281 (method <= SkBitmapScaler::RESIZE_LAST_ALGORITHM_METHOD)); |
| 282 | 282 |
| 283 SkResizeFilter filter(method, source.width(), source.height(), | 283 SkResizeFilter filter(method, source.width(), source.height(), |
| 284 destWidth, destHeight, destSubset, convolveProcs); | 284 destWidth, destHeight, destSubset, convolveProcs); |
| 285 | 285 |
| 286 // Get a subset encompassing this touched area. We construct the | 286 // Get a subset encompassing this touched area. We construct the |
| 287 // offsets and row strides such that it looks like a new bitmap, while | 287 // offsets and row strides such that it looks like a new bitmap, while |
| 288 // referring to the old data. | 288 // referring to the old data. |
| 289 const uint8_t* sourceSubset = reinterpret_cast<const uint8_t*>(source.addr()
); | 289 const uint8_t* sourceSubset = reinterpret_cast<const uint8_t*>(source.addr()
); |
| 290 | 290 |
| 291 // Convolve into the result. | 291 // Convolve into the result. |
| 292 SkBitmap result; | 292 SkBitmap result; |
| 293 result.setInfo(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()), | 293 result.setInfo(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()), |
| 294 SkScalarCeilToInt(destSubset.height()), | 294 SkScalarCeilToInt(destSubset.height()), |
| 295 source.alphaType())); | 295 source.alphaType())); |
| 296 result.allocPixels(allocator, NULL); | 296 result.allocPixels(allocator, nullptr); |
| 297 if (!result.readyToDraw()) { | 297 if (!result.readyToDraw()) { |
| 298 return false; | 298 return false; |
| 299 } | 299 } |
| 300 | 300 |
| 301 BGRAConvolve2D(sourceSubset, static_cast<int>(source.rowBytes()), | 301 BGRAConvolve2D(sourceSubset, static_cast<int>(source.rowBytes()), |
| 302 !source.isOpaque(), filter.xFilter(), filter.yFilter(), | 302 !source.isOpaque(), filter.xFilter(), filter.yFilter(), |
| 303 static_cast<int>(result.rowBytes()), | 303 static_cast<int>(result.rowBytes()), |
| 304 static_cast<unsigned char*>(result.getPixels()), | 304 static_cast<unsigned char*>(result.getPixels()), |
| 305 convolveProcs, true); | 305 convolveProcs, true); |
| 306 | 306 |
| 307 *resultPtr = result; | 307 *resultPtr = result; |
| 308 resultPtr->lockPixels(); | 308 resultPtr->lockPixels(); |
| 309 SkASSERT(resultPtr->getPixels()); | 309 SkASSERT(resultPtr->getPixels()); |
| 310 return true; | 310 return true; |
| 311 } | 311 } |
| 312 | 312 |
| OLD | NEW |