/////////////////////////////////////////////////////////////
// CINEMA 4D SDK                                           //
/////////////////////////////////////////////////////////////
// (c) 1989-2009 MAXON Computer GmbH, all rights reserved  //
/////////////////////////////////////////////////////////////
#include "lib_pictureviewer.h"

PictureViewLibrary* picture_viewer_lib_cache = NULL;

static PictureViewLibrary* CheckPictureViewLib(LONG offset)
{
	return (PictureViewLibrary*)CheckLib(C4D_PICTUREVIEWER_LIBRARY_ID, offset, (C4DLibrary**)&picture_viewer_lib_cache);
}

PictureViewer* CreatePictureViewer(LONG type)
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, CreatePictureViewer));
	if (!lib || !lib->CreatePictureViewer) return NULL;

	return (PictureViewer*)lib->CreatePictureViewer(type);
}

Bool PictureViewer::Open()
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, Open));
	if (!lib || !lib->Open) return FALSE;
	return (((iPictureViewer*)this)->*(lib->Open))(); 
}

Bool PictureViewer::ShowFile(const Filename &File)
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, ShowFile));
	if (!lib || !lib->ShowFile) return FALSE;
	return (((iPictureViewer*)this)->*(lib->ShowFile))(File);  
}

Bool PictureViewer::ShowImage(BaseBitmap *Bmp, const String &Name)
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, ShowImage));
	if (!lib || !lib->ShowImage) return FALSE;
	return (((iPictureViewer*)this)->*(lib->ShowImage))(Bmp,Name);  
}

Bool PictureViewer::AddSound(GeListNode *pNode, const BaseTime &from, const BaseTime &to, BaseSound *sound)
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, AddSound));
	if (!lib || !lib->AddSound) return FALSE;
	return (((iPictureViewer*)this)->*(lib->AddSound))(pNode,from,to,sound);  
}

GeListNode* PictureViewer::OpenRendering(const String &Name,Real Fps,LONG lStart,LONG lEnd,BaseContainer* bcrender )
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, OpenRendering));
	if (!lib || !lib->OpenRendering) return NULL;
	return (((iPictureViewer*)this)->*(lib->OpenRendering))(Name,Fps,lStart,lEnd,bcrender); 
}

Bool PictureViewer::Message(LONG id, void *t_data)
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, Message));
	if (!lib || !lib->Message) return FALSE;
	return (((iPictureViewer*)this)->*(lib->Message))(id,t_data); 
}


GeListNode *PictureViewer::BeginRendering(GeListNode *pNode, BaseBitmap *Bmp,const String &Name,const BaseTime &Time,LONG Frame,
																	 const Filename &savename,Bool fully_saved,const Filename &dispname, LONG lStream, STEREOTYPE lStereoType)
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, BeginRendering));
	if (!lib || !lib->BeginRendering) return NULL;
	return (((iPictureViewer*)this)->*(lib->BeginRendering))(pNode,Bmp,Name,Time,Frame,savename,fully_saved,dispname,lStream,lStereoType);  
}

Bool PictureViewer::EndRendering(GeListNode *beginNode, PVFRAME_FINISH finish, Bool incomplete, PVFinalizeImage *callback, void *userdata)
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, EndRendering));
	if (!lib || !lib->EndRendering) return FALSE;
	return (((iPictureViewer*)this)->*(lib->EndRendering))(beginNode,finish,incomplete,callback,userdata);  
}

Bool PictureViewer::CloseRendering(GeListNode *&pNode)
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, CloseRendering));
	if (!lib || !lib->CloseRendering) return FALSE;
	return (((iPictureViewer*)this)->*(lib->CloseRendering))(pNode); 
}

Bool PictureViewer::CheckHDMemory()
{
	PictureViewLibrary *lib = CheckPictureViewLib(LIBOFFSET(PictureViewLibrary, CheckHDMemory));
	if (!lib || !lib->CheckHDMemory) return FALSE;
	return (((iPictureViewer*)this)->*(lib->CheckHDMemory))(); 
}
