#ifdef _WINDOWS
	#include "stdafx.h"
#endif
#include "NkImageLibCtrl.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#ifdef _WINDOWS
#else
	#define	TRACE
#endif

// Static Variables
long s_ImageSDKLibInitCount = 0;
Nkfl_EntryProcPtr	s_pEntryFunc = NULL;	// Function pointer
#ifdef _WINDOWS
HINSTANCE			s_hDLL = NULL;			// Handle to DLL
#endif

//======================================================================
//	Constractor
//======================================================================
CImageLibCtrl::CImageLibCtrl()
{
	m_ulSessionID		= 0;		
} // CFileLibCtrl

//======================================================================
//	Destractor
//======================================================================
CImageLibCtrl::~CImageLibCtrl()
{	
} // ~CFileLibCtrl

//======================================================================
//	OpenLibrary
//======================================================================
unsigned long CImageLibCtrl::OpenLibrary()
{
	if ( s_ImageSDKLibInitCount > 0 )		return kNkfl_Code_None;

	if(!LoadFileLibrary())	return kNkfl_Code_Err_Unexpected;
//	AfxMessageBox("LoadFileLibrary is success", NULL, MB_OK | MB_ICONWARNING);

	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflLibraryParam	FileLibraryParam	= { 0 };
	FileLibraryParam.ulSize	  		= sizeof( NkflLibraryParam );
	FileLibraryParam.ulVersion		= 0x01000000;

#ifdef _WINDOWS
	unsigned long		ulErr		= kNkfl_Code_None;

	/////////////////////////////////////////////////
	// get current preference data from registry 
	/////////////////////////////////////////////////

	HKEY hkResult;							// hundle of registry key		
	
	// open registory
	if( ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Nikon\\NkImageSDKLib Sample", 0, KEY_ALL_ACCESS, &hkResult) )
	{		
		// registry opened, access registry and get data	
		// get VMMemory size
		DWORD dwSize = sizeof(long);		// set size of ulMemSize parameter		
		if( ERROR_SUCCESS != RegQueryValueEx( hkResult, "VMMemorySize", 0, NULL, (LPBYTE)&FileLibraryParam.ulVMMemorySize, (LPDWORD)&dwSize ))
		{
			FileLibraryParam.ulVMMemorySize = 0;
		}
		// get VMFilePath		
		dwSize = MAX_PATH;					// set max size of strFilePath
		if( ERROR_SUCCESS != RegQueryValueEx( hkResult, "VMFilePath", 0, NULL, (LPBYTE)FileLibraryParam.VMFileInfo, (LPDWORD)&dwSize ))
		{
			memset( FileLibraryParam.VMFileInfo, 0x00, MAX_PATH );
		}
		RegCloseKey( hkResult );			// close key
	}
	
	// check preference data and set default data if need
	if( 0 == FileLibraryParam.ulVMMemorySize )
	{
		// registroy doesn't exist, set default value	
		MEMORYSTATUS		MemStatus			= { 0 };

		// set swap file size
		// information about the current state of both physical and virtual memory.
		MemStatus.dwLength = sizeof( MEMORYSTATUS );
		::GlobalMemoryStatus( &MemStatus );

		FileLibraryParam.ulVMMemorySize	= (unsigned long)(MemStatus.dwAvailPhys / 2 >> SHIFT_TO_MEGA);		//set a half of virtual memory.
	}
	if( 0 == strlen( (const char*)FileLibraryParam.VMFileInfo ) )
	{
		// set swap file name
		char lpLibPath[256];
		char SwapFileName[MAX_PATH];
		if (GetTempPath(256,lpLibPath) == 0) {
			return kNkfl_Code_Err_Unexpected;
		}
		if (GetTempFileName(lpLibPath, "pre", 1, (char*)SwapFileName) == 0) {
			return kNkfl_Code_Err_Unexpected;
		}	 
		strcpy( (char*)&( FileLibraryParam.VMFileInfo ), SwapFileName );
	}

	try{
		ulErr = s_pEntryFunc( kNkfl_Cmd_OpenLibrary, &FileLibraryParam );
	}
	catch(...) {
		TRACE("Exception has occurred at OpenLibrary\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

#else

	unsigned long				ulErr = kNkfl_Code_None;
	short						foundVRefNum;
	long						foundDirID;
	FSSpec						nFSSpec;
	AliasHandle					hAlias = NULL;

	Boolean keyExistsAndHasValidFormat;
	SInt32 nVMSize = CFPreferencesGetAppIntegerValue(CFSTR(kVMMemorySizeKeyName), kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat);
	if( nVMSize == 0 )
		nVMSize = 512;
	FileLibraryParam.ulVMMemorySize	= nVMSize;

	CFStringRef pathRef = (CFStringRef)CFPreferencesCopyAppValue(CFSTR(kVMVMFilePath), kCFPreferencesCurrentApplication);
	if( pathRef != NULL )
	{
		char buffer[1024];
		if( CFStringGetCString(pathRef, buffer, 1024, kCFStringEncodingUTF8) )
		{
			FSRef ref;
			Boolean isDirectory;
			OSStatus err = FSPathMakeRef((UInt8*)buffer,&ref,&isDirectory);
			if( err == noErr )
			{
				UniChar vmName[32];
				const char *vmCName = "CheckerVM.tmp";
				for(int i=0; i<strlen(vmCName); i++)	// Convert to 16 bit
					vmName[i] = vmCName[i];
				err = FSNewAliasUnicode( NULL, &ref, strlen(vmCName), vmName, &hAlias, &isDirectory );
			}
			if( err == noErr || err == fnfErr )
				FileLibraryParam.VMFileInfo = hAlias;
		}
	}

	if( FileLibraryParam.VMFileInfo == NULL )
	{
		ulErr = ::FindFolder(kOnAppropriateDisk, kDesktopFolderType, kDontCreateFolder, &foundVRefNum, &foundDirID);
		if ( ulErr == noErr ) {
			ulErr = ::FSMakeFSSpec( foundVRefNum, foundDirID, "\pCheckerVM.tmp", &nFSSpec );
			if( ulErr == fnfErr ) {
				::FSpCreate( &nFSSpec, '????', '????', smSystemScript );
				ulErr = ::FSMakeFSSpec( foundVRefNum, foundDirID, "\pCheckerVM.tmp", &nFSSpec );
			}
			if ( ulErr == noErr ) {
				if ( (ulErr = NewAlias( NULL, &nFSSpec, &hAlias )) == noErr )
				{
					FileLibraryParam.VMFileInfo = hAlias;
					::FSpDelete( &nFSSpec );
				}
			}
		}
	}
	
	if ( ulErr == noErr ) {
		try{
				ulErr = s_pEntryFunc( kNkfl_Cmd_OpenLibrary, &FileLibraryParam );
		}
		catch(...) {
			ulErr = kNkfl_Code_Err_Unexpected;
		}
	}
		
	if ( hAlias != NULL ) {
		DisposeHandle( (Handle)hAlias );
	}

#endif	

	if ( ulErr == kNkfl_Code_None )
		++s_ImageSDKLibInitCount;

	return ulErr;
} // OpenLibrary


//======================================================================
//	CloseLibrary
//======================================================================
unsigned long CImageLibCtrl::CloseLibrary()
{
	// check succeed in openlib or not
	if ( s_ImageSDKLibInitCount == 0 )	return kNkfl_Code_None;

	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	--s_ImageSDKLibInitCount;
	if ( s_ImageSDKLibInitCount > 0 )		return kNkfl_Code_None;

	unsigned long	ulErr = kNkfl_Code_None;

	try{
		ulErr = s_pEntryFunc( kNkfl_Cmd_CloseLibrary, NULL );
	}
	catch(...) {
		TRACE("Exception has occurred at CloseLibrary\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	// release library handle
#ifdef _WINDOWS
	if ( s_hDLL )
		::FreeLibrary( s_hDLL );
	s_hDLL = NULL;
#endif
	s_pEntryFunc = NULL;
	
	return ulErr;
} // CloseLibrary


//======================================================================
//	OpenSession
//======================================================================
unsigned long CImageLibCtrl::OpenSession(void *pData, unsigned long ulSize/*= 0*/)
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflSessionParam	NkflSessionParam	= { 0 };
#ifndef _WINDOWS
	AliasHandle				hAlias				= NULL;
#endif

	NkflSessionParam.ulSize	= sizeof( NkflSessionParam );
	if(ulSize == 0) {
		// Open from file
		NkflSessionParam.ulType			= kNkfl_Source_FileName;
#ifdef _WINDOWS
		NkflSessionParam.pFileInfo		= pData;
#else
		if ( ::NewAlias( NULL, (FSSpec*)pData, &hAlias ) != noErr )
			hAlias = NULL;
		NkflSessionParam.pFileInfo		= (void*)hAlias;
#endif
	}
	else {
		// Open from memory
		NkflSessionParam.ulType			= kNkfl_Source_Memory;
		NkflSessionParam.pFileInfo		= pData;
		NkflSessionParam.ulFileSize		= ulSize;
	}

	try {
		if((ulErr = s_pEntryFunc(kNkfl_Cmd_OpenSession, &NkflSessionParam)) == kNkfl_Code_None) {
			// get ID of estabulished session.
			m_ulSessionID = NkflSessionParam.ulSessionID;
		}
	}
	catch(...) {
		TRACE("Exception has occurred at OpenSession\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

#ifndef _WINDOWS
	if ( hAlias != NULL )
		::DisposeHandle( (Handle)hAlias );
#endif
	m_bApplyPictCtrl = false;		// initialize flag of apply picturecontorol 

	return ulErr;
} // OpenSession


//======================================================================
//	CloseSession
//======================================================================
unsigned long CImageLibCtrl::CloseSession()
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;
	
	if(m_ulSessionID == 0)	return kNkfl_Code_None;

	unsigned long		ulErr					= kNkfl_Code_None;
	NkflSessionParam	NkflSessionParam	= { 0 };

	NkflSessionParam.ulSize		= sizeof( NkflSessionParam );
	NkflSessionParam.ulSessionID = m_ulSessionID;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_CloseSession, &NkflSessionParam );
	}
	catch(...) {
		TRACE("Exception has occurred at CloseSession\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	m_ulSessionID = 0;
	return ulErr;
} // CloseSession


//======================================================================
//	GetFileInfo
//======================================================================
unsigned long CImageLibCtrl::GetFileInfo(unsigned long *pulFormat)
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;
	
	unsigned long		ulErr				= kNkfl_Code_None;
	NkflFileInfoParam	NkflFileInfoParam	= { 0 };

	NkflFileInfoParam.ulSize		= sizeof(NkflFileInfoParam);
	NkflFileInfoParam.ulSessionID	= m_ulSessionID;
	
	try {
		if((ulErr = s_pEntryFunc( kNkfl_Cmd_GetFileInfo, &NkflFileInfoParam )) == kNkfl_Code_None) {
			if( pulFormat )
				*pulFormat = NkflFileInfoParam.ulFormat;
		}
	}
	catch(...) {
		TRACE("Exception has occurred at GetFileInfo\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}
	return ulErr;

} // GetFileInfo


//======================================================================
//	SetOutputProfile
//======================================================================
unsigned long CImageLibCtrl::SetOutputProfile( unsigned long ulRenderingIntent, unsigned char *pProfilePath )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long	ulErr = kNkfl_Code_None;

	NkflOutputProfileParam	NkflOutputProfile	= { 0 };

	NkflOutputProfile.ulSize			= sizeof( NkflOutputProfileParam );
	NkflOutputProfile.ulSessionID		= m_ulSessionID;
	NkflOutputProfile.ulRenderingIntent	= ulRenderingIntent;
#ifdef _WINDOWS
	memcpy( NkflOutputProfile.OutputProfile, pProfilePath, strlen( (char*)pProfilePath ) );
#else
	NewAlias( NULL, (FSSpec*)pProfilePath, &NkflOutputProfile.OutputProfile );
#endif
	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_SetOutputProfile, &NkflOutputProfile );
	}
	catch(...) {
		TRACE("Exception has occurred at SetOutputProfile\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}
	return ulErr;
} // SetOutputProfile


//======================================================================
//	GetOutputProfile
//======================================================================
unsigned long CImageLibCtrl::GetOutputProfile( unsigned long *pulRenderingIntent, unsigned char *pProfilePath )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long	ulErr = kNkfl_Code_None;

	NkflOutputProfileParam	NkflOutputProfile	= { 0 };

	NkflOutputProfile.ulSize			= sizeof( NkflOutputProfileParam );
	NkflOutputProfile.ulSessionID		= m_ulSessionID;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetOutputProfile, &NkflOutputProfile );
		if( ulErr == kNkfl_Code_None )
		{
			if( pulRenderingIntent )
				*pulRenderingIntent = NkflOutputProfile.ulRenderingIntent;
#ifdef _WINDOWS
			if( pProfilePath )
				memcpy( pProfilePath, NkflOutputProfile.OutputProfile, strlen( (char*)NkflOutputProfile.OutputProfile ) );
#else
			if( pProfilePath )
			{
				Boolean	wasChanged;
				ResolveAlias( NULL, NkflOutputProfile.OutputProfile, (FSSpec*)pProfilePath, &wasChanged );
			}
#endif
		}
	}
	catch(...) {
		TRACE("Exception has occurred at GetOutputProfile\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // GetOutputProfile

//======================================================================
//	GetImageInfo
//======================================================================
unsigned long CImageLibCtrl::GetImageInfo( NkIL_ImageInfo *pImgInfo )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflImageInfoParam	NkflImgInfoParam	= { 0 };

	NkflImgInfoParam.ulSize			= sizeof( NkflImageInfoParam );
	NkflImgInfoParam.ulSessionID	= m_ulSessionID;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetImageInfo, &NkflImgInfoParam );
	}
	catch(...) {
		TRACE("Exception has occurred at GetImageInfo\n");
		return kNkfl_Code_Err_Unexpected;
	}

	// set image size parameter
	pImgInfo->ulWidth		= NkflImgInfoParam.ulWidth;
	pImgInfo->ulHeight		= NkflImgInfoParam.ulHeight;
	pImgInfo->ulByteDepth	= NkflImgInfoParam.ulByteDepth;
	pImgInfo->ulColor		= NkflImgInfoParam.ulColor;
	pImgInfo->ulOrientation	= NkflImgInfoParam.ulOrientation;
	pImgInfo->dbResolution	= NkflImgInfoParam.dbResolution;
	return ulErr;

} // GetImageInfo


//======================================================================
//	SetImageInfo
//======================================================================
unsigned long CImageLibCtrl::SetImageInfo( NkIL_ImageInfo *pImgInfo )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflImageInfoParam	NkflImgInfoParam	= { 0 };

	NkflImgInfoParam.ulSize		  	= sizeof( NkflImageInfoParam );
	NkflImgInfoParam.ulSessionID  	= m_ulSessionID;
	NkflImgInfoParam.ulWidth	  	= pImgInfo->ulWidth;
	NkflImgInfoParam.ulHeight 	  	= pImgInfo->ulHeight;
	NkflImgInfoParam.ulByteDepth  	= pImgInfo->ulByteDepth;
	NkflImgInfoParam.ulColor	  	= pImgInfo->ulColor;
	NkflImgInfoParam.ulOrientation	= pImgInfo->ulOrientation;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_SetImageInfo, &NkflImgInfoParam );
	}
	catch(...) {
		TRACE("Exception has occurred at SetImageInfo\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // SetImageInfo

//======================================================================
//	GetOriginalInfo
//======================================================================
unsigned long CImageLibCtrl::GetOriginalInfo( NkIL_ImageInfo *pImgInfo )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflImageInfoParam	NkflImgInfoParam	= { 0 };

	NkflImgInfoParam.ulSize			= sizeof( NkflImageInfoParam );
	NkflImgInfoParam.ulSessionID	= m_ulSessionID;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetOriginalInfo, &NkflImgInfoParam );
	}
	catch(...) {
		TRACE("Exception has occurred at GetOriginalInfo\n");
		return kNkfl_Code_Err_Unexpected;
	}

	// set image size parameter
	pImgInfo->ulWidth		= NkflImgInfoParam.ulWidth;
	pImgInfo->ulHeight		= NkflImgInfoParam.ulHeight;
	pImgInfo->ulByteDepth	= NkflImgInfoParam.ulByteDepth;
	pImgInfo->ulColor		= NkflImgInfoParam.ulColor;
	pImgInfo->ulOrientation	= NkflImgInfoParam.ulOrientation;
	pImgInfo->dbResolution	= NkflImgInfoParam.dbResolution;
	return ulErr;

} // GetOriginalInfo


