BMMRES BitmapIO_CIN::GetImageInfoDlg(HWND hWnd, BitmapInfo* bmi, const TCHAR* fname) { BitmapInfo bInfo; if (!bmi) { assert(FALSE); return ProcessImageIOError(bmi, GetResIDCaption(IDS_CIN_Internal_Error)); } bInfo.Copy(bmi); if (fname) bInfo.SetName(fname); BMMRES bmmResult = GetImageInfo(&bInfo); if (bmmResult != BMMRES_SUCCESS) { return bmmResult; } #ifdef BASIC_INFO_DLG DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CIN_BASIC_INFO), hWnd, (DLGPROC) CIN_ImageInfoDialogProc, (LPARAM) this); #else DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CIN_INFO), hWnd, (DLGPROC) CIN_ImageInfoDialogProc, (LPARAM) this); #endif return BMMRES_SUCCESS; }
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; }
/// Called to update the controls of the dialog virtual void Update( TimeValue t, Interval &valid, IParamMap2 *map ) { ICustButton *bmSelectBtn; IParamBlock2 *pblock; int i; long buttons[ 6 ] = { IDC_FRONT_NAME, IDC_BACK_NAME, IDC_LEFT_NAME, IDC_RIGHT_NAME, IDC_TOP_NAME, IDC_BOTTOM_NAME }; BitmapInfo bi; ParamMap2UserDlgProc::Update( t, valid, map ); pblock = map->GetParamBlock(); for( i = plStaticEnvLayer::kBmpFrontBitmap; i <= plStaticEnvLayer::kBmpBottomBitmap; i++ ) { bmSelectBtn = GetICustButton( GetDlgItem( map->GetHWnd(), buttons[ i ] ) ); PBBitmap *pbbm = pblock->GetBitmap( i, t ); if( pbbm ) bmSelectBtn->SetText( (TCHAR *)pbbm->bi.Filename() ); else bmSelectBtn->SetText( _T( "None" ) ); ReleaseICustButton( bmSelectBtn ); } plStaticEnvLayer *layer = (plStaticEnvLayer *)map->GetParamBlock()->GetOwner(); bi.SetName( layer->GetBaseFilename( t ) ); SetDlgItemText( map->GetHWnd(), IDC_BASE_FILENAME, bi.Filename() ); map->Enable( plStaticEnvLayer::kBmpGenerateFaces, ( bi.Name() == NULL || bi.Name()[ 0 ] == 0 ) ? FALSE : TRUE ); bmSelectBtn = GetICustButton( GetDlgItem( map->GetHWnd(), IDC_GENERATE_FACES ) ); bmSelectBtn->SetText( _T( "Generate From Node" ) ); ReleaseICustButton( bmSelectBtn ); i = pblock->GetInt( plStaticEnvLayer::kBmpTextureSize, t ); pblock->SetValue( plStaticEnvLayer::kBmpLastTextureSize, t, i ); }
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; }
// // Create Bitmap // plMipmap *plBitmapCreator::ICreateBitmap(plBitmapData *bd) { hsGuardBegin("hsConverterUtils::CreateBitmap"); // Load the bitmap BitmapInfo bi; bi.SetName(bd->fileName.AsString().c_str()); #if 0 // This isn't really an issue since the textures are packed -Colin const int kMaxFileNameLength = 30; if (strlen(bi.Filename()) > kMaxFileNameLength) { // Allow to continue, But make it painful char errStr[256]; sprintf(errStr, "File name longer than %d, won't burn to CD (%s)", kMaxFileNameLength, bi.Filename());//bitmapTex->GetName()); MessageBox(GetActiveWindow(), errStr, bd->fileName, MB_OK|MB_ICONEXCLAMATION); } #endif bool notMipped = (bd->texFlags & plMipmap::kForceOneMipLevel) != 0; float sigma = bd->sig; // Load the bitmap Bitmap *bm = TheManager->Load(&bi); if (!bm) { // FIXME /* if (fErrorMsg->Set(!(fWarned & kWarnedNoMoreBitmapLoadErr), "Error loading bitmap", pathName).CheckAskOrCancel()) { fWarned |= kWarnedNoMoreBitmapLoadErr; } */ return nil; } BitmapStorage *storage = bm->Storage(); BitmapInfo *bInfo = &storage->bi; ICheckOutBitmap(bInfo, bm, bd->fileName); // // Create a plMipmap // plMipmap *hBitmap = new plMipmap; if( (bm->Width() ^ (bm->Width() & -bm->Width())) ||(bm->Height() ^ (bm->Height() & -bm->Height())) ) { IResampBitmap(bm, *hBitmap); } else if( ((bm->Width() >> 3) > bm->Height())||((bm->Height() >> 3) > bm->Width()) ) { IResampBitmap(bm, *hBitmap); } else {
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; }
BOOL plPlasmaMAXLayer::HandleBitmapSelection(int index /* = 0 */) { static ICustButton* bmSelectBtn; PBBitmap *pbbm = GetPBBitmap( index ); #ifdef MAXASS_AVAILABLE MaxAssInterface* maxAssInterface = GetMaxAssInterface(); #endif // If the control key is held, we want to get rid of this texture if ((GetKeyState(VK_CONTROL) & 0x8000) && pbbm != nil) { char msg[512]; sprintf(msg, "Are you sure you want to change this bitmap from %s to (none)?", pbbm->bi.Name()); if (hsMessageBox(msg, "Remove texture?", hsMessageBoxYesNo) == hsMBoxYes) { SetBitmap(nil, index); return TRUE; } return FALSE; } // if we have the assetman plug-in, then try to use it, unless shift is held down #ifdef MAXASS_AVAILABLE else if(maxAssInterface && !(GetKeyState(VK_SHIFT) & 0x8000)) { jvUniqueId assetId; GetBitmapAssetId(assetId, index); char filename[MAX_PATH]; if (maxAssInterface->OpenBitmapDlg(assetId, filename, sizeof(filename))) { SetBitmapAssetId(assetId, index); BitmapInfo bi; bi.SetName(filename); SetBitmap(&bi, index); return TRUE; } } #endif else { BitmapInfo bi; if( pbbm != NULL ) bi.SetName( pbbm->bi.Name() ); BOOL selectedNewBitmap = TheManager->SelectFileInput(&bi, GetCOREInterface()->GetMAXHWnd(), _T("Select Bitmap Image File")); if (selectedNewBitmap) { #ifdef MAXASS_AVAILABLE // Set the assetId to empty so our new, unmanaged texture will take jvUniqueId emptyId; SetBitmapAssetId(emptyId, index); #endif SetBitmap(&bi, index); return TRUE; } } return FALSE; }
void plTextureSearch::IUpdateTextures(plTextureSearch::Update update) { MtlSet mtls; plMtlCollector::GetMtls(&mtls, nil, plMtlCollector::kPlasmaOnly | plMtlCollector::kNoMultiMtl); char searchStr[256]; GetDlgItemText(fDlg, IDC_FIND_EDIT, searchStr, sizeof(searchStr)); strlwr(searchStr); HWND hList = GetDlgItem(fDlg, IDC_TEXTURE_LIST); ListView_DeleteAllItems(hList); int sizeX = -1, sizeY = -1; HWND hCombo = GetDlgItem(fDlg, IDC_SIZE_COMBO); // If we're updating the size, get whatever the user selected if (update == kUpdateSetSize) { int sel = ComboBox_GetCurSel(hCombo); uint32_t data = ComboBox_GetItemData(hCombo, sel); sizeX = LOWORD(data); sizeY = HIWORD(data); } MtlSet::iterator it = mtls.begin(); for (; it != mtls.end(); it++) { Mtl *mtl = (*it); LayerSet layers; plMtlCollector::GetMtlLayers(mtl, layers); LayerSet::iterator layerIt = layers.begin(); for (; layerIt != layers.end(); layerIt++) { plPlasmaMAXLayer *layer = (*layerIt); int numBitmaps = layer->GetNumBitmaps(); for (int i = 0; i < numBitmaps; i++) { PBBitmap *pbbm = layer->GetPBBitmap(i); if (pbbm) { const char *name = pbbm->bi.Filename(); if (name && *name != '\0') { char buf[256]; strncpy(buf, name, sizeof(buf)); strlwr(buf); // If we don't have a search string, or we do and it was // found in the texture name, add the texture to the list. if (searchStr[0] == '\0' || strstr(buf, searchStr)) { if (update == kUpdateLoadList) { LVITEM item = {0}; item.mask = LVIF_TEXT | LVIF_PARAM; item.pszText = mtl->GetName(); item.lParam = (LPARAM)mtl; // A little dangerous, since the user could delete this int idx = ListView_InsertItem(hList, &item); ListView_SetItemText(hList, idx, 1, layer->GetName()); ListView_SetItemText(hList, idx, 2, (char*)name); // If size is uninitialized or the same as the last, keep size if ((sizeX == -1 && sizeY == -1) || (sizeX == pbbm->bi.Width() && sizeY == pbbm->bi.Height())) { sizeX = pbbm->bi.Width(); sizeY = pbbm->bi.Height(); } // Otherwise clear it else { sizeX = sizeY = 0; } } else if (update == kUpdateReplace) { #ifdef MAXASS_AVAILABLE layer->SetBitmapAssetId(gAssetID, i); #endif BitmapInfo info; info.SetName(fFileName); layer->SetBitmap(&info, i); } else if (update == kUpdateSetSize) { layer->SetExportSize(sizeX, sizeY); } } } } } } } if (update == kUpdateLoadList) { HWND hButton = GetDlgItem(fDlg, IDC_SET_ALL_BUTTON); ComboBox_ResetContent(hCombo); // If all bitmaps are the same size, enable resizing if (sizeX != -1 && sizeX != 0) { sizeX = FloorPow2(sizeX); sizeY = FloorPow2(sizeY); char buf[256]; while (sizeX >= 4 && sizeY >= 4) { sprintf(buf, "%d x %d", sizeX, sizeY); int idx = ComboBox_AddString(hCombo, buf); ComboBox_SetItemData(hCombo, idx, MAKELPARAM(sizeX, sizeY)); sizeX >>= 1; sizeY >>= 1; } ComboBox_SetCurSel(hCombo, 0); EnableWindow(hCombo, TRUE); EnableWindow(hButton, TRUE); }
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; }