code_junkie

Multithreaded image processing in C++

Nov 12th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #pragma omp parallel for
  2. for (i=0; i < numPixels; i++)
  3. {
  4. pGrayScaleBitmap[i] = (unsigned BYTE)
  5. (pRGBBitmap[i].red * 0.299 +
  6. pRGBBitmap[i].green * 0.587 +
  7. pRGBBitmap[i].blue * 0.114);
  8. }
  9.  
  10. * pthread_create, pthread_detach.
  11. * pthread_mutexattr_init, pthread_mutexattr_settype, pthread_mutex_init,
  12. * pthread_mutexattr_destroy, pthread_mutex_destroy, pthread_mutex_lock,
  13. * pthread_mutex_trylock, pthread_mutex_unlock, pthread_mutex_timedlock.
  14. * sem_init, sem_destroy, sem_post, sem_wait, sem_trywait, sem_timedwait.
  15.  
  16. /*ThreadA:*/ while(1){ mutex.lock(); printf("an"); usleep(100000); mutex.unlock(); }
  17. /*ThreadB:*/ while(1){ mutex.lock(); printf("bn"); usleep(100000); mutex.unlock(); }
  18.  
  19. #pragma omp parallel for
  20. for (i=0; i < numPixels; i++)
  21. { ...}
  22.  
  23. parallel_for(0,numPixels,1,ToGrayScale());
  24.  
  25. parallel_for(0,numPixels,1,[&](int i)
  26. {
  27. pGrayScaleBitmap[i] = (unsigned BYTE)
  28. (pRGBBitmap[i].red * 0.299 +
  29. pRGBBitmap[i].green * 0.587 +
  30. pRGBBitmap[i].blue * 0.114);
  31. });
Add Comment
Please, Sign In to add comment