/*
 * GBuffer.h
 *
 *  Created on: Nov 7, 2008
 *      Author: alexander
 */

#ifndef GBUFFER_H_
#define GBUFFER_H_

#include "plates.h"


class Hystogramm;

class GBuffer {
public:
	typedef uint8_t Telement;
	static int count;

	int h;
	int w;
	Telement *data;


	GBuffer(int h, int w);
	GBuffer(AVPicture *frame, int h, int w, int deinterlace = 0);
	GBuffer(SDL_Surface *frame);
	GBuffer(GBuffer *src, int x1, int y1, int x2, int y2);

	GBuffer(int h, int w, uint8_t *data);


	void drawInto(SDL_Surface *dst);
	void drawInto(SDL_Surface *dst, int x, int y);


	GBuffer *filterSobel();
	GBuffer *filterSobelOrientation(GBuffer **orient);
	int getOrientation(int result1, int result2);
	GBuffer *suppressNonMaximum(int low, int high, GBuffer *orientation);


	GBuffer *filterGaussian();

	Hystogramm *getColorHyst();
	Hystogramm *getHHyst();
	Hystogramm *getWHyst();

	GBuffer *britnessContrast (int levellow, int levelhigh);
	GBuffer *threshold (int level);


	void drawRect(int x1, int y1, int x2, int y2);

	double multiplyAt(GBuffer *that, int x, int y);

	virtual ~GBuffer();

private:
		void init(int h, int w);

};


class Hystogramm
{
public:
	int w;
	int *data;

	void drawHInto(SDL_Surface *dst, int size);
	void drawHInto(SDL_Surface *dst, int size, int width);
	void drawHInto(SDL_Surface *dst, int size, int width, int x, int y);

	int getMin();
	int getMax();

	GBuffer *matchWith(Hystogramm *other, int *start, int *end);

	Hystogramm(int w);
	Hystogramm(int _w, int *_data);

	~Hystogramm();

};

#endif /* GBUFFER_H_ */
