Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "SkImageDecoder_pkm.h" | |
| 7 | 8 |
| 8 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 9 #include "SkImageDecoder.h" | |
| 10 #include "SkScaledBitmapSampler.h" | 10 #include "SkScaledBitmapSampler.h" |
| 11 #include "SkStream.h" | 11 #include "SkStream.h" |
| 12 #include "SkStreamPriv.h" | 12 #include "SkStreamPriv.h" |
| 13 #include "SkTextureCompressor.h" | 13 #include "SkTextureCompressor.h" |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 | 15 |
| 16 #include "etc1.h" | 16 #include "etc1.h" |
| 17 | 17 |
| 18 class SkPKMImageDecoder : public SkImageDecoder { | 18 class SkPKMImageDecoder : public SkImageDecoder { |
| 19 public: | 19 public: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBDataPtr); | 95 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBDataPtr); |
| 96 srcRow += sampler.srcY0() * srcRowBytes; | 96 srcRow += sampler.srcY0() * srcRowBytes; |
| 97 for (int y = 0; y < dstHeight; ++y) { | 97 for (int y = 0; y < dstHeight; ++y) { |
| 98 sampler.next(srcRow); | 98 sampler.next(srcRow); |
| 99 srcRow += sampler.srcDY() * srcRowBytes; | 99 srcRow += sampler.srcDY() * srcRowBytes; |
| 100 } | 100 } |
| 101 | 101 |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 //////////////////////////////////////////////////////////////////////////////// ///////// | 105 SkImageDecoder::Format SkDetectFormatPKMImageDecoder(SkStreamRewindable* stream) { |
| 106 DEFINE_DECODER_CREATOR(PKMImageDecoder); | |
| 107 //////////////////////////////////////////////////////////////////////////////// ///////// | |
| 108 | |
| 109 static bool is_pkm(SkStreamRewindable* stream) { | |
| 110 // Read the PKM header and make sure it's valid. | |
| 111 unsigned char buf[ETC_PKM_HEADER_SIZE]; | 106 unsigned char buf[ETC_PKM_HEADER_SIZE]; |
| 112 if (stream->read((void*)buf, ETC_PKM_HEADER_SIZE) != ETC_PKM_HEADER_SIZE) { | 107 if (stream->read((void*)buf, ETC_PKM_HEADER_SIZE) == ETC_PKM_HEADER_SIZE) { |
| 113 return false; | 108 if (etc1_pkm_is_valid(buf)) { |
|
scroggo
2014/11/12 18:00:13
nit: why not &&?
Kimmo Kinnunen
2014/11/18 08:29:45
Done.
| |
| 109 return SkImageDecoder::kPKM_Format; | |
| 110 } | |
| 114 } | 111 } |
| 115 | 112 return SkImageDecoder::kUnknown_Format; |
| 116 return SkToBool(etc1_pkm_is_valid(buf)); | |
| 117 } | 113 } |
| 118 | 114 |
| 119 static SkImageDecoder* sk_libpkm_dfactory(SkStreamRewindable* stream) { | 115 SkImageDecoder* SkCreatePKMImageDecoder(SkStreamRewindable* stream) { |
| 120 if (is_pkm(stream)) { | 116 if (SkDetectFormatPKMImageDecoder(stream) == SkImageDecoder::kPKM_Format) { |
| 121 return SkNEW(SkPKMImageDecoder); | 117 return SkNEW(SkPKMImageDecoder); |
| 122 } | 118 } |
| 123 return NULL; | 119 return NULL; |
| 124 } | 120 } |
| 125 | 121 |
| 126 static SkImageDecoder_DecodeReg gReg(sk_libpkm_dfactory); | |
| 127 | |
| 128 static SkImageDecoder::Format get_format_pkm(SkStreamRewindable* stream) { | |
| 129 if (is_pkm(stream)) { | |
| 130 return SkImageDecoder::kPKM_Format; | |
| 131 } | |
| 132 return SkImageDecoder::kUnknown_Format; | |
| 133 } | |
| 134 | |
| 135 static SkImageDecoder_FormatReg gFormatReg(get_format_pkm); | |
| OLD | NEW |