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 "SkCodec.h" | 9 #include "SkCodec.h" |
10 #include "SkCodecPriv.h" | 10 #include "SkCodecPriv.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 SkCodec* (*NewFromStream)(SkStream*); | 28 SkCodec* (*NewFromStream)(SkStream*); |
29 }; | 29 }; |
30 | 30 |
31 static const DecoderProc gDecoderProcs[] = { | 31 static const DecoderProc gDecoderProcs[] = { |
32 #ifdef SK_HAS_JPEG_LIBRARY | 32 #ifdef SK_HAS_JPEG_LIBRARY |
33 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, | 33 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, |
34 #endif | 34 #endif |
35 #ifdef SK_HAS_WEBP_LIBRARY | 35 #ifdef SK_HAS_WEBP_LIBRARY |
36 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, | 36 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, |
37 #endif | 37 #endif |
38 #ifdef SK_HAS_GIF_LIBRARY | |
39 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, | 38 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, |
40 #endif | |
41 #ifdef SK_HAS_PNG_LIBRARY | 39 #ifdef SK_HAS_PNG_LIBRARY |
42 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, | 40 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, |
43 #endif | 41 #endif |
44 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, | 42 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, |
45 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } | 43 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } |
46 }; | 44 }; |
47 | 45 |
48 size_t SkCodec::MinBufferedBytesNeeded() { | 46 size_t SkCodec::MinBufferedBytesNeeded() { |
49 return WEBP_VP8_HEADER_SIZE; | 47 return WEBP_VP8_HEADER_SIZE; |
50 } | 48 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 , fNeedsRewind(false) | 134 , fNeedsRewind(false) |
137 , fOrigin(origin) | 135 , fOrigin(origin) |
138 , fDstInfo() | 136 , fDstInfo() |
139 , fOptions() | 137 , fOptions() |
140 , fCurrScanline(-1) | 138 , fCurrScanline(-1) |
141 {} | 139 {} |
142 | 140 |
143 SkCodec::~SkCodec() {} | 141 SkCodec::~SkCodec() {} |
144 | 142 |
145 bool SkCodec::rewindIfNeeded() { | 143 bool SkCodec::rewindIfNeeded() { |
146 if (!fStream) { | |
147 // Some codecs do not have a stream. They may hold onto their own data
or another codec. | |
148 // They must handle rewinding themselves. | |
149 return true; | |
150 } | |
151 | |
152 // Store the value of fNeedsRewind so we can update it. Next read will | 144 // Store the value of fNeedsRewind so we can update it. Next read will |
153 // require a rewind. | 145 // require a rewind. |
154 const bool needsRewind = fNeedsRewind; | 146 const bool needsRewind = fNeedsRewind; |
155 fNeedsRewind = true; | 147 fNeedsRewind = true; |
156 if (!needsRewind) { | 148 if (!needsRewind) { |
157 return true; | 149 return true; |
158 } | 150 } |
159 | 151 |
160 // startScanlineDecode will need to be called before decoding scanlines. | 152 // startScanlineDecode will need to be called before decoding scanlines. |
161 fCurrScanline = -1; | 153 fCurrScanline = -1; |
162 // startIncrementalDecode will need to be called before incrementalDecode. | 154 // startIncrementalDecode will need to be called before incrementalDecode. |
163 fStartedIncrementalDecode = false; | 155 fStartedIncrementalDecode = false; |
164 | 156 |
165 if (!fStream->rewind()) { | 157 // Some codecs do not have a stream. They may hold onto their own data or a
nother codec. |
| 158 // They must handle rewinding themselves. |
| 159 if (fStream && !fStream->rewind()) { |
166 return false; | 160 return false; |
167 } | 161 } |
168 | 162 |
169 return this->onRewind(); | 163 return this->onRewind(); |
170 } | 164 } |
171 | 165 |
172 #define CHECK_COLOR_TABLE \ | 166 #define CHECK_COLOR_TABLE \ |
173 if (kIndex_8_SkColorType == info.colorType()) { \ | 167 if (kIndex_8_SkColorType == info.colorType()) { \ |
174 if (nullptr == ctable || nullptr == ctableCount) { \ | 168 if (nullptr == ctable || nullptr == ctableCount) { \ |
175 return SkCodec::kInvalidParameters; \ | 169 return SkCodec::kInvalidParameters; \ |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes); | 460 fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes); |
467 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler)
; | 461 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler)
; |
468 break; | 462 break; |
469 } | 463 } |
470 case kBottomUp_SkScanlineOrder: { | 464 case kBottomUp_SkScanlineOrder: { |
471 fillDst = dst; | 465 fillDst = dst; |
472 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); | 466 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); |
473 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler)
; | 467 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler)
; |
474 break; | 468 break; |
475 } | 469 } |
476 case kOutOfOrder_SkScanlineOrder: { | |
477 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq
uested); | |
478 const SkImageInfo fillInfo = info.makeWH(fillWidth, 1); | |
479 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | |
480 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r
owBytes); | |
481 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp
ler); | |
482 } | |
483 break; | |
484 } | |
485 } | 470 } |
486 } | 471 } |
487 | 472 |
488 bool SkCodec::initializeColorXform(const SkImageInfo& dstInfo) { | 473 bool SkCodec::initializeColorXform(const SkImageInfo& dstInfo) { |
489 fColorXform = nullptr; | 474 fColorXform = nullptr; |
490 if (needs_color_xform(dstInfo, fSrcInfo)) { | 475 if (needs_color_xform(dstInfo, fSrcInfo)) { |
491 fColorXform = SkColorSpaceXform::New(fSrcInfo.colorSpace(), dstInfo.colo
rSpace()); | 476 fColorXform = SkColorSpaceXform::New(fSrcInfo.colorSpace(), dstInfo.colo
rSpace()); |
492 if (!fColorXform) { | 477 if (!fColorXform) { |
493 return false; | 478 return false; |
494 } | 479 } |
495 } | 480 } |
496 | 481 |
497 return true; | 482 return true; |
498 } | 483 } |
OLD | NEW |