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 #ifndef SkCodec_DEFINED | 8 #ifndef SkCodec_DEFINED |
9 #define SkCodec_DEFINED | 9 #define SkCodec_DEFINED |
10 | 10 |
11 #include "../private/SkTemplates.h" | 11 #include "../private/SkTemplates.h" |
12 #include "SkColor.h" | 12 #include "SkColor.h" |
13 #include "SkColorSpace.h" | 13 #include "SkColorSpace.h" |
14 #include "SkEncodedFormat.h" | 14 #include "SkEncodedFormat.h" |
15 #include "SkImageInfo.h" | 15 #include "SkImageInfo.h" |
16 #include "SkSize.h" | 16 #include "SkSize.h" |
17 #include "SkStream.h" | 17 #include "SkStream.h" |
18 #include "SkTypes.h" | 18 #include "SkTypes.h" |
| 19 #include "SkYUVSizeInfo.h" |
19 | 20 |
20 class SkData; | 21 class SkData; |
21 class SkPngChunkReader; | 22 class SkPngChunkReader; |
22 class SkSampler; | 23 class SkSampler; |
23 | 24 |
24 /** | 25 /** |
25 * Abstraction layer directly on top of an image codec. | 26 * Abstraction layer directly on top of an image codec. |
26 */ | 27 */ |
27 class SkCodec : SkNoncopyable { | 28 class SkCodec : SkNoncopyable { |
28 public: | 29 public: |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 */ | 279 */ |
279 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, | 280 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, |
280 SkPMColor ctable[], int* ctableCount); | 281 SkPMColor ctable[], int* ctableCount); |
281 | 282 |
282 /** | 283 /** |
283 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and | 284 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and |
284 * uses the default Options. | 285 * uses the default Options. |
285 */ | 286 */ |
286 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 287 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
287 | 288 |
288 struct YUVSizeInfo { | |
289 SkISize fYSize; | |
290 SkISize fUSize; | |
291 SkISize fVSize; | |
292 | |
293 /** | |
294 * While the widths of the Y, U, and V planes are not restricted, the | |
295 * implementation requires that the width of the memory allocated for | |
296 * each plane be a multiple of DCTSIZE (which is always 8). | |
297 * | |
298 * This struct allows us to inform the client how many "widthBytes" | |
299 * that we need. Note that we use the new idea of "widthBytes" | |
300 * because this idea is distinct from "rowBytes" (used elsewhere in | |
301 * Skia). "rowBytes" allow the last row of the allocation to not | |
302 * include any extra padding, while, in this case, every single row of | |
303 * the allocation must be at least "widthBytes". | |
304 */ | |
305 size_t fYWidthBytes; | |
306 size_t fUWidthBytes; | |
307 size_t fVWidthBytes; | |
308 }; | |
309 | |
310 /** | 289 /** |
311 * If decoding to YUV is supported, this returns true. Otherwise, this | 290 * If decoding to YUV is supported, this returns true. Otherwise, this |
312 * returns false and does not modify any of the parameters. | 291 * returns false and does not modify any of the parameters. |
313 * | 292 * |
314 * @param sizeInfo Output parameter indicating the sizes and required | 293 * @param sizeInfo Output parameter indicating the sizes and required |
315 * allocation widths of the Y, U, and V planes. | 294 * allocation widths of the Y, U, and V planes. |
316 * @param colorSpace Output parameter. If non-NULL this is set to kJPEG, | 295 * @param colorSpace Output parameter. If non-NULL this is set to kJPEG, |
317 * otherwise this is ignored. | 296 * otherwise this is ignored. |
318 */ | 297 */ |
319 bool queryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { | 298 bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { |
320 if (nullptr == sizeInfo) { | 299 if (nullptr == sizeInfo) { |
321 return false; | 300 return false; |
322 } | 301 } |
323 | 302 |
324 return this->onQueryYUV8(sizeInfo, colorSpace); | 303 return this->onQueryYUV8(sizeInfo, colorSpace); |
325 } | 304 } |
326 | 305 |
327 /** | 306 /** |
328 * Returns kSuccess, or another value explaining the type of failure. | 307 * Returns kSuccess, or another value explaining the type of failure. |
329 * This always attempts to perform a full decode. If the client only | 308 * This always attempts to perform a full decode. If the client only |
330 * wants size, it should call queryYUV8(). | 309 * wants size, it should call queryYUV8(). |
331 * | 310 * |
332 * @param sizeInfo Needs to exactly match the values returned by the | 311 * @param sizeInfo Needs to exactly match the values returned by the |
333 * query, except the WidthBytes may be larger than the | 312 * query, except the WidthBytes may be larger than the |
334 * recommendation (but not smaller). | 313 * recommendation (but not smaller). |
335 * @param planes Memory for each of the Y, U, and V planes. | 314 * @param planes Memory for each of the Y, U, and V planes. |
336 */ | 315 */ |
337 Result getYUV8Planes(const YUVSizeInfo& sizeInfo, void* planes[3]) { | 316 Result getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) { |
338 if (nullptr == planes || nullptr == planes[0] || nullptr == planes[1] || | 317 if (nullptr == planes || nullptr == planes[0] || nullptr == planes[1] || |
339 nullptr == planes[2]) { | 318 nullptr == planes[2]) { |
340 return kInvalidInput; | 319 return kInvalidInput; |
341 } | 320 } |
342 | 321 |
343 if (!this->rewindIfNeeded()) { | 322 if (!this->rewindIfNeeded()) { |
344 return kCouldNotRewind; | 323 return kCouldNotRewind; |
345 } | 324 } |
346 | 325 |
347 return this->onGetYUV8Planes(sizeInfo, planes); | 326 return this->onGetYUV8Planes(sizeInfo, planes); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 * @param rowsDecoded When the encoded image stream is incomplete, this func
tion | 515 * @param rowsDecoded When the encoded image stream is incomplete, this func
tion |
537 * will return kIncompleteInput and rowsDecoded will be s
et to | 516 * will return kIncompleteInput and rowsDecoded will be s
et to |
538 * the number of scanlines that were successfully decoded
. | 517 * the number of scanlines that were successfully decoded
. |
539 * This will allow getPixels() to fill the uninitialized
memory. | 518 * This will allow getPixels() to fill the uninitialized
memory. |
540 */ | 519 */ |
541 virtual Result onGetPixels(const SkImageInfo& info, | 520 virtual Result onGetPixels(const SkImageInfo& info, |
542 void* pixels, size_t rowBytes, const Options&, | 521 void* pixels, size_t rowBytes, const Options&, |
543 SkPMColor ctable[], int* ctableCount, | 522 SkPMColor ctable[], int* ctableCount, |
544 int* rowsDecoded) = 0; | 523 int* rowsDecoded) = 0; |
545 | 524 |
546 virtual bool onQueryYUV8(YUVSizeInfo*, SkYUVColorSpace*) const { | 525 virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { |
547 return false; | 526 return false; |
548 } | 527 } |
549 | 528 |
550 virtual Result onGetYUV8Planes(const YUVSizeInfo&, void*[3] /*planes*/) { | 529 virtual Result onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) { |
551 return kUnimplemented; | 530 return kUnimplemented; |
552 } | 531 } |
553 | 532 |
554 virtual bool onGetValidSubset(SkIRect* /*desiredSubset*/) const { | 533 virtual bool onGetValidSubset(SkIRect* /*desiredSubset*/) const { |
555 // By default, subsets are not supported. | 534 // By default, subsets are not supported. |
556 return false; | 535 return false; |
557 } | 536 } |
558 | 537 |
559 /** | 538 /** |
560 * If the stream was previously read, attempt to rewind. | 539 * If the stream was previously read, attempt to rewind. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 * not affect ownership. | 678 * not affect ownership. |
700 * | 679 * |
701 * Only valid during scanline decoding. | 680 * Only valid during scanline decoding. |
702 */ | 681 */ |
703 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr;
} | 682 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr;
} |
704 | 683 |
705 friend class SkSampledCodec; | 684 friend class SkSampledCodec; |
706 friend class SkIcoCodec; | 685 friend class SkIcoCodec; |
707 }; | 686 }; |
708 #endif // SkCodec_DEFINED | 687 #endif // SkCodec_DEFINED |
OLD | NEW |