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 "SkScaledBitmapSampler.h" | |
10 #include "SkStream.h" | 11 #include "SkStream.h" |
11 #include "SkStreamHelpers.h" | 12 #include "SkStreamHelpers.h" |
12 #include "SkTypes.h" | 13 #include "SkTypes.h" |
13 | 14 |
14 #include "etc1.h" | 15 #include "etc1.h" |
15 | 16 |
16 class SkPKMImageDecoder : public SkImageDecoder { | 17 class SkPKMImageDecoder : public SkImageDecoder { |
17 public: | 18 public: |
18 SkPKMImageDecoder() { } | 19 SkPKMImageDecoder() { } |
19 | 20 |
(...skipping 23 matching lines...) Expand all Loading... | |
43 SkASSERT(etc1_pkm_is_valid(buf)); | 44 SkASSERT(etc1_pkm_is_valid(buf)); |
44 | 45 |
45 const unsigned short width = etc1_pkm_get_width(buf); | 46 const unsigned short width = etc1_pkm_get_width(buf); |
46 const unsigned short height = etc1_pkm_get_height(buf); | 47 const unsigned short height = etc1_pkm_get_height(buf); |
47 | 48 |
48 // should we allow the Chooser (if present) to pick a config for us??? | 49 // should we allow the Chooser (if present) to pick a config for us??? |
49 if (!this->chooseFromOneChoice(SkBitmap::kARGB_8888_Config, width, height)) { | 50 if (!this->chooseFromOneChoice(SkBitmap::kARGB_8888_Config, width, height)) { |
50 return false; | 51 return false; |
51 } | 52 } |
52 | 53 |
53 bm->setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, kOpaque_SkAlpha Type); | 54 // Setup the sampler... |
robertphillips
2014/05/23 17:55:20
this->getSampleSize() ??
krajcevski
2014/05/23 18:06:43
Done.
| |
55 SkScaledBitmapSampler sampler(width, height, getSampleSize()); | |
56 | |
57 // Set the config... | |
58 bm->setConfig(SkBitmap::kARGB_8888_Config, sampler.scaledWidth(), sampler.sc aledHeight(), | |
59 0, kOpaque_SkAlphaType); | |
54 if (SkImageDecoder::kDecodeBounds_Mode == mode) { | 60 if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
55 return true; | 61 return true; |
56 } | 62 } |
57 | 63 |
58 if (!this->allocPixelRef(bm, NULL)) { | 64 if (!this->allocPixelRef(bm, NULL)) { |
59 return false; | 65 return false; |
60 } | 66 } |
61 | 67 |
62 // Lock the pixels, since we're about to write to them... | 68 // Lock the pixels, since we're about to write to them... |
63 SkAutoLockPixels alp(*bm); | 69 SkAutoLockPixels alp(*bm); |
64 | 70 |
71 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { | |
72 return false; | |
73 } | |
74 | |
65 // Advance buffer past the header | 75 // Advance buffer past the header |
66 buf += ETC_PKM_HEADER_SIZE; | 76 buf += ETC_PKM_HEADER_SIZE; |
67 | 77 |
68 // ETC1 Data is encoded as RGB pixels, so we should extract it as such | 78 // ETC1 Data is encoded as RGB pixels, so we should extract it as such |
69 int nPixels = width * height; | 79 int nPixels = width * height; |
70 SkAutoMalloc outRGBData(nPixels * 3); | 80 SkAutoMalloc outRGBData(nPixels * 3); |
71 etc1_byte *outRGBDataPtr = reinterpret_cast<etc1_byte *>(outRGBData.get()); | 81 etc1_byte *outRGBDataPtr = reinterpret_cast<etc1_byte *>(outRGBData.get()); |
72 | 82 |
73 // Decode ETC1 | 83 // Decode ETC1 |
74 if (etc1_decode_image(buf, outRGBDataPtr, width, height, 3, width*3)) { | 84 if (etc1_decode_image(buf, outRGBDataPtr, width, height, 3, width*3)) { |
75 return false; | 85 return false; |
76 } | 86 } |
77 | 87 |
78 // Set each of the pixels... | 88 // Set each of the pixels... |
79 const uint8_t *src = reinterpret_cast<uint8_t *>(outRGBDataPtr); | 89 const int srcRowBytes = width * 3; |
80 uint8_t *dst = reinterpret_cast<uint8_t *>(bm->getPixels()); | 90 const int dstHeight = sampler.scaledHeight(); |
81 for (int i = 0; i < width*height; ++i) { | 91 const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBDataPtr); |
82 *dst++ = src[2]; // B | 92 srcRow += sampler.srcY0() * srcRowBytes; |
robertphillips
2014/05/23 17:55:20
++y ?
krajcevski
2014/05/23 18:06:43
Done.
| |
83 *dst++ = src[1]; // G | 93 for (int y = 0; y < dstHeight; y++) { |
84 *dst++ = src[0]; // R | 94 sampler.next(srcRow); |
85 *dst++ = 0xFF; // Opaque alpha... | 95 srcRow += sampler.srcDY() * srcRowBytes; |
86 src += 3; | |
87 } | 96 } |
88 | 97 |
89 return true; | 98 return true; |
90 } | 99 } |
91 | 100 |
92 //////////////////////////////////////////////////////////////////////////////// ///////// | 101 //////////////////////////////////////////////////////////////////////////////// ///////// |
93 DEFINE_DECODER_CREATOR(PKMImageDecoder); | 102 DEFINE_DECODER_CREATOR(PKMImageDecoder); |
94 //////////////////////////////////////////////////////////////////////////////// ///////// | 103 //////////////////////////////////////////////////////////////////////////////// ///////// |
95 | 104 |
96 static bool is_pkm(SkStreamRewindable* stream) { | 105 static bool is_pkm(SkStreamRewindable* stream) { |
(...skipping 16 matching lines...) Expand all Loading... | |
113 static SkImageDecoder_DecodeReg gReg(sk_libpkm_dfactory); | 122 static SkImageDecoder_DecodeReg gReg(sk_libpkm_dfactory); |
114 | 123 |
115 static SkImageDecoder::Format get_format_pkm(SkStreamRewindable* stream) { | 124 static SkImageDecoder::Format get_format_pkm(SkStreamRewindable* stream) { |
116 if (is_pkm(stream)) { | 125 if (is_pkm(stream)) { |
117 return SkImageDecoder::kPKM_Format; | 126 return SkImageDecoder::kPKM_Format; |
118 } | 127 } |
119 return SkImageDecoder::kUnknown_Format; | 128 return SkImageDecoder::kUnknown_Format; |
120 } | 129 } |
121 | 130 |
122 static SkImageDecoder_FormatReg gFormatReg(get_format_pkm); | 131 static SkImageDecoder_FormatReg gFormatReg(get_format_pkm); |
OLD | NEW |