Project

General

Profile

SO3Engine
RenderBuffer.cpp
Go to the documentation of this file.
1/*
2 This file is part of Hikari, a library that allows developers
3 to use Flash in their Ogre3D applications.
4
5 Copyright (C) 2008 Adam J. Simmons
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21/****************************************************************************************************
22 ___ ___ .__ __ .__
23 / | \|__| | _______ _______|__|
24/ ~ \ | |/ /\__ \\_ __ \ |
25\ Y / | < / __ \| | \/ |
26 \___|_ /|__|__|_ \‍(____ /__| |__| v0.4
27 \/ \/ \/
28
29
30* Zed Games PC Development Team - Jaime Crespillo Vilchez (jcrespillo@zed.com)
31* Build: 0.1 - Date: 13/10/2008
32* Undocked version of Hikari Lib
33* Brief: getter method for buffer implemented
34******************************************************************************************************/
36#include "conio.h"
37using namespace Hikari::Impl;
38
39RenderBuffer::RenderBuffer(int width, int height) : width(0), height(0), buffer(0), rowSpan(0)
40{
42}
43
45{
46 if(buffer)
47 {
48 delete[] buffer;
49 buffer = 0;
50 }
51}
52
53void RenderBuffer::reserve(int width, int height)
54{
55 if(this->width != width || this->height != height)
56 {
57 this->width = width;
58 this->height = height;
59
60 rowSpan = width * 4;
61
62 if(buffer)
63 {
64 delete[] buffer;
65 buffer = 0;
66 }
67
68 buffer = new unsigned char[width * height * 4];
69 memset(buffer, 0, width * height * 4);
70 }
71}
72
73void RenderBuffer::copyFrom(unsigned char* srcBuffer, int srcRowSpan)
74{
75 if (getBuffer())
76 {
77 for(int row = 0; row < height; row++)
78 memcpy(getBuffer() + row * rowSpan, srcBuffer + row * srcRowSpan, rowSpan);
79 }
80}
81
82void RenderBuffer::copyArea(RECT srcRect, unsigned char* srcBuffer, int srcRowSpan)
83{
84 if (getBuffer())
85 {
86 if(srcRect.right <= width && srcRect.bottom <= height && srcRect.left>=0 && srcRect.top>=0)
87 {
88 int srcWidth = srcRect.right - srcRect.left;
89 int srcHeight = srcRect.bottom - srcRect.top;
90
91 for(int row = 0; row < srcHeight; row++){
92 unsigned char* destinyBuf = getBuffer() + (row + srcRect.top) * rowSpan + (srcRect.left * 4);
93 unsigned char* sourceBuf = srcBuffer + row * srcRowSpan;
94 int sizeBuf = srcWidth * 4;
95 memcpy(destinyBuf, sourceBuf, sizeBuf);
96 }
97 }
98 }
99}
100
101void RenderBuffer::blitBGR(unsigned char* destBuffer, int destRowSpan, int destDepth)
102{
103 if (getBuffer())
104 {
105 if(destDepth == 3)
106 {
107 for(int row = 0; row < height; row++)
108 for(int col = 0; col < width; col++)
109 memcpy(destBuffer + row * destRowSpan + col * 3, getBuffer() + row * rowSpan + col * 4, 3);
110 }
111 else if(destDepth == 4)
112 {
113 for(int row = 0; row < height; row++)
114 memcpy(destBuffer + row * destRowSpan, getBuffer() + row * rowSpan, rowSpan);
115 }
116 }
117}
118
119
unsigned char * getBuffer()
void copyArea(RECT srcRect, unsigned char *srcBuffer, int srcRowSpan)
RenderBuffer(int width, int height)
void blitBGR(unsigned char *destBuffer, int destRowSpan, int destDepth)
void copyFrom(unsigned char *srcBuffer, int srcRowSpan)
void reserve(int width, int height)