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