//======================================================================
//	GetRawDevelopmentInfo
//======================================================================
unsigned long CImageLibCtrl::GetRawDevelopmentInfo( unsigned long *pulRawDevelopment )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long	ulErr = kNkfl_Code_None;

	NkflRawDevelopmentInfo NkflRawDevelopment	= { 0 };

	NkflRawDevelopment.ulSize		= sizeof( NkflRawDevelopmentInfo );
	NkflRawDevelopment.ulSessionID	= m_ulSessionID;	

	try {		
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetRawDevelopmentInfo, &NkflRawDevelopment );
		if( ulErr == kNkfl_Code_None )
		{
			if( pulRawDevelopment )
				*pulRawDevelopment = NkflRawDevelopment.ulRawDevelopmentInfo;
		}
	}
	catch(...) {
		TRACE("Exception has occurred at GetRawDevelopmentInfo\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // GetRawDevelopmentInfo


//======================================================================
//	RawDevelopment
//======================================================================
unsigned long CImageLibCtrl::RawDevelopment( unsigned long ulRawDevelopment, void *pData )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long	ulErr = kNkfl_Code_None;

	NkflRawDevelopmentParam	NkflRawDevelopment	= { 0 };

	NkflRawDevelopment.ulSize			= sizeof( NkflRawDevelopmentParam );
	NkflRawDevelopment.ulSessionID		= m_ulSessionID;
	NkflRawDevelopment.ulRawDevelopment	= ulRawDevelopment;
	NkflRawDevelopment.pData			= pData;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_RawDevelopment, &NkflRawDevelopment );
	}
	catch(...) {
		TRACE("Exception has occurred at RawDevelopment\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // RawDevelopment


//======================================================================
//	GetRawDevelopmentParam
//======================================================================
unsigned long CImageLibCtrl::GetRawDevelopmentParam( unsigned long ulRawDevelopment, void *pData )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long	ulErr = kNkfl_Code_None;

	NkflRawDevelopmentParam	NkflRawDevelopment	= { 0 };

	NkflRawDevelopment.ulSize			= sizeof( NkflRawDevelopmentParam );
	NkflRawDevelopment.ulSessionID		= m_ulSessionID;
	NkflRawDevelopment.ulRawDevelopment = ulRawDevelopment;
	NkflRawDevelopment.pData			= pData;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetRawDevelopmentParam, &NkflRawDevelopment );
	}
	catch(...) {
		TRACE("Exception has occurred at GetRawDevelopmentParam\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // GetRawDevelopmentParam


//======================================================================
//	GetColorTempRange
//======================================================================
unsigned long CImageLibCtrl::GetColorTempRange( unsigned long ulMWB, unsigned long *pulDefault, unsigned long *pulMinColorTemp, unsigned long *pulMaxColorTemp )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long	ulErr = kNkfl_Code_None;

	NkflColorTempRangeParam	NkflColorTempRange	= { 0 };

	NkflColorTempRange.ulSize			= sizeof( NkflColorTempRangeParam );
	NkflColorTempRange.ulSessionID		= m_ulSessionID;
	NkflColorTempRange.ulMWB			= ulMWB;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetColorTempRange, &NkflColorTempRange );
		if( ulErr == kNkfl_Code_None )
		{
			if( pulDefault )
				*pulDefault = NkflColorTempRange.ulDefalut;
			if( pulMinColorTemp )
				*pulMinColorTemp = NkflColorTempRange.ulMinColorTemp;
			if( pulMaxColorTemp )
				*pulMaxColorTemp = NkflColorTempRange.ulMaxColorTemp;
		}
	}
	catch(...) {
		TRACE("Exception has occurred at GetColorTempRange\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // GetColorTempRange


//======================================================================
//	GetImageData
//======================================================================
unsigned long CImageLibCtrl::GetImageData( NkIL_ImageParam* pParam )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;
	NkflImageParam	NkImageParam	= { 0 };
	unsigned long	ulErr			= kNkfl_Code_None;

	NkImageParam.ulSize			= sizeof(NkflImageParam);
	NkImageParam.ulSessionID	= m_ulSessionID;
	NkImageParam.rectArea		= pParam->rect;
	NkImageParam.ulDataSize		= pParam->ulLength;
	NkImageParam.pData			= pParam->pData;
	NkImageParam.pFunc			= pParam->pFunc;
	NkImageParam.pProgressParam	= pParam->pProgressParam;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetImageData, &NkImageParam );
	}
	catch(...) {
		TRACE("Exception has occurred at GetImageData\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;

} // GetImageData


//======================================================================
//	GetThumbnailCount
//======================================================================
unsigned long CImageLibCtrl::GetThumbnailCount( unsigned long *pulThumbnailCount )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflImageInfoParam	NkflImgInfoParam	= { 0 };

	NkflImgInfoParam.ulSize			= sizeof( NkflImageInfoParam );
	NkflImgInfoParam.ulSessionID	= m_ulSessionID;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetThumbnailCount, &NkflImgInfoParam ); 
		if( pulThumbnailCount )
			*pulThumbnailCount	= NkflImgInfoParam.ulImageID;
	}
	catch(...) {
		TRACE("Exception has occurred at GetThumbnailCount\n");
		return kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // GetThumbnailCount


//======================================================================
//	GetThumbnailInfo
//======================================================================
unsigned long CImageLibCtrl::GetThumbnailInfo( NkIL_ImageInfo *pImgInfo )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflImageInfoParam	NkflImgInfoParam = { 0 };

	NkflImgInfoParam.ulSize			= sizeof( NkflImageInfoParam );
	NkflImgInfoParam.ulSessionID	= m_ulSessionID;
	NkflImgInfoParam.ulImageID		= pImgInfo->ulThumbID;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetThumbnailInfo, &NkflImgInfoParam ); 
	}
	catch(...) {
		TRACE("Exception has occurred at GetThumbnailInfo\n");
		return kNkfl_Code_Err_Unexpected;
	}

	pImgInfo->ulWidth		= NkflImgInfoParam.ulWidth;
	pImgInfo->ulHeight		= NkflImgInfoParam.ulHeight;
	pImgInfo->ulByteDepth	= NkflImgInfoParam.ulByteDepth;
	pImgInfo->ulColor		= NkflImgInfoParam.ulColor;
	pImgInfo->ulOrientation = NkflImgInfoParam.ulOrientation;

	return ulErr;
} // GetThumbnailInfo


