Mercurial > mplayer.hg
annotate spudec.c @ 6158:74cfd91b82cd
some visual changes and applied Ulrich Hecht's 64bit fixes
author | alex |
---|---|
date | Thu, 23 May 2002 14:38:40 +0000 |
parents | 7bea806b9c5f |
children | bd6748605681 |
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 | 8 /* SPUdec.c |
673 | 9 Skeleton of function spudec_process_controll() is from xine sources. |
560 | 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 | 15 read brightness from the IFO. |
560 | 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 | 18 and <URL:http://members.aol.com/mpucoder/DVD/spu.html> |
560 | 19 |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
20 */ |
3183 | 21 #include "config.h" |
3822 | 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 | 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 | 28 #include <unistd.h> |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
4810
diff
changeset
|
29 #if ANTIALIASING_ALGORITHM == 2 |
4078
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 |
6110 | 32 #include "libvo/video_out.h" |
560 | 33 #include "spudec.h" |
34 | |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
35 #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
|
36 |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
37 typedef struct { |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
38 unsigned int global_palette[16]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
39 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
|
40 unsigned char* packet; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
41 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
|
42 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
|
43 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
|
44 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
|
45 unsigned int palette[4]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
46 unsigned int alpha[4]; |
5833
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
47 unsigned int cuspal[4]; |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
48 unsigned int custom; |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
49 unsigned int now_pts; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
50 unsigned int start_pts, end_pts; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
51 unsigned int start_col, end_col; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
52 unsigned int start_row, end_row; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
53 unsigned int width, height, stride; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
54 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
|
55 processed (for RLE decoding) for |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
56 even and odd lines */ |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
57 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
|
58 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
|
59 unsigned char *image; /* Grayscale value */ |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
60 unsigned char *aimage; /* Alpha value */ |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
4810
diff
changeset
|
61 unsigned int scaled_frame_width, scaled_frame_height; |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
62 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
|
63 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
|
64 size_t scaled_image_size; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
65 unsigned char *scaled_image; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
66 unsigned char *scaled_aimage; |
6110 | 67 int auto_palette; /* 1 if we lack a palette and must use an heuristic. */ |
68 int font_start_level; /* Darkest value used for the computed font */ | |
69 vo_functions_t *hw_spu; | |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
70 } spudec_handle_t; |
560 | 71 |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
72 |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
73 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
|
74 { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
75 return (p[0] << 8) + p[1]; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
76 } |
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 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
|
79 { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
80 return (get_be16(p) << 8) + p[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 void next_line(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 if (this->current_nibble[this->deinterlace_oddness] % 2) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
86 this->current_nibble[this->deinterlace_oddness]++; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
87 this->deinterlace_oddness = (this->deinterlace_oddness + 1) % 2; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
88 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
89 |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
90 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
|
91 { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
92 unsigned char nib; |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
93 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
|
94 if (*nibblep / 2 >= this->control_start) { |
3822 | 95 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
|
96 return 0; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
97 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
98 nib = this->packet[*nibblep / 2]; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
99 if (*nibblep % 2) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
100 nib &= 0xf; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
101 else |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
102 nib >>= 4; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
103 ++*nibblep; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
104 return nib; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
105 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
106 |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
107 static inline int mkalpha(int i) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
108 { |
3166 | 109 /* In mplayer's alpha planes, 0 is transparent, then 1 is nearly |
110 opaque upto 255 which is transparent */ | |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
111 switch (i) { |
3166 | 112 case 0xf: |
113 return 1; | |
114 case 0: | |
115 return 0; | |
116 default: | |
117 return (0xf - i) << 4; | |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
118 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
119 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
120 |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
121 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
|
122 { |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
123 unsigned int cmap[4], alpha[4]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
124 unsigned int i, x, y; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
125 |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
4810
diff
changeset
|
126 this->scaled_frame_width = 0; |
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
4810
diff
changeset
|
127 this->scaled_frame_height = 0; |
3166 | 128 for (i = 0; i < 4; ++i) { |
129 alpha[i] = mkalpha(this->alpha[i]); | |
130 if (alpha[i] == 0) | |
131 cmap[i] = 0; | |
5833
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
132 else if (this->custom){ |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
133 cmap[i] = ((this->cuspal[i] >> 16) & 0xff); |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
134 if (cmap[i] + alpha[i] > 255) |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
135 cmap[i] = 256 - alpha[i]; |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
136 } |
3166 | 137 else { |
4122 | 138 cmap[i] = ((this->global_palette[this->palette[i]] >> 16) & 0xff); |
139 if (cmap[i] + alpha[i] > 255) | |
140 cmap[i] = 256 - alpha[i]; | |
3166 | 141 } |
142 } | |
143 | |
3402 | 144 if (this->image_size < this->stride * this->height) { |
145 if (this->image != NULL) { | |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
146 free(this->image); |
3402 | 147 this->image_size = 0; |
148 } | |
149 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
|
150 if (this->image) { |
3402 | 151 this->image_size = this->stride * this->height; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
152 this->aimage = this->image + this->image_size; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
153 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
154 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
155 if (this->image == NULL) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
156 return; |
3402 | 157 |
158 /* Kludge: draw_alpha needs width multiple of 8. */ | |
159 if (this->width < this->stride) | |
160 for (y = 0; y < this->height; ++y) | |
161 memset(this->aimage + y * this->stride + this->width, 0, this->stride - this->width); | |
162 | |
3166 | 163 i = this->current_nibble[1]; |
3402 | 164 x = 0; |
165 y = 0; | |
3166 | 166 while (this->current_nibble[0] < i |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
167 && this->current_nibble[1] / 2 < this->control_start |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
168 && y < this->height) { |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
169 unsigned int len, color; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
170 unsigned int rle = 0; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
171 rle = get_nibble(this); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
172 if (rle < 0x04) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
173 rle = (rle << 4) | get_nibble(this); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
174 if (rle < 0x10) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
175 rle = (rle << 4) | get_nibble(this); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
176 if (rle < 0x040) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
177 rle = (rle << 4) | get_nibble(this); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
178 if (rle < 0x0004) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
179 rle |= ((this->width - x) << 2); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
180 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
181 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
182 } |
3166 | 183 color = 3 - (rle & 0x3); |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
184 len = rle >> 2; |
3402 | 185 if (len > this->width - x || len == 0) |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
186 len = this->width - x; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
187 /* FIXME have to use palette and alpha map*/ |
3402 | 188 memset(this->image + y * this->stride + x, cmap[color], len); |
189 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
|
190 x += len; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
191 if (x >= this->width) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
192 next_line(this); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
193 x = 0; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
194 ++y; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
195 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
196 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
197 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
198 |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
199 |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
200 /* |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
201 This function tries to create a usable palette. |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
202 Is searchs how many non-transparent colors are used and assigns different |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
203 gray scale values to each color. |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
204 I tested it with four streams and even got something readable. Half of the |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
205 times I got black characters with white around and half the reverse. |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
206 */ |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
207 static void compute_palette(spudec_handle_t *this) |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
208 { |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
209 int used[16],i,cused,start,step,color; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
210 |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
211 memset(used, 0, sizeof(used)); |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
212 for (i=0; i<4; i++) |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
213 if (this->alpha[i]) /* !Transparent? */ |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
214 used[this->palette[i]] = 1; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
215 for (cused=0, i=0; i<16; i++) |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
216 if (used[i]) cused++; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
217 if (!cused) return; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
218 if (cused == 1) { |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
219 start = 0x80; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
220 step = 0; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
221 } else { |
6110 | 222 start = this->font_start_level; |
223 step = (0xF0-this->font_start_level)/(cused-1); | |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
224 } |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
225 memset(used, 0, sizeof(used)); |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
226 for (i=0; i<4; i++) { |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
227 color = this->palette[i]; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
228 if (this->alpha[i] && !used[color]) { /* not assigned? */ |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
229 used[color] = 1; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
230 this->global_palette[color] = start<<16; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
231 start += step; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
232 } |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
233 } |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
234 } |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
235 |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
236 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
|
237 { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
238 int a,b; /* Temporary vars */ |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
239 unsigned int date, type; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
240 unsigned int off; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
241 unsigned int start_off = 0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
242 unsigned int next_off; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
243 |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
244 this->control_start = get_be16(this->packet + 2); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
245 next_off = this->control_start; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
246 while (start_off != next_off) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
247 start_off = next_off; |
5488
3f183ca22747
fixed SPU pts, it's 1024/90000 based instead of 1/100
arpi
parents:
5474
diff
changeset
|
248 date = get_be16(this->packet + start_off) * 1024; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
249 next_off = get_be16(this->packet + start_off + 2); |
3822 | 250 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
|
251 off = start_off + 4; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
252 for (type = this->packet[off++]; type != 0xff; type = this->packet[off++]) { |
3822 | 253 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
|
254 switch(type) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
255 case 0x00: |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
256 /* Menu ID, 1 byte */ |
3822 | 257 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Menu ID\n"); |
5474
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
258 /* shouldn't a Menu ID type force display start? */ |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
259 //this->start_pts = pts100 + date; |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
260 //this->end_pts = UINT_MAX; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
261 break; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
262 case 0x01: |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
263 /* Start display */ |
3822 | 264 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Start display!\n"); |
3842 | 265 this->start_pts = pts100 + date; |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
266 this->end_pts = UINT_MAX; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
267 break; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
268 case 0x02: |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
269 /* Stop display */ |
3822 | 270 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Stop display!\n"); |
3842 | 271 this->end_pts = pts100 + date; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
272 break; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
273 case 0x03: |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
274 /* Palette */ |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
275 this->palette[0] = this->packet[off] >> 4; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
276 this->palette[1] = this->packet[off] & 0xf; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
277 this->palette[2] = this->packet[off + 1] >> 4; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
278 this->palette[3] = this->packet[off + 1] & 0xf; |
3822 | 279 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
|
280 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
|
281 off+=2; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
282 break; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
283 case 0x04: |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
284 /* Alpha */ |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
285 this->alpha[0] = this->packet[off] >> 4; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
286 this->alpha[1] = this->packet[off] & 0xf; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
287 this->alpha[2] = this->packet[off + 1] >> 4; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
288 this->alpha[3] = this->packet[off + 1] & 0xf; |
6110 | 289 if (this->auto_palette) { |
290 compute_palette(this); | |
291 this->auto_palette = 0; | |
292 } | |
3822 | 293 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
|
294 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
|
295 off+=2; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
296 break; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
297 case 0x05: |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
298 /* Co-ords */ |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
299 a = get_be24(this->packet + off); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
300 b = get_be24(this->packet + off + 3); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
301 this->start_col = a >> 12; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
302 this->end_col = a & 0xfff; |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
303 this->width = (this->end_col < this->start_col) ? 0 : this->end_col - this->start_col + 1; |
3402 | 304 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
|
305 this->start_row = b >> 12; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
306 this->end_row = b & 0xfff; |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
307 this->height = (this->end_row < this->start_row) ? 0 : this->end_row - this->start_row /* + 1 */; |
3822 | 308 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
|
309 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
|
310 this->width, this->height); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
311 off+=6; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
312 break; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
313 case 0x06: |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
314 /* Graphic lines */ |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
315 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
|
316 this->current_nibble[1] = 2 * get_be16(this->packet + off + 2); |
3822 | 317 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
|
318 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
|
319 off+=4; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
320 break; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
321 case 0xff: |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
322 /* All done, bye-bye */ |
3822 | 323 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
|
324 return; |
3822 | 325 // break; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
326 default: |
3822 | 327 mp_msg(MSGT_SPUDEC,MSGL_WARN,"spudec: Error determining control type 0x%02x. Skipping %d bytes.\n", |
3402 | 328 type, next_off - off); |
329 goto next_control; | |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
330 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
331 } |
3402 | 332 next_control: |
3725 | 333 ; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
334 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
335 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
336 |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
337 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
|
338 { |
6110 | 339 if(this->hw_spu) { |
340 static vo_mpegpes_t packet = { NULL, 0, 0x20, 0 }; | |
341 static vo_mpegpes_t *pkg=&packet; | |
342 packet.data = this->packet; | |
343 packet.size = this->packet_size; | |
344 packet.timestamp = pts100; | |
345 this->hw_spu->draw_frame((uint8_t**)&pkg); | |
346 } else { | |
347 spudec_process_control(this, pts100); | |
348 spudec_process_data(this); | |
349 } | |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
350 } |
560 | 351 |
352 | |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
353 void spudec_assemble(void *this, unsigned char *packet, unsigned int len, unsigned int pts100) |
560 | 354 { |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
355 spudec_handle_t *spu = (spudec_handle_t*)this; |
3842 | 356 // spudec_heartbeat(this, pts100); |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
357 if (len < 2) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
358 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
|
359 return; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
360 } |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
361 if (spu->packet_offset == 0) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
362 unsigned int len2 = get_be16(packet); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
363 // Start new fragment |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
364 if (spu->packet_reserve < len2) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
365 if (spu->packet != NULL) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
366 free(spu->packet); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
367 spu->packet = malloc(len2); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
368 spu->packet_reserve = spu->packet != NULL ? len2 : 0; |
560 | 369 } |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
370 if (spu->packet != NULL) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
371 spu->deinterlace_oddness = 0; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
372 spu->packet_size = len2; |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
373 if (len > len2) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
374 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
|
375 return; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
376 } |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
377 memcpy(spu->packet, packet, len); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
378 spu->packet_offset = len; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
379 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
380 } else { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
381 // Continue current fragment |
3744 | 382 if (spu->packet_size < spu->packet_offset + len){ |
3822 | 383 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid fragment\n"); |
3744 | 384 spu->packet_size = spu->packet_offset = 0; |
385 } else { | |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
386 memcpy(spu->packet + spu->packet_offset, packet, len); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
387 spu->packet_offset += len; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
388 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
389 } |
3820 | 390 #if 1 |
391 // check if we have a complete packet (unfortunatelly packet_size is bad | |
392 // for some disks) | |
5917 | 393 if (spu->packet_offset == spu->packet_size){ |
394 unsigned int x=0,y; | |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
395 while(x+4<=spu->packet_offset){ |
3820 | 396 y=get_be16(spu->packet+x+2); // next control pointer |
3822 | 397 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 | 398 if(x>=4 && x==y){ // if it points to self - we're done! |
399 // we got it! | |
3822 | 400 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUgot: off=%d size=%d \n",spu->packet_offset,spu->packet_size); |
3842 | 401 spudec_decode(spu, pts100); |
3820 | 402 spu->packet_offset = 0; |
403 break; | |
404 } | |
405 if(y<=x || y>=spu->packet_size){ // invalid? | |
3822 | 406 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUtest: broken packet!!!!! y=%d < x=%d\n",y,x); |
3820 | 407 spu->packet_size = spu->packet_offset = 0; |
408 break; | |
409 } | |
410 x=y; | |
411 } | |
412 } | |
413 #else | |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
414 if (spu->packet_offset == spu->packet_size) { |
3842 | 415 spudec_decode(spu, pts100); |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
416 spu->packet_offset = 0; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
417 } |
3820 | 418 #endif |
560 | 419 } |
420 | |
3744 | 421 void spudec_reset(void *this) // called after seek |
422 { | |
423 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
|
424 spu->now_pts = 0; |
3744 | 425 spu->packet_size = spu->packet_offset = 0; |
426 } | |
427 | |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
428 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
|
429 { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
430 ((spudec_handle_t *)this)->now_pts = pts100; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
431 } |
560 | 432 |
5638
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
5488
diff
changeset
|
433 int spudec_visible(void *this){ |
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
5488
diff
changeset
|
434 spudec_handle_t *spu = (spudec_handle_t *)this; |
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
5488
diff
changeset
|
435 int ret=(spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts); |
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
5488
diff
changeset
|
436 // printf("spu visible: %d \n",ret); |
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
5488
diff
changeset
|
437 return ret; |
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
5488
diff
changeset
|
438 } |
86663f1b9b00
new osd code, use osd objs to follow changes and do minimal updates
arpi
parents:
5488
diff
changeset
|
439 |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
440 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
|
441 { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
442 spudec_handle_t *spu = (spudec_handle_t *)this; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
443 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
|
444 draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height, |
3402 | 445 spu->image, spu->aimage, spu->stride); |
561 | 446 } |
447 | |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
448 /* 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
|
449 static inline int canon_alpha(int alpha) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
450 { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
451 return alpha ? 256 - alpha : 0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
452 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
453 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
454 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
|
455 { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
456 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
|
457 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
|
458 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
|
459 || (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
|
460 if (spu->image) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
461 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
|
462 spu->image, spu->aimage, spu->stride); |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
463 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
464 else { |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
4810
diff
changeset
|
465 if (spu->scaled_frame_width != dxs || spu->scaled_frame_height != dys) { /* Resizing is needed */ |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
466 /* scaled_x = scalex * x / 0x100 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
467 scaled_y = scaley * y / 0x100 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 spu->scaled_width = spu->width * scalex / 0x100; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
474 spu->scaled_height = spu->height * scaley / 0x100; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
475 /* 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
|
476 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
|
477 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
|
478 if (spu->scaled_image) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
479 free(spu->scaled_image); |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
480 spu->scaled_image_size = 0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
481 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
482 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
|
483 if (spu->scaled_image) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
484 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
|
485 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
|
486 } |
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 if (spu->scaled_image) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
489 unsigned int x, y; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
490 /* 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
|
491 if (spu->scaled_width < spu->scaled_stride) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
492 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
|
493 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
|
494 spu->scaled_stride - spu->scaled_width); |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
495 /* FIXME: Why is this one needed? */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
496 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
|
497 spu->scaled_stride - spu->scaled_width); |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
498 } |
4180
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
499 #if ANTIALIASING_ALGORITHM == 0 |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
500 /* no antialiasing */ |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
501 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
|
502 int unscaled_y = y * 0x100 / scaley; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
503 int strides = spu->stride * unscaled_y; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
504 int scaled_strides = spu->scaled_stride * y; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
505 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
|
506 int unscaled_x = x * 0x100 / scalex; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
507 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
|
508 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
|
509 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
510 } |
4180
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
511 #elif ANTIALIASING_ALGORITHM == 1 |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
512 { |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
513 /* Intermediate antialiasing. */ |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
514 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
|
515 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
|
516 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
|
517 if (unscaled_bottom >= spu->height) |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
518 unscaled_bottom = spu->height - 1; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
519 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
|
520 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
|
521 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
|
522 unsigned int color = 0; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
523 unsigned int alpha = 0; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
524 unsigned int walkx, walky; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
525 unsigned int base, tmp; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
526 if (unscaled_right >= spu->width) |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
527 unscaled_right = spu->width - 1; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
528 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
|
529 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
|
530 base = walky * spu->stride + walkx; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
531 tmp = canon_alpha(spu->aimage[base]); |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
532 alpha += tmp; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
533 color += tmp * spu->image[base]; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
534 } |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
535 base = y * spu->scaled_stride + x; |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
536 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
|
537 spu->scaled_aimage[base] = |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
538 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
|
539 /* spu->scaled_aimage[base] = |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
540 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
|
541 if (spu->scaled_aimage[base]) { |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
542 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
|
543 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
|
544 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
|
545 } |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
546 } |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
547 } |
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
548 } |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
549 #else |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
550 { |
4180
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
551 /* Best antialiasing. Very slow. */ |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
552 /* 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
|
553 rectangular region comprised between the columns |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
554 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
|
555 unscaled_x and unscaled_x + 0x100 / scalex |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
556 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
557 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
|
558 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
|
559 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
560 +---+-----------------+---+ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
561 | 1 | 2 | 3 | |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
562 +---+-----------------+---+ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
563 | | | | |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
564 | 4 | 5 | 6 | |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
565 | | | | |
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 | 7 | 8 | 9 | |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
568 +---+-----------------+---+ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
569 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
570 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 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
|
578 one pixel. |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
579 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
580 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
|
581 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
|
582 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
|
583 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
|
584 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
585 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
|
586 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
|
587 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
|
588 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
|
589 unscaled_x_right. */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
590 const double inv_scalex = (double) 0x100 / scalex; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
591 const double inv_scaley = (double) 0x100 / scaley; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
592 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
|
593 const double unscaled_y = y * inv_scaley; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
594 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
|
595 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
|
596 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
|
597 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
|
598 ? (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
|
599 : 0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
600 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
|
601 ? unscaled_y_bottom - floor(unscaled_y_bottom) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
602 : 0.0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
603 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
|
604 const double unscaled_x = x * inv_scalex; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 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
|
609 ? (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
|
610 : 0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
611 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
|
612 ? unscaled_x_right - floor(unscaled_x_right) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
613 : 0.0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
614 double color = 0.0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
615 double alpha = 0.0; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
616 double tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
617 unsigned int base; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
618 /* 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
|
619 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
|
620 region's surface and alpha and lightness. |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
621 |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
622 transformed alpha = sum(surface * alpha) / sum(surface) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
623 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
|
624 */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
625 /* 1: top left part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
626 base = spu->stride * (unsigned int) unscaled_y; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
627 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
|
628 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
629 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
|
630 /* 2: top center part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
631 if (width > 0) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
632 unsigned int walkx; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
633 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
|
634 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
|
635 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
|
636 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
637 color += tmp * spu->image[base]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
638 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
639 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
640 /* 3: top right part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
641 if (right > 0.0) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
642 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
|
643 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
|
644 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
645 color += tmp * spu->image[base]; |
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 /* 4: center left part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
648 if (height > 0) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
649 unsigned int walky; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
650 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
|
651 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
|
652 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
|
653 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
654 color += tmp * spu->image[base]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
655 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
656 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
657 /* 5: center part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
658 if (width > 0 && height > 0) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
659 unsigned int walky; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
660 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
|
661 unsigned int walkx; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
662 base = spu->stride * walky; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
663 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
|
664 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
|
665 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
666 color += tmp * spu->image[base + walkx]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
667 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
668 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
669 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
670 /* 6: center right part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
671 if (right > 0.0 && height > 0) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
672 unsigned int walky; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
673 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
|
674 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
|
675 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
|
676 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
677 color += tmp * spu->image[base]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
678 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
679 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
680 /* 7: bottom left part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
681 if (bottom > 0.0) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
682 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
|
683 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
|
684 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
685 color += tmp * spu->image[base]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
686 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
687 /* 8: bottom center part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
688 if (width > 0 && bottom > 0.0) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
689 unsigned int walkx; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
690 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
|
691 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
|
692 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
|
693 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
694 color += tmp * spu->image[base + walkx]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
695 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
696 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
697 /* 9: bottom right part */ |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
698 if (right > 0.0 && bottom > 0.0) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
699 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
|
700 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
|
701 alpha += tmp; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
702 color += tmp * spu->image[base]; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
703 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
704 /* 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
|
705 base = spu->scaled_stride * y + x; |
4180
a70ded82ff77
Add a third scaling algorithm wich should be faster. Select by
kmkaplan
parents:
4122
diff
changeset
|
706 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
|
707 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
|
708 if (spu->scaled_aimage[base]) { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
709 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
|
710 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
|
711 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
|
712 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
713 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
714 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
715 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
716 #endif |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
4810
diff
changeset
|
717 spu->scaled_frame_width = dxs; |
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
4810
diff
changeset
|
718 spu->scaled_frame_height = dys; |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
719 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
720 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
721 if (spu->scaled_image) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
722 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
|
723 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
|
724 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
725 } |
5474
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
726 else |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
727 { |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
728 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPU not displayed: start_pts=%d end_pts=%d now_pts=%d\n", |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
729 spu->start_pts, spu->end_pts, spu->now_pts); |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
730 } |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
731 } |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
732 |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
733 void spudec_update_palette(void * this, unsigned int *palette) |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
734 { |
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
735 spudec_handle_t *spu = (spudec_handle_t *) this; |
6110 | 736 if (spu && palette) { |
5474
a303ae797429
spudec_update_palette() added - dvdnav patch by Kees Cook <mplayer@outflux.net>
arpi
parents:
5388
diff
changeset
|
737 memcpy(spu->global_palette, palette, sizeof(spu->global_palette)); |
6110 | 738 if(spu->hw_spu) |
739 spu->hw_spu->control(VOCTRL_SET_SPU_PALETTE,spu->global_palette); | |
740 } | |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
741 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
742 |
6110 | 743 void spudec_set_font_factor(void * this, double factor) |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
744 { |
6110 | 745 spudec_handle_t *spu = (spudec_handle_t *) this; |
746 spu->font_start_level = (int)(0xF0-(0xE0*factor)); | |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
747 } |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
748 |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
749 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
|
750 { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
751 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
|
752 if (this) { |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
753 if (palette) { |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
754 memcpy(this->global_palette, palette, sizeof(this->global_palette)); |
6110 | 755 this->auto_palette = 0; |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
756 } |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
757 else { |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
758 /* No palette, compute one */ |
6110 | 759 this->auto_palette = 1; |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
760 } |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
761 this->packet = NULL; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
762 this->image = NULL; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
763 this->scaled_image = NULL; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
764 this->orig_frame_width = frame_width; |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
765 this->orig_frame_height = frame_height; |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
766 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
767 else |
6110 | 768 mp_msg(MSGT_SPUDEC,MSGL_FATAL, "FATAL: spudec_init: calloc"); |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
769 return this; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
770 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
771 |
5833
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
772 /* get palette custom color, width, height from .idx file */ |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
773 void *spudec_new_scaled_vobsub(unsigned int *palette, unsigned int *cuspal, unsigned int custom, unsigned int frame_width, unsigned int frame_height) |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
774 { |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
775 spudec_handle_t *this = calloc(1, sizeof(spudec_handle_t)); |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
776 if (this){ |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
777 //(fprintf(stderr,"VobSub Custom Palette: %d,%d,%d,%d", this->cuspal[0], this->cuspal[1], this->cuspal[2],this->cuspal[3]); |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
778 this->packet = NULL; |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
779 this->image = NULL; |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
780 this->scaled_image = NULL; |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
781 this->orig_frame_width = frame_width; |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
782 this->orig_frame_height = frame_height; |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
783 this->custom = custom; |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
784 // set up palette: |
6110 | 785 this->auto_palette = 1; |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
786 if (palette){ |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
787 memcpy(this->global_palette, palette, sizeof(this->global_palette)); |
6110 | 788 this->auto_palette = 0; |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
789 } |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
790 this->custom = custom; |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
791 if (custom && cuspal) { |
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
792 memcpy(this->cuspal, cuspal, sizeof(this->cuspal)); |
6110 | 793 this->auto_palette = 0; |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
794 } |
5833
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
795 } |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
796 else |
6110 | 797 mp_msg(MSGT_SPUDEC,MSGL_FATAL, "FATAL: spudec_init: calloc"); |
5833
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
798 return this; |
91d766389a5d
VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents:
5638
diff
changeset
|
799 } |
5908
31159f453cf9
guessing palette - patch by salvador <salvador@inti.gov.ar>
arpi
parents:
5833
diff
changeset
|
800 |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
801 void *spudec_new(unsigned int *palette) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
802 { |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
803 return spudec_new_scaled(palette, 0, 0); |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
804 } |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
805 |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
806 void spudec_free(void *this) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
807 { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
808 spudec_handle_t *spu = (spudec_handle_t*)this; |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
809 if (spu) { |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
810 if (spu->packet) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
811 free(spu->packet); |
4078
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
812 if (spu->scaled_image) |
a8e7238bb7b4
Add spudec_new_scaled and spudec_draw_scaled for vobsub support.
kmkaplan
parents:
3842
diff
changeset
|
813 free(spu->scaled_image); |
3034
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
814 if (spu->image) |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
815 free(spu->image); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
816 free(spu); |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
817 } |
24d3dca4e813
DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
673
diff
changeset
|
818 } |
6110 | 819 |
820 void spudec_set_hw_spu(void *this, vo_functions_t *hw_spu) | |
821 { | |
822 spudec_handle_t *spu = (spudec_handle_t*)this; | |
823 if (!spu) | |
824 return; | |
825 spu->hw_spu = hw_spu; | |
826 hw_spu->control(VOCTRL_SET_SPU_PALETTE,spu->global_palette); | |
827 } |