Implemented basic Image.

This commit is contained in:
Angelo Papenhoff 2014-12-25 16:02:57 +01:00
parent 1951d063b4
commit 86decdafd5
3 changed files with 87 additions and 1 deletions

View File

@ -7,7 +7,7 @@ BUILDDIR=build-$(BUILD)
SRCDIR=src SRCDIR=src
SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\ SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\
geometry.cpp plugins.cpp ps2.cpp\ geometry.cpp plugins.cpp ps2.cpp\
ogl.cpp) ogl.cpp image.cpp)
OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC)) OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC))
DEP := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.d,$(SRC)) DEP := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.d,$(SRC))
CFLAGS=-Wall -Wextra -g $(BUILDDEF) #-Wno-parentheses #-Wconversion CFLAGS=-Wall -Wextra -g $(BUILDDEF) #-Wno-parentheses #-Wconversion

69
src/image.cpp Normal file
View File

@ -0,0 +1,69 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <fstream>
#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;
}
}

View File

@ -8,6 +8,23 @@ struct Object
void *parent; 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 // TODO: raster, link into texdict
struct Texture : PluginBase<Texture> struct Texture : PluginBase<Texture>
{ {