ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

pixelbuffer.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "graphics/pixelbuffer.h"
00024 
00025 namespace Graphics {
00026 
00027 PixelBuffer::PixelBuffer()
00028     : _buffer(NULL),
00029       _dispose(DisposeAfterUse::NO) {
00030 
00031 }
00032 
00033 PixelBuffer::PixelBuffer(const PixelFormat &format, int buffersize, DisposeAfterUse::Flag dispose)
00034     : _buffer(NULL),
00035     _dispose(DisposeAfterUse::NO) {
00036     create(format, buffersize, dispose);
00037 }
00038 
00039 PixelBuffer::PixelBuffer(const PixelFormat &format, byte *buffer)
00040     : _buffer(buffer),
00041       _format(format),
00042       _dispose(DisposeAfterUse::NO) {
00043 
00044 }
00045 
00046 PixelBuffer::PixelBuffer(const PixelBuffer &buf) {
00047     *this = buf;
00048 }
00049 
00050 PixelBuffer::~PixelBuffer() {
00051     if (_dispose == DisposeAfterUse::YES)
00052         free();
00053 }
00054 
00055 void PixelBuffer::create(const Graphics::PixelFormat &format, int buffersize, DisposeAfterUse::Flag dispose) {
00056     if (_dispose == DisposeAfterUse::YES)
00057         free();
00058 
00059     _format = format;
00060     _dispose = dispose;
00061     _buffer = new byte[buffersize * format.bytesPerPixel];
00062 }
00063 
00064 void PixelBuffer::create(int buffersize, DisposeAfterUse::Flag dispose) {
00065     if (_dispose == DisposeAfterUse::YES)
00066         free();
00067 
00068     _dispose = dispose;
00069     _buffer = new byte[buffersize * _format.bytesPerPixel];
00070 }
00071 
00072 void PixelBuffer::set(const Graphics::PixelFormat &format, byte *buffer) {
00073     if (_dispose == DisposeAfterUse::YES)
00074         free();
00075 
00076     _format = format;
00077     _buffer = buffer;
00078 }
00079 
00080 void PixelBuffer::free() {
00081     delete[] _buffer;
00082     _buffer = NULL;
00083 }
00084 
00085 void PixelBuffer::clear(int length) {
00086     memset(_buffer, 0, length * _format.bytesPerPixel);
00087 }
00088 
00089 void PixelBuffer::copyBuffer(int thisFrom, int otherFrom, int length, const PixelBuffer &buf) {
00090     if (buf._format == _format) {
00091         memcpy(_buffer + thisFrom * _format.bytesPerPixel, buf._buffer + otherFrom * _format.bytesPerPixel, length * _format.bytesPerPixel);
00092     } else {
00093         uint8 r, g, b, a;
00094         for (int i = 0; i < length; ++i) {
00095             buf.getARGBAt(i + otherFrom, a, r, g, b);
00096             setPixelAt(i + thisFrom, a, r, g, b);
00097         }
00098     }
00099 }
00100 
00101 PixelBuffer &PixelBuffer::operator=(const PixelBuffer &buf) {
00102     _buffer = buf._buffer;
00103     _format = buf._format;
00104     _dispose = DisposeAfterUse::NO;
00105 
00106     return *this;
00107 }
00108 
00109 PixelBuffer &PixelBuffer::operator=(byte *buffer) {
00110     _buffer = buffer;
00111     _dispose = DisposeAfterUse::NO;
00112 
00113     return *this;
00114 }
00115 
00116 }


Generated on Sat Feb 16 2019 05:01:01 for ResidualVM by doxygen 1.7.1
curved edge   curved edge