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/ARGBImageEncoderTest.cpp

Issue 322963002: hide SkBitmap::setConfig (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 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
« no previous file with comments | « src/ports/SkImageDecoder_empty.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkImageEncoder.h" 8 #include "SkImageEncoder.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkStream.h" 12 #include "SkStream.h"
13 #include "Test.h" 13 #include "Test.h"
14 14
15 static SkBitmap::Config configs[] = { 15 static SkColorType gColorTypes[] = {
16 SkBitmap::kRGB_565_Config, 16 kRGB_565_SkColorType,
17 SkBitmap::kARGB_8888_Config, 17 kN32_SkColorType,
18 }; 18 };
19 19
20 DEF_TEST(ARGBImageEncoder, reporter) { 20 DEF_TEST(ARGBImageEncoder, reporter) {
21 // Bytes we expect to get: 21 // Bytes we expect to get:
22 const int kWidth = 3; 22 const int kWidth = 3;
23 const int kHeight = 5; 23 const int kHeight = 5;
24 const unsigned char comparisonBuffer[] = { 24 const unsigned char comparisonBuffer[] = {
25 // kHeight rows, each with kWidth pixels, premultiplied ARGB for each pi xel 25 // kHeight rows, each with kWidth pixels, premultiplied ARGB for each pi xel
26 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, // red 26 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, // red
27 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, // green 27 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, // green
28 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue 28 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue
29 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue 29 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue
30 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue 30 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue
31 }; 31 };
32 32
33 SkAutoTDelete<SkImageEncoder> enc(CreateARGBImageEncoder()); 33 SkAutoTDelete<SkImageEncoder> enc(CreateARGBImageEncoder());
34 for (size_t configIndex = 0; configIndex < SK_ARRAY_COUNT(configs); ++config Index) { 34 for (size_t ctIndex = 0; ctIndex < SK_ARRAY_COUNT(gColorTypes); ++ctIndex) {
35 // A bitmap that should generate the above bytes: 35 // A bitmap that should generate the above bytes:
36 SkBitmap bitmap; 36 SkBitmap bitmap;
37 { 37 {
38 bitmap.setConfig(configs[configIndex], kWidth, kHeight); 38 bool success = bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight,
39 REPORTER_ASSERT(reporter, bitmap.allocPixels()); 39 gColorTypes[ctIndex], kO paque_SkAlphaType));
40 bitmap.setAlphaType(kOpaque_SkAlphaType); 40 REPORTER_ASSERT(reporter, success);
41 bitmap.eraseColor(SK_ColorBLUE); 41 bitmap.eraseColor(SK_ColorBLUE);
42 // Change rows [0,1] from blue to [red,green]. 42 // Change rows [0,1] from blue to [red,green].
43 SkCanvas canvas(bitmap); 43 SkCanvas canvas(bitmap);
44 SkPaint paint; 44 SkPaint paint;
45 paint.setColor(SK_ColorRED); 45 paint.setColor(SK_ColorRED);
46 canvas.drawIRect(SkIRect::MakeLTRB(0, 0, kWidth, 1), paint); 46 canvas.drawIRect(SkIRect::MakeLTRB(0, 0, kWidth, 1), paint);
47 paint.setColor(SK_ColorGREEN); 47 paint.setColor(SK_ColorGREEN);
48 canvas.drawIRect(SkIRect::MakeLTRB(0, 1, kWidth, 2), paint); 48 canvas.drawIRect(SkIRect::MakeLTRB(0, 1, kWidth, 2), paint);
49 } 49 }
50 50
51 // Transform the bitmap. 51 // Transform the bitmap.
52 int bufferSize = bitmap.width() * bitmap.height() * 4; 52 int bufferSize = bitmap.width() * bitmap.height() * 4;
53 SkAutoMalloc pixelBufferManager(bufferSize); 53 SkAutoMalloc pixelBufferManager(bufferSize);
54 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get()); 54 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get());
55 SkMemoryWStream out(pixelBuffer, bufferSize); 55 SkMemoryWStream out(pixelBuffer, bufferSize);
56 REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder ::kDefaultQuality)); 56 REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder ::kDefaultQuality));
57 57
58 // Confirm we got the expected results. 58 // Confirm we got the expected results.
59 REPORTER_ASSERT(reporter, bufferSize == sizeof(comparisonBuffer)); 59 REPORTER_ASSERT(reporter, bufferSize == sizeof(comparisonBuffer));
60 REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSi ze) == 0); 60 REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSi ze) == 0);
61 } 61 }
62 } 62 }
OLDNEW
« no previous file with comments | « src/ports/SkImageDecoder_empty.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698