| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 char buffer[sizeof(kBmpMagic)]; | 41 char buffer[sizeof(kBmpMagic)]; |
| 42 | 42 |
| 43 return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && | 43 return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && |
| 44 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic)); | 44 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static SkImageDecoder* sk_libbmp_dfactory(SkStreamRewindable* stream) { | 47 static SkImageDecoder* sk_libbmp_dfactory(SkStreamRewindable* stream) { |
| 48 if (is_bmp(stream)) { | 48 if (is_bmp(stream)) { |
| 49 return new SkBMPImageDecoder; | 49 return new SkBMPImageDecoder; |
| 50 } | 50 } |
| 51 return NULL; | 51 return nullptr; |
| 52 } | 52 } |
| 53 | 53 |
| 54 static SkImageDecoder_DecodeReg gReg(sk_libbmp_dfactory); | 54 static SkImageDecoder_DecodeReg gReg(sk_libbmp_dfactory); |
| 55 | 55 |
| 56 static SkImageDecoder::Format get_format_bmp(SkStreamRewindable* stream) { | 56 static SkImageDecoder::Format get_format_bmp(SkStreamRewindable* stream) { |
| 57 if (is_bmp(stream)) { | 57 if (is_bmp(stream)) { |
| 58 return SkImageDecoder::kBMP_Format; | 58 return SkImageDecoder::kBMP_Format; |
| 59 } | 59 } |
| 60 return SkImageDecoder::kUnknown_Format; | 60 return SkImageDecoder::kUnknown_Format; |
| 61 } | 61 } |
| 62 | 62 |
| 63 static SkImageDecoder_FormatReg gFormatReg(get_format_bmp); | 63 static SkImageDecoder_FormatReg gFormatReg(get_format_bmp); |
| 64 | 64 |
| 65 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
| 66 | 66 |
| 67 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { | 67 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { |
| 68 public: | 68 public: |
| 69 // we don't copy the bitmap, just remember the pointer | 69 // we don't copy the bitmap, just remember the pointer |
| 70 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} | 70 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} |
| 71 | 71 |
| 72 // override from BmpDecoderCallback | 72 // override from BmpDecoderCallback |
| 73 virtual uint8* SetSize(int width, int height) { | 73 virtual uint8* SetSize(int width, int height) { |
| 74 fWidth = width; | 74 fWidth = width; |
| 75 fHeight = height; | 75 fHeight = height; |
| 76 if (fJustBounds) { | 76 if (fJustBounds) { |
| 77 return NULL; | 77 return nullptr; |
| 78 } | 78 } |
| 79 | 79 |
| 80 fRGB.setCount(width * height * 3); // 3 == r, g, b | 80 fRGB.setCount(width * height * 3); // 3 == r, g, b |
| 81 return fRGB.begin(); | 81 return fRGB.begin(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 int width() const { return fWidth; } | 84 int width() const { return fWidth; } |
| 85 int height() const { return fHeight; } | 85 int height() const { return fHeight; } |
| 86 const uint8_t* rgb() const { return fRGB.begin(); } | 86 const uint8_t* rgb() const { return fRGB.begin(); } |
| 87 | 87 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 SkScaledBitmapSampler sampler(width, height, getSampleSize()); | 133 SkScaledBitmapSampler sampler(width, height, getSampleSize()); |
| 134 | 134 |
| 135 bm->setInfo(SkImageInfo::Make(sampler.scaledWidth(), sampler.scaledHeight(), | 135 bm->setInfo(SkImageInfo::Make(sampler.scaledWidth(), sampler.scaledHeight(), |
| 136 colorType, kOpaque_SkAlphaType)); | 136 colorType, kOpaque_SkAlphaType)); |
| 137 | 137 |
| 138 if (justBounds) { | 138 if (justBounds) { |
| 139 return kSuccess; | 139 return kSuccess; |
| 140 } | 140 } |
| 141 | 141 |
| 142 if (!this->allocPixelRef(bm, NULL)) { | 142 if (!this->allocPixelRef(bm, nullptr)) { |
| 143 return kFailure; | 143 return kFailure; |
| 144 } | 144 } |
| 145 | 145 |
| 146 SkAutoLockPixels alp(*bm); | 146 SkAutoLockPixels alp(*bm); |
| 147 | 147 |
| 148 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { | 148 if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) { |
| 149 return kFailure; | 149 return kFailure; |
| 150 } | 150 } |
| 151 | 151 |
| 152 const int srcRowBytes = width * 3; | 152 const int srcRowBytes = width * 3; |
| 153 const int dstHeight = sampler.scaledHeight(); | 153 const int dstHeight = sampler.scaledHeight(); |
| 154 const uint8_t* srcRow = callback.rgb(); | 154 const uint8_t* srcRow = callback.rgb(); |
| 155 | 155 |
| 156 srcRow += sampler.srcY0() * srcRowBytes; | 156 srcRow += sampler.srcY0() * srcRowBytes; |
| 157 for (int y = 0; y < dstHeight; y++) { | 157 for (int y = 0; y < dstHeight; y++) { |
| 158 sampler.next(srcRow); | 158 sampler.next(srcRow); |
| 159 srcRow += sampler.srcDY() * srcRowBytes; | 159 srcRow += sampler.srcDY() * srcRowBytes; |
| 160 } | 160 } |
| 161 return kSuccess; | 161 return kSuccess; |
| 162 } | 162 } |
| OLD | NEW |