| 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 "SkAndroidCodec.h" | 8 #include "SkAndroidCodec.h" |
| 9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
| 10 #include "SkCodecPriv.h" | 10 #include "SkCodecPriv.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 return NewFromStream(new SkMemoryStream(data)); | 48 return NewFromStream(new SkMemoryStream(data)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 SkISize SkAndroidCodec::getSampledDimensions(int sampleSize) const { | 51 SkISize SkAndroidCodec::getSampledDimensions(int sampleSize) const { |
| 52 if (!is_valid_sample_size(sampleSize)) { | 52 if (!is_valid_sample_size(sampleSize)) { |
| 53 return SkISize::Make(0, 0); | 53 return SkISize::Make(0, 0); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Fast path for when we are not scaling. |
| 57 if (1 == sampleSize) { |
| 58 return fInfo.dimensions(); |
| 59 } |
| 60 |
| 56 return this->onGetSampledDimensions(sampleSize); | 61 return this->onGetSampledDimensions(sampleSize); |
| 57 } | 62 } |
| 58 | 63 |
| 59 bool SkAndroidCodec::getSupportedSubset(SkIRect* desiredSubset) const { | 64 bool SkAndroidCodec::getSupportedSubset(SkIRect* desiredSubset) const { |
| 60 if (!desiredSubset || !is_valid_subset(*desiredSubset, fInfo.dimensions()))
{ | 65 if (!desiredSubset || !is_valid_subset(*desiredSubset, fInfo.dimensions()))
{ |
| 61 return false; | 66 return false; |
| 62 } | 67 } |
| 63 | 68 |
| 64 return this->onGetSupportedSubset(desiredSubset); | 69 return this->onGetSupportedSubset(desiredSubset); |
| 65 } | 70 } |
| 66 | 71 |
| 67 SkISize SkAndroidCodec::getSampledSubsetDimensions(int sampleSize, const SkIRect
& subset) const { | 72 SkISize SkAndroidCodec::getSampledSubsetDimensions(int sampleSize, const SkIRect
& subset) const { |
| 68 if (!is_valid_sample_size(sampleSize)) { | 73 if (!is_valid_sample_size(sampleSize)) { |
| 69 return SkISize::Make(0, 0); | 74 return SkISize::Make(0, 0); |
| 70 } | 75 } |
| 71 | 76 |
| 72 // We require that the input subset is a subset that is supported by SkAndro
idCodec. | 77 // We require that the input subset is a subset that is supported by SkAndro
idCodec. |
| 73 // We test this by calling getSupportedSubset() and verifying that no modifi
cations | 78 // We test this by calling getSupportedSubset() and verifying that no modifi
cations |
| 74 // are made to the subset. | 79 // are made to the subset. |
| 75 SkIRect copySubset = subset; | 80 SkIRect copySubset = subset; |
| 76 if (!this->getSupportedSubset(©Subset) || copySubset != subset) { | 81 if (!this->getSupportedSubset(©Subset) || copySubset != subset) { |
| 77 return SkISize::Make(0, 0); | 82 return SkISize::Make(0, 0); |
| 78 } | 83 } |
| 79 | 84 |
| 80 // If the subset is the entire image, for consistency, use onGetSampledDimen
sions(). | 85 // If the subset is the entire image, for consistency, use getSampledDimensi
ons(). |
| 81 if (fInfo.dimensions() == subset.size()) { | 86 if (fInfo.dimensions() == subset.size()) { |
| 82 return onGetSampledDimensions(sampleSize); | 87 return this->getSampledDimensions(sampleSize); |
| 83 } | 88 } |
| 84 | 89 |
| 85 // This should perhaps call a virtual function, but currently both of our su
bclasses | 90 // This should perhaps call a virtual function, but currently both of our su
bclasses |
| 86 // want the same implementation. | 91 // want the same implementation. |
| 87 return SkISize::Make(get_scaled_dimension(subset.width(), sampleSize), | 92 return SkISize::Make(get_scaled_dimension(subset.width(), sampleSize), |
| 88 get_scaled_dimension(subset.height(), sampleSize)); | 93 get_scaled_dimension(subset.height(), sampleSize)); |
| 89 } | 94 } |
| 90 | 95 |
| 91 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void*
pixels, | 96 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void*
pixels, |
| 92 size_t rowBytes, AndroidOptions* options) { | 97 size_t rowBytes, AndroidOptions* options) { |
| 93 if (!pixels) { | 98 if (!pixels) { |
| 94 return SkCodec::kInvalidParameters; | 99 return SkCodec::kInvalidParameters; |
| 95 } | 100 } |
| 96 if (rowBytes < info.minRowBytes()) { | 101 if (rowBytes < info.minRowBytes()) { |
| 97 return SkCodec::kInvalidParameters; | 102 return SkCodec::kInvalidParameters; |
| 98 } | 103 } |
| 99 | 104 |
| 100 AndroidOptions defaultOptions; | 105 AndroidOptions defaultOptions; |
| 101 if (!options) { | 106 if (!options) { |
| 102 options = &defaultOptions; | 107 options = &defaultOptions; |
| 103 } else if (options->fSubset) { | 108 } else if (options->fSubset) { |
| 104 if (!is_valid_subset(*options->fSubset, fInfo.dimensions())) { | 109 if (!is_valid_subset(*options->fSubset, fInfo.dimensions())) { |
| 105 return SkCodec::kInvalidParameters; | 110 return SkCodec::kInvalidParameters; |
| 106 } | 111 } |
| 112 |
| 113 if (SkIRect::MakeSize(fInfo.dimensions()) == *options->fSubset) { |
| 114 // The caller wants the whole thing, rather than a subset. Modify |
| 115 // the AndroidOptions passed to onGetAndroidPixels to not specify |
| 116 // a subset. |
| 117 defaultOptions = *options; |
| 118 defaultOptions.fSubset = nullptr; |
| 119 options = &defaultOptions; |
| 120 } |
| 107 } | 121 } |
| 108 | 122 |
| 109 return this->onGetAndroidPixels(info, pixels, rowBytes, *options); | 123 return this->onGetAndroidPixels(info, pixels, rowBytes, *options); |
| 110 } | 124 } |
| 111 | 125 |
| 112 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void*
pixels, | 126 SkCodec::Result SkAndroidCodec::getAndroidPixels(const SkImageInfo& info, void*
pixels, |
| 113 size_t rowBytes) { | 127 size_t rowBytes) { |
| 114 return this->getAndroidPixels(info, pixels, rowBytes, nullptr); | 128 return this->getAndroidPixels(info, pixels, rowBytes, nullptr); |
| 115 } | 129 } |
| OLD | NEW |