Browse Source
webvtt_css_family_fallback_mono.mkv with forced non zero background 32% less instr for RGBA/YUVApull/113/head
5 changed files with 345 additions and 249 deletions
@ -0,0 +1,83 @@ |
|||
/*****************************************************************************
|
|||
* blend.h : |
|||
***************************************************************************** |
|||
* Copyright (C) 2002 - 2020 VLC authors and VideoLAN |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU Lesser General Public License as published by |
|||
* the Free Software Foundation; either version 2.1 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Lesser General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Lesser General Public License |
|||
* along with this program; if not, write to the Free Software Foundation, Inc., |
|||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
*****************************************************************************/ |
|||
#ifndef VLC_FREETYPE_BLEND_H |
|||
#define VLC_FREETYPE_BLEND_H |
|||
|
|||
typedef void (*ft_glyph_blender)( picture_t *, int, int, |
|||
int, int, int, int, FT_BitmapGlyph ); |
|||
typedef void (*ft_surface_filler)( picture_t *, int, int, int, int, |
|||
int, int, int, int); |
|||
typedef void (*ft_components_extractor)( uint32_t, uint8_t *, uint8_t *, uint8_t * ); |
|||
|
|||
typedef struct |
|||
{ |
|||
ft_components_extractor extract; |
|||
ft_surface_filler fill; |
|||
ft_glyph_blender blend; |
|||
} ft_drawing_functions; |
|||
|
|||
#define DECL_PIXEL_BLENDER( name, APOS, XPOS, YPOS, ZPOS, APLANE, XPLANE, YPLANE, ZPLANE ) \ |
|||
static inline void Blend##name##Pixel( uint8_t **dst, int a, int x, int y, int z, int glyph_a )\ |
|||
{\ |
|||
if( glyph_a == 0 )\ |
|||
return;\ |
|||
\ |
|||
int i_an = a * glyph_a / 255;\ |
|||
\ |
|||
int i_ao = dst[APLANE][APOS];\ |
|||
if( i_ao == 0 )\ |
|||
{\ |
|||
dst[XPLANE][XPOS] = x;\ |
|||
dst[YPLANE][YPOS] = y;\ |
|||
dst[ZPLANE][ZPOS] = z;\ |
|||
dst[APLANE][APOS] = i_an;\ |
|||
}\ |
|||
else\ |
|||
{\ |
|||
int i_ani = 255 - i_an;\ |
|||
dst[APLANE][APOS] = 255 - (255 - i_ao) * i_ani / 255;\ |
|||
if( dst[APLANE][APOS] != 0 )\ |
|||
{\ |
|||
int i_aoni = i_ao * i_ani / 255;\ |
|||
dst[XPLANE][XPOS] = ( dst[XPLANE][XPOS] * i_aoni + x * i_an ) / dst[APLANE][APOS];\ |
|||
dst[YPLANE][YPOS] = ( dst[YPLANE][YPOS] * i_aoni + y * i_an ) / dst[APLANE][APOS];\ |
|||
dst[ZPLANE][ZPOS] = ( dst[ZPLANE][ZPOS] * i_aoni + z * i_an ) / dst[APLANE][APOS];\ |
|||
}\ |
|||
}\ |
|||
} |
|||
|
|||
static void BlendAXYZLine( picture_t *p_picture, |
|||
int i_picture_x, int i_picture_y, |
|||
int i_a, int i_x, int i_y, int i_z, |
|||
const line_character_t *p_current, |
|||
const line_character_t *p_next, |
|||
ft_drawing_functions draw ) |
|||
{ |
|||
int i_line_width = p_current->p_glyph->bitmap.width; |
|||
if( p_next ) |
|||
i_line_width = p_next->p_glyph->left - p_current->p_glyph->left; |
|||
|
|||
draw.fill( p_picture, |
|||
i_a, i_x, i_y, i_z, |
|||
i_picture_x, i_picture_y + p_current->i_line_offset, |
|||
i_line_width, p_current->i_line_thickness ); |
|||
} |
|||
|
|||
#endif // VLC_FREETYPE_BLEND_H
|
|||
@ -0,0 +1,109 @@ |
|||
/*****************************************************************************
|
|||
* rgb.h : |
|||
***************************************************************************** |
|||
* Copyright (C) 2002 - 2020 VLC authors and VideoLAN |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU Lesser General Public License as published by |
|||
* the Free Software Foundation; either version 2.1 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Lesser General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Lesser General Public License |
|||
* along with this program; if not, write to the Free Software Foundation, Inc., |
|||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
*****************************************************************************/ |
|||
#include "blend.h" |
|||
|
|||
static void RGBFromRGB( uint32_t i_argb, |
|||
uint8_t *pi_r, uint8_t *pi_g, uint8_t *pi_b ) |
|||
{ |
|||
*pi_r = ( i_argb & 0x00ff0000 ) >> 16; |
|||
*pi_g = ( i_argb & 0x0000ff00 ) >> 8; |
|||
*pi_b = ( i_argb & 0x000000ff ); |
|||
} |
|||
|
|||
#define DECL_RGB_FILLER( name, APOS, XPOS, YPOS, ZPOS ) \ |
|||
static void Fill##name##Picture( picture_t *p_picture,\ |
|||
int a, int r, int g, int b,\ |
|||
int x, int y, int w, int h )\ |
|||
{\ |
|||
uint8_t *row = &p_picture->p[0].p_pixels[y * p_picture->p->i_pitch + x * 4];\ |
|||
\ |
|||
if (unlikely(a == 0 || (a == r && b == g && r == g)))\ |
|||
{ /* fast path */\ |
|||
memset(row, a, h * p_picture->p[0].i_pitch);\ |
|||
return;\ |
|||
}\ |
|||
\ |
|||
for( int dy = 0; dy < h; dy++ )\ |
|||
{\ |
|||
uint8_t *p = row;\ |
|||
for( int dx = 0; dx < w; dx++ )\ |
|||
{\ |
|||
p[XPOS] = r;\ |
|||
p[YPOS] = g;\ |
|||
p[ZPOS] = b;\ |
|||
p[APOS] = a;\ |
|||
p += 4;\ |
|||
}\ |
|||
row += p_picture->p->i_pitch;\ |
|||
}\ |
|||
} |
|||
|
|||
DECL_RGB_FILLER( RGBA, 3, 0, 1, 2 ); |
|||
DECL_PIXEL_BLENDER(RGBA, 3, 0, 1, 2, 0, 0, 0, 0); |
|||
|
|||
DECL_RGB_FILLER( ARGB, 0, 1, 2, 3 ); |
|||
DECL_PIXEL_BLENDER(ARGB, 0, 1, 2, 3, 0, 0, 0, 0); |
|||
|
|||
#undef DECL_RGB_FILLER |
|||
|
|||
static inline void BlendGlyphToRGB( picture_t *p_picture, |
|||
int i_picture_x, int i_picture_y, |
|||
int i_a, int i_x, int i_y, int i_z, |
|||
FT_BitmapGlyph p_glyph, |
|||
void (*BlendPixel)( uint8_t **, int, int, int, int, int ) ) |
|||
{ |
|||
const uint8_t *srcrow = p_glyph->bitmap.buffer; |
|||
int i_pitch_src = p_glyph->bitmap.pitch; |
|||
int i_pitch_dst = p_picture->p[0].i_pitch; |
|||
uint8_t *dstrow = &p_picture->p[0].p_pixels[i_picture_y * i_pitch_dst + 4 * i_picture_x]; |
|||
|
|||
for( unsigned int dy = 0; dy < p_glyph->bitmap.rows; dy++ ) |
|||
{ |
|||
const uint8_t *src = srcrow; |
|||
uint8_t *dst = dstrow; |
|||
for( unsigned int dx = 0; dx < p_glyph->bitmap.width; dx++ ) |
|||
{ |
|||
BlendPixel( &dst, i_a, i_x, i_y, i_z, *src++ ); |
|||
dst += 4; |
|||
} |
|||
srcrow += i_pitch_src; |
|||
dstrow += i_pitch_dst; |
|||
} |
|||
} |
|||
|
|||
static void BlendGlyphToRGBA( picture_t *p_picture, |
|||
int i_picture_x, int i_picture_y, |
|||
int i_a, int i_x, int i_y, int i_z, |
|||
FT_BitmapGlyph p_glyph ) |
|||
{ |
|||
BlendGlyphToRGB( p_picture, i_picture_x, i_picture_y, |
|||
i_a, i_x, i_y, i_z, p_glyph, |
|||
BlendRGBAPixel ); |
|||
} |
|||
|
|||
static void BlendGlyphToARGB( picture_t *p_picture, |
|||
int i_picture_x, int i_picture_y, |
|||
int i_a, int i_x, int i_y, int i_z, |
|||
FT_BitmapGlyph p_glyph ) |
|||
{ |
|||
BlendGlyphToRGB( p_picture, i_picture_x, i_picture_y, |
|||
i_a, i_x, i_y, i_z, p_glyph, |
|||
BlendARGBPixel ); |
|||
} |
|||
@ -0,0 +1,103 @@ |
|||
/*****************************************************************************
|
|||
* yuv.h : |
|||
***************************************************************************** |
|||
* Copyright (C) 2002 - 2020 VLC authors and VideoLAN |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the GNU Lesser General Public License as published by |
|||
* the Free Software Foundation; either version 2.1 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Lesser General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Lesser General Public License |
|||
* along with this program; if not, write to the Free Software Foundation, Inc., |
|||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
*****************************************************************************/ |
|||
#include "blend.h" |
|||
|
|||
static void YUVFromRGB( uint32_t i_argb, |
|||
uint8_t *pi_y, uint8_t *pi_u, uint8_t *pi_v ) |
|||
{ |
|||
int i_red = ( i_argb & 0x00ff0000 ) >> 16; |
|||
int i_green = ( i_argb & 0x0000ff00 ) >> 8; |
|||
int i_blue = ( i_argb & 0x000000ff ); |
|||
|
|||
/* 18.13 fixed point of
|
|||
Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16 |
|||
Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128 |
|||
Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128 */ |
|||
uint8_t y = abs( 2104 * i_red + 4130 * i_green + |
|||
802 * i_blue + 4096 + 131072 ) >> 13; |
|||
uint8_t u = abs( -1214 * i_red + -2384 * i_green + |
|||
3598 * i_blue + 4096 + 1048576) >> 13; |
|||
uint8_t v = abs( 3598 * i_red + -3013 * i_green + |
|||
-585 * i_blue + 4096 + 1048576) >> 13; |
|||
*pi_y = __MIN(y, 235); |
|||
*pi_u = __MIN(u, 240); |
|||
*pi_v = __MIN(v, 240); |
|||
} |
|||
|
|||
static void FillYUVAPicture( picture_t *p_picture, |
|||
int i_a, int i_y, int i_u, int i_v, |
|||
int x, int y, int w, int h ) |
|||
{ |
|||
int values[4] = { i_y, i_u, i_v, i_a }; |
|||
for( int i = 0; i < 4; i++ ) |
|||
{ |
|||
plane_t *plane = &p_picture->p[i]; |
|||
uint8_t *row = &plane->p_pixels[y * p_picture->p->i_pitch + |
|||
x * plane->i_pixel_pitch]; |
|||
for( int dy = 0; dy < h; dy++ ) |
|||
{ |
|||
memset( row, values[i], plane->i_pixel_pitch * w ); |
|||
row += p_picture->p->i_pitch; |
|||
} |
|||
} |
|||
} |
|||
|
|||
DECL_PIXEL_BLENDER(YUVA, 0, 0, 0, 0, A_PLANE, Y_PLANE, U_PLANE, V_PLANE); |
|||
|
|||
static void BlendGlyphToYUVA( picture_t *p_picture, |
|||
int i_picture_x, int i_picture_y, |
|||
int i_a, int i_x, int i_y, int i_z, |
|||
FT_BitmapGlyph p_glyph ) |
|||
{ |
|||
const uint8_t *srcrow = p_glyph->bitmap.buffer; |
|||
int i_pitch_src = p_glyph->bitmap.pitch; |
|||
|
|||
uint8_t *dstrows[4]; |
|||
dstrows[0] = &p_picture->p[0].p_pixels[i_picture_y * p_picture->p[0].i_pitch + |
|||
i_picture_x * p_picture->p[0].i_pixel_pitch]; |
|||
dstrows[1] = &p_picture->p[1].p_pixels[i_picture_y * p_picture->p[1].i_pitch + |
|||
i_picture_x * p_picture->p[1].i_pixel_pitch]; |
|||
dstrows[2] = &p_picture->p[2].p_pixels[i_picture_y * p_picture->p[2].i_pitch + |
|||
i_picture_x * p_picture->p[2].i_pixel_pitch]; |
|||
dstrows[3] = &p_picture->p[3].p_pixels[i_picture_y * p_picture->p[3].i_pitch + |
|||
i_picture_x * p_picture->p[3].i_pixel_pitch]; |
|||
|
|||
for( unsigned int dy = 0; dy < p_glyph->bitmap.rows; dy++ ) |
|||
{ |
|||
const uint8_t *src = srcrow; |
|||
|
|||
uint8_t *dst[4]; |
|||
memcpy(dst, dstrows, 4 * sizeof(dst[0])); |
|||
for( unsigned int dx = 0; dx < p_glyph->bitmap.width; dx++ ) |
|||
{ |
|||
BlendYUVAPixel( dst, i_a, i_x, i_y, i_z, *src++ ); |
|||
dst[0] += p_picture->p[0].i_pixel_pitch; |
|||
dst[1] += p_picture->p[1].i_pixel_pitch; |
|||
dst[2] += p_picture->p[2].i_pixel_pitch; |
|||
dst[3] += p_picture->p[3].i_pixel_pitch; |
|||
} |
|||
|
|||
srcrow += i_pitch_src; |
|||
dstrows[0] += p_picture->p[0].i_pitch; |
|||
dstrows[1] += p_picture->p[1].i_pitch; |
|||
dstrows[2] += p_picture->p[2].i_pitch; |
|||
dstrows[3] += p_picture->p[3].i_pitch; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue