pleyo.com

/src/trunk2/BAL/Interfaces/BTRGBA32Buffer.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Pleyo.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1.  Redistributions of source code must retain the above copyright
00009  *     notice, this list of conditions and the following disclaimer.
00010  * 2.  Redistributions in binary form must reproduce the above copyright
00011  *     notice, this list of conditions and the following disclaimer in the
00012  *     documentation and/or other materials provided with the distribution.
00013  * 3.  Neither the name of Pleyo nor the names of
00014  *     its contributors may be used to endorse or promote products derived
00015  *     from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY PLEYO AND ITS CONTRIBUTORS "AS IS" AND ANY
00018  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020  * DISCLAIMED. IN NO EVENT SHALL PLEYO OR ITS CONTRIBUTORS BE LIABLE FOR ANY
00021  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00034 #ifndef BTRGBA32BUFFER_H
00035 #define BTRGBA32BUFFER_H
00036 
00037 #include "config.h"
00038 #include "IntRect.h"
00039 #include <wtf/Vector.h>
00040 #include "DeprecatedArray.h"
00041 #include "RGBA32Array.h"
00042 
00043 namespace BAL {
00044 
00045 typedef WebCore::DeprecatedArray<char> DeprecatedByteArray;
00046 
00051 class RGBA32Buffer
00052 {
00053 public:
00054     enum FrameStatus { FrameEmpty, FramePartial, FrameComplete };
00055 
00056     RGBA32Buffer() : m_height(0), m_status(FrameEmpty), m_duration(0),
00057                      m_includeInNextFrame(false), m_hasAlpha(false)
00058     {}
00059 
00063     const RGBA32Array& bytes() const { return m_bytes; }
00064     RGBA32Array& bytes() { return m_bytes; }
00068     const WebCore::IntRect& rect() const { return m_rect; }
00072     unsigned height() const { return m_height; }
00076     unsigned width() const { return m_rect.width(); }
00080     FrameStatus status() const { return m_status; }
00084     unsigned duration() const { return m_duration; }
00088     bool includeInNextFrame() const { return m_includeInNextFrame; }
00092     bool hasAlpha() const { return m_hasAlpha; }
00093 
00097     void setRect(const WebCore::IntRect& r) { m_rect = r; }
00101     void ensureHeight(unsigned rowIndex) { if (rowIndex > m_height) m_height = rowIndex; }
00105     void setStatus(FrameStatus s) { m_status = s; }
00109     void setDuration(unsigned duration) { m_duration = duration; }
00113     void setIncludeInNextFrame(bool n) { m_includeInNextFrame = n; }
00117     void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }
00118 
00122     static void setRGBA(unsigned& pos, unsigned r, unsigned g, unsigned b, unsigned a)
00123     {
00124         // We store this data pre-multiplied.
00125         if (a == 0)
00126             pos = 0;
00127         else {
00128             if (a < 255) {
00129                 float alphaPercent = a / 255.0f;
00130                 r = (unsigned int)((float)r * alphaPercent);
00131                 g = (unsigned int)((float)g * alphaPercent);
00132                 b = (unsigned int)((float)b * alphaPercent);
00133             }
00134             pos = (a << 24 | r << 16 | g << 8 | b);
00135         }
00136     }
00137 
00138 private:
00139     RGBA32Array m_bytes;
00140     WebCore::IntRect m_rect;    // The rect of the original specified frame within the overall buffer.
00141                        // This will always just be the entire buffer except for GIF frames
00142                        // whose original rect was smaller than the overall image size.
00143     unsigned m_height; // The height (the number of rows we've fully decoded).
00144     FrameStatus m_status; // Whether or not this frame is completely finished decoding.
00145     unsigned m_duration; // The animation delay.
00146     bool m_includeInNextFrame; // Whether or not the next buffer should be initially populated with our data.
00147     bool m_hasAlpha; // Whether or not any of the pixels in the buffer have transparency.
00148 };
00149 
00150 }
00151 
00152 #endif

Generated on Wed Nov 21 20:04:16 2007 for Origyn Web Browser by Doxygen 1.5.3

pleyo.com
pleyo.com