#ifndef _JPEG_H
#define _JPEG_H

#include "GenericTypeDefs.h"
#include "SSD1928.h"
#include "fish.h"



typedef enum 
{
	JPEG_DECODE_STAGE_INIT=0,
	JPEG_DECODE_STAGE_HEADER,
	JPEG_DECODE_STAGE_HEADER_COMPLETE,
	JPEG_DECODE_STAGE_BODY,
	JPEG_DECODE_STAGE_BODY_COMPLETE
} PROGRESS;

typedef struct _JPEG_DECODE
{
	// Input by User
    BYTE *jpeg_buffer;
    LONG jpeg_buffer_size;
	LONG jpeg_buffer_ptr;
	LONG temp_count;

	LONG jpeg_file_size;

    LONG fifo_addr;
    LONG fifo_size;
	LONG fifo_ptr;
    LONG raw_addr;
    LONG raw_maxsize;
	LONG raw_ptr;

    LONG clip_x1;
    LONG clip_y1;
    LONG clip_x2;
    LONG clip_y2;

    LONG resize_factor;
    LONG resize_method;

	// Private, Used by library only
	PROGRESS stage;
	LONG op_mode;

    LONG orig_width;
    LONG orig_height;

    LONG clip_width;
    LONG clip_height;

	LONG resize_addr;
    LONG resize_width;
    LONG resize_height;

    LONG decoded_width;
    LONG aligned_width;
} JPEG_DECODE;

typedef struct _JPEG_ENCODE
{
	// Input by user
	DWORD dest_offset;
	DWORD fifo_offset;
	DWORD fifo_size;
	DWORD dv_offset;
	DWORD maxsize;
	DWORD hratio;
	DWORD vratio;
	DWORD motion;

	// Output by program
	DWORD size;

	// Private: Used by library only
	DWORD fifo_ptr;	
	DWORD byte_got;
	BYTE dc_mode;
	DWORD not_reset;

} JPEG_ENCODE;

void ssd1928_jpeg_init(void);
void ssd1928_jpeg_decode_prepare(JPEG_DECODE *jpeg);
LONG ssd1928_jpeg_decode_header(JPEG_DECODE *jpeg);
LONG ssd1928_jpeg_decode_clip(JPEG_DECODE *jpeg);
LONG ssd1928_jpeg_decode_resize(JPEG_DECODE *jpeg);
LONG ssd1928_jpeg_decode_start(JPEG_DECODE *jpeg);
LONG ssd1928_jpeg_decode_data(JPEG_DECODE *jpeg);
LONG ssd1928_jpeg_decode_wait(JPEG_DECODE *jpeg);
LONG ssd1928_jpeg_decode_stop(void);

LONG ssd1928_jpeg_encode_start(JPEG_ENCODE *jpeg);
LONG ssd1928_jpeg_encode_data(JPEG_ENCODE *jpeg);
LONG ssd1928_jpeg_encode_stop(JPEG_ENCODE *jpeg);

#endif

