BITMAPINFO* Gradient::GetVPDisplayDIB(TimeValue t, TexHandleMaker& thmaker, Interval &valid, BOOL mono, BOOL forceW, BOOL forceH) { Bitmap* bm = NULL; Interval v; Update(t,v); bm = BuildBitmap(thmaker.Size()); BITMAPINFO *bmi = thmaker.BitmapToDIB(bm,uvGen->SymFlags(),0,forceW,forceH); bm->DeleteThis(); valid.SetInfinite(); Color ac; pblock->GetValue( grad_color1, t, ac, valid ); pblock->GetValue( grad_color2, t, ac, valid ); pblock->GetValue( grad_color3, t, ac, valid ); return bmi; }
int PlateMap::AllocMap(int w, int h) { if ( bm && w==bm->Width() && h==bm->Height()) return 1; BitmapInfo bi; if (bm) bm->DeleteThis(); bi.SetName(_T("")); bi.SetWidth(w); bi.SetHeight(h); bi.SetType(BMM_TRUE_32); bi.SetCustomFlag(BMM_CUSTOM_GAMMA); bi.SetCustomGamma(1.0f); bm = TheManager->Create(&bi); // bm->CreateChannels(BMM_CHAN_Z); return 1; }
DWORD UVtex::GetActiveTexHandle(TimeValue t, TexHandleMaker& thmaker) { #endif if (texHandle) { if (texHandleValid.InInterval(t)) return texHandle->GetHandle(); else DiscardTexHandle(); } Interval v; Update(t,v); Bitmap *bm; bm = BuildBitmap(thmaker.Size()); texHandle = thmaker.CreateHandle(bm); bm->DeleteThis(); texHandleValid.SetInfinite(); int i; pblock->GetValue(uv_uvchannel, t, i, texHandleValid); pblock->GetValue(uv_rtype, t, i, texHandleValid); pblock->GetValue(uv_gtype, t, i, texHandleValid); pblock->GetValue(uv_btype, t, i, texHandleValid); pblock->GetValue(uv_rcount, t, i, texHandleValid); pblock->GetValue(uv_gcount, t, i, texHandleValid); pblock->GetValue(uv_bcount, t, i, texHandleValid); float f; pblock->GetValue(uv_tintAmount, t, f, texHandleValid); pblock->GetValue(uv_rAmount, t, f, texHandleValid); pblock->GetValue(uv_gAmount, t, f, texHandleValid); pblock->GetValue(uv_bAmount, t, f, texHandleValid); Color c; pblock->GetValue(uv_tintColor, t, c, texHandleValid); BOOL b; pblock->GetValue(uv_clampUVW, t, b, texHandleValid); return texHandle->GetHandle(); }
void plPlasmaMAXLayer::SetBitmap(BitmapInfo *bi, int index) { #ifdef MAXASS_AVAILABLE jvUniqueId targetAssetId; GetBitmapAssetId(targetAssetId, index); #endif Bitmap *BM = GetMaxBitmap(index); if (BM) { BM->DeleteThis(); BM = NULL; } if (bi) { #ifdef MAXASS_AVAILABLE if (!targetAssetId.IsEmpty()) { // If this texture has an assetId, we will check the // asset database and make sure we have the latest version // of the texture file before loading it MaxAssInterface* assInterface = GetMaxAssInterface(); if (assInterface) { char buf[20]; assInterface->UniqueIdToString(targetAssetId, buf); bi->SetDevice(buf); const char* filename = bi->Name(); // Download the latest version and retrieve the filename char newfilename[MAX_PATH]; if (assInterface->GetLatestVersionFile(targetAssetId, newfilename, sizeof(newfilename))) { // If the filename has changed, we have to reset the bitmap in the ParamBlock if(stricmp(filename, newfilename) != 0) bi->SetName(newfilename); } } } #endif BMMRES result; BM = TheManager->Load(bi, &result); if (result == BMMRES_SUCCESS) ISetMaxBitmap(BM, index); else ISetMaxBitmap(NULL, index); // The load may have failed, but we still want to set the paramblock. We // don't want to modify the layer if we're just missing the file. PBBitmap pbBitmap(*bi); ISetPBBitmap(&pbBitmap, index); } else { ISetMaxBitmap(NULL, index); ISetPBBitmap(NULL, index); } /* Bitmap *BM = GetMaxBitmap(index); if (BM) { BM->DeleteThis(); BM = NULL; } if (filename) { BitmapInfo bi; bi.SetName(filename); // If this texture has an assetId, get the latest version from AssetMan before loading it if (assetId && !assetId->IsEmpty()) { MaxAssInterface* maxAssInterface = GetMaxAssInterface(); if (maxAssInterface) { // Download the latest version and retrieve the filename char newfilename[MAX_PATH]; if (maxAssInterface->GetLatestVersionFile(*assetId, newfilename, sizeof(newfilename))) { // If the filename has changed, we have to reset the bitmap in the ParamBlock if (stricmp(filename, newfilename) != 0) { bi.SetName(newfilename); } } } } ISetMaxBitmap(TheManager->Load(&bi)); PBBitmap pbBitmap(bi); // TheManager->LoadInto(&pbBitmap.bi, &pbBitmap.bm, TRUE); ISetPBBitmap(&pbBitmap, index); if (assetId) SetBitmapAssetId(*assetId, index); } else { ISetMaxBitmap(NULL, index); ISetPBBitmap(NULL, index); } NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); */ }
void FreeMap() { if (bm) bm->DeleteThis(); bm = NULL; }
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 {
void plStaticEnvLayer::RenderCubicMap( INode *node ) { int res, size; BOOL success = 0; TSTR fname, fullname; Bitmap *bm = NULL; TSTR path, filename, ext, thisFilename; BitmapInfo biOutFile; static TCHAR suffixes[ 6 ][ 4 ] = { "_FR", "_BK", "_LF", "_RT", "_UP", "_DN" }; Interface *ip = GetCOREInterface(); size = fBitmapPB->GetInt( kBmpTextureSize, ip->GetTime() ); if( size <= 0 ) { return; } thisFilename = fBitmapPB->GetStr( kBmpBaseFilename, ip->GetTime() ); if( thisFilename.isNull() ) { return; } SplitFilename( thisFilename, &path, &filename, &ext ); BOOL wasHid = node->IsNodeHidden(); node->Hide( TRUE ); // Create a blank bitmap biOutFile.SetWidth( size ); biOutFile.SetHeight( size ); biOutFile.SetType( BMM_TRUE_64 ); biOutFile.SetAspect( 1.0f ); biOutFile.SetCurrentFrame( 0 ); bm = TheManager->Create( &biOutFile ); Matrix3 nodeTM = node->GetNodeTM( ip->GetTime() ); Matrix3 tm; INode *root = ip->GetRootNode(); bm->Display( GetString( IDS_CUBIC_RENDER_TITLE ) ); /// Set up rendering contexts ViewParams vp; vp.projType = PROJ_PERSPECTIVE; vp.hither = .001f; vp.yon = 1.0e30f; vp.fov = M_PI/2.0f; if( fBitmapPB->GetInt( kBmpUseMAXAtmosphere ) ) { vp.nearRange = 0; vp.farRange = fBitmapPB->GetFloat( kBmpFarDistance ); } else { vp.nearRange = vp.farRange = 1.0e30f; } BOOL saveUseEnvMap = ip->GetUseEnvironmentMap(); ip->SetUseEnvironmentMap( false ); res = ip->OpenCurRenderer( &vp ); for( int i = 0; i < 6; i++ ) { tm = IGetViewTM( i ); tm.PreTranslate( -nodeTM.GetTrans() ); vp.affineTM = tm; // Construct filename thisFilename.printf( _T( "%s\\%s%s%s" ), path, filename, suffixes[ i ], ext ); res = ip->CurRendererRenderFrame( ip->GetTime(), bm, NULL, 1.0f, &vp ); if( !res ) goto fail; if( !IWriteBM( &biOutFile, bm, thisFilename ) ) goto fail; } success = 1; fail: ip->CloseCurRenderer(); ip->SetUseEnvironmentMap( saveUseEnvMap ); bm->DeleteThis(); node->Hide( wasHid ); if( success ) { for(int i = 0; i < 6; i++ ) { BitmapInfo bi; thisFilename.printf( _T( "%s\\%s%s%s" ), path, filename, suffixes[ i ], ext ); bi.SetName( thisFilename ); PBBitmap pbBitmap( bi ); fBitmapPB->SetValue( kBmpFrontBitmap + i, ip->GetTime(), &pbBitmap ); } fBitmapPB->GetMap()->UpdateUI( ip->GetTime() ); } }
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; }