| 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 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 */ | 270 */ |
| 271 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, | 271 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, |
| 272 SkPMColor ctable[], int* ctableCount); | 272 SkPMColor ctable[], int* ctableCount); |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and | 275 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and |
| 276 * uses the default Options. | 276 * uses the default Options. |
| 277 */ | 277 */ |
| 278 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 278 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
| 279 | 279 |
| 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 /** |
| 303 * If decoding to YUV is supported, this returns true. Otherwise, this |
| 304 * returns false and does not modify any of the parameters. |
| 305 * |
| 306 * @param sizeInfo Output parameter indicating the sizes and required |
| 307 * allocation widths of the Y, U, and V planes. |
| 308 * @param colorSpace Output parameter. If non-NULL this is set to kJPEG, |
| 309 * otherwise this is ignored. |
| 310 */ |
| 311 bool queryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const { |
| 312 if (nullptr == sizeInfo) { |
| 313 return false; |
| 314 } |
| 315 |
| 316 return this->onQueryYUV8(sizeInfo, colorSpace); |
| 317 } |
| 318 |
| 319 /** |
| 320 * Returns kSuccess, or another value explaining the type of failure. |
| 321 * This always attempts to perform a full decode. If the client only |
| 322 * wants size, it should call queryYUV8(). |
| 323 * |
| 324 * @param sizeInfo Needs to exactly match the values returned by the |
| 325 * query, except the WidthBytes may be larger than the |
| 326 * recommendation (but not smaller). |
| 327 * @param planes Memory for each of the Y, U, and V planes. |
| 328 */ |
| 329 Result getYUV8Planes(const YUVSizeInfo& sizeInfo, void* planes[3]) { |
| 330 if (nullptr == planes || nullptr == planes[0] || nullptr == planes[1] || |
| 331 nullptr == planes[2]) { |
| 332 return kInvalidInput; |
| 333 } |
| 334 |
| 335 if (!this->rewindIfNeeded()) { |
| 336 return kCouldNotRewind; |
| 337 } |
| 338 |
| 339 return this->onGetYUV8Planes(sizeInfo, planes); |
| 340 } |
| 341 |
| 280 /** | 342 /** |
| 281 * The remaining functions revolve around decoding scanlines. | 343 * The remaining functions revolve around decoding scanlines. |
| 282 */ | 344 */ |
| 283 | 345 |
| 284 /** | 346 /** |
| 285 * Prepare for a scanline decode with the specified options. | 347 * Prepare for a scanline decode with the specified options. |
| 286 * | 348 * |
| 287 * After this call, this class will be ready to decode the first scanline. | 349 * After this call, this class will be ready to decode the first scanline. |
| 288 * | 350 * |
| 289 * This must be called in order to call getScanlines or skipScanlines. | 351 * This must be called in order to call getScanlines or skipScanlines. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 * is located in the encoded data. | 497 * is located in the encoded data. |
| 436 * | 498 * |
| 437 * This will equal inputScanline, except in the case of strangely | 499 * This will equal inputScanline, except in the case of strangely |
| 438 * encoded image types (bottom-up bmps, interlaced gifs). | 500 * encoded image types (bottom-up bmps, interlaced gifs). |
| 439 */ | 501 */ |
| 440 int outputScanline(int inputScanline) const; | 502 int outputScanline(int inputScanline) const; |
| 441 | 503 |
| 442 protected: | 504 protected: |
| 443 SkCodec(const SkImageInfo&, SkStream*); | 505 SkCodec(const SkImageInfo&, SkStream*); |
| 444 | 506 |
| 445 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { | 507 virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const { |
| 446 // By default, scaling is not supported. | 508 // By default, scaling is not supported. |
| 447 return this->getInfo().dimensions(); | 509 return this->getInfo().dimensions(); |
| 448 } | 510 } |
| 449 | 511 |
| 450 // FIXME: What to do about subsets?? | 512 // FIXME: What to do about subsets?? |
| 451 /** | 513 /** |
| 452 * Subclasses should override if they support dimensions other than the | 514 * Subclasses should override if they support dimensions other than the |
| 453 * srcInfo's. | 515 * srcInfo's. |
| 454 */ | 516 */ |
| 455 virtual bool onDimensionsSupported(const SkISize&) { | 517 virtual bool onDimensionsSupported(const SkISize&) { |
| 456 return false; | 518 return false; |
| 457 } | 519 } |
| 458 | 520 |
| 459 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 521 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
| 460 | 522 |
| 461 /** | 523 /** |
| 462 * @param rowsDecoded When the encoded image stream is incomplete, this func
tion | 524 * @param rowsDecoded When the encoded image stream is incomplete, this func
tion |
| 463 * will return kIncompleteInput and rowsDecoded will be s
et to | 525 * will return kIncompleteInput and rowsDecoded will be s
et to |
| 464 * the number of scanlines that were successfully decoded
. | 526 * the number of scanlines that were successfully decoded
. |
| 465 * This will allow getPixels() to fill the uninitialized
memory. | 527 * This will allow getPixels() to fill the uninitialized
memory. |
| 466 */ | 528 */ |
| 467 virtual Result onGetPixels(const SkImageInfo& info, | 529 virtual Result onGetPixels(const SkImageInfo& info, |
| 468 void* pixels, size_t rowBytes, const Options&, | 530 void* pixels, size_t rowBytes, const Options&, |
| 469 SkPMColor ctable[], int* ctableCount, | 531 SkPMColor ctable[], int* ctableCount, |
| 470 int* rowsDecoded) = 0; | 532 int* rowsDecoded) = 0; |
| 471 | 533 |
| 472 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { | 534 virtual bool onQueryYUV8(YUVSizeInfo*, SkYUVColorSpace*) const { |
| 535 return false; |
| 536 } |
| 537 |
| 538 virtual Result onGetYUV8Planes(const YUVSizeInfo&, void*[3] /*planes*/) { |
| 539 return kUnimplemented; |
| 540 } |
| 541 |
| 542 virtual bool onGetValidSubset(SkIRect* /*desiredSubset*/) const { |
| 473 // By default, subsets are not supported. | 543 // By default, subsets are not supported. |
| 474 return false; | 544 return false; |
| 475 } | 545 } |
| 476 | 546 |
| 477 /** | 547 /** |
| 478 * If the stream was previously read, attempt to rewind. | 548 * If the stream was previously read, attempt to rewind. |
| 479 * | 549 * |
| 480 * If the stream needed to be rewound, call onRewind. | 550 * If the stream needed to be rewound, call onRewind. |
| 481 * @returns true if the codec is at the right position and can be used. | 551 * @returns true if the codec is at the right position and can be used. |
| 482 * false if there was a failure to rewind. | 552 * false if there was a failure to rewind. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 * not affect ownership. | 697 * not affect ownership. |
| 628 * | 698 * |
| 629 * Only valid during scanline decoding. | 699 * Only valid during scanline decoding. |
| 630 */ | 700 */ |
| 631 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr;
} | 701 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr;
} |
| 632 | 702 |
| 633 friend class SkSampledCodec; | 703 friend class SkSampledCodec; |
| 634 friend class SkIcoCodec; | 704 friend class SkIcoCodec; |
| 635 }; | 705 }; |
| 636 #endif // SkCodec_DEFINED | 706 #endif // SkCodec_DEFINED |
| OLD | NEW |