doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / gameengine / GamePlayer / common / GPC_RawImage.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29    
30 #include <iostream>
31 #include <string.h>
32
33 #include "GPC_RawImage.h"
34 #include "GPC_RawLogoArrays.h"
35
36
37 GPC_RawImage::GPC_RawImage()
38                 : m_data(0), m_dataSize(0), m_width(0), m_height(0)
39 {
40 }
41
42
43 bool GPC_RawImage::Load(
44                 const char *srcName,
45                 int destWidth, int destHeight,
46                 TImageAlignment alignment, int offsetX, int offsetY)
47 {
48         int srcWidth, srcHeight;
49         bool success = true;
50         if(strcmp(srcName, "BlenderLogo") == 0)
51                 GetRawBlenderLogo(&m_data, &srcWidth, &srcHeight);
52         else
53                 if(strcmp(srcName, "Blender3DLogo") == 0)
54                         GetRawBlender3DLogo(&m_data, &srcWidth, &srcHeight);
55 #if 0
56         else
57                 if(strcmp(srcName, "NaNLogo") == 0)
58                         GetRawNaNLogo(&m_data, &srcWidth, &srcHeight);
59 #endif
60                 else  // unknown image
61                         success = false;
62
63         if(success)
64         {
65                 unsigned char *tempData = m_data;
66
67                 int numBytes = destWidth * destHeight * 4;
68                 m_data = new unsigned char[numBytes];  // re-use m_data ('unsigned char' was 'char')
69                 if(m_data)
70                 {
71                         ::memset(m_data, 0x00000000, numBytes);
72                         m_width = destWidth;
73                         m_height = destHeight;
74
75                         int srcBytesWidth = srcWidth * 4;
76                         int dstBytesWidth = m_width * 4;
77                         int numRows = (srcHeight + offsetY) < m_height ? srcHeight : m_height - offsetY;
78                         numBytes = (srcWidth + offsetX) < m_width ? srcBytesWidth : (m_width - offsetX) * 4;
79
80                         if((offsetX < m_width) && (offsetY < m_height))
81                         {
82                                 unsigned char* src = (unsigned char*)tempData;
83                                 unsigned char* dst = (unsigned char*)m_data;
84                                 if(alignment == alignTopLeft)
85                                 {
86                                         // Put original in upper left corner
87
88                                         // Add vertical offset
89                                         dst += offsetY * dstBytesWidth; 
90                                         // Add horizontal offset
91                                         dst += offsetX * 4;
92                                         for (int row = 0; row < numRows; row++)
93                                         {
94                                                 ::memcpy(dst, src, numBytes);
95                                                 src += srcBytesWidth;
96                                                 dst += dstBytesWidth;
97                                         }
98                                 }
99                                 else
100                                 {
101                                         // Put original in lower right corner
102
103                                         // Add vertical offset
104                                         dst += (m_height - (srcHeight + offsetY)) * dstBytesWidth;
105                                         // Add horizontal offset
106                                         if (m_width > (srcWidth + offsetX)) {
107                                                 dst += (m_width - (srcWidth + offsetX)) * 4;
108                                         }
109                                         else {
110                                                 src += (srcWidth + offsetX - m_width) * 4;
111                                         }
112                                         for (int row = 0; row < numRows; row++) {
113                                                 ::memcpy(dst, src, numBytes);
114                                                 src += srcBytesWidth;
115                                                 dst += dstBytesWidth;
116                                         }
117                                 }
118                         }
119 // doesn't compile under Linux                  delete [] tempData;
120                         delete tempData;
121                 }
122                 else {
123                         // Allocation failed, restore old data
124                         m_data = tempData;
125                         success = false;
126                 }
127         }
128         
129         return success;
130 }
131