JFLib

img_hevc#

HEVC (H.265) intra coding -- crate root lib/img_hevc/lib.rs

img_hevc -- HEVC (H.265) intra decoder and encoder for HEIC still images
                                 [src/img/hevc.s, hevc_ps.s, hevc_ctu.s, hevc_rec.s, hevc_lf.s,
                                  hevc_enc.s, ASMLIB/inc/hevc_int.inc]

  Hevc::new(flags, maxctu)          the decoder (hevc_new); set_cancel, nal (hevc_nal),
                                    annexb (hevc_annexb), finish -> Pic (hevc_finish),
                                    newpic (hevc_newpic)
  encode(&EncCfg) -> EncOut         the encoder (hevc_encode): VPS, SPS, PPS, IDR slice

Modules: dec (the decoder record and the driver: hevc.s), ps (NAL / RBSP reader, parameter
sets, slice header, tiles: hevc_ps.s), ctu (CABAC, slice data: hevc_ctu.s), rec (intra
prediction, reconstruction: hevc_rec.s), lf (deblocking, SAO: hevc_lf.s), enc (the encoder:
hevc_enc.s).  Model of both: tools/hevc_ref.py / tools/hevc_enc_ref.py (bit-exact).

img_hevc API#

From lib/img_hevc/dec.rs:

flags (hevc_new)

HVF_NODEBLOCK: u32 = 1  // skip the deblocking filter (test hook)
HVF_NOSAO: u32 = 2  // skip SAO (test hook)
  • struct Pic<'p> the decoded picture (HEVCPIC): planes owned by the decoder

    • w: u32 -- output size (conformance window applied)
    • h: u32
    • x0: u32 -- luma offset of the window in the planes
    • y0: u32
    • bd: u32 -- BitDepthY / C
    • bdc: u32
    • chroma: u32 -- chroma_format_idc
    • subw: u32
    • subh: u32
    • vuicol: u32 -- colour description present (VUI)
    • prim: u32
    • trc: u32
    • mc: u32
    • full: u32 -- video_full_range_flag
    • planes: [&'p [u16]; 3]
    • pw: [u32; 3] -- plane width (= stride in samples) / height
    • ph: [u32; 3]
  • struct Hevc<'a> the decoder record (HV)

impl<'a> Hevc<'a>

  • fn new(flags: u32, maxctu: u32) -> Hevc<'a> hevc_new: a fresh (zeroed) record
  • fn set_cancel(&mut self, flag: Option<&'a AtomicU32>) hevc_set_cancel: a flag polled per CTU (None = none)
  • fn newpic(&mut self) -> i32 hevc_newpic: allocate the planes and maps of a picture (SPS / PPS active; the encoder uses the record for prediction / reconstruction)
  • fn nal(&mut self, nal: &[u8]) -> i32 hevc_nal: one NAL unit (see the file header)
  • fn annexb(&mut self, data: &[u8]) -> i32 hevc_annexb: split at 00 00 01 start codes (trailing zero bytes of a NAL dropped) and feed every NAL unit to nal
  • fn finish(&mut self) -> Result<Pic<'_>, i32> hevc_finish: deblocking, SAO and the picture (see the file header)

From lib/img_hevc/enc.rs (img_hevc::enc):

HEF_LOSSLESS: u32 = 1  // cu_transquant_bypass for every CU (QP ignored)
HEF_NODEBLOCK: u32 = 2  // pps_deblocking_filter_disabled (tests)
  • struct EncCfg<'a> the input of encode (HECFG)

    • pl: [&'a [u16]; 3] -- source planes (u16 samples, 8-bit values)
    • st: [u32; 3] -- strides in samples
    • w: u32 -- picture width (even for 4:2:0)
    • h: u32 -- picture height (even for 4:2:0)
    • chroma: u32 -- chroma_format_idc 0 / 1 / 3
    • qp: u32 -- QP 0..51
    • flags: u32 -- HEF_*
    • vui: u32 -- primaries | transfer << 8 | matrix << 16 | full range << 24
    • cancel: Option<&'a AtomicU32> -- polled per CTU
  • struct EncOut the result of encode (HEOUT)

    • nal: [Vec<u8>; 4] -- VPS, SPS, PPS, slice: NAL units (header, emulation prevention)
    • ptl: [u8; 12] -- general profile / tier / level bytes (hvcC)
  • fn encode(cfg: &EncCfg) -> Result<EncOut, i32> hevc_encode: encode the picture of cfg (see the file header)

img_hevc modules#

The codec's building blocks (public for the codec test app codectest; see their source headers):

ModuleContent
img_hevc::encHEVC intra encoder for HEIC (model: tools/hevc_enc_ref.py, byte-exact)

Source: docs/API.md in the JFLib repository.