//======================================================================
//	SetThumbnailInfo
//======================================================================
unsigned long CImageLibCtrl::SetThumbnailInfo( NkIL_ImageInfo *pImgInfo )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflImageInfoParam	NkflImgInfoParam	= { 0 };
		
	NkflImgInfoParam.ulSize			= sizeof( NkflImageInfoParam );
	NkflImgInfoParam.ulSessionID	= m_ulSessionID;
	NkflImgInfoParam.ulImageID		= pImgInfo->ulThumbID;
	NkflImgInfoParam.ulWidth		= pImgInfo->ulWidth;
	NkflImgInfoParam.ulHeight		= pImgInfo->ulHeight;
	NkflImgInfoParam.ulByteDepth	= pImgInfo->ulByteDepth;
	NkflImgInfoParam.ulColor		= pImgInfo->ulColor;
	NkflImgInfoParam.ulOrientation	= pImgInfo->ulOrientation;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_SetThumbnailInfo, &NkflImgInfoParam ); 
	}
	catch(...) {
		TRACE("Exception has occurred at SetThumbnailInfo\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // SetThumbnailInfo


//======================================================================
//	GetThumbnailData
//======================================================================
unsigned long CImageLibCtrl::GetThumbnailData(NkIL_ImageParam* pParam)
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;
	unsigned long		ulErr		= kNkfl_Code_None;
	NkflImageParam		NkImageParam;

	NkImageParam.ulSize			= sizeof(NkflImageParam);
	NkImageParam.ulSessionID	= m_ulSessionID;
	NkImageParam.ulImageID		= pParam->ulThumbID;
	NkImageParam.rectArea		= pParam->rect;
	NkImageParam.ulDataSize		= pParam->ulLength;
	NkImageParam.pData			= pParam->pData;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetThumbnailData, &NkImageParam );
	}
	catch(...) {
		TRACE("Exception has occurred at GetThumbnailData\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}

	return ulErr;
} // GetThumbnailData


//======================================================================
//	GetTagInfo
//======================================================================
unsigned long CImageLibCtrl::GetTagInfo(unsigned long* pulList, unsigned long* pulCount)
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;
	if ( pulCount == NULL)	return kNkfl_Code_Err_InvalidParam;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflTagInfoParam	NkflTagInfo = { 0 };
	
	NkflTagInfo.ulSize			= sizeof(NkflTagInfoParam);
	NkflTagInfo.ulSessionID		= m_ulSessionID;
	NkflTagInfo.ulCount			= *pulCount;
	NkflTagInfo.pulTagList		= pulList;
	
	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetTagInfo, &NkflTagInfo );
		// save get data length
		*pulCount = NkflTagInfo.ulCount;
	}
	catch(...) {
		TRACE("Exception has occurred at GetTagInfo\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}
	
	return ulErr;
} // GeTagInfo


//======================================================================
//	GetTagData
//======================================================================
unsigned long CImageLibCtrl::GetTagData( NkIL_TagDataParam* pParam )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long		ulErr				= kNkfl_Code_None;
	NkflTagDataParam	NkflTagData	= { 0 };

	NkflTagData.ulSize			= sizeof( NkflTagDataParam );
	NkflTagData.ulSessionID		= m_ulSessionID;
	NkflTagData.ulTagID			= pParam->ulTagID;
	NkflTagData.pData			= pParam->pData;
	if ( pParam->pData )  
		NkflTagData.ulTagLength = pParam->ulTagLength;

	try {
		ulErr = s_pEntryFunc( kNkfl_Cmd_GetTagData, &NkflTagData );
	}
	catch(...) {
		TRACE("Exception has occurred at GetTagData\n");
		return kNkfl_Code_Err_Unexpected;
	}

	pParam->ulTagType	= NkflTagData.ulTagType;
	pParam->ulTagValue	= NkflTagData.ulTagValue;
	pParam->ulTagLength	= NkflTagData.ulTagLength;
	
	return ulErr;
	
} // GetTagData


