| 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 "SkCodec_libbmp.h" | 8 #include "SkCodec_libbmp.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkStream.h" | 11 #include "SkStream.h" |
| 12 #include "SkUtils.h" | |
| 13 | 12 |
| 14 /* | 13 /* |
| 15 * | 14 * |
| 16 * Checks if the conversion between the input image and the requested output | 15 * Checks if the conversion between the input image and the requested output |
| 17 * image has been implemented | 16 * image has been implemented |
| 18 * | 17 * |
| 19 */ | 18 */ |
| 20 static bool conversion_possible(const SkImageInfo& dst, | 19 static bool conversion_possible(const SkImageInfo& dst, |
| 21 const SkImageInfo& src) { | 20 const SkImageInfo& src) { |
| 22 // Ensure that the profile type is unchanged | 21 // Ensure that the profile type is unchanged |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 } | 595 } |
| 597 | 596 |
| 598 // Create the color table if necessary and prepare the stream for decode | 597 // Create the color table if necessary and prepare the stream for decode |
| 599 // Note that if it is non-NULL, inputColorCount will be modified | 598 // Note that if it is non-NULL, inputColorCount will be modified |
| 600 if (!createColorTable(dstInfo.alphaType(), inputColorCount)) { | 599 if (!createColorTable(dstInfo.alphaType(), inputColorCount)) { |
| 601 SkCodecPrintf("Error: could not create color table.\n"); | 600 SkCodecPrintf("Error: could not create color table.\n"); |
| 602 return kInvalidInput; | 601 return kInvalidInput; |
| 603 } | 602 } |
| 604 | 603 |
| 605 // Copy the color table to the client if necessary | 604 // Copy the color table to the client if necessary |
| 606 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 605 copy_color_table(dstInfo, fColorTable, inputColorPtr, inputColorCount); |
| 607 SkASSERT(NULL != inputColorPtr); | |
| 608 SkASSERT(NULL != inputColorCount); | |
| 609 SkASSERT(NULL != fColorTable.get()); | |
| 610 sk_memcpy32(inputColorPtr, fColorTable->readColors(), *inputColorCount); | |
| 611 } | |
| 612 | 606 |
| 613 // Perform the decode | 607 // Perform the decode |
| 614 switch (fInputFormat) { | 608 switch (fInputFormat) { |
| 615 case kBitMask_BitmapInputFormat: | 609 case kBitMask_BitmapInputFormat: |
| 616 return decodeMask(dstInfo, dst, dstRowBytes, opts); | 610 return decodeMask(dstInfo, dst, dstRowBytes, opts); |
| 617 case kRLE_BitmapInputFormat: | 611 case kRLE_BitmapInputFormat: |
| 618 return decodeRLE(dstInfo, dst, dstRowBytes, opts); | 612 return decodeRLE(dstInfo, dst, dstRowBytes, opts); |
| 619 case kStandard_BitmapInputFormat: | 613 case kStandard_BitmapInputFormat: |
| 620 return decode(dstInfo, dst, dstRowBytes, opts); | 614 return decode(dstInfo, dst, dstRowBytes, opts); |
| 621 default: | 615 default: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 637 if (fBitsPerPixel <= 8) { | 631 if (fBitsPerPixel <= 8) { |
| 638 // Zero is a default for maxColors | 632 // Zero is a default for maxColors |
| 639 // Also set fNumColors to maxColors when it is too large | 633 // Also set fNumColors to maxColors when it is too large |
| 640 maxColors = 1 << fBitsPerPixel; | 634 maxColors = 1 << fBitsPerPixel; |
| 641 if (fNumColors == 0 || fNumColors >= maxColors) { | 635 if (fNumColors == 0 || fNumColors >= maxColors) { |
| 642 fNumColors = maxColors; | 636 fNumColors = maxColors; |
| 643 } | 637 } |
| 644 | 638 |
| 645 // Inform the caller of the number of colors | 639 // Inform the caller of the number of colors |
| 646 if (NULL != numColors) { | 640 if (NULL != numColors) { |
| 647 SkASSERT(256 == *numColors); | |
| 648 // We set the number of colors to maxColors in order to ensure | 641 // We set the number of colors to maxColors in order to ensure |
| 649 // safe memory accesses. Otherwise, an invalid pixel could | 642 // safe memory accesses. Otherwise, an invalid pixel could |
| 650 // access memory outside of our color table array. | 643 // access memory outside of our color table array. |
| 651 *numColors = maxColors; | 644 *numColors = maxColors; |
| 652 } | 645 } |
| 653 | 646 |
| 654 // Read the color table from the stream | 647 // Read the color table from the stream |
| 655 colorBytes = fNumColors * fBytesPerColor; | 648 colorBytes = fNumColors * fBytesPerColor; |
| 656 SkAutoTDeleteArray<uint8_t> cBuffer(SkNEW_ARRAY(uint8_t, colorBytes)); | 649 SkAutoTDeleteArray<uint8_t> cBuffer(SkNEW_ARRAY(uint8_t, colorBytes)); |
| 657 if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) { | 650 if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) { |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 uint32_t alphaBit = | 1222 uint32_t alphaBit = |
| 1230 (srcBuffer.get()[quotient] >> shift) & 0x1; | 1223 (srcBuffer.get()[quotient] >> shift) & 0x1; |
| 1231 dstRow[x] &= alphaBit - 1; | 1224 dstRow[x] &= alphaBit - 1; |
| 1232 } | 1225 } |
| 1233 } | 1226 } |
| 1234 } | 1227 } |
| 1235 | 1228 |
| 1236 // Finished decoding the entire image | 1229 // Finished decoding the entire image |
| 1237 return kSuccess; | 1230 return kSuccess; |
| 1238 } | 1231 } |
| OLD | NEW |