gavl
Data Structures | Functions
Rectangles

Data Structures

struct  gavl_rectangle_i_t
 
struct  gavl_rectangle_f_t
 

Functions

GAVL_PUBLIC void gavl_rectangle_i_crop_to_format (gavl_rectangle_i_t *r, const gavl_video_format_t *format)
 Crop an integer rectangle so it fits into the image size of a video format. More...
 
GAVL_PUBLIC void gavl_rectangle_f_crop_to_format (gavl_rectangle_f_t *r, const gavl_video_format_t *format)
 Crop a floating point rectangle so it fits into the image size of a video format. More...
 
GAVL_PUBLIC void gavl_rectangle_crop_to_format_noscale (gavl_rectangle_i_t *src_rect, gavl_rectangle_i_t *dst_rect, const gavl_video_format_t *src_format, const gavl_video_format_t *dst_format)
 Set 2 rectangles as source and destination when no scaling is available. More...
 
GAVL_PUBLIC void gavl_rectangle_crop_to_format_scale (gavl_rectangle_f_t *src_rect, gavl_rectangle_i_t *dst_rect, const gavl_video_format_t *src_format, const gavl_video_format_t *dst_format)
 Crop 2 rectangles to their formats when scaling is available. More...
 
GAVL_PUBLIC void gavl_rectangle_i_set_all (gavl_rectangle_i_t *r, const gavl_video_format_t *format)
 Let an integer rectangle span the whole image size of a video format. More...
 
GAVL_PUBLIC void gavl_rectangle_f_set_all (gavl_rectangle_f_t *r, const gavl_video_format_t *format)
 Let a float rectangle span the whole image size of a video format. More...
 
GAVL_PUBLIC void gavl_rectangle_i_crop_left (gavl_rectangle_i_t *r, int num_pixels)
 Crop an integer rectangle by some pixels from the left border. More...
 
GAVL_PUBLIC void gavl_rectangle_i_crop_right (gavl_rectangle_i_t *r, int num_pixels)
 Crop an integer rectangle by some pixels from the right border. More...
 
GAVL_PUBLIC void gavl_rectangle_i_crop_top (gavl_rectangle_i_t *r, int num_pixels)
 Crop an integer rectangle by some pixels from the top border. More...
 
GAVL_PUBLIC void gavl_rectangle_i_crop_bottom (gavl_rectangle_i_t *r, int num_pixels)
 Crop an integer rectangle by some pixels from the bottom border. More...
 
GAVL_PUBLIC void gavl_rectangle_f_crop_left (gavl_rectangle_f_t *r, double num_pixels)
 Crop a float rectangle by some pixels from the left border. More...
 
GAVL_PUBLIC void gavl_rectangle_f_crop_right (gavl_rectangle_f_t *r, double num_pixels)
 Crop a float rectangle by some pixels from the right border. More...
 
GAVL_PUBLIC void gavl_rectangle_f_crop_top (gavl_rectangle_f_t *r, double num_pixels)
 Crop a float rectangle by some pixels from the top border. More...
 
GAVL_PUBLIC void gavl_rectangle_f_crop_bottom (gavl_rectangle_f_t *r, double num_pixels)
 Crop a float rectangle by some pixels from the bottom border. More...
 
GAVL_PUBLIC void gavl_rectangle_i_align (gavl_rectangle_i_t *r, int h_align, int v_align)
 Align a rectangle. More...
 
GAVL_PUBLIC void gavl_rectangle_i_align_to_format (gavl_rectangle_i_t *r, const gavl_video_format_t *format)
 Align a rectangle to a format. More...
 
GAVL_PUBLIC void gavl_rectangle_i_copy (gavl_rectangle_i_t *dst, const gavl_rectangle_i_t *src)
 Copy an integer rectangle. More...
 
GAVL_PUBLIC void gavl_rectangle_f_copy (gavl_rectangle_f_t *dst, const gavl_rectangle_f_t *src)
 Copy a float rectangle. More...
 
GAVL_PUBLIC void gavl_rectangle_i_to_f (gavl_rectangle_f_t *dst, const gavl_rectangle_i_t *src)
 Convert an integer rectangle to a floating point rectangle. More...
 
GAVL_PUBLIC void gavl_rectangle_f_to_i (gavl_rectangle_i_t *dst, const gavl_rectangle_f_t *src)
 Convert a floating point rectangle to an integer rectangle. More...
 
GAVL_PUBLIC int gavl_rectangle_i_is_empty (const gavl_rectangle_i_t *r)
 Check if an integer rectangle is empty. More...
 
GAVL_PUBLIC int gavl_rectangle_f_is_empty (const gavl_rectangle_f_t *r)
 Check if a float rectangle is empty. More...
 
GAVL_PUBLIC void gavl_rectangle_fit_aspect (gavl_rectangle_i_t *dst_rect, const gavl_video_format_t *src_format, const gavl_rectangle_f_t *src_rect, const gavl_video_format_t *dst_format, float zoom, float squeeze)
 Calculate a destination rectangle for scaling. More...
 
GAVL_PUBLIC void gavl_rectangle_i_dump (const gavl_rectangle_i_t *r)
 Dump a rectangle to stderr. More...
 
