コード例 #1
0
ファイル: main.cpp プロジェクト: amadlover/setupRGBShaders
__declspec( dllexport ) MStatus initializePlugin( MObject obj )
{
    char *version;

#ifdef MAYA2010
    version = "2010";
#else
    version = "2008";
#endif

    MImage ip1;
    ip1.readFromFile( "E:/Release/bump.jpg" );

    unsigned char *ip1Pix = ip1.pixels();
    unsigned int ip1width, ip1height;
    ip1.getSize( ip1width, ip1height );

    MImage ip2;
    ip2.readFromFile( "E:/Release/transReflect.jpg" );

    unsigned char *ip2Pix = ip2.pixels();
    unsigned int ip2Width, ip2Height;
    ip2.getSize( ip2Width, ip2Height );

    float *pixels = new float[ ip2Width, ip2Height ];

    for( int y = 150; y < 200; y++ ) {
        for( int x = 100; x < 150; x++ ) {
            ip2Pix[ ( y * ip2Width + x ) * ip2.depth() ] += 1;//ip1Pix[ ( y * ip1width + x ) * ip1.depth() ];
            ip2Pix[ ( y * ip2Width + x ) * ip2.depth() + 1 ] += 1;//ip1Pix[ ( y * ip1width + x ) * ip1.depth() + 1 ];
            ip2Pix[ ( y * ip2Width + x ) * ip2.depth() + 2 ] += 1;//ip1Pix[ ( y * ip1width + x ) * ip1.depth() + 2 ];
        }
    }

    MImage img;
    img.create( ip2Width, ip2Height, ip2.depth() );
    img.setPixels( ip2Pix, ip2Width, ip2Height );
    img.writeToFile( "E:/Release/f****d.jpg", "jpg" );

    MFnPlugin plugFn( obj, "The LABS", version );
    MStatus stat = plugFn.registerCommand( "setupRGBShaders", setupRGBShaders::creator );

    if( !stat ) {
        stat.perror( "Registering Command setupRGBShaders" );
        return MS::kFailure;
    }



    return MS::kSuccess;
}
コード例 #2
0
// Post-render callback
//
void refreshCompute::postRenderCB(const MString& panelName, void * data)
{	
	refreshCompute *thisCompute = (refreshCompute *) data;
	if (!thisCompute)
		return;

	// Get the view if any for the panel
	M3dView view;
	MStatus status = M3dView::getM3dViewFromModelPanel(panelName, view);
	if (status != MS::kSuccess)
		return;

	view.popViewport();

	if (thisCompute->mBufferOperation == kDrawDepthBuffer)
	{
		int width = 0, height = 0;
		width = view.portWidth( &status ) / 2 ;
		if (status != MS::kSuccess || (width < 2))
			return;
		height = view.portHeight( &status ) / 2 ;
		if (status != MS::kSuccess || (height < 2))
			return;

		unsigned int numPixels = width * height;

		float *depthPixels = new float[numPixels];
		if (!depthPixels)
			return;

		unsigned char *colorPixels = new unsigned char[numPixels * 4];
		if (!colorPixels)
		{
			delete depthPixels;
			delete colorPixels;
		}

		// Read into a float buffer
		status = view.readDepthMap( 0,0, width, height, (unsigned char *)depthPixels, M3dView::kDepth_Float );

		if (status != MS::kSuccess)
		{
			delete depthPixels;
			delete colorPixels;
			return;
		}

		// Find depth range and remap normalized depth range (-1 to 1) into 0...255
		// for color.
		float *dPtr = depthPixels;
		unsigned int i = 0;

		float zmin = 100.0f; // *dPtr;
		float zmax = -100.0f; // *dPtr;
		for(i=0; i<numPixels; i++)
		{
			float val = *dPtr; // * 2.0f - 1.0f;
			if(val < zmin) {
				zmin = *dPtr;
			}
			if(val > zmax) {
				zmax = *dPtr;
			}
			dPtr++;
		}
		float zrange = zmax - zmin;
		//printf("depth values = (%g, %g). Range = %g\n", zmin, zmax, zrange);

		unsigned char *cPtr = colorPixels;

		dPtr = depthPixels;
		for(i=0; i < numPixels; i++)
		{
			float val = *dPtr; // * 2.0f - 1.0f;
			//unsigned char depth = (unsigned char)(255.0f * (( (*dPtr)-zmin) / zrange) + zmin );
			unsigned char depth = (unsigned char)(255.0f * (( (val)-zmin) / zrange) );
			//unsigned char depth = (unsigned char)(255.0f * val);
			*cPtr = depth; cPtr++;
			*cPtr = depth; cPtr++;
			*cPtr = depth; cPtr++;
			*cPtr = 0xff;   
			cPtr++;
			dPtr++;
		}

		MImage image;
		image.setPixels( colorPixels, width, height );

		// Uncomment next line to test writing buffer to file.
		//image.writeToFile( "C:\\temp\\dumpDepth.iff" );

		// Write all pixels back. The origin of the image (lower left)
		// is used 
		status = view.writeColorBuffer( image, 5, 5 );

		if (depthPixels)
			delete depthPixels;
		if (colorPixels)
			delete colorPixels;
	}

	// Do a simple color invert operation on all pixels
	//
	else if (thisCompute->mBufferOperation == kInvertColorBuffer)
	{
		// Optional to read as RGBA. Note that this will be slower
		// since we must swizzle the bytes around from the default
		// BGRA format.
		bool readAsRGBA = true;

		// Read the RGB values from the color buffer
		MImage image;
		status = view.readColorBuffer( image, readAsRGBA );
		if (status != MS::kSuccess)
			return;

		status = view.writeColorBuffer( image, 5, 5 );

		unsigned char *pixelPtr = (unsigned char*)image.pixels();
		if (pixelPtr)
		{
			unsigned int width, height;
			image.getSize( width, height );

			MImage image2;
			image2.create( width, height );
			unsigned char *pixelPtr2 = (unsigned char*)image2.pixels();

			unsigned int numPixels = width * height;
			for (unsigned int i=0; i < numPixels; i++)
			{
				*pixelPtr2 = (255 - *pixelPtr);	
				pixelPtr2++; pixelPtr++;
				*pixelPtr2 = (255 - *pixelPtr);	
				pixelPtr2++; pixelPtr++;
				*pixelPtr2 = (255 - *pixelPtr);	
				pixelPtr2++; pixelPtr++;
				*pixelPtr2 = 255;	
				pixelPtr2++; pixelPtr++;
			}

			// Write all pixels back. The origin of the image (lower left)
			// is used 
			status = view.writeColorBuffer( image2, 5, short(5+height/2) );
		}
	}
}