//======================================================================
//	GetTagStringInfo
//======================================================================
unsigned long CImageLibCtrl::GetTagStringInfo( unsigned long *pulLines, unsigned long *pulColumns )
{
	if(!s_pEntryFunc)	return kNkfl_Code_Err_Unexpected;

	unsigned long				ulErr				= kNkfl_Code_None;
	NkflTagStringInfoParam		NkflTagStrInfoParam	= { 0 };

	NkflTagStrInfoParam.ulSize		= sizeof( NkflTagStringInfoParam );
	NkflTagStrInfoParam.ulSessionID	= m_ulSessionID;
	
	try {
		ulErr = s_pEntryFunc(kNkfl_Cmd_GetTagStringInfo, &NkflTagStrInfoParam);
	}
	catch(...) {
		TRACE("Exception has occurred at GetTagStringInfo\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}
	
	if( pulLines )
		*pulLines	= NkflTagStrInfoParam.ulLines;
	if( pulColumns )
		*pulColumns	= NkflTagStrInfoParam.ulColumns;

	return ulErr;
} // GetTagStringInfo


//======================================================================
//	GetTagString
//======================================================================
unsigned long CImageLibCtrl::GetTagString(NkIL_TagStringParam* pData)
{
	if(!s_pEntryFunc)	return kNkfl_Code_Err_Unexpected;

	unsigned long			ulErr			= kNkfl_Code_None;
	NkflTagStringParam		NkflTagStrParam	= { 0 };

	NkflTagStrParam.ulSize			= sizeof( NkflTagStringParam );
	NkflTagStrParam.ulSessionID		= m_ulSessionID;
	NkflTagStrParam.ulLines			= pData->ulLines;
	NkflTagStrParam.ulColumns		= pData->ulColumns;
	NkflTagStrParam.ulStringLength	= pData->ulLength;
	NkflTagStrParam.pData			= pData->pData;
	
	try {
		ulErr = s_pEntryFunc(kNkfl_Cmd_GetTagString, &NkflTagStrParam);
	}
	catch(...) {
		TRACE("Exception has occurred at GetTagString\n");
		ulErr = kNkfl_Code_Err_Unexpected;
	}
	
	pData->ulLayout		= NkflTagStrParam.ulLayoutLength;
	pData->ulLength		= NkflTagStrParam.ulStringLength;

	return ulErr;
} // GetTagString


//======================================================================
// NAME			: LoadFileLibrary
//
// FUNCTION		: Load FileLibrary (protected member proc)
//
// PARAMETER	: none
//
// RETURN		: TRUE	success, FALSE error
//======================================================================
bool CImageLibCtrl::LoadFileLibrary()
{
#ifdef _WINDOWS
	bool bRet = FALSE;

	// Load library
	s_hDLL	= LoadLibraryEx(FLSTR_IMAGESDKLIB_PATH_VER, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
	if(s_hDLL != NULL) {
		// get proc address
		if((s_pEntryFunc = (Nkfl_EntryProcPtr)GetProcAddress(s_hDLL, "Nkfl_Entry")) != NULL) {
			bRet = TRUE;
		} else {
			FreeLibrary( s_hDLL );
			s_hDLL = NULL;
				bRet = FALSE;
		}
	} else {
		bRet = FALSE;
	}
		
	return bRet;
#else
	s_pEntryFunc = (Nkfl_EntryProcPtr)Nkfl_Entry;
	return true;
#endif
} // LoadFileLibrary

//======================================================================
//	GetRawQuality
//======================================================================
unsigned long CImageLibCtrl::GetRawQuality( unsigned long* pulRawQuality )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr = kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_RawQuality & ulRawDevelopInfo )
	{
		NkflRawDevelopment_RawQuality	StrRawQuality = {0};
		StrRawQuality.ulSize	= sizeof(NkflRawDevelopment_RawQuality);				
		
		ulErr	= GetRawDevelopmentParam( kNkfl_RawDevelopment_RawQuality, &StrRawQuality );
		if( ulErr == kNkfl_Code_None )
		{
			*pulRawQuality = StrRawQuality.ulQuality;
		}
	}
	return ulErr;
}

//======================================================================
//	GetParamSettings
//======================================================================
unsigned long CImageLibCtrl::GetParamSettings( unsigned long* pulParamSet )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_RawParameterSet & ulRawDevelopInfo )
	{
		NkflRawDevelopment_RawParameterSet StrParamSet = {0};			
		StrParamSet.ulSize	= sizeof(NkflRawDevelopment_RawParameterSet);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_RawParameterSet, &StrParamSet );
		if( ulErr == kNkfl_Code_None )
		{
			*pulParamSet = StrParamSet.ulParamterSet;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetExpComp
//======================================================================
unsigned long CImageLibCtrl::GetExpComp( double* pdbExpComp )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr = kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_ExpComp & ulRawDevelopInfo )
	{
		NkflRawDevelopment_ExpComp StrExpComp = {0};			
		StrExpComp.ulSize = sizeof(NkflRawDevelopment_ExpComp);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_ExpComp, &StrExpComp );
		if( ulErr == kNkfl_Code_None )
		{			
			*pdbExpComp = StrExpComp.dbExpComp;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetWBInfo
//======================================================================
unsigned long CImageLibCtrl::GetWBInfo( NkIL_WBInfo* pStrWBInfo )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_WBAdjustment & ulRawDevelopInfo )
	{
		NkflRawDevelopment_WBAdj StrWBAdj = {0};			
		StrWBAdj.ulSize = sizeof(NkflRawDevelopment_WBAdj);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_WBAdjustment, &StrWBAdj );
		if( ulErr == kNkfl_Code_None )
		{
			pStrWBInfo->ulMWB		= StrWBAdj.ulMWB;
			pStrWBInfo->lColorTemp	= StrWBAdj.lColorTemp;
			pStrWBInfo->rgb			= StrWBAdj.rgb;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetTint
//======================================================================
unsigned long CImageLibCtrl::GetTint( long* plTint )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_Tint & ulRawDevelopInfo )
	{				
		NkflRawDevelopment_Tint StrTint = {0};			
		StrTint.ulSize		= sizeof(NkflRawDevelopment_Tint);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_Tint, &StrTint );
		if( ulErr == kNkfl_Code_None )
		{
			*plTint = StrTint.lTint;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetNR
//======================================================================
unsigned long CImageLibCtrl::GetNR( unsigned long* pulNR, bool* pbIsNR )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;
	*pbIsNR = false;
	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_NR & ulRawDevelopInfo )
	{				
		NkflRawDevelopment_NR StrNR = {0};			
		StrNR.ulSize		= sizeof(NkflRawDevelopment_NR);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_NR, &StrNR );
		if( ulErr == kNkfl_Code_None )
		{
			*pulNR = StrNR.ulNRType;
			*pbIsNR = true;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetADL
//======================================================================
unsigned long CImageLibCtrl::GetADL( unsigned long *pulADL, bool* pbIsADL )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;
	*pbIsADL = false;
	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_ActiveDLighting & ulRawDevelopInfo )
	{				
		NkflRawDevelopment_ActiveDLighting StrADL = {0};			
		StrADL.ulSize		= sizeof(NkflRawDevelopment_ActiveDLighting);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_ActiveDLighting, &StrADL );
		if( ulErr == kNkfl_Code_None )
		{
			*pulADL = StrADL.ulActiveDLighting;
			*pbIsADL = true;			
		}
	}
	
	return ulErr;
}

