| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "bmpdecoderhelper.h" | 10 #include "bmpdecoderhelper.h" |
| 11 #include "SkImageDecoder.h" | 11 #include "SkImageDecoder.h" |
| 12 #include "SkScaledBitmapSampler.h" | 12 #include "SkScaledBitmapSampler.h" |
| 13 #include "SkStream.h" | 13 #include "SkStream.h" |
| 14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
| 15 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
| 16 #include "SkTRegistry.h" | 16 #include "SkTRegistry.h" |
| 17 | 17 |
| 18 class SkBMPImageDecoder : public SkImageDecoder { | 18 class SkBMPImageDecoder : public SkImageDecoder { |
| 19 public: | 19 public: |
| 20 SkBMPImageDecoder() {} | 20 SkBMPImageDecoder() {} |
| 21 | 21 |
| 22 virtual Format getFormat() const { | 22 virtual Format getFormat() const SK_OVERRIDE { |
| 23 return kBMP_Format; | 23 return kBMP_Format; |
| 24 } | 24 } |
| 25 | 25 |
| 26 protected: | 26 protected: |
| 27 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode); | 27 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE
; |
| 28 |
| 29 private: |
| 30 typedef SkImageDecoder INHERITED; |
| 28 }; | 31 }; |
| 29 | 32 |
| 30 /////////////////////////////////////////////////////////////////////////////// | 33 /////////////////////////////////////////////////////////////////////////////// |
| 31 DEFINE_DECODER_CREATOR(BMPImageDecoder); | 34 DEFINE_DECODER_CREATOR(BMPImageDecoder); |
| 32 /////////////////////////////////////////////////////////////////////////////// | 35 /////////////////////////////////////////////////////////////////////////////// |
| 33 | 36 |
| 34 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) { | 37 static SkImageDecoder* sk_libbmp_dfactory(SkStream* stream) { |
| 35 static const char kBmpMagic[] = { 'B', 'M' }; | 38 static const char kBmpMagic[] = { 'B', 'M' }; |
| 36 | 39 |
| 37 size_t len = stream->getLength(); | 40 size_t len = stream->getLength(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, false); | 111 SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, false); |
| 109 | 112 |
| 110 // only accept prefConfig if it makes sense for us | 113 // only accept prefConfig if it makes sense for us |
| 111 if (SkBitmap::kARGB_4444_Config != config && | 114 if (SkBitmap::kARGB_4444_Config != config && |
| 112 SkBitmap::kRGB_565_Config != config) { | 115 SkBitmap::kRGB_565_Config != config) { |
| 113 config = SkBitmap::kARGB_8888_Config; | 116 config = SkBitmap::kARGB_8888_Config; |
| 114 } | 117 } |
| 115 | 118 |
| 116 SkScaledBitmapSampler sampler(width, height, getSampleSize()); | 119 SkScaledBitmapSampler sampler(width, height, getSampleSize()); |
| 117 | 120 |
| 121 if (justBounds) { |
| 122 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); |
| 123 bm->setIsOpaque(true); |
| 124 return true; |
| 125 } |
| 126 // No Bitmap reuse supported for this format |
| 127 if (!bm->isNull()) { |
| 128 return false; |
| 129 } |
| 130 |
| 118 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); | 131 bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); |
| 119 bm->setIsOpaque(true); | 132 bm->setIsOpaque(true); |
| 120 if (justBounds) { | |
| 121 return true; | |
| 122 } | |
| 123 | 133 |
| 124 if (!this->allocPixelRef(bm, NULL)) { | 134 if (!this->allocPixelRef(bm, NULL)) { |
| 125 return false; | 135 return false; |
| 126 } | 136 } |
| 127 | 137 |
| 128 SkAutoLockPixels alp(*bm); | 138 SkAutoLockPixels alp(*bm); |
| 129 | 139 |
| 130 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, getDitherImage())) { | 140 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, getDitherImage())) { |
| 131 return false; | 141 return false; |
| 132 } | 142 } |
| 133 | 143 |
| 134 const int srcRowBytes = width * 3; | 144 const int srcRowBytes = width * 3; |
| 135 const int dstHeight = sampler.scaledHeight(); | 145 const int dstHeight = sampler.scaledHeight(); |
| 136 const uint8_t* srcRow = callback.rgb(); | 146 const uint8_t* srcRow = callback.rgb(); |
| 137 | 147 |
| 138 srcRow += sampler.srcY0() * srcRowBytes; | 148 srcRow += sampler.srcY0() * srcRowBytes; |
| 139 for (int y = 0; y < dstHeight; y++) { | 149 for (int y = 0; y < dstHeight; y++) { |
| 140 sampler.next(srcRow); | 150 sampler.next(srcRow); |
| 141 srcRow += sampler.srcDY() * srcRowBytes; | 151 srcRow += sampler.srcDY() * srcRowBytes; |
| 142 } | 152 } |
| 143 return true; | 153 return true; |
| 144 } | 154 } |
| OLD | NEW |