1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google, Inc.
4 * Copyright (C) 2009 Holger Hans Peter Freyther
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "config.h"
29 #include "ImageDecoder.h"
30
31 #include "NotImplemented.h"
32
33 #include <QPixmap>
34 #include <stdio.h>
35
36 namespace WebCore {
37
ImageFrame()38 ImageFrame::ImageFrame()
39 : m_hasAlpha(false)
40 , m_size()
41 , m_status(FrameEmpty)
42 , m_duration(0)
43 , m_disposalMethod(DisposeNotSpecified)
44 {
45 }
46
operator =(const ImageFrame & other)47 ImageFrame& ImageFrame::operator=(const ImageFrame& other)
48 {
49 if (this == &other)
50 return *this;
51
52 copyBitmapData(other);
53 setOriginalFrameRect(other.originalFrameRect());
54 setStatus(other.status());
55 setDuration(other.duration());
56 setDisposalMethod(other.disposalMethod());
57 return *this;
58 }
59
clearPixelData()60 void ImageFrame::clearPixelData()
61 {
62 m_pixmap = QPixmap();
63 m_image = QImage();
64 m_status = FrameEmpty;
65 // NOTE: Do not reset other members here; clearFrameBufferCache()
66 // calls this to free the bitmap data, but other functions like
67 // initFrameBuffer() and frameComplete() may still need to read
68 // other metadata out of this frame later.
69 }
70
zeroFillPixelData()71 void ImageFrame::zeroFillPixelData()
72 {
73 if (m_pixmap.isNull() && !m_image.isNull()) {
74 m_pixmap = QPixmap(m_image.width(), m_image.height());
75 m_image = QImage();
76 }
77 m_pixmap.fill(QColor(0, 0, 0, 0));
78 }
79
copyBitmapData(const ImageFrame & other)80 bool ImageFrame::copyBitmapData(const ImageFrame& other)
81 {
82 if (this == &other)
83 return true;
84
85 m_image = other.m_image;
86 m_pixmap = other.m_pixmap;
87 m_size = other.m_size;
88 m_hasAlpha = other.m_hasAlpha;
89 return true;
90 }
91
setSize(int newWidth,int newHeight)92 bool ImageFrame::setSize(int newWidth, int newHeight)
93 {
94 // This function should only be called once, it will leak memory
95 // otherwise.
96 ASSERT(width() == 0 && height() == 0);
97
98 m_size = IntSize(newWidth, newHeight);
99 m_image = QImage();
100 m_pixmap = QPixmap(newWidth, newHeight);
101 if (m_pixmap.isNull())
102 return false;
103
104 zeroFillPixelData();
105
106 return true;
107 }
108
asNewNativeImage() const109 QPixmap* ImageFrame::asNewNativeImage() const
110 {
111 if (m_pixmap.isNull() && !m_image.isNull()) {
112 m_pixmap = QPixmap::fromImage(m_image);
113 m_image = QImage();
114 }
115 return new QPixmap(m_pixmap);
116 }
117
hasAlpha() const118 bool ImageFrame::hasAlpha() const
119 {
120 return m_hasAlpha;
121 }
122
setHasAlpha(bool alpha)123 void ImageFrame::setHasAlpha(bool alpha)
124 {
125 m_hasAlpha = alpha;
126 }
127
setColorProfile(const ColorProfile & colorProfile)128 void ImageFrame::setColorProfile(const ColorProfile& colorProfile)
129 {
130 notImplemented();
131 }
132
setStatus(FrameStatus status)133 void ImageFrame::setStatus(FrameStatus status)
134 {
135 m_status = status;
136 }
137
138 // The image must not have format 8888 pre multiplied...
setPixmap(const QPixmap & pixmap)139 void ImageFrame::setPixmap(const QPixmap& pixmap)
140 {
141 m_pixmap = pixmap;
142 m_image = QImage();
143 m_size = pixmap.size();
144 m_hasAlpha = pixmap.hasAlphaChannel();
145 }
146
width() const147 int ImageFrame::width() const
148 {
149 return m_size.width();
150 }
151
height() const152 int ImageFrame::height() const
153 {
154 return m_size.height();
155 }
156
157 }
158