|
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 #include "config.h" |
|
32 #include "WebImageDecoder.h" |
|
33 |
|
34 #include "BMPImageDecoder.h" |
|
35 #include "ICOImageDecoder.h" |
|
36 #include "SharedBuffer.h" |
|
37 #include "WebData.h" |
|
38 #include "WebImage.h" |
|
39 #include "WebSize.h" |
|
40 |
|
41 #if WEBKIT_USING_SKIA |
|
42 #include <wtf/OwnPtr.h> |
|
43 #include <wtf/PassRefPtr.h> |
|
44 #endif |
|
45 |
|
46 using namespace WebCore; |
|
47 |
|
48 namespace WebKit { |
|
49 |
|
50 void WebImageDecoder::reset() |
|
51 { |
|
52 delete m_private; |
|
53 } |
|
54 |
|
55 void WebImageDecoder::init(Type type) |
|
56 { |
|
57 switch (type) { |
|
58 case TypeBMP: |
|
59 m_private = new BMPImageDecoder(); |
|
60 break; |
|
61 case TypeICO: |
|
62 m_private = new ICOImageDecoder(); |
|
63 break; |
|
64 } |
|
65 } |
|
66 |
|
67 void WebImageDecoder::setData(const WebData& data, bool allDataReceived) |
|
68 { |
|
69 ASSERT(m_private); |
|
70 m_private->setData(PassRefPtr<SharedBuffer>(data).get(), allDataReceived); |
|
71 } |
|
72 |
|
73 bool WebImageDecoder::isFailed() const |
|
74 { |
|
75 ASSERT(m_private); |
|
76 return m_private->failed(); |
|
77 } |
|
78 |
|
79 bool WebImageDecoder::isSizeAvailable() const |
|
80 { |
|
81 ASSERT(m_private); |
|
82 return m_private->isSizeAvailable(); |
|
83 } |
|
84 |
|
85 WebSize WebImageDecoder::size() const |
|
86 { |
|
87 ASSERT(m_private); |
|
88 return m_private->size(); |
|
89 } |
|
90 |
|
91 size_t WebImageDecoder::frameCount() const |
|
92 { |
|
93 ASSERT(m_private); |
|
94 return m_private->frameCount(); |
|
95 } |
|
96 |
|
97 bool WebImageDecoder::isFrameCompleteAtIndex(int index) const |
|
98 { |
|
99 ASSERT(m_private); |
|
100 RGBA32Buffer* const frameBuffer = m_private->frameBufferAtIndex(index); |
|
101 if (!frameBuffer) |
|
102 return false; |
|
103 return (frameBuffer->status() == RGBA32Buffer::FrameComplete); |
|
104 } |
|
105 |
|
106 WebImage WebImageDecoder::getFrameAtIndex(int index = 0) const |
|
107 { |
|
108 ASSERT(m_private); |
|
109 RGBA32Buffer* const frameBuffer = m_private->frameBufferAtIndex(index); |
|
110 if (!frameBuffer) |
|
111 return WebImage(); |
|
112 #if WEBKIT_USING_SKIA |
|
113 OwnPtr<NativeImageSkia>image(frameBuffer->asNewNativeImage()); |
|
114 return WebImage(*image); |
|
115 #elif WEBKIT_USING_CG |
|
116 // FIXME: Implement CG side of this. |
|
117 return WebImage(frameBuffer->asNewNativeImage()); |
|
118 #endif |
|
119 } |
|
120 |
|
121 } // namespace WebKit |