Driver

The JPEG Encoder IP requires a processor to set up the core. This can be any processor. A JPEG encoder driver (prt_jpeg_enc_drv) is provided for this task. It is plain C with no operating system or vendor library behind it, so it ports to whatever core sits next to the IP.

The driver is deliberately small. The encoder has no protocol to run and no link to bring up, so there is no firmware and no system controller behind it — the whole API is a handful of register accesses. One prt_jpeg_enc_ds_struct describes one IP-core; a design with several encoders keeps one of these per core and passes the right one to every call.

The one substantial thing the driver does is build the JPEG header. The hardware does not generate markers: it produces entropy coded data and replays whatever header the host gave it in front of every image. prt_jpeg_enc_cfg assembles that header — SOI, APP0, the two DQT tables, SOF0, the four DHT tables, a COM comment and SOS — and writes it into the core. The comment is padded with spaces so the header ends on an 8-byte boundary, which is what lets the codestream mux hand out whole 64-bit words.

prt_jpeg_enc_cfg also loads the quantization table into the hardware, so it has to be called before the encoder is started. The quality argument sets the image quality: 50 is the standard table of ISO/IEC 10918-1 Annex K, higher gives a better image and a larger codestream. The DQT markers in the header and the table in the hardware both follow from that one argument, so the two cannot disagree about how the image was quantized.

Note

The quality is limited to 90. The quantizer produces 10-bit coefficients and a finer table makes them larger, so beyond that they start to clip — which shows as artefacts in high contrast areas rather than as a codestream that fails to decode.

An IP-core is brought up in this order.

prt_jpeg_enc_init (&jpeg, JPEG_ENC_BASE_ADDR);   // find the IP-core
prt_jpeg_enc_cfg  (&jpeg, 3840, 2160, 50);       // header and quantization table
prt_jpeg_enc_str  (&jpeg);                       // start encoding

From that point on every incoming frame is encoded and appears on the codestream interface. The image resolution is fixed by the header, so a change of video format means calling prt_jpeg_enc_stp, prt_jpeg_enc_cfg with the new size, and prt_jpeg_enc_str again. The same holds for a change of quality: the hardware would pick up a new table at the next frame on its own, but the DQT markers in the header are replayed per image and would then still describe the previous one.

API

This section provides information about the driver API. The functions are grouped the same way as in prt_jpeg_enc_drv.h: setup and control.

Setup

prt_jpeg_enc_init

  • description: Sets the JPEG encoder base address, clears the control register and checks that the core responds.
  • syntax: bool prt_jpeg_enc_init (prt_jpeg_enc_ds_struct *jpeg, uint32_t base);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
    • basebase address
  • returns: true when the identification register reads back correctly, else false.

prt_jpeg_enc_cfg

  • description: Builds the JPEG header for the given image size and quality, writes it into the core and loads the matching quantization table. The header is replayed by the hardware in front of every image, so this only has to be called once per video format.
  • syntax: void prt_jpeg_enc_cfg (prt_jpeg_enc_ds_struct *jpeg, uint16_t width, uint16_t height, uint8_t quality);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
    • widthimage width in pixels
    • heightimage height in lines
    • qualityimage quality, 1 to 90 (PRT_JPEG_ENC_QUALITY_MIN / _MAX). 50 is the standard table of ISO/IEC 10918-1 Annex K; values outside the range are clamped
  • returns: none

prt_jpeg_enc_ver_major

  • description: Returns the major version of the IP-core.
  • syntax: uint8_t prt_jpeg_enc_ver_major (prt_jpeg_enc_ds_struct *jpeg);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
  • returns: major version number.

prt_jpeg_enc_ver_minor

  • description: Returns the minor version of the IP-core.
  • syntax: uint8_t prt_jpeg_enc_ver_minor (prt_jpeg_enc_ds_struct *jpeg);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
  • returns: minor version number.

Control

prt_jpeg_enc_str

  • description: Starts the encoder by setting the run bit in the control register. From this point every incoming frame is encoded.
  • syntax: void prt_jpeg_enc_str (prt_jpeg_enc_ds_struct *jpeg);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
  • returns: none

prt_jpeg_enc_stp

  • description: Stops the encoder by clearing the run bit in the control register, which holds the datapath in reset.
  • syntax: void prt_jpeg_enc_stp (prt_jpeg_enc_ds_struct *jpeg);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
  • returns: none