clamp.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /****************************************************************************
  2. *
  3. * Module Title : clamp.c
  4. *
  5. * Description : Image pixel value clamping routines.
  6. *
  7. ***************************************************************************/
  8. /****************************************************************************
  9. * Header Files
  10. ****************************************************************************/
  11. #include "postp.h"
  12. /****************************************************************************
  13. *
  14. * ROUTINE : ClampLevels_C
  15. *
  16. * INPUTS : POSTPROC_INSTANCE *pbi : Pointer to post-processor instance.
  17. * INT32 BlackClamp, : Number of levels to clamp up from 0.
  18. * INT32 WhiteClamp, : Number of levels to clamp down from 255.
  19. * UINT8 *Src, : Pointer to input image to be clamped.
  20. * UINT8 *Dst : Pointer to clamped image.
  21. *
  22. * OUTPUTS : None.
  23. *
  24. * RETURNS : void
  25. *
  26. * FUNCTION : Clamps the pixel values in the input image at each
  27. * end of the 8-bit range.
  28. *
  29. * SPECIAL NOTES : BlackClamp/WhiteClamp are the number.of levels to
  30. * clamp at either end of the range. In particular, it
  31. * should be noted that WhiteClamp is _not_ the level
  32. * to clamp to at the high end of the range.
  33. *
  34. ****************************************************************************/
  35. void ClampLevels_C
  36. (
  37. POSTPROC_INSTANCE *pbi,
  38. INT32 BlackClamp,
  39. INT32 WhiteClamp,
  40. UINT8 *Src,
  41. UINT8 *Dst
  42. )
  43. {
  44. int i;
  45. int row,col;
  46. unsigned char clamped[256];
  47. int width = pbi->HFragments*8;
  48. int height = pbi->VFragments*8;
  49. UINT8 *SrcPtr = Src + pbi->ReconYDataOffset;
  50. UINT8 *DestPtr = Dst + pbi->ReconYDataOffset;
  51. UINT32 LineLength = pbi->YStride;
  52. // set up clamping table so we can avoid ifs while clamping
  53. for ( i=0; i<256; i++ )
  54. {
  55. clamped[i] = i;
  56. if ( i<BlackClamp )
  57. clamped[i] = BlackClamp;
  58. if ( i>(255-WhiteClamp) )
  59. clamped[i] = 255-WhiteClamp;
  60. }
  61. // clamping is for Y only!
  62. for ( row=0 ; row<height; row++ )
  63. {
  64. for ( col=0; col<width; col++ )
  65. SrcPtr[col] = clamped[DestPtr[col]];
  66. SrcPtr += LineLength;
  67. DestPtr += LineLength;
  68. }
  69. }