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

Side by Side Diff: tests/ARGBImageEncoderTest.cpp

Issue 25275004: store SkAlphaType inside SkBitmap, on road to support unpremul (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove occurances of setIsOpaque Created 7 years, 2 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 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 /** Tests for ARGBImageEncoder. */ 8 /** Tests for ARGBImageEncoder. */
9 9
10 #include "Test.h" 10 #include "Test.h"
(...skipping 30 matching lines...) Expand all
41 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue 41 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue
42 }; 42 };
43 43
44 SkAutoTDelete<SkImageEncoder> enc(CreateARGBImageEncoder()); 44 SkAutoTDelete<SkImageEncoder> enc(CreateARGBImageEncoder());
45 for (size_t configIndex = 0; configIndex < SK_ARRAY_COUNT(configs); ++config Index) { 45 for (size_t configIndex = 0; configIndex < SK_ARRAY_COUNT(configs); ++config Index) {
46 // A bitmap that should generate the above bytes: 46 // A bitmap that should generate the above bytes:
47 SkBitmap bitmap; 47 SkBitmap bitmap;
48 { 48 {
49 bitmap.setConfig(configs[configIndex], kWidth, kHeight); 49 bitmap.setConfig(configs[configIndex], kWidth, kHeight);
50 REPORTER_ASSERT(reporter, bitmap.allocPixels()); 50 REPORTER_ASSERT(reporter, bitmap.allocPixels());
51 bitmap.setIsOpaque(true); 51 bitmap.setAlphaType(kOpaque_SkAlphaType);
52 bitmap.eraseColor(SK_ColorBLUE); 52 bitmap.eraseColor(SK_ColorBLUE);
53 // Change rows [0,1] from blue to [red,green]. 53 // Change rows [0,1] from blue to [red,green].
54 SkCanvas canvas(bitmap); 54 SkCanvas canvas(bitmap);
55 SkPaint paint; 55 SkPaint paint;
56 paint.setColor(SK_ColorRED); 56 paint.setColor(SK_ColorRED);
57 canvas.drawIRect(SkIRect::MakeLTRB(0, 0, kWidth, 1), paint); 57 canvas.drawIRect(SkIRect::MakeLTRB(0, 0, kWidth, 1), paint);
58 paint.setColor(SK_ColorGREEN); 58 paint.setColor(SK_ColorGREEN);
59 canvas.drawIRect(SkIRect::MakeLTRB(0, 1, kWidth, 2), paint); 59 canvas.drawIRect(SkIRect::MakeLTRB(0, 1, kWidth, 2), paint);
60 } 60 }
61 61
62 // Transform the bitmap. 62 // Transform the bitmap.
63 int bufferSize = bitmap.width() * bitmap.height() * 4; 63 int bufferSize = bitmap.width() * bitmap.height() * 4;
64 SkAutoMalloc pixelBufferManager(bufferSize); 64 SkAutoMalloc pixelBufferManager(bufferSize);
65 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get()); 65 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get());
66 SkMemoryWStream out(pixelBuffer, bufferSize); 66 SkMemoryWStream out(pixelBuffer, bufferSize);
67 REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder ::kDefaultQuality)); 67 REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder ::kDefaultQuality));
68 68
69 // Confirm we got the expected results. 69 // Confirm we got the expected results.
70 REPORTER_ASSERT(reporter, bufferSize == sizeof(comparisonBuffer)); 70 REPORTER_ASSERT(reporter, bufferSize == sizeof(comparisonBuffer));
71 REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSi ze) == 0); 71 REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSi ze) == 0);
72 } 72 }
73 } 73 }
74 74
75 static TestRegistry gReg(BitmapTransformerTestClass::Factory); 75 static TestRegistry gReg(BitmapTransformerTestClass::Factory);
76 76
77 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698