annotate spudec.c @ 9267:46d15316cf9a

Name added, patch by Lu Ran <hephooey@fastmail.fm>.
author diego
date Tue, 04 Feb 2003 08:52:00 +0000
parents d430529c5b4b
children 8e205102fc8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
1 /* SPUdec.c
673
0fdcf08e7df8 (C) fixed
arpi_esp
parents: 561
diff changeset
2 Skeleton of function spudec_process_controll() is from xine sources.
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
3 Further works:
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
4 LGB,... (yeah, try to improve it and insert your name here! ;-)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
5
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
6 Kim Minh Kaplan
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
7 implement fragments reassembly, RLE decoding.
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
8 read brightness from the IFO.
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
9
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
10 For information on SPU format see <URL:http://sam.zoy.org/doc/dvd/subtitles/>
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
11 and <URL:http://members.aol.com/mpucoder/DVD/spu.html>
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
12
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
13 */
3183
ce9acee4e129 Fix spudec compile with libdvdread enabled.
atmos4
parents: 3180
diff changeset
14 #include "config.h"
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
15 #include "mp_msg.h"
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
16
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
17 #include <errno.h>
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
18 #include <limits.h>
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
19 #include <stdio.h>
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
20 #include <stdlib.h>
3175
3538c34117a3 unistd.h required at least by FreeBSD
nexus
parents: 3166
diff changeset
21 #include <unistd.h>
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
22 #include <string.h>
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
23 #include <math.h>
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
24 #include "libvo/video_out.h"
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
25 #include "spudec.h"
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
26 #include "postproc/swscale.h"
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
27
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
28 #define MIN(a, b) ((a)<(b)?(a):(b))
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
29
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
30 /* Valid values for spu_aamode:
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
31 0: none (fastest, most ugly)
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
32 1: approximate
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
33 2: full (slowest)
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
34 3: bilinear (similiar to vobsub, fast and not too bad)
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
35 4: uses swscaler gaussian (this is the only one that looks good)
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
36 */
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
37
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
38 int spu_aamode = 3;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
39 int spu_alignment = -1;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
40 float spu_gaussvar = 1.0;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
41 extern int sub_pos;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
42
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
43 typedef struct packet_t packet_t;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
44 struct packet_t {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
45 unsigned char *data;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
46 unsigned int process_pts; /* When to process the packet */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
47 size_t reserve; /* size of the memory pointed to by packet */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
48 unsigned int offset; /* end of the currently assembled fragment */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
49 unsigned int size; /* size of the packet once all fragments are assembled */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
50 unsigned int fragment_pts; /* PTS of the last fragment for this packet */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
51 unsigned int control_start; /* index of start of control data */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
52 packet_t *next;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
53 };
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
54
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
55 typedef struct {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
56 packet_t *packets; /* Linked list of packets sorted by process_pts */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
57 packet_t *last_packet; /* Last packet in linked list */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
58
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
59 unsigned int global_palette[16];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
60 unsigned int orig_frame_width, orig_frame_height;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
61 unsigned int palette[4];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
62 unsigned int alpha[4];
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
63 unsigned int cuspal[4];
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
64 unsigned int custom;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
65 unsigned int now_pts;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
66 unsigned int start_pts, end_pts;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
67 unsigned int start_col, end_col;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
68 unsigned int start_row, end_row;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
69 unsigned int width, height, stride;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
70 unsigned int current_nibble[2]; /* next data nibble (4 bits) to be
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
71 processed (for RLE decoding) for
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
72 even and odd lines */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
73 int deinterlace_oddness; /* 0 or 1, index into current_nibble */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
74 size_t image_size; /* Size of the image buffer */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
75 unsigned char *image; /* Grayscale value */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
76 unsigned char *aimage; /* Alpha value */
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4810
diff changeset
77 unsigned int scaled_frame_width, scaled_frame_height;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
78 unsigned int scaled_start_col, scaled_start_row;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
79 unsigned int scaled_width, scaled_height, scaled_stride;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
80 size_t scaled_image_size;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
81 unsigned char *scaled_image;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
82 unsigned char *scaled_aimage;
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
83 int auto_palette; /* 1 if we lack a palette and must use an heuristic. */
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
84 int font_start_level; /* Darkest value used for the computed font */
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
85 vo_functions_t *hw_spu;
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
86 int spu_changed;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
87 } spudec_handle_t;
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
88
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
89 /* Add packet to end of list */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
90 static void spudec_append_packet (spudec_handle_t *this, packet_t *packet)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
91 {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
92 packet->next = NULL;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
93 if (this->last_packet == NULL)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
94 this->packets = packet;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
95 else
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
96 this->last_packet->next = packet;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
97
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
98 this->last_packet = packet;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
99 }
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
100
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
101 /* Add a new packet to end of the list */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
102 static void spudec_append_new_packet (spudec_handle_t *this)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
103 {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
104 packet_t *new_packet = calloc (1, sizeof (packet_t));
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
105
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
106 /* Do not process packet yet, so set process time way into the future */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
107 new_packet->process_pts = -1L;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
108
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
109 spudec_append_packet (this, new_packet);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
110 }
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
111
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
112 /* Remove top-most packet and free the memory it used */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
113 static void spudec_pop_packet (spudec_handle_t *this)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
114 {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
115 packet_t *temp;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
116
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
117 if (this->packets != NULL)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
118 {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
119 temp = this->packets;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
120 this->packets = temp->next;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
121 if (temp->data != NULL)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
122 free (temp->data);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
123 free (temp);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
124
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
125 /* Null last packet pointer if there are no packets in the queue */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
126 if (this->packets == NULL)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
127 this->last_packet = NULL;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
128 }
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
129 }
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
130
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
131 static inline unsigned int get_be16(const unsigned char *p)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
132 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
133 return (p[0] << 8) + p[1];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
134 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
135
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
136 static inline unsigned int get_be24(const unsigned char *p)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
137 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
138 return (get_be16(p) << 8) + p[2];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
139 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
140
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
141 static void next_line(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
142 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
143 if (this->current_nibble[this->deinterlace_oddness] % 2)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
144 this->current_nibble[this->deinterlace_oddness]++;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
145 this->deinterlace_oddness = (this->deinterlace_oddness + 1) % 2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
146 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
147
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
148 static inline unsigned char get_nibble(spudec_handle_t *this, packet_t *packet)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
149 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
150 unsigned char nib;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
151 unsigned int *nibblep = this->current_nibble + this->deinterlace_oddness;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
152 if (*nibblep / 2 >= packet->control_start) {
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
153 mp_msg(MSGT_SPUDEC,MSGL_WARN, "SPUdec: ERROR: get_nibble past end of packet\n");
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
154 return 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
155 }
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
156 nib = packet->data[*nibblep / 2];
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
157 if (*nibblep % 2)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
158 nib &= 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
159 else
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
160 nib >>= 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
161 ++*nibblep;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
162 return nib;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
163 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
164
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
165 static inline int mkalpha(int i)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
166 {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
167 /* In mplayer's alpha planes, 0 is transparent, then 1 is nearly
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
168 opaque upto 255 which is transparent */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
169 switch (i) {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
170 case 0xf:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
171 return 1;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
172 case 0:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
173 return 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
174 default:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
175 return (0xf - i) << 4;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
176 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
177 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
178
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
179 /* Cut the sub to visible part */
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
180 static inline void spudec_cut_image(spudec_handle_t *this)
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
181 {
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
182 unsigned int fy, ly;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
183 unsigned int first_y, last_y;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
184 unsigned char *image;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
185 unsigned char *aimage;
6223
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
186
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
187 if (this->stride == 0 || this->height == 0) {
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
188 return;
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
189 }
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
190
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
191 for (fy = 0; fy < this->image_size && !this->aimage[fy]; fy++);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
192 for (ly = this->stride * this->height-1; ly && !this->aimage[ly]; ly--);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
193 first_y = fy / this->stride;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
194 last_y = ly / this->stride;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
195 //printf("first_y: %d, last_y: %d\n", first_y, last_y);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
196 this->start_row += first_y;
6223
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
197
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
198 // Some subtitles trigger this condition
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
199 if (last_y + 1 > first_y ) {
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
200 this->height = last_y - first_y +1;
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
201 } else {
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
202 this->height = 0;
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
203 }
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
204
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
205 //printf("new h %d new start %d (sz %d st %d)---\n\n", this->height, this->start_row, this->image_size, this->stride);
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
206
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
207 image = malloc(2 * this->stride * this->height);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
208 if(image){
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
209 this->image_size = this->stride * this->height;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
210 aimage = image + this->image_size;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
211 memcpy(image, this->image + this->stride * first_y, this->image_size);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
212 memcpy(aimage, this->aimage + this->stride * first_y, this->image_size);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
213 free(this->image);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
214 this->image = image;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
215 this->aimage = aimage;
6223
7833c711d62b avoids malloc()ing a negative number (== very big size_t)
pl
parents: 6215
diff changeset
216 } else {
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
217 mp_msg(MSGT_SPUDEC, MSGL_FATAL, "Fatal: update_spu: malloc requested %d bytes\n", 2 * this->stride * this->height);
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
218 }
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
219 }
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
220
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
221 static void spudec_process_data(spudec_handle_t *this, packet_t *packet)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
222 {
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
223 unsigned int cmap[4], alpha[4];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
224 unsigned int i, x, y;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
225
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
226 this->deinterlace_oddness = 0;
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4810
diff changeset
227 this->scaled_frame_width = 0;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4810
diff changeset
228 this->scaled_frame_height = 0;
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
229 for (i = 0; i < 4; ++i) {
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
230 alpha[i] = mkalpha(this->alpha[i]);
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
231 if (alpha[i] == 0)
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
232 cmap[i] = 0;
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
233 else if (this->custom){
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
234 cmap[i] = ((this->cuspal[i] >> 16) & 0xff);
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
235 if (cmap[i] + alpha[i] > 255)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
236 cmap[i] = 256 - alpha[i];
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
237 }
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
238 else {
4122
3ee2a23f91c7 Fix brightness of subtitles
kmkaplan
parents: 4078
diff changeset
239 cmap[i] = ((this->global_palette[this->palette[i]] >> 16) & 0xff);
3ee2a23f91c7 Fix brightness of subtitles
kmkaplan
parents: 4078
diff changeset
240 if (cmap[i] + alpha[i] > 255)
3ee2a23f91c7 Fix brightness of subtitles
kmkaplan
parents: 4078
diff changeset
241 cmap[i] = 256 - alpha[i];
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
242 }
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
243 }
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
244
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
245 if (this->image_size < this->stride * this->height) {
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
246 if (this->image != NULL) {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
247 free(this->image);
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
248 this->image_size = 0;
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
249 }
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
250 this->image = malloc(2 * this->stride * this->height);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
251 if (this->image) {
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
252 this->image_size = this->stride * this->height;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
253 this->aimage = this->image + this->image_size;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
254 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
255 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
256 if (this->image == NULL)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
257 return;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
258
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
259 /* Kludge: draw_alpha needs width multiple of 8. */
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
260 if (this->width < this->stride)
6459
f82b8063f3e7 Suppress garbage at the end of some subtitles.
kmkaplan
parents: 6225
diff changeset
261 for (y = 0; y < this->height; ++y) {
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
262 memset(this->aimage + y * this->stride + this->width, 0, this->stride - this->width);
6459
f82b8063f3e7 Suppress garbage at the end of some subtitles.
kmkaplan
parents: 6225
diff changeset
263 /* FIXME: Why is this one needed? */
f82b8063f3e7 Suppress garbage at the end of some subtitles.
kmkaplan
parents: 6225
diff changeset
264 memset(this->image + y * this->stride + this->width, 0, this->stride - this->width);
f82b8063f3e7 Suppress garbage at the end of some subtitles.
kmkaplan
parents: 6225
diff changeset
265 }
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
266
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
267 i = this->current_nibble[1];
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
268 x = 0;
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
269 y = 0;
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
270 while (this->current_nibble[0] < i
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
271 && this->current_nibble[1] / 2 < packet->control_start
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
272 && y < this->height) {
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
273 unsigned int len, color;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
274 unsigned int rle = 0;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
275 rle = get_nibble(this, packet);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
276 if (rle < 0x04) {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
277 rle = (rle << 4) | get_nibble(this, packet);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
278 if (rle < 0x10) {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
279 rle = (rle << 4) | get_nibble(this, packet);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
280 if (rle < 0x040) {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
281 rle = (rle << 4) | get_nibble(this, packet);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
282 if (rle < 0x0004)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
283 rle |= ((this->width - x) << 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
284 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
285 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
286 }
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
287 color = 3 - (rle & 0x3);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
288 len = rle >> 2;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
289 if (len > this->width - x || len == 0)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
290 len = this->width - x;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
291 /* FIXME have to use palette and alpha map*/
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
292 memset(this->image + y * this->stride + x, cmap[color], len);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
293 memset(this->aimage + y * this->stride + x, alpha[color], len);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
294 x += len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
295 if (x >= this->width) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
296 next_line(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
297 x = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
298 ++y;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
299 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
300 }
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
301 spudec_cut_image(this);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
302 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
303
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
304
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
305 /*
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
306 This function tries to create a usable palette.
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
307 Is searchs how many non-transparent colors are used and assigns different
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
308 gray scale values to each color.
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
309 I tested it with four streams and even got something readable. Half of the
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
310 times I got black characters with white around and half the reverse.
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
311 */
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
312 static void compute_palette(spudec_handle_t *this)
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
313 {
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
314 int used[16],i,cused,start,step,color;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
315
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
316 memset(used, 0, sizeof(used));
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
317 for (i=0; i<4; i++)
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
318 if (this->alpha[i]) /* !Transparent? */
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
319 used[this->palette[i]] = 1;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
320 for (cused=0, i=0; i<16; i++)
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
321 if (used[i]) cused++;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
322 if (!cused) return;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
323 if (cused == 1) {
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
324 start = 0x80;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
325 step = 0;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
326 } else {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
327 start = this->font_start_level;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
328 step = (0xF0-this->font_start_level)/(cused-1);
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
329 }
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
330 memset(used, 0, sizeof(used));
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
331 for (i=0; i<4; i++) {
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
332 color = this->palette[i];
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
333 if (this->alpha[i] && !used[color]) { /* not assigned? */
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
334 used[color] = 1;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
335 this->global_palette[color] = start<<16;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
336 start += step;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
337 }
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
338 }
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
339 }
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
340
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
341 static void spudec_process_control(spudec_handle_t *this, packet_t *packet)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
342 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
343 int a,b; /* Temporary vars */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
344 unsigned int date, type;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
345 unsigned int off;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
346 unsigned int start_off = 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
347 unsigned int next_off;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
348 unsigned int pts100 = packet->process_pts;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
349
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
350 packet->control_start = get_be16(packet->data + 2);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
351 next_off = packet->control_start;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
352 while (start_off != next_off) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
353 start_off = next_off;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
354 date = get_be16(packet->data + start_off) * 1024;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
355 next_off = get_be16(packet->data + start_off + 2);
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
356 mp_msg(MSGT_SPUDEC,MSGL_DBG2, "date=%d\n", date);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
357 off = start_off + 4;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
358 for (type = packet->data[off++]; type != 0xff; type = packet->data[off++]) {
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
359 mp_msg(MSGT_SPUDEC,MSGL_DBG2, "cmd=%d ",type);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
360 switch(type) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
361 case 0x00:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
362 /* Menu ID, 1 byte */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
363 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Menu ID\n");
5474
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
364 /* shouldn't a Menu ID type force display start? */
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
365 //this->start_pts = pts100 + date;
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
366 //this->end_pts = UINT_MAX;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
367 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
368 case 0x01:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
369 /* Start display */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
370 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Start display!\n");
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
371 this->start_pts = pts100 + date;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
372 this->end_pts = UINT_MAX;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
373 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
374 case 0x02:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
375 /* Stop display */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
376 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Stop display!\n");
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
377 this->end_pts = pts100 + date;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
378 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
379 case 0x03:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
380 /* Palette */
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
381 this->palette[0] = packet->data[off] >> 4;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
382 this->palette[1] = packet->data[off] & 0xf;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
383 this->palette[2] = packet->data[off + 1] >> 4;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
384 this->palette[3] = packet->data[off + 1] & 0xf;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
385 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Palette %d, %d, %d, %d\n",
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
386 this->palette[0], this->palette[1], this->palette[2], this->palette[3]);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
387 off+=2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
388 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
389 case 0x04:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
390 /* Alpha */
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
391 this->alpha[0] = packet->data[off] >> 4;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
392 this->alpha[1] = packet->data[off] & 0xf;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
393 this->alpha[2] = packet->data[off + 1] >> 4;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
394 this->alpha[3] = packet->data[off + 1] & 0xf;
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
395 if (this->auto_palette) {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
396 compute_palette(this);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
397 this->auto_palette = 0;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
398 }
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
399 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Alpha %d, %d, %d, %d\n",
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
400 this->alpha[0], this->alpha[1], this->alpha[2], this->alpha[3]);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
401 off+=2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
402 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
403 case 0x05:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
404 /* Co-ords */
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
405 a = get_be24(packet->data + off);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
406 b = get_be24(packet->data + off + 3);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
407 this->start_col = a >> 12;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
408 this->end_col = a & 0xfff;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
409 this->width = (this->end_col < this->start_col) ? 0 : this->end_col - this->start_col + 1;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
410 this->stride = (this->width + 7) & ~7; /* Kludge: draw_alpha needs width multiple of 8 */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
411 this->start_row = b >> 12;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
412 this->end_row = b & 0xfff;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
413 this->height = (this->end_row < this->start_row) ? 0 : this->end_row - this->start_row /* + 1 */;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
414 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Coords col: %d - %d row: %d - %d (%dx%d)\n",
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
415 this->start_col, this->end_col, this->start_row, this->end_row,
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
416 this->width, this->height);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
417 off+=6;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
418 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
419 case 0x06:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
420 /* Graphic lines */
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
421 this->current_nibble[0] = 2 * get_be16(packet->data + off);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
422 this->current_nibble[1] = 2 * get_be16(packet->data + off + 2);
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
423 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Graphic offset 1: %d offset 2: %d\n",
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
424 this->current_nibble[0] / 2, this->current_nibble[1] / 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
425 off+=4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
426 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
427 case 0xff:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
428 /* All done, bye-bye */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
429 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Done!\n");
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
430 return;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
431 // break;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
432 default:
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
433 mp_msg(MSGT_SPUDEC,MSGL_WARN,"spudec: Error determining control type 0x%02x. Skipping %d bytes.\n",
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
434 type, next_off - off);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
435 goto next_control;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
436 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
437 }
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
438 next_control:
3725
ba98028ddc27 fixes warnings
pl
parents: 3402
diff changeset
439 ;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
440 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
441 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
442
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
443 static void spudec_decode(spudec_handle_t *this, packet_t *queued_packet)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
444 {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
445 if(this->hw_spu) {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
446 static vo_mpegpes_t packet = { NULL, 0, 0x20, 0 };
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
447 static vo_mpegpes_t *pkg=&packet;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
448 packet.data = queued_packet->data;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
449 packet.size = queued_packet->size;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
450 packet.timestamp = queued_packet->process_pts;
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
451 this->hw_spu->draw_frame((uint8_t**)&pkg);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
452 } else {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
453 spudec_process_control(this, queued_packet);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
454 spudec_process_data(this, queued_packet);
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
455 }
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
456 this->spu_changed = 1;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
457 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
458
6190
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
459 int spudec_changed(void * this)
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
460 {
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
461 spudec_handle_t * spu = (spudec_handle_t*)this;
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
462 return (spu->spu_changed || spu->now_pts > spu->end_pts);
6190
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
463 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
464
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
465 void spudec_assemble(void *this, unsigned char *packet_bytes, unsigned int len, unsigned int pts100)
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
466 {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
467 spudec_handle_t *spu = (spudec_handle_t*)this;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
468 packet_t *last_packet;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
469
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
470 /* Create a new packet if one doesn't exist in the queue */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
471 if (spu->last_packet == NULL)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
472 spudec_append_new_packet (spu);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
473
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
474 last_packet = spu->last_packet;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
475
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
476 // spudec_heartbeat(this, pts100);
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
477 if (len < 2) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
478 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: packet too short\n");
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
479 return;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
480 }
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
481 if ((last_packet->fragment_pts + 10000) < pts100) {
7743
a280cc3087ea All right: The patch adresses two issues which I found, when I analyzed
arpi
parents: 6938
diff changeset
482 // [cb] too long since last fragment: force new packet
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
483 last_packet->offset = 0;
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
484 }
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
485 last_packet->fragment_pts = pts100;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
486 if (last_packet->offset == 0) {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
487 unsigned int len2 = get_be16(packet_bytes);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
488 // Start new fragment
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
489 if (last_packet->reserve < len2) {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
490 if (last_packet->data != NULL)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
491 free(last_packet->data);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
492 last_packet->data = malloc(len2);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
493 last_packet->reserve = last_packet->data != NULL ? len2 : 0;
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
494 }
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
495 if (last_packet->data != NULL) {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
496 last_packet->size = len2;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
497 if (len > len2) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
498 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid frag len / len2: %d / %d \n", len, len2);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
499 return;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
500 }
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
501 memcpy(last_packet->data, packet_bytes, len);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
502 last_packet->offset = len;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
503 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
504 } else {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
505 // Continue current fragment
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
506 if (last_packet->size < last_packet->offset + len){
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
507 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid fragment\n");
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
508 last_packet->size = last_packet->offset = 0;
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
509 } else {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
510 memcpy(last_packet->data + last_packet->offset, packet_bytes, len);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
511 last_packet->offset += len;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
512 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
513 }
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
514 #if 1
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
515 // check if we have a complete packet (unfortunatelly packet_size is bad
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
516 // for some disks)
7743
a280cc3087ea All right: The patch adresses two issues which I found, when I analyzed
arpi
parents: 6938
diff changeset
517 // [cb] packet_size is padded to be even -> may be one byte too long
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
518 if ((last_packet->offset == last_packet->size) ||
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
519 ((last_packet->offset + 1) == last_packet->size)){
5917
ab2cd00a0a52 Suggested fix by
atmos4
parents: 5908
diff changeset
520 unsigned int x=0,y;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
521 while(x+4<=last_packet->offset) {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
522 y=get_be16(last_packet->data+x+2); // next control pointer
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
523 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUtest: x=%d y=%d off=%d size=%d\n",x,y,last_packet->offset,last_packet->size);
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
524 if(x>=4 && x==y){ // if it points to self - we're done!
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
525 // we got it!
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
526 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUgot: off=%d size=%d \n",last_packet->offset,last_packet->size);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
527 break;
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
528 }
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
529 if(y<=x || y>=last_packet->size){ // invalid?
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
530 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUtest: broken packet!!!!! y=%d < x=%d\n",y,x);
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
531 last_packet->size = last_packet->offset = 0;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
532 return;
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
533 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
534 x=y;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
535 }
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
536
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
537 /* Packet is done. Schedule time to process it and start a new one. */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
538 last_packet->process_pts = last_packet->fragment_pts;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
539 spudec_append_new_packet (spu);
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
540 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
541 #else
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
542 if (spu->packet_offset == spu->packet_size) {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
543 /* Packet is done. Schedule time to process it and start a new one. */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
544 last_packet->process_pts = last_packet->fragment_pts;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
545 spudec_append_new_packet (spu);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
546 }
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
547 #endif
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
548 }
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
549
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
550 void spudec_reset(void *this) // called after seek
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
551 {
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
552 spudec_handle_t *spu = (spudec_handle_t*)this;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
553 spu->now_pts = 0;
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
554 while (spu->packets != NULL)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
555 spudec_pop_packet (spu);
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
556 }
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
557
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
558 void spudec_heartbeat(void *this, unsigned int pts100)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
559 {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
560 spudec_handle_t *spu = (spudec_handle_t*) this;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
561 spu->now_pts = pts100;
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
562
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
563 /* Process queued instructions for the current beat */
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
564 while (spu->packets != NULL && pts100 >= spu->packets->process_pts)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
565 {
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
566 spudec_decode (spu, spu->packets);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
567 spudec_pop_packet (spu);
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
568 }
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
569 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
570
5638
86663f1b9b00 new osd code, use osd objs to follow changes and do minimal updates
arpi
parents: 5488
diff changeset
571 int spudec_visible(void *this){
86663f1b9b00 new osd code, use osd objs to follow changes and do minimal updates
arpi
parents: 5488
diff changeset
572 spudec_handle_t *spu = (spudec_handle_t *)this;
86663f1b9b00 new osd code, use osd objs to follow changes and do minimal updates
arpi
parents: 5488
diff changeset
573 int ret=(spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts);
86663f1b9b00 new osd code, use osd objs to follow changes and do minimal updates
arpi
parents: 5488
diff changeset
574 // printf("spu visible: %d \n",ret);
86663f1b9b00 new osd code, use osd objs to follow changes and do minimal updates
arpi
parents: 5488
diff changeset
575 return ret;
86663f1b9b00 new osd code, use osd objs to follow changes and do minimal updates
arpi
parents: 5488
diff changeset
576 }
86663f1b9b00 new osd code, use osd objs to follow changes and do minimal updates
arpi
parents: 5488
diff changeset
577
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
578 void spudec_draw(void *this, void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
579 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
580 spudec_handle_t *spu = (spudec_handle_t *)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
581 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts && spu->image)
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
582 {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
583 draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height,
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
584 spu->image, spu->aimage, spu->stride);
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
585 spu->spu_changed = 0;
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
586 }
561
36fd71db0d33 spudec_decode() moved from mplayer.c to spudec.c
arpi_esp
parents: 560
diff changeset
587 }
36fd71db0d33 spudec_decode() moved from mplayer.c to spudec.c
arpi_esp
parents: 560
diff changeset
588
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
589 /* calc the bbox for spudec subs */
6190
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
590 void spudec_calc_bbox(void *me, unsigned int dxs, unsigned int dys, unsigned int* bbox)
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
591 {
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
592 spudec_handle_t *spu;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
593 spu = (spudec_handle_t *)me;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
594 if (spu->orig_frame_width == 0 || spu->orig_frame_height == 0
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
595 || (spu->orig_frame_width == dxs && spu->orig_frame_height == dys)) {
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
596 bbox[0] = spu->start_col;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
597 bbox[1] = spu->start_col + spu->width;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
598 bbox[2] = spu->start_row;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
599 bbox[3] = spu->start_row + spu->height;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
600 }
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
601 else if (spu->scaled_frame_width != dxs || spu->scaled_frame_height != dys) {
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
602 unsigned int scalex = 0x100 * dxs / spu->orig_frame_width;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
603 unsigned int scaley = 0x100 * dys / spu->orig_frame_height;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
604 bbox[0] = spu->start_col * scalex / 0x100;
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
605 bbox[1] = spu->start_col * scalex / 0x100 + spu->width * scalex / 0x100;
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
606 switch (spu_alignment) {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
607 case 0:
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
608 bbox[3] = dys*sub_pos/100 + spu->height * scaley / 0x100;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
609 if (bbox[3] > dys) bbox[3] = dys;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
610 bbox[2] = bbox[3] - spu->height * scaley / 0x100;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
611 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
612 case 1:
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
613 if (sub_pos < 50) {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
614 bbox[2] = dys*sub_pos/100 - spu->height * scaley / 0x200;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
615 if (bbox[2] < 0) bbox[2] = 0;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
616 bbox[3] = bbox[2] + spu->height;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
617 } else {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
618 bbox[3] = dys*sub_pos/100 + spu->height * scaley / 0x200;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
619 if (bbox[3] > dys) bbox[3] = dys;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
620 bbox[2] = bbox[3] - spu->height * scaley / 0x100;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
621 }
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
622 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
623 case 2:
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
624 bbox[2] = dys*sub_pos/100 - spu->height * scaley / 0x100;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
625 if (bbox[2] < 0) bbox[2] = 0;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
626 bbox[3] = bbox[2] + spu->height;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
627 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
628 default: /* -1 */
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
629 bbox[2] = spu->start_row * scaley / 0x100;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
630 bbox[3] = spu->start_row * scaley / 0x100 + spu->height * scaley / 0x100;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
631 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
632 }
6190
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
633 }
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
634 }
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
635 /* transform mplayer's alpha value into an opacity value that is linear */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
636 static inline int canon_alpha(int alpha)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
637 {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
638 return alpha ? 256 - alpha : 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
639 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
640
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
641 typedef struct {
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
642 unsigned position;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
643 unsigned left_up;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
644 unsigned right_down;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
645 }scale_pixel;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
646
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
647
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
648 static void scale_table(unsigned int start_src, unsigned int start_tar, unsigned int end_src, unsigned int end_tar, scale_pixel * table)
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
649 {
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
650 unsigned int t;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
651 unsigned int delta_src = end_src - start_src;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
652 unsigned int delta_tar = end_tar - start_tar;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
653 int src = 0;
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
654 int src_step;
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
655 if (delta_src == 0 || delta_tar == 0) {
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
656 return;
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
657 }
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
658 src_step = (delta_src << 16) / delta_tar >>1;
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
659 for (t = 0; t<=delta_tar; src += (src_step << 1), t++){
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
660 table[t].position= MIN(src >> 16, end_src - 1);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
661 table[t].right_down = src & 0xffff;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
662 table[t].left_up = 0x10000 - table[t].right_down;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
663 }
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
664 }
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
665
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
666 /* bilinear scale, similar to vobsub's code */
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
667 static void scale_image(int x, int y, scale_pixel* table_x, scale_pixel* table_y, spudec_handle_t * spu)
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
668 {
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
669 int alpha[4];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
670 int color[4];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
671 unsigned int scale[4];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
672 int base = table_y[y].position * spu->stride + table_x[x].position;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
673 int scaled = y * spu->scaled_stride + x;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
674 alpha[0] = canon_alpha(spu->aimage[base]);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
675 alpha[1] = canon_alpha(spu->aimage[base + 1]);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
676 alpha[2] = canon_alpha(spu->aimage[base + spu->stride]);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
677 alpha[3] = canon_alpha(spu->aimage[base + spu->stride + 1]);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
678 color[0] = spu->image[base];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
679 color[1] = spu->image[base + 1];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
680 color[2] = spu->image[base + spu->stride];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
681 color[3] = spu->image[base + spu->stride + 1];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
682 scale[0] = (table_x[x].left_up * table_y[y].left_up >> 16) * alpha[0];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
683 scale[1] = (table_x[x].right_down * table_y[y].left_up >>16) * alpha[1];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
684 scale[2] = (table_x[x].left_up * table_y[y].right_down >> 16) * alpha[2];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
685 scale[3] = (table_x[x].right_down * table_y[y].right_down >> 16) * alpha[3];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
686 spu->scaled_image[scaled] = (color[0] * scale[0] + color[1] * scale[1] + color[2] * scale[2] + color[3] * scale[3])>>24;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
687 spu->scaled_aimage[scaled] = (scale[0] + scale[1] + scale[2] + scale[3]) >> 16;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
688 if (spu->scaled_aimage[scaled]){
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
689 spu->scaled_aimage[scaled] = 256 - spu->scaled_aimage[scaled];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
690 if(spu->scaled_aimage[scaled] + spu->scaled_image[scaled] > 255)
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
691 spu->scaled_image[scaled] = 256 - spu->scaled_aimage[scaled];
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
692 }
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
693 }
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
694
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
695 void sws_spu_image(unsigned char *d1, unsigned char *d2, int dw, int dh, int ds,
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
696 unsigned char *s1, unsigned char *s2, int sw, int sh, int ss)
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
697 {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
698 SwsContext *ctx;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
699 static SwsFilter filter;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
700 static int firsttime = 1;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
701 static float oldvar;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
702 int i;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
703
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
704 if (!firsttime && oldvar != spu_gaussvar) freeVec(filter.lumH);
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
705 if (firsttime) {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
706 filter.lumH = filter.lumV =
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
707 filter.chrH = filter.chrV = getGaussianVec(spu_gaussvar, 3.0);
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
708 normalizeVec(filter.lumH, 1.0);
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
709 firsttime = 0;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
710 oldvar = spu_gaussvar;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
711 }
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
712
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
713 ctx=getSwsContext(sw, sh, IMGFMT_Y800, dw, dh, IMGFMT_Y800, SWS_GAUSS, &filter, NULL);
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
714 ctx->swScale(ctx,&s1,&ss,0,sh,&d1,&ds);
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
715 for (i=ss*sh-1; i>=0; i--) if (!s2[i]) s2[i] = 255; //else s2[i] = 1;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
716 ctx->swScale(ctx,&s2,&ss,0,sh,&d2,&ds);
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
717 for (i=ds*dh-1; i>=0; i--) if (d2[i]==0) d2[i] = 1; else if (d2[i]==255) d2[i] = 0;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
718 freeSwsContext(ctx);
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
719 }
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
720
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
721 void spudec_draw_scaled(void *me, unsigned int dxs, unsigned int dys, void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
722 {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
723 spudec_handle_t *spu = (spudec_handle_t *)me;
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
724 scale_pixel *table_x;
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
725 scale_pixel *table_y;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
726 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts) {
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
727 if (!(spu_aamode&16) && (spu->orig_frame_width == 0 || spu->orig_frame_height == 0
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
728 || (spu->orig_frame_width == dxs && spu->orig_frame_height == dys))) {
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
729 if (spu->image)
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
730 {
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
731 draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height,
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
732 spu->image, spu->aimage, spu->stride);
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
733 spu->spu_changed = 0;
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
734 }
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
735 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
736 else {
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4810
diff changeset
737 if (spu->scaled_frame_width != dxs || spu->scaled_frame_height != dys) { /* Resizing is needed */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
738 /* scaled_x = scalex * x / 0x100
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
739 scaled_y = scaley * y / 0x100
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
740 order of operations is important because of rounding. */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
741 unsigned int scalex = 0x100 * dxs / spu->orig_frame_width;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
742 unsigned int scaley = 0x100 * dys / spu->orig_frame_height;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
743 spu->scaled_start_col = spu->start_col * scalex / 0x100;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
744 spu->scaled_start_row = spu->start_row * scaley / 0x100;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
745 spu->scaled_width = spu->width * scalex / 0x100;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
746 spu->scaled_height = spu->height * scaley / 0x100;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
747 /* Kludge: draw_alpha needs width multiple of 8 */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
748 spu->scaled_stride = (spu->scaled_width + 7) & ~7;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
749 if (spu->scaled_image_size < spu->scaled_stride * spu->scaled_height) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
750 if (spu->scaled_image) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
751 free(spu->scaled_image);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
752 spu->scaled_image_size = 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
753 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
754 spu->scaled_image = malloc(2 * spu->scaled_stride * spu->scaled_height);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
755 if (spu->scaled_image) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
756 spu->scaled_image_size = spu->scaled_stride * spu->scaled_height;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
757 spu->scaled_aimage = spu->scaled_image + spu->scaled_image_size;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
758 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
759 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
760 if (spu->scaled_image) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
761 unsigned int x, y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
762 /* Kludge: draw_alpha needs width multiple of 8. */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
763 if (spu->scaled_width < spu->scaled_stride)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
764 for (y = 0; y < spu->scaled_height; ++y) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
765 memset(spu->scaled_aimage + y * spu->scaled_stride + spu->scaled_width, 0,
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
766 spu->scaled_stride - spu->scaled_width);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
767 /* FIXME: Why is this one needed? */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
768 memset(spu->scaled_image + y * spu->scaled_stride + spu->scaled_width, 0,
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
769 spu->scaled_stride - spu->scaled_width);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
770 }
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
771 if (spu->scaled_width <= 1 || spu->scaled_height <= 1) {
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
772 goto nothing_to_do;
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
773 }
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
774 switch(spu_aamode&15) {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
775 case 4:
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
776 sws_spu_image(spu->scaled_image, spu->scaled_aimage,
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
777 spu->scaled_width, spu->scaled_height, spu->scaled_stride,
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
778 spu->image, spu->aimage, spu->width, spu->height, spu->stride);
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
779 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
780 case 3:
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
781 table_x = calloc(spu->scaled_width, sizeof(scale_pixel));
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
782 table_y = calloc(spu->scaled_height, sizeof(scale_pixel));
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
783 if (!table_x || !table_y) {
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
784 mp_msg(MSGT_SPUDEC, MSGL_FATAL, "Fatal: spudec_draw_scaled: calloc failed\n");
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
785 }
6215
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
786 scale_table(0, 0, spu->width - 1, spu->scaled_width - 1, table_x);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
787 scale_table(0, 0, spu->height - 1, spu->scaled_height - 1, table_y);
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
788 for (y = 0; y < spu->scaled_height; y++)
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
789 for (x = 0; x < spu->scaled_width; x++)
e435026183c3 spu/vobsub speedup patch, new all better bilinear scaler similiar to win vobsub ones. ptyh by Hephooey.
atmos4
parents: 6190
diff changeset
790 scale_image(x, y, table_x, table_y, spu);
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
791 free(table_x);
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
792 free(table_y);
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
793 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
794 case 0:
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
795 /* no antialiasing */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
796 for (y = 0; y < spu->scaled_height; ++y) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
797 int unscaled_y = y * 0x100 / scaley;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
798 int strides = spu->stride * unscaled_y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
799 int scaled_strides = spu->scaled_stride * y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
800 for (x = 0; x < spu->scaled_width; ++x) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
801 int unscaled_x = x * 0x100 / scalex;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
802 spu->scaled_image[scaled_strides + x] = spu->image[strides + unscaled_x];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
803 spu->scaled_aimage[scaled_strides + x] = spu->aimage[strides + unscaled_x];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
804 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
805 }
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
806 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
807 case 1:
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
808 {
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
809 /* Intermediate antialiasing. */
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
810 for (y = 0; y < spu->scaled_height; ++y) {
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
811 const unsigned int unscaled_top = y * spu->orig_frame_height / dys;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
812 unsigned int unscaled_bottom = (y + 1) * spu->orig_frame_height / dys;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
813 if (unscaled_bottom >= spu->height)
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
814 unscaled_bottom = spu->height - 1;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
815 for (x = 0; x < spu->scaled_width; ++x) {
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
816 const unsigned int unscaled_left = x * spu->orig_frame_width / dxs;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
817 unsigned int unscaled_right = (x + 1) * spu->orig_frame_width / dxs;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
818 unsigned int color = 0;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
819 unsigned int alpha = 0;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
820 unsigned int walkx, walky;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
821 unsigned int base, tmp;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
822 if (unscaled_right >= spu->width)
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
823 unscaled_right = spu->width - 1;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
824 for (walky = unscaled_top; walky <= unscaled_bottom; ++walky)
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
825 for (walkx = unscaled_left; walkx <= unscaled_right; ++walkx) {
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
826 base = walky * spu->stride + walkx;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
827 tmp = canon_alpha(spu->aimage[base]);
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
828 alpha += tmp;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
829 color += tmp * spu->image[base];
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
830 }
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
831 base = y * spu->scaled_stride + x;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
832 spu->scaled_image[base] = alpha ? color / alpha : 0;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
833 spu->scaled_aimage[base] =
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
834 alpha * (1 + unscaled_bottom - unscaled_top) * (1 + unscaled_right - unscaled_left);
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
835 /* spu->scaled_aimage[base] =
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
836 alpha * dxs * dys / spu->orig_frame_width / spu->orig_frame_height; */
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
837 if (spu->scaled_aimage[base]) {
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
838 spu->scaled_aimage[base] = 256 - spu->scaled_aimage[base];
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
839 if (spu->scaled_aimage[base] + spu->scaled_image[base] > 255)
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
840 spu->scaled_image[base] = 256 - spu->scaled_aimage[base];
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
841 }
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
842 }
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
843 }
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
844 }
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
845 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
846 case 2:
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
847 {
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
848 /* Best antialiasing. Very slow. */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
849 /* Any pixel (x, y) represents pixels from the original
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
850 rectangular region comprised between the columns
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
851 unscaled_y and unscaled_y + 0x100 / scaley and the rows
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
852 unscaled_x and unscaled_x + 0x100 / scalex
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
853
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
854 The original rectangular region that the scaled pixel
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
855 represents is cut in 9 rectangular areas like this:
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
856
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
857 +---+-----------------+---+
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
858 | 1 | 2 | 3 |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
859 +---+-----------------+---+
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
860 | | | |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
861 | 4 | 5 | 6 |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
862 | | | |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
863 +---+-----------------+---+
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
864 | 7 | 8 | 9 |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
865 +---+-----------------+---+
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
866
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
867 The width of the left column is at most one pixel and
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
868 it is never null and its right column is at a pixel
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
869 boundary. The height of the top row is at most one
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
870 pixel it is never null and its bottom row is at a
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
871 pixel boundary. The width and height of region 5 are
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
872 integral values. The width of the right column is
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
873 what remains and is less than one pixel. The height
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
874 of the bottom row is what remains and is less than
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
875 one pixel.
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
876
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
877 The row above 1, 2, 3 is unscaled_y. The row between
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
878 1, 2, 3 and 4, 5, 6 is top_low_row. The row between 4,
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
879 5, 6 and 7, 8, 9 is (unsigned int)unscaled_y_bottom.
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
880 The row beneath 7, 8, 9 is unscaled_y_bottom.
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
881
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
882 The column left of 1, 4, 7 is unscaled_x. The column
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
883 between 1, 4, 7 and 2, 5, 8 is left_right_column. The
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
884 column between 2, 5, 8 and 3, 6, 9 is (unsigned
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
885 int)unscaled_x_right. The column right of 3, 6, 9 is
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
886 unscaled_x_right. */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
887 const double inv_scalex = (double) 0x100 / scalex;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
888 const double inv_scaley = (double) 0x100 / scaley;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
889 for (y = 0; y < spu->scaled_height; ++y) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
890 const double unscaled_y = y * inv_scaley;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
891 const double unscaled_y_bottom = unscaled_y + inv_scaley;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
892 const unsigned int top_low_row = MIN(unscaled_y_bottom, unscaled_y + 1.0);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
893 const double top = top_low_row - unscaled_y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
894 const unsigned int height = unscaled_y_bottom > top_low_row
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
895 ? (unsigned int) unscaled_y_bottom - top_low_row
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
896 : 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
897 const double bottom = unscaled_y_bottom > top_low_row
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
898 ? unscaled_y_bottom - floor(unscaled_y_bottom)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
899 : 0.0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
900 for (x = 0; x < spu->scaled_width; ++x) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
901 const double unscaled_x = x * inv_scalex;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
902 const double unscaled_x_right = unscaled_x + inv_scalex;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
903 const unsigned int left_right_column = MIN(unscaled_x_right, unscaled_x + 1.0);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
904 const double left = left_right_column - unscaled_x;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
905 const unsigned int width = unscaled_x_right > left_right_column
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
906 ? (unsigned int) unscaled_x_right - left_right_column
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
907 : 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
908 const double right = unscaled_x_right > left_right_column
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
909 ? unscaled_x_right - floor(unscaled_x_right)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
910 : 0.0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
911 double color = 0.0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
912 double alpha = 0.0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
913 double tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
914 unsigned int base;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
915 /* Now use these informations to compute a good alpha,
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
916 and lightness. The sum is on each of the 9
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
917 region's surface and alpha and lightness.
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
918
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
919 transformed alpha = sum(surface * alpha) / sum(surface)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
920 transformed color = sum(surface * alpha * color) / sum(surface * alpha)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
921 */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
922 /* 1: top left part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
923 base = spu->stride * (unsigned int) unscaled_y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
924 tmp = left * top * canon_alpha(spu->aimage[base + (unsigned int) unscaled_x]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
925 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
926 color += tmp * spu->image[base + (unsigned int) unscaled_x];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
927 /* 2: top center part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
928 if (width > 0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
929 unsigned int walkx;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
930 for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
931 base = spu->stride * (unsigned int) unscaled_y + walkx;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
932 tmp = /* 1.0 * */ top * canon_alpha(spu->aimage[base]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
933 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
934 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
935 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
936 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
937 /* 3: top right part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
938 if (right > 0.0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
939 base = spu->stride * (unsigned int) unscaled_y + (unsigned int) unscaled_x_right;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
940 tmp = right * top * canon_alpha(spu->aimage[base]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
941 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
942 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
943 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
944 /* 4: center left part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
945 if (height > 0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
946 unsigned int walky;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
947 for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
948 base = spu->stride * walky + (unsigned int) unscaled_x;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
949 tmp = left /* * 1.0 */ * canon_alpha(spu->aimage[base]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
950 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
951 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
952 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
953 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
954 /* 5: center part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
955 if (width > 0 && height > 0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
956 unsigned int walky;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
957 for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
958 unsigned int walkx;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
959 base = spu->stride * walky;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
960 for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
961 tmp = /* 1.0 * 1.0 * */ canon_alpha(spu->aimage[base + walkx]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
962 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
963 color += tmp * spu->image[base + walkx];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
964 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
965 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
966 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
967 /* 6: center right part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
968 if (right > 0.0 && height > 0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
969 unsigned int walky;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
970 for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
971 base = spu->stride * walky + (unsigned int) unscaled_x_right;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
972 tmp = right /* * 1.0 */ * canon_alpha(spu->aimage[base]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
973 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
974 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
975 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
976 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
977 /* 7: bottom left part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
978 if (bottom > 0.0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
979 base = spu->stride * (unsigned int) unscaled_y_bottom + (unsigned int) unscaled_x;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
980 tmp = left * bottom * canon_alpha(spu->aimage[base]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
981 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
982 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
983 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
984 /* 8: bottom center part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
985 if (width > 0 && bottom > 0.0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
986 unsigned int walkx;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
987 base = spu->stride * (unsigned int) unscaled_y_bottom;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
988 for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
989 tmp = /* 1.0 * */ bottom * canon_alpha(spu->aimage[base + walkx]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
990 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
991 color += tmp * spu->image[base + walkx];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
992 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
993 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
994 /* 9: bottom right part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
995 if (right > 0.0 && bottom > 0.0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
996 base = spu->stride * (unsigned int) unscaled_y_bottom + (unsigned int) unscaled_x_right;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
997 tmp = right * bottom * canon_alpha(spu->aimage[base]);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
998 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
999 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1000 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1001 /* Finally mix these transparency and brightness information suitably */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1002 base = spu->scaled_stride * y + x;
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
1003 spu->scaled_image[base] = alpha > 0 ? color / alpha : 0;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1004 spu->scaled_aimage[base] = alpha * scalex * scaley / 0x10000;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1005 if (spu->scaled_aimage[base]) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1006 spu->scaled_aimage[base] = 256 - spu->scaled_aimage[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1007 if (spu->scaled_aimage[base] + spu->scaled_image[base] > 255)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1008 spu->scaled_image[base] = 256 - spu->scaled_aimage[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1009 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1010 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1011 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1012 }
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1013 }
6225
75e8e1cf1f77 - hardened a bit the new bilinear algo (missing checks)
pl
parents: 6223
diff changeset
1014 nothing_to_do:
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4810
diff changeset
1015 spu->scaled_frame_width = dxs;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4810
diff changeset
1016 spu->scaled_frame_height = dys;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1017 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1018 }
6190
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
1019 if (spu->scaled_image){
9077
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1020 switch (spu_alignment) {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1021 case 0:
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1022 spu->scaled_start_row = dys*sub_pos/100;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1023 if (spu->scaled_start_row + spu->scaled_height > dys)
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1024 spu->scaled_start_row = dys - spu->scaled_height;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1025 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1026 case 1:
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1027 spu->scaled_start_row = dys*sub_pos/100 - spu->scaled_height/2;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1028 if (sub_pos < 50) {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1029 if (spu->scaled_start_row < 0) spu->scaled_start_row = 0;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1030 } else {
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1031 if (spu->scaled_start_row + spu->scaled_height > dys)
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1032 spu->scaled_start_row = dys - spu->scaled_height;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1033 }
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1034 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1035 case 2:
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1036 spu->scaled_start_row = dys*sub_pos/100 - spu->scaled_height;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1037 if (spu->scaled_start_row < 0) spu->scaled_start_row = 0;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1038 break;
d430529c5b4b Improvements to spudec (DVD/VobSub) subtitle code:
rfelker
parents: 8843
diff changeset
1039 }
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1040 draw_alpha(spu->scaled_start_col, spu->scaled_start_row, spu->scaled_width, spu->scaled_height,
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1041 spu->scaled_image, spu->scaled_aimage, spu->scaled_stride);
6778
f33d4ab7a6b2 Make spudec_assemble more resistent in the face of incomplete packets.
kmkaplan
parents: 6459
diff changeset
1042 spu->spu_changed = 0;
6190
bd6748605681 Bounding box and partial update patch for vob/dvdsub by Hephooey.
atmos4
parents: 6110
diff changeset
1043 }
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1044 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1045 }
5474
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1046 else
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1047 {
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1048 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPU not displayed: start_pts=%d end_pts=%d now_pts=%d\n",
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1049 spu->start_pts, spu->end_pts, spu->now_pts);
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1050 }
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1051 }
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1052
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1053 void spudec_update_palette(void * this, unsigned int *palette)
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1054 {
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1055 spudec_handle_t *spu = (spudec_handle_t *) this;
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1056 if (spu && palette) {
5474
a303ae797429 spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents: 5388
diff changeset
1057 memcpy(spu->global_palette, palette, sizeof(spu->global_palette));
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1058 if(spu->hw_spu)
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1059 spu->hw_spu->control(VOCTRL_SET_SPU_PALETTE,spu->global_palette);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1060 }
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1061 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1062
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1063 void spudec_set_font_factor(void * this, double factor)
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1064 {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1065 spudec_handle_t *spu = (spudec_handle_t *) this;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1066 spu->font_start_level = (int)(0xF0-(0xE0*factor));
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1067 }
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1068
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1069 void *spudec_new_scaled(unsigned int *palette, unsigned int frame_width, unsigned int frame_height)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1070 {
6938
d796833e77af Put all spudec_new stuff in a single function,
kmkaplan
parents: 6778
diff changeset
1071 return spudec_new_scaled_vobsub(palette, NULL, 0, frame_width, frame_height);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1072 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1073
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1074 /* get palette custom color, width, height from .idx file */
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1075 void *spudec_new_scaled_vobsub(unsigned int *palette, unsigned int *cuspal, unsigned int custom, unsigned int frame_width, unsigned int frame_height)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1076 {
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1077 spudec_handle_t *this = calloc(1, sizeof(spudec_handle_t));
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1078 if (this){
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1079 //(fprintf(stderr,"VobSub Custom Palette: %d,%d,%d,%d", this->cuspal[0], this->cuspal[1], this->cuspal[2],this->cuspal[3]);
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
1080 this->packets = NULL;
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1081 this->image = NULL;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1082 this->scaled_image = NULL;
6938
d796833e77af Put all spudec_new stuff in a single function,
kmkaplan
parents: 6778
diff changeset
1083 /* XXX Although the video frame is some size, the SPU frame is
d796833e77af Put all spudec_new stuff in a single function,
kmkaplan
parents: 6778
diff changeset
1084 always maximum size i.e. 720 wide and 576 or 480 high */
d796833e77af Put all spudec_new stuff in a single function,
kmkaplan
parents: 6778
diff changeset
1085 this->orig_frame_width = 720;
d796833e77af Put all spudec_new stuff in a single function,
kmkaplan
parents: 6778
diff changeset
1086 this->orig_frame_height = (frame_height == 480 || frame_height == 240) ? 480 : 576;
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1087 this->custom = custom;
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1088 // set up palette:
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1089 this->auto_palette = 1;
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1090 if (palette){
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1091 memcpy(this->global_palette, palette, sizeof(this->global_palette));
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1092 this->auto_palette = 0;
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1093 }
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1094 this->custom = custom;
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1095 if (custom && cuspal) {
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1096 memcpy(this->cuspal, cuspal, sizeof(this->cuspal));
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1097 this->auto_palette = 0;
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1098 }
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1099 }
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1100 else
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1101 mp_msg(MSGT_SPUDEC,MSGL_FATAL, "FATAL: spudec_init: calloc");
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1102 return this;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5638
diff changeset
1103 }
5908
31159f453cf9 guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents: 5833
diff changeset
1104
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1105 void *spudec_new(unsigned int *palette)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1106 {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1107 return spudec_new_scaled(palette, 0, 0);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1108 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1109
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1110 void spudec_free(void *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1111 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1112 spudec_handle_t *spu = (spudec_handle_t*)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1113 if (spu) {
8843
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
1114 while (spu->packets != NULL)
c70444c5b516 I have seen problems where DVD subtitles don't display
arpi
parents: 7743
diff changeset
1115 spudec_pop_packet (this);
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1116 if (spu->scaled_image)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
1117 free(spu->scaled_image);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1118 if (spu->image)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1119 free(spu->image);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1120 free(spu);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1121 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
1122 }
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1123
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1124 void spudec_set_hw_spu(void *this, vo_functions_t *hw_spu)
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1125 {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1126 spudec_handle_t *spu = (spudec_handle_t*)this;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1127 if (!spu)
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1128 return;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1129 spu->hw_spu = hw_spu;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1130 hw_spu->control(VOCTRL_SET_SPU_PALETTE,spu->global_palette);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5917
diff changeset
1131 }