Bitmap *Gradient::BuildBitmap(int size) { float u,v; BitmapInfo bi; static MaxSDK::AssetManagement::AssetUser bitMapAssetUser; if (bitMapAssetUser.GetId() == MaxSDK::AssetManagement::kInvalidId) bitMapAssetUser = MaxSDK::AssetManagement::IAssetManager::GetInstance()->GetAsset(GetString(IDS_RB_GRADTEMP), MaxSDK::AssetManagement::kBitmapAsset); bi.SetAsset(bitMapAssetUser); bi.SetWidth(size); bi.SetHeight(size); bi.SetType(BMM_TRUE_32); Bitmap *bm = TheManager->Create(&bi); if (bm==NULL) return NULL; PixelBuf l64(size); float d = 1.0f/float(size); v = 1.0f - 0.5f*d; for (int y=0; y<size; y++) { BMM_Color_64 *p64=l64.Ptr(); u = 0.0f; for (int x=0; x<size; x++, p64++) { AColor c = DispEvalFunc(u,v); p64->r = FlToWord(c.r); p64->g = FlToWord(c.g); p64->b = FlToWord(c.b); p64->a = 0xffff; u += d; } bm->PutPixels(0,y, size, l64.Ptr()); v -= d; } return bm; }
Bitmap* UVtex::BuildBitmap(int size) { float u,v; BitmapInfo bi; bi.SetName(_T("uvTexTemp")); bi.SetWidth(size); bi.SetHeight(size); bi.SetType(BMM_TRUE_32); Bitmap *bm = TheManager->Create(&bi); if (bm==NULL) return NULL; PixelBuf l64(size); float d = 1.0f/float(size); v = 0.0f; for (int y=0; y<size; y++) { BMM_Color_64 *p64=l64.Ptr(); u = 0.0f; for (int x=0; x<size; x++, p64++) { Color c = EvalUVtex( Point3(u,(1.0f-v),0.0f) ); p64->r = FlToWord(c.r); p64->g = FlToWord(c.g); p64->b = FlToWord(c.b); p64->a = 0xffff; u += d; } bm->PutPixels(0,y, size, l64.Ptr()); v += d; } return bm; }
Bitmap *Gradient::BuildBitmap(int size) { float u,v; BitmapInfo bi; bi.SetName(GetString(IDS_RB_GRADTEMP)); bi.SetWidth(size); bi.SetHeight(size); bi.SetType(BMM_TRUE_32); Bitmap *bm = TheManager->Create(&bi); if (bm==NULL) return NULL; PixelBuf l64(size); float d = 1.0f/float(size); v = 1.0f - 0.5f*d; for (int y=0; y<size; y++) { BMM_Color_64 *p64=l64.Ptr(); u = 0.0f; for (int x=0; x<size; x++, p64++) { AColor c = DispEvalFunc(u,v); p64->r = FlToWord(c.r); p64->g = FlToWord(c.g); p64->b = FlToWord(c.b); p64->a = 0xffff; u += d; } bm->PutPixels(0,y, size, l64.Ptr()); v -= d; } return bm; }
//DIB Methods Value* getViewportDib_cf(Value** arg_list, int count) { check_arg_count(getViewportDib, 0, count); GraphicsWindow *gw = MAXScript_interface->GetActiveViewExp().getGW(); BITMAPINFO *bmi = NULL; BITMAPINFOHEADER *bmih; BitmapInfo bi; Bitmap *bmp; int size; gw->getDIB(NULL, &size); bmi = (BITMAPINFO *)malloc(size); bmih = (BITMAPINFOHEADER *)bmi; gw->getDIB(bmi, &size); bi.SetWidth((WORD)bmih->biWidth); bi.SetHeight((WORD)bmih->biHeight); bi.SetType(BMM_TRUE_32); UWORD *gammatab = NULL; IColorCorrectionMgr* idispGamMgr = (IColorCorrectionMgr*) GetCOREInterface(COLORCORRECTIONMGR_INTERFACE); float gamma = 1.0f; // default if off if(gammaMgr.IsEnabled() && idispGamMgr) { gamma = idispGamMgr->GetGamma(); gammatab = new UWORD[RCOLN]; // Build gamma correction table if (gammatab) BuildGammaTab(gammatab, 1.0f/gamma, true); // To gamma-correct we need 64 bits resolution bi.SetType(BMM_TRUE_64); } bi.SetGamma(1.0f); // New bitmap will be linear bmp = CreateBitmapFromBitmapInfo(bi); // Make new, linear bitmap bmp->FromDib(bmi); free(bmi); // JBW 10.7.99: missing free(), elided above I/O, not desired // If gamma is on: /* EXPLANATION: The code that saves a bitmap always assumes the bitmap to be saved comes from the renderer, and hence, is linear. Since we are grabbing off the viewport (with an embedded gamma) we need to linearize the bitmap first */ if (gammatab) { // We still want this to be SAVED with a gamma. What gamma MaxScript will save // this with (by default) is defined by the gamma of the BitmapInfo bi's gamma // And we intentionally want it to look like it was displayed - hence we use the // display gamma!! bi.SetGamma(gamma); int h = bmp->Height(); int w = bmp->Width(); BMM_Color_64 *pixelrow = (BMM_Color_64 *)LocalAlloc(LPTR,w*sizeof(BMM_Color_64)); if (pixelrow) { for (int iy = 0; iy < h; iy++) { bmp->GetPixels(0, iy, w, pixelrow); for (int ix = 0; ix < w; ix++) { pixelrow[ix].r = gammatab[UWORD(pixelrow[ix].r) >> RCSH16]; pixelrow[ix].g = gammatab[UWORD(pixelrow[ix].g) >> RCSH16]; pixelrow[ix].b = gammatab[UWORD(pixelrow[ix].b) >> RCSH16]; } bmp->PutPixels(0, iy, w, pixelrow); } LocalFree(pixelrow); } delete [] gammatab; } return new MAXBitMap(bi, bmp); }
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; }