| 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 "SkBmpCodec.h" | 8 #include "SkBmpCodec.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (nullptr == data.get()) { | 133 if (nullptr == data.get()) { |
| 134 SkCodecPrintf("Warning: could not create embedded stream.\n"); | 134 SkCodecPrintf("Warning: could not create embedded stream.\n"); |
| 135 break; | 135 break; |
| 136 } | 136 } |
| 137 SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get
())); | 137 SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get
())); |
| 138 bytesRead += size; | 138 bytesRead += size; |
| 139 | 139 |
| 140 // Check if the embedded codec is bmp or png and create the codec | 140 // Check if the embedded codec is bmp or png and create the codec |
| 141 SkCodec* codec = nullptr; | 141 SkCodec* codec = nullptr; |
| 142 if (SkPngCodec::IsPng((const char*) data->bytes(), data->size())) { | 142 if (SkPngCodec::IsPng((const char*) data->bytes(), data->size())) { |
| 143 codec = SkPngCodec::NewFromStream(embeddedStream.detach()); | 143 codec = SkPngCodec::NewFromStream(embeddedStream.release()); |
| 144 } else { | 144 } else { |
| 145 codec = SkBmpCodec::NewFromIco(embeddedStream.detach()); | 145 codec = SkBmpCodec::NewFromIco(embeddedStream.release()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // Save a valid codec | 148 // Save a valid codec |
| 149 if (nullptr != codec) { | 149 if (nullptr != codec) { |
| 150 codecs->push_back().reset(codec); | 150 codecs->push_back().reset(codec); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Recognize if there are no valid codecs | 154 // Recognize if there are no valid codecs |
| 155 if (0 == codecs->count()) { | 155 if (0 == codecs->count()) { |
| 156 SkCodecPrintf("Error: could not find any valid embedded ico codecs.\n"); | 156 SkCodecPrintf("Error: could not find any valid embedded ico codecs.\n"); |
| 157 return nullptr; | 157 return nullptr; |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Use the largest codec as a "suggestion" for image info | 160 // Use the largest codec as a "suggestion" for image info |
| 161 uint32_t maxSize = 0; | 161 uint32_t maxSize = 0; |
| 162 uint32_t maxIndex = 0; | 162 uint32_t maxIndex = 0; |
| 163 for (int32_t i = 0; i < codecs->count(); i++) { | 163 for (int32_t i = 0; i < codecs->count(); i++) { |
| 164 SkImageInfo info = codecs->operator[](i)->getInfo(); | 164 SkImageInfo info = codecs->operator[](i)->getInfo(); |
| 165 uint32_t size = info.width() * info.height(); | 165 uint32_t size = info.width() * info.height(); |
| 166 if (size > maxSize) { | 166 if (size > maxSize) { |
| 167 maxSize = size; | 167 maxSize = size; |
| 168 maxIndex = i; | 168 maxIndex = i; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 SkImageInfo info = codecs->operator[](maxIndex)->getInfo(); | 171 SkImageInfo info = codecs->operator[](maxIndex)->getInfo(); |
| 172 | 172 |
| 173 // Note that stream is owned by the embedded codec, the ico does not need | 173 // Note that stream is owned by the embedded codec, the ico does not need |
| 174 // direct access to the stream. | 174 // direct access to the stream. |
| 175 return new SkIcoCodec(info, codecs.detach()); | 175 return new SkIcoCodec(info, codecs.release()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 /* | 178 /* |
| 179 * Creates an instance of the decoder | 179 * Creates an instance of the decoder |
| 180 * Called only by NewFromStream | 180 * Called only by NewFromStream |
| 181 */ | 181 */ |
| 182 SkIcoCodec::SkIcoCodec(const SkImageInfo& info, | 182 SkIcoCodec::SkIcoCodec(const SkImageInfo& info, |
| 183 SkTArray<SkAutoTDelete<SkCodec>, true>* codecs) | 183 SkTArray<SkAutoTDelete<SkCodec>, true>* codecs) |
| 184 : INHERITED(info, nullptr) | 184 : INHERITED(info, nullptr) |
| 185 , fEmbeddedCodecs(codecs) | 185 , fEmbeddedCodecs(codecs) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 SkCodec::SkScanlineOrder SkIcoCodec::onGetScanlineOrder() const { | 310 SkCodec::SkScanlineOrder SkIcoCodec::onGetScanlineOrder() const { |
| 311 // FIXME: This function will possibly return the wrong value if it is called | 311 // FIXME: This function will possibly return the wrong value if it is called |
| 312 // before startScanlineDecode(). | 312 // before startScanlineDecode(). |
| 313 return fCurrScanlineCodec ? fCurrScanlineCodec->getScanlineOrder() : | 313 return fCurrScanlineCodec ? fCurrScanlineCodec->getScanlineOrder() : |
| 314 INHERITED::onGetScanlineOrder(); | 314 INHERITED::onGetScanlineOrder(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 SkSampler* SkIcoCodec::getSampler(bool createIfNecessary) { | 317 SkSampler* SkIcoCodec::getSampler(bool createIfNecessary) { |
| 318 return fCurrScanlineCodec ? fCurrScanlineCodec->getSampler(createIfNecessary
) : nullptr; | 318 return fCurrScanlineCodec ? fCurrScanlineCodec->getSampler(createIfNecessary
) : nullptr; |
| 319 } | 319 } |
| OLD | NEW |