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

Side by Side Diff: tests/BitmapTransformerTest.cpp

Issue 14267031: ARGB image encoder for checksums. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Something which can actually be checked in. Created 7 years, 8 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
« no previous file with comments | « tests/ARGBImageEncoderTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 /**
10 * Tests for SkBitmapTransformer.h and SkBitmapTransformer.cpp
11 */
12
13 #include "Test.h"
14 #include "SkBitmap.h"
15 #include "SkBitmapTransformer.h"
16
17 namespace skiatest {
18 class BitmapTransformerTestClass : public Test {
19 public:
20 static Test* Factory(void*) {return SkNEW(BitmapTransformerTestClass); }
21 protected:
22 virtual void onGetName(SkString* name) { name->set("BitmapTransformer"); }
23 virtual void onRun(Reporter* reporter) {
24 this->fReporter = reporter;
25 RunTest();
26 }
27 private:
28 void RunTest() {
29 SkBitmap bitmap;
30 SkBitmap::Config supportedConfig = SkBitmap::kARGB_8888_Config;
31 SkBitmap::Config unsupportedConfig = SkBitmap::kARGB_4444_Config;
32 SkBitmapTransformer::PixelFormat supportedPixelFormat =
33 SkBitmapTransformer::kARGB_8888_Premul_PixelFormat;
34 const int kWidth = 55;
35 const int kHeight = 333;
36
37 // Transformations that we know are unsupported:
38 {
39 bitmap.setConfig(unsupportedConfig, kWidth, kHeight);
40 SkBitmapTransformer transformer = SkBitmapTransformer(bitmap, su pportedPixelFormat);
41 REPORTER_ASSERT(fReporter, !transformer.isValid());
42 }
43
44 // Valid transformations:
45 {
46 // Bytes we expect to get:
47 const int kWidth = 3;
48 const int kHeight = 5;
49 const unsigned char comparisonBuffer[] = {
50 // kHeight rows, each with kWidth pixels, premultiplied ARGB for each pixel
51 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x0 0, // red
52 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x0 0, // green
53 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xf f, // blue
54 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xf f, // blue
55 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xf f, // blue
56 };
57
58 // A bitmap that should generate the above bytes:
59 bitmap.setConfig(supportedConfig, kWidth, kHeight);
60 REPORTER_ASSERT(fReporter, bitmap.allocPixels());
61 bitmap.setIsOpaque(true);
62 bitmap.eraseColor(SK_ColorBLUE);
63 bitmap.lockPixels();
64 // Change rows [0,1] from blue to [red,green].
65 SkColor oldColor = SK_ColorBLUE;
66 SkColor newColors[] = {SK_ColorRED, SK_ColorGREEN};
67 for (int y = 0; y <= 1; y++) {
68 for (int x = 0; x < kWidth; x++) {
69 REPORTER_ASSERT(fReporter, bitmap.getColor(x, y) == oldC olor);
70 SkPMColor* pixel = static_cast<SkPMColor *>(bitmap.getAd dr(x, y));
71 *pixel = SkPreMultiplyColor(newColors[y]);
72 REPORTER_ASSERT(fReporter, bitmap.getColor(x, y) == newC olors[y]);
73 }
74 }
75 bitmap.unlockPixels();
76
77 // Transform the bitmap and confirm we got the expected results.
78 SkBitmapTransformer transformer = SkBitmapTransformer(bitmap, su pportedPixelFormat);
79 REPORTER_ASSERT(fReporter, transformer.isValid());
80 REPORTER_ASSERT(fReporter, transformer.bytesNeededPerRow() == kW idth * 4);
81 REPORTER_ASSERT(fReporter, transformer.bytesNeededTotal() == kWi dth * kHeight * 4);
82 int bufferSize = transformer.bytesNeededTotal();
83 SkAutoMalloc pixelBufferManager(bufferSize);
84 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get() );
85 REPORTER_ASSERT(fReporter,
86 transformer.copyBitmapToPixelBuffer(pixelBuffer, bufferSize));
87 REPORTER_ASSERT(fReporter, bufferSize == sizeof(comparisonBuffer ));
88 REPORTER_ASSERT(fReporter, memcmp(pixelBuffer, comparisonBuffer, bufferSize) == 0);
89 }
90
91 }
92
93 Reporter* fReporter;
94 };
95
96 static TestRegistry gReg(BitmapTransformerTestClass::Factory);
97 }
OLDNEW
« no previous file with comments | « tests/ARGBImageEncoderTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698