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 <string.h> | 7 #include <string.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 for (int y = 0; y < masked.height(); ++y) { | 112 for (int y = 0; y < masked.height(); ++y) { |
113 uint32* rgb_row = rgb.getAddr32(0, y); | 113 uint32* rgb_row = rgb.getAddr32(0, y); |
114 uint32* alpha_row = alpha.getAddr32(0, y); | 114 uint32* alpha_row = alpha.getAddr32(0, y); |
115 uint32* dst_row = masked.getAddr32(0, y); | 115 uint32* dst_row = masked.getAddr32(0, y); |
116 | 116 |
117 for (int x = 0; x < masked.width(); ++x) { | 117 for (int x = 0; x < masked.width(); ++x) { |
118 SkColor rgb_pixel = SkUnPreMultiply::PMColorToColor(rgb_row[x]); | 118 SkColor rgb_pixel = SkUnPreMultiply::PMColorToColor(rgb_row[x]); |
119 SkColor alpha_pixel = SkUnPreMultiply::PMColorToColor(alpha_row[x]); | 119 SkColor alpha_pixel = SkUnPreMultiply::PMColorToColor(alpha_row[x]); |
120 int alpha = SkAlphaMul(SkColorGetA(rgb_pixel), | 120 int alpha = SkAlphaMul(SkColorGetA(rgb_pixel), |
121 SkAlpha255To256(SkColorGetA(alpha_pixel))); | 121 SkAlpha255To256(SkColorGetA(alpha_pixel))); |
122 int alpha_256 = SkAlpha255To256(alpha); | 122 dst_row[x] = SkPreMultiplyARGB(alpha, |
123 dst_row[x] = SkColorSetARGB(alpha, | 123 SkColorGetR(rgb_pixel), |
124 SkAlphaMul(SkColorGetR(rgb_pixel), alpha_256), | 124 SkColorGetG(rgb_pixel), |
125 SkAlphaMul(SkColorGetG(rgb_pixel), alpha_256), | 125 SkColorGetB(rgb_pixel)); |
126 SkAlphaMul(SkColorGetB(rgb_pixel), | |
127 alpha_256)); | |
128 } | 126 } |
129 } | 127 } |
130 | 128 |
131 return masked; | 129 return masked; |
132 } | 130 } |
133 | 131 |
134 // static | 132 // static |
135 SkBitmap SkBitmapOperations::CreateButtonBackground(SkColor color, | 133 SkBitmap SkBitmapOperations::CreateButtonBackground(SkColor color, |
136 const SkBitmap& image, | 134 const SkBitmap& image, |
137 const SkBitmap& mask) { | 135 const SkBitmap& mask) { |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 canvas.translate(SkFloatToScalar(result.width() * 0.5f), | 786 canvas.translate(SkFloatToScalar(result.width() * 0.5f), |
789 SkFloatToScalar(result.height() * 0.5f)); | 787 SkFloatToScalar(result.height() * 0.5f)); |
790 canvas.rotate(angle); | 788 canvas.rotate(angle); |
791 canvas.translate(-SkFloatToScalar(source.width() * 0.5f), | 789 canvas.translate(-SkFloatToScalar(source.width() * 0.5f), |
792 -SkFloatToScalar(source.height() * 0.5f)); | 790 -SkFloatToScalar(source.height() * 0.5f)); |
793 canvas.drawBitmap(source, 0, 0); | 791 canvas.drawBitmap(source, 0, 0); |
794 canvas.flush(); | 792 canvas.flush(); |
795 | 793 |
796 return result; | 794 return result; |
797 } | 795 } |
OLD | NEW |