Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/images/SkImageDecoder_libbmp.cpp

Issue 670453002: Remove image decoder and encoder autoregistration (Closed) Base URL: https://skia.googlesource.com/skia.git@separate-image-decoder-01-skpicture
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/images/SkImageDecoder_libbmp.h ('k') | src/images/SkImageDecoder_libgif.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "SkImageDecoder_libbmp.h"
10 #include "bmpdecoderhelper.h"
11 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
12 #include "SkImageDecoder.h"
13 #include "SkScaledBitmapSampler.h" 11 #include "SkScaledBitmapSampler.h"
14 #include "SkStream.h" 12 #include "SkStream.h"
15 #include "SkStreamPriv.h" 13 #include "SkStreamPriv.h"
16 #include "SkTDArray.h" 14 #include "SkTDArray.h"
15 #include "bmpdecoderhelper.h"
17 16
18 class SkBMPImageDecoder : public SkImageDecoder { 17 class SkBMPImageDecoder : public SkImageDecoder {
19 public: 18 public:
20 SkBMPImageDecoder() {} 19 SkBMPImageDecoder() {}
21 20
22 virtual Format getFormat() const SK_OVERRIDE { 21 virtual Format getFormat() const SK_OVERRIDE {
23 return kBMP_Format; 22 return kBMP_Format;
24 } 23 }
25 24
26 protected: 25 protected:
27 virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRI DE; 26 virtual Result onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRI DE;
28 27
29 private: 28 private:
30 typedef SkImageDecoder INHERITED; 29 typedef SkImageDecoder INHERITED;
31 }; 30 };
32 31
33 /////////////////////////////////////////////////////////////////////////////// 32 SkImageDecoder::Format SkDetectFormatBMPImageDecoder(SkStreamRewindable* stream) {
34 DEFINE_DECODER_CREATOR(BMPImageDecoder);
35 ///////////////////////////////////////////////////////////////////////////////
36
37 static bool is_bmp(SkStreamRewindable* stream) {
38 static const char kBmpMagic[] = { 'B', 'M' }; 33 static const char kBmpMagic[] = { 'B', 'M' };
39
40
41 char buffer[sizeof(kBmpMagic)]; 34 char buffer[sizeof(kBmpMagic)];
42 35 if (stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) &&
43 return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) && 36 0 == memcmp(buffer, 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; 37 return SkImageDecoder::kBMP_Format;
59 } 38 }
60 return SkImageDecoder::kUnknown_Format; 39 return SkImageDecoder::kUnknown_Format;
61 } 40 }
62 41
63 static SkImageDecoder_FormatReg gFormatReg(get_format_bmp); 42
43 SkImageDecoder* SkCreateBMPImageDecoder(SkImageDecoder::Format format) {
44 SkASSERT(SkImageDecoder::kBMP_Format == format);
45 return SkNEW(SkBMPImageDecoder);
46 }
64 47
65 /////////////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////////////
66 49
67 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback { 50 class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback {
68 public: 51 public:
69 // we don't copy the bitmap, just remember the pointer 52 // we don't copy the bitmap, just remember the pointer
70 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {} 53 SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {}
71 54
72 // override from BmpDecoderCallback 55 // override from BmpDecoderCallback
73 virtual uint8* SetSize(int width, int height) { 56 virtual uint8* SetSize(int width, int height) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 const int dstHeight = sampler.scaledHeight(); 136 const int dstHeight = sampler.scaledHeight();
154 const uint8_t* srcRow = callback.rgb(); 137 const uint8_t* srcRow = callback.rgb();
155 138
156 srcRow += sampler.srcY0() * srcRowBytes; 139 srcRow += sampler.srcY0() * srcRowBytes;
157 for (int y = 0; y < dstHeight; y++) { 140 for (int y = 0; y < dstHeight; y++) {
158 sampler.next(srcRow); 141 sampler.next(srcRow);
159 srcRow += sampler.srcDY() * srcRowBytes; 142 srcRow += sampler.srcDY() * srcRowBytes;
160 } 143 }
161 return kSuccess; 144 return kSuccess;
162 } 145 }
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libbmp.h ('k') | src/images/SkImageDecoder_libgif.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698