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 <QPixmap> 32 #include <stdio.h> 33 34 namespace WebCore { 35 36 RGBA32Buffer::RGBA32Buffer() 37 : m_hasAlpha(false) 38 , m_size() 39 , m_status(FrameEmpty) 40 , m_duration(0) 41 , m_disposalMethod(DisposeNotSpecified) 42 { 43 } 44 45 // The image must not have format 8888 pre multiplied... 46 void RGBA32Buffer::setDecodedImage(const QImage& image) 47 { 48 m_image = image; 49 m_size = image.size(); 50 m_hasAlpha = image.hasAlphaChannel(); 51 } 52 53 void RGBA32Buffer::clear() 54 { 55 m_image = QImage(); 56 m_status = FrameEmpty; 57 // NOTE: Do not reset other members here; clearFrameBufferCache() 58 // calls this to free the bitmap data, but other functions like 59 // initFrameBuffer() and frameComplete() may still need to read 60 // other metadata out of this frame later. 61 } 62 63 void RGBA32Buffer::zeroFill() 64 { 65 m_image.fill(0); 66 } 67 68 void RGBA32Buffer::copyBitmapData(const RGBA32Buffer& other) 69 { 70 if (this == &other) 71 return; 72 73 m_image = other.m_image; 74 m_size = other.m_size; 75 m_hasAlpha = other.m_hasAlpha; 76 } 77 78 bool RGBA32Buffer::setSize(int newWidth, int newHeight) 79 { 80 // This function should only be called once, it will leak memory 81 // otherwise. 82 ASSERT(width() == 0 && height() == 0); 83 84 m_size = IntSize(newWidth, newHeight); 85 m_image = QImage(newWidth, newHeight, QImage::Format_ARGB32_Premultiplied); 86 if (m_image.isNull()) 87 return false; 88 89 // Zero the image. 90 zeroFill(); 91 92 return true; 93 } 94 95 QPixmap* RGBA32Buffer::asNewNativeImage() const 96 { 97 QPixmap pix = QPixmap::fromImage(m_image); 98 m_image = QImage(); 99 100 return new QPixmap(pix); 101 } 102 103 bool RGBA32Buffer::hasAlpha() const 104 { 105 return m_hasAlpha; 106 } 107 108 void RGBA32Buffer::setHasAlpha(bool alpha) 109 { 110 m_hasAlpha = alpha; 111 } 112 113 void RGBA32Buffer::setStatus(FrameStatus status) 114 { 115 m_status = status; 116 } 117 118 RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other) 119 { 120 if (this == &other) 121 return *this; 122 123 copyBitmapData(other); 124 setRect(other.rect()); 125 setStatus(other.status()); 126 setDuration(other.duration()); 127 setDisposalMethod(other.disposalMethod()); 128 return *this; 129 } 130 131 int RGBA32Buffer::width() const 132 { 133 return m_size.width(); 134 } 135 136 int RGBA32Buffer::height() const 137 { 138 return m_size.height(); 139 } 140 141 } 142