OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #ifndef SkJpegCodec_DEFINED | 8 #ifndef SkJpegCodec_DEFINED |
9 #define SkJpegCodec_DEFINED | 9 #define SkJpegCodec_DEFINED |
10 | 10 |
11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
12 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
13 #include "SkJpegDecoderMgr.h" | 13 #include "SkJpegDecoderMgr.h" |
14 #include "SkJpegUtility_codec.h" | 14 #include "SkJpegUtility_codec.h" |
15 #include "SkStream.h" | 15 #include "SkStream.h" |
16 | 16 |
17 extern "C" { | 17 extern "C" { |
18 #include "jpeglib.h" | 18 #include "jpeglib.h" |
19 } | 19 } |
20 | 20 |
21 class SkScanlineDecoder; | |
22 | |
23 /* | 21 /* |
24 * | 22 * |
25 * This class implements the decoding for jpeg images | 23 * This class implements the decoding for jpeg images |
26 * | 24 * |
27 */ | 25 */ |
28 class SkJpegCodec : public SkCodec { | 26 class SkJpegCodec : public SkCodec { |
29 public: | 27 public: |
30 | 28 |
31 /* | 29 /* |
32 * Checks the start of the stream to see if the image is a jpeg | 30 * Checks the start of the stream to see if the image is a jpeg |
33 * Does not take ownership of the stream | 31 * Does not take ownership of the stream |
34 */ | 32 */ |
35 static bool IsJpeg(SkStream*); | 33 static bool IsJpeg(SkStream*); |
36 | 34 |
37 /* | 35 /* |
38 * Assumes IsJpeg was called and returned true | 36 * Assumes IsJpeg was called and returned true |
39 * Creates a jpeg decoder | 37 * Creates a jpeg decoder |
40 * Takes ownership of the stream | 38 * Takes ownership of the stream |
41 */ | 39 */ |
42 static SkCodec* NewFromStream(SkStream*); | 40 static SkCodec* NewFromStream(SkStream*); |
43 | 41 |
44 /* | |
45 * Assumes IsJpeg was called and returned true | |
46 * Creates a jpeg scanline decoder | |
47 * Takes ownership of the stream | |
48 */ | |
49 static SkScanlineDecoder* NewSDFromStream(SkStream*); | |
50 | |
51 protected: | 42 protected: |
52 | 43 |
53 /* | 44 /* |
54 * Recommend a set of destination dimensions given a requested scale | 45 * Recommend a set of destination dimensions given a requested scale |
55 */ | 46 */ |
56 SkISize onGetScaledDimensions(float desiredScale) const override; | 47 SkISize onGetScaledDimensions(float desiredScale) const override; |
57 | 48 |
58 /* | 49 /* |
59 * Initiates the jpeg decode | 50 * Initiates the jpeg decode |
60 */ | 51 */ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 * Creates an instance of the decoder | 86 * Creates an instance of the decoder |
96 * Called only by NewFromStream | 87 * Called only by NewFromStream |
97 * | 88 * |
98 * @param srcInfo contains the source width and height | 89 * @param srcInfo contains the source width and height |
99 * @param stream the encoded image data | 90 * @param stream the encoded image data |
100 * @param decoderMgr holds decompress struct, src manager, and error manager | 91 * @param decoderMgr holds decompress struct, src manager, and error manager |
101 * takes ownership | 92 * takes ownership |
102 */ | 93 */ |
103 SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, JpegDecoderMgr* de
coderMgr); | 94 SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, JpegDecoderMgr* de
coderMgr); |
104 | 95 |
| 96 ~SkJpegCodec() override; |
| 97 |
105 /* | 98 /* |
106 * Checks if the conversion between the input image and the requested output | 99 * Checks if the conversion between the input image and the requested output |
107 * image has been implemented | 100 * image has been implemented |
108 * Sets the output color space | 101 * Sets the output color space |
109 */ | 102 */ |
110 bool setOutputColorSpace(const SkImageInfo& dst); | 103 bool setOutputColorSpace(const SkImageInfo& dst); |
111 | 104 |
112 /* | 105 /* |
113 * Checks if we can natively scale to the requested dimensions and natively
scales the | 106 * Checks if we can natively scale to the requested dimensions and natively
scales the |
114 * dimensions if possible | 107 * dimensions if possible |
115 */ | 108 */ |
116 bool nativelyScaleToDimensions(uint32_t width, uint32_t height); | 109 bool nativelyScaleToDimensions(uint32_t width, uint32_t height); |
117 | 110 |
| 111 // scanline decoding |
| 112 Result initializeSwizzler(const SkImageInfo&, const SkCodec::Options&); |
| 113 Result onStart(const SkImageInfo& dstInfo, const Options& options, |
| 114 SkPMColor ctable[], int* ctableCount) override; |
| 115 Result onGetScanlines(void* dst, int count, size_t rowBytes) override; |
| 116 Result onSkipScanlines(int count) override; |
| 117 |
118 SkAutoTDelete<JpegDecoderMgr> fDecoderMgr; | 118 SkAutoTDelete<JpegDecoderMgr> fDecoderMgr; |
119 // We will save the state of the decompress struct after reading the header. | 119 // We will save the state of the decompress struct after reading the header. |
120 // This allows us to safely call onGetScaledDimensions() at any time. | 120 // This allows us to safely call onGetScaledDimensions() at any time. |
121 const int fReadyState; | 121 const int fReadyState; |
| 122 |
| 123 // scanline decoding |
| 124 SkAutoMalloc fStorage; // Only used if sampling is needed |
| 125 uint8_t* fSrcRow; // Only used if sampling is needed |
| 126 SkAutoTDelete<SkSwizzler> fSwizzler; |
122 | 127 |
123 friend class SkJpegScanlineDecoder; | |
124 | |
125 typedef SkCodec INHERITED; | 128 typedef SkCodec INHERITED; |
126 }; | 129 }; |
127 | 130 |
128 #endif | 131 #endif |
OLD | NEW |