| 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 YUVPlanesSizes { |
| 281 SkISize YSize; |
| 282 SkISize USize; |
| 283 SkISize VSize; |
| 284 }; |
| 285 |
| 286 /** |
| 287 * While the widths of the Y, U, and V planes are not restricted, the |
| 288 * implementation requires that the width of the memory allocated for |
| 289 * each plane be a multiple of DCTSIZE (which is always 8). |
| 290 * |
| 291 * This struct allows us to inform the client how many "widthBytes" |
| 292 * that we need. Note that we use the new idea of "widthBytes" because |
| 293 * this idea is distinct from "rowBytes" (used elsewhere in Skia). |
| 294 * "rowBytes" allow the last row of the allocation to not include any |
| 295 * extra padding, while, in this case, every single row of the allocation |
| 296 * must be at least "widthBytes". |
| 297 */ |
| 298 struct YUVPlanesWidthBytes { |
| 299 size_t YWidthBytes; |
| 300 size_t UWidthBytes; |
| 301 size_t VWidthBytes; |
| 302 }; |
| 303 |
| 304 /** |
| 305 * If decoding to YUV is supported, this returns true. Otherwise, this |
| 306 * returns false and does not modify any of the parameters. |
| 307 * |
| 308 * @param sizes Output parameter indicating the sizes of the Y, U, |
| 309 * and V planes. |
| 310 * @param widthBytes Output parameter indicating the required allocation |
| 311 * width in bytes for each of the Y, U, and V planes. |
| 312 * @param colorSpace Output parameter. If non-NULL this is set to kJPEG, |
| 313 * otherwise this is ignored. |
| 314 */ |
| 315 bool queryYUV8(YUVPlanesSizes* sizes, YUVPlanesWidthBytes* widthBytes, |
| 316 SkYUVColorSpace* colorSpace) const { |
| 317 if (nullptr == sizes || nullptr == widthBytes) { |
| 318 return false; |
| 319 } |
| 320 |
| 321 return this->onQueryYUV8(sizes, widthBytes, colorSpace); |
| 322 } |
| 323 |
| 324 /** |
| 325 * Returns kSuccess, or another value explaining the type of failure. |
| 326 * This always attempts to perform a full decode. If the client only |
| 327 * wants size, it should call queryYUV8(). |
| 328 * |
| 329 * @param sizes Sizes of each of the Y, U, and V planes. The size |
| 330 * of the Y plane will be the same size as the image. |
| 331 * The size of the U and V planes may be the same size |
| 332 * as the image, or they may be a fraction of the size |
| 333 * of the image (due to sampling). It is quite common |
| 334 * for the width to be sampled at a different rate than |
| 335 * the height. 2 and 4 are common sampling rates. The |
| 336 * U and V planes are often the same size. |
| 337 * @param planes Memory for each of the Y, U, and V planes. |
| 338 * @param widthBytes Width in bytes of each row of the Y, U, and V planes. |
| 339 * Each Y, U, or V "sample" is a single byte. Also, |
| 340 * the implementation requires that the width of the |
| 341 * memory allocated be padded to a multiple of 8. So |
| 342 * the widthBytes should at least equal the Y, U, and V |
| 343 * widths rounded up to the nearest multiples of 8. |
| 344 */ |
| 345 Result getYUV8Planes(const YUVPlanesSizes* sizes, void* planes[3], |
| 346 const YUVPlanesWidthBytes* widthBytes) { |
| 347 if (nullptr == sizes || nullptr == planes || nullptr == planes[0] || |
| 348 nullptr == planes[1] || nullptr == planes[2] || nullptr == width
Bytes) { |
| 349 return kInvalidInput; |
| 350 } |
| 351 |
| 352 if (!this->rewindIfNeeded()) { |
| 353 return kCouldNotRewind; |
| 354 } |
| 355 |
| 356 return this->onGetYUV8Planes(sizes, planes, widthBytes); |
| 357 } |
| 358 |
| 280 /** | 359 /** |
| 281 * The remaining functions revolve around decoding scanlines. | 360 * The remaining functions revolve around decoding scanlines. |
| 282 */ | 361 */ |
| 283 | 362 |
| 284 /** | 363 /** |
| 285 * Prepare for a scanline decode with the specified options. | 364 * Prepare for a scanline decode with the specified options. |
| 286 * | 365 * |
| 287 * After this call, this class will be ready to decode the first scanline. | 366 * After this call, this class will be ready to decode the first scanline. |
| 288 * | 367 * |
| 289 * This must be called in order to call getScanlines or skipScanlines. | 368 * 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. | 514 * is located in the encoded data. |
| 436 * | 515 * |
| 437 * This will equal inputScanline, except in the case of strangely | 516 * This will equal inputScanline, except in the case of strangely |
| 438 * encoded image types (bottom-up bmps, interlaced gifs). | 517 * encoded image types (bottom-up bmps, interlaced gifs). |
| 439 */ | 518 */ |
| 440 int outputScanline(int inputScanline) const; | 519 int outputScanline(int inputScanline) const; |
| 441 | 520 |
| 442 protected: | 521 protected: |
| 443 SkCodec(const SkImageInfo&, SkStream*); | 522 SkCodec(const SkImageInfo&, SkStream*); |
| 444 | 523 |
| 445 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { | 524 virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const { |
| 446 // By default, scaling is not supported. | 525 // By default, scaling is not supported. |
| 447 return this->getInfo().dimensions(); | 526 return this->getInfo().dimensions(); |
| 448 } | 527 } |
| 449 | 528 |
| 450 // FIXME: What to do about subsets?? | 529 // FIXME: What to do about subsets?? |
| 451 /** | 530 /** |
| 452 * Subclasses should override if they support dimensions other than the | 531 * Subclasses should override if they support dimensions other than the |
| 453 * srcInfo's. | 532 * srcInfo's. |
| 454 */ | 533 */ |
| 455 virtual bool onDimensionsSupported(const SkISize&) { | 534 virtual bool onDimensionsSupported(const SkISize&) { |
| 456 return false; | 535 return false; |
| 457 } | 536 } |
| 458 | 537 |
| 459 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 538 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
| 460 | 539 |
| 461 /** | 540 /** |
| 462 * @param rowsDecoded When the encoded image stream is incomplete, this func
tion | 541 * @param rowsDecoded When the encoded image stream is incomplete, this func
tion |
| 463 * will return kIncompleteInput and rowsDecoded will be s
et to | 542 * will return kIncompleteInput and rowsDecoded will be s
et to |
| 464 * the number of scanlines that were successfully decoded
. | 543 * the number of scanlines that were successfully decoded
. |
| 465 * This will allow getPixels() to fill the uninitialized
memory. | 544 * This will allow getPixels() to fill the uninitialized
memory. |
| 466 */ | 545 */ |
| 467 virtual Result onGetPixels(const SkImageInfo& info, | 546 virtual Result onGetPixels(const SkImageInfo& info, |
| 468 void* pixels, size_t rowBytes, const Options&, | 547 void* pixels, size_t rowBytes, const Options&, |
| 469 SkPMColor ctable[], int* ctableCount, | 548 SkPMColor ctable[], int* ctableCount, |
| 470 int* rowsDecoded) = 0; | 549 int* rowsDecoded) = 0; |
| 471 | 550 |
| 472 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { | 551 virtual bool onQueryYUV8(YUVPlanesSizes*, YUVPlanesWidthBytes*, SkYUVColorSp
ace*) const { |
| 552 return false; |
| 553 } |
| 554 |
| 555 virtual Result onGetYUV8Planes(const YUVPlanesSizes*, void*[3] /*planes*/, |
| 556 const YUVPlanesWidthBytes*) { |
| 557 return kUnimplemented; |
| 558 } |
| 559 |
| 560 virtual bool onGetValidSubset(SkIRect* /*desiredSubset*/) const { |
| 473 // By default, subsets are not supported. | 561 // By default, subsets are not supported. |
| 474 return false; | 562 return false; |
| 475 } | 563 } |
| 476 | 564 |
| 477 /** | 565 /** |
| 478 * If the stream was previously read, attempt to rewind. | 566 * If the stream was previously read, attempt to rewind. |
| 479 * | 567 * |
| 480 * If the stream needed to be rewound, call onRewind. | 568 * If the stream needed to be rewound, call onRewind. |
| 481 * @returns true if the codec is at the right position and can be used. | 569 * @returns true if the codec is at the right position and can be used. |
| 482 * false if there was a failure to rewind. | 570 * 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. | 715 * not affect ownership. |
| 628 * | 716 * |
| 629 * Only valid during scanline decoding. | 717 * Only valid during scanline decoding. |
| 630 */ | 718 */ |
| 631 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr;
} | 719 virtual SkSampler* getSampler(bool /*createIfNecessary*/) { return nullptr;
} |
| 632 | 720 |
| 633 friend class SkSampledCodec; | 721 friend class SkSampledCodec; |
| 634 friend class SkIcoCodec; | 722 friend class SkIcoCodec; |
| 635 }; | 723 }; |
| 636 #endif // SkCodec_DEFINED | 724 #endif // SkCodec_DEFINED |
| OLD | NEW |