Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: src/core/SkBitmapScaler.cpp

Issue 173893002: use colortype instead of config (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkBitmapProcShader.cpp ('k') | src/core/SkBitmap_scroll.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "SkBitmapScaler.h" 1 #include "SkBitmapScaler.h"
2 #include "SkBitmapFilter.h" 2 #include "SkBitmapFilter.h"
3 #include "SkRect.h" 3 #include "SkRect.h"
4 #include "SkTArray.h" 4 #include "SkTArray.h"
5 #include "SkErrorInternals.h" 5 #include "SkErrorInternals.h"
6 #include "SkConvolver.h" 6 #include "SkConvolver.h"
7 7
8 // SkResizeFilter -------------------------------------------------------------- -- 8 // SkResizeFilter -------------------------------------------------------------- --
9 9
10 // Encapsulates computation and storage of the filters required for one complete 10 // Encapsulates computation and storage of the filters required for one complete
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 268 }
269 269
270 method = ResizeMethodToAlgorithmMethod(method); 270 method = ResizeMethodToAlgorithmMethod(method);
271 271
272 // Check that we deal with an "algorithm methods" from this point onward. 272 // Check that we deal with an "algorithm methods" from this point onward.
273 SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) && 273 SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) &&
274 (method <= SkBitmapScaler::RESIZE_LAST_ALGORITHM_METHOD)); 274 (method <= SkBitmapScaler::RESIZE_LAST_ALGORITHM_METHOD));
275 275
276 SkAutoLockPixels locker(source); 276 SkAutoLockPixels locker(source);
277 if (!source.readyToDraw() || 277 if (!source.readyToDraw() ||
278 source.config() != SkBitmap::kARGB_8888_Config) { 278 source.colorType() != kPMColor_SkColorType) {
279 return false; 279 return false;
280 } 280 }
281 281
282 SkResizeFilter filter(method, source.width(), source.height(), 282 SkResizeFilter filter(method, source.width(), source.height(),
283 destWidth, destHeight, destSubset, convolveProcs); 283 destWidth, destHeight, destSubset, convolveProcs);
284 284
285 // Get a source bitmap encompassing this touched area. We construct the 285 // Get a source bitmap encompassing this touched area. We construct the
286 // offsets and row strides such that it looks like a new bitmap, while 286 // offsets and row strides such that it looks like a new bitmap, while
287 // referring to the old data. 287 // referring to the old data.
288 const unsigned char* sourceSubset = 288 const unsigned char* sourceSubset =
289 reinterpret_cast<const unsigned char*>(source.getPixels()); 289 reinterpret_cast<const unsigned char*>(source.getPixels());
290 290
291 // Convolve into the result. 291 // Convolve into the result.
292 SkBitmap result; 292 SkBitmap result;
293 result.setConfig(SkBitmap::kARGB_8888_Config, 293 result.setConfig(SkImageInfo::MakeN32(destSubset.width(),
294 destSubset.width(), destSubset.height(), 0, 294 destSubset.height(),
295 source.alphaType()); 295 source.alphaType()));
296 result.allocPixels(allocator, NULL); 296 result.allocPixels(allocator, NULL);
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(NULL != resultPtr->getPixels()); 309 SkASSERT(NULL != resultPtr->getPixels());
310 return true; 310 return true;
311 } 311 }
312 312
313 // static 313 // static
314 bool SkBitmapScaler::Resize(SkBitmap* resultPtr, 314 bool SkBitmapScaler::Resize(SkBitmap* resultPtr,
315 const SkBitmap& source, 315 const SkBitmap& source,
316 ResizeMethod method, 316 ResizeMethod method,
317 int destWidth, int destHeight, 317 int destWidth, int destHeight,
318 const SkConvolutionProcs& convolveProcs, 318 const SkConvolutionProcs& convolveProcs,
319 SkBitmap::Allocator* allocator) { 319 SkBitmap::Allocator* allocator) {
320 SkIRect destSubset = { 0, 0, destWidth, destHeight }; 320 SkIRect destSubset = { 0, 0, destWidth, destHeight };
321 return Resize(resultPtr, source, method, destWidth, destHeight, destSubset, 321 return Resize(resultPtr, source, method, destWidth, destHeight, destSubset,
322 convolveProcs, allocator); 322 convolveProcs, allocator);
323 } 323 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcShader.cpp ('k') | src/core/SkBitmap_scroll.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698