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

Side by Side Diff: tests/PremulAlphaRoundTripTest.cpp

Issue 199413013: add new readPixels with direct memory parameters (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkConfig8888.h" 10 #include "SkConfig8888.h"
(...skipping 21 matching lines...) Expand all
32 byte[0] = SkColorGetB(c); 32 byte[0] = SkColorGetB(c);
33 byte[1] = SkColorGetG(c); 33 byte[1] = SkColorGetG(c);
34 byte[2] = SkColorGetR(c); 34 byte[2] = SkColorGetR(c);
35 byte[3] = SkColorGetA(c); 35 byte[3] = SkColorGetA(c);
36 return packed; 36 return packed;
37 } 37 }
38 38
39 typedef uint32_t (*PackUnpremulProc)(SkColor); 39 typedef uint32_t (*PackUnpremulProc)(SkColor);
40 40
41 const struct { 41 const struct {
42 SkColorType fColorType; 42 SkColorType fColorType;
43 PackUnpremulProc fPackProc; 43 PackUnpremulProc fPackProc;
44 SkCanvas::Config8888 fConfig8888;
45 } gUnpremul[] = { 44 } gUnpremul[] = {
46 { kRGBA_8888_SkColorType, pack_unpremul_rgba, SkCanvas::kRGBA_Unpremul_Confi g8888 }, 45 { kRGBA_8888_SkColorType, pack_unpremul_rgba },
47 { kBGRA_8888_SkColorType, pack_unpremul_bgra, SkCanvas::kBGRA_Unpremul_Confi g8888 }, 46 { kBGRA_8888_SkColorType, pack_unpremul_bgra },
48 }; 47 };
49 48
50 static void fillCanvas(SkCanvas* canvas, SkColorType colorType, PackUnpremulProc proc) { 49 static void fillCanvas(SkCanvas* canvas, SkColorType colorType, PackUnpremulProc proc) {
51 // Don't strictly need a bitmap, but its a handy way to allocate the pixels 50 // Don't strictly need a bitmap, but its a handy way to allocate the pixels
52 SkBitmap bmp; 51 SkBitmap bmp;
53 bmp.allocN32Pixels(256, 256); 52 bmp.allocN32Pixels(256, 256);
54 53
55 for (int a = 0; a < 256; ++a) { 54 for (int a = 0; a < 256; ++a) {
56 uint32_t* pixels = bmp.getAddr32(0, a); 55 uint32_t* pixels = bmp.getAddr32(0, a);
57 for (int r = 0; r < 256; ++r) { 56 for (int r = 0; r < 256; ++r) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 continue; 91 continue;
93 } 92 }
94 93
95 device.reset(SkGpuDevice::Create(context, info, 0)); 94 device.reset(SkGpuDevice::Create(context, info, 0));
96 #else 95 #else
97 continue; 96 continue;
98 #endif 97 #endif
99 } 98 }
100 SkCanvas canvas(device); 99 SkCanvas canvas(device);
101 100
102 SkBitmap readBmp1;
103 readBmp1.allocN32Pixels(256, 256);
104 SkBitmap readBmp2;
105 readBmp2.allocN32Pixels(256, 256);
106
107 for (size_t upmaIdx = 0; upmaIdx < SK_ARRAY_COUNT(gUnpremul); ++upma Idx) { 101 for (size_t upmaIdx = 0; upmaIdx < SK_ARRAY_COUNT(gUnpremul); ++upma Idx) {
108 fillCanvas(&canvas, gUnpremul[upmaIdx].fColorType, gUnpremul[upm aIdx].fPackProc); 102 fillCanvas(&canvas, gUnpremul[upmaIdx].fColorType, gUnpremul[upm aIdx].fPackProc);
109 103
104 const SkImageInfo info = SkImageInfo::Make(256, 256, gUnpremul[u pmaIdx].fColorType,
105 kUnpremul_SkAlphaType );
106 SkBitmap readBmp1;
107 readBmp1.allocPixels(info);
108 SkBitmap readBmp2;
109 readBmp2.allocPixels(info);
110
110 readBmp1.eraseColor(0); 111 readBmp1.eraseColor(0);
111 readBmp2.eraseColor(0); 112 readBmp2.eraseColor(0);
112 113
113 canvas.readPixels(&readBmp1, 0, 0, gUnpremul[upmaIdx].fConfig888 8); 114 canvas.readPixels(&readBmp1, 0, 0);
114 sk_tool_utils::write_pixels(&canvas, readBmp1, 0, 0, gUnpremul[u pmaIdx].fColorType, 115 sk_tool_utils::write_pixels(&canvas, readBmp1, 0, 0, gUnpremul[u pmaIdx].fColorType,
115 kUnpremul_SkAlphaType); 116 kUnpremul_SkAlphaType);
116 canvas.readPixels(&readBmp2, 0, 0, gUnpremul[upmaIdx].fConfig888 8); 117 canvas.readPixels(&readBmp2, 0, 0);
117 118
118 bool success = true; 119 bool success = true;
119 for (int y = 0; y < 256 && success; ++y) { 120 for (int y = 0; y < 256 && success; ++y) {
120 const uint32_t* pixels1 = readBmp1.getAddr32(0, y); 121 const uint32_t* pixels1 = readBmp1.getAddr32(0, y);
121 const uint32_t* pixels2 = readBmp2.getAddr32(0, y); 122 const uint32_t* pixels2 = readBmp2.getAddr32(0, y);
122 for (int x = 0; x < 256 && success; ++x) { 123 for (int x = 0; x < 256 && success; ++x) {
123 REPORTER_ASSERT(reporter, success = pixels1[x] == pixels 2[x]); 124 REPORTER_ASSERT(reporter, success = pixels1[x] == pixels 2[x]);
124 } 125 }
125 } 126 }
126 } 127 }
127 } 128 }
128 } 129 }
129 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698