Merge pull request #1 from quiret/master

Windows VS2013 build files + GCC fix
This commit is contained in:
aap 2015-06-10 21:59:23 +02:00
commit aff3dd5a0c
4 changed files with 714 additions and 483 deletions

View File

@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "librw_2013", "librw_2013.vcxproj", "{44700D30-55D1-4D17-917C-5BF474F322C4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dffwrite", "..\..\various\dffwrite\dffwrite_2013.vcxproj", "{FD03F2BD-125B-4D3C-809D-420D8DABEB5B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{44700D30-55D1-4D17-917C-5BF474F322C4}.Debug|Win32.ActiveCfg = Debug|Win32
{44700D30-55D1-4D17-917C-5BF474F322C4}.Debug|Win32.Build.0 = Debug|Win32
{44700D30-55D1-4D17-917C-5BF474F322C4}.Release|Win32.ActiveCfg = Release|Win32
{44700D30-55D1-4D17-917C-5BF474F322C4}.Release|Win32.Build.0 = Release|Win32
{FD03F2BD-125B-4D3C-809D-420D8DABEB5B}.Debug|Win32.ActiveCfg = Debug|Win32
{FD03F2BD-125B-4D3C-809D-420D8DABEB5B}.Debug|Win32.Build.0 = Debug|Win32
{FD03F2BD-125B-4D3C-809D-420D8DABEB5B}.Release|Win32.ActiveCfg = Release|Win32
{FD03F2BD-125B-4D3C-809D-420D8DABEB5B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{44700D30-55D1-4D17-917C-5BF474F322C4}</ProjectGuid>
<RootNamespace>win32_2013</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetName>librw_d_2013</TargetName>
<OutDir>$(ProjectDir)..\..\lib\</OutDir>
<IntDir>$(ProjectDir)..\..\obj\win32_$(Configuration)_2013\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetName>librw_2013</TargetName>
<OutDir>$(ProjectDir)..\..\lib\</OutDir>
<IntDir>$(ProjectDir)..\..\obj\win32_$(Configuration)_2013\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\clump.cpp" />
<ClCompile Include="..\..\src\geometry.cpp" />
<ClCompile Include="..\..\src\gtaplg.cpp" />
<ClCompile Include="..\..\src\image.cpp" />
<ClCompile Include="..\..\src\ogl.cpp" />
<ClCompile Include="..\..\src\plugins.cpp" />
<ClCompile Include="..\..\src\ps2.cpp" />
<ClCompile Include="..\..\src\rwbase.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\rw.h" />
<ClInclude Include="..\..\src\gtaplg.h" />
<ClInclude Include="..\..\src\rwbase.h" />
<ClInclude Include="..\..\src\rwobjects.h" />
<ClInclude Include="..\..\src\rwogl.h" />
<ClInclude Include="..\..\src\rwplugin.h" />
<ClInclude Include="..\..\src\rwps2.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,483 +1,489 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
#include <new> #include <new>
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
#include "rwobjects.h" #include "rwobjects.h"
using namespace std; #ifdef __linux__
#define PACKED_STRUCT __attribute__((__packed__))
namespace rw { #else
#define PACKED_STRUCT
// #endif
// TexDictionary
// using namespace std;
TexDictionary *currentTexDictionary; namespace rw {
TexDictionary::TexDictionary(void) //
{ // TexDictionary
this->first = NULL; //
}
TexDictionary *currentTexDictionary;
void
TexDictionary::add(Texture *tex) TexDictionary::TexDictionary(void)
{ {
tex->next = this->first; this->first = NULL;
this->first = tex; }
}
void
Texture* TexDictionary::add(Texture *tex)
TexDictionary::find(const char *name) {
{ tex->next = this->first;
for(Texture *tex = this->first; tex; tex = tex->next) this->first = tex;
if(strncmp(tex->name, name, 32) == 0) }
return tex;
return NULL; Texture*
} TexDictionary::find(const char *name)
{
// for(Texture *tex = this->first; tex; tex = tex->next)
// Texture if(strncmp(tex->name, name, 32) == 0)
// return tex;
return NULL;
Texture::Texture(void) }
{
memset(this->name, 0, 32); //
memset(this->mask, 0, 32); // Texture
this->filterAddressing = (WRAP << 12) | (WRAP << 8) | NEAREST; //
this->raster = NULL;
this->refCount = 1; Texture::Texture(void)
this->next = NULL; {
this->constructPlugins(); memset(this->name, 0, 32);
} memset(this->mask, 0, 32);
this->filterAddressing = (WRAP << 12) | (WRAP << 8) | NEAREST;
Texture::~Texture(void) this->raster = NULL;
{ this->refCount = 1;
this->destructPlugins(); this->next = NULL;
} this->constructPlugins();
}
void
Texture::decRef(void) Texture::~Texture(void)
{ {
this->refCount--; this->destructPlugins();
if(this->refCount) }
delete this;
} void
Texture::decRef(void)
// TODO: do this properly, pretty ugly right now {
Texture* this->refCount--;
Texture::read(const char *name, const char *mask) if(this->refCount)
{ delete this;
(void)mask; }
Raster *raster = NULL;
Texture *tex; // TODO: do this properly, pretty ugly right now
Texture*
if(currentTexDictionary && (tex = currentTexDictionary->find(name))) Texture::read(const char *name, const char *mask)
return tex; {
tex = new Texture; (void)mask;
strncpy(tex->name, name, 32); Raster *raster = NULL;
strncpy(tex->mask, mask, 32); Texture *tex;
char *n = (char*)malloc(strlen(name) + 5);
strcpy(n, name); if(currentTexDictionary && (tex = currentTexDictionary->find(name)))
strcat(n, ".tga"); return tex;
Image *img = readTGA(n); tex = new Texture;
free(n); strncpy(tex->name, name, 32);
if(img){ strncpy(tex->mask, mask, 32);
raster = Raster::createFromImage(img); char *n = (char*)malloc(strlen(name) + 5);
delete img; strcpy(n, name);
} strcat(n, ".tga");
tex->raster = raster; Image *img = readTGA(n);
if(currentTexDictionary) free(n);
currentTexDictionary->add(tex); if(img){
return tex; raster = Raster::createFromImage(img);
} delete img;
}
Texture* tex->raster = raster;
Texture::streamRead(Stream *stream) if(currentTexDictionary)
{ currentTexDictionary->add(tex);
uint32 length; return tex;
char name[32], mask[32]; }
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
uint32 filterAddressing = stream->readU16(); Texture*
// TODO: what is this? (mipmap? i think) Texture::streamRead(Stream *stream)
stream->seek(2); {
uint32 length;
assert(findChunk(stream, ID_STRING, &length, NULL)); char name[32], mask[32];
stream->read(name, length); assert(findChunk(stream, ID_STRUCT, NULL, NULL));
uint32 filterAddressing = stream->readU16();
assert(findChunk(stream, ID_STRING, &length, NULL)); // TODO: what is this? (mipmap? i think)
stream->read(mask, length); stream->seek(2);
Texture *tex = Texture::read(name, mask); assert(findChunk(stream, ID_STRING, &length, NULL));
tex->refCount++; stream->read(name, length);
tex->filterAddressing = filterAddressing;
assert(findChunk(stream, ID_STRING, &length, NULL));
tex->streamReadPlugins(stream); stream->read(mask, length);
return tex; Texture *tex = Texture::read(name, mask);
} tex->refCount++;
tex->filterAddressing = filterAddressing;
bool
Texture::streamWrite(Stream *stream) tex->streamReadPlugins(stream);
{
int size; return tex;
writeChunkHeader(stream, ID_TEXTURE, this->streamGetSize()); }
writeChunkHeader(stream, ID_STRUCT, 4);
stream->writeU32(this->filterAddressing); bool
Texture::streamWrite(Stream *stream)
// TODO: length can't be > 32 {
size = strlen(this->name)+4 & ~3; int size;
writeChunkHeader(stream, ID_STRING, size); writeChunkHeader(stream, ID_TEXTURE, this->streamGetSize());
stream->write(this->name, size); writeChunkHeader(stream, ID_STRUCT, 4);
stream->writeU32(this->filterAddressing);
size = strlen(this->mask)+4 & ~3;
writeChunkHeader(stream, ID_STRING, size); // TODO: length can't be > 32
stream->write(this->mask, size); size = strlen(this->name)+4 & ~3;
writeChunkHeader(stream, ID_STRING, size);
this->streamWritePlugins(stream); stream->write(this->name, size);
return true;
} size = strlen(this->mask)+4 & ~3;
writeChunkHeader(stream, ID_STRING, size);
uint32 stream->write(this->mask, size);
Texture::streamGetSize(void)
{ this->streamWritePlugins(stream);
uint32 size = 0; return true;
size += 12 + 4; }
size += 12 + 12;
size += strlen(this->name)+4 & ~3; uint32
size += strlen(this->mask)+4 & ~3; Texture::streamGetSize(void)
size += 12 + this->streamGetPluginSize(); {
return size; uint32 size = 0;
} size += 12 + 4;
size += 12 + 12;
// size += strlen(this->name)+4 & ~3;
// Image size += strlen(this->mask)+4 & ~3;
// size += 12 + this->streamGetPluginSize();
return size;
Image::Image(int32 width, int32 height, int32 depth) }
{
this->flags = 0; //
this->width = width; // Image
this->height = height; //
this->depth = depth;
this->stride = 0; Image::Image(int32 width, int32 height, int32 depth)
this->pixels = NULL; {
this->palette = NULL; this->flags = 0;
} this->width = width;
this->height = height;
Image::~Image(void) this->depth = depth;
{ this->stride = 0;
this->free(); this->pixels = NULL;
} this->palette = NULL;
}
void
Image::allocate(void) Image::~Image(void)
{ {
if(this->pixels == NULL){ this->free();
this->stride = this->width*(this->depth==4 ? 1 : this->depth/8); }
this->pixels = new uint8[this->stride*this->height];
this->flags |= 1; void
} Image::allocate(void)
if(this->palette == NULL){ {
if(this->depth == 4 || this->depth == 8) if(this->pixels == NULL){
this->palette = new uint8[(this->depth==4? 16 : 256)*4]; this->stride = this->width*(this->depth==4 ? 1 : this->depth/8);
this->flags |= 2; this->pixels = new uint8[this->stride*this->height];
} this->flags |= 1;
} }
if(this->palette == NULL){
void if(this->depth == 4 || this->depth == 8)
Image::free(void) this->palette = new uint8[(this->depth==4? 16 : 256)*4];
{ this->flags |= 2;
if(this->flags&1) }
delete[] this->pixels; }
if(this->flags&2)
delete[] this->palette; void
} Image::free(void)
{
void if(this->flags&1)
Image::setPixels(uint8 *pixels) delete[] this->pixels;
{ if(this->flags&2)
this->pixels = pixels; delete[] this->palette;
this->flags |= 1; }
}
void
void Image::setPixels(uint8 *pixels)
Image::setPalette(uint8 *palette) {
{ this->pixels = pixels;
this->palette = palette; this->flags |= 1;
this->flags |= 2; }
}
void
static char *searchPaths = NULL; Image::setPalette(uint8 *palette)
int numSearchPaths = 0; {
this->palette = palette;
void this->flags |= 2;
Image::setSearchPath(const char *path) }
{
char *p, *end; static char *searchPaths = NULL;
::free(searchPaths); int numSearchPaths = 0;
numSearchPaths = 0;
if(path) void
searchPaths = p = strdup(path); Image::setSearchPath(const char *path)
else{ {
searchPaths = NULL; char *p, *end;
return; ::free(searchPaths);
} numSearchPaths = 0;
while(p && *p){ if(path)
end = strchr(p, ';'); searchPaths = p = strdup(path);
if(end) else{
*end++ = '\0'; searchPaths = NULL;
numSearchPaths++; return;
p = end; }
} while(p && *p){
} end = strchr(p, ';');
if(end)
void *end++ = '\0';
Image::printSearchPath(void) numSearchPaths++;
{ p = end;
char *p = searchPaths; }
for(int i = 0; i < numSearchPaths; i++){ }
printf("%s\n", p);
p += strlen(p) + 1; void
} Image::printSearchPath(void)
} {
char *p = searchPaths;
char* for(int i = 0; i < numSearchPaths; i++){
Image::getFilename(const char *name) printf("%s\n", p);
{ p += strlen(p) + 1;
FILE *f; }
char *s, *p = searchPaths; }
int len = strlen(name)+1;
if(numSearchPaths == 0){ char*
f = fopen(name, "r"); Image::getFilename(const char *name)
if(f){ {
fclose(f); FILE *f;
printf("found %s\n", name); char *s, *p = searchPaths;
return strdup(name); int len = strlen(name)+1;
} if(numSearchPaths == 0){
return NULL; f = fopen(name, "r");
}else if(f){
for(int i = 0; i < numSearchPaths; i++){ fclose(f);
s = (char*)malloc(strlen(p)+len); printf("found %s\n", name);
strcpy(s, p); return strdup(name);
strcat(s, name); }
f = fopen(s, "r"); return NULL;
if(f){ }else
fclose(f); for(int i = 0; i < numSearchPaths; i++){
printf("found %s\n", name); s = (char*)malloc(strlen(p)+len);
return s; strcpy(s, p);
} strcat(s, name);
::free(s); f = fopen(s, "r");
p += strlen(p) + 1; if(f){
} fclose(f);
return NULL; printf("found %s\n", name);
} return s;
}
// ::free(s);
// TGA I/O p += strlen(p) + 1;
// }
return NULL;
#ifndef RW_PS2 }
#pragma pack(push)
#pragma pack(1) //
#endif // TGA I/O
struct __attribute__((__packed__)) TGAHeader //
{
int8 IDlen; #ifndef RW_PS2
int8 colorMapType; #pragma pack(push)
int8 imageType; #pragma pack(1)
int16 colorMapOrigin; #endif
int16 colorMapLength; struct PACKED_STRUCT TGAHeader
int8 colorMapDepth; {
int16 xOrigin, yOrigin; int8 IDlen;
int16 width, height; int8 colorMapType;
uint8 depth; int8 imageType;
uint8 descriptor; int16 colorMapOrigin;
}; int16 colorMapLength;
#ifndef RW_PS2 int8 colorMapDepth;
#pragma pack(push) int16 xOrigin, yOrigin;
#endif int16 width, height;
uint8 depth;
Image* uint8 descriptor;
readTGA(const char *afilename) };
{ #ifndef RW_PS2
TGAHeader header; #pragma pack(push)
Image *image; #endif
char *filename;
int depth = 0, palDepth = 0; Image*
filename = Image::getFilename(afilename); readTGA(const char *afilename)
if(filename == NULL) {
return NULL; TGAHeader header;
StreamFile file; Image *image;
assert(file.open(filename, "rb") != NULL); char *filename;
free(filename); int depth = 0, palDepth = 0;
file.read(&header, sizeof(header)); filename = Image::getFilename(afilename);
if(filename == NULL)
assert(header.imageType == 1 || header.imageType == 2); return NULL;
file.seek(header.IDlen); StreamFile file;
if(header.colorMapType){ assert(file.open(filename, "rb") != NULL);
assert(header.colorMapOrigin == 0); free(filename);
depth = (header.colorMapLength <= 16) ? 4 : 8; file.read(&header, sizeof(header));
palDepth = header.colorMapDepth;
assert(palDepth == 24 || palDepth == 32); assert(header.imageType == 1 || header.imageType == 2);
}else{ file.seek(header.IDlen);
depth = header.depth; if(header.colorMapType){
assert(depth == 24 || depth == 32); assert(header.colorMapOrigin == 0);
} depth = (header.colorMapLength <= 16) ? 4 : 8;
palDepth = header.colorMapDepth;
image = new Image(header.width, header.height, depth); assert(palDepth == 24 || palDepth == 32);
image->allocate(); }else{
uint8 *palette = header.colorMapType ? image->palette : NULL; depth = header.depth;
uint8 (*color)[4] = NULL; assert(depth == 24 || depth == 32);
if(palette){ }
int maxlen = depth == 4 ? 16 : 256;
color = (uint8(*)[4])palette; image = new Image(header.width, header.height, depth);
int i; image->allocate();
for(i = 0; i < header.colorMapLength; i++){ uint8 *palette = header.colorMapType ? image->palette : NULL;
color[i][2] = file.readU8(); uint8 (*color)[4] = NULL;
color[i][1] = file.readU8(); if(palette){
color[i][0] = file.readU8(); int maxlen = depth == 4 ? 16 : 256;
color[i][3] = 0xFF; color = (uint8(*)[4])palette;
if(palDepth == 32) int i;
color[i][3] = file.readU8(); for(i = 0; i < header.colorMapLength; i++){
} color[i][2] = file.readU8();
for(; i < maxlen; i++){ color[i][1] = file.readU8();
color[i][0] = color[i][1] = color[i][2] = 0; color[i][0] = file.readU8();
color[i][3] = 0xFF; color[i][3] = 0xFF;
} if(palDepth == 32)
} color[i][3] = file.readU8();
}
uint8 *pixels = image->pixels; for(; i < maxlen; i++){
if(!(header.descriptor & 0x20)) color[i][0] = color[i][1] = color[i][2] = 0;
pixels += (image->height-1)*image->stride; color[i][3] = 0xFF;
for(int y = 0; y < image->height; y++){ }
uint8 *line = pixels; }
for(int x = 0; x < image->width; x++){
if(palette) uint8 *pixels = image->pixels;
*line++ = file.readU8(); if(!(header.descriptor & 0x20))
else{ pixels += (image->height-1)*image->stride;
line[2] = file.readU8(); for(int y = 0; y < image->height; y++){
line[1] = file.readU8(); uint8 *line = pixels;
line[0] = file.readU8(); for(int x = 0; x < image->width; x++){
line += 3; if(palette)
if(depth == 32) *line++ = file.readU8();
*line++ = file.readU8(); else{
} line[2] = file.readU8();
} line[1] = file.readU8();
pixels += (header.descriptor&0x20) ? line[0] = file.readU8();
image->stride : -image->stride; line += 3;
} if(depth == 32)
*line++ = file.readU8();
file.close(); }
return image; }
} pixels += (header.descriptor&0x20) ?
image->stride : -image->stride;
void }
writeTGA(Image *image, const char *filename)
{ file.close();
TGAHeader header; return image;
StreamFile file; }
assert(file.open(filename, "wb"));
header.IDlen = 0; void
header.imageType = image->palette != NULL ? 1 : 2; writeTGA(Image *image, const char *filename)
header.colorMapType = image->palette != NULL; {
header.colorMapOrigin = 0; TGAHeader header;
header.colorMapLength = image->depth == 4 ? 16 : StreamFile file;
image->depth == 8 ? 256 : 0; assert(file.open(filename, "wb"));
header.colorMapDepth = image->palette ? 32 : 0; header.IDlen = 0;
header.xOrigin = 0; header.imageType = image->palette != NULL ? 1 : 2;
header.yOrigin = 0; header.colorMapType = image->palette != NULL;
header.width = image->width; header.colorMapOrigin = 0;
header.height = image->height; header.colorMapLength = image->depth == 4 ? 16 :
header.depth = image->depth == 4 ? 8 : image->depth; image->depth == 8 ? 256 : 0;
header.descriptor = 0x20 | (image->depth == 32 ? 8 : 0); header.colorMapDepth = image->palette ? 32 : 0;
file.write(&header, sizeof(header)); header.xOrigin = 0;
header.yOrigin = 0;
uint8 *pixels = image->pixels; header.width = image->width;
uint8 *palette = header.colorMapType ? image->palette : NULL; header.height = image->height;
uint8 (*color)[4] = (uint8(*)[4])palette;; header.depth = image->depth == 4 ? 8 : image->depth;
if(palette) header.descriptor = 0x20 | (image->depth == 32 ? 8 : 0);
for(int i = 0; i < header.colorMapLength; i++){ file.write(&header, sizeof(header));
file.writeU8(color[i][2]);
file.writeU8(color[i][1]); uint8 *pixels = image->pixels;
file.writeU8(color[i][0]); uint8 *palette = header.colorMapType ? image->palette : NULL;
file.writeU8(color[i][3]); uint8 (*color)[4] = (uint8(*)[4])palette;;
} if(palette)
for(int i = 0; i < header.colorMapLength; i++){
for(int y = 0; y < image->height; y++){ file.writeU8(color[i][2]);
uint8 *line = pixels; file.writeU8(color[i][1]);
for(int x = 0; x < image->width; x++){ file.writeU8(color[i][0]);
if(palette) file.writeU8(color[i][3]);
file.writeU8(*line++); }
else{
file.writeU8(line[2]); for(int y = 0; y < image->height; y++){
file.writeU8(line[1]); uint8 *line = pixels;
file.writeU8(line[0]); for(int x = 0; x < image->width; x++){
line += 3; if(palette)
if(image->depth == 32) file.writeU8(*line++);
file.writeU8(*line++); else{
} file.writeU8(line[2]);
} file.writeU8(line[1]);
pixels += image->stride; file.writeU8(line[0]);
} line += 3;
file.close(); if(image->depth == 32)
} file.writeU8(*line++);
}
// }
// Raster pixels += image->stride;
// }
file.close();
Raster::Raster(void) }
{
this->type = 0; //
this->width = this->height = this->depth = this->stride = 0; // Raster
this->format = 0; //
this->texels = this->palette = NULL;
this->constructPlugins(); Raster::Raster(void)
} {
this->type = 0;
Raster::~Raster(void) this->width = this->height = this->depth = this->stride = 0;
{ this->format = 0;
this->destructPlugins(); this->texels = this->palette = NULL;
delete[] this->texels; this->constructPlugins();
delete[] this->palette; }
}
Raster::~Raster(void)
Raster* {
Raster::createFromImage(Image *image) this->destructPlugins();
{ delete[] this->texels;
Raster *raster = new Raster; delete[] this->palette;
raster->type = 4; }
raster->width = image->width;
raster->stride = image->stride; Raster*
raster->height = image->height; Raster::createFromImage(Image *image)
raster->depth = image->depth; {
raster->texels = raster->palette = NULL; Raster *raster = new Raster;
if(raster->depth == 32) raster->type = 4;
raster->format = Raster::C8888; raster->width = image->width;
else if(raster->depth == 24) raster->stride = image->stride;
raster->format = Raster::C888; raster->height = image->height;
else if(raster->depth == 16) raster->depth = image->depth;
raster->format = Raster::C1555; raster->texels = raster->palette = NULL;
else if(raster->depth == 8) if(raster->depth == 32)
raster->format = Raster::PAL8 | Raster::C8888; raster->format = Raster::C8888;
else if(raster->depth == 4) else if(raster->depth == 24)
raster->format = Raster::PAL4 | Raster::C8888; raster->format = Raster::C888;
else{ else if(raster->depth == 16)
delete raster; raster->format = Raster::C1555;
return NULL; else if(raster->depth == 8)
} raster->format = Raster::PAL8 | Raster::C8888;
raster->texels = new uint8[raster->stride*raster->height]; else if(raster->depth == 4)
memcpy(raster->texels, image->pixels, raster->stride*raster->height); raster->format = Raster::PAL4 | Raster::C8888;
if(image->palette){ else{
int size = raster->depth == 4 ? 16 : 256; delete raster;
raster->palette = new uint8[size*4]; return NULL;
memcpy(raster->palette, image->palette, size*4); }
} raster->texels = new uint8[raster->stride*raster->height];
return raster; memcpy(raster->texels, image->pixels, raster->stride*raster->height);
} if(image->palette){
int size = raster->depth == 4 ? 16 : 256;
} raster->palette = new uint8[size*4];
memcpy(raster->palette, image->palette, size*4);
}
return raster;
}
}

View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{FD03F2BD-125B-4D3C-809D-420D8DABEB5B}</ProjectGuid>
<RootNamespace>dffwrite</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(ProjectDir)..\..\bin\</OutDir>
<IntDir>$(ProjectDir)..\..\obj\dffwrite\win32_$(Configuration)_2013\</IntDir>
<TargetName>dffwrite_d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)..\..\bin\</OutDir>
<IntDir>$(ProjectDir)..\..\obj\dffwrite\win32_$(Configuration)_2013\</IntDir>
<TargetName>dffwrite</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)$(TargetName)_2013.pdb</ProgramDatabaseFile>
<ManifestFile>$(IntDir)$(TargetName)_2013$(TargetExt).intermediate.manifest</ManifestFile>
<AdditionalLibraryDirectories>..\..\lib\</AdditionalLibraryDirectories>
<AdditionalDependencies>librw_d_2013.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ProgramDatabaseFile>$(OutDir)$(TargetName)_2013.pdb</ProgramDatabaseFile>
<ManifestFile>$(IntDir)$(TargetName)_2013$(TargetExt).intermediate.manifest</ManifestFile>
<AdditionalLibraryDirectories>..\..\lib\</AdditionalLibraryDirectories>
<AdditionalDependencies>librw_2013.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\dffwrite.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\rw.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>