/*---------------------------------------------------------------------------*
  Project:  TwlSDK - SSP - include
  File:     jpegdec.h

  Copyright 2007-2008 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-01-09#$
  $Rev: 9810 $
  $Author: kitase_hirotake $
 *---------------------------------------------------------------------------*/

#ifndef TWL_SSP_JPEGDEC_H_
#define TWL_SSP_JPEGDEC_H_

#include <twl/ssp/common/ssp_jpeg_type.h>
#include <twl/ssp/ARM9/exifdec.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <twl/types.h>

/*---------------------------------------------------------------------------*
  Name:         SSP_CheckJpegDecoderSign

  Description:  Only checks a JPEG file's signature.

  Arguments:    data: JPEG file
                size: JPEG file size

  Returns:      Returns TRUE on success.
 *---------------------------------------------------------------------------*/
BOOL SSP_CheckJpegDecoderSign(u8* data, u32 size);

/*---------------------------------------------------------------------------*
  Name:         SSP_StartJpegDecoder

  Description:  Decodes a JPEG file.

  Arguments:    data: JPEG file
                size: JPEG file size
                dst: Destination buffer for decoding (now only RGB555)
                width: Gives the maximum image width as an argument.
                         When the image is decoded successfully, its width will be returned.
                height: Gives the maximum image height as an argument.
                         When the image is decoded successfully, its height will be returned.
                option: Options (bitwise logical OR)
                         SSP_JPEG_RGB555: Decode in the RGB555 format.
                                Currently, even if this is not specified, data will be decoded in the RGB555 format.
                         SSP_JPEG_THUMBNAIL: Decode thumbnails. When this is unspecified, the main image will be decoded.
                         SSP_JPEG_EXIF: Get only EXIF information

  Returns:      Returns TRUE on success.
 *---------------------------------------------------------------------------*/
BOOL SSP_StartJpegDecoder(u8* data, u32 size, void* dst, s16* width, s16* height, u32 option);

/*---------------------------------------------------------------------------*
  Name:         SSP_StartJpegDecoderEx

  Description:  Specifies whether to use a signature and decode a JPEG file.

  Arguments:    data: JPEG file
                size: JPEG file size
                dst: Destination buffer for decoding (now only RGB555)
                width: Gives the maximum image width as an argument.
                         When the image is decoded successfully, its width will be returned.
                height: Gives the maximum image height as an argument.
                         When the image is decoded successfully, its height will be returned.
                option: Options (bitwise logical OR)
                         SSP_JPEG_RGB555: Decode in the RGB555 format.
                                Currently, even if this is not specified, data will be decoded in the RGB555 format.
                         SSP_JPEG_THUMBNAIL: Decode thumbnails. When this is unspecified, the main image will be decoded.
                         SSP_JPEG_EXIF: Get only EXIF information
                sign: Specify TRUE to check the signature.

  Returns:      Returns TRUE on success.
 *---------------------------------------------------------------------------*/
static inline BOOL SSP_StartJpegDecoderEx(u8* data, u32 size, void* dst, s16* width, s16* height, u32 option, BOOL sign)
{
    BOOL result;
    
    (void)SSP_SetJpegDecoderSignMode(sign);
    result = SSP_StartJpegDecoder(data, size, dst, width, height, option);
    (void)SSP_SetJpegDecoderSignMode(FALSE);
    
    return result;
}

/*---------------------------------------------------------------------------*
  Name:         SSP_ExtractJpegDecoderExif

  Description:  Extracts only EXIF information from a JPEG file.
                Use the various get functions to get the actual extracted values.

  Arguments:    data: JPEG file
                size: JPEG file size
                
  Returns:      Returns TRUE on success.
 *---------------------------------------------------------------------------*/
static inline BOOL SSP_ExtractJpegDecoderExif(u8* data, u32 size)
{
    return SSP_StartJpegDecoder(data, size, 0, 0, 0, SSP_JPEG_EXIF);
}

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

/* TWL_SSP_JPEGDEC_H_ */
#endif
