OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 */ | |
30 | |
31 #ifndef PNGImageEncoder_h | |
32 #define PNGImageEncoder_h | |
33 | |
34 #include "platform/geometry/IntSize.h" | |
35 extern "C" { | |
36 #include "png.h" | |
37 } | |
38 #include <memory> | |
39 #include "platform/wtf/Allocator.h" | |
40 #include "platform/wtf/Vector.h" | |
41 | |
42 namespace blink { | |
43 | |
44 struct ImageDataBuffer; | |
45 | |
46 class PLATFORM_EXPORT PNGImageEncoderState final { | |
47 USING_FAST_MALLOC(PNGImageEncoderState); | |
48 WTF_MAKE_NONCOPYABLE(PNGImageEncoderState); | |
49 | |
50 public: | |
51 static std::unique_ptr<PNGImageEncoderState> Create( | |
52 const IntSize& image_size, | |
53 Vector<unsigned char>* output); | |
54 ~PNGImageEncoderState(); | |
55 png_struct* Png() { | |
56 DCHECK(png_); | |
57 return png_; | |
58 } | |
59 png_info* Info() { | |
60 DCHECK(info_); | |
61 return info_; | |
62 } | |
63 | |
64 private: | |
65 PNGImageEncoderState(png_struct* png, png_info* info) | |
66 : png_(png), info_(info) {} | |
67 png_struct* png_; | |
68 png_info* info_; | |
69 }; | |
70 | |
71 class PLATFORM_EXPORT PNGImageEncoder { | |
72 STATIC_ONLY(PNGImageEncoder); | |
73 | |
74 public: | |
75 // Encode the input data with default compression quality. See also | |
76 // https://crbug.com/179289 | |
77 static bool Encode(const ImageDataBuffer&, Vector<unsigned char>* output); | |
78 | |
79 // Functions for progressive image encoding | |
80 static void WriteOneRowToPng(unsigned char* pixels, PNGImageEncoderState*); | |
81 static void FinalizePng(PNGImageEncoderState*); | |
82 }; | |
83 | |
84 } // namespace blink | |
85 | |
86 #endif | |
OLD | NEW |