annotate spudec.c @ 5328:014ddf03476d

check and set codec selection - impossible to do it at find_codec
author arpi
date Mon, 25 Mar 2002 03:19:43 +0000
parents bb6b9aca7195
children 3af2729c5c87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
1 /* Valid values for ANTIALIASING_ALGORITHM:
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
2 0: none (fastest, most ugly)
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
3 1: aproximate
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
4 2: full (slowest, best looking)
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
5 */
4810
bb6b9aca7195 10l accidently commited an already customized version with different default scaling algo.
atmos4
parents: 4809
diff changeset
6 #define ANTIALIASING_ALGORITHM 1
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
7
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
8 /* SPUdec.c
673
0fdcf08e7df8 (C) fixed
arpi_esp
parents: 561
diff changeset
9 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
10 Further works:
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
11 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
12
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
13 Kim Minh Kaplan
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
14 implement fragments reassembly, RLE decoding.
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
15 read brightness from the IFO.
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
16
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
17 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
18 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
19
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
20 */
3183
ce9acee4e129 Fix spudec compile with libdvdread enabled.
atmos4
parents: 3180
diff changeset
21 #include "config.h"
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
22 #include "mp_msg.h"
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
23
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
24 #include <errno.h>
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
25 #include <limits.h>
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
26 #include <stdio.h>
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
27 #include <stdlib.h>
3175
3538c34117a3 unistd.h required at least by FreeBSD
nexus
parents: 3166
diff changeset
28 #include <unistd.h>
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
29 #ifndef WITH_NO_ANTIALIASING
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
30 #include <math.h>
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
31 #endif
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
32 #include "spudec.h"
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
33
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
34 #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
35
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
36 typedef struct {
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
37 unsigned int global_palette[16];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
38 unsigned int orig_frame_width, orig_frame_height;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
39 unsigned char* packet;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
40 size_t packet_reserve; /* size of the memory pointed to by packet */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
41 unsigned int packet_offset; /* end of the currently assembled fragment */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
42 unsigned int packet_size; /* size of the packet once all fragments are assembled */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
43 unsigned int control_start; /* index of start of control data */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
44 unsigned int palette[4];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
45 unsigned int alpha[4];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
46 unsigned int now_pts;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
47 unsigned int start_pts, end_pts;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
48 unsigned int start_col, end_col;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
49 unsigned int start_row, end_row;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
50 unsigned int width, height, stride;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
51 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
52 processed (for RLE decoding) for
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
53 even and odd lines */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
54 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
55 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
56 unsigned char *image; /* Grayscale value */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
57 unsigned char *aimage; /* Alpha value */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
58 int scaled; /* flag if the image has already been scaled */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
59 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
60 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
61 size_t scaled_image_size;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
62 unsigned char *scaled_image;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
63 unsigned char *scaled_aimage;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
64 } spudec_handle_t;
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
65
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
66 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
67 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
68 return (p[0] << 8) + p[1];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
69 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
70
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
71 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
72 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
73 return (get_be16(p) << 8) + p[2];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
74 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
75
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
76 static void next_line(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
77 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
78 if (this->current_nibble[this->deinterlace_oddness] % 2)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
79 this->current_nibble[this->deinterlace_oddness]++;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
80 this->deinterlace_oddness = (this->deinterlace_oddness + 1) % 2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
81 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
82
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
83 static inline unsigned char get_nibble(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
84 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
85 unsigned char nib;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
86 unsigned int *nibblep = this->current_nibble + this->deinterlace_oddness;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
87 if (*nibblep / 2 >= this->control_start) {
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
88 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
89 return 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
90 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
91 nib = this->packet[*nibblep / 2];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
92 if (*nibblep % 2)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
93 nib &= 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
94 else
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
95 nib >>= 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
96 ++*nibblep;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
97 return nib;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
98 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
99
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
100 static inline int mkalpha(int i)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
101 {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
102 /* In mplayer's alpha planes, 0 is transparent, then 1 is nearly
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
103 opaque upto 255 which is transparent */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
104 switch (i) {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
105 case 0xf:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
106 return 1;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
107 case 0:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
108 return 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
109 default:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
110 return (0xf - i) << 4;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
111 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
112 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
113
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
114 static void spudec_process_data(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
115 {
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
116 unsigned int cmap[4], alpha[4];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
117 unsigned int i, x, y;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
118
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
119 this->scaled = 0;
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
120 for (i = 0; i < 4; ++i) {
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
121 alpha[i] = mkalpha(this->alpha[i]);
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
122 if (alpha[i] == 0)
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
123 cmap[i] = 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
124 else {
4122
3ee2a23f91c7 Fix brightness of subtitles
kmkaplan
parents: 4078
diff changeset
125 cmap[i] = ((this->global_palette[this->palette[i]] >> 16) & 0xff);
3ee2a23f91c7 Fix brightness of subtitles
kmkaplan
parents: 4078
diff changeset
126 if (cmap[i] + alpha[i] > 255)
3ee2a23f91c7 Fix brightness of subtitles
kmkaplan
parents: 4078
diff changeset
127 cmap[i] = 256 - alpha[i];
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
128 }
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
129 }
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
130
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
131 if (this->image_size < this->stride * this->height) {
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
132 if (this->image != NULL) {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
133 free(this->image);
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
134 this->image_size = 0;
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
135 }
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
136 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
137 if (this->image) {
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
138 this->image_size = this->stride * this->height;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
139 this->aimage = this->image + this->image_size;
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 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
142 if (this->image == NULL)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
143 return;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
144
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
145 /* Kludge: draw_alpha needs width multiple of 8. */
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
146 if (this->width < this->stride)
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
147 for (y = 0; y < this->height; ++y)
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
148 memset(this->aimage + y * this->stride + this->width, 0, this->stride - this->width);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
149
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
150 i = this->current_nibble[1];
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
151 x = 0;
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
152 y = 0;
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
153 while (this->current_nibble[0] < i
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
154 && this->current_nibble[1] / 2 < this->control_start
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
155 && y < this->height) {
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
156 unsigned int len, color;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
157 unsigned int rle = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
158 rle = get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
159 if (rle < 0x04) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
160 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
161 if (rle < 0x10) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
162 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
163 if (rle < 0x040) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
164 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
165 if (rle < 0x0004)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
166 rle |= ((this->width - x) << 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
167 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
168 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
169 }
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
170 color = 3 - (rle & 0x3);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
171 len = rle >> 2;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
172 if (len > this->width - x || len == 0)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
173 len = this->width - x;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
174 /* FIXME have to use palette and alpha map*/
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
175 memset(this->image + y * this->stride + x, cmap[color], len);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
176 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
177 x += len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
178 if (x >= this->width) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
179 next_line(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
180 x = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
181 ++y;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
182 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
183 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
184 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
185
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
186 static void spudec_process_control(spudec_handle_t *this, unsigned int pts100)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
187 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
188 int a,b; /* Temporary vars */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
189 unsigned int date, type;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
190 unsigned int off;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
191 unsigned int start_off = 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
192 unsigned int next_off;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
193
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
194 this->control_start = get_be16(this->packet + 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
195 next_off = this->control_start;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
196 while (start_off != next_off) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
197 start_off = next_off;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
198 date = get_be16(this->packet + start_off);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
199 next_off = get_be16(this->packet + start_off + 2);
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
200 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
201 off = start_off + 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
202 for (type = this->packet[off++]; type != 0xff; type = this->packet[off++]) {
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
203 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
204 switch(type) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
205 case 0x00:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
206 /* Menu ID, 1 byte */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
207 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Menu ID\n");
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
208 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
209 case 0x01:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
210 /* Start display */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
211 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
212 this->start_pts = pts100 + date;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
213 this->end_pts = UINT_MAX;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
214 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
215 case 0x02:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
216 /* Stop display */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
217 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
218 this->end_pts = pts100 + date;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
219 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
220 case 0x03:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
221 /* Palette */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
222 this->palette[0] = this->packet[off] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
223 this->palette[1] = this->packet[off] & 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
224 this->palette[2] = this->packet[off + 1] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
225 this->palette[3] = this->packet[off + 1] & 0xf;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
226 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
227 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
228 off+=2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
229 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
230 case 0x04:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
231 /* Alpha */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
232 this->alpha[0] = this->packet[off] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
233 this->alpha[1] = this->packet[off] & 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
234 this->alpha[2] = this->packet[off + 1] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
235 this->alpha[3] = this->packet[off + 1] & 0xf;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
236 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
237 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
238 off+=2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
239 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
240 case 0x05:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
241 /* Co-ords */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
242 a = get_be24(this->packet + off);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
243 b = get_be24(this->packet + off + 3);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
244 this->start_col = a >> 12;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
245 this->end_col = a & 0xfff;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
246 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
247 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
248 this->start_row = b >> 12;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
249 this->end_row = b & 0xfff;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
250 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
251 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
252 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
253 this->width, this->height);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
254 off+=6;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
255 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
256 case 0x06:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
257 /* Graphic lines */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
258 this->current_nibble[0] = 2 * get_be16(this->packet + off);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
259 this->current_nibble[1] = 2 * get_be16(this->packet + off + 2);
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
260 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
261 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
262 off+=4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
263 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
264 case 0xff:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
265 /* All done, bye-bye */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
266 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
267 return;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
268 // break;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
269 default:
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
270 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
271 type, next_off - off);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
272 goto next_control;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
273 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
274 }
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
275 next_control:
3725
ba98028ddc27 fixes warnings
pl
parents: 3402
diff changeset
276 ;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
277 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
278 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
279
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
280 static void spudec_decode(spudec_handle_t *this, unsigned int pts100)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
281 {
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
282 spudec_process_control(this, pts100);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
283 spudec_process_data(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
284 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
285
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
286
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
287 void spudec_assemble(void *this, unsigned char *packet, unsigned int len, unsigned int pts100)
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
288 {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
289 spudec_handle_t *spu = (spudec_handle_t*)this;
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
290 // spudec_heartbeat(this, pts100);
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
291 if (len < 2) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
292 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
293 return;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
294 }
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
295 if (spu->packet_offset == 0) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
296 unsigned int len2 = get_be16(packet);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
297 // Start new fragment
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
298 if (spu->packet_reserve < len2) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
299 if (spu->packet != NULL)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
300 free(spu->packet);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
301 spu->packet = malloc(len2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
302 spu->packet_reserve = spu->packet != NULL ? len2 : 0;
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
303 }
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
304 if (spu->packet != NULL) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
305 spu->deinterlace_oddness = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
306 spu->packet_size = len2;
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
307 if (len > len2) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
308 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
309 return;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
310 }
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
311 memcpy(spu->packet, packet, len);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
312 spu->packet_offset = len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
313 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
314 } else {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
315 // Continue current fragment
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
316 if (spu->packet_size < spu->packet_offset + len){
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
317 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid fragment\n");
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
318 spu->packet_size = spu->packet_offset = 0;
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
319 } else {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
320 memcpy(spu->packet + spu->packet_offset, packet, len);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
321 spu->packet_offset += len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
322 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
323 }
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
324 #if 1
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
325 // 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
326 // for some disks)
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
327 // if (spu->packet_offset == spu->packet_size)
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
328 { unsigned int x=0,y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
329 while(x+4<=spu->packet_offset){
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
330 y=get_be16(spu->packet+x+2); // next control pointer
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
331 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUtest: x=%d y=%d off=%d size=%d\n",x,y,spu->packet_offset,spu->packet_size);
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
332 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
333 // we got it!
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
334 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUgot: off=%d size=%d \n",spu->packet_offset,spu->packet_size);
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
335 spudec_decode(spu, pts100);
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
336 spu->packet_offset = 0;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
337 break;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
338 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
339 if(y<=x || y>=spu->packet_size){ // invalid?
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
340 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUtest: broken packet!!!!! y=%d < x=%d\n",y,x);
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
341 spu->packet_size = spu->packet_offset = 0;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
342 break;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
343 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
344 x=y;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
345 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
346 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
347 #else
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
348 if (spu->packet_offset == spu->packet_size) {
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
349 spudec_decode(spu, pts100);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
350 spu->packet_offset = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
351 }
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
352 #endif
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
353 }
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
354
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
355 void spudec_reset(void *this) // called after seek
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
356 {
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
357 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
358 spu->now_pts = 0;
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
359 spu->packet_size = spu->packet_offset = 0;
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
360 }
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
361
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
362 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
363 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
364 ((spudec_handle_t *)this)->now_pts = pts100;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
365 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
366
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
367 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
368 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
369 spudec_handle_t *spu = (spudec_handle_t *)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
370 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts && spu->image)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
371 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
372 spu->image, spu->aimage, spu->stride);
561
36fd71db0d33 spudec_decode() moved from mplayer.c to spudec.c
arpi_esp
parents: 560
diff changeset
373 }
36fd71db0d33 spudec_decode() moved from mplayer.c to spudec.c
arpi_esp
parents: 560
diff changeset
374
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
375 /* 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
376 static inline int canon_alpha(int alpha)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
377 {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
378 return alpha ? 256 - alpha : 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
379 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
380
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
381 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
382 {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
383 spudec_handle_t *spu = (spudec_handle_t *)me;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
384 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
385 if (spu->orig_frame_width == 0 || spu->orig_frame_height == 0
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
386 || (spu->orig_frame_width == dxs && spu->orig_frame_height == dys)) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
387 if (spu->image)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
388 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
389 spu->image, spu->aimage, spu->stride);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
390 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
391 else {
4809
e508a517c33d Forgot to commit with vo_sdl osd patch.
atmos4
parents: 4180
diff changeset
392 if (!spu->scaled ||
e508a517c33d Forgot to commit with vo_sdl osd patch.
atmos4
parents: 4180
diff changeset
393 spu->orig_frame_width != dxs || spu->orig_frame_height != dys) { /* Resizing is needed */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
394 /* scaled_x = scalex * x / 0x100
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
395 scaled_y = scaley * y / 0x100
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
396 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
397 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
398 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
399 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
400 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
401 spu->scaled_width = spu->width * scalex / 0x100;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
402 spu->scaled_height = spu->height * scaley / 0x100;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
403 /* 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
404 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
405 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
406 if (spu->scaled_image) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
407 free(spu->scaled_image);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
408 spu->scaled_image_size = 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
409 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
410 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
411 if (spu->scaled_image) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
412 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
413 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
414 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
415 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
416 if (spu->scaled_image) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
417 unsigned int x, y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
418 /* 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
419 if (spu->scaled_width < spu->scaled_stride)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
420 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
421 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
422 spu->scaled_stride - spu->scaled_width);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
423 /* FIXME: Why is this one needed? */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
424 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
425 spu->scaled_stride - spu->scaled_width);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
426 }
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
427 #if ANTIALIASING_ALGORITHM == 0
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
428 /* no antialiasing */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
429 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
430 int unscaled_y = y * 0x100 / scaley;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
431 int strides = spu->stride * unscaled_y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
432 int scaled_strides = spu->scaled_stride * y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
433 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
434 int unscaled_x = x * 0x100 / scalex;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
435 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
436 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
437 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
438 }
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
439 #elif ANTIALIASING_ALGORITHM == 1
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
440 {
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
441 /* Intermediate antialiasing. */
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
442 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
443 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
444 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
445 if (unscaled_bottom >= spu->height)
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
446 unscaled_bottom = spu->height - 1;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
447 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
448 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
449 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
450 unsigned int color = 0;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
451 unsigned int alpha = 0;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
452 unsigned int walkx, walky;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
453 unsigned int base, tmp;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
454 if (unscaled_right >= spu->width)
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
455 unscaled_right = spu->width - 1;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
456 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
457 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
458 base = walky * spu->stride + walkx;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
459 tmp = canon_alpha(spu->aimage[base]);
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
460 alpha += tmp;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
461 color += tmp * spu->image[base];
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
462 }
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
463 base = y * spu->scaled_stride + x;
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
464 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
465 spu->scaled_aimage[base] =
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
466 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
467 /* spu->scaled_aimage[base] =
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
468 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
469 if (spu->scaled_aimage[base]) {
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
470 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
471 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
472 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
473 }
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
474 }
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
475 }
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
476 }
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
477 #else
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
478 {
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
479 /* Best antialiasing. Very slow. */
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
480 /* 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
481 rectangular region comprised between the columns
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
482 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
483 unscaled_x and unscaled_x + 0x100 / scalex
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
484
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
485 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
486 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
487
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
488 +---+-----------------+---+
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
489 | 1 | 2 | 3 |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
490 +---+-----------------+---+
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
491 | | | |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
492 | 4 | 5 | 6 |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
493 | | | |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
494 +---+-----------------+---+
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
495 | 7 | 8 | 9 |
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
496 +---+-----------------+---+
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
497
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
498 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
499 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
500 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
501 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
502 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
503 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
504 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
505 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
506 one pixel.
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
507
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
508 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
509 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
510 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
511 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
512
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
513 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
514 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
515 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
516 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
517 unscaled_x_right. */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
518 const double inv_scalex = (double) 0x100 / scalex;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
519 const double inv_scaley = (double) 0x100 / scaley;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
520 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
521 const double unscaled_y = y * inv_scaley;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
522 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
523 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
524 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
525 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
526 ? (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
527 : 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
528 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
529 ? unscaled_y_bottom - floor(unscaled_y_bottom)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
530 : 0.0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
531 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
532 const double unscaled_x = x * inv_scalex;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
533 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
534 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
535 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
536 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
537 ? (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
538 : 0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
539 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
540 ? unscaled_x_right - floor(unscaled_x_right)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
541 : 0.0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
542 double color = 0.0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
543 double alpha = 0.0;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
544 double tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
545 unsigned int base;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
546 /* 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
547 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
548 region's surface and alpha and lightness.
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
549
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
550 transformed alpha = sum(surface * alpha) / sum(surface)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
551 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
552 */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
553 /* 1: top left part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
554 base = spu->stride * (unsigned int) unscaled_y;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
555 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
556 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
557 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
558 /* 2: top center part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
559 if (width > 0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
560 unsigned int walkx;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
561 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
562 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
563 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
564 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
565 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
566 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
567 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
568 /* 3: top right part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
569 if (right > 0.0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
570 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
571 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
572 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
573 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
574 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
575 /* 4: center left part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
576 if (height > 0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
577 unsigned int walky;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
578 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
579 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
580 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
581 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
582 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
583 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
584 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
585 /* 5: center part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
586 if (width > 0 && height > 0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
587 unsigned int walky;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
588 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
589 unsigned int walkx;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
590 base = spu->stride * walky;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
591 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
592 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
593 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
594 color += tmp * spu->image[base + walkx];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
595 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
596 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
597 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
598 /* 6: center right part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
599 if (right > 0.0 && height > 0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
600 unsigned int walky;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
601 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
602 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
603 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
604 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
605 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
606 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
607 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
608 /* 7: bottom left part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
609 if (bottom > 0.0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
610 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
611 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
612 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
613 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
614 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
615 /* 8: bottom center part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
616 if (width > 0 && bottom > 0.0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
617 unsigned int walkx;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
618 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
619 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
620 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
621 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
622 color += tmp * spu->image[base + walkx];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
623 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
624 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
625 /* 9: bottom right part */
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
626 if (right > 0.0 && bottom > 0.0) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
627 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
628 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
629 alpha += tmp;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
630 color += tmp * spu->image[base];
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
631 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
632 /* 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
633 base = spu->scaled_stride * y + x;
4180
a70ded82ff77 Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents: 4122
diff changeset
634 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
635 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
636 if (spu->scaled_aimage[base]) {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
637 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
638 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
639 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
640 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
641 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
642 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
643 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
644 #endif
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
645 spu->scaled = 1;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
646 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
647 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
648 if (spu->scaled_image)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
649 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
650 spu->scaled_image, spu->scaled_aimage, spu->scaled_stride);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
651 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
652 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
653 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
654
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
655 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
656 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
657 spudec_handle_t *this = calloc(1, sizeof(spudec_handle_t));
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
658 if (this) {
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
659 if (palette)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
660 memcpy(this->global_palette, palette, sizeof(this->global_palette));
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
661 this->packet = NULL;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
662 this->image = NULL;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
663 this->scaled_image = NULL;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
664 this->orig_frame_width = frame_width;
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
665 this->orig_frame_height = frame_height;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
666 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
667 else
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
668 perror("FATAL: spudec_init: calloc");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
669 return this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
670 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
671
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
672 void *spudec_new(unsigned int *palette)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
673 {
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
674 return spudec_new_scaled(palette, 0, 0);
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
675 }
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
676
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
677 void spudec_free(void *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
678 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
679 spudec_handle_t *spu = (spudec_handle_t*)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
680 if (spu) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
681 if (spu->packet)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
682 free(spu->packet);
4078
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
683 if (spu->scaled_image)
a8e7238bb7b4 Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents: 3842
diff changeset
684 free(spu->scaled_image);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
685 if (spu->image)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
686 free(spu->image);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
687 free(spu);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
688 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
689 }