| 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.h" | 8 #include "SkCodec.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) | 96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) |
| 97 : INHERITED(info, stream) {} | 97 : INHERITED(info, stream) {} |
| 98 | 98 |
| 99 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { | 99 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { |
| 100 return kWBMP_SkEncodedFormat; | 100 return kWBMP_SkEncodedFormat; |
| 101 } | 101 } |
| 102 | 102 |
| 103 SkImageGenerator::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, | 103 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, |
| 104 void* pixels, | 104 void* pixels, |
| 105 size_t rowBytes, | 105 size_t rowBytes, |
| 106 const Options&, | 106 const Options&, |
| 107 SkPMColor ctable[], | 107 SkPMColor ctable[], |
| 108 int* ctableCount) { | 108 int* ctableCount) { |
| 109 SkCodec::RewindState rewindState = this->rewindIfNeeded(); | 109 SkCodec::RewindState rewindState = this->rewindIfNeeded(); |
| 110 if (rewindState == kCouldNotRewind_RewindState) { | 110 if (rewindState == kCouldNotRewind_RewindState) { |
| 111 return SkImageGenerator::kCouldNotRewind; | 111 return kCouldNotRewind; |
| 112 } else if (rewindState == kRewound_RewindState) { | 112 } else if (rewindState == kRewound_RewindState) { |
| 113 (void)read_header(this->stream(), NULL); | 113 (void)read_header(this->stream(), NULL); |
| 114 } | 114 } |
| 115 if (info.dimensions() != this->getInfo().dimensions()) { | 115 if (info.dimensions() != this->getInfo().dimensions()) { |
| 116 return SkImageGenerator::kInvalidScale; | 116 return kInvalidScale; |
| 117 } | 117 } |
| 118 ExpandProc proc = NULL; | 118 ExpandProc proc = NULL; |
| 119 switch (info.colorType()) { | 119 switch (info.colorType()) { |
| 120 case kGray_8_SkColorType: | 120 case kGray_8_SkColorType: |
| 121 proc = expand_bits_to_T<uint8_t, bit_to_grayscale>; | 121 proc = expand_bits_to_T<uint8_t, bit_to_grayscale>; |
| 122 break; | 122 break; |
| 123 case kN32_SkColorType: | 123 case kN32_SkColorType: |
| 124 proc = expand_bits_to_T<SkPMColor, bit_to_pmcolor>; | 124 proc = expand_bits_to_T<SkPMColor, bit_to_pmcolor>; |
| 125 break; | 125 break; |
| 126 case kIndex_8_SkColorType: | 126 case kIndex_8_SkColorType: |
| 127 ctable[0] = BLACK; | 127 ctable[0] = BLACK; |
| 128 ctable[1] = WHITE; | 128 ctable[1] = WHITE; |
| 129 *ctableCount = 2; | 129 *ctableCount = 2; |
| 130 proc = expand_bits_to_T<uint8_t, bit_to_bit>; | 130 proc = expand_bits_to_T<uint8_t, bit_to_bit>; |
| 131 break; | 131 break; |
| 132 case kRGB_565_SkColorType: | 132 case kRGB_565_SkColorType: |
| 133 proc = expand_bits_to_T<uint16_t, bit_to_rgb565>; | 133 proc = expand_bits_to_T<uint16_t, bit_to_rgb565>; |
| 134 break; | 134 break; |
| 135 default: | 135 default: |
| 136 return SkImageGenerator::kInvalidConversion; | 136 return kInvalidConversion; |
| 137 } | 137 } |
| 138 SkISize size = info.dimensions(); | 138 SkISize size = info.dimensions(); |
| 139 uint8_t* dst = static_cast<uint8_t*>(pixels); | 139 uint8_t* dst = static_cast<uint8_t*>(pixels); |
| 140 size_t srcRowBytes = SkAlign8(size.width()) >> 3; | 140 size_t srcRowBytes = SkAlign8(size.width()) >> 3; |
| 141 SkAutoTMalloc<uint8_t> src(srcRowBytes); | 141 SkAutoTMalloc<uint8_t> src(srcRowBytes); |
| 142 for (int y = 0; y < size.height(); ++y) { | 142 for (int y = 0; y < size.height(); ++y) { |
| 143 if (this->stream()->read(src.get(), srcRowBytes) != srcRowBytes) { | 143 if (this->stream()->read(src.get(), srcRowBytes) != srcRowBytes) { |
| 144 return SkImageGenerator::kIncompleteInput; | 144 return kIncompleteInput; |
| 145 } | 145 } |
| 146 proc(dst, src.get(), size.width()); | 146 proc(dst, src.get(), size.width()); |
| 147 dst += rowBytes; | 147 dst += rowBytes; |
| 148 } | 148 } |
| 149 return SkImageGenerator::kSuccess; | 149 return kSuccess; |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool SkWbmpCodec::IsWbmp(SkStream* stream) { | 152 bool SkWbmpCodec::IsWbmp(SkStream* stream) { |
| 153 return read_header(stream, NULL); | 153 return read_header(stream, NULL); |
| 154 } | 154 } |
| 155 | 155 |
| 156 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { | 156 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { |
| 157 SkAutoTDelete<SkStream> streamDeleter(stream); | 157 SkAutoTDelete<SkStream> streamDeleter(stream); |
| 158 SkISize size; | 158 SkISize size; |
| 159 if (!read_header(stream, &size)) { | 159 if (!read_header(stream, &size)) { |
| 160 return NULL; | 160 return NULL; |
| 161 } | 161 } |
| 162 SkImageInfo info = | 162 SkImageInfo info = |
| 163 SkImageInfo::Make(size.width(), size.height(), kGray_8_SkColorType, | 163 SkImageInfo::Make(size.width(), size.height(), kGray_8_SkColorType, |
| 164 kOpaque_SkAlphaType); | 164 kOpaque_SkAlphaType); |
| 165 return SkNEW_ARGS(SkWbmpCodec, (info, streamDeleter.detach())); | 165 return SkNEW_ARGS(SkWbmpCodec, (info, streamDeleter.detach())); |
| 166 } | 166 } |
| OLD | NEW |