Chromium Code Reviews| 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 #include "SkImageDecoder_libbmp.h" | |
| 9 | 10 |
| 10 #include "bmpdecoderhelper.h" | 11 #include "bmpdecoderhelper.h" |
| 11 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
| 12 #include "SkImageDecoder.h" | |
| 13 #include "SkScaledBitmapSampler.h" | 13 #include "SkScaledBitmapSampler.h" |
| 14 #include "SkStream.h" | 14 #include "SkStream.h" |
| 15 #include "SkStreamPriv.h" | 15 #include "SkStreamPriv.h" |
| 16 #include "SkTDArray.h" | 16 #include "SkTDArray.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 SK_OVERRIDE { | 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) SK_OVERRIDE ; | 27 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE ; |
| 28 | 28 |
| 29 private: | 29 private: |
| 30 typedef SkImageDecoder INHERITED; | 30 typedef SkImageDecoder INHERITED; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 /////////////////////////////////////////////////////////////////////////////// | |
| 34 DEFINE_DECODER_CREATOR(BMPImageDecoder); | |
| 35 /////////////////////////////////////////////////////////////////////////////// | |
| 36 | |
| 37 static bool is_bmp(SkStreamRewindable* stream) { | |
| 38 static const char kBmpMagic[] = { 'B', 'M' }; | |
| 39 | |
| 40 | |
| 41 char buffer[sizeof(kBmpMagic)]; | |
| 42 | |
| 43 return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && | |
| 44 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic)); | |
| 45 } | |
| 46 | |
| 47 static SkImageDecoder* sk_libbmp_dfactory(SkStreamRewindable* stream) { | |
| 48 if (is_bmp(stream)) { | |
| 49 return SkNEW(SkBMPImageDecoder); | |
| 50 } | |
| 51 return NULL; | |
| 52 } | |
| 53 | |
| 54 static SkImageDecoder_DecodeReg gReg(sk_libbmp_dfactory); | |
| 55 | |
| 56 static SkImageDecoder::Format get_format_bmp(SkStreamRewindable* stream) { | |
| 57 if (is_bmp(stream)) { | |
| 58 return SkImageDecoder::kBMP_Format; | |
| 59 } | |
| 60 return SkImageDecoder::kUnknown_Format; | |
| 61 } | |
| 62 | |
| 63 static SkImageDecoder_FormatReg gFormatReg(get_format_bmp); | |
| 64 | |
| 65 /////////////////////////////////////////////////////////////////////////////// | |
| 66 | |
| 67 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { | 33 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { |
| 68 public: | 34 public: |
| 69 // we don't copy the bitmap, just remember the pointer | 35 // we don't copy the bitmap, just remember the pointer |
| 70 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} | 36 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} |
| 71 | 37 |
| 72 // override from BmpDecoderCallback | 38 // override from BmpDecoderCallback |
| 73 virtual uint8* SetSize(int width, int height) { | 39 virtual uint8* SetSize(int width, int height) { |
| 74 fWidth = width; | 40 fWidth = width; |
| 75 fHeight = height; | 41 fHeight = height; |
| 76 if (fJustBounds) { | 42 if (fJustBounds) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 const int dstHeight = sampler.scaledHeight(); | 119 const int dstHeight = sampler.scaledHeight(); |
| 154 const uint8_t* srcRow = callback.rgb(); | 120 const uint8_t* srcRow = callback.rgb(); |
| 155 | 121 |
| 156 srcRow += sampler.srcY0() * srcRowBytes; | 122 srcRow += sampler.srcY0() * srcRowBytes; |
| 157 for (int y = 0; y < dstHeight; y++) { | 123 for (int y = 0; y < dstHeight; y++) { |
| 158 sampler.next(srcRow); | 124 sampler.next(srcRow); |
| 159 srcRow += sampler.srcDY() * srcRowBytes; | 125 srcRow += sampler.srcDY() * srcRowBytes; |
| 160 } | 126 } |
| 161 return true; | 127 return true; |
| 162 } | 128 } |
| 129 | |
| 130 SkImageDecoder::Format SkDetectFormatBMPImageDecoder(SkStreamRewindable* stream) { | |
| 131 static const char kBmpMagic[] = { 'B', 'M' }; | |
| 132 char buffer[sizeof(kBmpMagic)]; | |
| 133 if (stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && | |
| 134 !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic))) { | |
|
scroggo
2014/11/12 18:00:12
I don't think it's in the style guide, but this is
Kimmo Kinnunen
2014/11/18 08:29:45
Right..
| |
| 135 return SkImageDecoder::kBMP_Format; | |
| 136 } | |
| 137 return SkImageDecoder::kUnknown_Format; | |
| 138 } | |
| 139 | |
| 140 SkImageDecoder* SkCreateBMPImageDecoder(SkStreamRewindable* stream) { | |
| 141 if (SkDetectFormatBMPImageDecoder(stream) == SkImageDecoder::kBMP_Format) { | |
| 142 return SkNEW(SkBMPImageDecoder); | |
| 143 } | |
| 144 return NULL; | |
| 145 } | |
| OLD | NEW |