OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 | 8 |
9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 fShouldCancelDecode = false; | 222 fShouldCancelDecode = false; |
223 | 223 |
224 return this->onBuildTileIndex(stream, width, height); | 224 return this->onBuildTileIndex(stream, width, height); |
225 } | 225 } |
226 | 226 |
227 bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, | 227 bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, |
228 int dstX, int dstY, int width, int height, | 228 int dstX, int dstY, int width, int height, |
229 int srcX, int srcY) { | 229 int srcX, int srcY) { |
230 int w = width / sampleSize; | 230 int w = width / sampleSize; |
231 int h = height / sampleSize; | 231 int h = height / sampleSize; |
232 if (src->getConfig() == SkBitmap::kIndex8_Config) { | 232 if (src->config() == SkBitmap::kIndex8_Config) { |
233 // kIndex8 does not allow drawing via an SkCanvas, as is done below. | 233 // kIndex8 does not allow drawing via an SkCanvas, as is done below. |
234 // Instead, use extractSubset. Note that this shares the SkPixelRef and | 234 // Instead, use extractSubset. Note that this shares the SkPixelRef and |
235 // SkColorTable. | 235 // SkColorTable. |
236 // FIXME: Since src is discarded in practice, this holds on to more | 236 // FIXME: Since src is discarded in practice, this holds on to more |
237 // pixels than is strictly necessary. Switch to a copy if memory | 237 // pixels than is strictly necessary. Switch to a copy if memory |
238 // savings are more important than speed here. This also means | 238 // savings are more important than speed here. This also means |
239 // that the pixels in dst can not be reused (though there is no | 239 // that the pixels in dst can not be reused (though there is no |
240 // allocation, which was already done on src). | 240 // allocation, which was already done on src). |
241 int x = (dstX - srcX) / sampleSize; | 241 int x = (dstX - srcX) / sampleSize; |
242 int y = (dstY - srcY) / sampleSize; | 242 int y = (dstY - srcY) / sampleSize; |
243 SkIRect subset = SkIRect::MakeXYWH(x, y, w, h); | 243 SkIRect subset = SkIRect::MakeXYWH(x, y, w, h); |
244 return src->extractSubset(dst, subset); | 244 return src->extractSubset(dst, subset); |
245 } | 245 } |
246 // if the destination has no pixels then we must allocate them. | 246 // if the destination has no pixels then we must allocate them. |
247 if (dst->isNull()) { | 247 if (dst->isNull()) { |
248 dst->setConfig(src->getConfig(), w, h, 0, src->alphaType()); | 248 dst->setConfig(src->config(), w, h, 0, src->alphaType()); |
249 | 249 |
250 if (!this->allocPixelRef(dst, NULL)) { | 250 if (!this->allocPixelRef(dst, NULL)) { |
251 SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); | 251 SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); |
252 return false; | 252 return false; |
253 } | 253 } |
254 } | 254 } |
255 // check to see if the destination is large enough to decode the desired | 255 // check to see if the destination is large enough to decode the desired |
256 // region. If this assert fails we will just draw as much of the source | 256 // region. If this assert fails we will just draw as much of the source |
257 // into the destination that we can. | 257 // into the destination that we can. |
258 if (dst->width() < w || dst->height() < h) { | 258 if (dst->width() < w || dst->height() < h) { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 if (kUnknown_Format == *format) { | 462 if (kUnknown_Format == *format) { |
463 if (stream->rewind()) { | 463 if (stream->rewind()) { |
464 *format = GetStreamFormat(stream); | 464 *format = GetStreamFormat(stream); |
465 } | 465 } |
466 } | 466 } |
467 } | 467 } |
468 delete codec; | 468 delete codec; |
469 } | 469 } |
470 return success; | 470 return success; |
471 } | 471 } |
OLD | NEW |