OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/skbitmap_operations.h" | 5 #include "ui/gfx/skbitmap_operations.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 dst_row[x] = SkColorSetARGB(a, r, g, b); | 126 dst_row[x] = SkColorSetARGB(a, r, g, b); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 return blended; | 130 return blended; |
131 } | 131 } |
132 | 132 |
133 // static | 133 // static |
134 SkBitmap SkBitmapOperations::CreateMaskedBitmap(const SkBitmap& rgb, | 134 SkBitmap SkBitmapOperations::CreateMaskedBitmap(const SkBitmap& rgb, |
135 const SkBitmap& alpha) { | 135 const SkBitmap& alpha) { |
136 DCHECK(rgb.width() == alpha.width()); | 136 // DCHECK(rgb.width() == alpha.width()); |
137 DCHECK(rgb.height() == alpha.height()); | 137 // DCHECK(rgb.height() == alpha.height()); |
138 DCHECK(rgb.bytesPerPixel() == alpha.bytesPerPixel()); | 138 DCHECK(rgb.bytesPerPixel() == alpha.bytesPerPixel()); |
139 DCHECK(rgb.config() == SkBitmap::kARGB_8888_Config); | 139 DCHECK(rgb.config() == SkBitmap::kARGB_8888_Config); |
140 DCHECK(alpha.config() == SkBitmap::kARGB_8888_Config); | 140 DCHECK(alpha.config() == SkBitmap::kARGB_8888_Config); |
141 | 141 |
142 SkBitmap masked; | 142 SkBitmap masked; |
143 masked.setConfig(SkBitmap::kARGB_8888_Config, rgb.width(), rgb.height(), 0); | 143 masked.setConfig(SkBitmap::kARGB_8888_Config, |
| 144 std::min(rgb.width(), alpha.width()), |
| 145 std::min(rgb.height(), alpha.height()), 0); |
144 masked.allocPixels(); | 146 masked.allocPixels(); |
145 masked.eraseARGB(0, 0, 0, 0); | 147 masked.eraseARGB(0, 0, 0, 0); |
146 | 148 |
147 SkAutoLockPixels lock_rgb(rgb); | 149 SkAutoLockPixels lock_rgb(rgb); |
148 SkAutoLockPixels lock_alpha(alpha); | 150 SkAutoLockPixels lock_alpha(alpha); |
149 SkAutoLockPixels lock_masked(masked); | 151 SkAutoLockPixels lock_masked(masked); |
150 | 152 |
151 for (int y = 0; y < masked.height(); ++y) { | 153 for (int y = 0; y < masked.height(); ++y) { |
152 uint32* rgb_row = rgb.getAddr32(0, y); | 154 uint32* rgb_row = rgb.getAddr32(0, y); |
153 uint32* alpha_row = alpha.getAddr32(0, y); | 155 uint32* alpha_row = alpha.getAddr32(0, y); |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 canvas.translate(SkFloatToScalar(result.width() * 0.5f), | 844 canvas.translate(SkFloatToScalar(result.width() * 0.5f), |
843 SkFloatToScalar(result.height() * 0.5f)); | 845 SkFloatToScalar(result.height() * 0.5f)); |
844 canvas.rotate(angle); | 846 canvas.rotate(angle); |
845 canvas.translate(-SkFloatToScalar(source.width() * 0.5f), | 847 canvas.translate(-SkFloatToScalar(source.width() * 0.5f), |
846 -SkFloatToScalar(source.height() * 0.5f)); | 848 -SkFloatToScalar(source.height() * 0.5f)); |
847 canvas.drawBitmap(source, 0, 0); | 849 canvas.drawBitmap(source, 0, 0); |
848 canvas.flush(); | 850 canvas.flush(); |
849 | 851 |
850 return result; | 852 return result; |
851 } | 853 } |
OLD | NEW |