Replaced C++ streams in tga functions. ps2 test builds again.

This commit is contained in:
Angelo Papenhoff 2015-01-26 10:15:26 +01:00
parent d55e9ea43b
commit ad21deaf0f
4 changed files with 32 additions and 51 deletions

View File

@ -2,9 +2,7 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
#include <new>
#include <iostream>
#include <fstream>
#include "rwbase.h" #include "rwbase.h"
#include "rwplugin.h" #include "rwplugin.h"
@ -14,21 +12,6 @@ using namespace std;
namespace rw { namespace rw {
uint8
readUInt8(istream &rw)
{
uint8 tmp;
rw.read((char*)&tmp, sizeof(uint8));
return tmp;
}
uint32
writeUInt8(uint8 tmp, ostream &rw)
{
rw.write((char*)&tmp, sizeof(uint8));
return sizeof(uint8);
}
// //
// TexDictionary // TexDictionary
// //
@ -161,7 +144,6 @@ uint32
Texture::streamGetSize(void) Texture::streamGetSize(void)
{ {
uint32 size = 0; uint32 size = 0;
int strsize;
size += 12 + 4; size += 12 + 4;
size += 12 + 12; size += 12 + 12;
size += strlen(this->name)+4 & ~3; size += strlen(this->name)+4 & ~3;
@ -325,16 +307,16 @@ readTGA(const char *afilename)
Image *image; Image *image;
char *filename; char *filename;
int depth = 0, palDepth = 0; int depth = 0, palDepth = 0;
// TODO: open from image path
filename = Image::getFilename(afilename); filename = Image::getFilename(afilename);
if(filename == NULL) if(filename == NULL)
return NULL; return NULL;
ifstream file(filename, ios::binary); StreamFile file;
assert(file.open(filename, "rb") != NULL);
free(filename); free(filename);
file.read((char*)&header, sizeof(header)); file.read(&header, sizeof(header));
assert(header.imageType == 1 || header.imageType == 2); assert(header.imageType == 1 || header.imageType == 2);
file.seekg(header.IDlen, ios::cur); 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;
@ -354,12 +336,12 @@ readTGA(const char *afilename)
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] = readUInt8(file); color[i][2] = file.readU8();
color[i][1] = readUInt8(file); color[i][1] = file.readU8();
color[i][0] = readUInt8(file); color[i][0] = file.readU8();
color[i][3] = 0xFF; color[i][3] = 0xFF;
if(palDepth == 32) if(palDepth == 32)
color[i][3] = readUInt8(file); 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;
@ -374,14 +356,14 @@ readTGA(const char *afilename)
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++ = readUInt8(file); *line++ = file.readU8();
else{ else{
line[2] = readUInt8(file); line[2] = file.readU8();
line[1] = readUInt8(file); line[1] = file.readU8();
line[0] = readUInt8(file); line[0] = file.readU8();
line += 3; line += 3;
if(depth == 32) if(depth == 32)
*line++ = readUInt8(file); *line++ = file.readU8();
} }
} }
pixels += (header.descriptor&0x20) ? pixels += (header.descriptor&0x20) ?
@ -396,8 +378,8 @@ void
writeTGA(Image *image, const char *filename) writeTGA(Image *image, const char *filename)
{ {
TGAHeader header; TGAHeader header;
// TODO: open from image path StreamFile file;
ofstream file(filename, ios::binary); 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;
@ -411,31 +393,31 @@ writeTGA(Image *image, const char *filename)
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((char*)&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++){
writeUInt8(color[i][2], file); file.writeU8(color[i][2]);
writeUInt8(color[i][1], file); file.writeU8(color[i][1]);
writeUInt8(color[i][0], file); file.writeU8(color[i][0]);
writeUInt8(color[i][3], file); 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)
writeUInt8(*line++, file); file.writeU8(*line++);
else{ else{
writeUInt8(line[2], file); file.writeU8(line[2]);
writeUInt8(line[1], file); file.writeU8(line[1]);
writeUInt8(line[0], file); file.writeU8(line[0]);
line += 3; line += 3;
if(image->depth == 32) if(image->depth == 32)
writeUInt8(*line++, file); file.writeU8(*line++);
} }
} }
pixels += image->stride; pixels += image->stride;

View File

@ -222,7 +222,7 @@ writeMesh(Stream *stream, int32, void *object, int32, int32)
} }
static int32 static int32
getSizeMesh(void *object, int32) getSizeMesh(void *object, int32, int32)
{ {
Geometry *geo = (Geometry*)object; Geometry *geo = (Geometry*)object;
if(geo->meshHeader == NULL) if(geo->meshHeader == NULL)

View File

@ -53,7 +53,7 @@ public:
void close(void); void close(void);
uint32 write(const void *data, uint32 length); uint32 write(const void *data, uint32 length);
uint32 read(void *data, uint32 length); uint32 read(void *data, uint32 length);
void seek(int32 offset, int32 whence); void seek(int32 offset, int32 whence = 1);
uint32 tell(void); uint32 tell(void);
bool eof(void); bool eof(void);
StreamMemory *open(uint8 *data, uint32 length, uint32 capacity = 0); StreamMemory *open(uint8 *data, uint32 length, uint32 capacity = 0);
@ -71,7 +71,7 @@ public:
void close(void); void close(void);
uint32 write(const void *data, uint32 length); uint32 write(const void *data, uint32 length);
uint32 read(void *data, uint32 length); uint32 read(void *data, uint32 length);
void seek(int32 offset, int32 whence); void seek(int32 offset, int32 whence = 1);
uint32 tell(void); uint32 tell(void);
bool eof(void); bool eof(void);
StreamFile *open(const char *path, const char *mode); StreamFile *open(const char *path, const char *mode);

View File

@ -4,12 +4,10 @@ AS=ee-g++
LD=ee-g++ -v LD=ee-g++ -v
DVPAS=ee-dvp-as DVPAS=ee-dvp-as
LINK=-T$(PS2SDK)/ee/startup/linkfile $(PS2SDK)/ee/startup/crt0.o LINK=-T$(PS2SDK)/ee/startup/linkfile
#LINK=-T$(PS2SDK)/ee/startup/linkfile $(PS2DEV)/ee/lib/gcc-lib/ee/3.2.2/crti.o $(PS2DEV)/ee/lib/gcc-lib/ee/3.2.2/crtbegin.o $(PS2SDK)/ee/startup/crt0.o
LIBPATH=-L$(PS2SDK)/ee/lib LIBPATH=-L$(PS2SDK)/ee/lib
INCPATH=-I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I$(HOME)/src/librw INCPATH=-I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I$(HOME)/src/librw
LIBS=$(HOME)/src/librw/librw-ps2.a -lc -lc -lkernel -lmf # g++ throws one -lc away, why? (unless -nostdlib) LIBS=$(HOME)/src/librw/librw-ps2.a -lc -lc -lkernel -lmf # g++ throws one -lc away, why? (unless -nostdlib)
#LIBS=-nostdlib $(HOME)/src/librw/librw-ps2.a -lc -lkernel -lmf -lstdc++ -lm -lc -lgcc -lgcc $(PS2DEV)/ee/lib/gcc-lib/ee/3.2.2/crtend.o $(PS2DEV)/ee/lib/gcc-lib/ee/3.2.2/crtn.o
CFLAGS = -c -Wall -nostdlib -fno-common -DPS2_EE $(INCPATH) CFLAGS = -c -Wall -nostdlib -fno-common -DPS2_EE $(INCPATH)
ASFLAGS = -c -xassembler-with-cpp ASFLAGS = -c -xassembler-with-cpp
@ -22,7 +20,8 @@ HEADER=dma.h ee_regs.h gif.h gs.h mips_regs.h ps2.h math.h mesh.h
OBJ=$(C_SRC:.cpp=.o) $(S_SRC:.s=.o) vu.o defaultpipe.o skinpipe.o OBJ=$(C_SRC:.cpp=.o) $(S_SRC:.s=.o) vu.o defaultpipe.o skinpipe.o
$(OUT).elf: $(OBJ) $(HEADER) $(OUT).elf: $(OBJ) $(HEADER)
$(LD) $(LDFLAGS) $(LINK) $(OBJ) $(LIBS) -o $(OUT).elf $(LD) $(LDFLAGS) $(LINK) $(PS2SDK)/ee/startup/crt0.o \
$(OBJ) $(LIBS) -o $(OUT).elf
.cpp.o: $(HEADER) .cpp.o: $(HEADER)
$(CXX) $(CFLAGS) $< -o $@ $(CXX) $(CFLAGS) $< -o $@