一个简单的能处理MIP-MAP的类

本文展示了一个能处理MIP - MAP的简单类eiTexture。该类包含构造、析构函数,有加载纹理、归一化、生成MIP - MAP等方法,还实现了获取颜色、双线性插值等功能,通过一系列代码逻辑完成对纹理数据的处理。
None.gif // -------------------------------------------------------------------------
None.gif
eiTexture::eiTexture(eiBool instance_type, eiBool mip_map_filter)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    format        
= NONE;
InBlock.gif    type        
= SRC;
InBlock.gif    m_width        
= 0;
InBlock.gif    m_height    
= 0;
InBlock.gif    instance    
= instance_type;
InBlock.gif    use_mip_map    
= mip_map_filter;
InBlock.gif    bits        
= NULL;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiTexture:: ~ eiTexture()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiBool eiTexture::load(eiChar  * file_name)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    CFile file;
InBlock.gif
InBlock.gif    
if!file.Open( file_name, CFile::modeRead | CFile::shareDenyWrite ) )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        msger.print(
"Load texture failed.");    
InBlock.gif        
return false;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    BITMAPFILEHEADER bfhHeader;
InBlock.gif
InBlock.gif    file.Read( 
&bfhHeader, sizeof(BITMAPFILEHEADER) );
InBlock.gif
InBlock.gif    
if( bfhHeader.bfType != 0x4d42 )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        msger.print(
"Load texture failed.");
InBlock.gif        
return false;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    eiUInt uBmpInfoLen 
= (eiUInt) bfhHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
InBlock.gif
InBlock.gif    LPBITMAPINFOHEADER m_lpBMPHdr 
= (LPBITMAPINFOHEADER) new eiByte [ uBmpInfoLen ];
InBlock.gif
InBlock.gif    eiUInt counts 
= file.Read(m_lpBMPHdr, uBmpInfoLen);
InBlock.gif
InBlock.gif    
if(m_lpBMPHdr->biSize != sizeof(BITMAPINFOHEADER))
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        msger.print(
"Texture format error.");
InBlock.gif        
return false;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    DWORD m_dwImageSize 
= m_lpBMPHdr->biSizeImage;
InBlock.gif
InBlock.gif    
if(m_dwImageSize == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        DWORD dwBytes 
= ((DWORD) m_lpBMPHdr->biWidth * m_lpBMPHdr->biBitCount) / 32;
InBlock.gif        
InBlock.gif        
if(((DWORD) m_lpBMPHdr->biWidth * m_lpBMPHdr->biBitCount) % 32)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            dwBytes
++;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        dwBytes 
*= 4;
InBlock.gif
InBlock.gif        m_dwImageSize 
= dwBytes * m_lpBMPHdr->biHeight; 
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    bits 
= (eiByte*new eiByte [ m_dwImageSize ];
InBlock.gif
InBlock.gif    counts 
= file.Read(bits, m_dwImageSize);
InBlock.gif
InBlock.gif    file.Close();
InBlock.gif
InBlock.gif    m_width  
= m_lpBMPHdr->biWidth;
InBlock.gif    m_height 
= m_lpBMPHdr->biHeight;
InBlock.gif
InBlock.gif    delete []m_lpBMPHdr;
InBlock.gif
InBlock.gif    format 
= BMP;
InBlock.gif
InBlock.gif    normalize();
InBlock.gif
InBlock.gif    inv_width    
= 1.0 / m_width;
InBlock.gif    inv_height    
= 1.0 / m_height;
InBlock.gif
InBlock.gif    
if(use_mip_map)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        make_mip_map();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
return true;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiVoid eiTexture::normalize()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    eiByte    
*pbits;
InBlock.gif    eiInt    n_width,n_height;
InBlock.gif    eiFloat dx,dy;
InBlock.gif    eiColor color;
InBlock.gif
InBlock.gif    pbits 
= bits;
InBlock.gif    n_width 
= (eiInt) powf( 2, (eiInt) log2f( m_width ) + 1 );
InBlock.gif    n_height 
= (eiInt) powf( 2, (eiInt) log2f( m_height ) + 1 );
InBlock.gif
InBlock.gif    dx 
= (eiFloat) m_width / (eiFloat) n_width;
InBlock.gif    dy 
= (eiFloat) m_height / (eiFloat) n_height;
InBlock.gif
InBlock.gif    src.resize( n_width 
* n_height * 3 );
InBlock.gif
InBlock.gif    std::vector
<eiByte>::iterator pbyPtr = src.begin();
InBlock.gif
InBlock.gif    
for(eiInt j = 0 ; j < n_height ; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
for(eiInt i = 0 ; i < n_width ; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            color 
= get_bilinear_color( pbits, i * dx, j * dy );
InBlock.gif
InBlock.gif            pbyPtr[
0= (eiByte) ( color.b * 255 );
InBlock.gif            pbyPtr[
1= (eiByte) ( color.g * 255 );
InBlock.gif            pbyPtr[
2= (eiByte) ( color.r * 255 );
InBlock.gif
InBlock.gif            pbyPtr 
+= 3;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    delete []pbits;
InBlock.gif    bits 
= NULL;
InBlock.gif
InBlock.gif    m_width 
= n_width;
InBlock.gif    m_height 
= n_height;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiInt eiTexture::get_width()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
return m_width;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiInt eiTexture::get_height()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
return m_height;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiColorB eiTexture::get_color(eiByte  * dibbits, eiInt x, eiInt y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    eiColorB color;
InBlock.gif
InBlock.gif    color.r 
= color.g = color.b = 0;
InBlock.gif
InBlock.gif    
if(dibbits == NULL)
InBlock.gif        
return color;
InBlock.gif
InBlock.gif    
if(x < 0)
InBlock.gif        x 
= 0;
InBlock.gif    
if(x >= m_width)
InBlock.gif        x 
= m_width - 1;
InBlock.gif    
if(y < 0)
InBlock.gif        y 
= 0;
InBlock.gif    
if(y >= m_height)
InBlock.gif        y 
= m_height - 1;
InBlock.gif
InBlock.gif    eiByte 
*pbyPtr;
InBlock.gif
InBlock.gif    pbyPtr 
= dibbits + (y * m_width + x) * 3;
InBlock.gif
InBlock.gif    color.b 
= pbyPtr[0];
InBlock.gif    color.g 
= pbyPtr[1];
InBlock.gif    color.r 
= pbyPtr[2];
InBlock.gif
InBlock.gif    
return color;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiColor eiTexture::get_bilinear_color(eiByte  * dibbits, eiFloat x, eiFloat y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    eiInt        u,v;
InBlock.gif
InBlock.gif    u 
= (eiInt) x;
InBlock.gif    v 
= (eiInt) y;
InBlock.gif
InBlock.gif    
if( (eiFloat) u == x && (eiFloat) v == y )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        eiColorB clr 
= get_color(dibbits,u,v);
InBlock.gif        
InBlock.gif        
return newclr(    clr.r * EI_BYTE_2_FLOAT,
InBlock.gif                        clr.g 
* EI_BYTE_2_FLOAT,
InBlock.gif                        clr.b 
* EI_BYTE_2_FLOAT    );
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    eiFloat        du,dv,r1,g1,b1,r2,g2,b2;
InBlock.gif    eiColorB    c1,c2,c3,c4;
InBlock.gif
InBlock.gif    du 
= curve( x - u );
InBlock.gif    dv 
= curve( y - v );
InBlock.gif
InBlock.gif    c1 
= get_color(dibbits,u,v);
InBlock.gif    c2 
= get_color(dibbits,u+1,v);
InBlock.gif    c3 
= get_color(dibbits,u+1,v+1);
InBlock.gif    c4 
= get_color(dibbits,u,v+1);
InBlock.gif
InBlock.gif    r1 
= c1.r + (c2.r - c1.r) * du;
InBlock.gif    g1 
= c1.g + (c2.g - c1.g) * du;
InBlock.gif    b1 
= c1.b + (c2.b - c1.b) * du;
InBlock.gif
InBlock.gif    r2 
= c4.r + (c3.r - c4.r) * du;
InBlock.gif    g2 
= c4.g + (c3.g - c4.g) * du;
InBlock.gif    b2 
= c4.b + (c3.b - c4.b) * du;
InBlock.gif
InBlock.gif    r1 
= r1 + (r2 - r1) * dv;
InBlock.gif    g1 
= g1 + (g2 - g1) * dv;
InBlock.gif    b1 
= b1 + (b2 - b1) * dv;
InBlock.gif
InBlock.gif    r1 
*= EI_BYTE_2_FLOAT;
InBlock.gif    g1 
*= EI_BYTE_2_FLOAT;
InBlock.gif    b1 
*= EI_BYTE_2_FLOAT;
InBlock.gif
InBlock.gif    
return newclr(r1,g1,b1);
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiColorB eiTexture::get_src_color(eiInt x, eiInt y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    eiColorB color;
InBlock.gif
InBlock.gif    color.r 
= color.g = color.b = 0;
InBlock.gif
InBlock.gif    
if(src.empty())
InBlock.gif        
return color;
InBlock.gif
InBlock.gif    
if(x < 0)
InBlock.gif        x 
= 0;
InBlock.gif    
if(x >= m_width)
InBlock.gif        x 
= m_width - 1;
InBlock.gif    
if(y < 0)
InBlock.gif        y 
= 0;
InBlock.gif    
if(y >= m_height)
InBlock.gif        y 
= m_height - 1;
InBlock.gif
InBlock.gif    std::vector
<eiByte>::iterator pbyPtr;
InBlock.gif
InBlock.gif    pbyPtr 
= src.begin() + (y * m_width + x) * 3;
InBlock.gif
InBlock.gif    color.b 
= pbyPtr[0];
InBlock.gif    color.g 
= pbyPtr[1];
InBlock.gif    color.r 
= pbyPtr[2];
InBlock.gif
InBlock.gif    
return color;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiColor eiTexture::get_src_bilinear_color(eiFloat x, eiFloat y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    eiInt        u,v;
InBlock.gif
InBlock.gif    u 
= (eiInt) x;
InBlock.gif    v 
= (eiInt) y;
InBlock.gif
InBlock.gif    
if( (eiFloat) u == x && (eiFloat) v == y )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        eiColorB clr 
= get_src_color(u,v);
InBlock.gif        
InBlock.gif        
return newclr(    clr.r * EI_BYTE_2_FLOAT,
InBlock.gif                        clr.g 
* EI_BYTE_2_FLOAT,
InBlock.gif                        clr.b 
* EI_BYTE_2_FLOAT    );
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    eiFloat        du,dv,r1,g1,b1,r2,g2,b2;
InBlock.gif    eiColorB    c1,c2,c3,c4;
InBlock.gif
InBlock.gif    du 
= curve( x - u );
InBlock.gif    dv 
= curve( y - v );
InBlock.gif
InBlock.gif    c1 
= get_src_color(u,v);
InBlock.gif    c2 
= get_src_color(u+1,v);
InBlock.gif    c3 
= get_src_color(u+1,v+1);
InBlock.gif    c4 
= get_src_color(u,v+1);
InBlock.gif
InBlock.gif    r1 
= c1.r + (c2.r - c1.r) * du;
InBlock.gif    g1 
= c1.g + (c2.g - c1.g) * du;
InBlock.gif    b1 
= c1.b + (c2.b - c1.b) * du;
InBlock.gif
InBlock.gif    r2 
= c4.r + (c3.r - c4.r) * du;
InBlock.gif    g2 
= c4.g + (c3.g - c4.g) * du;
InBlock.gif    b2 
= c4.b + (c3.b - c4.b) * du;
InBlock.gif
InBlock.gif    r1 
= r1 + (r2 - r1) * dv;
InBlock.gif    g1 
= g1 + (g2 - g1) * dv;
InBlock.gif    b1 
= b1 + (b2 - b1) * dv;
InBlock.gif
InBlock.gif    r1 
*= EI_BYTE_2_FLOAT;
InBlock.gif    g1 
*= EI_BYTE_2_FLOAT;
InBlock.gif    b1 
*= EI_BYTE_2_FLOAT;
InBlock.gif
InBlock.gif    
return newclr(r1,g1,b1);
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiVoid eiTexture::blt(eiInt x1,eiInt y1,eiInt x2,eiInt y2,
None.gif                        eiInt width,eiInt height)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    eiInt    c1,c2,c3,c4;
InBlock.gif    std::vector
<eiByte>::iterator    pbyPtr;
InBlock.gif
InBlock.gif    
for( eiInt j = y1, mj = y2 ; j < (y1 + height) ; j += 2, mj++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
for( eiInt i = x1, mi = x2 ; i < (x1 + width) ; i += 2, mi++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            pbyPtr 
= mip_map.begin() + j * m_width + i;
InBlock.gif            c1 
= pbyPtr[0];
InBlock.gif            c2 
= pbyPtr[1];
InBlock.gif
InBlock.gif            pbyPtr 
+= m_width;
InBlock.gif            c3 
= pbyPtr[0];
InBlock.gif            c4 
= pbyPtr[1];
InBlock.gif
InBlock.gif            pbyPtr 
= mip_map.begin() + mj * m_width + mi;
InBlock.gif            pbyPtr[
0= (eiByte) ( (eiFloat) ( c1 + c2 + c3 + c4 ) * 0.25 );
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiVoid eiTexture::bltB(eiInt x1,eiInt y1,eiInt x2,eiInt y2,
None.gif                        eiInt width,eiInt height)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if(width == 0 || height == 0)
InBlock.gif        
return;
InBlock.gif
InBlock.gif    eiInt width2,height2;
InBlock.gif
InBlock.gif    width2 
= width / 2;
InBlock.gif    height2 
= height / 2;
InBlock.gif
InBlock.gif    blt( x1, y1, x2, y2, width, height);
InBlock.gif
InBlock.gif    bltB( x2, y2, x2 
/ 2, y2 / 2, width2, height2 );
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiVoid eiTexture::bltG(eiInt x1,eiInt y1,eiInt x2,eiInt y2,
None.gif                        eiInt width,eiInt height)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if(width == 0 || height == 0)
InBlock.gif        
return;
InBlock.gif
InBlock.gif    eiInt width2,height2;
InBlock.gif
InBlock.gif    width2 
= width / 2;
InBlock.gif    height2 
= height / 2;
InBlock.gif
InBlock.gif    blt( x1, y1, x2, y2, width, height);
InBlock.gif
InBlock.gif    bltG( x2, y2, x2 
/ 2, y2, width2, height2 );
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiVoid eiTexture::bltR(eiInt x1,eiInt y1,eiInt x2,eiInt y2,
None.gif                        eiInt width,eiInt height)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if(width == 0 || height == 0)
InBlock.gif        
return;
InBlock.gif
InBlock.gif    eiInt width2,height2;
InBlock.gif
InBlock.gif    width2 
= width / 2;
InBlock.gif    height2 
= height / 2;
InBlock.gif
InBlock.gif    blt( x1, y1, x2, y2, width, height);
InBlock.gif
InBlock.gif    bltR( x2, y2, x2, y2 
/ 2, width2, height2 );
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiBool eiTexture::make_mip_map()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if(format == NONE || type == MIP_MAP)
InBlock.gif        
return false;
InBlock.gif
InBlock.gif    mip_map.resize( m_width 
* m_height );
InBlock.gif
InBlock.gif    eiColorB                        c1,c2,c3,c4;
InBlock.gif    eiFloat                            r,g,b;
InBlock.gif    std::vector
<eiByte>::iterator    pbyPtr;
InBlock.gif    eiInt                            width2,height2;
InBlock.gif
InBlock.gif    width2 
= m_width / 2;
InBlock.gif    height2 
= m_height / 2;
InBlock.gif
InBlock.gif    
for( eiInt j = 0, mj = 0 ; j < m_height ; j += 2, mj++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
for( eiInt i = 0, mi = 0 ; i < m_width ; i += 2, mi++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            c1 
= get_src_color( i , j );
InBlock.gif            c2 
= get_src_color( i + 1 , j );
InBlock.gif            c3 
= get_src_color( i + 1 , j + 1 );
InBlock.gif            c4 
= get_src_color( i , j + 1 );
InBlock.gif
InBlock.gif            b 
= (eiFloat) ( (eiInt) c1.b + (eiInt) c2.b + (eiInt) c3.b + (eiInt) c4.b ) * 0.25;
InBlock.gif            g 
= (eiFloat) ( (eiInt) c1.g + (eiInt) c2.g + (eiInt) c3.g + (eiInt) c4.g ) * 0.25;
InBlock.gif            r 
= (eiFloat) ( (eiInt) c1.r + (eiInt) c2.r + (eiInt) c3.r + (eiInt) c4.r ) * 0.25;
InBlock.gif
InBlock.gif            
// i have not considered efficiency problem in precomputing progressdot.gif
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**//* mip-map is built as follow :
InBlock.gif
InBlock.gif            NEXT GREEN
ExpandedSubBlockEnd.gif            RED  BLUE    
*/

InBlock.gif
InBlock.gif            pbyPtr 
= mip_map.begin() + ( mj + height2 ) * m_width + mi + width2;
InBlock.gif            pbyPtr[
0= (eiByte) b;
InBlock.gif
InBlock.gif            pbyPtr 
= mip_map.begin() + mj * m_width + mi + width2;
InBlock.gif            pbyPtr[
0= (eiByte) g;
InBlock.gif
InBlock.gif            pbyPtr 
= mip_map.begin() + ( mj + height2 ) * m_width + mi;
InBlock.gif            pbyPtr[
0= (eiByte) r;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    bltB( width2, height2, m_width 
/ 4, m_height / 4, width2, height2 );
InBlock.gif    bltG( width2, 
0, m_width / 40, width2, height2 );
InBlock.gif    bltR( 
0, height2, 0, m_height / 4, width2, height2 );
InBlock.gif
InBlock.gif    type 
= MIP_MAP;
InBlock.gif
InBlock.gif    
return true;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiFloat eiTexture::get_bilinear(eiFloat x, eiFloat y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    eiInt                            u,v;
InBlock.gif    std::vector
<eiByte>::iterator    pbyPtr;
InBlock.gif
InBlock.gif    u 
= (eiInt) x;
InBlock.gif    v 
= (eiInt) y;
InBlock.gif
InBlock.gif    
if( (eiFloat) u == x && (eiFloat) v == y )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        pbyPtr 
= mip_map.begin() + m_width * v + u;
InBlock.gif
InBlock.gif        
return pbyPtr[0* EI_BYTE_2_FLOAT;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    eiFloat        du,dv,r1,r2;
InBlock.gif    eiByte        f1,f2,f3,f4;
InBlock.gif
InBlock.gif    du 
= curve( x - u );
InBlock.gif    dv 
= curve( y - v );
InBlock.gif
InBlock.gif    pbyPtr 
= mip_map.begin() + m_width * v + u;
InBlock.gif    f1 
= pbyPtr[0];
InBlock.gif    f2 
= pbyPtr[1];
InBlock.gif
InBlock.gif    pbyPtr 
+= m_width;
InBlock.gif    f3 
= pbyPtr[1];
InBlock.gif    f4 
= pbyPtr[0];
InBlock.gif
InBlock.gif    r1 
= f1 + (f2 - f1) * du;
InBlock.gif
InBlock.gif    r2 
= f4 + (f3 - f4) * du;
InBlock.gif
InBlock.gif    r1 
= r1 + (r2 - r1) * dv;
InBlock.gif
InBlock.gif    
return r1 * EI_BYTE_2_FLOAT;
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiColor eiTexture::get_pixel(eiFloat x, eiFloat y, eiInt d)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if(src.empty() || ( type == MIP_MAP && mip_map.empty() ) )
InBlock.gif        
return newclr();
InBlock.gif
InBlock.gif    
if(d == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
return get_src_bilinear_color( x, y );
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    eiFloat b,g,r,scale;
InBlock.gif
InBlock.gif    scale 
= 1 / powf( 2 , d );
InBlock.gif
InBlock.gif    eiFloat mx,my,width2,height2;
InBlock.gif
InBlock.gif    width2 
= m_width * scale;
InBlock.gif    height2 
= m_height * scale;
InBlock.gif    mx 
= x * scale;
InBlock.gif    my 
= y * scale;
InBlock.gif
InBlock.gif    b 
= get_bilinear( width2 + mx , height2 + my );
InBlock.gif
InBlock.gif    g 
= get_bilinear( width2 + mx , my );
InBlock.gif
InBlock.gif    r 
= get_bilinear( mx , height2 + my );
InBlock.gif
InBlock.gif    
return newclr(r,g,b);
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiColor eiTexture::lookup( const  eiPlane &  uv)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
return get_pixel(uv.x, uv.y, uv.z, uv.w);
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
None.gif
eiColor eiTexture::get_pixel(eiFloat x, eiFloat y, eiFloat dx, eiFloat dy)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    x 
*= m_width;
InBlock.gif    y 
*= m_height;
InBlock.gif
InBlock.gif    
if( type == SRC || ( dx == 0.0 && dy == 0.0 ) )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//maybe shading for raytracing, do not use mip-mapdot.gif
InBlock.gif

InBlock.gif        
return get_src_bilinear_color( x, y );
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    dx 
*= m_width;
InBlock.gif    dy 
*= m_height;
InBlock.gif
InBlock.gif    eiFloat d;
InBlock.gif    eiInt    di;
InBlock.gif    eiColor    c1,c2;
InBlock.gif
InBlock.gif    d 
= max(dx,dy);
InBlock.gif
InBlock.gif    d 
= log2f(d);
InBlock.gif    di 
= (eiInt) d;
InBlock.gif    d 
= d - (eiFloat) di;
InBlock.gif
InBlock.gif    c1 
= get_pixel( x, y, di );
InBlock.gif    c2 
= get_pixel( x, y, di + 1 );
InBlock.gif
InBlock.gif    
return mixclr( c1, c2, d );
ExpandedBlockEnd.gif}

None.gif
// -------------------------------------------------------------------------
posted on 2005-07-08 18:56 Len3d 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/len3d/archive/2005/07/08/188838.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值