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
3 // found in the LICENSE file.
5 #include "ui/gfx/skbitmap_operations.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkColorPriv.h"
11 #include "third_party/skia/include/core/SkRect.h"
12 #include "third_party/skia/include/core/SkRegion.h"
13 #include "third_party/skia/include/core/SkUnPreMultiply.h"
17 // Returns true if each channel of the given two colors are "close." This is
18 // used for comparing colors where rounding errors may cause off-by-one.
19 inline bool ColorsClose(uint32_t a
, uint32_t b
) {
20 return abs(static_cast<int>(SkColorGetB(a
) - SkColorGetB(b
))) <= 2 &&
21 abs(static_cast<int>(SkColorGetG(a
) - SkColorGetG(b
))) <= 2 &&
22 abs(static_cast<int>(SkColorGetR(a
) - SkColorGetR(b
))) <= 2 &&
23 abs(static_cast<int>(SkColorGetA(a
) - SkColorGetA(b
))) <= 2;
26 inline bool MultipliedColorsClose(uint32_t a
, uint32_t b
) {
27 return ColorsClose(SkUnPreMultiply::PMColorToColor(a
),
28 SkUnPreMultiply::PMColorToColor(b
));
31 bool BitmapsClose(const SkBitmap
& a
, const SkBitmap
& b
) {
32 SkAutoLockPixels
a_lock(a
);
33 SkAutoLockPixels
b_lock(b
);
35 for (int y
= 0; y
< a
.height(); y
++) {
36 for (int x
= 0; x
< a
.width(); x
++) {
37 SkColor a_pixel
= *a
.getAddr32(x
, y
);
38 SkColor b_pixel
= *b
.getAddr32(x
, y
);
39 if (!ColorsClose(a_pixel
, b_pixel
))
46 void FillDataToBitmap(int w
, int h
, SkBitmap
* bmp
) {
47 bmp
->setConfig(SkBitmap::kARGB_8888_Config
, w
, h
);
50 unsigned char* src_data
=
51 reinterpret_cast<unsigned char*>(bmp
->getAddr32(0, 0));
52 for (int i
= 0; i
< w
* h
; i
++) {
53 src_data
[i
* 4 + 0] = static_cast<unsigned char>(i
% 255);
54 src_data
[i
* 4 + 1] = static_cast<unsigned char>(i
% 255);
55 src_data
[i
* 4 + 2] = static_cast<unsigned char>(i
% 255);
56 src_data
[i
* 4 + 3] = static_cast<unsigned char>(i
% 255);
60 // The reference (i.e., old) implementation of |CreateHSLShiftedBitmap()|.
61 SkBitmap
ReferenceCreateHSLShiftedBitmap(
62 const SkBitmap
& bitmap
,
63 color_utils::HSL hsl_shift
) {
65 shifted
.setConfig(SkBitmap::kARGB_8888_Config
, bitmap
.width(),
67 shifted
.allocPixels();
68 shifted
.eraseARGB(0, 0, 0, 0);
69 shifted
.setIsOpaque(false);
71 SkAutoLockPixels
lock_bitmap(bitmap
);
72 SkAutoLockPixels
lock_shifted(shifted
);
74 // Loop through the pixels of the original bitmap.
75 for (int y
= 0; y
< bitmap
.height(); ++y
) {
76 SkPMColor
* pixels
= bitmap
.getAddr32(0, y
);
77 SkPMColor
* tinted_pixels
= shifted
.getAddr32(0, y
);
79 for (int x
= 0; x
< bitmap
.width(); ++x
) {
80 tinted_pixels
[x
] = SkPreMultiplyColor(color_utils::HSLShift(
81 SkUnPreMultiply::PMColorToColor(pixels
[x
]), hsl_shift
));
90 // Invert bitmap and verify the each pixel is inverted and the alpha value is
92 TEST(SkBitmapOperationsTest
, CreateInvertedBitmap
) {
93 int src_w
= 16, src_h
= 16;
95 src
.setConfig(SkBitmap::kARGB_8888_Config
, src_w
, src_h
);
98 for (int y
= 0; y
< src_h
; y
++) {
99 for (int x
= 0; x
< src_w
; x
++) {
100 int i
= y
* src_w
+ x
;
101 *src
.getAddr32(x
, y
) =
102 SkColorSetARGB((255 - i
) % 255, i
% 255, i
* 4 % 255, 0);
106 SkBitmap inverted
= SkBitmapOperations::CreateInvertedBitmap(src
);
107 SkAutoLockPixels
src_lock(src
);
108 SkAutoLockPixels
inverted_lock(inverted
);
110 for (int y
= 0; y
< src_h
; y
++) {
111 for (int x
= 0; x
< src_w
; x
++) {
112 int i
= y
* src_w
+ x
;
113 EXPECT_EQ(static_cast<unsigned int>((255 - i
) % 255),
114 SkColorGetA(*inverted
.getAddr32(x
, y
)));
115 EXPECT_EQ(static_cast<unsigned int>(255 - (i
% 255)),
116 SkColorGetR(*inverted
.getAddr32(x
, y
)));
117 EXPECT_EQ(static_cast<unsigned int>(255 - (i
* 4 % 255)),
118 SkColorGetG(*inverted
.getAddr32(x
, y
)));
119 EXPECT_EQ(static_cast<unsigned int>(255),
120 SkColorGetB(*inverted
.getAddr32(x
, y
)));
125 // Blend two bitmaps together at 50% alpha and verify that the result
126 // is the middle-blend of the two.
127 TEST(SkBitmapOperationsTest
, CreateBlendedBitmap
) {
128 int src_w
= 16, src_h
= 16;
130 src_a
.setConfig(SkBitmap::kARGB_8888_Config
, src_w
, src_h
);
134 src_b
.setConfig(SkBitmap::kARGB_8888_Config
, src_w
, src_h
);
137 for (int y
= 0, i
= 0; y
< src_h
; y
++) {
138 for (int x
= 0; x
< src_w
; x
++) {
139 *src_a
.getAddr32(x
, y
) = SkColorSetARGB(255, 0, i
* 2 % 255, i
% 255);
140 *src_b
.getAddr32(x
, y
) =
141 SkColorSetARGB((255 - i
) % 255, i
% 255, i
* 4 % 255, 0);
147 SkBitmap blended
= SkBitmapOperations::CreateBlendedBitmap(
149 SkAutoLockPixels
srca_lock(src_a
);
150 SkAutoLockPixels
srcb_lock(src_b
);
151 SkAutoLockPixels
blended_lock(blended
);
153 for (int y
= 0; y
< src_h
; y
++) {
154 for (int x
= 0; x
< src_w
; x
++) {
155 int i
= y
* src_w
+ x
;
156 EXPECT_EQ(static_cast<unsigned int>((255 + ((255 - i
) % 255)) / 2),
157 SkColorGetA(*blended
.getAddr32(x
, y
)));
158 EXPECT_EQ(static_cast<unsigned int>(i
% 255 / 2),
159 SkColorGetR(*blended
.getAddr32(x
, y
)));
160 EXPECT_EQ((static_cast<unsigned int>((i
* 2) % 255 + (i
* 4) % 255) / 2),
161 SkColorGetG(*blended
.getAddr32(x
, y
)));
162 EXPECT_EQ(static_cast<unsigned int>(i
% 255 / 2),
163 SkColorGetB(*blended
.getAddr32(x
, y
)));
168 // Test our masking functions.
169 TEST(SkBitmapOperationsTest
, CreateMaskedBitmap
) {
170 int src_w
= 16, src_h
= 16;
173 FillDataToBitmap(src_w
, src_h
, &src
);
175 // Generate alpha mask
177 alpha
.setConfig(SkBitmap::kARGB_8888_Config
, src_w
, src_h
);
179 for (int y
= 0, i
= 0; y
< src_h
; y
++) {
180 for (int x
= 0; x
< src_w
; x
++) {
181 *alpha
.getAddr32(x
, y
) = SkColorSetARGB((i
+ 128) % 255,
189 SkBitmap masked
= SkBitmapOperations::CreateMaskedBitmap(src
, alpha
);
191 SkAutoLockPixels
src_lock(src
);
192 SkAutoLockPixels
alpha_lock(alpha
);
193 SkAutoLockPixels
masked_lock(masked
);
194 for (int y
= 0; y
< src_h
; y
++) {
195 for (int x
= 0; x
< src_w
; x
++) {
196 // Test that the alpha is equal.
197 SkColor src_pixel
= SkUnPreMultiply::PMColorToColor(*src
.getAddr32(x
, y
));
198 SkColor alpha_pixel
=
199 SkUnPreMultiply::PMColorToColor(*alpha
.getAddr32(x
, y
));
200 SkColor masked_pixel
= *masked
.getAddr32(x
, y
);
202 int alpha_value
= SkAlphaMul(SkColorGetA(src_pixel
),
203 SkAlpha255To256(SkColorGetA(alpha_pixel
)));
204 int alpha_value_256
= SkAlpha255To256(alpha_value
);
205 SkColor expected_pixel
= SkColorSetARGB(
207 SkAlphaMul(SkColorGetR(src_pixel
), alpha_value_256
),
208 SkAlphaMul(SkColorGetG(src_pixel
), alpha_value_256
),
209 SkAlphaMul(SkColorGetB(src_pixel
), alpha_value_256
));
211 EXPECT_EQ(expected_pixel
, masked_pixel
);
216 // Make sure that when shifting a bitmap without any shift parameters,
217 // the end result is close enough to the original (rounding errors
219 TEST(SkBitmapOperationsTest
, CreateHSLShiftedBitmapToSame
) {
220 int src_w
= 16, src_h
= 16;
222 src
.setConfig(SkBitmap::kARGB_8888_Config
, src_w
, src_h
);
225 for (int y
= 0, i
= 0; y
< src_h
; y
++) {
226 for (int x
= 0; x
< src_w
; x
++) {
227 *src
.getAddr32(x
, y
) = SkPreMultiplyColor(SkColorSetARGB((i
+ 128) % 255,
228 (i
+ 128) % 255, (i
+ 64) % 255, (i
+ 0) % 255));
233 color_utils::HSL hsl
= { -1, -1, -1 };
234 SkBitmap shifted
= ReferenceCreateHSLShiftedBitmap(src
, hsl
);
236 SkAutoLockPixels
src_lock(src
);
237 SkAutoLockPixels
shifted_lock(shifted
);
239 for (int y
= 0; y
< src_h
; y
++) {
240 for (int x
= 0; x
< src_w
; x
++) {
241 SkColor src_pixel
= *src
.getAddr32(x
, y
);
242 SkColor shifted_pixel
= *shifted
.getAddr32(x
, y
);
243 EXPECT_TRUE(MultipliedColorsClose(src_pixel
, shifted_pixel
)) <<
244 "source: (a,r,g,b) = (" << SkColorGetA(src_pixel
) << "," <<
245 SkColorGetR(src_pixel
) << "," <<
246 SkColorGetG(src_pixel
) << "," <<
247 SkColorGetB(src_pixel
) << "); " <<
248 "shifted: (a,r,g,b) = (" << SkColorGetA(shifted_pixel
) << "," <<
249 SkColorGetR(shifted_pixel
) << "," <<
250 SkColorGetG(shifted_pixel
) << "," <<
251 SkColorGetB(shifted_pixel
) << ")";
256 // Shift a blue bitmap to red.
257 TEST(SkBitmapOperationsTest
, CreateHSLShiftedBitmapHueOnly
) {
258 int src_w
= 16, src_h
= 16;
260 src
.setConfig(SkBitmap::kARGB_8888_Config
, src_w
, src_h
);
263 for (int y
= 0, i
= 0; y
< src_h
; y
++) {
264 for (int x
= 0; x
< src_w
; x
++) {
265 *src
.getAddr32(x
, y
) = SkColorSetARGB(255, 0, 0, i
% 255);
271 color_utils::HSL hsl
= { 0, -1, -1 };
273 SkBitmap shifted
= SkBitmapOperations::CreateHSLShiftedBitmap(src
, hsl
);
275 SkAutoLockPixels
src_lock(src
);
276 SkAutoLockPixels
shifted_lock(shifted
);
278 for (int y
= 0, i
= 0; y
< src_h
; y
++) {
279 for (int x
= 0; x
< src_w
; x
++) {
280 EXPECT_TRUE(ColorsClose(shifted
.getColor(x
, y
),
281 SkColorSetARGB(255, i
% 255, 0, 0)));
287 // Validate HSL shift.
288 TEST(SkBitmapOperationsTest
, ValidateHSLShift
) {
289 // Note: 255/51 = 5 (exactly) => 6 including 0!
291 const int dim
= 255 / inc
+ 1;
293 src
.setConfig(SkBitmap::kARGB_8888_Config
, dim
*dim
, dim
*dim
);
296 for (int a
= 0, y
= 0; a
<= 255; a
+= inc
) {
297 for (int r
= 0; r
<= 255; r
+= inc
, y
++) {
298 for (int g
= 0, x
= 0; g
<= 255; g
+= inc
) {
299 for (int b
= 0; b
<= 255; b
+= inc
, x
++) {
300 *src
.getAddr32(x
, y
) =
301 SkPreMultiplyColor(SkColorSetARGB(a
, r
, g
, b
));
307 // Shhhh. The spec says I should set things to -1 for "no change", but
308 // actually -0.1 will do. Don't tell anyone I did this.
309 for (double h
= -0.1; h
<= 1.0001; h
+= 0.1) {
310 for (double s
= -0.1; s
<= 1.0001; s
+= 0.1) {
311 for (double l
= -0.1; l
<= 1.0001; l
+= 0.1) {
312 color_utils::HSL hsl
= { h
, s
, l
};
313 SkBitmap ref_shifted
= ReferenceCreateHSLShiftedBitmap(src
, hsl
);
314 SkBitmap shifted
= SkBitmapOperations::CreateHSLShiftedBitmap(src
, hsl
);
315 EXPECT_TRUE(BitmapsClose(ref_shifted
, shifted
))
316 << "h = " << h
<< ", s = " << s
<< ", l = " << l
;
322 // Test our cropping.
323 TEST(SkBitmapOperationsTest
, CreateCroppedBitmap
) {
324 int src_w
= 16, src_h
= 16;
326 FillDataToBitmap(src_w
, src_h
, &src
);
328 SkBitmap cropped
= SkBitmapOperations::CreateTiledBitmap(src
, 4, 4,
330 ASSERT_EQ(8, cropped
.width());
331 ASSERT_EQ(8, cropped
.height());
333 SkAutoLockPixels
src_lock(src
);
334 SkAutoLockPixels
cropped_lock(cropped
);
335 for (int y
= 4; y
< 12; y
++) {
336 for (int x
= 4; x
< 12; x
++) {
337 EXPECT_EQ(*src
.getAddr32(x
, y
),
338 *cropped
.getAddr32(x
- 4, y
- 4));
343 // Test whether our cropping correctly wraps across image boundaries.
344 TEST(SkBitmapOperationsTest
, CreateCroppedBitmapWrapping
) {
345 int src_w
= 16, src_h
= 16;
347 FillDataToBitmap(src_w
, src_h
, &src
);
349 SkBitmap cropped
= SkBitmapOperations::CreateTiledBitmap(
350 src
, src_w
/ 2, src_h
/ 2, src_w
, src_h
);
351 ASSERT_EQ(src_w
, cropped
.width());
352 ASSERT_EQ(src_h
, cropped
.height());
354 SkAutoLockPixels
src_lock(src
);
355 SkAutoLockPixels
cropped_lock(cropped
);
356 for (int y
= 0; y
< src_h
; y
++) {
357 for (int x
= 0; x
< src_w
; x
++) {
358 EXPECT_EQ(*src
.getAddr32(x
, y
),
359 *cropped
.getAddr32((x
+ src_w
/ 2) % src_w
,
360 (y
+ src_h
/ 2) % src_h
));
365 TEST(SkBitmapOperationsTest
, DownsampleByTwo
) {
366 // Use an odd-sized bitmap to make sure the edge cases where there isn't a
367 // 2x2 block of pixels is handled correctly.
368 // Here's the ARGB example
370 // 50% transparent green opaque 50% blue white
371 // 80008000 FF000080 FFFFFFFF
373 // 50% transparent red opaque 50% gray black
374 // 80800000 80808080 FF000000
376 // black white 50% gray
377 // FF000000 FFFFFFFF FF808080
379 // The result of this computation should be:
383 input
.setConfig(SkBitmap::kARGB_8888_Config
, 3, 3);
386 // The color order may be different, but we don't care (the channels are
388 *input
.getAddr32(0, 0) = 0x80008000;
389 *input
.getAddr32(1, 0) = 0xFF000080;
390 *input
.getAddr32(2, 0) = 0xFFFFFFFF;
391 *input
.getAddr32(0, 1) = 0x80800000;
392 *input
.getAddr32(1, 1) = 0x80808080;
393 *input
.getAddr32(2, 1) = 0xFF000000;
394 *input
.getAddr32(0, 2) = 0xFF000000;
395 *input
.getAddr32(1, 2) = 0xFFFFFFFF;
396 *input
.getAddr32(2, 2) = 0xFF808080;
398 SkBitmap result
= SkBitmapOperations::DownsampleByTwo(input
);
399 EXPECT_EQ(2, result
.width());
400 EXPECT_EQ(2, result
.height());
402 // Some of the values are off-by-one due to rounding.
403 SkAutoLockPixels
lock(result
);
404 EXPECT_EQ(0x9f404040, *result
.getAddr32(0, 0));
405 EXPECT_EQ(0xFF7f7f7f, *result
.getAddr32(1, 0));
406 EXPECT_EQ(0xFF7f7f7f, *result
.getAddr32(0, 1));
407 EXPECT_EQ(0xFF808080, *result
.getAddr32(1, 1));
410 // Test edge cases for DownsampleByTwo.
411 TEST(SkBitmapOperationsTest
, DownsampleByTwoSmall
) {
412 SkPMColor reference
= 0xFF4080FF;
414 // Test a 1x1 bitmap.
416 one_by_one
.setConfig(SkBitmap::kARGB_8888_Config
, 1, 1);
417 one_by_one
.allocPixels();
418 *one_by_one
.getAddr32(0, 0) = reference
;
419 SkBitmap result
= SkBitmapOperations::DownsampleByTwo(one_by_one
);
420 SkAutoLockPixels
lock1(result
);
421 EXPECT_EQ(1, result
.width());
422 EXPECT_EQ(1, result
.height());
423 EXPECT_EQ(reference
, *result
.getAddr32(0, 0));
425 // Test an n by 1 bitmap.
427 one_by_n
.setConfig(SkBitmap::kARGB_8888_Config
, 300, 1);
428 one_by_n
.allocPixels();
429 result
= SkBitmapOperations::DownsampleByTwo(one_by_n
);
430 SkAutoLockPixels
lock2(result
);
431 EXPECT_EQ(300, result
.width());
432 EXPECT_EQ(1, result
.height());
434 // Test a 1 by n bitmap.
436 n_by_one
.setConfig(SkBitmap::kARGB_8888_Config
, 1, 300);
437 n_by_one
.allocPixels();
438 result
= SkBitmapOperations::DownsampleByTwo(n_by_one
);
439 SkAutoLockPixels
lock3(result
);
440 EXPECT_EQ(1, result
.width());
441 EXPECT_EQ(300, result
.height());
443 // Test an empty bitmap
445 result
= SkBitmapOperations::DownsampleByTwo(empty
);
446 EXPECT_TRUE(result
.isNull());
447 EXPECT_EQ(0, result
.width());
448 EXPECT_EQ(0, result
.height());
451 // Here we assume DownsampleByTwo works correctly (it's tested above) and
452 // just make sure that the wrapper function does the right thing.
453 TEST(SkBitmapOperationsTest
, DownsampleByTwoUntilSize
) {
454 // First make sure a "too small" bitmap doesn't get modified at all.
456 too_small
.setConfig(SkBitmap::kARGB_8888_Config
, 10, 10);
457 too_small
.allocPixels();
458 SkBitmap result
= SkBitmapOperations::DownsampleByTwoUntilSize(
460 EXPECT_EQ(10, result
.width());
461 EXPECT_EQ(10, result
.height());
463 // Now make sure giving it a 0x0 target returns something reasonable.
464 result
= SkBitmapOperations::DownsampleByTwoUntilSize(too_small
, 0, 0);
465 EXPECT_EQ(1, result
.width());
466 EXPECT_EQ(1, result
.height());
468 // Test multiple steps of downsampling.
470 large
.setConfig(SkBitmap::kARGB_8888_Config
, 100, 43);
472 result
= SkBitmapOperations::DownsampleByTwoUntilSize(large
, 6, 6);
474 // The result should be divided in half 100x43 -> 50x22 -> 25x11
475 EXPECT_EQ(25, result
.width());
476 EXPECT_EQ(11, result
.height());
479 TEST(SkBitmapOperationsTest
, UnPreMultiply
) {
481 input
.setConfig(SkBitmap::kARGB_8888_Config
, 2, 2);
484 // Set PMColors into the bitmap
485 *input
.getAddr32(0, 0) = SkPackARGB32NoCheck(0x80, 0x00, 0x00, 0x00);
486 *input
.getAddr32(1, 0) = SkPackARGB32NoCheck(0x80, 0x80, 0x80, 0x80);
487 *input
.getAddr32(0, 1) = SkPackARGB32NoCheck(0xFF, 0x00, 0xCC, 0x88);
488 *input
.getAddr32(1, 1) = SkPackARGB32NoCheck(0x00, 0x00, 0xCC, 0x88);
490 SkBitmap result
= SkBitmapOperations::UnPreMultiply(input
);
491 EXPECT_EQ(2, result
.width());
492 EXPECT_EQ(2, result
.height());
494 SkAutoLockPixels
lock(result
);
495 EXPECT_EQ(0x80000000, *result
.getAddr32(0, 0));
496 EXPECT_EQ(0x80FFFFFF, *result
.getAddr32(1, 0));
497 EXPECT_EQ(0xFF00CC88, *result
.getAddr32(0, 1));
498 EXPECT_EQ(0x00000000u
, *result
.getAddr32(1, 1)); // "Division by zero".
501 TEST(SkBitmapOperationsTest
, CreateTransposedBitmap
) {
503 input
.setConfig(SkBitmap::kARGB_8888_Config
, 2, 3);
506 for (int x
= 0; x
< input
.width(); ++x
) {
507 for (int y
= 0; y
< input
.height(); ++y
) {
508 *input
.getAddr32(x
, y
) = x
* input
.width() + y
;
512 SkBitmap result
= SkBitmapOperations::CreateTransposedBitmap(input
);
513 EXPECT_EQ(3, result
.width());
514 EXPECT_EQ(2, result
.height());
516 SkAutoLockPixels
lock(result
);
517 for (int x
= 0; x
< input
.width(); ++x
) {
518 for (int y
= 0; y
< input
.height(); ++y
) {
519 EXPECT_EQ(*input
.getAddr32(x
, y
), *result
.getAddr32(y
, x
));
524 // Check that Rotate provides the desired results
525 TEST(SkBitmapOperationsTest
, RotateImage
) {
526 const int src_w
= 6, src_h
= 4;
528 // Create a simple 4 color bitmap:
533 src
.setConfig(SkBitmap::kARGB_8888_Config
, src_w
, src_h
);
536 SkCanvas
canvas(src
);
539 region
.setRect(0, 0, src_w
/ 2, src_h
/ 2);
540 canvas
.setClipRegion(region
);
541 canvas
.drawColor(SK_ColorRED
, SkXfermode::kSrc_Mode
);
542 region
.setRect(src_w
/ 2, 0, src_w
, src_h
/ 2);
543 canvas
.setClipRegion(region
);
544 canvas
.drawColor(SK_ColorBLUE
, SkXfermode::kSrc_Mode
);
545 region
.setRect(0, src_h
/ 2, src_w
/ 2, src_h
);
546 canvas
.setClipRegion(region
);
547 canvas
.drawColor(SK_ColorGREEN
, SkXfermode::kSrc_Mode
);
548 region
.setRect(src_w
/ 2, src_h
/ 2, src_w
, src_h
);
549 canvas
.setClipRegion(region
);
550 canvas
.drawColor(SK_ColorYELLOW
, SkXfermode::kSrc_Mode
);
553 SkBitmap rotate90
, rotate180
, rotate270
;
554 rotate90
= SkBitmapOperations::Rotate(src
,
555 SkBitmapOperations::ROTATION_90_CW
);
556 rotate180
= SkBitmapOperations::Rotate(src
,
557 SkBitmapOperations::ROTATION_180_CW
);
558 rotate270
= SkBitmapOperations::Rotate(src
,
559 SkBitmapOperations::ROTATION_270_CW
);
561 ASSERT_EQ(rotate90
.width(), src
.height());
562 ASSERT_EQ(rotate90
.height(), src
.width());
563 ASSERT_EQ(rotate180
.width(), src
.width());
564 ASSERT_EQ(rotate180
.height(), src
.height());
565 ASSERT_EQ(rotate270
.width(), src
.height());
566 ASSERT_EQ(rotate270
.height(), src
.width());
568 SkAutoLockPixels
lock_src(src
);
569 SkAutoLockPixels
lock_90(rotate90
);
570 SkAutoLockPixels
lock_180(rotate180
);
571 SkAutoLockPixels
lock_270(rotate270
);
573 for (int x
=0; x
< src_w
; ++x
) {
574 for (int y
=0; y
< src_h
; ++y
) {
575 ASSERT_EQ(*src
.getAddr32(x
,y
), *rotate90
.getAddr32(y
, src_w
- (x
+1)));
576 ASSERT_EQ(*src
.getAddr32(x
,y
), *rotate270
.getAddr32(src_h
- (y
+1),x
));
577 ASSERT_EQ(*src
.getAddr32(x
,y
),
578 *rotate180
.getAddr32(src_w
- (x
+1), src_h
- (y
+1)));