| OLD | NEW |
| 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 #include "SkImageEncoder.h" |
| 9 | 9 |
| 10 #include "Test.h" | |
| 11 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 12 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 13 #include "SkImageEncoder.h" | |
| 14 #include "SkStream.h" | 12 #include "SkStream.h" |
| 13 #include "Test.h" |
| 14 #include "TestClassDef.h" |
| 15 | 15 |
| 16 namespace skiatest { | 16 static SkBitmap::Config configs[] = { |
| 17 | 17 SkBitmap::kRGB_565_Config, |
| 18 class BitmapTransformerTestClass : public Test { | 18 SkBitmap::kARGB_8888_Config, |
| 19 public: | |
| 20 static Test* Factory(void*) { return SkNEW(BitmapTransformerTestClass); } | |
| 21 protected: | |
| 22 virtual void onGetName(SkString* name) SK_OVERRIDE { name->set("ARGBImageEnc
oder"); } | |
| 23 virtual void onRun(Reporter* reporter) SK_OVERRIDE; | |
| 24 }; | 19 }; |
| 25 | 20 |
| 26 static SkBitmap::Config configs[] = { | 21 DEF_TEST(ARGBImageEncoder, reporter) { |
| 27 SkBitmap::kRGB_565_Config, | |
| 28 SkBitmap::kARGB_8888_Config, | |
| 29 }; | |
| 30 | |
| 31 void BitmapTransformerTestClass::onRun(Reporter* reporter) { | |
| 32 // Bytes we expect to get: | 22 // Bytes we expect to get: |
| 33 const int kWidth = 3; | 23 const int kWidth = 3; |
| 34 const int kHeight = 5; | 24 const int kHeight = 5; |
| 35 const unsigned char comparisonBuffer[] = { | 25 const unsigned char comparisonBuffer[] = { |
| 36 // kHeight rows, each with kWidth pixels, premultiplied ARGB for each pi
xel | 26 // kHeight rows, each with kWidth pixels, premultiplied ARGB for each pi
xel |
| 37 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, // red | 27 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00, // red |
| 38 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, // green | 28 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, 0xff,0x00,0xff,0x00, // green |
| 39 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 |
| 40 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 |
| 41 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue | 31 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, // blue |
| (...skipping 22 matching lines...) Expand all Loading... |
| 64 SkAutoMalloc pixelBufferManager(bufferSize); | 54 SkAutoMalloc pixelBufferManager(bufferSize); |
| 65 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get()); | 55 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get()); |
| 66 SkMemoryWStream out(pixelBuffer, bufferSize); | 56 SkMemoryWStream out(pixelBuffer, bufferSize); |
| 67 REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder
::kDefaultQuality)); | 57 REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder
::kDefaultQuality)); |
| 68 | 58 |
| 69 // Confirm we got the expected results. | 59 // Confirm we got the expected results. |
| 70 REPORTER_ASSERT(reporter, bufferSize == sizeof(comparisonBuffer)); | 60 REPORTER_ASSERT(reporter, bufferSize == sizeof(comparisonBuffer)); |
| 71 REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSi
ze) == 0); | 61 REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSi
ze) == 0); |
| 72 } | 62 } |
| 73 } | 63 } |
| 74 | |
| 75 static TestRegistry gReg(BitmapTransformerTestClass::Factory); | |
| 76 | |
| 77 } | |
| OLD | NEW |