From ad21deaf0f723ffb5fc93435f062fbe9766dd9c2 Mon Sep 17 00:00:00 2001 From: Angelo Papenhoff Date: Mon, 26 Jan 2015 10:15:26 +0100 Subject: [PATCH] Replaced C++ streams in tga functions. ps2 test builds again. --- src/image.cpp | 70 +++++++++++++++++----------------------------- src/plugins.cpp | 2 +- src/rwbase.h | 4 +-- tests/ps2/Makefile | 7 ++--- 4 files changed, 32 insertions(+), 51 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index edbfac3..ce8e3a5 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -2,9 +2,7 @@ #include #include #include - -#include -#include +#include #include "rwbase.h" #include "rwplugin.h" @@ -14,21 +12,6 @@ using namespace std; 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 // @@ -161,7 +144,6 @@ uint32 Texture::streamGetSize(void) { uint32 size = 0; - int strsize; size += 12 + 4; size += 12 + 12; size += strlen(this->name)+4 & ~3; @@ -325,16 +307,16 @@ readTGA(const char *afilename) Image *image; char *filename; int depth = 0, palDepth = 0; - // TODO: open from image path filename = Image::getFilename(afilename); if(filename == NULL) return NULL; - ifstream file(filename, ios::binary); + StreamFile file; + assert(file.open(filename, "rb") != NULL); free(filename); - file.read((char*)&header, sizeof(header)); + file.read(&header, sizeof(header)); assert(header.imageType == 1 || header.imageType == 2); - file.seekg(header.IDlen, ios::cur); + file.seek(header.IDlen); if(header.colorMapType){ assert(header.colorMapOrigin == 0); depth = (header.colorMapLength <= 16) ? 4 : 8; @@ -354,12 +336,12 @@ readTGA(const char *afilename) color = (uint8(*)[4])palette; int i; for(i = 0; i < header.colorMapLength; i++){ - color[i][2] = readUInt8(file); - color[i][1] = readUInt8(file); - color[i][0] = readUInt8(file); + color[i][2] = file.readU8(); + color[i][1] = file.readU8(); + color[i][0] = file.readU8(); color[i][3] = 0xFF; if(palDepth == 32) - color[i][3] = readUInt8(file); + color[i][3] = file.readU8(); } for(; i < maxlen; i++){ color[i][0] = color[i][1] = color[i][2] = 0; @@ -374,14 +356,14 @@ readTGA(const char *afilename) uint8 *line = pixels; for(int x = 0; x < image->width; x++){ if(palette) - *line++ = readUInt8(file); + *line++ = file.readU8(); else{ - line[2] = readUInt8(file); - line[1] = readUInt8(file); - line[0] = readUInt8(file); + line[2] = file.readU8(); + line[1] = file.readU8(); + line[0] = file.readU8(); line += 3; if(depth == 32) - *line++ = readUInt8(file); + *line++ = file.readU8(); } } pixels += (header.descriptor&0x20) ? @@ -396,8 +378,8 @@ void writeTGA(Image *image, const char *filename) { TGAHeader header; - // TODO: open from image path - ofstream file(filename, ios::binary); + StreamFile file; + assert(file.open(filename, "wb")); header.IDlen = 0; header.imageType = image->palette != NULL ? 1 : 2; header.colorMapType = image->palette != NULL; @@ -411,31 +393,31 @@ writeTGA(Image *image, const char *filename) header.height = image->height; header.depth = image->depth == 4 ? 8 : image->depth; header.descriptor = 0x20 | (image->depth == 32 ? 8 : 0); - file.write((char*)&header, sizeof(header)); + file.write(&header, sizeof(header)); uint8 *pixels = image->pixels; uint8 *palette = header.colorMapType ? image->palette : NULL; uint8 (*color)[4] = (uint8(*)[4])palette;; if(palette) for(int i = 0; i < header.colorMapLength; i++){ - writeUInt8(color[i][2], file); - writeUInt8(color[i][1], file); - writeUInt8(color[i][0], file); - writeUInt8(color[i][3], file); + file.writeU8(color[i][2]); + file.writeU8(color[i][1]); + file.writeU8(color[i][0]); + file.writeU8(color[i][3]); } for(int y = 0; y < image->height; y++){ uint8 *line = pixels; for(int x = 0; x < image->width; x++){ if(palette) - writeUInt8(*line++, file); + file.writeU8(*line++); else{ - writeUInt8(line[2], file); - writeUInt8(line[1], file); - writeUInt8(line[0], file); + file.writeU8(line[2]); + file.writeU8(line[1]); + file.writeU8(line[0]); line += 3; if(image->depth == 32) - writeUInt8(*line++, file); + file.writeU8(*line++); } } pixels += image->stride; diff --git a/src/plugins.cpp b/src/plugins.cpp index 19f6b1f..3bc2a8c 100644 --- a/src/plugins.cpp +++ b/src/plugins.cpp @@ -222,7 +222,7 @@ writeMesh(Stream *stream, int32, void *object, int32, int32) } static int32 -getSizeMesh(void *object, int32) +getSizeMesh(void *object, int32, int32) { Geometry *geo = (Geometry*)object; if(geo->meshHeader == NULL) diff --git a/src/rwbase.h b/src/rwbase.h index 1d0c40f..5656699 100644 --- a/src/rwbase.h +++ b/src/rwbase.h @@ -53,7 +53,7 @@ public: void close(void); uint32 write(const 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); bool eof(void); StreamMemory *open(uint8 *data, uint32 length, uint32 capacity = 0); @@ -71,7 +71,7 @@ public: void close(void); uint32 write(const 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); bool eof(void); StreamFile *open(const char *path, const char *mode); diff --git a/tests/ps2/Makefile b/tests/ps2/Makefile index 3b94437..653a894 100755 --- a/tests/ps2/Makefile +++ b/tests/ps2/Makefile @@ -4,12 +4,10 @@ AS=ee-g++ LD=ee-g++ -v DVPAS=ee-dvp-as -LINK=-T$(PS2SDK)/ee/startup/linkfile $(PS2SDK)/ee/startup/crt0.o -#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 +LINK=-T$(PS2SDK)/ee/startup/linkfile LIBPATH=-L$(PS2SDK)/ee/lib 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=-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) 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 $(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) $(CXX) $(CFLAGS) $< -o $@