예제 #1
0
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.

}
예제 #2
0
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;
}
예제 #3
0
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;
	}
예제 #4
0
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;
	}
예제 #5
0
파일: gradient.cpp 프로젝트: 2asoft/xray
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;
	}
예제 #6
0
파일: plate.cpp 프로젝트: artemeliy/inf4715
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;
	}
예제 #7
0
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
		{
예제 #8
0
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() );
    }
}
예제 #9
0
//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);
}
예제 #10
0
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;
}
예제 #11
0
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;
}