Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * update an image by altering the pixels to become grayscale.
- */
- void irr::output::CScreenFilter::modifyGrayscale(video::ITexture* image)
- {
- irr::c8* data;
- irr::s32 code;
- irr::u32 steps;
- IplImage* modify;
- IplImage* modified;
- core::dimension2di size;
- // retrieve the size of the image
- size = image->getSize();
- // retrieve the specific code to use for formatting and the number of steps
- switch( image->getColorFormat() )
- {
- default: // unknown
- case video::ECF_R8G8B8: steps = 3; code = CV_RGB2GRAY; break; // RGB
- case video::ECF_A8R8G8B8: steps = 4; code = CV_RGBA2GRAY; break; // ARGB
- }
- // retrieve the data pointer object for transformation on the image
- data = (char*)image->lock();
- // create the image using openCV
- modify = cvCreateImageHeader( cvSize(size.Width, size.Height), IPL_DEPTH_8U, 1 );
- modified = cvCreateImageHeader( cvSize(size.Width, size.Height), IPL_DEPTH_8U, 1 );
- // copy the data from the original texture into the new image object
- cvSetData( modify, data, size.Width * steps );
- // perform the grayscale operation on the data
- cvCvtColor( modify, modified, code );
- // ensure that the data is updated to match the grayscale image
- memcpy( data, modified->imageData, modified->imageSize );
- // destroy the image since it is no longer required
- cvReleaseImageHeader( &modify );
- cvReleaseImageHeader( &modified );
- // unlock the image for processing normally by the irrlicht engine
- image->unlock();
- }
Add Comment
Please, Sign In to add comment