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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 enum BmpInputFormat { | 49 enum BmpInputFormat { |
50 kStandard_BmpInputFormat, | 50 kStandard_BmpInputFormat, |
51 kRLE_BmpInputFormat, | 51 kRLE_BmpInputFormat, |
52 kBitMask_BmpInputFormat, | 52 kBitMask_BmpInputFormat, |
53 kUnknown_BmpInputFormat | 53 kUnknown_BmpInputFormat |
54 }; | 54 }; |
55 | 55 |
56 /* | 56 /* |
57 * Checks the start of the stream to see if the image is a bitmap | 57 * Checks the start of the stream to see if the image is a bitmap |
58 */ | 58 */ |
59 bool SkBmpCodec::IsBmp(SkStream* stream) { | 59 bool SkBmpCodec::IsBmp(const char* buffer, size_t bytesRead) { |
60 // TODO: Support "IC", "PT", "CI", "CP", "BA" | 60 // TODO: Support "IC", "PT", "CI", "CP", "BA" |
61 const char bmpSig[] = { 'B', 'M' }; | 61 const char bmpSig[] = { 'B', 'M' }; |
62 char buffer[sizeof(bmpSig)]; | 62 return bytesRead >= sizeof(bmpSig) && !memcmp(buffer, bmpSig, sizeof(bmpSig)
); |
63 return stream->read(buffer, sizeof(bmpSig)) == sizeof(bmpSig) && | |
64 !memcmp(buffer, bmpSig, sizeof(bmpSig)); | |
65 } | 63 } |
66 | 64 |
67 /* | 65 /* |
68 * Assumes IsBmp was called and returned true | 66 * Assumes IsBmp was called and returned true |
69 * Creates a bmp decoder | 67 * Creates a bmp decoder |
70 * Reads enough of the stream to determine the image format | 68 * Reads enough of the stream to determine the image format |
71 */ | 69 */ |
72 SkCodec* SkBmpCodec::NewFromStream(SkStream* stream) { | 70 SkCodec* SkBmpCodec::NewFromStream(SkStream* stream) { |
73 return SkBmpCodec::NewFromStream(stream, false); | 71 return SkBmpCodec::NewFromStream(stream, false); |
74 } | 72 } |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 return prepareToDecode(dstInfo, options, inputColorPtr, inputColorCount); | 569 return prepareToDecode(dstInfo, options, inputColorPtr, inputColorCount); |
572 } | 570 } |
573 | 571 |
574 int SkBmpCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { | 572 int SkBmpCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
575 // Create a new image info representing the portion of the image to decode | 573 // Create a new image info representing the portion of the image to decode |
576 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count)
; | 574 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count)
; |
577 | 575 |
578 // Decode the requested rows | 576 // Decode the requested rows |
579 return this->decodeRows(rowInfo, dst, rowBytes, this->options()); | 577 return this->decodeRows(rowInfo, dst, rowBytes, this->options()); |
580 } | 578 } |
OLD | NEW |