mirror of
https://github.com/id-Software/GtkRadiant.git
synced 2026-03-19 16:39:26 +01:00
The GtkRadiant sources as originally released under the GPL license.
This commit is contained in:
157
plugins/imagehl/hlw.cpp
Normal file
157
plugins/imagehl/hlw.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// by Hydra - hydra@hydras-world.com
|
||||
//
|
||||
// HLW = Half-Life-WAD, I don't know if the actual in data in the WAD files
|
||||
// has it's own name, so I'm just calling the individal textures .HLW files :)
|
||||
//
|
||||
// Thanks to the guys that made Wally for releasing an example WAD loader.
|
||||
// without it this would not have been possible.
|
||||
|
||||
#include "hlw.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
#include "ifilesystem.h"
|
||||
|
||||
#include "imagelib.h"
|
||||
|
||||
|
||||
/*
|
||||
============================================================================
|
||||
|
||||
HLW IMAGE
|
||||
|
||||
HalfLife WAD files contain files that look like this:
|
||||
|
||||
Mip section
|
||||
First mip
|
||||
Mip header
|
||||
First mip (width * height)
|
||||
Second mip (width * height / 4)
|
||||
Third mip (width * height / 16)
|
||||
Fourth mip (width * height / 64)
|
||||
Palette size (WORD)
|
||||
Palette (Palette size * 3)
|
||||
Padding (WORD)
|
||||
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#define GET_MIP_DATA_SIZE(WIDTH, HEIGHT) (sizeof(WAD3_MIP) + (WIDTH * HEIGHT) + (WIDTH * HEIGHT / 4) + (WIDTH * HEIGHT / 16) + (WIDTH * HEIGHT / 64))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[16];
|
||||
unsigned int width, height;
|
||||
unsigned int offsets[4]; // four mip maps stored
|
||||
} WAD3_MIP, *LPWAD3_MIP;
|
||||
|
||||
/*
|
||||
=========================================================
|
||||
|
||||
HLW LOADING
|
||||
|
||||
Hydra: this code isn't bullet proof and probably won't
|
||||
like corrupt WAD files, but it works for now.
|
||||
|
||||
TODO: make it more robust.
|
||||
=========================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
=============
|
||||
LoadHLW
|
||||
=============
|
||||
*/
|
||||
|
||||
Image* LoadHLWBuff(byte* buffer)
|
||||
{
|
||||
byte *buf_p;
|
||||
unsigned long mipdatasize;
|
||||
int columns, rows, numPixels;
|
||||
byte *pixbuf;
|
||||
int row, column;
|
||||
byte *palette;
|
||||
LPWAD3_MIP lpMip;
|
||||
unsigned char red, green, blue, alphabyte;
|
||||
|
||||
lpMip = (LPWAD3_MIP)buffer; //!\todo Make endian-safe.
|
||||
|
||||
mipdatasize = GET_MIP_DATA_SIZE(lpMip->width,lpMip->height);
|
||||
|
||||
palette = buffer+mipdatasize+2;
|
||||
|
||||
buf_p = buffer+lpMip->offsets[0];
|
||||
|
||||
columns = lpMip->width;
|
||||
rows = lpMip->height;
|
||||
numPixels = columns * rows;
|
||||
|
||||
RGBAImage* image = new RGBAImage(columns, rows);
|
||||
|
||||
for (row = 0; row < rows; row++)
|
||||
{
|
||||
pixbuf = image->getRGBAPixels() + row * columns * 4;
|
||||
|
||||
for (column = 0; column < columns; column++)
|
||||
{
|
||||
int palIndex;
|
||||
|
||||
palIndex = *buf_p++;
|
||||
|
||||
red = *(palette+(palIndex*3));
|
||||
green = *(palette+(palIndex*3)+1);
|
||||
blue = *(palette+(palIndex*3)+2);
|
||||
|
||||
// HalfLife engine makes pixels that are BLUE transparent.
|
||||
// So show them that way in the editor.
|
||||
if (blue == 0xff && red == 0x00 && green == 0x00)
|
||||
{
|
||||
alphabyte = 0x00;
|
||||
blue = 0x00; // don't set the resulting pixel to blue
|
||||
}
|
||||
else
|
||||
{
|
||||
alphabyte = 0xff;
|
||||
}
|
||||
|
||||
*pixbuf++ = red;
|
||||
*pixbuf++ = green;
|
||||
*pixbuf++ = blue;
|
||||
|
||||
*pixbuf++ = alphabyte;
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
Image* LoadHLW(ArchiveFile& file)
|
||||
{
|
||||
ScopedArchiveBuffer buffer(file);
|
||||
return LoadHLWBuff(buffer.buffer );
|
||||
}
|
||||
31
plugins/imagehl/hlw.h
Normal file
31
plugins/imagehl/hlw.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined (INCLUDED_HLW_H)
|
||||
#define INCLUDED_HLW_H
|
||||
|
||||
class Image;
|
||||
class ArchiveFile;
|
||||
|
||||
Image* LoadHLW(ArchiveFile& file);
|
||||
|
||||
#endif
|
||||
|
||||
116
plugins/imagehl/imagehl.cpp
Normal file
116
plugins/imagehl/imagehl.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "imagehl.h"
|
||||
|
||||
#include "debugging/debugging.h"
|
||||
#include "ifilesystem.h"
|
||||
#include "iimage.h"
|
||||
|
||||
#include "hlw.h"
|
||||
#include "mip.h"
|
||||
#include "sprite.h"
|
||||
|
||||
#include "modulesystem/singletonmodule.h"
|
||||
|
||||
|
||||
class ImageDependencies : public GlobalFileSystemModuleRef
|
||||
{
|
||||
};
|
||||
|
||||
class ImageHLWAPI
|
||||
{
|
||||
_QERPlugImageTable m_imagehlw;
|
||||
public:
|
||||
typedef _QERPlugImageTable Type;
|
||||
STRING_CONSTANT(Name, "hlw");
|
||||
|
||||
ImageHLWAPI()
|
||||
{
|
||||
m_imagehlw.loadImage = LoadHLW;
|
||||
}
|
||||
_QERPlugImageTable* getTable()
|
||||
{
|
||||
return &m_imagehlw;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SingletonModule<ImageHLWAPI, ImageDependencies> ImageHLWModule;
|
||||
|
||||
ImageHLWModule g_ImageHLWModule;
|
||||
|
||||
|
||||
class ImageMipAPI
|
||||
{
|
||||
_QERPlugImageTable m_imagemip;
|
||||
public:
|
||||
typedef _QERPlugImageTable Type;
|
||||
STRING_CONSTANT(Name, "mip");
|
||||
|
||||
ImageMipAPI()
|
||||
{
|
||||
m_imagemip.loadImage = LoadMIP;
|
||||
}
|
||||
_QERPlugImageTable* getTable()
|
||||
{
|
||||
return &m_imagemip;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SingletonModule<ImageMipAPI, ImageDependencies> ImageMipModule;
|
||||
|
||||
ImageMipModule g_ImageMipModule;
|
||||
|
||||
|
||||
class ImageSpriteAPI
|
||||
{
|
||||
_QERPlugImageTable m_imagesprite;
|
||||
public:
|
||||
typedef _QERPlugImageTable Type;
|
||||
STRING_CONSTANT(Name, "spr");
|
||||
|
||||
ImageSpriteAPI()
|
||||
{
|
||||
m_imagesprite.loadImage = LoadIDSP;
|
||||
}
|
||||
_QERPlugImageTable* getTable()
|
||||
{
|
||||
return &m_imagesprite;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SingletonModule<ImageSpriteAPI, ImageDependencies> ImageSpriteModule;
|
||||
|
||||
ImageSpriteModule g_ImageSpriteModule;
|
||||
|
||||
|
||||
|
||||
extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
|
||||
{
|
||||
GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
|
||||
GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
|
||||
GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
|
||||
GlobalModuleServer::instance().set(server);
|
||||
|
||||
g_ImageHLWModule.selfRegister();
|
||||
g_ImageMipModule.selfRegister();
|
||||
g_ImageSpriteModule.selfRegister();
|
||||
}
|
||||
7
plugins/imagehl/imagehl.def
Normal file
7
plugins/imagehl/imagehl.def
Normal file
@@ -0,0 +1,7 @@
|
||||
; imagehl.def : Declares the module parameters for the DLL.
|
||||
|
||||
LIBRARY "ImageHL"
|
||||
|
||||
EXPORTS
|
||||
; Explicit exports can go here
|
||||
Radiant_RegisterModules @1
|
||||
174
plugins/imagehl/imagehl.dsp
Normal file
174
plugins/imagehl/imagehl.dsp
Normal file
@@ -0,0 +1,174 @@
|
||||
# Microsoft Developer Studio Project File - Name="imagehl" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=imagehl - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "imagehl.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "imagehl.mak" CFG="imagehl - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "imagehl - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "imagehl - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName "imagehl"
|
||||
# PROP Scc_LocalPath "..\.."
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "imagehl - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE F90 /compile_only /include:"Release/" /libs:dll /nologo /warn:nofileopt /dll
|
||||
# ADD F90 /compile_only /include:"Release/" /libs:dll /nologo /warn:nofileopt /dll
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMAGE_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /O2 /I "..\..\include" /I "..\..\..\gtk2-win32\include\glib-2.0" /I "..\..\..\gtk2-win32\lib\glib-2.0\include" /I "..\common" /I "..\..\libs" /I "..\..\..\STLPort\stlport" /I "..\..\..\libxml2\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMAGE_EXPORTS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 glib-2.0.lib /nologo /dll /machine:I386 /def:".\imagehl.def" /libpath:"..\..\..\gtk2-win32\lib\\"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Copy to dir...
|
||||
PostBuild_Cmds=copy Release\imagehl.dll "../../install/modules"
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "imagehl - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE F90 /check:bounds /compile_only /debug:full /include:"Debug/" /libs:dll /nologo /warn:argument_checking /warn:nofileopt /dll
|
||||
# ADD F90 /check:bounds /compile_only /debug:full /include:"Debug/" /libs:dll /nologo /warn:argument_checking /warn:nofileopt /dll
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMAGE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\..\gtk2-win32\include\glib-2.0" /I "..\..\..\gtk2-win32\lib\glib-2.0\include" /I "..\common" /I "..\..\libs" /I "..\..\..\STLPort\stlport" /I "..\..\..\libxml2\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMAGE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 glib-2.0.lib /nologo /dll /debug /machine:I386 /def:".\imagehl.def" /pdbtype:sept /libpath:"..\..\..\gtk2-win32\lib\\"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Copy to dir...
|
||||
PostBuild_Cmds=copy Debug\imagehl.dll "../../install/modules"
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "imagehl - Win32 Release"
|
||||
# Name "imagehl - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;f90;for;f;fpp"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\hlw.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\imagehl.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\imagehl.def
|
||||
# PROP Exclude_From_Build 1
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mip.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sprite.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\wal.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\hlw.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\imagehl.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mip.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sprite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\wal.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;txt"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\imagehl.txt
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Conscript
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
25
plugins/imagehl/imagehl.h
Normal file
25
plugins/imagehl/imagehl.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright (C) 2001-2006, William Joseph.
|
||||
All Rights Reserved.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined(INCLUDED_IMAGEHL_H)
|
||||
#define INCLUDED_IMAGEHL_H
|
||||
|
||||
#endif
|
||||
30
plugins/imagehl/imagehl.txt
Normal file
30
plugins/imagehl/imagehl.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
ImageHL
|
||||
=======
|
||||
|
||||
Coding by Dominic Clifton - Hydra - hydra@hydras-world.com
|
||||
|
||||
What is it ?
|
||||
------------
|
||||
|
||||
This GTKRadiant 1.2+ plugin handles the loading of textures from .WAD files.
|
||||
I'll refer to these textures as .HLW files, even though they don't have any
|
||||
extension when they're stored in the .WAD file itself.
|
||||
|
||||
You need a VFS plugin to go with this plugin that can open and read .WAD files
|
||||
My VFSWAD plugin does just this.
|
||||
|
||||
Developer Notes
|
||||
---------------
|
||||
|
||||
The project file will copy the compiled DLL file and this .TXT file to
|
||||
"$(HLRADIANTDIR)modules" so make sure you have that environment variable
|
||||
defined.
|
||||
|
||||
For my GTKRadiant 1.2 HalfLife game pack files I use the directory:
|
||||
"E:\games\HalfLife\Tools\GTKR12N". Under which there are the directories
|
||||
"modules" and "plugins"
|
||||
|
||||
Credits
|
||||
-------
|
||||
Thanks to the guys that made Wally for releasing an example WAD loader.
|
||||
without it this would not have been possible.
|
||||
221
plugins/imagehl/imagehl.vcproj
Normal file
221
plugins/imagehl/imagehl.vcproj
Normal file
@@ -0,0 +1,221 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="imagehl"
|
||||
ProjectGUID="{15DEA3EA-9386-49C7-80C6-5B090DE1D536}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../include;../../libs;"../../../STLPort-4.6/stlport";"../../../gtk2-2.4/include/glib-2.0";"../../../gtk2-2.4/lib/glib-2.0/include""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;IMAGEHL_EXPORTS"
|
||||
StringPooling="TRUE"
|
||||
MinimalRebuild="TRUE"
|
||||
ExceptionHandling="FALSE"
|
||||
BasicRuntimeChecks="0"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="FALSE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
BrowseInformation="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
DisableSpecificWarnings="4610;4510;4512;4505;4100;4127"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/imagehl.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""
|
||||
IgnoreDefaultLibraryNames="msvcprtd.lib"
|
||||
ModuleDefinitionFile="$(ProjectName).def"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/imagehl.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary="$(OutDir)/imagehl.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy "$(TargetPath)" "$(SolutionDir)install\modules\"
|
||||
copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)install\modules\""/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
GlobalOptimizations="TRUE"
|
||||
InlineFunctionExpansion="2"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OptimizeForWindowsApplication="FALSE"
|
||||
AdditionalIncludeDirectories="../../include;../../libs;"../../../STLPort-4.6/stlport";"../../../gtk2-2.4/include/glib-2.0";"../../../gtk2-2.4/lib/glib-2.0/include""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;IMAGEHL_EXPORTS"
|
||||
StringPooling="TRUE"
|
||||
ExceptionHandling="FALSE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
DisableSpecificWarnings="4610;4510;4512;4505;4100;4127"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)/imagehl.dll"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""
|
||||
IgnoreDefaultLibraryNames="msvcprt.lib"
|
||||
ModuleDefinitionFile="$(ProjectName).def"
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/imagehl.lib"
|
||||
TargetMachine="1"
|
||||
FixedBaseAddress="0"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy "$(TargetPath)" "$(SolutionDir)install\modules\"
|
||||
copy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)install\modules\""/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="src"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\imagehl.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\imagehl.h">
|
||||
</File>
|
||||
<Filter
|
||||
Name="modules"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||
<File
|
||||
RelativePath=".\hlw.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\hlw.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\mip.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\mip.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\sprite.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\sprite.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath="..\..\debug.py">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="python "$(SolutionDir)debug.py"
|
||||
"
|
||||
AdditionalDependencies=""$(SolutionDir)install\modules\$(TargetName).pdb""
|
||||
Outputs=""$(TargetDir)$(TargetName).pdb""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="python "$(SolutionDir)debug.py"
|
||||
"
|
||||
AdditionalDependencies=""$(SolutionDir)install\modules\$(TargetName).pdb""
|
||||
Outputs=""$(TargetDir)$(TargetName).pdb""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\imagehl.def">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="python "$(SolutionDir)touch.py" "$(TargetPath)"
|
||||
"
|
||||
AdditionalDependencies=""$(SolutionDir)install\modules\$(TargetFileName)""
|
||||
Outputs=""$(TargetPath)""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="python "$(SolutionDir)touch.py" "$(TargetPath)"
|
||||
"
|
||||
AdditionalDependencies=""$(SolutionDir)install\modules\$(TargetFileName)""
|
||||
Outputs=""$(TargetPath)""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
205
plugins/imagehl/mip.cpp
Normal file
205
plugins/imagehl/mip.cpp
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "mip.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
#include "ifilesystem.h"
|
||||
|
||||
#include "imagelib.h"
|
||||
#include "bytestreamutils.h"
|
||||
|
||||
/*
|
||||
============================================================================
|
||||
|
||||
MIP IMAGE
|
||||
|
||||
Quake WAD files contain miptex files that look like this:
|
||||
|
||||
Mip section
|
||||
First mip
|
||||
Mip header
|
||||
First mip (width * height)
|
||||
Second mip (width * height / 4)
|
||||
Third mip (width * height / 16)
|
||||
Fourth mip (width * height / 64)
|
||||
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
#define GET_MIP_DATA_SIZE(WIDTH, HEIGHT) (sizeof(WAD3_MIP) + (WIDTH * HEIGHT) + (WIDTH * HEIGHT / 4) + (WIDTH * HEIGHT / 16) + (WIDTH * HEIGHT / 64))
|
||||
|
||||
const int MIP_NAME_LENGTH = 16;
|
||||
const int MIP_MIPMAP_COUNT = 4;
|
||||
typedef struct
|
||||
{
|
||||
char name[MIP_NAME_LENGTH];
|
||||
unsigned int width, height;
|
||||
unsigned int offsets[MIP_MIPMAP_COUNT]; // four mip maps stored
|
||||
} WAD3_MIP, *LPWAD3_MIP;
|
||||
|
||||
static const byte quakepalette[768] =
|
||||
{
|
||||
0x00,0x00,0x00, 0x0f,0x0f,0x0f, 0x1f,0x1f,0x1f, 0x2f,0x2f,0x2f,
|
||||
0x3f,0x3f,0x3f, 0x4b,0x4b,0x4b, 0x5b,0x5b,0x5b, 0x6b,0x6b,0x6b,
|
||||
0x7b,0x7b,0x7b, 0x8b,0x8b,0x8b, 0x9b,0x9b,0x9b, 0xab,0xab,0xab,
|
||||
0xbb,0xbb,0xbb, 0xcb,0xcb,0xcb, 0xdb,0xdb,0xdb, 0xeb,0xeb,0xeb,
|
||||
0x0f,0x0b,0x07, 0x17,0x0f,0x0b, 0x1f,0x17,0x0b, 0x27,0x1b,0x0f,
|
||||
0x2f,0x23,0x13, 0x37,0x2b,0x17, 0x3f,0x2f,0x17, 0x4b,0x37,0x1b,
|
||||
0x53,0x3b,0x1b, 0x5b,0x43,0x1f, 0x63,0x4b,0x1f, 0x6b,0x53,0x1f,
|
||||
0x73,0x57,0x1f, 0x7b,0x5f,0x23, 0x83,0x67,0x23, 0x8f,0x6f,0x23,
|
||||
0x0b,0x0b,0x0f, 0x13,0x13,0x1b, 0x1b,0x1b,0x27, 0x27,0x27,0x33,
|
||||
0x2f,0x2f,0x3f, 0x37,0x37,0x4b, 0x3f,0x3f,0x57, 0x47,0x47,0x67,
|
||||
0x4f,0x4f,0x73, 0x5b,0x5b,0x7f, 0x63,0x63,0x8b, 0x6b,0x6b,0x97,
|
||||
0x73,0x73,0xa3, 0x7b,0x7b,0xaf, 0x83,0x83,0xbb, 0x8b,0x8b,0xcb,
|
||||
0x00,0x00,0x00, 0x07,0x07,0x00, 0x0b,0x0b,0x00, 0x13,0x13,0x00,
|
||||
0x1b,0x1b,0x00, 0x23,0x23,0x00, 0x2b,0x2b,0x07, 0x2f,0x2f,0x07,
|
||||
0x37,0x37,0x07, 0x3f,0x3f,0x07, 0x47,0x47,0x07, 0x4b,0x4b,0x0b,
|
||||
0x53,0x53,0x0b, 0x5b,0x5b,0x0b, 0x63,0x63,0x0b, 0x6b,0x6b,0x0f,
|
||||
0x07,0x00,0x00, 0x0f,0x00,0x00, 0x17,0x00,0x00, 0x1f,0x00,0x00,
|
||||
0x27,0x00,0x00, 0x2f,0x00,0x00, 0x37,0x00,0x00, 0x3f,0x00,0x00,
|
||||
0x47,0x00,0x00, 0x4f,0x00,0x00, 0x57,0x00,0x00, 0x5f,0x00,0x00,
|
||||
0x67,0x00,0x00, 0x6f,0x00,0x00, 0x77,0x00,0x00, 0x7f,0x00,0x00,
|
||||
0x13,0x13,0x00, 0x1b,0x1b,0x00, 0x23,0x23,0x00, 0x2f,0x2b,0x00,
|
||||
0x37,0x2f,0x00, 0x43,0x37,0x00, 0x4b,0x3b,0x07, 0x57,0x43,0x07,
|
||||
0x5f,0x47,0x07, 0x6b,0x4b,0x0b, 0x77,0x53,0x0f, 0x83,0x57,0x13,
|
||||
0x8b,0x5b,0x13, 0x97,0x5f,0x1b, 0xa3,0x63,0x1f, 0xaf,0x67,0x23,
|
||||
0x23,0x13,0x07, 0x2f,0x17,0x0b, 0x3b,0x1f,0x0f, 0x4b,0x23,0x13,
|
||||
0x57,0x2b,0x17, 0x63,0x2f,0x1f, 0x73,0x37,0x23, 0x7f,0x3b,0x2b,
|
||||
0x8f,0x43,0x33, 0x9f,0x4f,0x33, 0xaf,0x63,0x2f, 0xbf,0x77,0x2f,
|
||||
0xcf,0x8f,0x2b, 0xdf,0xab,0x27, 0xef,0xcb,0x1f, 0xff,0xf3,0x1b,
|
||||
0x0b,0x07,0x00, 0x1b,0x13,0x00, 0x2b,0x23,0x0f, 0x37,0x2b,0x13,
|
||||
0x47,0x33,0x1b, 0x53,0x37,0x23, 0x63,0x3f,0x2b, 0x6f,0x47,0x33,
|
||||
0x7f,0x53,0x3f, 0x8b,0x5f,0x47, 0x9b,0x6b,0x53, 0xa7,0x7b,0x5f,
|
||||
0xb7,0x87,0x6b, 0xc3,0x93,0x7b, 0xd3,0xa3,0x8b, 0xe3,0xb3,0x97,
|
||||
0xab,0x8b,0xa3, 0x9f,0x7f,0x97, 0x93,0x73,0x87, 0x8b,0x67,0x7b,
|
||||
0x7f,0x5b,0x6f, 0x77,0x53,0x63, 0x6b,0x4b,0x57, 0x5f,0x3f,0x4b,
|
||||
0x57,0x37,0x43, 0x4b,0x2f,0x37, 0x43,0x27,0x2f, 0x37,0x1f,0x23,
|
||||
0x2b,0x17,0x1b, 0x23,0x13,0x13, 0x17,0x0b,0x0b, 0x0f,0x07,0x07,
|
||||
0xbb,0x73,0x9f, 0xaf,0x6b,0x8f, 0xa3,0x5f,0x83, 0x97,0x57,0x77,
|
||||
0x8b,0x4f,0x6b, 0x7f,0x4b,0x5f, 0x73,0x43,0x53, 0x6b,0x3b,0x4b,
|
||||
0x5f,0x33,0x3f, 0x53,0x2b,0x37, 0x47,0x23,0x2b, 0x3b,0x1f,0x23,
|
||||
0x2f,0x17,0x1b, 0x23,0x13,0x13, 0x17,0x0b,0x0b, 0x0f,0x07,0x07,
|
||||
0xdb,0xc3,0xbb, 0xcb,0xb3,0xa7, 0xbf,0xa3,0x9b, 0xaf,0x97,0x8b,
|
||||
0xa3,0x87,0x7b, 0x97,0x7b,0x6f, 0x87,0x6f,0x5f, 0x7b,0x63,0x53,
|
||||
0x6b,0x57,0x47, 0x5f,0x4b,0x3b, 0x53,0x3f,0x33, 0x43,0x33,0x27,
|
||||
0x37,0x2b,0x1f, 0x27,0x1f,0x17, 0x1b,0x13,0x0f, 0x0f,0x0b,0x07,
|
||||
0x6f,0x83,0x7b, 0x67,0x7b,0x6f, 0x5f,0x73,0x67, 0x57,0x6b,0x5f,
|
||||
0x4f,0x63,0x57, 0x47,0x5b,0x4f, 0x3f,0x53,0x47, 0x37,0x4b,0x3f,
|
||||
0x2f,0x43,0x37, 0x2b,0x3b,0x2f, 0x23,0x33,0x27, 0x1f,0x2b,0x1f,
|
||||
0x17,0x23,0x17, 0x0f,0x1b,0x13, 0x0b,0x13,0x0b, 0x07,0x0b,0x07,
|
||||
0xff,0xf3,0x1b, 0xef,0xdf,0x17, 0xdb,0xcb,0x13, 0xcb,0xb7,0x0f,
|
||||
0xbb,0xa7,0x0f, 0xab,0x97,0x0b, 0x9b,0x83,0x07, 0x8b,0x73,0x07,
|
||||
0x7b,0x63,0x07, 0x6b,0x53,0x00, 0x5b,0x47,0x00, 0x4b,0x37,0x00,
|
||||
0x3b,0x2b,0x00, 0x2b,0x1f,0x00, 0x1b,0x0f,0x00, 0x0b,0x07,0x00,
|
||||
0x00,0x00,0xff, 0x0b,0x0b,0xef, 0x13,0x13,0xdf, 0x1b,0x1b,0xcf,
|
||||
0x23,0x23,0xbf, 0x2b,0x2b,0xaf, 0x2f,0x2f,0x9f, 0x2f,0x2f,0x8f,
|
||||
0x2f,0x2f,0x7f, 0x2f,0x2f,0x6f, 0x2f,0x2f,0x5f, 0x2b,0x2b,0x4f,
|
||||
0x23,0x23,0x3f, 0x1b,0x1b,0x2f, 0x13,0x13,0x1f, 0x0b,0x0b,0x0f,
|
||||
0x2b,0x00,0x00, 0x3b,0x00,0x00, 0x4b,0x07,0x00, 0x5f,0x07,0x00,
|
||||
0x6f,0x0f,0x00, 0x7f,0x17,0x07, 0x93,0x1f,0x07, 0xa3,0x27,0x0b,
|
||||
0xb7,0x33,0x0f, 0xc3,0x4b,0x1b, 0xcf,0x63,0x2b, 0xdb,0x7f,0x3b,
|
||||
0xe3,0x97,0x4f, 0xe7,0xab,0x5f, 0xef,0xbf,0x77, 0xf7,0xd3,0x8b,
|
||||
0xa7,0x7b,0x3b, 0xb7,0x9b,0x37, 0xc7,0xc3,0x37, 0xe7,0xe3,0x57,
|
||||
0x7f,0xbf,0xff, 0xab,0xe7,0xff, 0xd7,0xff,0xff, 0x67,0x00,0x00,
|
||||
0x8b,0x00,0x00, 0xb3,0x00,0x00, 0xd7,0x00,0x00, 0xff,0x00,0x00,
|
||||
0xff,0xf3,0x93, 0xff,0xf7,0xc7, 0xff,0xff,0xff, 0x9f,0x5b,0x53
|
||||
};
|
||||
|
||||
/*
|
||||
=============
|
||||
LoadMIP
|
||||
=============
|
||||
*/
|
||||
|
||||
Image* LoadMIPBuff(byte* buffer)
|
||||
{
|
||||
byte *buf_p;
|
||||
int palettelength;
|
||||
unsigned long mipdatasize;
|
||||
int columns, rows, numPixels;
|
||||
byte *pixbuf;
|
||||
int i;
|
||||
byte *loadedpalette;
|
||||
const byte *palette;
|
||||
|
||||
loadedpalette = 0;
|
||||
|
||||
PointerInputStream inputStream(buffer);
|
||||
|
||||
inputStream.seek(MIP_NAME_LENGTH);
|
||||
columns = istream_read_int32_le(inputStream);
|
||||
rows = istream_read_int32_le(inputStream);
|
||||
int offset = istream_read_int32_le(inputStream);
|
||||
|
||||
if(std::size_t(columns) > 65536 && std::size_t(rows) > 65536)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
mipdatasize = GET_MIP_DATA_SIZE(columns, rows);
|
||||
|
||||
palettelength = vfsLoadFile ("gfx/palette.lmp", (void **) &loadedpalette);
|
||||
if (palettelength == 768)
|
||||
palette = loadedpalette;
|
||||
else
|
||||
{
|
||||
loadedpalette = 0;
|
||||
palette = quakepalette;
|
||||
}
|
||||
|
||||
buf_p = buffer + offset;
|
||||
|
||||
numPixels = columns * rows;
|
||||
|
||||
RGBAImage* image = new RGBAImage(columns, rows);
|
||||
|
||||
//Sys_Printf("lpMip->width = %i, lpMip->height = %i, lpMip->offsets[0] = %i, lpMip->offsets[1] = %i, lpMip->offsets[2] = %i, lpMip->offsets[3] = %i, numPixels = %i\n", lpMip->width, lpMip->height, lpMip->offsets[0], lpMip->offsets[1], lpMip->offsets[2], lpMip->offsets[3], numPixels);
|
||||
//for (i = 0; i < sizeof(*lpMip); i++)
|
||||
// Sys_Printf("%02x", (int) ((unsigned char *)lpMip)[i]);
|
||||
|
||||
pixbuf = image->getRGBAPixels();
|
||||
|
||||
for (i = 0; i < numPixels; i++)
|
||||
{
|
||||
int palIndex = *buf_p++;
|
||||
*pixbuf++ = palette[palIndex*3];
|
||||
*pixbuf++ = palette[palIndex*3+1];
|
||||
*pixbuf++ = palette[palIndex*3+2];
|
||||
*pixbuf++ = 0xff;
|
||||
}
|
||||
|
||||
if (loadedpalette != 0)
|
||||
vfsFreeFile(loadedpalette);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
Image* LoadMIP(ArchiveFile& file)
|
||||
{
|
||||
ScopedArchiveBuffer buffer(file);
|
||||
return LoadMIPBuff( buffer.buffer );
|
||||
}
|
||||
31
plugins/imagehl/mip.h
Normal file
31
plugins/imagehl/mip.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined (INCLUDED_MIP_H)
|
||||
#define INCLUDED_MIP_H
|
||||
|
||||
class Image;
|
||||
class ArchiveFile;
|
||||
|
||||
Image* LoadMIP(ArchiveFile& file);
|
||||
|
||||
#endif
|
||||
|
||||
229
plugins/imagehl/sprite.cpp
Normal file
229
plugins/imagehl/sprite.cpp
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// by Hydra - hydra@hydras-world.com
|
||||
|
||||
#include "sprite.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
#include "ifilesystem.h"
|
||||
|
||||
#include "imagelib.h"
|
||||
|
||||
/*
|
||||
============================================================================
|
||||
|
||||
IDSP IMAGE (.spr files)
|
||||
|
||||
Some code copied straight from the Q1 source, also used the HalfLife SDK as
|
||||
a reference.
|
||||
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
|
||||
typedef enum { SPR_SINGLE=0, SPR_GROUP } spriteframetype_t;
|
||||
|
||||
typedef struct dspriteheader_s {
|
||||
int ident;
|
||||
int version;
|
||||
} dspriteheader_t;
|
||||
|
||||
// Quake1
|
||||
typedef struct {
|
||||
int type;
|
||||
float boundingradius;
|
||||
int width;
|
||||
int height;
|
||||
int numframes;
|
||||
float beamlength;
|
||||
synctype_t synctype;
|
||||
} dspritev1_t;
|
||||
|
||||
// Halflife
|
||||
typedef struct {
|
||||
int type;
|
||||
int texFormat;
|
||||
float boundingradius;
|
||||
int width;
|
||||
int height;
|
||||
int numframes;
|
||||
float beamlength;
|
||||
synctype_t synctype;
|
||||
} dspritev2_t;
|
||||
|
||||
typedef struct {
|
||||
int origin[2];
|
||||
int width;
|
||||
int height;
|
||||
} dspriteframe_t;
|
||||
|
||||
typedef struct {
|
||||
short type;
|
||||
} dspriteframetype_t;
|
||||
|
||||
/*
|
||||
typedef struct {
|
||||
byte rgb[256][3];
|
||||
} dpalette_t;
|
||||
*/
|
||||
|
||||
#define IDSPRITEHEADER (('P'<<24)+('S'<<16)+('D'<<8)+'I')
|
||||
// little-endian "IDSP"
|
||||
|
||||
/*
|
||||
=============
|
||||
LoadIDSP
|
||||
=============
|
||||
*/
|
||||
|
||||
Image* LoadIDSPBuff(byte *buffer)
|
||||
{
|
||||
byte *buf_p;
|
||||
int columns, rows, numPixels;
|
||||
byte *pixbuf;
|
||||
|
||||
int row, column;
|
||||
byte *palette;
|
||||
unsigned char red, green, blue, alphabyte;
|
||||
|
||||
dspriteheader_t *header;
|
||||
dspritev1_t *pinv1;
|
||||
dspritev2_t *pinv2;
|
||||
dspriteframetype_t *pframetype;
|
||||
int version;
|
||||
int numframes;
|
||||
dspriteframe_t *spriteframe;
|
||||
|
||||
header = (dspriteheader_t *)buffer;
|
||||
|
||||
if (header->ident != IDSPRITEHEADER)
|
||||
{
|
||||
globalErrorStream() << "WARNING: IDSP file has wrong header\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
version = header->version;
|
||||
if (version != 1 && version != 2 )
|
||||
{
|
||||
globalErrorStream() << "WARNING: IDSP file has wrong version number "
|
||||
"(" << version << " should be 1 or 2)\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// initialise variables depending on the sprite version.
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
pinv1 = (dspritev1_t *)(header+1);
|
||||
numframes = pinv1->numframes;
|
||||
columns = pinv1->width;
|
||||
rows = pinv1->height;
|
||||
pframetype = (dspriteframetype_t *)(pinv1 + 1);
|
||||
break;
|
||||
case 2:
|
||||
pinv2 = (dspritev2_t *)(header+1);
|
||||
numframes = pinv2->numframes;
|
||||
columns = pinv2->width;
|
||||
rows = pinv2->height;
|
||||
pframetype = (dspriteframetype_t *)(pinv2 + 1);
|
||||
break;
|
||||
default:
|
||||
globalErrorStream() << "WARNING: IDSP file has unsupported version\n";
|
||||
return 0;
|
||||
}
|
||||
if (numframes > 1)
|
||||
globalErrorStream() << "WARNING: IDSP file has multiple frames, only the first frame will be used.\n";
|
||||
|
||||
// palette = buffer+mipdatasize+2;
|
||||
// buf_p = buffer+lpMip->offsets[0];
|
||||
|
||||
numPixels = columns * rows;
|
||||
|
||||
RGBAImage* image = new RGBAImage(columns, rows);
|
||||
|
||||
#ifdef DEBUG
|
||||
frametype = spriteframetype_t(pframetype->type);
|
||||
if (frametype == SPR_SINGLE)
|
||||
{
|
||||
globalOutputStream() << "Single Frame\n";
|
||||
}
|
||||
else if (frametype == SPR_GROUP)
|
||||
{
|
||||
globalOutputStream() << "Group of Frames\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
globalOutputStream() << "Bleh!\n"; // <-- we always get this, wtf!
|
||||
}
|
||||
#endif
|
||||
|
||||
palette = (byte *)(pframetype+1);
|
||||
spriteframe = (dspriteframe_t *)(palette + (256*3) + 4); // what are those 4 extra bytes ? what's missing ?
|
||||
buf_p = (byte *)(spriteframe + 1);
|
||||
|
||||
for (row = 0; row < rows; row++)
|
||||
{
|
||||
pixbuf = image->getRGBAPixels() + row * columns * 4;
|
||||
|
||||
for (column = 0; column < columns; column++)
|
||||
{
|
||||
int palIndex;
|
||||
|
||||
palIndex = *buf_p++;
|
||||
|
||||
red = *(palette+(palIndex*3));
|
||||
green = *(palette+(palIndex*3)+1);
|
||||
blue = *(palette+(palIndex*3)+2);
|
||||
|
||||
// HalfLife engine makes pixels that are BLUE transparent. (RGB = 0x0000FF)
|
||||
// So show them that way in the editor.
|
||||
if (blue == 0xff && red == 0x00 && green == 0x00)
|
||||
{
|
||||
alphabyte = 0xff; //FIXME: backwards? (so sprite models to render correctly)
|
||||
blue = 0x00; // don't set the resulting pixel to blue
|
||||
}
|
||||
else
|
||||
{
|
||||
alphabyte = 0x00; //FIXME: backwards? (so sprite models to render correctly)
|
||||
}
|
||||
|
||||
*pixbuf++ = red;
|
||||
*pixbuf++ = green;
|
||||
*pixbuf++ = blue;
|
||||
|
||||
*pixbuf++ = alphabyte;
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
Image* LoadIDSP(ArchiveFile& file)
|
||||
{
|
||||
ScopedArchiveBuffer buffer(file);
|
||||
return LoadIDSPBuff( buffer.buffer );
|
||||
}
|
||||
31
plugins/imagehl/sprite.h
Normal file
31
plugins/imagehl/sprite.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined (INCLUDED_SPRITE_H)
|
||||
#define INCLUDED_SPRITE_H
|
||||
|
||||
class Image;
|
||||
class ArchiveFile;
|
||||
|
||||
Image* LoadIDSP(ArchiveFile& file);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user