GAVL_PUBLIC void gavl_rectangle_f_dump (const gavl_rectangle_f_t *r)
 Dump a floating point rectangle to stderr. More...
 

Detailed Description

Define rectangular areas in a video frame

Function Documentation

◆ gavl_rectangle_i_crop_to_format()

GAVL_PUBLIC void gavl_rectangle_i_crop_to_format ( gavl_rectangle_i_t r,
const gavl_video_format_t format 
)

Crop an integer rectangle so it fits into the image size of a video format.

Parameters
rAn integer rectangle
formatThe video format into which the rectangle must fit

◆ gavl_rectangle_f_crop_to_format()

GAVL_PUBLIC void gavl_rectangle_f_crop_to_format ( gavl_rectangle_f_t r,
const gavl_video_format_t format 
)

Crop a floating point rectangle so it fits into the image size of a video format.

Parameters
rA floating point rectangle
formatThe video format into which the rectangle must fit

◆ gavl_rectangle_crop_to_format_noscale()

GAVL_PUBLIC void gavl_rectangle_crop_to_format_noscale ( gavl_rectangle_i_t src_rect,
gavl_rectangle_i_t dst_rect,
const gavl_video_format_t src_format,
const gavl_video_format_t dst_format 
)

Set 2 rectangles as source and destination when no scaling is available.

Parameters
src_rectSource rectangle
dst_rectDestination rectangle
src_formatSource format
dst_formatDestination format

This shrinks src_rect and dest_rect that neither is outside the image boundaries of the format. Both rectangles will have the same dimensions.

This function can be used for fitting a video image into a window for the case, that no scaling is available.

◆ gavl_rectangle_crop_to_format_scale()

GAVL_PUBLIC void gavl_rectangle_crop_to_format_scale ( gavl_rectangle_f_t src_rect,
gavl_rectangle_i_t dst_rect,
const gavl_video_format_t src_format,
const gavl_video_format_t dst_format 
)

Crop 2 rectangles to their formats when scaling is available.

Parameters
src_rectSource rectangle
dst_rectDestination rectangle
src_formatSource format
dst_formatDestination format

This shrinks src_rect and dest_rect that neither is outside the image boundaries of the format.

◆ gavl_rectangle_i_set_all()

GAVL_PUBLIC void gavl_rectangle_i_set_all ( gavl_rectangle_i_t r,
const gavl_video_format_t format 
)

Let an integer rectangle span the whole image size of a video format.

Parameters
rAn integer rectangle
formatThe video format into which the rectangle must fit

◆ gavl_rectangle_f_set_all()

GAVL_PUBLIC void gavl_rectangle_f_set_all ( gavl_rectangle_f_t r,
const gavl_video_format_t format 
)

Let a float rectangle span the whole image size of a video format.

Parameters
rA float rectangle
formatThe video format into which the rectangle must fit

◆ gavl_rectangle_i_crop_left()

GAVL_PUBLIC void gavl_rectangle_i_crop_left ( gavl_rectangle_i_t r,
int  num_pixels 
)

Crop an integer rectangle by some pixels from the left border.

Parameters
rAn integer rectangle
num_pixelsThe number of pixels by which the rectangle gets smaller

◆ gavl_rectangle_i_crop_right()

GAVL_PUBLIC void gavl_rectangle_i_crop_right ( gavl_rectangle_i_t r,
int  num_pixels 
)

Crop an integer rectangle by some pixels from the right border.

Parameters
rAn integer rectangle
num_pixelsThe number of pixels by which the rectangle gets smaller

◆ gavl_rectangle_i_crop_top()

GAVL_PUBLIC void gavl_rectangle_i_crop_top ( gavl_rectangle_i_t r,
int  num_pixels 
)

Crop an integer rectangle by some pixels from the top border.

Parameters
rAn integer rectangle
num_pixelsThe number of pixels by which the rectangle gets smaller

◆ gavl_rectangle_i_crop_bottom()

GAVL_PUBLIC void gavl_rectangle_i_crop_bottom ( gavl_rectangle_i_t r,
int  num_pixels 
)

Crop an integer rectangle by some pixels from the bottom border.

Parameters
rAn integer rectangle
num_pixelsThe number of pixels by which the rectangle gets smaller

◆ gavl_rectangle_f_crop_left()

GAVL_PUBLIC void gavl_rectangle_f_crop_left ( gavl_rectangle_f_t r,
double  num_pixels 
)

Crop a float rectangle by some pixels from the left border.

Parameters
rA float rectangle
num_pixelsThe number of pixels by which the rectangle gets smaller

◆ gavl_rectangle_f_crop_right()

GAVL_PUBLIC void gavl_rectangle_f_crop_right ( gavl_rectangle_f_t r,
double  num_pixels 
)

Crop a float rectangle by some pixels from the right border.

Parameters
rA float rectangle
num_pixelsThe number of pixels by which the rectangle gets smaller

◆ gavl_rectangle_f_crop_top()

GAVL_PUBLIC void gavl_rectangle_f_crop_top ( gavl_rectangle_f_t r,
double  num_pixels 
)

