avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
av::SubtitleRect Class Reference

Non-owning view over AVSubtitleRect. More...

#include <subtitle.h>

Inheritance diagram for av::SubtitleRect:

Public Member Functions

 SubtitleRect (AVSubtitleRect *rect)
 Wrap a rectangle.
bool isValid () const noexcept
 Whether the view refers to a rectangle.
 operator bool () const noexcept
 Whether the view refers to a rectangle.
AVSubtitleType type () const noexcept
 Kind of payload the rectangle carries.
void setType (AVSubtitleType type) noexcept
 Set the payload kind.
int x () const noexcept
 Horizontal position of the rectangle.
int y () const noexcept
 Vertical position of the rectangle.
int width () const noexcept
 Width of the bitmap.
int height () const noexcept
 Height of the bitmap.
void setArea (int x, int y, int width, int height) noexcept
 Set the position and the size at once.
int nbColors () const noexcept
 Number of palette entries of a bitmap rectangle.
std::string_view text () const noexcept
 Plain UTF-8 text.
std::string_view ass () const noexcept
 ASS/SSA event line.
void setText (std::string_view text, OptionalErrorCode ec=throws())
 Store plain UTF-8 text in the rectangle.
void setAss (std::string_view ass, OptionalErrorCode ec=throws())
 Store an ASS/SSA event line in the rectangle.
void clearText () noexcept
 Free the text payload and clear the pointer.
void clearAss () noexcept
 Free the ASS payload and clear the pointer.
bool isForced () const noexcept
 Whether the rectangle is flagged as forced.
void setForced (bool forced) noexcept
 Mark the rectangle as forced.
uint8_t * data (size_t plane=0) noexcept
 Pointer to one image plane.
const uint8_t * data (size_t plane=0) const noexcept
 Pointer to one image plane, read-only.
int linesize (size_t plane=0) const noexcept
 Distance between two rows of a plane.
void setBitmap (const uint8_t *data, int stride, int width, int height, OptionalErrorCode ec=throws())
 Sets plane 0 to an index bitmap and updates width, height and linesize.
void setPalette (const uint32_t *palette, int count, OptionalErrorCode ec=throws())
 Sets plane 1 to a palette and updates nb_colors.
std::span< const uint8_t > bitmap () const noexcept
 Plane 0 as an index bitmap: linesize(0) * height() bytes.
std::span< const uint32_t > palette () const noexcept
 Plane 1 as a palette: nbColors() entries.
void setBitmap (std::span< const uint8_t > data, int stride, int width, int height, OptionalErrorCode ec=throws())
 Sets plane 0 to an index bitmap and updates width, height and linesize.
void setPalette (std::span< const uint32_t > palette, OptionalErrorCode ec=throws())
 Sets plane 1 to a palette and updates nb_colors.
Public Member Functions inherited from FFWrapperPtr< AVSubtitleRect >
 FFWrapperPtr ()=default
 Create an empty wrapper; isNull() is true.
const AVSubtitleRect * raw () const
 Read access to the wrapped object.
void reset (AVSubtitleRect *raw=nullptr)
 Replace the stored pointer.
bool isNull () const
 Whether the wrapper is empty.
void _log (int level, const char *fmt) const
 Log through the FFmpeg log system, using this wrapper as the context.

Additional Inherited Members

Protected Attributes inherited from FFWrapperPtr< AVSubtitleRect >
AVSubtitleRect * m_raw
 The wrapped pointer; owned by the derived class, not by this template.

Detailed Description

The view is valid while the owning SubtitleFrame is alive. Setters are meant for rectangles owned by a SubtitleFrame; they allocate memory compatible with avsubtitle_free().

Examples
api2-subtitles.cpp.

Constructor & Destructor Documentation

◆ SubtitleRect()

av::SubtitleRect::SubtitleRect ( AVSubtitleRect * rect)
explicit
Parameters
rectthe FFmpeg rectangle; null produces an invalid view
Note
Non-owning: the rectangle must outlive the view.

Member Function Documentation

◆ ass()

std::string_view av::SubtitleRect::ass ( ) const
noexcept

Empty when the rectangle has no ASS payload.

Returns
the ASS line, empty when there is no payload
Examples
api2-subtitles.cpp.

◆ bitmap()

std::span< const uint8_t > av::SubtitleRect::bitmap ( ) const
noexcept
Returns
the bitmap bytes

◆ data() [1/2]

const uint8_t * av::SubtitleRect::data ( size_t plane = 0) const
noexcept
Parameters
planeplane index
Returns
the plane pointer, or nullptr when it is absent

