#include "Face.h"
#include "Image.h"
#include <iostream.h>
#include <conio.h>
     
Face :: Face()
{
	PixData = NULL;
}

Face :: ~Face()
{
	if(PixData != NULL)
	{
		delete [] PixData;
	}
}

void Face :: Initialize(char FileName[])
{
	ImageManip Im;
	if(PixData != NULL)
	{
		delete [] PixData;
	}
	PixData = Im.GetPixelData(FileName,W,H);
}


int * Face :: GetPixData(int Bno,int Nrow,int Ncol)
{
	int * P = new int [Nrow * Ncol];
	int h = H / Nrow;
	int w = W / Ncol;
	int r = Bno / w;
	int c = Bno - r * w;
	int x = 0;
	for(int i = r * Nrow;i < (r + 1) * Nrow;i ++)
	{
		for(int j = c * Ncol;j < (c + 1) * Ncol;j ++)
		{
			P[x ++] = PixData[i * W + j];
		}
	}
	return P;
}

int * Face :: GetPixData(int Left,int Top,int Right,int Bottom)
{
	int * P = new int [(Bottom - Top) * (Right - Left)];
	int x = 0;
	for(int i = Top;i < Bottom;i ++)
	{
		for(int j = Left;j < Right;j ++)
		{
			P[x ++] = PixData[i * W + j];
		}
	}
	return P;
}
