/*=====================================================================
 IMPress V3

 Copyright (C) 2007-2008 IT Access.,Co.Ltd. All Rights Reserved.

 This software is the confidential and proprietary information
 of IT Access.,Co.Ltd.
=====================================================================*/
#ifndef _INC_LSIMAGE_H
#define _INC_LSIMAGE_H

#ifdef __cplusplus
extern "C" {		/* Assume C declarations for C++ */
#endif				/* __cplusplus */

/*=====================================================================
	Color mode
=====================================================================*/
/* 1byte per data */
#if defined( __GNUC__ )	/* GNU-C */
//	#pragma pack(1)		// BUG, cause <sizeof(LsJpgInfo)> dismatch inside jpegdec.c 10/02/10
//	#define _PACK_		__attribute__ ((packed)) <- inhibit warning messages
	#define _PACK_
	#define _GCC_PACK_	__attribute__ ((packed))
#elif defined( WIN32 )	/* Windows */
	#pragma pack( push, 1 )
	#define _PACK_
	#define _GCC_PACK_
#elif defined( _SHC )	/* HEW */
/*	#pragma pack1  <- not supported until SHC Ver.8 */
	#define _PACK_
	#define _GCC_PACK_
#else
	#define _PACK_
	#define _GCC_PACK_
#endif

typedef struct {
	unsigned char	b			_PACK_;
	unsigned char	g			_PACK_;
	unsigned char	r			_PACK_;
} _GCC_PACK_ LSRGB				_PACK_;

typedef struct {
	unsigned char	b			_PACK_;
	unsigned char	g			_PACK_;
	unsigned char	r			_PACK_;
	unsigned char	a			_PACK_;
} _GCC_PACK_ LSRGBA				_PACK_;

typedef struct {
	unsigned short	b			_PACK_;
	unsigned short	g			_PACK_;
	unsigned short	r			_PACK_;
	unsigned short	a			_PACK_;
} _GCC_PACK_ LSRGBAW			_PACK_;

typedef struct {
	unsigned short	b			_PACK_;
	unsigned short	g			_PACK_;
	unsigned short	r			_PACK_;
} _GCC_PACK_ LSRGBW				_PACK_;

typedef struct {
	unsigned char	b			_PACK_;
	unsigned char	g			_PACK_;
	unsigned char	r			_PACK_;
	unsigned char	a			_PACK_;
} _GCC_PACK_ LSPAL				_PACK_;

typedef struct {
	unsigned char	y			_PACK_;
	char			c			_PACK_;
} _GCC_PACK_ LSYUV				_PACK_;

typedef struct {
	unsigned short	y			_PACK_;
	short			c			_PACK_;
} _GCC_PACK_ LSYUVW				_PACK_;

typedef struct {
	unsigned char	y			_PACK_;
	unsigned char	u			_PACK_;
	unsigned char	v			_PACK_;
} _GCC_PACK_ LSYUV4				_PACK_;

typedef struct {
	unsigned char	l			_PACK_;
	unsigned char	a			_PACK_;
	unsigned char	b			_PACK_;
} _GCC_PACK_ LSLAB				_PACK_;

/* YCbCr structures */
/* 444 */
typedef struct {
	unsigned char	y			_PACK_;
	unsigned char   cb			_PACK_;
	unsigned char   cr			_PACK_;
} _GCC_PACK_ LSYCC444			_PACK_;

/* 422 */
typedef struct {
	unsigned char	y1			_PACK_;
	unsigned char	y2			_PACK_;
	unsigned char   cb			_PACK_;
	unsigned char   cr			_PACK_;
} _GCC_PACK_ LSYCC422			_PACK_;

/* 420 */
typedef struct {
	unsigned char	y1			_PACK_;
	unsigned char	y2			_PACK_;
	unsigned char	y3			_PACK_;
	unsigned char	y4			_PACK_;
	unsigned char   cb			_PACK_;
	unsigned char   cr			_PACK_;
} _GCC_PACK_ LSYCC420			_PACK_;

/* 422P */
typedef struct {
	unsigned char	*y			_PACK_;
	unsigned char   *c			_PACK_;
} _GCC_PACK_ LSYCC422P			_PACK_;

typedef struct  {
	unsigned char	k			_PACK_;
	unsigned char	a			_PACK_;
} _GCC_PACK_ LSGRAYA			_PACK_;

/* High color */
typedef	unsigned short	LSHIGH;

#if defined( WIN32 )	/* Windows */
#pragma pack(pop)
#endif

typedef struct {
	unsigned short	x;
	unsigned short	y;
	unsigned short	w;
	unsigned short	h;
} LSRECT;

typedef struct {
	long			mode;
	unsigned short	width;
	unsigned short	height;
	long			lineint;
	signed char		fmt;		/* bit width (from -16 to 16 ) */
	unsigned char	palfmt;		/* = PhotometricIntepritation : LS_MODE_MONO */
	unsigned short	palcount;
	void			*palbuf;
	void			*object;
} LsImageInfo;

typedef struct {
	long			mode;
	unsigned short	width;
	unsigned short	height;
	long			lineint;
	signed char		fmt;		/* bit width (from -16 to 16 ) */
	unsigned char	palfmt;		/* = PhotometricIntepritation : LS_MODE_MONO */
	unsigned short	palcount;
	void			*palbuf;
	void			*object;

	void			*pixels;
	unsigned long	size;
} LsImage;

/* Thumbnail */
typedef struct {
	unsigned short	width;
	unsigned short	height;
	void			*data;
	unsigned long	size;
	unsigned char	aspect;
	unsigned char	pad1;	// Add 2010/03/05 to avoid padding difference 
	unsigned short	pad2;	// Add 2010/03/05 to avoid padding difference
	LSRGB		*margincol;
} LsThm;

typedef enum{

	LS_MODE_UNK		= ( 0x0000 ),
	LS_MODE_RGB		= ( 0x0001 ),
	LS_MODE_YUV		= ( 0x0002 ),
	LS_MODE_GRAY	= ( 0x0003 ),
	LS_MODE_INDEX	= ( 0x0004 ),
	LS_MODE_MONO	= ( 0x0005 ),

	LS_MODE_RGBA	= ( 0x0006 ),
	LS_MODE_GRAYA	= ( 0x0007 ),
	
	/* 2Byte Option */
	LS_MODE_RGBW	= ( 0x0008 ),
	LS_MODE_YUVW	= ( 0x0009 ),
	LS_MODE_GRAYW	= ( 0x000a ),

	/* Option */
	LS_MODE_LAB		= ( 0x000b ),
	LS_MODE_HIGH	= ( 0x000c ),

	/* Unsupported */
	LS_MODE_YCC444	= ( 0x000d ),
	LS_MODE_YCC422	= ( 0x000e ),
	LS_MODE_YCC420	= ( 0x000f ),
	LS_MODE_YCC422P	= ( 0x0010 ),

} LS_IMAGE_MODE;

/* palfmt (LS_MODE_MONO) */
#define	LS_BLACKISZERO	0
#define	LS_WHITEISZERO	1

/*=========================================================
	YUV<->RGB Matrix
=========================================================*/
typedef struct {
	long	m11;	long	m12;	long	m13;
	long	m21;	long	m22;	long	m23;
	long	m31;	long	m32;	long	m33;
} LsMatrix;

/*=========================================================
	Convert colorspace ( Unsupported )
=========================================================*/
int LsLibFunc LsYuvToRgb( LSYUV *yuv, LSRGB *rgb, unsigned short width );
int LsLibFunc LsLabToRgb( LSLAB *lab, LSRGB *rgb, unsigned short width );
int LsLibFunc LsHighToRgb( LSHIGH *high, LSRGB *rgb, unsigned short width );

int LsLibFunc LsYuvWToRgbW( LSYUVW *yuv, LSRGBW *rgb, unsigned short width );
#ifdef __cplusplus
	}	
#endif

#endif					/* _INC_LSIMAGE_H */