//======================================================================
//	GetColorMode
//======================================================================
unsigned long CImageLibCtrl::GetColorMode( unsigned long* pulColorMode, bool* pbIsColorMode )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;
	*pbIsColorMode = false;
	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_ColorMode & ulRawDevelopInfo )
	{
		NkflRawDevelopment_ColorMode StrColorMode = {0};			
		StrColorMode.ulSize		= sizeof(NkflRawDevelopment_ColorMode);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_ColorMode, &StrColorMode );
		if( ulErr == kNkfl_Code_None )
		{
			*pulColorMode = StrColorMode.ulColorMode;
			*pbIsColorMode = true;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetSharpness
//======================================================================
unsigned long CImageLibCtrl::GetSharpness( unsigned long* pulSharpness )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_Sharpness & ulRawDevelopInfo )
	{				
		NkflRawDevelopment_Sharpness StrSharpness = {0};			
		StrSharpness.ulSize		= sizeof(NkflRawDevelopment_Sharpness);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_Sharpness, &StrSharpness );
		if( ulErr == kNkfl_Code_None )
		{
			*pulSharpness = StrSharpness.ulSharpness;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetToneComp
//======================================================================
unsigned long CImageLibCtrl::GetToneComp( unsigned long* pulToneComp )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_ToneComp & ulRawDevelopInfo )
	{				
		NkflRawDevelopment_ToneComp StrToneComp = {0};			
		StrToneComp.ulSize	= sizeof(NkflRawDevelopment_ToneComp);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_ToneComp, &StrToneComp );
		if( ulErr == kNkfl_Code_None )
		{
			*pulToneComp = StrToneComp.ulToneComp;
		}
	}
	return ulErr;
}

