void UtilTest::RenderFrame() { int res; // Create a blank bitmap static Bitmap *bm = NULL; if (!bm) { BitmapInfo bi; bi.SetWidth(320); bi.SetHeight(200); bi.SetType(BMM_TRUE_64); bi.SetFlags(MAP_HAS_ALPHA); bi.SetAspect(1.0f); bm = TheManager->Create(&bi); } // Get the active viewport to render // Display the bitmap bm->Display(_T("Test")); // Open up the renderer, render a frame and close it. res = ip->OpenCurRenderer(NULL,ip->GetActiveViewExp().ToPointer()); res = ip->CurRendererRenderFrame( ip->GetTime(),bm); ip->CloseCurRenderer(); // We're done with the viewport. }
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; }
AWDTexture * AWDExporter::ExportTexture(AWD *awd, awd_ncache *ncache,Texmap* tex, Class_ID cid, int subNo, AWDMaterial * mat ) { AWDTexture *awd_tex; const char* name; int name_len; bool hasAlpha = false; MSTR path; awd_uint8 * buf; int buf_len; if (!tex) return NULL; if (tex->ClassID() != Class_ID(BMTEX_CLASS_ID, 0x00) ) return NULL; // texture already exist in cache awd_tex = (AWDTexture *)awd_ncache_get( ncache, tex ); if( awd_tex ) return awd_tex; BitmapTex *bmptex = (BitmapTex*)tex; MaxSDK::AssetManagement::AssetUser asset = bmptex->GetMap(); hasAlpha = bmptex->GetBitmap( GetStaticFrame() )->HasAlpha(); if( !asset.GetFullFilePath(path) ) { fprintf( logfile, " export !asset.GetFullFilePath(path) : %i \n", asset.GetType() ); fflush( logfile ); //return NULL; } fprintf( logfile, " export : %s \n", path ); fflush( logfile ); AWD_tex_type textype = EXTERNAL; if( GetIncludeMaps() && asset.GetType() == MaxSDK::AssetManagement::kBitmapAsset ) { const char * dot; dot = strrchr(path,'.'); if( !strcmp(dot, ".jpg")|| !strcmp(dot, ".JPG")|| !strcmp(dot, ".jpeg")|| !strcmp(dot, ".JPEG") ) { textype = EMBEDDED_JPEG; } else if ( !strcmp(dot, ".png")|| !strcmp(dot, ".PNG") ) { textype = EMBEDDED_PNG; } if( textype == 0 ) { fprintf( logfile, " export texture : %s \n", path ); fflush( logfile ); // try to extract data Bitmap *bmp = bmptex->GetBitmap( GetStaticFrame() ); BitmapInfo bi; MaxSDK::Util::Path *temppath; bi.SetWidth( bmp->Width() ); bi.SetHeight( bmp->Height() ); if( hasAlpha ) { bi.SetType( BMM_TRUE_32 ); bi.SetFlags( MAP_HAS_ALPHA ); path = "C:\\Users\\lepersp\\Desktop\\temp\\awdexporttempjpg.png"; textype = EMBEDDED_PNG; } else { bi.SetType( BMM_TRUE_24 ); path = "C:\\Users\\lepersp\\Desktop\\temp\\awdexporttempjpg.jpg"; textype = EMBEDDED_JPEG; } temppath = new MaxSDK::Util::Path( path ); bi.SetPath( *temppath ); bmp->OpenOutput( & bi ); bmp->Write( & bi ); bmp->Close(& bi); } if( path != NULL ) { size_t result; int fd; errno_t err = _sopen_s( &fd, path, _O_RDONLY|_O_BINARY, _SH_DENYNO, _S_IREAD ); if( err == 0 ) { struct stat *s; s = (struct stat *)malloc(sizeof(struct stat)); fstat(fd, s); buf_len = s->st_size; buf = (awd_uint8 *) malloc (buf_len * sizeof( awd_uint8 ) ); lseek(fd, 0, SEEK_SET); result = read(fd, buf, buf_len); if (result != buf_len) { textype = EXTERNAL; } _close( fd ); } else { textype = EXTERNAL; } } } name = tex->GetName(); name_len = strlen( name ); char* namecpy = (char*) malloc( name_len*sizeof( char ) ) ; strcpy( namecpy, name ); awd_tex = new AWDTexture( textype, namecpy, name_len ); if( textype != 0 ) { awd_tex->set_embed_data(buf, buf_len); } char * pathcpy = (char *) malloc( (path.length()+1) * sizeof( char ) ); strcpy( pathcpy, path.data() ); awd_tex->set_url( pathcpy, strlen( pathcpy ) ); awd->add_texture( awd_tex ); awd_ncache_add( ncache, tex, awd_tex ); if( subNo == ID_DI ) { mat->set_texture( awd_tex ); mat->alpha_blending = hasAlpha; } return awd_tex; }