OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 WebImage_h | 31 #ifndef WebImage_h |
32 #define WebImage_h | 32 #define WebImage_h |
33 | 33 |
34 #include "WebCommon.h" | 34 #include "WebCommon.h" |
35 #include "WebSize.h" | |
36 | 35 |
37 #if WEBKIT_USING_SKIA | 36 #if WEBKIT_USING_SKIA |
38 class SkBitmap; | 37 #include <SkBitmap.h> |
| 38 #elif WEBKIT_USING_CG |
| 39 typedef struct CGImage* CGImageRef; |
39 #endif | 40 #endif |
40 | 41 |
41 namespace WebKit { | 42 namespace WebKit { |
42 | 43 class WebData; |
43 class WebImagePixels; | 44 struct WebSize; |
44 class WebImagePrivate; | |
45 | 45 |
46 // A container for an ARGB bitmap. | 46 // A container for an ARGB bitmap. |
47 class WebImage { | 47 class WebImage { |
48 public: | 48 public: |
49 ~WebImage() { reset(); } | 49 ~WebImage() { reset(); } |
50 | 50 |
51 WebImage() : m_private(0) { } | 51 WebImage() { init(); } |
52 WebImage(const WebImage& image) : m_private(0) { assign(image); } | 52 WebImage(const WebImage& image) { init(); assign(image); } |
53 | 53 |
54 WebImage& operator=(const WebImage& image) | 54 WebImage& operator=(const WebImage& image) |
55 { | 55 { |
56 assign(image); | 56 assign(image); |
57 return *this; | 57 return *this; |
58 } | 58 } |
59 | 59 |
| 60 // Decodes the given image data. If the image has multiple frames, |
| 61 // then the frame whose size is desiredSize is returned. Otherwise, |
| 62 // the first frame is returned. |
| 63 WEBKIT_API static WebImage fromData(const WebData&, const WebSize& desiredSize); |
| 64 |
60 WEBKIT_API void reset(); | 65 WEBKIT_API void reset(); |
| 66 WEBKIT_API void assign(const WebImage&); |
| 67 |
| 68 WEBKIT_API bool isNull() const; |
61 WEBKIT_API WebSize size() const; | 69 WEBKIT_API WebSize size() const; |
62 | 70 |
63 WebImagePixels pixels() const; | |
64 bool isNull() const { return m_private == 0; } | |
65 | |
66 #if WEBKIT_USING_SKIA | 71 #if WEBKIT_USING_SKIA |
67 WebImage(const SkBitmap& bitmap) : m_private(0) | 72 WebImage(const SkBitmap& bitmap) : m_bitmap(bitmap) { } |
68 { | |
69 assign(bitmap); | |
70 } | |
71 | 73 |
72 WebImage& operator=(const SkBitmap& bitmap) | 74 WebImage& operator=(const SkBitmap& bitmap) |
73 { | 75 { |
74 assign(bitmap); | 76 m_bitmap = bitmap; |
75 return *this; | 77 return *this; |
76 } | 78 } |
77 | 79 |
78 WEBKIT_API operator SkBitmap() const; | 80 SkBitmap& getSkBitmap() { return m_bitmap; } |
79 #endif | 81 const SkBitmap& getSkBitmap() const { return m_bitmap; } |
80 | 82 |
81 private: | 83 private: |
82 friend class WebImagePixels; | 84 void init() { } |
| 85 SkBitmap m_bitmap; |
83 | 86 |
84 WEBKIT_API void assign(const WebImage&); | 87 #elif WEBKIT_USING_CG |
85 WEBKIT_API const void* lockPixels(); | 88 WebImage(CGImageRef imageRef) { init(); assign(imageRef); } |
86 WEBKIT_API void unlockPixels(); | |
87 | 89 |
88 #if WEBKIT_USING_SKIA | 90 WebImage& operator=(CGImageRef imageRef) |
89 WEBKIT_API void assign(const SkBitmap&); | |
90 #endif | |
91 | |
92 WebImagePrivate* m_private; | |
93 }; | |
94 | |
95 class WebImagePixels { | |
96 public: | |
97 WebImagePixels(WebImage* image) : m_image(image) | |
98 { | 91 { |
99 m_data = m_image->lockPixels(); | 92 assign(imageRef); |
| 93 return *this; |
100 } | 94 } |
101 | 95 |
102 WebImagePixels(const WebImagePixels& other) : m_image(other.m_image) | 96 CGImageRef getCGImageRef() const { return m_imageRef; } |
103 { | |
104 m_data = m_image->lockPixels(); | |
105 } | |
106 | |
107 ~WebImagePixels() { m_image->unlockPixels(); } | |
108 | |
109 const void* get() const { return m_data; } | |
110 operator const void*() const { return m_data; } | |
111 | 97 |
112 private: | 98 private: |
113 WebImagePixels& operator=(const WebImagePixels&); | 99 void init() { m_imageRef = 0; } |
114 | 100 void assign(CGImageRef); |
115 WebImage* m_image; | 101 CGImageRef m_imageRef; |
116 const void* m_data; | 102 #endif |
117 }; | 103 }; |
118 | 104 |
119 inline WebImagePixels WebImage::pixels() const | |
120 { | |
121 return WebImagePixels(const_cast<WebImage*>(this)); | |
122 } | |
123 | |
124 } // namespace WebKit | 105 } // namespace WebKit |
125 | 106 |
126 #endif | 107 #endif |
OLD | NEW |