- added windows project files

This commit is contained in:
quiret 2015-05-31 11:59:47 +02:00
parent 652c82424a
commit d03c22dcd6
3 changed files with 603 additions and 483 deletions

View File

@ -0,0 +1,22 @@

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", "librw_2013.vcxproj", "{44700D30-55D1-4D17-917C-5BF474F322C4}"
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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

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