//////////////////////////////////////////////////////////////////////////////
//
// Tools_NvTextureTools.cpp
//
// Copyright (c) 2007 Rebellion. All rights reserved.
//
// Description:
//
//     helpers for using NVidia's texture tools code
//
//////////////////////////////////////////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

#include "Core/Asura.h"

// This file's header.
#include "ImageProcessing/Tools_NvTextureTools.h"

// in middleware.
#include "NVidia/DDS_Utilities/dxtlib.h"


void Tools_NvTextureTools::SetOptionsForSharpenMipMaps(nvCompressionOptions& xOptions, u_int uWidth, u_int uHeight)
{
	xOptions.sharpenFilterType = kSharpenFilterSharpenSoft;
	u_int uLastLevelToSharpen = 0;
	const u_int uMaxDim = Asura_Maths::Max(uWidth, uHeight);
	u_int uMipLevelDim = uMaxDim / 2;

	while (uMipLevelDim > 63)
	{
		uMipLevelDim /= 2;
		++uLastLevelToSharpen;
	}
	Asura_Assert(uLastLevelToSharpen < MAX_MIP_MAPS, "image too big");
	uLastLevelToSharpen = Asura_Maths::Min(uLastLevelToSharpen, static_cast<u_int>(MAX_MIP_MAPS - 1)); // safety.
	xOptions.sharpening_passes_per_mip_level[0] = 0;
	for (u_int u = 1; u <= uLastLevelToSharpen; ++u)
	{
		xOptions.sharpening_passes_per_mip_level[u] = 1;
	}
	for (u_int u = uLastLevelToSharpen + 1; u < MAX_MIP_MAPS; ++u)
	{
		xOptions.sharpening_passes_per_mip_level[u] = 0;
	}
}
