#include <image.hpp>
#ifdef TCOD_IMAGE_SUPPORT
TCODImage::TCODImage(const char *filename) : deleteData(true) {
data=(void *)TCOD_image_load(filename);
}
TCODImage::TCODImage(int width, int height) : deleteData(true) {
data=(void *)TCOD_image_new(width,height);
}
#ifdef TCOD_CONSOLE_SUPPORT
TCODImage::TCODImage(const TCODConsole *con) {
data=(void *)TCOD_image_from_console(con->data);
}
#endif
void TCODImage::clear(const TCODColor col) {
TCOD_color_t ccol;
ccol.r=col.r;
ccol.g=col.g;
ccol.b=col.b;
TCOD_image_clear(data,ccol);
}
void TCODImage::getSize(int *w,int *h) const {
TCOD_image_get_size(data,w,h);
}
TCODImage::~TCODImage() {
if ( deleteData ) TCOD_image_delete(data);
}
TCODColor TCODImage::getPixel(int x, int y) const {
return TCOD_image_get_pixel(data,x,y);
}
int TCODImage::getAlpha(int x,int y) const {
return TCOD_image_get_alpha(data,x,y);
}
TCODColor TCODImage::getMipmapPixel(float x0,float y0, float x1, float y1) {
return TCOD_image_get_mipmap_pixel(data,x0,y0,x1,y1);
}
void TCODImage::putPixel(int x, int y, const TCODColor col) {
TCOD_color_t ccol = {col.r,col.g,col.b};
TCOD_image_put_pixel(data,x,y,ccol);
}
#ifdef TCOD_CONSOLE_SUPPORT
void TCODImage::blit(TCODConsole *console, float x, float y, TCOD_bkgnd_flag_t bkgnd_flag, float scalex, float scaley, float angle) const {
TCOD_image_blit(data,console->data,x,y,bkgnd_flag,scalex,scaley,angle);
}
void TCODImage::blitRect(TCODConsole *console, int x, int y, int w, int h, TCOD_bkgnd_flag_t bkgnd_flag) const {
TCOD_image_blit_rect(data,console->data,x,y,w,h,bkgnd_flag);
}
#endif
void TCODImage::save(const char *filename) const {
TCOD_image_save(data,filename);
}
void TCODImage::setKeyColor(const TCODColor keyColor) {
TCOD_color_t ccol = {keyColor.r,keyColor.g,keyColor.b};
TCOD_image_set_key_color(data,ccol);
}
bool TCODImage::isPixelTransparent(int x, int y) const {
return TCOD_image_is_pixel_transparent(data,x,y) != 0;
}
#ifdef TCOD_CONSOLE_SUPPORT
void TCODImage::refreshConsole(const TCODConsole *console) {
TCOD_image_refresh_console(data,console->data);
}
#endif
void TCODImage::invert() {
TCOD_image_invert(data);
}
void TCODImage::hflip() {
TCOD_image_hflip(data);
}
void TCODImage::rotate90(int numRotations) {
TCOD_image_rotate90(data,numRotations);
}
void TCODImage::vflip() {
TCOD_image_vflip(data);
}
void TCODImage::scale(int neww, int newh) {
TCOD_image_scale(data,neww,newh);
}
#ifdef TCOD_CONSOLE_SUPPORT
void TCODImage::blit2x(TCODConsole *dest, int dx, int dy, int sx, int sy, int w, int h) const {
TCOD_image_blit_2x(data,dest->data,dx,dy,sx,sy,w,h);
}
#endif
#endif