◆ data() [2/2]

uint8_t * av::SubtitleRect::data ( size_t plane = 0)
noexcept
Parameters
planeplane index: 0 is the bitmap, 1 is the palette
Returns
the plane pointer, or nullptr when it is absent
Note
Borrowed; valid while the owning frame lives.

◆ height()

int av::SubtitleRect::height ( ) const
noexcept
Returns
the height in pixels
Examples
api2-subtitles.cpp.

◆ isForced()

bool av::SubtitleRect::isForced ( ) const
noexcept

Forced subtitles are shown even when the user disabled subtitles, which is how translations of on-screen text are usually delivered.

Returns
the forced flag
Examples
api2-subtitles.cpp.

◆ isValid()

bool av::SubtitleRect::isValid ( ) const
noexcept
Returns
true when the underlying AVSubtitleRect exists

◆ linesize()

int av::SubtitleRect::linesize ( size_t plane = 0) const
noexcept
Parameters
planeplane index
Returns
the stride in bytes

◆ nbColors()

int av::SubtitleRect::nbColors ( ) const
noexcept
Returns
the entry count, or zero when there is no palette
Examples
api2-subtitles.cpp.

◆ operator bool()

av::SubtitleRect::operator bool ( ) const
noexcept
Returns
true when the underlying AVSubtitleRect exists

◆ palette()

std::span< const uint32_t > av::SubtitleRect::palette ( ) const
noexcept
Returns
the palette entries

◆ setArea()

void av::SubtitleRect::setArea ( int x,
int y,
int width,
int height )
noexcept
Parameters
xleft edge in pixels
ytop edge in pixels
widthwidth in pixels
heightheight in pixels

◆ setAss()

void av::SubtitleRect::setAss ( std::string_view ass,
OptionalErrorCode ec = throws() )
Parameters
assthe dialogue line, without the "Dialogue:" prefix
echolder for the error code

◆ setBitmap() [1/2]

void av::SubtitleRect::setBitmap ( const uint8_t * data,
int stride,
int width,
int height,
OptionalErrorCode ec = throws() )

Also sets the rectangle type to SUBTITLE_BITMAP when it was SUBTITLE_NONE.

Parameters
data
stride
width
height
ec

◆ setBitmap() [2/2]

void av::SubtitleRect::setBitmap ( std::span< const uint8_t > data,
int stride,
int width,
int height,
OptionalErrorCode ec = throws() )
Parameters
datathe bitmap bytes
stridebytes per row
widthwidth in pixels
heightheight in pixels
echolder for the error code

◆ setForced()

void av::SubtitleRect::setForced ( bool forced)
noexcept
Parameters
forcedthe new value of the flag

◆ setPalette() [1/2]

void av::SubtitleRect::setPalette ( const uint32_t * palette,
int count,
OptionalErrorCode ec = throws() )
Parameters
palette
count
ec

◆ setPalette() [2/2]

void av::SubtitleRect::setPalette ( std::span< const uint32_t > palette,
OptionalErrorCode ec = throws() )
Parameters
palettethe palette entries
echolder for the error code

◆ setText()

void av::SubtitleRect::setText ( std::string_view text,
OptionalErrorCode ec = throws() )

The previous payload is freed. Memory comes from the FFmpeg allocator, so it is released by avsubtitle_free() together with the frame.

Parameters
textthe text to store
echolder for the error code

◆ setType()

void av::SubtitleRect::setType ( AVSubtitleType type)
noexcept
Parameters
typethe AVSubtitleType to record

◆ text()

std::string_view av::SubtitleRect::text ( ) const
noexcept

Empty when the rectangle has no text.

Returns
the text, empty when there is none
Examples
api2-subtitles.cpp.

◆ type()

AVSubtitleType av::SubtitleRect::type ( ) const
noexcept
Returns
SUBTITLE_TEXT, SUBTITLE_ASS, SUBTITLE_BITMAP or SUBTITLE_NONE
Examples
api2-subtitles.cpp.

◆ width()

int av::SubtitleRect::width ( ) const
noexcept
Returns
the width in pixels
Examples
api2-subtitles.cpp.

◆ x()

int av::SubtitleRect::x ( ) const
noexcept
Returns
the left edge in pixels
Examples
api2-subtitles.cpp.

◆ y()

int av::SubtitleRect::y ( ) const
noexcept
Returns
the top edge in pixels
Examples
api2-subtitles.cpp.

The documentation for this class was generated from the following file: