mirror of https://github.com/aap/librw.git
Implemented basic Image.
This commit is contained in:
parent
1951d063b4
commit
86decdafd5
2
Makefile
2
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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Texture>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue