From 86decdafd51edb8987e262ebf6bf8a49f38bc593 Mon Sep 17 00:00:00 2001 From: Angelo Papenhoff Date: Thu, 25 Dec 2014 16:02:57 +0100 Subject: [PATCH] Implemented basic Image. --- Makefile | 2 +- src/image.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ src/rwobjects.h | 17 ++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/image.cpp diff --git a/Makefile b/Makefile index 603f2a1..4d4f4cf 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ BUILDDIR=build-$(BUILD) SRCDIR=src SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\ geometry.cpp plugins.cpp ps2.cpp\ - ogl.cpp) + ogl.cpp image.cpp) OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC)) DEP := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.d,$(SRC)) CFLAGS=-Wall -Wextra -g $(BUILDDEF) #-Wno-parentheses #-Wconversion diff --git a/src/image.cpp b/src/image.cpp new file mode 100644 index 0000000..3f6a94b --- /dev/null +++ b/src/image.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include + +#include +#include + +#include "rwbase.h" +#include "rwplugin.h" +#include "rwobjects.h" + +namespace Rw { + +Image::Image(int32 width, int32 height, int32 depth) +{ + this->flags = 0; + this->width = width; + this->height = height; + this->depth = depth; + this->stride = 0; + this->pixels = NULL; + this->palette = NULL; +} + +Image::~Image(void) +{ + this->free(); +} + +void +Image::allocate(void) +{ + if(this->pixels == NULL){ + this->pixels = new uint8[this->width*this->height* + (this->depth==4) ? 1 : this->depth/8]; + this->flags |= 1; + } + if(this->palette == NULL){ + if(this->depth == 4 || this->depth == 8) + this->palette = new uint8[this->depth == 4 ? 16 : 256]; + this->flags |= 2; + } +} + +void +Image::free(void) +{ + if(this->flags&1) + delete[] this->pixels; + if(this->flags&2) + delete[] this->palette; +} + +void +Image::setPixels(uint8 *pixels) +{ + this->pixels = pixels; + this->flags |= 1; +} + +void +Image::setPalette(uint8 *palette) +{ + this->palette = palette; + this->flags |= 2; +} + +} diff --git a/src/rwobjects.h b/src/rwobjects.h index 065216b..7e7caa7 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -8,6 +8,23 @@ struct Object void *parent; }; +struct Image +{ + int32 flags; + int32 width, height; + int32 depth; + int32 stride; + uint8 *pixels; + uint8 *palette; + + Image(int32 width, int32 height, int32 depth); + ~Image(void); + void allocate(void); + void free(void); + void setPixels(uint8 *pixels); + void setPalette(uint8 *palette); +}; + // TODO: raster, link into texdict struct Texture : PluginBase {