#ifndef MOSAIC_IMAGE_H
#define MOSAIC_IMAGE_H

#include <GL/glut.h>
#include <math.h>
#include <string>
//#include "Filter.h"

using namespace std;

#define NUM_SIZES 8
#define NUM_IMAGES 2938
#define IMG_WIDTH 256
#define IMG_HEIGHT 256

// some types for later use
typedef unsigned char byte;
typedef byte rgb[3];			// these are 3 byte rgbs in RGB order

#define R 0
#define G 1
#define B 2

//*****************************************************************************
// a class to represent the resampling image
//*****************************************************************************
class ResampledImage
{
public:
	int	xsize;		/* horizontal size of the image in pixels */
	int	ysize;		/* vertical size of the image in pixels */
	int span;
	rgb *data;		/* pointer to first scanline of image */

	ResampledImage(int x, int y);
	~ResampledImage();
	rgb *get_pixel(int x, int y);
	void get_row(rgb *row, int y);
	void get_column(rgb *row, int x);
	void put_pixel(int x, int y, rgb pix);
	void zoom(ResampledImage *dst);
	void SaveToFile();
};

class MosaicImage;//forward

//*****************************************************************************
// an object to represent the framebuffer where I draw
//*****************************************************************************
class FrameBuffer
{
public:
	int width, height;
	rgb *pix;

	int TileSize;//size of tile
	int DownSize;//size of downsampled tile
	int TileCount;
	int *Tiles;//indices of tiles
	MosaicImage *mi;
	int ZoomSize;
	int CompareSize;
	int NewImage;
	int VisibleTiles;

	FrameBuffer(int w, int h, MosaicImage *pmi);
	void Clear(const rgb p);
	void Resample();
	void FindIndices();
	void CopyTile(ResampledImage *tile, int tileno);
	void ZoomCopyFromFB(ResampledImage *img, int tx, int ty);
	void ZoomCopyToFB(ResampledImage *img, int tx, int ty);
	void SaveToFile();
	~FrameBuffer();
};

//*****************************************************************************
// an object to represent a "multiscale" image
//*****************************************************************************
class MosaicImage
{
public:
    unsigned int num;
	rgb i1[1];//1x1
	rgb i2[4];//2x2
	rgb i4[16];//4x4
	rgb *img;//bigger tiles
	
	MosaicImage();
	void ReadFromFile(int size, rgb *dest);
	void CopyToFB(int x, int y, int size, int ix, int iy, int w, int h, FrameBuffer *fb);
	~MosaicImage();
};

#endif