Add image destructors.

master
Fabien Freling 2014-07-03 23:53:06 +02:00
parent 9e8d79d384
commit a871d92723
1 changed files with 30 additions and 0 deletions

View File

@ -6,11 +6,17 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <chrono> #include <chrono>
#include <cstdlib>
#include <xmmintrin.h> #include <xmmintrin.h>
#include <emmintrin.h>
using namespace std; using namespace std;
//
//
// Point
//
template <typename T> template <typename T>
struct TPoint { struct TPoint {
@ -22,15 +28,24 @@ struct TPoint {
, y(b) , y(b)
{} {}
}; };
typedef TPoint<int> Point; typedef TPoint<int> Point;
typedef TPoint<double> DPoint; // absolute point, can be negative typedef TPoint<double> DPoint; // absolute point, can be negative
template<typename Elem, typename Traits, typename T> template<typename Elem, typename Traits, typename T>
std::basic_ostream<Elem, Traits>& operator << (std::basic_ostream<Elem, Traits>& o, TPoint<T> const& p) std::basic_ostream<Elem, Traits>& operator << (std::basic_ostream<Elem, Traits>& o, TPoint<T> const& p)
{ {
o << "(" << p.x << ", " << p.y << ")"; o << "(" << p.x << ", " << p.y << ")";
return o; return o;
} }
//
//
// Image
//
struct Image { struct Image {
unsigned int width; unsigned int width;
unsigned int height; unsigned int height;
@ -42,6 +57,11 @@ struct Image {
, buffer(NULL) , buffer(NULL)
{} {}
virtual ~Image()
{
delete [] buffer;
}
Image(unsigned int w, unsigned int h) Image(unsigned int w, unsigned int h)
{ {
this->width = w; this->width = w;
@ -221,6 +241,16 @@ struct TiledImage : public Image {
, nb_row_tile(0) , nb_row_tile(0)
{} {}
~TiledImage()
{
unsigned int const nb_tiles = nb_col_tile * nb_row_tile;
for (unsigned int i = 0; i < nb_tiles; ++i)
{
delete [] tiles[i];
}
delete [] tiles;
}
TiledImage(unsigned int w, unsigned int h) TiledImage(unsigned int w, unsigned int h)
{ {
allocate_memory(w, h); allocate_memory(w, h);