Guest User

Untitled

a guest
Jun 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. /**
  2. * update an image by altering the pixels to become grayscale.
  3. */
  4. void irr::output::CScreenFilter::modifyGrayscale(video::ITexture* image)
  5. {
  6. irr::c8* data;
  7. irr::s32 code;
  8. irr::u32 steps;
  9. IplImage* modify;
  10. IplImage* modified;
  11. core::dimension2di size;
  12.  
  13. // retrieve the size of the image
  14. size = image->getSize();
  15.  
  16. // retrieve the specific code to use for formatting and the number of steps
  17. switch( image->getColorFormat() )
  18. {
  19. default: // unknown
  20. case video::ECF_R8G8B8: steps = 3; code = CV_RGB2GRAY; break; // RGB
  21. case video::ECF_A8R8G8B8: steps = 4; code = CV_RGBA2GRAY; break; // ARGB
  22. }
  23.  
  24. // retrieve the data pointer object for transformation on the image
  25. data = (char*)image->lock();
  26.  
  27. // create the image using openCV
  28. modify = cvCreateImageHeader( cvSize(size.Width, size.Height), IPL_DEPTH_8U, 1 );
  29. modified = cvCreateImageHeader( cvSize(size.Width, size.Height), IPL_DEPTH_8U, 1 );
  30.  
  31. // copy the data from the original texture into the new image object
  32. cvSetData( modify, data, size.Width * steps );
  33.  
  34. // perform the grayscale operation on the data
  35. cvCvtColor( modify, modified, code );
  36.  
  37. // ensure that the data is updated to match the grayscale image
  38. memcpy( data, modified->imageData, modified->imageSize );
  39.  
  40. // destroy the image since it is no longer required
  41. cvReleaseImageHeader( &modify );
  42. cvReleaseImageHeader( &modified );
  43.  
  44. // unlock the image for processing normally by the irrlicht engine
  45. image->unlock();
  46. }
Add Comment
Please, Sign In to add comment