summaryrefslogtreecommitdiffstats
path: root/spudec.c
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-07-10 13:45:09 +0000
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-11-02 04:14:43 +0200
commit96c17fe68b12104269f70b113d757fbc67b5ed1f (patch)
treeb63db7e8a5b4d090210e621ab5ad948eaf12e788 /spudec.c
parentd6322407c503bbca1f1bb48e06e275f7b610a3a8 (diff)
downloadmpv-96c17fe68b12104269f70b113d757fbc67b5ed1f.tar.bz2
mpv-96c17fe68b12104269f70b113d757fbc67b5ed1f.tar.xz
subs: Add support for PGS subtitle decoding via libavcodec
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31665 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'spudec.c')
-rw-r--r--spudec.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/spudec.c b/spudec.c
index 84af67e563..6c5213bc92 100644
--- a/spudec.c
+++ b/spudec.c
@@ -59,7 +59,9 @@ extern int sub_pos;
typedef struct packet_t packet_t;
struct packet_t {
+ int is_decoded;
unsigned char *packet;
+ int data_len;
unsigned int palette[4];
unsigned int alpha[4];
unsigned int control_start; /* index of start of control data */
@@ -629,9 +631,28 @@ void spudec_heartbeat(void *this, unsigned int pts100)
packet_t *packet = spudec_dequeue_packet(spu);
spu->start_pts = packet->start_pts;
spu->end_pts = packet->end_pts;
+ if (packet->is_decoded) {
+ free(spu->image);
+ spu->image_size = packet->data_len;
+ spu->image = packet->packet;
+ spu->aimage = packet->packet + packet->stride * packet->height;
+ packet->packet = NULL;
+ spu->width = packet->width;
+ spu->height = packet->height;
+ spu->stride = packet->stride;
+ spu->start_col = packet->start_col;
+ spu->start_row = packet->start_row;
+
+ // TODO use correct values
+ spu->scaled_frame_width = 0;
+ spu->scaled_frame_height = 0;
+ spu->orig_frame_width = 1920;
+ spu->orig_frame_height = 1080;
+ } else {
if (spu->auto_palette)
compute_palette(spu, packet);
spudec_process_data(spu, packet);
+ }
spudec_free_packet(packet);
spu->spu_changed = 1;
}
@@ -1260,3 +1281,54 @@ void spudec_set_hw_spu(void *this, struct vo *hw_spu)
spu->hw_spu = hw_spu;
vo_control(hw_spu, VOCTRL_SET_SPU_PALETTE, spu->global_palette);
}
+
+#define MP_NOPTS_VALUE (-1LL<<63) //both int64_t and double should be able to represent this exactly
+
+/**
+ * palette must contain at least 256 32-bit entries, otherwise crashes
+ * are possible
+ */
+void spudec_set_paletted(void *this, const uint8_t *pal_img, int pal_stride,
+ const void *palette,
+ int x, int y, int w, int h,
+ double pts, double endpts)
+{
+ packet_t *packet;
+ const uint32_t *pal = palette;
+ spudec_handle_t *spu = this;
+ uint8_t *img;
+ uint8_t *aimg;
+ int stride = (w + 7) & ~7;
+ if ((unsigned)w >= 0x8000 || (unsigned)h > 0x4000)
+ return;
+ packet = calloc(1, sizeof(packet_t));
+ packet->is_decoded = 1;
+ packet->width = w;
+ packet->height = h;
+ packet->stride = stride;
+ packet->start_col = x;
+ packet->start_row = y;
+ packet->data_len = 2 * stride * h;
+ packet->packet = malloc(packet->data_len);
+ img = packet->packet;
+ aimg = packet->packet + stride * h;
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++) {
+ uint32_t pixel = pal[pal_img[x]];
+ *aimg++ = -(pixel >> 24);
+ *img++ = (((pixel & 0x000000ff) >> 0) +
+ ((pixel & 0x0000ff00) >> 7) +
+ ((pixel & 0x00ff0000) >> 16)) >> 2;
+ }
+ for (; x < stride; x++)
+ *aimg++ = *img++ = 0;
+ pal_img += pal_stride;
+ }
+ packet->start_pts = 0;
+ packet->end_pts = 0x7fffffff;
+ if (pts != MP_NOPTS_VALUE)
+ packet->start_pts = pts * 90000;
+ if (endpts != MP_NOPTS_VALUE)
+ packet->end_pts = endpts * 90000;
+ spudec_queue_packet(spu, packet);
+}