Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include <iostream> 00034 #include <string.h> 00035 00036 #include "GPC_RawImage.h" 00037 #include "GPC_RawLogoArrays.h" 00038 00039 00040 GPC_RawImage::GPC_RawImage() 00041 : m_data(0), m_dataSize(0), m_width(0), m_height(0) 00042 { 00043 } 00044 00045 00046 bool GPC_RawImage::Load( 00047 const char *srcName, 00048 int destWidth, int destHeight, 00049 TImageAlignment alignment, int offsetX, int offsetY) 00050 { 00051 int srcWidth, srcHeight; 00052 bool success = true; 00053 if(strcmp(srcName, "BlenderLogo") == 0) 00054 GetRawBlenderLogo(&m_data, &srcWidth, &srcHeight); 00055 else 00056 if(strcmp(srcName, "Blender3DLogo") == 0) 00057 GetRawBlender3DLogo(&m_data, &srcWidth, &srcHeight); 00058 #if 0 00059 else 00060 if(strcmp(srcName, "NaNLogo") == 0) 00061 GetRawNaNLogo(&m_data, &srcWidth, &srcHeight); 00062 #endif 00063 else // unknown image 00064 success = false; 00065 00066 if(success) 00067 { 00068 unsigned char *tempData = m_data; 00069 00070 int numBytes = destWidth * destHeight * 4; 00071 m_data = new unsigned char[numBytes]; // re-use m_data ('unsigned char' was 'char') 00072 if(m_data) 00073 { 00074 ::memset(m_data, 0x00000000, numBytes); 00075 m_width = destWidth; 00076 m_height = destHeight; 00077 00078 int srcBytesWidth = srcWidth * 4; 00079 int dstBytesWidth = m_width * 4; 00080 int numRows = (srcHeight + offsetY) < m_height ? srcHeight : m_height - offsetY; 00081 numBytes = (srcWidth + offsetX) < m_width ? srcBytesWidth : (m_width - offsetX) * 4; 00082 00083 if((offsetX < m_width) && (offsetY < m_height)) 00084 { 00085 unsigned char* src = (unsigned char*)tempData; 00086 unsigned char* dst = (unsigned char*)m_data; 00087 if(alignment == alignTopLeft) 00088 { 00089 // Put original in upper left corner 00090 00091 // Add vertical offset 00092 dst += offsetY * dstBytesWidth; 00093 // Add horizontal offset 00094 dst += offsetX * 4; 00095 for (int row = 0; row < numRows; row++) 00096 { 00097 ::memcpy(dst, src, numBytes); 00098 src += srcBytesWidth; 00099 dst += dstBytesWidth; 00100 } 00101 } 00102 else 00103 { 00104 // Put original in lower right corner 00105 00106 // Add vertical offset 00107 dst += (m_height - (srcHeight + offsetY)) * dstBytesWidth; 00108 // Add horizontal offset 00109 if (m_width > (srcWidth + offsetX)) { 00110 dst += (m_width - (srcWidth + offsetX)) * 4; 00111 } 00112 else { 00113 src += (srcWidth + offsetX - m_width) * 4; 00114 } 00115 for (int row = 0; row < numRows; row++) { 00116 ::memcpy(dst, src, numBytes); 00117 src += srcBytesWidth; 00118 dst += dstBytesWidth; 00119 } 00120 } 00121 } 00122 // doesn't compile under Linux delete [] tempData; 00123 delete tempData; 00124 } 00125 else { 00126 // Allocation failed, restore old data 00127 m_data = tempData; 00128 success = false; 00129 } 00130 } 00131 00132 return success; 00133 } 00134