| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "gm_expectations.h" | 8 #include "gm_expectations.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 static SkTArray<SkString, false> gMissingExpectations; | 104 static SkTArray<SkString, false> gMissingExpectations; |
| 105 static SkTArray<SkString, false> gMissingSubsetExpectations; | 105 static SkTArray<SkString, false> gMissingSubsetExpectations; |
| 106 | 106 |
| 107 static SkBitmap::Config gPrefConfig(SkBitmap::kNo_Config); | 107 static SkBitmap::Config gPrefConfig(SkBitmap::kNo_Config); |
| 108 | 108 |
| 109 // Expections read from a file specified by readExpectationsPath. The expectatio
ns must have been | 109 // Expections read from a file specified by readExpectationsPath. The expectatio
ns must have been |
| 110 // previously written using createExpectationsPath. | 110 // previously written using createExpectationsPath. |
| 111 SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations; | 111 SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations; |
| 112 | 112 |
| 113 static bool write_bitmap(const char outName[], const SkBitmap& bm) { | 113 static bool write_bitmap(const char outName[], const SkBitmap& bm) { |
| 114 const SkBitmap* bmPtr; | 114 if (SkImageEncoder::EncodeFile(outName, bm, SkImageEncoder::kPNG_Type, 100))
{ |
| 115 return true; |
| 116 } |
| 117 |
| 118 if (bm.config() == SkBitmap::kARGB_8888_Config) { |
| 119 // First attempt at encoding failed, and the bitmap was already 8888. Ma
king |
| 120 // a copy is not going to help. |
| 121 return false; |
| 122 } |
| 123 |
| 124 // Encoding failed. Copy to 8888 and try again. |
| 115 SkBitmap bm8888; | 125 SkBitmap bm8888; |
| 116 if (bm.config() == SkBitmap::kA8_Config) { | 126 if (!bm.copyTo(&bm8888, SkBitmap::kARGB_8888_Config)) { |
| 117 // Copy A8 into ARGB_8888, since our image encoders do not currently | 127 return false; |
| 118 // support A8. | |
| 119 if (!bm.copyTo(&bm8888, SkBitmap::kARGB_8888_Config)) { | |
| 120 return false; | |
| 121 } | |
| 122 bmPtr = &bm8888; | |
| 123 } else { | |
| 124 bmPtr = &bm; | |
| 125 } | 128 } |
| 126 return SkImageEncoder::EncodeFile(outName, *bmPtr, SkImageEncoder::kPNG_Type
, 100); | 129 return SkImageEncoder::EncodeFile(outName, bm8888, SkImageEncoder::kPNG_Type
, 100); |
| 127 } | 130 } |
| 128 | 131 |
| 129 /** | 132 /** |
| 130 * Return a random SkIRect inside the range specified. | 133 * Return a random SkIRect inside the range specified. |
| 131 * @param rand Random number generator. | 134 * @param rand Random number generator. |
| 132 * @param maxX Exclusive maximum x-coordinate. SkIRect's fLeft and fRight will
be | 135 * @param maxX Exclusive maximum x-coordinate. SkIRect's fLeft and fRight will
be |
| 133 * in the range [0, maxX) | 136 * in the range [0, maxX) |
| 134 * @param maxY Exclusive maximum y-coordinate. SkIRect's fTop and fBottom will
be | 137 * @param maxY Exclusive maximum y-coordinate. SkIRect's fTop and fBottom will
be |
| 135 * in the range [0, maxY) | 138 * in the range [0, maxY) |
| 136 * @return SkIRect Non-empty, non-degenerate rectangle. | 139 * @return SkIRect Non-empty, non-degenerate rectangle. |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } | 715 } |
| 713 | 716 |
| 714 return failed ? -1 : 0; | 717 return failed ? -1 : 0; |
| 715 } | 718 } |
| 716 | 719 |
| 717 #if !defined SK_BUILD_FOR_IOS | 720 #if !defined SK_BUILD_FOR_IOS |
| 718 int main(int argc, char * const argv[]) { | 721 int main(int argc, char * const argv[]) { |
| 719 return tool_main(argc, (char**) argv); | 722 return tool_main(argc, (char**) argv); |
| 720 } | 723 } |
| 721 #endif | 724 #endif |
| OLD | NEW |