31 #include "libavutil/imgutils.h"
32 #include "libavutil/opt.h"
34 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
90 for (picture = 0; picture < UINT16_MAX; ++picture) {
112 int pixel_count, line_count;
114 rle_bitmap_end = buf + buf_size;
124 while (buf < rle_bitmap_end && line_count < sub->rects[rect]->h) {
128 color = bytestream_get_byte(&buf);
132 flags = bytestream_get_byte(&buf);
135 run = (run << 8) + bytestream_get_byte(&buf);
136 color = flags & 0x80 ? bytestream_get_byte(&buf) : 0;
139 if (run > 0 && pixel_count + run <= sub->rects[rect]->w * sub->
rects[rect]->
h) {
140 memset(sub->
rects[rect]->
pict.
data[0] + pixel_count, color, run);
147 if (pixel_count % sub->
rects[rect]->
w > 0)
149 pixel_count % sub->
rects[rect]->
w, sub->
rects[rect]->
w);
154 if (pixel_count < sub->rects[rect]->w * sub->
rects[rect]->
h) {
159 av_dlog(avctx,
"Pixel Count = %d, Area = %d\n", pixel_count, sub->
rects[rect]->
w * sub->
rects[rect]->
h);
188 picture_id = bytestream_get_be16(&buf);
194 sequence_desc = bytestream_get_byte(&buf);
196 if (!(sequence_desc & 0x80)) {
213 rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
216 width = bytestream_get_be16(&buf);
217 height = bytestream_get_be16(&buf);
220 if (avctx->
width < width || avctx->
height < height) {
225 if (buf_size > rle_bitmap_len) {
238 memcpy(ctx->
pictures[picture_id].
rle, buf, buf_size);
260 const uint8_t *buf_end = buf + buf_size;
264 int r,
g,
b, r_add, g_add, b_add;
269 while (buf < buf_end) {
270 color_id = bytestream_get_byte(&buf);
271 y = bytestream_get_byte(&buf);
272 cr = bytestream_get_byte(&buf);
273 cb = bytestream_get_byte(&buf);
274 alpha = bytestream_get_byte(&buf);
279 av_dlog(avctx,
"Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
282 ctx->
clut[color_id] =
RGBA(r,g,b,alpha);
303 int w = bytestream_get_be16(&buf);
304 int h = bytestream_get_be16(&buf);
306 uint16_t object_index;
310 av_dlog(avctx,
"Video Dimensions %dx%d\n",
334 if (buf_size < ctx->presentation.object_count * 8) {
348 reference->
picture_id = bytestream_get_be16(&buf);
353 reference->
composition = bytestream_get_byte(&buf);
355 reference->
x = bytestream_get_be16(&buf);
356 reference->
y = bytestream_get_be16(&buf);
359 av_dlog(avctx,
"Subtitle Placement ID=%d, x=%d, y=%d\n", reference->
picture_id, reference->
x, reference->
y);
361 if (reference->
x > avctx->
width || reference->
y > avctx->
height) {
362 av_log(avctx,
AV_LOG_ERROR,
"Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
401 memset(sub, 0,
sizeof(*sub));
416 for (rect = 0; rect < sub->
num_rects; ++rect) {
453 int buf_size = avpkt->
size;
461 av_dlog(avctx,
"PGS sub packet:\n");
463 for (i = 0; i < buf_size; i++) {
464 av_dlog(avctx,
"%02x ", buf[i]);
478 buf_end = buf + buf_size;
481 while (buf < buf_end) {
482 segment_type = bytestream_get_byte(&buf);
483 segment_length = bytestream_get_be16(&buf);
485 av_dlog(avctx,
"Segment Length %d, Segment Type %x\n", segment_length, segment_type);
490 switch (segment_type) {
515 segment_type, segment_length);
519 buf += segment_length;
525 #define OFFSET(x) offsetof(PGSSubContext, x)
526 #define SD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
528 {
"forced_subs_only",
"Only show forced subtitles",
OFFSET(forced_subs_only),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
SD},
548 .priv_class = &pgsdec_class,
int x
top left corner of pict, undefined when pict is not set
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
unsigned int rle_remaining_len
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
int nb_colors
number of colors in pict, undefined when pict is not set
Various defines for YUV<->RGB conversion.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
AVCodec ff_pgssub_decoder
PGSSubPresentation presentation
PGSSubPictureReference * objects
static void parse_presentation_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int64_t pts)
Parse the presentation segment packet.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int decode_rle(AVCodecContext *avctx, AVSubtitle *sub, int rect, const uint8_t *buf, unsigned int buf_size)
Decode the RLE data.
int w
width of pict, undefined when pict is not set
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static double cb(void *priv, double x, double y)
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
const char * name
Name of the codec implementation.
static const AVClass pgsdec_class
static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
int h
height of pict, undefined when pict is not set
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
const OptionDef options[]
static int parse_picture_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse the picture segment packet.
static double alpha(void *priv, double x, double y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define YUV_TO_RGB2(r, g, b, y1)
int y
top left corner of pict, undefined when pict is not set
unsigned int rle_buffer_size
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define YUV_TO_RGB1(cb1, cr1)
Libavcodec external API header.
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
A bitmap, pict will be set.
#define AV_SUBTITLE_FLAG_FORCED
AVPicture pict
data+linesize for the bitmap of this subtitle.
static av_cold int close_decoder(AVCodecContext *avctx)
int width
picture width / height.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static av_cold int init_decoder(AVCodecContext *avctx)
static int display_end_segment(AVCodecContext *avctx, void *data, const uint8_t *buf, int buf_size)
Parse the display segment packet.
main external API structure.
static void close(AVCodecParserContext *s)
BYTE int const BYTE int int int height
Describe the class of an AVClass context structure.
uint32_t start_display_time
static void parse_palette_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse the palette segment packet.
#define AVERROR_INVALIDDATA
PGSSubPicture pictures[UINT16_MAX]
unsigned int rle_data_len
8 bit with PIX_FMT_RGB32 palette
static double cr(void *priv, double x, double y)
This structure stores compressed data.
#define AV_NOPTS_VALUE
Undefined timestamp value.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...