1 #pragma once 2 3 #include <stdbool.h> 4 5 enum { 6 // This controls bheavior with different bit widths per component (like 7 // RGB565). If ROUND_DOWN is specified, the planar format will use the min. 8 // bit width of all components, otherwise the transformation is lossless. 9 REPACK_CREATE_ROUND_DOWN = (1 << 0), 10 11 // Expand some (not all) low bit depth fringe formats to 8 bit on unpack. 12 REPACK_CREATE_EXPAND_8BIT = (1 << 1), 13 14 // For mp_repack_create_planar(). If specified, the planar format uses a 15 // float 32 bit sample format. No range expansion is done. 16 REPACK_CREATE_PLANAR_F32 = (1 << 2), 17 }; 18 19 struct mp_repack; 20 struct mp_image; 21 22 // Create a repacker between any format (imgfmt parameter) and an equivalent 23 // planar format (that is native endian). If pack==true, imgfmt is the output, 24 // otherwise it is the input. The respective other input/output is the planar 25 // format. The planar format can be queried with mp_repack_get_format_*(). 26 // Note that some formats may change the "implied" colorspace (for example, 27 // packed xyz unpacks as rgb). 28 // If imgfmt is already planar, a passthrough repacker may be created. 29 // imgfmt: src or dst format (usually packed, non-planar, etc.) 30 // pack: true if imgfmt is dst, false if imgfmt is src 31 // flags: any of REPACK_CREATE_* flags 32 // returns: NULL on failure, otherwise free with talloc_free(). 33 struct mp_repack *mp_repack_create_planar(int imgfmt, bool pack, int flags); 34 35 // Return input and output formats for which rp was created. 36 int mp_repack_get_format_src(struct mp_repack *rp); 37 int mp_repack_get_format_dst(struct mp_repack *rp); 38 39 // Return pixel alignment. For x, this is a lowest pixel count at which there is 40 // a byte boundary and a full chroma pixel (horizontal subsampling) on src/dst. 41 // For y, this is the pixel height of the vertical subsampling. 42 // Always returns a power of 2. 43 int mp_repack_get_align_x(struct mp_repack *rp); 44 int mp_repack_get_align_y(struct mp_repack *rp); 45 46 // Repack a single line from dst to src, as set in repack_config_buffers(). 47 // For subsampled chroma formats, this copies as many luma/alpha rows as needed 48 // for a complete line (e.g. 2 luma lines, 1 chroma line for 4:2:0). 49 // dst_x, src_x, y must be aligned to the pixel alignment. w may be unaligned 50 // if at the right crop-border of the image, but must be always aligned to 51 // horiz. sub-sampling. y is subject to hslice. 52 void repack_line(struct mp_repack *rp, int dst_x, int dst_y, 53 int src_x, int src_y, int w); 54 55 // Configure with a source and target buffer. The rp instance will keep the 56 // mp_image pointers and access them on repack_line() calls. Refcounting is 57 // not respected - the caller needs to make sure dst is always writable. 58 // The images can have different sizes (as repack_line() lets you use different 59 // target coordinates for dst/src). 60 // This also allocaters potentially required temporary buffers. 61 // dst_flags: REPACK_BUF_* flags for dst 62 // dst: where repack_line() writes to 63 // src_flags: REPACK_BUF_* flags for src 64 // src: where repack_line() reads from 65 // enable_passthrough: if non-NULL, an bool array of size MP_MAX_PLANES indexed 66 // by plane; a true entry requests disabling copying the 67 // plane data to the dst plane. The function will write to 68 // this array whether the plane can really be passed through 69 // (i.e. will set array entries from true to false if pass- 70 // through is not possible). It writes to all MP_MAX_PLANES 71 // entries. If NULL, all entries are implicitly false. 72 // returns: success (fails on OOM) 73 bool repack_config_buffers(struct mp_repack *rp, 74 int dst_flags, struct mp_image *dst, 75 int src_flags, struct mp_image *src, 76 bool *enable_passthrough); 77