// Filename : extr.h
//
// This file was initially generated by SpaceStudio but is meant to be modified
// by the user.
#ifndef EXTR_H
#define EXTR_H

#include "spacecomp.h"
#include "abstract_module.h"
#include "application_definitions.h"

// Do NOT move macros, functions and includes beginning with "spacecomp".

class extr: public abstract_module {
	SPACECOMP_START(extr, INDEX, extr);

public:
	extr(SPACECOMP_CTOR_PARAMS(extr, INDEX));

	void thread(SPACECOMP_THREAD_PARAMS(extr, INDEX, thread));

private:
	void communicate_IJPEG(unsigned short command);
	uint16_t  decode_interleaved_scan();
	void  initialize();
	void end_application();

	unsigned char  m_currentJPEGImageNo;
	unsigned char  m_currentBitmapImage;
	unsigned long m_decompressedImageAddr[MAX_NB_IMAGE];   // Adresses of decompressed images

	unsigned long m_infoImageHeaderAdd; // latest image header jpeg data address,

	unsigned long m_inputAdd;				// latest jpeg data address, multiple of 4 and 0x20 afetr header

	unsigned long m_jpegAddress ; // address of very first image in memory
	unsigned long m_jpegDist;		// distance between 2 images

	unsigned char m_currentHuffmanComponent;

	SPACE_ALIGNED uint8_t m_inputBuffer[4];
	bool m_bufferValid;

	//
	// JPEG related
	//
	JPEG_DECODER_STRUCTURE m_jpeg_decoder_structure;

	uint8_t read_next_marker();
	uint8_t read_soi_marker ();
	uint8_t read_sof_marker ();
	uint8_t read_dqt_marker ();
	uint8_t skip_marker ();
	uint8_t read_8_bits ();
	uint16_t read_16_bits ();
	void skip_bytes(uint16_t nbBytes);

	SPACECOMP_END(extr, INDEX, extr);
};

#endif
