/**
 *  \file displacement.c
 *  \brief This file describes the actins with the displacement buffer
 *
 *  \ingroup corefiles
 *  \date Aug 14, 2009
 *  \author alexander
 */

#include "global.h"

#include <stdlib.h>

#include "displacement.h"

#ifdef ASSERTS
int displacementBufferCounter = 0;
#endif

/**
 *
 * \brief This function creates a displacement buffer for the given width and height.
 *
 * \attention You should not forget to destroy the created buffer with the call to displacementBufferDelete(toDelete)
 *
 * \param h The height of the buffer to be created.
 * \param w The width of the buffer to be created.
 *
 * \return a newly created buffer.
 */

DisplacementBuffer *displacementBufferCreate(int h, int w)
{
	DisplacementBuffer *toReturn = (DisplacementBuffer *) dv_malloc (sizeof (DisplacementBuffer));
	toReturn->h = h;
	toReturn->w = w;
	toReturn->data = (uint16_t *) dv_calloc(h * w , sizeof(uint16_t));

#ifdef ASSERTS
	displacementBufferCounter++;
#endif

	return toReturn;
}

/**
 * This function deletes a displacement buffer
 *
 * \param toDelete the buffer to be deleted
 */
void displacementBufferDelete(DisplacementBuffer *toDelete)
{
	if (toDelete->data != NULL)
		dv_free(toDelete->data);
	dv_free(toDelete);


#ifdef ASSERTS
	displacementBufferCounter--;
#endif

}
