| 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 #include "SkImageEncoder.h" | 8 #include "SkImageEncoder.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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 ctIndex = 0; ctIndex < SK_ARRAY_COUNT(gColorTypes); ++ctIndex) { | 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 bool success = bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight, | 38 bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight, gColorTypes[ct
Index], |
| 39 gColorTypes[ctIndex], kO
paque_SkAlphaType)); | 39 kOpaque_SkAlphaType)); |
| 40 REPORTER_ASSERT(reporter, success); | |
| 41 bitmap.eraseColor(SK_ColorBLUE); | 40 bitmap.eraseColor(SK_ColorBLUE); |
| 42 // Change rows [0,1] from blue to [red,green]. | 41 // Change rows [0,1] from blue to [red,green]. |
| 43 SkCanvas canvas(bitmap); | 42 SkCanvas canvas(bitmap); |
| 44 SkPaint paint; | 43 SkPaint paint; |
| 45 paint.setColor(SK_ColorRED); | 44 paint.setColor(SK_ColorRED); |
| 46 canvas.drawIRect(SkIRect::MakeLTRB(0, 0, kWidth, 1), paint); | 45 canvas.drawIRect(SkIRect::MakeLTRB(0, 0, kWidth, 1), paint); |
| 47 paint.setColor(SK_ColorGREEN); | 46 paint.setColor(SK_ColorGREEN); |
| 48 canvas.drawIRect(SkIRect::MakeLTRB(0, 1, kWidth, 2), paint); | 47 canvas.drawIRect(SkIRect::MakeLTRB(0, 1, kWidth, 2), paint); |
| 49 } | 48 } |
| 50 | 49 |
| 51 // Transform the bitmap. | 50 // Transform the bitmap. |
| 52 int bufferSize = bitmap.width() * bitmap.height() * 4; | 51 int bufferSize = bitmap.width() * bitmap.height() * 4; |
| 53 SkAutoMalloc pixelBufferManager(bufferSize); | 52 SkAutoMalloc pixelBufferManager(bufferSize); |
| 54 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get()); | 53 char *pixelBuffer = static_cast<char *>(pixelBufferManager.get()); |
| 55 SkMemoryWStream out(pixelBuffer, bufferSize); | 54 SkMemoryWStream out(pixelBuffer, bufferSize); |
| 56 REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder
::kDefaultQuality)); | 55 REPORTER_ASSERT(reporter, enc->encodeStream(&out, bitmap, SkImageEncoder
::kDefaultQuality)); |
| 57 | 56 |
| 58 // Confirm we got the expected results. | 57 // Confirm we got the expected results. |
| 59 REPORTER_ASSERT(reporter, bufferSize == sizeof(comparisonBuffer)); | 58 REPORTER_ASSERT(reporter, bufferSize == sizeof(comparisonBuffer)); |
| 60 REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSi
ze) == 0); | 59 REPORTER_ASSERT(reporter, memcmp(pixelBuffer, comparisonBuffer, bufferSi
ze) == 0); |
| 61 } | 60 } |
| 62 } | 61 } |
| OLD | NEW |