Exemplo n.º 1
0
void CGraphView::Blit(const Canvas& src,int x,int y,bool trans)
{
    if (trans)
    {
        AlphaBlit(src,x,y);
        return;
    }
    
    const int bpp=4;
    
    int nDestwidth=pDib->Width();
    int nDestheight=pDib->Height();
    
    int xstart=0;
    int ystart=0;
    int xlen=src.Width();
    int ylen=src.Height();
    int ox=x;
    int oy=y;
    
    DoClipping(x,y,xstart,xlen,ystart,ylen);

    if (xlen<1 || ylen<1)   return; // offscreen
    
    u32* pDest=(u32*)(pDib->GetPixels())+(y*nDestwidth+x);
    u32* pSrc =(u32*)src.GetPixels() +(ystart*src.Width()+xstart);
    
    while (ylen)
    {
        int x=xlen;
        while (x)
        {
            // convert from ARGB to ABGR
            /*
            u32 c=*pSrc++;
            u8 r=(u8)((c>>16)&255);
            u8 b=(u8)(c&255);
            c&=0xFF00FF00;                              // the alpha and green channels don't move, keep them intact                        
            *pDest++=c|(b<<16)|r;
            /*/
            // Did I need to convert this to ASM?  Doubt it. ;D
            __asm
            {
                mov     ebx,[pSrc]
                mov     eax,[ebx]
                
                mov     ebx,[pDest]
                mov     [ebx],eax
                
                mov     al,[ebx]
                mov     ah,[ebx+2]
                mov     [ebx],ah                        // have to switch from BGRA to RGBA
                mov     [ebx+2],al
            }
            ++pSrc; ++pDest;
            //*/
            x--;
        }
        pDest+=nDestwidth-xlen;
        pSrc+=src.Width()-xlen;
        --ylen;
    }
}   
Exemplo n.º 2
0
void CGraphView::AlphaBlit(const Canvas& src,int x,int y)
{
    const int bpp=4;
    
    int nDestwidth=pDib->Width();
    int nDestheight=pDib->Height();
    
    int xstart=0;
    int ystart=0;
    int xlen=src.Width();
    int ylen=src.Height();
    int ox=x;
    int oy=y;
    
    DoClipping(x,y,xstart,xlen,ystart,ylen);
    
    if (xlen<1 || ylen<1)   return; // offscreen
    
    u32* pDest=(u32*)(pDib->GetPixels())+(y*nDestwidth+x);
    u32* pSrc =(u32*)src.GetPixels() +(ystart*src.Width()+xstart);
    
    while (ylen)
    {
        int x=xlen;
        while (x)
        {
            // convert from ARGB to ABGR
            /*
            u32 c=*pSrc++;
            u8 r=(u8)((c>>16)&255);
            u8 b=(u8)(c&255);
            c&=0xFF00FF00;                              // the alpha and green channels don't move, keep them intact                        
            *pDest++=c|(b<<16)|r;
            /*/
            // Did I need to convert this to ASM?  Doubt it. ;D
            __asm
            {
                mov     ebx,[pSrc]
                mov     eax,[ebx]
                
                test    eax,0xFF000000
                jz      nodraw
                
                mov     ebx,[pDest]
                mov     [ebx],eax
                
                mov     al,[ebx]
                mov     ah,[ebx+2]
                mov     [ebx],ah                        // have to switch from BGRA to RGBA
                mov     [ebx+2],al
                
    nodraw:
            }
            ++pSrc; ++pDest;
            //*/
            x--;
        }
        pDest+=nDestwidth-xlen;
        pSrc+=src.Width()-xlen;
        --ylen;
    }
}

void CGraphView::HLine(int x1,int x2,int y,u32 colour)
{
    if (x1>x2)
    std::swap<int>(x1,x2);
    
    if (y<0 || y>=nDIBsize) return;
    if (x1<0)               x1=0;
    if (x2<0)               return;
    if (x1>=nDIBsize)       return;
    if (x2>=nDIBsize)       x2=nDIBsize-1;
    
    u32* p=(u32*)pDib->GetPixels()+(y*pDib->Width())+x1;
    int xlen=x2-x1+1;
    
    while (xlen--)
        *p++=colour;
}

void CGraphView::VLine(int x,int y1,int y2,u32 colour)
{
    if (y1>y2)
    std::swap<int>(y1,y2);
    
    if (x<0 || x>=nDIBsize) return;
    if (y1<0)               y1=0;
    if (y2<0)               return;
    if (y1>=nDIBsize)       return;
    if (y2>=nDIBsize)       y2=nDIBsize-1;

    u32* p=(u32*)pDib->GetPixels()+(y1*pDib->Width())+x;
    int ylen=y2-y1+1;
    while (ylen--)
    {
        *p=colour;
        p+=pDib->Width();
    }
}

void CGraphView::DrawRect(int x1,int y1,int x2,int y2,u32 colour)
{
    HLine(x1,x2,y1,colour);
    HLine(x1,x2,y2,colour);
    VLine(x1,y1,y2,colour);
    VLine(x2,y1,y2,colour);
}