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; }
void SampleEffect::Apply(TimeValue t, Bitmap *bm, RenderGlobalContext *gc,CheckAbortCallback *checkAbort) { // JBW: all pblock references now use the new permanent param IDs Color color; float fstr; BOOL iBack; pblock->GetValue(prm_color, t, color, FOREVER); pblock->GetValue(prm_strength, t, fstr, FOREVER); pblock->GetValue(prm_iBack, t, iBack, FOREVER); pblock->GetValue(prm_slow, t, slow, FOREVER); int w = bm->Width(); int h = bm->Height(); int s = int(4095.0f*fstr); int cs = 4095-s; float alpha; PixelBuf l64(w); BMM_Color_64 *p=l64.Ptr(); BMM_Color_64 tempCol; BMM_Color_64 c = color; for (int y = 0; y<h; y++) { bm->GetPixels(0, y, w, p); for (int x=0; x<w; x++) { if ( iBack ) { // skip transparent pixel if (p[x].a == 0) continue; // otherwise, blend on alpha value alpha = p[x].a / MAX_COLf; tempCol.r = (cs*p[x].r+s*((p[x].r+c.r)>>1))>>12; tempCol.g = (cs*p[x].g+s*((p[x].g+c.g)>>1))>>12; tempCol.b = (cs*p[x].b+s*((p[x].b+c.b)>>1))>>12; p[x].r = (USHORT)(tempCol.r*alpha + p[x].r*(1.0f-alpha)); p[x].g = (USHORT)(tempCol.g*alpha + p[x].g*(1.0f-alpha)); p[x].b = (USHORT)(tempCol.b*alpha + p[x].b*(1.0f-alpha)); } else { p[x].r = (cs*p[x].r+s*((p[x].r+c.r)>>1))>>12; p[x].g = (cs*p[x].g+s*((p[x].g+c.g)>>1))>>12; p[x].b = (cs*p[x].b+s*((p[x].b+c.b)>>1))>>12; } if (slow) { double t1(10.0), t2(100.0); for (int k=0; k<20; k++) t1 += sqrt(t1+t2); // do something to slow things down for testing } } bm->PutPixels(0, y, w, p); if (((y&3)==0)&&checkAbort&&checkAbort->Progress(y,h)) return; }
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 *PainterTextureSample::BuildBitmap(int size) { float u,v; BitmapInfo bi; bi.SetName(_T("checkerTemp")); bi.SetWidth(size); bi.SetHeight(size); bi.SetType(BMM_TRUE_32); if (bm == NULL) { 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(0.0f,0.0f,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; } } width = size; 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; }
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; }