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" |
11 #include "SkImagePriv.h" | 11 #include "SkImagePriv.h" |
12 #include "SkPixelRef.h" | 12 #include "SkPixelRef.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
14 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
16 | 16 |
17 SkImageDecoder::SkImageDecoder() | 17 SkImageDecoder::SkImageDecoder() |
18 : fPeeker(NULL) | 18 : fPeeker(nullptr) |
19 , fAllocator(NULL) | 19 , fAllocator(nullptr) |
20 , fSampleSize(1) | 20 , fSampleSize(1) |
21 , fDefaultPref(kUnknown_SkColorType) | 21 , fDefaultPref(kUnknown_SkColorType) |
22 , fPreserveSrcDepth(false) | 22 , fPreserveSrcDepth(false) |
23 , fDitherImage(true) | 23 , fDitherImage(true) |
24 , fSkipWritingZeroes(false) | 24 , fSkipWritingZeroes(false) |
25 , fPreferQualityOverSpeed(false) | 25 , fPreferQualityOverSpeed(false) |
26 , fRequireUnpremultipliedColors(false) { | 26 , fRequireUnpremultipliedColors(false) { |
27 } | 27 } |
28 | 28 |
29 SkImageDecoder::~SkImageDecoder() { | 29 SkImageDecoder::~SkImageDecoder() { |
30 SkSafeUnref(fPeeker); | 30 SkSafeUnref(fPeeker); |
31 SkSafeUnref(fAllocator); | 31 SkSafeUnref(fAllocator); |
32 } | 32 } |
33 | 33 |
34 void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) { | 34 void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) { |
35 if (NULL == other) { | 35 if (nullptr == other) { |
36 return; | 36 return; |
37 } | 37 } |
38 other->setPeeker(fPeeker); | 38 other->setPeeker(fPeeker); |
39 other->setAllocator(fAllocator); | 39 other->setAllocator(fAllocator); |
40 other->setSampleSize(fSampleSize); | 40 other->setSampleSize(fSampleSize); |
41 other->setPreserveSrcDepth(fPreserveSrcDepth); | 41 other->setPreserveSrcDepth(fPreserveSrcDepth); |
42 other->setDitherImage(fDitherImage); | 42 other->setDitherImage(fDitherImage); |
43 other->setSkipWritingZeroes(fSkipWritingZeroes); | 43 other->setSkipWritingZeroes(fSkipWritingZeroes); |
44 other->setPreferQualityOverSpeed(fPreferQualityOverSpeed); | 44 other->setPreferQualityOverSpeed(fPreferQualityOverSpeed); |
45 other->setRequireUnpremultipliedColors(fRequireUnpremultipliedColors); | 45 other->setRequireUnpremultipliedColors(fRequireUnpremultipliedColors); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // allocation, which was already done on src). | 181 // allocation, which was already done on src). |
182 int x = (dstX - srcX) / sampleSize; | 182 int x = (dstX - srcX) / sampleSize; |
183 int y = (dstY - srcY) / sampleSize; | 183 int y = (dstY - srcY) / sampleSize; |
184 SkIRect subset = SkIRect::MakeXYWH(x, y, w, h); | 184 SkIRect subset = SkIRect::MakeXYWH(x, y, w, h); |
185 return src->extractSubset(dst, subset); | 185 return src->extractSubset(dst, subset); |
186 } | 186 } |
187 // if the destination has no pixels then we must allocate them. | 187 // if the destination has no pixels then we must allocate them. |
188 if (dst->isNull()) { | 188 if (dst->isNull()) { |
189 dst->setInfo(src->info().makeWH(w, h)); | 189 dst->setInfo(src->info().makeWH(w, h)); |
190 | 190 |
191 if (!this->allocPixelRef(dst, NULL)) { | 191 if (!this->allocPixelRef(dst, nullptr)) { |
192 SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); | 192 SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); |
193 return false; | 193 return false; |
194 } | 194 } |
195 } | 195 } |
196 // check to see if the destination is large enough to decode the desired | 196 // check to see if the destination is large enough to decode the desired |
197 // region. If this assert fails we will just draw as much of the source | 197 // region. If this assert fails we will just draw as much of the source |
198 // into the destination that we can. | 198 // into the destination that we can. |
199 if (dst->width() < w || dst->height() < h) { | 199 if (dst->width() < w || dst->height() < h) { |
200 SkDEBUGF(("SkImageDecoder::cropBitmap does not have a large enough bitma
p.\n")); | 200 SkDEBUGF(("SkImageDecoder::cropBitmap does not have a large enough bitma
p.\n")); |
201 } | 201 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return success; | 265 return success; |
266 } | 266 } |
267 | 267 |
268 bool SkImageDecoder::decodeYUV8Planes(SkStream* stream, SkISize componentSizes[3
], void* planes[3], | 268 bool SkImageDecoder::decodeYUV8Planes(SkStream* stream, SkISize componentSizes[3
], void* planes[3], |
269 size_t rowBytes[3], SkYUVColorSpace* color
Space) { | 269 size_t rowBytes[3], SkYUVColorSpace* color
Space) { |
270 // we reset this to false before calling onDecodeYUV8Planes | 270 // we reset this to false before calling onDecodeYUV8Planes |
271 fShouldCancelDecode = false; | 271 fShouldCancelDecode = false; |
272 | 272 |
273 return this->onDecodeYUV8Planes(stream, componentSizes, planes, rowBytes, co
lorSpace); | 273 return this->onDecodeYUV8Planes(stream, componentSizes, planes, rowBytes, co
lorSpace); |
274 } | 274 } |
OLD | NEW |