//======================================================================
//	GetSaturation
//======================================================================
unsigned long CImageLibCtrl::GetSaturation( unsigned long* pulSaturation )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_Saturation & ulRawDevelopInfo )
	{				
		NkflRawDevelopment_Saturation StrSaturation = {0};			
		StrSaturation.ulSize = sizeof(NkflRawDevelopment_Saturation);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_Saturation, &StrSaturation );
		if( ulErr == kNkfl_Code_None )
		{
			*pulSaturation = StrSaturation.ulSaturation;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetHueAdj
//======================================================================
unsigned long CImageLibCtrl::GetHueAdj( long* plHueAdj )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_HueAdjustment & ulRawDevelopInfo )
	{				
		NkflRawDevelopment_HueAdj StrHueAdj = {0};			
		StrHueAdj.ulSize = sizeof(NkflRawDevelopment_HueAdj);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_HueAdjustment, &StrHueAdj );
		if( ulErr == kNkfl_Code_None )
		{
			*plHueAdj = StrHueAdj.ulHueAdj;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetFiltEffect
//======================================================================
unsigned long CImageLibCtrl::GetFiltEffect( unsigned long* pulFiltEffect )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	unsigned long ulErr	= kNkfl_Code_None;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_FilterEffect & ulRawDevelopInfo )
	{				
		NkflRawDevelopment_FilterEffect StrFiltEffect = {0};			
		StrFiltEffect.ulSize = sizeof(NkflRawDevelopment_FilterEffect);
		
		ulErr = GetRawDevelopmentParam( kNkfl_RawDevelopment_FilterEffect, &StrFiltEffect );
		if( ulErr == kNkfl_Code_None )
		{
			*pulFiltEffect = StrFiltEffect.ulFilterEffect;
		}	
	}
	return ulErr;
}