Crop a float rectangle by some pixels from the top border.

Parameters
rA float rectangle
num_pixelsThe number of pixels by which the rectangle gets smaller

◆ gavl_rectangle_f_crop_bottom()

GAVL_PUBLIC void gavl_rectangle_f_crop_bottom ( gavl_rectangle_f_t r,
double  num_pixels 
)

Crop a float rectangle by some pixels from the bottom border.

Parameters
rA float rectangle
num_pixelsThe number of pixels by which the rectangle gets smaller

◆ gavl_rectangle_i_align()

GAVL_PUBLIC void gavl_rectangle_i_align ( gavl_rectangle_i_t r,
int  h_align,
int  v_align 
)

Align a rectangle.

Parameters
rAn integer rectangle
h_alignHorizontal alignment
v_alignVertical alignment

This aligns a rectangle such that the horizontal and vertical coordinates are multiples of h_align and v_align respectively. When dealing with chroma subsampled formats, you must call this function with the return values of gavl_pixelformat_chroma_sub before taking subframes from video frames.

◆ gavl_rectangle_i_align_to_format()

GAVL_PUBLIC void gavl_rectangle_i_align_to_format ( gavl_rectangle_i_t r,
const gavl_video_format_t format 
)

Align a rectangle to a format.

Parameters
rAn integer rectangle
formatA video format

The convenience function does the same as gavl_rectangle_i_align but takes a format as argument.

◆ gavl_rectangle_i_copy()

GAVL_PUBLIC void gavl_rectangle_i_copy ( gavl_rectangle_i_t dst,
const gavl_rectangle_i_t src 
)

Copy an integer rectangle.

Parameters
dstDestination rectangle
srcSource rectangle

◆ gavl_rectangle_f_copy()

GAVL_PUBLIC void gavl_rectangle_f_copy ( gavl_rectangle_f_t dst,
const gavl_rectangle_f_t src 
)

Copy a float rectangle.

Parameters
dstDestination rectangle
srcSource rectangle

◆ gavl_rectangle_i_to_f()

GAVL_PUBLIC void gavl_rectangle_i_to_f ( gavl_rectangle_f_t dst,
const gavl_rectangle_i_t src 
)

Convert an integer rectangle to a floating point rectangle.

Parameters
dstDestination rectangle
srcSource rectangle

◆ gavl_rectangle_f_to_i()

GAVL_PUBLIC void gavl_rectangle_f_to_i ( gavl_rectangle_i_t dst,
const gavl_rectangle_f_t src 
)

Convert a floating point rectangle to an integer rectangle.

Parameters
dstDestination rectangle
srcSource rectangle

◆ gavl_rectangle_i_is_empty()

GAVL_PUBLIC int gavl_rectangle_i_is_empty ( const gavl_rectangle_i_t r)

Check if an integer rectangle is empty.

Parameters
rRectangle
Returns
1 if the rectangle is empty, 0 else.

A rectangle is considered to be empty if the width or height are <= 0.

◆ gavl_rectangle_f_is_empty()

GAVL_PUBLIC int gavl_rectangle_f_is_empty ( const gavl_rectangle_f_t r)

Check if a float rectangle is empty.

Parameters
rRectangle
Returns
1 if the rectangle is empty, 0 else.

A rectangle is considered to be empty if the width or height are <= 0.

◆ gavl_rectangle_fit_aspect()

GAVL_PUBLIC void gavl_rectangle_fit_aspect ( gavl_rectangle_i_t dst_rect,
const gavl_video_format_t src_format,
const gavl_rectangle_f_t src_rect,
const gavl_video_format_t dst_format,
float  zoom,
float  squeeze 
)

Calculate a destination rectangle for scaling.

Parameters
dst_rectDestination rectangle
src_formatSource format
src_rectSource rectangle
dst_formatDestination format
zoomZoom factor
squeezeSqueeze factor

Assuming we take src_rect from a frame in src_format, calculate the optimal dst_rect in dst_format. The source and destination display aspect ratio will be preserved unless it is changed with the squeeze parameter.

Zoom is a zoom factor (1.0 = 100 %). Squeeze is a value between -1.0 and 1.0, which changes the apsect ratio in both directions. 0.0 means unchanged.

Note that dst_rect might be outside the image dimensions of dst_format. If you don't like this, call gavl_rectangle_crop_to_format_scale afterwards.

Furthermore, the chroma subsampling is ignored by this function. If you you use the rectangles to fire up a gavl_video_scaler_t, this is no problem (the scaler will align the rectangles internally). You can align the destination rectangle manually using gavl_rectangle_i_align or gavl_rectangle_i_align_to_format.

◆ gavl_rectangle_i_dump()

GAVL_PUBLIC void gavl_rectangle_i_dump ( const gavl_rectangle_i_t r)

Dump a rectangle to stderr.

Parameters
rRectangle

◆ gavl_rectangle_f_dump()

GAVL_PUBLIC void gavl_rectangle_f_dump ( const gavl_rectangle_f_t r)

Dump a floating point rectangle to stderr.

Parameters
rFloating point rectangle