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 | 7 |
8 #include "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 protected: | 43 protected: |
44 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; | 44 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; |
45 | 45 |
46 private: | 46 private: |
47 typedef SkImageDecoder INHERITED; | 47 typedef SkImageDecoder INHERITED; |
48 }; | 48 }; |
49 | 49 |
50 SkImageDecoder::Result SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* b
m, Mode mode) { | 50 SkImageDecoder::Result SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* b
m, Mode mode) { |
51 // TODO: Implement SkStream::copyToData() that's cheap for memory and file s
treams | 51 // TODO: Implement SkStream::copyToData() that's cheap for memory and file s
treams |
52 SkAutoDataUnref data(SkCopyStreamToData(stream)); | 52 SkAutoDataUnref data(SkCopyStreamToData(stream)); |
53 if (NULL == data) { | 53 if (nullptr == data) { |
54 return kFailure; | 54 return kFailure; |
55 } | 55 } |
56 | 56 |
57 SkKTXFile ktxFile(data); | 57 SkKTXFile ktxFile(data); |
58 if (!ktxFile.valid()) { | 58 if (!ktxFile.valid()) { |
59 return kFailure; | 59 return kFailure; |
60 } | 60 } |
61 | 61 |
62 const unsigned short width = ktxFile.width(); | 62 const unsigned short width = ktxFile.width(); |
63 const unsigned short height = ktxFile.height(); | 63 const unsigned short height = ktxFile.height(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 const int w = sampler.scaledWidth(); | 111 const int w = sampler.scaledWidth(); |
112 const int h = sampler.scaledHeight(); | 112 const int h = sampler.scaledHeight(); |
113 bm->setInfo(SkImageInfo::MakeN32(w, h, alphaType)); | 113 bm->setInfo(SkImageInfo::MakeN32(w, h, alphaType)); |
114 } | 114 } |
115 | 115 |
116 if (SkImageDecoder::kDecodeBounds_Mode == mode) { | 116 if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
117 return kSuccess; | 117 return kSuccess; |
118 } | 118 } |
119 | 119 |
120 // If we've made it this far, then we know how to grok the data. | 120 // If we've made it this far, then we know how to grok the data. |
121 if (!this->allocPixelRef(bm, NULL)) { | 121 if (!this->allocPixelRef(bm, nullptr)) { |
122 return kFailure; | 122 return kFailure; |
123 } | 123 } |
124 | 124 |
125 // Lock the pixels, since we're about to write to them... | 125 // Lock the pixels, since we're about to write to them... |
126 SkAutoLockPixels alp(*bm); | 126 SkAutoLockPixels alp(*bm); |
127 | 127 |
128 if (isCompressedAlpha) { | 128 if (isCompressedAlpha) { |
129 if (!sampler.begin(bm, SkScaledBitmapSampler::kGray, *this)) { | 129 if (!sampler.begin(bm, SkScaledBitmapSampler::kGray, *this)) { |
130 return kFailure; | 130 return kFailure; |
131 } | 131 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 ////////////////////////////////////////////////////////////////////////////////
///////// | 305 ////////////////////////////////////////////////////////////////////////////////
///////// |
306 DEFINE_DECODER_CREATOR(KTXImageDecoder); | 306 DEFINE_DECODER_CREATOR(KTXImageDecoder); |
307 DEFINE_ENCODER_CREATOR(KTXImageEncoder); | 307 DEFINE_ENCODER_CREATOR(KTXImageEncoder); |
308 ////////////////////////////////////////////////////////////////////////////////
///////// | 308 ////////////////////////////////////////////////////////////////////////////////
///////// |
309 | 309 |
310 static SkImageDecoder* sk_libktx_dfactory(SkStreamRewindable* stream) { | 310 static SkImageDecoder* sk_libktx_dfactory(SkStreamRewindable* stream) { |
311 if (SkKTXFile::is_ktx(stream)) { | 311 if (SkKTXFile::is_ktx(stream)) { |
312 return new SkKTXImageDecoder; | 312 return new SkKTXImageDecoder; |
313 } | 313 } |
314 return NULL; | 314 return nullptr; |
315 } | 315 } |
316 | 316 |
317 static SkImageDecoder::Format get_format_ktx(SkStreamRewindable* stream) { | 317 static SkImageDecoder::Format get_format_ktx(SkStreamRewindable* stream) { |
318 if (SkKTXFile::is_ktx(stream)) { | 318 if (SkKTXFile::is_ktx(stream)) { |
319 return SkImageDecoder::kKTX_Format; | 319 return SkImageDecoder::kKTX_Format; |
320 } | 320 } |
321 return SkImageDecoder::kUnknown_Format; | 321 return SkImageDecoder::kUnknown_Format; |
322 } | 322 } |
323 | 323 |
324 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) { | 324 SkImageEncoder* sk_libktx_efactory(SkImageEncoder::Type t) { |
325 return (SkImageEncoder::kKTX_Type == t) ? new SkKTXImageEncoder : NULL; | 325 return (SkImageEncoder::kKTX_Type == t) ? new SkKTXImageEncoder : nullptr; |
326 } | 326 } |
327 | 327 |
328 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory); | 328 static SkImageDecoder_DecodeReg gReg(sk_libktx_dfactory); |
329 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx); | 329 static SkImageDecoder_FormatReg gFormatReg(get_format_ktx); |
330 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory); | 330 static SkImageEncoder_EncodeReg gEReg(sk_libktx_efactory); |
OLD | NEW |