/*---------------------------------------------------------------------------*
  Project:  TwlSDK - TCL - include
  File:     api.h

  Copyright 2008-2009 Nintendo. All rights reserved.

  These coded instructions, statements, and computer programs contain
  proprietary information of Nintendo of America Inc. and/or Nintendo
  Company Ltd., and are protected by Federal copyright law. They may
  not be disclosed to third parties or copied or duplicated in any form,
  in whole or in part, without the prior written consent of Nintendo.

  $Date:: 2009-06-04#$
  $Rev: 10698 $
  $Author: okubata_ryoma $
 *---------------------------------------------------------------------------*/
#ifndef TWL_TCL_API_H_
#define TWL_TCL_API_H_

#include <twl/misc.h>
#include <twl/types.h>
#include <nitro/fs.h>
#include <twl/tcl/ARM9/types.h>

#ifdef __cplusplus
extern "C" {
#endif

/*-------------------------------------------------------------------------*
  Name: TCL_GetTableBufferSize

  Description: Buffer size needed to load the management file.

  Arguments: 

  Returns: Buffer size.
*-------------------------------------------------------------------------*/
extern u32 TCL_GetTableBufferSize( void );

/*-------------------------------------------------------------------------*
  Name: TCL_GetWorkBufferSize

  Description: Working buffer size needed to use the management file.

  Arguments: 

  Returns: Buffer size.
*-------------------------------------------------------------------------*/
extern u32 TCL_GetWorkBufferSize( void );

/*-------------------------------------------------------------------------*
  Name: TCL_LoadTable

  Description: Loads the management table.
               Allocate a 32-byte aligned buffer.

  Arguments: pAccessor: Accessor
             tableBuffer: Loading buffer
             tableBufferSize: Buffer size.
                               (The size provided by the TCL_GetTableBufferSize function.)
             workBuffer: Working buffer
             workBufferSize: Working buffer size.
                               (The size provided by the TCL_GetWorkBufferSize function.)
             pFSResult: Where the FSResult is stored when an error is generated by an FS function.

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_LoadTable( TCLAccessor* pAccessor ,
                                void* tableBuffer ,
                                u32 tableBufferSize ,
                                void* workBuffer ,
                                u32 workBufferSize ,
                                FSResult* pFSResult );

/*-------------------------------------------------------------------------*
  Name: TCL_CreateTable

  Description: Creates management table.
               Allocate a 32-byte aligned buffer.

  Arguments: pAccessor: Accessor
             tableBuffer: Loading buffer
             tableBufferSize: Buffer size.
                               (The size provided by the TCL_GetTableBufferSize function.)
             workBuffer: Working buffer
             workBufferSize: Working buffer size.
                               (The size provided by the TCL_GetWorkBufferSize function.)
             pFSResult: Where the FSResult is stored when an error is generated by an FS function.

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_CreateTable( TCLAccessor* pAccessor ,
                                  void* tableBuffer ,
                                  u32 tableBufferSize ,
                                  void* workBuffer ,
                                  u32 workBufferSize ,
                                  FSResult* pFSResult );

/*-------------------------------------------------------------------------*
  Name: TCL_RepairTable

  Description: Restores management table.

  Arguments: pAccessor: Accessor
             pFSResult: Where the FSResult is stored when an error is generated by an FS function.

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_RepairTable( TCLAccessor* pAccessor , FSResult* pFSResult );

/*-------------------------------------------------------------------------*
  Name: TCL_SortTable

  Description: Sorts management table.

  Arguments: pAccessor: Accessor
             sortType: Sort type

  Returns: None.
*-------------------------------------------------------------------------*/
extern void TCL_SortTable( TCLAccessor* pAccessor , TCLSortType sortType );

/*-------------------------------------------------------------------------*
  Name: TCL_InitSearchObject

  Description: Initializes search object.

  Arguments: pSearchObj: Search object
             condition: Search condition

  Returns: None.
*-------------------------------------------------------------------------*/
extern void TCL_InitSearchObject( TCLSearchObject* pSearchObj , u32 condition );

/*-------------------------------------------------------------------------*
  Name: TCL_GetNumPictures

  Description: How many photos match the search conditions?

  Arguments: pAccessor: Accessor
             pSearchObj: Search object

  Returns: Number of photos.
*-------------------------------------------------------------------------*/
extern int TCL_GetNumPictures( const TCLAccessor* pAccessor , const TCLSearchObject* pSearchObj );

/*-------------------------------------------------------------------------*
  Name: TCL_SearchNextPictureInfo

  Description: Gets the next piece of photo information that matches the search conditions.

  Arguments: pAccessor: Accessor
             ppPicInfo: Photo information storage location
             pSearchObj: Search object

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_SearchNextPictureInfo( const TCLAccessor* pAccessor ,
                                            const TCLPictureInfo** ppPicInfo ,
                                            TCLSearchObject* pSearchObj );

/*-------------------------------------------------------------------------*
  Name: TCL_SearchPictureInfoByIndex

  Description: Gets photo information that matches the search conditions at the specified index.
               

  Arguments: pAccessor: Accessor
             ppPicInfo: Photo information storage location
             pSearchObj: Search object
             index: Index

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_SearchPictureInfoByIndex( const TCLAccessor* pAccessor ,
                                               const TCLPictureInfo** ppPicInfo ,
                                               const TCLSearchObject* pSearchObj ,
                                               int index );

/*-------------------------------------------------------------------------*
  Name: TCL_SearchNextPicturePath

  Description: Gets the next photo path that matches the search conditions.

  Arguments: pAccessor: Accessor
             path: Path storage location
             len: Path length
             pSearchObj: Search object

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_SearchNextPicturePath( const TCLAccessor* pAccessor ,
                                            char* path ,
                                            size_t len ,
                                            TCLSearchObject* pSearchObj );

/*-------------------------------------------------------------------------*
  Name: TCL_SearchPicturePathByIndex

  Description: Gets the photo path that matches the search conditions at the specified index.
               

  Arguments: pAccessor: Accessor
             path: Path storage location
             len: Path length
             pSearchObj: Search object
             index: Index

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_SearchPicturePathByIndex( const TCLAccessor* pAccessor ,
                                               char* path ,
                                               size_t len ,
                                               const TCLSearchObject* pSearchObj ,
                                               int index );

/*-------------------------------------------------------------------------*
  Name: TCL_PrintPicturePath

  Description: Gets photo path.

  Arguments: path: Path storage location
             len: Path length
             pPicInfo: Photo information

  Returns: STD_TSNPrintf return value.
*-------------------------------------------------------------------------*/
extern int TCL_PrintPicturePath( char* path ,
                                 size_t len ,
                                 const TCLPictureInfo* pPicInfo );

/*-------------------------------------------------------------------------*
  Name: TCL_GetPictureInfoFromPath

  Description: Gets photo information from a path.

  Arguments: pAccessor: Accessor
             pPicInfo: Photo information
             path: Path storage location
             len: Path length

  Returns: Returns TRUE if it could be obtained.
*-------------------------------------------------------------------------*/
extern BOOL TCL_GetPictureInfoFromPath( const TCLAccessor* pAccessor ,
                          TCLPictureInfo** ppPicInfo ,
                          const char* path ,
                          size_t len );

/*-------------------------------------------------------------------------*
  Name: TCL_CalcNumEnableToTakePictures

  Description: Calculates how many photos can be taken.

  Arguments: pAccessor: Accessor

  Returns: Number of photos that can be taken. (A negative number indicates some kind of failure.)
*-------------------------------------------------------------------------*/
extern int TCL_CalcNumEnableToTakePictures( const TCLAccessor* pAccessor );

/*-------------------------------------------------------------------------*
  Name: TCL_GetJpegEncoderBufferSize

  Description: Returns the buffer size required for JPEG encoding.
               Calls the SSP_GetJpegEncoderBufferSize function.

  Arguments: option: Option to pass to the SSP_GetJpegEncoderBufferSize function.

  Returns: Return value of the SSP_GetJpegEncoderBufferSize function.
*-------------------------------------------------------------------------*/
extern u32 TCL_GetJpegEncoderBufferSize( u32 option );

/*-------------------------------------------------------------------------*
  Name: TCL_EncodeAndWritePicture

  Description: Performs JPEG encoding of image and saves it. Also updates the management file.
               Calls the TCL_GetCurrentSecond function.

  Arguments: pAccessor: Accessor
             imageBuffer: Image buffer
             jpegBuffer: JPEG buffer
             jpegBufferSize: JPEG buffer size
             workBuffer: Work buffer necessary for JPEG encoding
             quality: JPEG encoding quality
             option: JPEG encoding options
             pFSResult: Where the FSResult is stored when an error is generated by an FS function

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_EncodeAndWritePicture( TCLAccessor* pAccessor ,
                                            const void* imageBuffer ,
                                            u8* jpegBuffer ,
                                            u32 jpegBufferSize ,
                                            u8* workBuffer ,
                                            u32 quality ,
                                            u32 option ,
                                            FSResult* pFSResult );

/*-------------------------------------------------------------------------*
  Name: TCL_EncodeAndWritePictureEx

  Description: Performs JPEG encoding (user maker note settings) of image and saves it. Also updates the management file.
               Calls the TCL_GetCurrentSecond function.

  Arguments: pAccessor: Accessor
             imageBuffer: Image buffer
             jpegBuffer: JPEG buffer
             jpegBufferSize: JPEG buffer size
             workBuffer: Work buffer necessary for JPEG encoding
             quality: JPEG encoding quality
             option: JPEG encoding options
             makerNoteBuffer: User maker note buffer
             makerNoteBufferSize: User maker note buffer size
             pFSResult: Where the FSResult is stored when an error is generated by an FS function

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_EncodeAndWritePictureEx( TCLAccessor* pAccessor ,
                                              const void* imageBuffer ,
                                              u8* jpegBuffer ,
                                              u32 jpegBufferSize ,
                                              u8* workBuffer ,
                                              u32 quality ,
                                              u32 option ,
                                              u8* makerNoteBuffer ,
                                              u16 makerNoteBufferSize ,
                                              FSResult* pFSResult );

/*-------------------------------------------------------------------------*
  Name: TCL_GetLastWrittenPicturePath

  Description: Returns path of image written last.

  Arguments:

  Returns: Path of image last written.
*-------------------------------------------------------------------------*/
extern const char* TCL_GetLastWrittenPicturePath( void );

/*-------------------------------------------------------------------------*
  Name: TCL_GetLastWrittenPictureInfo

  Description: Returns TCLPictureInfo for the last image to be written.

  Arguments:

  Returns: TCLPictureInfo of the last image to be written.
*-------------------------------------------------------------------------*/
extern const TCLPictureInfo* TCL_GetLastWrittenPictureInfo( void );

/*-------------------------------------------------------------------------*
  Name: TCL_DecodePicture

  Description: Performs JPEG decoding.

  Arguments: fileBuffer: File buffer
             fileBufferSize: File buffer size
             imageBuffer: Image buffer
             width: Decode image width
             height: Decode image height
             decodeOption: Decode option

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_DecodePicture( u8* fileBuffer ,
                                    u32 fileBufferSize ,
                                    void* imageBuffer ,
                                    s16 width ,
                                    s16 height ,
                                    u32 decodeOption );

/*-------------------------------------------------------------------------*
  Name: TCL_DeletePicture

  Description: Deletes a JPEG file.

  Arguments: pAccessor: Accessor
             pPicInfo: Photo information
             pFSResult: Where the FSResult is stored when an error is generated by an FS function

  Returns: TCLResult.
*-------------------------------------------------------------------------*/
extern TCLResult TCL_DeletePicture( TCLAccessor* pAccessor ,
                                    const TCLPictureInfo* pPicInfo ,
                                    FSResult* pFSResult );

/*-------------------------------------------------------------------------*
  Name: TCL_IsSameImageType

  Description: Whether recognized as same image type.

  Arguments: pPicInfo: Photo information
             pMakerNote: Manufacturer's notes

  Returns: TRUE when recognized as same.
*-------------------------------------------------------------------------*/
extern BOOL TCL_IsSameImageType( const TCLPictureInfo* pPicInfo , const TCLMakerNote* pMakerNote );

/*-------------------------------------------------------------------------*
  Name: TCL_GetCurrentSecond

  Description: Gets the current time (in seconds).
               Calls the RTC_GetDateTime function internally.
               This function is defined with a weak symbol.
               Redefine when exclusive processing for RTC is needed.

  Arguments:

  Returns: Current time (in seconds).
*-------------------------------------------------------------------------*/
extern s64 TCL_GetCurrentSecond( void );

#ifdef __cplusplus
} /* extern "C" */
#endif

/* TWL_TCL_API_H_ */
#endif