//======================================================================
//	GetPicCtrl
//======================================================================
unsigned long CImageLibCtrl::GetPicCtrl( NkIL_PicCtrlParam* pStrPicCtrl )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	// get info of application each image process
	unsigned long ulRawDevelopInfo = 0;
	if( kNkfl_Code_None != GetRawDevelopmentInfo( &ulRawDevelopInfo ))
	{
		return kNkfl_Code_Err_Unexpected;
	}

	if( kNkfl_RawDevelopment_PictureControl & ulRawDevelopInfo )
	{				
		m_bApplyPictCtrl = true;
		pStrPicCtrl->ulSize		= sizeof(NkflRawDevelopment_PictureControl);
		return GetRawDevelopmentParam( kNkfl_RawDevelopment_PictureControl, pStrPicCtrl );
	}
	return kNkfl_Code_None;
}

//======================================================================
//	SetRawQuality
//======================================================================
unsigned long CImageLibCtrl::SetRawQuality( unsigned long ulRawQuality )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_RawQuality StrRawQuality = {0};
	StrRawQuality.ulSize		= sizeof(NkflRawDevelopment_RawQuality);
	StrRawQuality.ulQuality		= ulRawQuality;

	return RawDevelopment( kNkfl_RawDevelopment_RawQuality, &StrRawQuality);
}

//======================================================================
//	SetParamSettings
//======================================================================
unsigned long CImageLibCtrl::SetParamSettings( unsigned long ulParamSet )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;	

	NkflRawDevelopment_RawParameterSet StrParamSet;			
	StrParamSet.ulSize			= sizeof(NkflRawDevelopment_RawParameterSet);
	StrParamSet.ulParamterSet	= ulParamSet;

	return RawDevelopment( kNkfl_RawDevelopment_RawParameterSet, &StrParamSet );
}

