| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
| 11 #include "SkMD5.h" | 11 #include "SkMD5.h" |
| 12 #include "SkScanlineDecoder.h" |
| 12 #include "Test.h" | 13 #include "Test.h" |
| 13 | 14 |
| 14 static SkStreamAsset* resource(const char path[]) { | 15 static SkStreamAsset* resource(const char path[]) { |
| 15 SkString fullPath = GetResourcePath(path); | 16 SkString fullPath = GetResourcePath(path); |
| 16 return SkStream::NewFromFile(fullPath.c_str()); | 17 return SkStream::NewFromFile(fullPath.c_str()); |
| 17 } | 18 } |
| 18 | 19 |
| 19 static void md5(const SkBitmap& bm, SkMD5::Digest* digest) { | 20 static void md5(const SkBitmap& bm, SkMD5::Digest* digest) { |
| 20 SkAutoLockPixels autoLockPixels(bm); | 21 SkAutoLockPixels autoLockPixels(bm); |
| 21 SkASSERT(bm.getPixels()); | 22 SkASSERT(bm.getPixels()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 | 45 |
| 45 // This test is used primarily to verify rewinding works properly. Using kN
32 allows | 46 // This test is used primarily to verify rewinding works properly. Using kN
32 allows |
| 46 // us to test this without the added overhead of creating different bitmaps
depending | 47 // us to test this without the added overhead of creating different bitmaps
depending |
| 47 // on the color type (ex: building a color table for kIndex8). DM is where
we test | 48 // on the color type (ex: building a color table for kIndex8). DM is where
we test |
| 48 // decodes to all possible destination color types. | 49 // decodes to all possible destination color types. |
| 49 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); | 50 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); |
| 50 REPORTER_ASSERT(r, info.dimensions() == size); | 51 REPORTER_ASSERT(r, info.dimensions() == size); |
| 51 SkBitmap bm; | 52 SkBitmap bm; |
| 52 bm.allocPixels(info); | 53 bm.allocPixels(info); |
| 53 SkAutoLockPixels autoLockPixels(bm); | 54 SkAutoLockPixels autoLockPixels(bm); |
| 54 SkImageGenerator::Result result = | 55 SkCodec::Result result = |
| 55 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 56 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
| 56 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | 57 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 57 | 58 |
| 58 SkMD5::Digest digest1, digest2; | 59 SkMD5::Digest digest1, digest2; |
| 59 md5(bm, &digest1); | 60 md5(bm, &digest1); |
| 60 | 61 |
| 61 bm.eraseColor(SK_ColorYELLOW); | 62 bm.eraseColor(SK_ColorYELLOW); |
| 62 | 63 |
| 63 result = | 64 result = |
| 64 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); | 65 codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL); |
| 65 | 66 |
| 66 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | 67 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 67 // verify that re-decoding gives the same result. | 68 // verify that re-decoding gives the same result. |
| 68 md5(bm, &digest2); | 69 md5(bm, &digest2); |
| 69 REPORTER_ASSERT(r, digest1 == digest2); | 70 REPORTER_ASSERT(r, digest1 == digest2); |
| 70 | 71 |
| 71 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info); | 72 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info); |
| 72 if (supportsScanlineDecoding) { | 73 if (supportsScanlineDecoding) { |
| 73 bm.eraseColor(SK_ColorYELLOW); | 74 bm.eraseColor(SK_ColorYELLOW); |
| 74 REPORTER_ASSERT(r, scanlineDecoder); | 75 REPORTER_ASSERT(r, scanlineDecoder); |
| 75 | 76 |
| 76 // Regular decodes should be disabled after creating a scanline decoder | 77 // Regular decodes should be disabled after creating a scanline decoder |
| 77 result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NUL
L, NULL); | 78 result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NUL
L, NULL); |
| 78 REPORTER_ASSERT(r, SkImageGenerator::kInvalidParameters == result); | 79 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
| 79 for (int y = 0; y < info.height(); y++) { | 80 for (int y = 0; y < info.height(); y++) { |
| 80 result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0); | 81 result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0); |
| 81 REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess); | 82 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
| 82 } | 83 } |
| 83 // verify that scanline decoding gives the same result. | 84 // verify that scanline decoding gives the same result. |
| 84 SkMD5::Digest digest3; | 85 SkMD5::Digest digest3; |
| 85 md5(bm, &digest3); | 86 md5(bm, &digest3); |
| 86 REPORTER_ASSERT(r, digest3 == digest1); | 87 REPORTER_ASSERT(r, digest3 == digest1); |
| 87 } else { | 88 } else { |
| 88 REPORTER_ASSERT(r, !scanlineDecoder); | 89 REPORTER_ASSERT(r, !scanlineDecoder); |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 | 92 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 for (float scale = -0.05f; scale < 2.0f; scale += 0.05f) { | 183 for (float scale = -0.05f; scale < 2.0f; scale += 0.05f) { |
| 183 // Scale the output dimensions | 184 // Scale the output dimensions |
| 184 SkISize scaledDims = codec->getScaledDimensions(scale); | 185 SkISize scaledDims = codec->getScaledDimensions(scale); |
| 185 SkImageInfo scaledInfo = codec->getInfo().makeWH(scaledDims.width(), sca
ledDims.height()); | 186 SkImageInfo scaledInfo = codec->getInfo().makeWH(scaledDims.width(), sca
ledDims.height()); |
| 186 | 187 |
| 187 // Set up for the decode | 188 // Set up for the decode |
| 188 size_t rowBytes = scaledDims.width() * sizeof(SkPMColor); | 189 size_t rowBytes = scaledDims.width() * sizeof(SkPMColor); |
| 189 size_t totalBytes = scaledInfo.getSafeSize(rowBytes); | 190 size_t totalBytes = scaledInfo.getSafeSize(rowBytes); |
| 190 SkAutoTMalloc<SkPMColor> pixels(totalBytes); | 191 SkAutoTMalloc<SkPMColor> pixels(totalBytes); |
| 191 | 192 |
| 192 SkImageGenerator::Result result = | 193 SkCodec::Result result = |
| 193 codec->getPixels(scaledInfo, pixels.get(), rowBytes, NULL, NULL,
NULL); | 194 codec->getPixels(scaledInfo, pixels.get(), rowBytes, NULL, NULL,
NULL); |
| 194 REPORTER_ASSERT(r, SkImageGenerator::kSuccess == result); | 195 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
| 195 } | 196 } |
| 196 } | 197 } |
| 197 | 198 |
| 198 // Ensure that onGetScaledDimensions returns valid image dimensions to use for d
ecodes | 199 // Ensure that onGetScaledDimensions returns valid image dimensions to use for d
ecodes |
| 199 DEF_TEST(Codec_Dimensions, r) { | 200 DEF_TEST(Codec_Dimensions, r) { |
| 200 // JPG | 201 // JPG |
| 201 test_dimensions(r, "CMYK.jpg"); | 202 test_dimensions(r, "CMYK.jpg"); |
| 202 test_dimensions(r, "color_wheel.jpg"); | 203 test_dimensions(r, "color_wheel.jpg"); |
| 203 test_dimensions(r, "grayscale.jpg"); | 204 test_dimensions(r, "grayscale.jpg"); |
| 204 test_dimensions(r, "mandrill_512_q075.jpg"); | 205 test_dimensions(r, "mandrill_512_q075.jpg"); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 221 test_empty(r, "empty_images/zero-embedded.ico"); | 222 test_empty(r, "empty_images/zero-embedded.ico"); |
| 222 test_empty(r, "empty_images/zero-width.bmp"); | 223 test_empty(r, "empty_images/zero-width.bmp"); |
| 223 test_empty(r, "empty_images/zero-height.bmp"); | 224 test_empty(r, "empty_images/zero-height.bmp"); |
| 224 test_empty(r, "empty_images/zero-width.jpg"); | 225 test_empty(r, "empty_images/zero-width.jpg"); |
| 225 test_empty(r, "empty_images/zero-height.jpg"); | 226 test_empty(r, "empty_images/zero-height.jpg"); |
| 226 test_empty(r, "empty_images/zero-width.png"); | 227 test_empty(r, "empty_images/zero-width.png"); |
| 227 test_empty(r, "empty_images/zero-height.png"); | 228 test_empty(r, "empty_images/zero-height.png"); |
| 228 test_empty(r, "empty_images/zero-width.wbmp"); | 229 test_empty(r, "empty_images/zero-width.wbmp"); |
| 229 test_empty(r, "empty_images/zero-height.wbmp"); | 230 test_empty(r, "empty_images/zero-height.wbmp"); |
| 230 } | 231 } |
| OLD | NEW |