Exemplo n.º 1
0
inline void BlendFill(
    NormalPixel                   color,
    GenericPixelPtr<DstPixelType> d_line,
    const unsigned char          *a_line,
    int                           a_pitch,
    int     w,
    int     h,
    bool    inverted,
    int     alpha_0,
    int     alpha_1 )
{
    size_t line_size = w * sizeof(DstPixelType);
    MemBlock d_cache( line_size );

    while ( h-- )
    {
        MemCopy( d_cache.GetPtr(), (DstPixelType*)d_line, line_size );

        DstPixelType *d_ptr = (DstPixelType*)d_cache.GetPtr();
        const unsigned char *a_ptr = a_line;

        if ( alpha_0>0 || alpha_1<256 ) 
        {
            if (!inverted)
                for ( int i=w; i--; ++a_ptr, ++d_ptr )
                {
                    BlendPixel( *d_ptr, color, *a_ptr *(alpha_1-alpha_0)/256+alpha_0 );
                }
            else
                for ( int i=w; i--; ++a_ptr, ++d_ptr )
                {
                    BlendPixel( *d_ptr, color, (255-*a_ptr) *(alpha_1-alpha_0)/256+alpha_0 );
                }
        }
        else if (!inverted)
            for ( int i=w; i--; ++a_ptr, ++d_ptr )
            {
                BlendPixel( *d_ptr, color, *a_ptr );
            }
        else
            for ( int i=w; i--; ++a_ptr, ++d_ptr )
            {
                BlendPixel( *d_ptr, color, 255-*a_ptr );
            }
        MemCopy( (DstPixelType*)d_line, d_cache.GetPtr(), line_size );

        d_line.Next();
        a_line += a_pitch;
    }
}
Exemplo n.º 2
0
int VideoBuffer::BlendCharacter(int x, int y, int c, int r, int g, int b, int a)
{
	int i, j, w, bn = 0, ba = 0;
	char *rp = font_data + font_ptrs[c];
	w = *(rp++);
	for (j=0; j<FONT_H; j++)
		for (i=0; i<w; i++)
		{
			if (!bn)
			{
				ba = *(rp++);
				bn = 8;
			}
			BlendPixel(x+i, y+j, r, g, b, ((ba&3)*a)/3);
			ba >>= 2;
			bn -= 2;
		}
	return x + w;
}
Exemplo n.º 3
0
inline void RotoBlendFill (
    NormalPixel color,
    GenericPixelPtr<DstPixelType> d_line,
    const unsigned char          *a_line,
    int                           a_pitch,
    int    w,
    int    h,
    bool   inverted,
    int    alpha_0,
    int    alpha_1,
    double angle,
    int    dest_w,
    int    dest_h,
    int    center_x,
    int    center_y )
{   
    size_t line_size = dest_w * sizeof(DstPixelType);
    MemBlock d_cache( line_size );
    int sn = 1024*sin(angle);
    int cs = 1024*cos(angle);
    int x_ = -cs*(center_x) + sn*(center_y);
    int y_ = -cs*(center_y) - sn*(center_x);
    int a_sgn_pitch = (sn>0)? a_pitch:-a_pitch;
    
    int quoter = (sn>=0 && cs>=0)? 1: (sn>=0 && cs<0)? 2: (sn<0 && cs<0)? 3:4;

    for ( int v=dest_h; v--; )
    {
        MemCopy( d_cache.GetPtr(), (DstPixelType*)d_line, line_size );

        DstPixelType *d_ptr = (DstPixelType*)d_cache.GetPtr();

        int x=x_;
        int y=y_;

        int a1 = -w*512 - x_;
        int a2 =  w*512 - x_;
        int b1 = -h*512 - y_;
        int b2 =  h*512 - y_;
        int a=0,b=0;

        if ( sn && cs )
            switch(quoter)
            {
            case 1:
                a = ( a1/cs > b1/sn )? a1/cs : b1/sn;
                b = ( a2/cs < b2/sn )? a2/cs : b2/sn; break;
            case 2:
                a = ( a2/cs > b1/sn )? a2/cs : b1/sn;
                b = ( a1/cs < b2/sn )? a1/cs : b2/sn; break;
            case 3:
                a = ( a2/cs > b2/sn )? a2/cs : b2/sn;
                b = ( a1/cs < b1/sn )? a1/cs : b1/sn; break;
            case 4:
                a = ( a1/cs > b2/sn )? a1/cs : b2/sn;
                b = ( a2/cs < b1/sn )? a2/cs : b1/sn; break;
            }
        else
            if ( cs ) // 0 or 180 degrees
            {
                if ( y_>=-512*h && y_<512*h )
                {
                    a = center_x - w/2;
                    b = center_x + w/2;
                }
            }
            else // 90 or 270 degrees
            {
                if ( x_>=-512*w && x_<512*w )
                {
                    a = center_x - h/2;
                    b = center_x + h/2;
                }
            }

        int k = 0;
        b = (b<dest_w)? b : dest_w;

        for (; k<=a; ++k, ++d_ptr, x+=cs, y+=sn )
        {}

        int i = x/1024 + (w/2); x%=1024;
        int j = a_pitch * (y/1024 +(h/2)); y%=1024;

#define __ALPHA_ROTATION_LOOP( Command ) \
    { for (; k<b ; ++k, ++d_ptr ) \
    { \
        Command; \
        x += cs; i += x/1024; x %= 1024; \
        y += sn; j += (y/1024)? a_sgn_pitch : 0; y %= 1024; \
    }}

        if ( alpha_0>0 || alpha_1<256 )
        {
          if (!inverted)
            __ALPHA_ROTATION_LOOP( BlendPixel( *d_ptr, color, a_line[j+i] *(alpha_1-alpha_0)/256+alpha_0 ) )
          else
            __ALPHA_ROTATION_LOOP( BlendPixel( *d_ptr, color, (255-a_line[j+i]) *(alpha_1-alpha_0)/256+alpha_0 ) )
        }
        else
        {
          if (!inverted)
            __ALPHA_ROTATION_LOOP( BlendPixel( *d_ptr, color, a_line[j+i] ) )
          else
            __ALPHA_ROTATION_LOOP( BlendPixel( *d_ptr, color, 255-a_line[j+i] ) )
        }

#undef __ALPHA_ROTATION_LOOP

        MemCopy( (DstPixelType*)d_line, d_cache.GetPtr(), line_size );

        d_line.Next();
        x_ += -sn;
        y_ += cs;
    }