| 234 | | } |
|---|
| 235 | | } |
|---|
| 236 | | |
|---|
| 237 | | msg_Dbg( p_filter, "no matching alpha blending routine" ); |
|---|
| | 244 | case VLC_FOURCC('R','V','1','6'): |
|---|
| | 245 | BlendRGBAR16( p_filter, p_dst, p_dst_orig, p_src, |
|---|
| | 246 | i_x_offset, i_y_offset, |
|---|
| | 247 | i_width, i_height, i_alpha ); |
|---|
| | 248 | return; |
|---|
| | 249 | } |
|---|
| | 250 | } |
|---|
| | 251 | |
|---|
| | 252 | msg_Dbg( p_filter, "no matching alpha blending routine " |
|---|
| | 253 | "(chroma: %4.4s -> %4.4s)", |
|---|
| | 254 | (char *)&p_filter->fmt_in.video.i_chroma, |
|---|
| | 255 | (char *)&p_filter->fmt_out.video.i_chroma ); |
|---|
| | 1249 | |
|---|
| | 1250 | static void BlendRGBAR24( filter_t *p_filter, picture_t *p_dst_pic, |
|---|
| | 1251 | picture_t *p_dst_orig, picture_t *p_src, |
|---|
| | 1252 | int i_x_offset, int i_y_offset, |
|---|
| | 1253 | int i_width, int i_height, int i_alpha ) |
|---|
| | 1254 | { |
|---|
| | 1255 | int i_src1_pitch, i_src2_pitch, i_dst_pitch; |
|---|
| | 1256 | uint8_t *p_dst, *p_src1, *p_src2; |
|---|
| | 1257 | int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch; |
|---|
| | 1258 | uint16_t i_pix; |
|---|
| | 1259 | |
|---|
| | 1260 | i_pix_pitch = p_dst_pic->p->i_pixel_pitch; |
|---|
| | 1261 | i_dst_pitch = p_dst_pic->p->i_pitch; |
|---|
| | 1262 | p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch + |
|---|
| | 1263 | p_filter->fmt_out.video.i_x_offset * i_pix_pitch + |
|---|
| | 1264 | p_dst_pic->p->i_pitch * |
|---|
| | 1265 | ( i_y_offset + p_filter->fmt_out.video.i_y_offset ); |
|---|
| | 1266 | |
|---|
| | 1267 | i_src1_pitch = p_dst_orig->p->i_pitch; |
|---|
| | 1268 | p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch + |
|---|
| | 1269 | p_filter->fmt_out.video.i_x_offset * i_pix_pitch + |
|---|
| | 1270 | p_dst_orig->p->i_pitch * |
|---|
| | 1271 | ( i_y_offset + p_filter->fmt_out.video.i_y_offset ); |
|---|
| | 1272 | |
|---|
| | 1273 | i_src_pix_pitch = p_src->p->i_pixel_pitch; |
|---|
| | 1274 | i_src2_pitch = p_src->p->i_pitch; |
|---|
| | 1275 | p_src2 = p_src->p->p_pixels + |
|---|
| | 1276 | p_filter->fmt_in.video.i_x_offset * i_pix_pitch + |
|---|
| | 1277 | p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset; |
|---|
| | 1278 | |
|---|
| | 1279 | #define MAX_TRANS 255 |
|---|
| | 1280 | #define TRANS_BITS 8 |
|---|
| | 1281 | |
|---|
| | 1282 | /* Draw until we reach the bottom of the subtitle */ |
|---|
| | 1283 | for( i_y = 0; i_y < i_height; i_y++, |
|---|
| | 1284 | p_dst += i_dst_pitch, p_src1 += i_src1_pitch, p_src2 += i_src2_pitch ) |
|---|
| | 1285 | { |
|---|
| | 1286 | /* Draw until we reach the end of the line */ |
|---|
| | 1287 | for( i_x = 0; i_x < i_width; i_x++ ) |
|---|
| | 1288 | { |
|---|
| | 1289 | #define R ( p_src2[i_x * i_src_pix_pitch + 0] ) |
|---|
| | 1290 | #define G ( p_src2[i_x * i_src_pix_pitch + 1] ) |
|---|
| | 1291 | #define B ( p_src2[i_x * i_src_pix_pitch + 2] ) |
|---|
| | 1292 | i_trans = ( p_src2[i_x * i_src_pix_pitch + 3] * i_alpha ) / 255; |
|---|
| | 1293 | if( !i_trans ) |
|---|
| | 1294 | { |
|---|
| | 1295 | /* Completely transparent. Don't change pixel */ |
|---|
| | 1296 | continue; |
|---|
| | 1297 | } |
|---|
| | 1298 | else if( i_trans == MAX_TRANS ) |
|---|
| | 1299 | { |
|---|
| | 1300 | /* Completely opaque. Completely overwrite underlying pixel */ |
|---|
| | 1301 | *((uint16_t *)(&p_dst[i_x * i_pix_pitch])) = ((R >> 3) << 11) | ((G >> 2) << 5) | (B >> 3); |
|---|
| | 1302 | continue; |
|---|
| | 1303 | } |
|---|
| | 1304 | |
|---|
| | 1305 | /* Blending */ |
|---|
| | 1306 | i_pix = *((uint16_t *)(&p_dst[i_x * i_pix_pitch])); |
|---|
| | 1307 | *((uint16_t *)(&p_dst[i_x * i_pix_pitch])) = |
|---|
| | 1308 | ( ( ( (R >> 3)*i_trans |
|---|
| | 1309 | + (i_pix >> 11) * (MAX_TRANS - i_trans) ) |
|---|
| | 1310 | >> TRANS_BITS ) << 11 ) |
|---|
| | 1311 | | ( ( ( (G >> 2)*i_trans |
|---|
| | 1312 | + ((i_pix & 0x07e0)>> 5) * (MAX_TRANS - i_trans) ) |
|---|
| | 1313 | >> TRANS_BITS ) << 5 ) |
|---|
| | 1314 | | ( ( ( (B >> 3)*i_trans |
|---|
| | 1315 | + (i_pix & 0x001f) * (MAX_TRANS - i_trans) ) |
|---|
| | 1316 | >> TRANS_BITS ) ); |
|---|
| | 1317 | #undef R |
|---|
| | 1318 | #undef G |
|---|
| | 1319 | #undef B |
|---|
| | 1320 | } |
|---|
| | 1321 | } |
|---|
| | 1322 | |
|---|
| | 1323 | #undef MAX_TRANS |
|---|
| | 1324 | #undef TRANS_BITS |
|---|
| | 1325 | |
|---|
| | 1326 | return; |
|---|
| | 1327 | } |
|---|