Ejemplo n.º 1
0
uint32_t  *plLayerConverter::IGetInitBitmapBuffer( plDynamicTextLayer *layer ) const
{
    uint32_t          *buffer;
    hsRGBAColor32   *buffPtr;
    uint16_t          width, height;


    IParamBlock2 *bitmapPB = layer->GetParamBlockByID( plDynamicTextLayer::kBlkBitmap );
    Bitmap      *initBitmap = layer->GetBitmap( TimeValue( 0 ) );

    if( bitmapPB->GetInt( (ParamID)plDynamicTextLayer::kBmpUseInitImage ) == 0 || initBitmap == nil )
        return nil;

    width = bitmapPB->GetInt( (ParamID)plDynamicTextLayer::kBmpExportWidth );
    height = bitmapPB->GetInt( (ParamID)plDynamicTextLayer::kBmpExportHeight );

    buffer = new uint32_t[ width * height ];
    if( buffer == nil )
        return nil;

    // Fill buffer from the MAX bitmap
    PixelBuf        l64( width );
    BMM_Color_64    *p64 = l64.Ptr();

    buffPtr = (hsRGBAColor32 *)buffer;
    for( int y = 0; y < height; y++ )
    {
        hsRGBAColor32   color;

        if( !initBitmap->GetLinearPixels( 0, y, width, p64 ) )
        {
            delete [] buffer;
            return nil;
        }

        for( int x = 0; x < width; x++ )
        {
            const float konst = 255.f / 65535.f;
            color.SetARGB((uint8_t)(p64[ x ].a * konst),
                          (uint8_t)(p64[ x ].r * konst),
                          (uint8_t)(p64[ x ].g * konst),
                          (uint8_t)(p64[ x ].b * konst));
            buffPtr[ x ] = color;
        }

        buffPtr += width;
    }

    return buffer;
}
Ejemplo n.º 2
0
AColor plStaticEnvLayer::EvalColor(ShadeContext& sc)
{
    if (!sc.doMaps) 
        return AColor(0.0f, 0.0f, 0.0f, 1.0f);

    AColor color;
    if (sc.GetCache(this, color)) 
        return color;

    if (gbufID) 
        sc.SetGBufferID(gbufID);

    // Evaluate the Bitmap

//  Point3  v = sc.VectorTo( sc.V(), REF_OBJECT );//WORLD );
    Point3  v = sc.VectorTo( sc.Normal(), REF_OBJECT );
    float   wx,wy,wz;
    Color   rcol;
    Bitmap  *refmap = NULL;
    Point3  rv;
    Point2  uv;
    int     size;

    wx = (float)fabs( v.x );  
    wy = (float)fabs( v.y );
    wz = (float)fabs( v.z ); 
    if( wx >= wy && wx >= wz )
    {
        if( v.x < 0 )
        {
            refmap = fBitmaps[ kLeftFace ];
            uv = CompUV( -v.y, -v.z,  v.x );
        }
        else
        {
            refmap = fBitmaps[ kRightFace ];
            uv = CompUV( v.y, -v.z, -v.x );
        }
    }
    else if( wy >= wx && wy >= wz ) 
    {
        if( v.y > 0 )
        {
            refmap = fBitmaps[ kBackFace ];
            uv = CompUV( -v.x, -v.z, -v.y );
        }
        else
        {
            refmap = fBitmaps[ kFrontFace ];
            uv = CompUV(  v.x, -v.z,  v.y );
        }
    }
    else if( wz >= wx && wz >= wy ) 
    {
        if( v.z < 0 )
        {   
            refmap = fBitmaps[ kBottomFace ];
            uv = CompUV( -v.x, -v.y,  v.z );
        }
        else     
        {   
            refmap = fBitmaps[ kTopFace ];
            uv = CompUV( -v.x,  v.y, -v.z );
        }
    }

    if( refmap == NULL )
        color.White();
    else
    {
        if( uv.x < 0.0f )
            uv.x = 0.0f; 
        else if( uv.x > 1.0f )
            uv.x = 1.0f;
        if( uv.y < 0.0f )
            uv.y = 0.0f; 
        else if( uv.y > 1.0f )
            uv.y = 1.0f;
        size = refmap->Width();
        int x = (int)( uv.x * (float)( size - 1 ) );
        int y = (int)( ( 1.0f - uv.y ) * (float)( size - 1 ) );

        BMM_Color_64 c;
        refmap->GetLinearPixels( x, y, 1, &c );
        color = AColor( c.r / 65535.f, c.g / 65535.f, c.b / 65535.f, c.a / 65535.f );
    }

    // Invert color if specified
    if( fBitmapPB->GetInt( kBmpInvertColor ) )
    {
        color.r = 1.0f - color.r;
        color.g = 1.0f - color.g;
        color.b = 1.0f - color.b;
    }
    // Discard color if specified
    if( fBitmapPB->GetInt( kBmpDiscardColor ) )
        color.r = color.g = color.b = 1.0f;

    // Invert alpha if specified
    if( fBitmapPB->GetInt( kBmpInvertAlpha ) )
        color.a = 1.0f - color.a;
    // Discard alpha if specified
    if( fBitmapPB->GetInt( kBmpDiscardAlpha ) )
        color.a = 1.0f;

    // If RGB output is set to alpha, show RGB as grayscale of the alpha
    if( fBitmapPB->GetInt( kBmpRGBOutput ) == 1 )
        color = AColor( color.a, color.a, color.a, 1.0f );

    sc.PutCache(this, color); 
    return color;
}
Ejemplo n.º 3
0
void DxStdMtl2::LoadTextureData(IHLSLCodeGenerator * codeGen)
{
	Bitmap * bmap;
	BitmapInfo stBI;

	TimeValue t = GetCOREInterface()->GetTime();
	int nWidth,nHeight;

	int numberOfTextures = elementContainer.NumberofElementsByType(EffectElements::kEleTex);
	for(int i=0; i<numberOfTextures;i++)
	{
		bool bBump;
		TextureElement * texEle = static_cast<TextureElement*>(elementContainer.GetElementByType(i,EffectElements::kEleTex));

		TSTR mapType = texEle->GetMapName();
		Texmap *texmap = codeGen->GetShaderDefinedTexmap(map,mapType.data(),bBump);

		if(texmap)
		{
			BMM_Color_64 *p;
			nWidth = nHeight = DIMDEFAULT;
			BitmapDimensions(nWidth,nHeight,texmap);
			// load and create the D3D texture;
/*			if(texmap->ClassID() == Class_ID(BMTEX_CLASS_ID, 0))
			{
				BitmapTex *pBT;
				Bitmap *pTex;
				pBT = (BitmapTex *)texmap;
				pTex = pBT->GetBitmap(t);
				if (pTex)
				{
					nWidth = getClosestPowerOf2(pTex->Width());
					nHeight = getClosestPowerOf2(pTex->Height());
				}

			}
*/				
			stBI.SetType(BMM_TRUE_32);
			stBI.SetWidth(nWidth);
			stBI.SetHeight(nHeight);        
			bmap = TheManager->Create(&stBI);

			if (bmap)
			{
//				LPDIRECT3DTEXTURE9 pRenderTex = texEle->GetD3DTexture();

				texmap->RenderBitmap(t, bmap, MAPSCALE3D * 2.0f);
				p = new BMM_Color_64[nWidth*nHeight];

				for (int y = 0; y < nHeight; y++)
					bmap->GetLinearPixels(0, y, nWidth, p + y * nWidth);
			
				if(texEle->pTex)
				{
					D3DSURFACE_DESC stLD;
					texEle->pTex->GetLevelDesc(0, &stLD);
					if (stLD.Width != nWidth || stLD.Height != nHeight)
					{
						SAFE_RELEASE(texEle->pTex);
					}

				}
				if(!texEle->pTex)
					pd3dDevice->CreateTexture(nWidth,nHeight, 0,D3DUSAGE_AUTOGENMIPMAP,	D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&texEle->pTex, NULL);

				if(texEle->pTex)
				{
					PIXELFMT *pT;
					D3DLOCKED_RECT stLR;
					texEle->pTex->LockRect(0, &stLR, 0, 0);
					pT = (PIXELFMT *)stLR.pBits;

					for (int i = 0; i < nWidth * nHeight; i++)
					{
						pT[i].r = p[i].r >> 8;
						pT[i].g = p[i].g >> 8;
						pT[i].b = p[i].b >> 8;
						pT[i].a = p[i].a >> 8;
					}
					texEle->pTex->UnlockRect(0);
				
					if(bBump && texmap->ClassID() != GNORMAL_CLASS_ID)
					{
//						LPDIRECT3DTEXTURE9 normalTex = texEle->GetD3DBumpTexture();
						
						if(texEle->pBumpTex)
						{
							D3DSURFACE_DESC stLD;
							texEle->pBumpTex->GetLevelDesc(0, &stLD);
							if (stLD.Width != nWidth || stLD.Height != nHeight)
							{
								SAFE_RELEASE(texEle->pBumpTex);
							}
						}
						if(!texEle->pBumpTex)
							pd3dDevice->CreateTexture(nWidth,nHeight, 0,D3DUSAGE_AUTOGENMIPMAP,	D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&texEle->pBumpTex, NULL);

						D3DXComputeNormalMap(texEle->pBumpTex,texEle->pTex,NULL, NULL, D3DX_CHANNEL_RED,30.0f);

						if(texEle->GetParamHandle())
						{
							pEffectParser->LoadTexture(texEle->pBumpTex, texEle->GetParameterName());
//							pEffect->SetTexture(texEle->GetParamHandle(),texEle->pBumpTex);
//							D3DXSaveTextureToFile("c:\\temp\\normal_notgnormal.dds", D3DXIFF_DDS, texEle->pBumpTex, NULL);
							SAFE_RELEASE(texEle->pBumpTex);
						}
					}
					else
					{
						if(texEle->GetParamHandle())
						{
							pEffectParser->LoadTexture(texEle->pTex, texEle->GetParameterName());
//							pEffect->SetTexture(texEle->GetParamHandle(),texEle->pTex);
//							D3DXSaveTextureToFile("c:\\temp\\normal_gnormal.dds", D3DXIFF_DDS, texEle->pTex, NULL);
							SAFE_RELEASE(texEle->pTex);
						}

					}
				}
				bmap->DeleteThis();

			}
			delete p;
		}
		else
		{
Ejemplo n.º 4
0
BITMAPINFO *plLayerTex::GetVPDisplayDIB(TimeValue t, TexHandleMaker& thmaker, Interval &valid, BOOL mono, BOOL forceW, BOOL forceH)
{
    // FIXME
    fTexTime = 0;//CalcFrame(t);
//  texValid = clipValid;
    BITMAPINFO *bmi = NULL;
    int xflags = 0;

    if (fBitmapPB->GetInt(kBmpApply))
    {
        float clipu = fBitmapPB->GetFloat(kBmpClipU);
        float clipv = fBitmapPB->GetFloat(kBmpClipV);
        float clipw = fBitmapPB->GetFloat(kBmpClipW);
        float cliph = fBitmapPB->GetFloat(kBmpClipH);
        int discardAlpha = fBitmapPB->GetInt(kBmpDiscardAlpha);
        int alphaAsRGB = (fBitmapPB->GetInt(kBmpRGBOutput) == 1);

        int w = fBM->Width();
        int h = fBM->Height();

        Bitmap *newBM;
        BitmapInfo bi;
        bi.SetName(_T("y8798734"));
        bi.SetType(BMM_TRUE_32);
        bi.SetFlags(MAP_HAS_ALPHA);

        if (fBitmapPB->GetInt(kBmpCropPlace) == 1)
        {
            int x0, y0, nw, nh;
            int bmw = thmaker.Size();
            int bmh = int(float(bmw)*float(h)/float(w));
            bi.SetWidth(bmw);
            bi.SetHeight(bmh);
            newBM = TheManager->Create(&bi);
            newBM->Fill(0,0,0,0);
            nw = int(float(bmw)*clipw);
            nh = int(float(bmh)*cliph);
            x0 = int(float(bmw-1)*clipu);
            y0 = int(float(bmh-1)*clipv);

            if (nw<1) nw = 1;
            if (nh<1) nh = 1;
            PixelBuf row(nw);

            Bitmap *tmpBM;
            BitmapInfo bif2;
            bif2.SetName(_T("xxxx67878"));
            bif2.SetType(BMM_TRUE_32);
            bif2.SetFlags(MAP_HAS_ALPHA);
            bif2.SetWidth(nw);
            bif2.SetHeight(nh);
            tmpBM = TheManager->Create(&bif2);
            tmpBM->CopyImage(fBM, COPY_IMAGE_RESIZE_LO_QUALITY, 0);
            BMM_Color_64*  p1 = row.Ptr();
            for (int y = 0; y<nh; y++)
            {
                tmpBM->GetLinearPixels(0,y, nw, p1);
                if (alphaAsRGB)
                {
                    for (int ix =0; ix<nw; ix++)
                        p1[ix].r = p1[ix].g = p1[ix].b = p1[ix].a;
                }
                if (discardAlpha)
                {
                    for (int ix = 0; ix < nw; ix++)
                        p1[ix].a = 0xffff;
                }
                newBM->PutPixels(x0, y+y0, nw, p1);
            }
            tmpBM->DeleteThis();
            bmi = thmaker.BitmapToDIB(newBM, fUVGen->SymFlags(), xflags, forceW, forceH);
            newBM->DeleteThis();
        }
        else
        {
            int x0,y0,nw,nh;
            x0 = int(float(w-1)*clipu);
            y0 = int(float(h-1)*clipv);
            nw = int(float(w)*clipw);
            nh = int(float(h)*cliph);
            if (nw<1) nw = 1;
            if (nh<1) nh = 1;
            bi.SetWidth(nw);
            bi.SetHeight(nh);
            PixelBuf row(nw);
            newBM = TheManager->Create(&bi);
            BMM_Color_64*  p1 = row.Ptr();
            for (int y = 0; y<nh; y++)
            {
                fBM->GetLinearPixels(x0,y+y0, nw, p1);
                if (alphaAsRGB)
                {
                    for (int ix = 0; ix < nw; ix++)
                        p1[ix].r = p1[ix].g = p1[ix].b = p1[ix].a;
                }
                if (discardAlpha)
                {
                    for (int ix = 0; ix < nw; ix++)
                        p1[ix].a = 0xffff;
                }
                newBM->PutPixels(0, y, nw, p1);
            }
            bmi = thmaker.BitmapToDIB(newBM, fUVGen->SymFlags(), xflags, forceW, forceH);
            newBM->DeleteThis();
        }
    }
    else
    {
        if (fBitmapPB->GetInt(kBmpRGBOutput) == 1)
            xflags |= EX_RGB_FROM_ALPHA;
        bmi = thmaker.BitmapToDIB(fBM, fUVGen->SymFlags(), xflags, forceW, forceH);
    }

    return bmi;
}