2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 Lugaru 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.
16 You should have received a copy of the GNU General Public License
17 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
20 /**> HEADER FILES <**/
22 #include "TGALoader.h"
24 extern float texdetail;
25 extern TGAImageRec texture;
28 extern bool visibleloading;
30 extern bool LoadImage(const char * fname, TGAImageRec & tex);
31 /********************> LoadTGA() <*****/
32 bool upload_image(const unsigned char* filePath, bool hasalpha)
35 Game::LoadingScreen();
39 // for Windows, just use TGA loader for now
41 CopyPascalStringToC( filePath, fileName);
42 return (LoadImage(fileName, texture));
51 err = FSMakeFSSpec (0, 0, filePath, &fsspec);
55 GraphicsImportComponent gi;
56 err = GetGraphicsImporterForFile(&fsspec, &gi);
61 cr = GraphicsImportGetNaturalBounds(gi, &natbounds);
63 texture.sizeX = natbounds.right;
64 texture.sizeY = natbounds.bottom;
68 err = QTNewGWorldFromPtr(&gw, k32ARGBPixelFormat, &natbounds, NULL, NULL,
69 0, texture.data, 4 * natbounds.right);
73 cr = GraphicsImportSetGWorld(gi, gw, NULL);
75 natbounds.top = natbounds.bottom;
78 cr = GraphicsImportSetBoundsRect(gi, &natbounds);
80 cr = GraphicsImportDraw(gi);
82 err = CloseComponent(gi);
88 // Loop Through The Image Data
89 GLuint imageSize; // Used To Store The Image Size When Setting Aside Ram
90 GLuint temp; // Temporary Variable
91 GLuint bytesPerPixel; // Temporary Variable
92 bytesPerPixel = texture.bpp / 8;
93 imageSize = texture.sizeX * texture.sizeY * bytesPerPixel;
95 for ( GLuint i = 0; i < int( imageSize ); i += 4 ) {
96 // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue)
97 temp = texture.data[i]; // Temporarily Store The Value At Image Data 'i'
98 texture.data[i] = texture.data[i + 1]; // Set The 1st Byte To The Value Of The 3rd Byte
99 texture.data[i + 1] = texture.data[i + 2]; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value)
100 texture.data[i + 2] = texture.data[i + 3];
101 texture.data[i + 3] = temp;
105 for ( GLuint i = 0; i < int( imageSize ); i += 4 ) {
106 texture.data[i + 3] = 255;
114 for ( GLuint k = 0; k < int( imageSize); k += bytesPerPixel * texture.sizeX * texdetail ) {
115 for ( GLuint i = 0; i < int( imageSize / texture.sizeY ); i += bytesPerPixel * texdetail ) {
116 for ( GLuint b = 0; b < bytesPerPixel ; b ++ ) {
119 for ( GLuint l = 0; l < texdetail * texture.sizeX ; l += texture.sizeX ) {
120 for ( GLuint j = 0; j < texdetail ; j ++ ) {
121 temp += (int)texture.data[k + i + j * bytesPerPixel + l * bytesPerPixel + b]; // Set The 1st Byte To The Value Of The 3rd Byte
125 texture.data[which + b] = GLubyte(temp / howmany);
127 which += bytesPerPixel;
130 texture.sizeX /= texdetail;
131 texture.sizeY /= texdetail;