35 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
36 #define MAX_EPOCH_PALETTES 8 // Max 8 allowed per PGS epoch
37 #define MAX_EPOCH_OBJECTS 64 // Max 64 allowed per PGS epoch
38 #define MAX_OBJECT_REFS 2 // Max objects per display set
116 for (i = 0; i < objects->
count; i++) {
118 return &objects->
object[i];
127 for (i = 0; i < palettes->
count; i++) {
159 const uint8_t *buf,
unsigned int buf_size)
162 int pixel_count, line_count;
164 rle_bitmap_end = buf + buf_size;
174 while (buf < rle_bitmap_end && line_count < rect->h) {
178 color = bytestream_get_byte(&buf);
182 flags = bytestream_get_byte(&buf);
185 run = (run << 8) + bytestream_get_byte(&buf);
186 color = flags & 0x80 ? bytestream_get_byte(&buf) : 0;
189 if (run > 0 && pixel_count + run <= rect->w * rect->
h) {
190 memset(rect->
pict.
data[0] + pixel_count, color, run);
197 if (pixel_count % rect->
w > 0) {
199 pixel_count % rect->
w, rect->
w);
208 if (pixel_count < rect->w * rect->
h) {
213 av_dlog(avctx,
"Pixel Count = %d, Area = %d\n", pixel_count, rect->
w * rect->
h);
229 const uint8_t *buf,
int buf_size)
242 id = bytestream_get_be16(&buf);
257 sequence_desc = bytestream_get_byte(&buf);
259 if (!(sequence_desc & 0x80)) {
265 object->rle_data_len += buf_size;
266 object->rle_remaining_len -= buf_size;
276 rle_bitmap_len = bytestream_get_be24(&buf) - 2*2;
278 if (buf_size > rle_bitmap_len) {
280 "Buffer dimension %d larger than the expected RLE data %d\n",
281 buf_size, rle_bitmap_len);
286 width = bytestream_get_be16(&buf);
287 height = bytestream_get_be16(&buf);
290 if (avctx->
width < width || avctx->
height < height) {
303 memcpy(object->
rle, buf, buf_size);
304 object->rle_data_len = buf_size;
305 object->rle_remaining_len = rle_bitmap_len - buf_size;
321 const uint8_t *buf,
int buf_size)
326 const uint8_t *buf_end = buf + buf_size;
329 int y, cb, cr, alpha;
330 int r,
g,
b, r_add, g_add, b_add;
333 id = bytestream_get_byte(&buf);
347 while (buf < buf_end) {
348 color_id = bytestream_get_byte(&buf);
349 y = bytestream_get_byte(&buf);
350 cr = bytestream_get_byte(&buf);
351 cb = bytestream_get_byte(&buf);
352 alpha = bytestream_get_byte(&buf);
357 av_dlog(avctx,
"Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha);
360 palette->
clut[color_id] =
RGBA(r,g,b,alpha);
377 const uint8_t *buf,
int buf_size,
385 int w = bytestream_get_be16(&buf);
386 int h = bytestream_get_be16(&buf);
390 av_dlog(avctx,
"Video Dimensions %dx%d\n",
410 state = bytestream_get_byte(&buf) >> 6;
423 "Invalid number of presentation objects %d\n",
448 av_dlog(avctx,
"Subtitle Placement x=%d, y=%d\n",
453 av_log(avctx,
AV_LOG_ERROR,
"Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n",
479 const uint8_t *buf,
int buf_size)
486 memset(sub, 0,
sizeof(*sub));
514 if (!sub->
rects[i]) {
539 sub->
rects[i]->
w =
object->w;
540 sub->
rects[i]->
h =
object->h;
583 int buf_size = avpkt->
size;
590 av_dlog(avctx,
"PGS sub packet:\n");
592 for (i = 0; i < buf_size; i++) {
593 av_dlog(avctx,
"%02x ", buf[i]);
607 buf_end = buf + buf_size;
610 while (buf < buf_end) {
611 segment_type = bytestream_get_byte(&buf);
612 segment_length = bytestream_get_be16(&buf);
614 av_dlog(avctx,
"Segment Length %d, Segment Type %x\n", segment_length, segment_type);
620 switch (segment_type) {
647 segment_type, segment_length);
654 buf += segment_length;
static int parse_object_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse the picture segment packet.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
int x
top left corner of pict, undefined when pict is not set
static int parse_presentation_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int64_t pts)
Parse the presentation segment packet.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
int nb_colors
number of colors in pict, undefined when pict is not set
Various defines for YUV<->RGB conversion.
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
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int w
width of pict, undefined when pict is not set
8 bit with PIX_FMT_RGB32 palette
uint8_t * data[AV_NUM_DATA_POINTERS]
static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
int h
height of pict, undefined when pict is not set
static int parse_palette_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse the palette segment packet.
#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
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int decode_rle(AVCodecContext *avctx, AVSubtitleRect *rect, const uint8_t *buf, unsigned int buf_size)
Decode the RLE data.
#define YUV_TO_RGB1(cb1, cr1)
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
uint32_t end_display_time
int64_t pts
Same as packet pts, in AV_TIME_BASE.
PGSSubObject object[MAX_EPOCH_OBJECTS]
A bitmap, pict will be set.
#define AV_SUBTITLE_FLAG_FORCED
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
AVPicture pict
data+linesize for the bitmap of this subtitle.
static av_cold int close_decoder(AVCodecContext *avctx)
int width
picture width / height.
static PGSSubObject * find_object(int id, PGSSubObjects *objects)
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.
#define MAX_EPOCH_OBJECTS
Libavcodec external API header.
main external API structure.
static void close(AVCodecParserContext *s)
static void flush_cache(AVCodecContext *avctx)
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
PGSSubPalette palette[MAX_EPOCH_PALETTES]
PGSSubObjectRef objects[MAX_OBJECT_REFS]
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
unsigned int rle_remaining_len
common internal api header.
unsigned int rle_data_len
uint32_t start_display_time
static const uint8_t color[]
static av_cold int init(AVCodecParserContext *s)
static PGSSubPalette * find_palette(int id, PGSSubPalettes *palettes)
unsigned int rle_buffer_size
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define MAX_EPOCH_PALETTES