Chromium Code Reviews| Index: src/codec/SkJpegCodec.h |
| diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee519a167f22582da299f6d770e107c624831b8a |
| --- /dev/null |
| +++ b/src/codec/SkJpegCodec.h |
| @@ -0,0 +1,94 @@ |
| +/* |
| + * Copyright 2015 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef SkJpegCodec_DEFINED |
| +#define SkJpegCodec_DEFINED |
| + |
| +#include "SkCodec.h" |
| +#include "SkImageInfo.h" |
| +#include "SkJpegAutoClean.h" |
| +#include "SkJpegUtility.h" |
| +#include "SkStream.h" |
| +#include "jpeglib.h" |
|
scroggo
2015/04/14 13:10:33
nit: We might keep this separate from the other in
msarett
2015/04/14 19:30:36
I will make sure to do that. Also, it turns out w
scroggo
2015/04/15 00:31:05
I wonder if that is because we're stuck on an old
|
| + |
| +/* |
| + * |
| + * This class implements the decoding for jpeg images |
| + * |
| + */ |
| +class SkJpegCodec : public SkCodec { |
| +public: |
| + |
| + /* |
| + * Checks the start of the stream to see if the image is a jpeg |
| + * Does not take ownership of the stream |
| + */ |
| + static bool IsJpeg(SkStream*); |
| + |
| + /* |
| + * Assumes IsJpeg was called and returned true |
| + * Creates a jpeg decoder |
| + * Takes ownership of the stream |
| + */ |
| + static SkCodec* NewFromStream(SkStream*); |
| + |
| +protected: |
| + |
| + /* |
| + * Recommend a set of destination dimensions given a requested scale |
| + */ |
| + SkISize onGetScaledDimensions(float desiredScale) const override; |
| + |
| + /* |
| + * Initiates the jpeg decode |
| + */ |
| + Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&, |
| + SkPMColor*, int*) override; |
| + |
| + SkEncodedFormat onGetEncodedFormat() const override { |
| + return kJPEG_SkEncodedFormat; |
| + } |
| + |
| +private: |
| + |
| + /* |
| + * Read enough of the stream to initialize the SkJpegCodec. |
| + * Returns a bool representing success or failure. |
| + * |
| + * @param codecOut |
| + * If it returned true, and codecOut was not NULL, |
| + * codecOut will be set to a new SkJpegCodec. |
| + * |
| + * @param decodeMgrOut |
| + * If it returned true, and codecOut was NULL, |
| + * decodeMgrOut must be non-NULL and decodeMgrOut will be set to a new |
| + * JpegAutoClean pointer. |
| + * |
| + * @param stream |
| + * Deleted on failure. |
| + * codecOut will take ownership of it in the case where we created a codec. |
| + * Ownership is unchanged when we set decodeMgrOut. |
| + * |
| + */ |
| + static bool ReadHeader(SkStream* stream, SkCodec** codecOut, |
| + JpegAutoClean** decodeMgrOut); |
| + |
| + /* |
| + * Creates an instance of the decoder |
| + * Called only by NewFromStream |
| + * |
| + * @param srcInfo contains the source width and height |
| + * @param stream the encoded image data |
| + */ |
| + SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream, JpegAutoClean* decodeMgr); |
|
scroggo
2015/04/14 13:10:33
@param decodeMgr Holds jpeg_decompress_struct etc.
msarett
2015/04/14 19:30:36
Done.
|
| + |
| + SkAutoTDelete<JpegAutoClean> fDecodeMgr; |
| + |
| + typedef SkCodec INHERITED; |
| +}; |
| + |
| +#endif |