//======================================================================
//	SetExpComp
//======================================================================
unsigned long CImageLibCtrl::SetExpComp( double dbExpComp )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_ExpComp StrExpComp = {0};			
	StrExpComp.ulSize		= sizeof(NkflRawDevelopment_ExpComp);
	StrExpComp.dbExpComp	= dbExpComp;

	return RawDevelopment( kNkfl_RawDevelopment_ExpComp, &StrExpComp );	
}

//======================================================================
//	SetWBInfo
//======================================================================
unsigned long CImageLibCtrl::SetWBInfo( NkIL_WBInfo StrWBInfo )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_WBAdj StrWBAdj = {0};			
	StrWBAdj.ulSize		= sizeof(NkflRawDevelopment_WBAdj);
	StrWBAdj.ulMWB		= StrWBInfo.ulMWB;
	StrWBAdj.lColorTemp	= StrWBInfo.lColorTemp;
	StrWBAdj.rgb		= StrWBInfo.rgb;

	return RawDevelopment( kNkfl_RawDevelopment_WBAdjustment, &StrWBAdj );	
}

//======================================================================
//	SetTint
//======================================================================
unsigned long CImageLibCtrl::SetTint( long lTint )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_Tint StrTint = {0};			
	StrTint.ulSize		= sizeof(NkflRawDevelopment_Tint);
	StrTint.lTint		= lTint;

	return RawDevelopment(  kNkfl_RawDevelopment_Tint, &StrTint );	
}

//======================================================================
//	SetNR
//======================================================================
unsigned long CImageLibCtrl::SetNR( unsigned long ulNR )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_NR StrNR = {0};			
	StrNR.ulSize		= sizeof(NkflRawDevelopment_NR);
	StrNR.ulNRType		= ulNR;

	return RawDevelopment(  kNkfl_RawDevelopment_NR, &StrNR );	
}

//======================================================================
//	SetADL
//======================================================================
unsigned long CImageLibCtrl::SetADL( unsigned long ulADL )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_ActiveDLighting StrADL = {0};			
	StrADL.ulSize				= sizeof(NkflRawDevelopment_ActiveDLighting);
	StrADL.ulActiveDLighting	= ulADL;

	return RawDevelopment(  kNkfl_RawDevelopment_ActiveDLighting, &StrADL );	
}

//======================================================================
//	SetColorMode
//======================================================================
unsigned long CImageLibCtrl::SetColorMode( unsigned long ulColorMode )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_ColorMode StrColorMode = {0};			
	StrColorMode.ulSize			= sizeof(NkflRawDevelopment_ColorMode);
	StrColorMode.ulColorMode	= ulColorMode;

	return RawDevelopment(  kNkfl_RawDevelopment_ColorMode, &StrColorMode );	
}

//======================================================================
//	SetSharpness
//======================================================================
unsigned long CImageLibCtrl::SetSharpness( unsigned long ulSharpness )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_Sharpness StrSharpness = {0};			
	StrSharpness.ulSize			= sizeof(NkflRawDevelopment_Sharpness);
	StrSharpness.ulSharpness	= ulSharpness;

	return RawDevelopment(  kNkfl_RawDevelopment_Sharpness, &StrSharpness );	
}

//======================================================================
//	SetToneComp
//======================================================================
unsigned long CImageLibCtrl::SetToneComp( unsigned long ulToneComp )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_ToneComp StrToneComp = {0};			
	StrToneComp.ulSize		= sizeof(NkflRawDevelopment_ToneComp);
	StrToneComp.ulToneComp	= ulToneComp;

	return RawDevelopment(  kNkfl_RawDevelopment_ToneComp, &StrToneComp );	
}

//======================================================================
//	SetSaturation
//======================================================================
unsigned long CImageLibCtrl::SetSaturation( unsigned long ulSaturation )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_Saturation StrSaturation = {0};			
	StrSaturation.ulSize		= sizeof(NkflRawDevelopment_Saturation);
	StrSaturation.ulSaturation	= ulSaturation;

	return RawDevelopment(  kNkfl_RawDevelopment_Saturation, &StrSaturation );	
}

//======================================================================
//	SetHueAdj
//======================================================================
unsigned long CImageLibCtrl::SetHueAdj( long lHueAdj )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_HueAdj StrHueAdj = {0};			
	StrHueAdj.ulSize	= sizeof(NkflRawDevelopment_HueAdj);
	StrHueAdj.ulHueAdj	= lHueAdj;

	return RawDevelopment(  kNkfl_RawDevelopment_HueAdjustment, &StrHueAdj );	
}

//======================================================================
//	SetFiltEffect
//======================================================================
unsigned long CImageLibCtrl::SetFiltEffect( unsigned long ulFiltEffect )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	NkflRawDevelopment_FilterEffect StrFiltEffect = {0};			
	StrFiltEffect.ulSize			= sizeof(NkflRawDevelopment_FilterEffect);
	StrFiltEffect.ulFilterEffect	= ulFiltEffect;

	return RawDevelopment(  kNkfl_RawDevelopment_FilterEffect, &StrFiltEffect );	
}

//======================================================================
//	GetPicCtrl
//======================================================================
unsigned long CImageLibCtrl::SetPicCtrl( NkIL_PicCtrlParam StrPicCtrl )
{
	if ( !s_pEntryFunc )	return kNkfl_Code_Err_Unexpected;

	StrPicCtrl.ulSize		= sizeof(NkflRawDevelopment_PictureControl);
	
	return RawDevelopment( kNkfl_RawDevelopment_PictureControl, &StrPicCtrl );
}