Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkBitmapTransformer.h" | 10 #include "SkBitmapTransformer.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 const char *srcBytes = const_cast<const char *>(static_cast<char*>(fBitmap.g etPixels())); | 78 const char *srcBytes = const_cast<const char *>(static_cast<char*>(fBitmap.g etPixels())); |
| 79 char *dstBytes = static_cast<char *>(dstBuffer); | 79 char *dstBytes = static_cast<char *>(dstBuffer); |
| 80 for (int y = 0; y < fBitmap.height(); y++) { | 80 for (int y = 0; y < fBitmap.height(); y++) { |
| 81 transform_scanline(srcBytes, width, dstBytes); | 81 transform_scanline(srcBytes, width, dstBytes); |
| 82 srcBytes += srcRowBytes; | 82 srcBytes += srcRowBytes; |
| 83 dstBytes += dstRowBytes; | 83 dstBytes += dstRowBytes; |
| 84 } | 84 } |
| 85 fBitmap.unlockPixels(); | 85 fBitmap.unlockPixels(); |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 | |
| 89 bool SkBitmapTransformer::copyRowToPixelBuffer(int row, void *dstBuffer, | |
| 90 size_t dstBufferSize) const { | |
| 91 if (!this->isValid(true)) { | |
| 92 return false; | |
| 93 } | |
| 94 if ((row < 0) || (row >= this->numRows())) { | |
| 95 // EPOGER: add unit test for this check | |
| 96 SkDEBUGF(("row %d must be within range [0,%d]\n", row, numRows()-1)); | |
| 97 return false; | |
| 98 } | |
| 99 size_t bytesNeeded = this->bytesNeededPerRow(); | |
| 100 if (dstBufferSize < bytesNeeded) { | |
| 101 SkDEBUGF(("dstBufferSize %d must be >= %d\n", dstBufferSize, bytesNeeded )); | |
| 102 return false; | |
| 103 } | |
| 104 | |
| 105 fBitmap.lockPixels(); | |
|
bungeman-skia
2013/04/22 05:14:02
This isn't cheap as it involves taking a mutex, as
| |
| 106 int width = fBitmap.width(); | |
| 107 size_t srcRowBytes = fBitmap.rowBytes(); | |
| 108 const char *srcBytes = const_cast<const char *>(static_cast<char*>(fBitmap.g etPixels())); | |
| 109 char *dstBytes = static_cast<char *>(dstBuffer); | |
| 110 srcBytes += srcRowBytes * row; | |
| 111 transform_scanline(srcBytes, width, dstBytes); | |
| 112 fBitmap.unlockPixels(); | |
| 113 return true; | |
| 114 } | |
| OLD | NEW |