OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef JPEGImageEncoder_h | 31 #ifndef JPEGImageEncoder_h |
32 #define JPEGImageEncoder_h | 32 #define JPEGImageEncoder_h |
33 | 33 |
34 #include "platform/geometry/IntSize.h" | 34 #include "platform/geometry/IntSize.h" |
35 #include "wtf/Allocator.h" | 35 #include "wtf/Allocator.h" |
36 #include "wtf/PassOwnPtr.h" | |
37 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
| 37 #include <memory> |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 struct ImageDataBuffer; | 41 struct ImageDataBuffer; |
42 | 42 |
43 class PLATFORM_EXPORT JPEGImageEncoderState { | 43 class PLATFORM_EXPORT JPEGImageEncoderState { |
44 USING_FAST_MALLOC(JPEGImageEncoderState); | 44 USING_FAST_MALLOC(JPEGImageEncoderState); |
45 WTF_MAKE_NONCOPYABLE(JPEGImageEncoderState); | 45 WTF_MAKE_NONCOPYABLE(JPEGImageEncoderState); |
46 public: | 46 public: |
47 static PassOwnPtr<JPEGImageEncoderState> create(const IntSize& imageSize, co
nst double& quality, Vector<unsigned char>* output); | 47 static std::unique_ptr<JPEGImageEncoderState> create(const IntSize& imageSiz
e, const double& quality, Vector<unsigned char>* output); |
48 JPEGImageEncoderState() {} | 48 JPEGImageEncoderState() {} |
49 virtual ~JPEGImageEncoderState() {} | 49 virtual ~JPEGImageEncoderState() {} |
50 }; | 50 }; |
51 | 51 |
52 class PLATFORM_EXPORT JPEGImageEncoder { | 52 class PLATFORM_EXPORT JPEGImageEncoder { |
53 STATIC_ONLY(JPEGImageEncoder); | 53 STATIC_ONLY(JPEGImageEncoder); |
54 public: | 54 public: |
55 enum { | 55 enum { |
56 ProgressiveEncodeFailed = -1 | 56 ProgressiveEncodeFailed = -1 |
57 }; | 57 }; |
58 | 58 |
59 // Encode the image data with a compression quality in [0-100]. | 59 // Encode the image data with a compression quality in [0-100]. |
60 // Warning: Calling this method off the main thread may result in data race | 60 // Warning: Calling this method off the main thread may result in data race |
61 // problems; instead, call JPEGImageEncoderState::create on main thread | 61 // problems; instead, call JPEGImageEncoderState::create on main thread |
62 // first followed by encodeWithPreInitializedState off the main thread will | 62 // first followed by encodeWithPreInitializedState off the main thread will |
63 // be safer. | 63 // be safer. |
64 static bool encode(const ImageDataBuffer&, const double& quality, Vector<uns
igned char>*); | 64 static bool encode(const ImageDataBuffer&, const double& quality, Vector<uns
igned char>*); |
65 | 65 |
66 static bool encodeWithPreInitializedState(PassOwnPtr<JPEGImageEncoderState>,
const unsigned char*, int numRowsCompleted = 0); | 66 static bool encodeWithPreInitializedState(std::unique_ptr<JPEGImageEncoderSt
ate>, const unsigned char*, int numRowsCompleted = 0); |
67 static int progressiveEncodeRowsJpegHelper(JPEGImageEncoderState*, unsigned
char*, int, const double, double); | 67 static int progressiveEncodeRowsJpegHelper(JPEGImageEncoderState*, unsigned
char*, int, const double, double); |
68 static int computeCompressionQuality(const double& quality); | 68 static int computeCompressionQuality(const double& quality); |
69 | 69 |
70 private: | 70 private: |
71 // For callers: provide a reasonable compression quality default. | 71 // For callers: provide a reasonable compression quality default. |
72 enum Quality { DefaultCompressionQuality = 92 }; | 72 enum Quality { DefaultCompressionQuality = 92 }; |
73 }; | 73 }; |
74 | 74 |
75 } // namespace blink | 75 } // namespace blink |
76 | 76 |
77 #endif | 77 #endif |
OLD | NEW |