| 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 "SkBmpMaskCodec.h" | 9 #include "SkBmpMaskCodec.h" |
| 10 #include "SkBmpRLECodec.h" | 10 #include "SkBmpRLECodec.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 * Creates a bmp decoder for a bmp embedded in ico | 77 * Creates a bmp decoder for a bmp embedded in ico |
| 78 * Reads enough of the stream to determine the image format | 78 * Reads enough of the stream to determine the image format |
| 79 */ | 79 */ |
| 80 SkCodec* SkBmpCodec::NewFromIco(SkStream* stream) { | 80 SkCodec* SkBmpCodec::NewFromIco(SkStream* stream) { |
| 81 return SkBmpCodec::NewFromStream(stream, true); | 81 return SkBmpCodec::NewFromStream(stream, true); |
| 82 } | 82 } |
| 83 | 83 |
| 84 /* | 84 /* |
| 85 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool | 85 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool |
| 86 * representing success or failure. If it returned true, and codecOut was | 86 * representing success or failure. If it returned true, and codecOut was |
| 87 * not NULL, it will be set to a new SkBmpCodec. | 87 * not nullptr, it will be set to a new SkBmpCodec. |
| 88 * Does *not* take ownership of the passed in SkStream. | 88 * Does *not* take ownership of the passed in SkStream. |
| 89 */ | 89 */ |
| 90 bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) { | 90 bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) { |
| 91 // Header size constants | 91 // Header size constants |
| 92 static const uint32_t kBmpHeaderBytes = 14; | 92 static const uint32_t kBmpHeaderBytes = 14; |
| 93 static const uint32_t kBmpHeaderBytesPlusFour = kBmpHeaderBytes + 4; | 93 static const uint32_t kBmpHeaderBytesPlusFour = kBmpHeaderBytes + 4; |
| 94 static const uint32_t kBmpOS2V1Bytes = 12; | 94 static const uint32_t kBmpOS2V1Bytes = 12; |
| 95 static const uint32_t kBmpOS2V2Bytes = 64; | 95 static const uint32_t kBmpOS2V2Bytes = 64; |
| 96 static const uint32_t kBmpInfoBaseBytes = 16; | 96 static const uint32_t kBmpInfoBaseBytes = 16; |
| 97 static const uint32_t kBmpInfoV1Bytes = 40; | 97 static const uint32_t kBmpInfoV1Bytes = 40; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 case 32: | 434 case 32: |
| 435 break; | 435 break; |
| 436 default: | 436 default: |
| 437 SkCodecPrintf("Error: invalid input value for bits per pixel.\n"); | 437 SkCodecPrintf("Error: invalid input value for bits per pixel.\n"); |
| 438 return false; | 438 return false; |
| 439 } | 439 } |
| 440 | 440 |
| 441 // Check that input bit masks are valid and create the masks object | 441 // Check that input bit masks are valid and create the masks object |
| 442 SkAutoTDelete<SkMasks> | 442 SkAutoTDelete<SkMasks> |
| 443 masks(SkMasks::CreateMasks(inputMasks, bitsPerPixel)); | 443 masks(SkMasks::CreateMasks(inputMasks, bitsPerPixel)); |
| 444 if (NULL == masks) { | 444 if (nullptr == masks) { |
| 445 SkCodecPrintf("Error: invalid input masks.\n"); | 445 SkCodecPrintf("Error: invalid input masks.\n"); |
| 446 return false; | 446 return false; |
| 447 } | 447 } |
| 448 | 448 |
| 449 // Check for a valid number of total bytes when in RLE mode | 449 // Check for a valid number of total bytes when in RLE mode |
| 450 if (totalBytes <= offset && kRLE_BmpInputFormat == inputFormat) { | 450 if (totalBytes <= offset && kRLE_BmpInputFormat == inputFormat) { |
| 451 SkCodecPrintf("Error: RLE requires valid input size.\n"); | 451 SkCodecPrintf("Error: RLE requires valid input size.\n"); |
| 452 return false; | 452 return false; |
| 453 } | 453 } |
| 454 const size_t RLEBytes = totalBytes - offset; | 454 const size_t RLEBytes = totalBytes - offset; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 507 |
| 508 return true; | 508 return true; |
| 509 } | 509 } |
| 510 | 510 |
| 511 /* | 511 /* |
| 512 * Creates a bmp decoder | 512 * Creates a bmp decoder |
| 513 * Reads enough of the stream to determine the image format | 513 * Reads enough of the stream to determine the image format |
| 514 */ | 514 */ |
| 515 SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, bool inIco) { | 515 SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, bool inIco) { |
| 516 SkAutoTDelete<SkStream> streamDeleter(stream); | 516 SkAutoTDelete<SkStream> streamDeleter(stream); |
| 517 SkCodec* codec = NULL; | 517 SkCodec* codec = nullptr; |
| 518 if (ReadHeader(stream, inIco, &codec)) { | 518 if (ReadHeader(stream, inIco, &codec)) { |
| 519 // codec has taken ownership of stream, so we do not need to | 519 // codec has taken ownership of stream, so we do not need to |
| 520 // delete it. | 520 // delete it. |
| 521 SkASSERT(codec); | 521 SkASSERT(codec); |
| 522 streamDeleter.detach(); | 522 streamDeleter.detach(); |
| 523 return codec; | 523 return codec; |
| 524 } | 524 } |
| 525 return NULL; | 525 return nullptr; |
| 526 } | 526 } |
| 527 | 527 |
| 528 SkBmpCodec::SkBmpCodec(const SkImageInfo& info, SkStream* stream, | 528 SkBmpCodec::SkBmpCodec(const SkImageInfo& info, SkStream* stream, |
| 529 uint16_t bitsPerPixel, RowOrder rowOrder) | 529 uint16_t bitsPerPixel, RowOrder rowOrder) |
| 530 : INHERITED(info, stream) | 530 : INHERITED(info, stream) |
| 531 , fBitsPerPixel(bitsPerPixel) | 531 , fBitsPerPixel(bitsPerPixel) |
| 532 , fRowOrder(rowOrder) | 532 , fRowOrder(rowOrder) |
| 533 {} | 533 {} |
| 534 | 534 |
| 535 bool SkBmpCodec::onRewind() { | 535 bool SkBmpCodec::onRewind() { |
| 536 return SkBmpCodec::ReadHeader(this->stream(), this->inIco(), NULL); | 536 return SkBmpCodec::ReadHeader(this->stream(), this->inIco(), nullptr); |
| 537 } | 537 } |
| 538 | 538 |
| 539 /* | 539 /* |
| 540 * Get the destination row to start filling from | 540 * Get the destination row to start filling from |
| 541 * Used to fill the remainder of the image on incomplete input for bmps | 541 * Used to fill the remainder of the image on incomplete input for bmps |
| 542 * This is tricky since bmps may be kTopDown or kBottomUp. For kTopDown, | 542 * This is tricky since bmps may be kTopDown or kBottomUp. For kTopDown, |
| 543 * we start filling from where we left off, but for kBottomUp we start | 543 * we start filling from where we left off, but for kBottomUp we start |
| 544 * filling at the top of the image. | 544 * filling at the top of the image. |
| 545 */ | 545 */ |
| 546 void* SkBmpCodec::getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const
{ | 546 void* SkBmpCodec::getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const
{ |
| 547 return (kTopDown_RowOrder == fRowOrder) ? SkTAddOffset<void*>(dst, y * dstRo
wBytes) : dst; | 547 return (kTopDown_RowOrder == fRowOrder) ? SkTAddOffset<void*>(dst, y * dstRo
wBytes) : dst; |
| 548 } | 548 } |
| 549 | 549 |
| 550 /* | 550 /* |
| 551 * Compute the number of colors in the color table | 551 * Compute the number of colors in the color table |
| 552 */ | 552 */ |
| 553 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { | 553 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { |
| 554 // Zero is a default for maxColors | 554 // Zero is a default for maxColors |
| 555 // Also set numColors to maxColors when it is too large | 555 // Also set numColors to maxColors when it is too large |
| 556 uint32_t maxColors = 1 << fBitsPerPixel; | 556 uint32_t maxColors = 1 << fBitsPerPixel; |
| 557 if (numColors == 0 || numColors >= maxColors) { | 557 if (numColors == 0 || numColors >= maxColors) { |
| 558 return maxColors; | 558 return maxColors; |
| 559 } | 559 } |
| 560 return numColors; | 560 return numColors; |
| 561 } | 561 } |
| OLD | NEW |