## jd_prepare

The jd_prepare function analyzes the JPEG data and create a decompression object for subsequnet decompression process.

    JRESULT jd_prepare (
      JDEC* jdec,        /* Pointer to blank decompression object */
      size_t (*infunc)(JDEC*, uint8_t*, size_t), /* Pointer to input function */
      void* work,        /* Pointer to the work area */
      size_t sz_work,    /* Size of the work area */
      void* device       /* Session identifier for the session */
    );

#### Parameters

jdec
  Specifies the decompression object to be initialized. The decompression object is used by subsequent decompression process.
input
  Pointer to the user defined data input function. The `jd_prepare` and `jd_decomp` function call this function to read the JPEG data from the input stream.
work
  Pointer to the work area for this session. It should be aligned to the word boundary, or it can result a hard fault on some processors.
sz_work
  Size of the work area in unit of byte. TJpgDec requires upto 3092 bytes of work area depends on the built-in parameter tables of the JPEG image to deccompress.
device
  Pointer to the user defined session identifier for this session. It is stored to the member `device` in the decompression object. It can be refered by I/O functions to identify the corresponding session. If this feature is not needed, set null and do not care about this.

#### Return Values

JDR_OK
  Function succeeded and the decompression object is valid.
JDR_INP
  An error occured in input function due to a hard error or wrong stream termination.
JDR_MEM1
  Insufficient work area for this JPEG image.
JDR_MEM2
  Insufficient input buffer for this JPEG image. JD_SZBUF may be too small.
JDR_FMT1
  Data format error. The JPEG data can be collapted.
JDR_FMT3
  Not supported JPEG standard. May be a progressive JPEG image.

#### Description

The jd_prepare function is the first stage of a JPEG decompression session. It analyzes the JPEG image and create parameter tables for decompression. After the function succeeded, the session gets ready to decompress the JPEG image by the jd_decomp fnction. The application program can refer the dimensions of the JPEG image stored in the decompression object. These information will be used to configure the output device and parameters for subsequent decompression stage.

Return