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

Side by Side Diff: gm/all_bitmap_configs.cpp

Issue 1514503004: SkBitmap move (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-10 (Thursday) 17:55:13 EST Created 5 years 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
« no previous file with comments | « no previous file | gm/arithmode.cpp » ('j') | src/core/SkBitmap.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "sk_tool_utils.h" 8 #include "sk_tool_utils.h"
9 #include "SkSurface.h" 9 #include "SkSurface.h"
10 #include "Resources.h" 10 #include "Resources.h"
11 #include "gm.h" 11 #include "gm.h"
12 12
13 #include "SkMath.h" 13 #include "SkMath.h"
14 #include "SkColorPriv.h" 14 #include "SkColorPriv.h"
15 15
16 static SkBitmap copy_bitmap(const SkBitmap& src, SkColorType colorType) { 16 static SkBitmap copy_bitmap(const SkBitmap& src, SkColorType colorType) {
17 SkBitmap copy; 17 SkBitmap copy;
18 src.copyTo(&copy, colorType); 18 src.copyTo(&copy, colorType);
19 copy.setImmutable(); 19 copy.setImmutable();
20 return copy; 20 return skstd::move(copy);
21 } 21 }
22 22
23 #define SCALE 128 23 #define SCALE 128
24 24
25 // Make either A8 or gray8 bitmap. 25 // Make either A8 or gray8 bitmap.
26 static SkBitmap make_bitmap(SkColorType ct) { 26 static SkBitmap make_bitmap(SkColorType ct) {
27 SkBitmap bm; 27 SkBitmap bm;
28 switch (ct) { 28 switch (ct) {
29 case kAlpha_8_SkColorType: 29 case kAlpha_8_SkColorType:
30 bm.allocPixels(SkImageInfo::MakeA8(SCALE, SCALE)); 30 bm.allocPixels(SkImageInfo::MakeA8(SCALE, SCALE));
31 break; 31 break;
32 case kGray_8_SkColorType: 32 case kGray_8_SkColorType:
33 bm.allocPixels( 33 bm.allocPixels(
34 SkImageInfo::Make(SCALE, SCALE, ct, kOpaque_SkAlphaType)); 34 SkImageInfo::Make(SCALE, SCALE, ct, kOpaque_SkAlphaType));
35 break; 35 break;
36 default: 36 default:
37 SkASSERT(false); 37 SkASSERT(false);
38 return bm; 38 return bm;
39 } 39 }
40 SkAutoLockPixels autoLockPixels(bm); 40 SkAutoLockPixels autoLockPixels(bm);
41 uint8_t spectrum[256]; 41 uint8_t spectrum[256];
42 for (int y = 0; y < 256; ++y) { 42 for (int y = 0; y < 256; ++y) {
43 spectrum[y] = y; 43 spectrum[y] = y;
44 } 44 }
45 for (int y = 0; y < 128; ++y) { 45 for (int y = 0; y < 128; ++y) {
46 // Shift over one byte each scanline. 46 // Shift over one byte each scanline.
47 memcpy(bm.getAddr8(0, y), &spectrum[y], 128); 47 memcpy(bm.getAddr8(0, y), &spectrum[y], 128);
48 } 48 }
49 bm.setImmutable(); 49 bm.setImmutable();
50 return bm; 50 return skstd::move(bm);
51 } 51 }
52 52
53 static void draw_center_letter(char c, 53 static void draw_center_letter(char c,
54 SkPaint* p, 54 SkPaint* p,
55 SkColor color, 55 SkColor color,
56 SkScalar x, 56 SkScalar x,
57 SkScalar y, 57 SkScalar y,
58 SkCanvas* canvas) { 58 SkCanvas* canvas) {
59 SkRect bounds; 59 SkRect bounds;
60 p->setColor(color); 60 p->setColor(color);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 bm.allocPixels(info, nullptr, ctable); 130 bm.allocPixels(info, nullptr, ctable);
131 SkAutoLockPixels autoLockPixels1(n32bitmap); 131 SkAutoLockPixels autoLockPixels1(n32bitmap);
132 SkAutoLockPixels autoLockPixels2(bm); 132 SkAutoLockPixels autoLockPixels2(bm);
133 for (int y = 0; y < SCALE; ++y) { 133 for (int y = 0; y < SCALE; ++y) {
134 for (int x = 0; x < SCALE; ++x) { 134 for (int x = 0; x < SCALE; ++x) {
135 SkPMColor c = *n32bitmap.getAddr32(x, y); 135 SkPMColor c = *n32bitmap.getAddr32(x, y);
136 int idx = find(pmColors, SK_ARRAY_COUNT(pmColors), c); 136 int idx = find(pmColors, SK_ARRAY_COUNT(pmColors), c);
137 *bm.getAddr8(x, y) = SkClampMax(idx, SK_ARRAY_COUNT(pmColors) - 1); 137 *bm.getAddr8(x, y) = SkClampMax(idx, SK_ARRAY_COUNT(pmColors) - 1);
138 } 138 }
139 } 139 }
140 return bm; 140 return skstd::move(bm);
141 } 141 }
142 142
143 static void draw(SkCanvas* canvas, 143 static void draw(SkCanvas* canvas,
144 const SkPaint& p, 144 const SkPaint& p,
145 const SkBitmap& src, 145 const SkBitmap& src,
146 SkColorType colorType, 146 SkColorType colorType,
147 const char text[]) { 147 const char text[]) {
148 SkASSERT(src.colorType() == colorType); 148 SkASSERT(src.colorType() == colorType);
149 canvas->drawBitmap(src, 0.0f, 0.0f); 149 canvas->drawBitmap(src, 0.0f, 0.0f);
150 canvas->drawText(text, strlen(text), 0.0f, 12.0f, p); 150 canvas->drawText(text, strlen(text), 0.0f, 12.0f, p);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 SkASSERT(notN32bitmap.colorType() == ct); 209 SkASSERT(notN32bitmap.colorType() == ct);
210 return SkImage::NewFromBitmap(notN32bitmap); 210 return SkImage::NewFromBitmap(notN32bitmap);
211 } 211 }
212 212
213 DEF_SIMPLE_GM(not_native32_bitmap_config, canvas, SCALE, SCALE) { 213 DEF_SIMPLE_GM(not_native32_bitmap_config, canvas, SCALE, SCALE) {
214 SkAutoTUnref<SkImage> notN32image(make_not_native32_color_wheel()); 214 SkAutoTUnref<SkImage> notN32image(make_not_native32_color_wheel());
215 SkASSERT(notN32image); 215 SkASSERT(notN32image);
216 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8); 216 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
217 canvas->drawImage(notN32image, 0.0f, 0.0f); 217 canvas->drawImage(notN32image, 0.0f, 0.0f);
218 } 218 }
OLDNEW
« no previous file with comments | « no previous file | gm/arithmode.cpp » ('j') | src/core/SkBitmap.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698