home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Riza / source / utils.fxh < prev    next >
Encoding:
Text File  |  2009-10-24  |  1.8 KB  |  53 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    A/V interface library
  3. //    Copyright (C) 1998-2008 Avery Lee
  4. //
  5. //    This program is free software; you can redistribute it and/or modify
  6. //    it under the terms of the GNU General Public License as published by
  7. //    the Free Software Foundation; either version 2 of the License, or
  8. //    (at your option) any later version.
  9. //
  10. //    This program is distributed in the hope that it will be useful,
  11. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //    GNU General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU General Public License
  16. //    along with this program; if not, write to the Free Software
  17. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #ifndef UTILS_FXH
  20. #define UTILS_FXH
  21.  
  22. float4 ConvertYCbCrToRGB(float y, float cb, float cr) {
  23.     const float3 kCoeffCr = { 1.596f, -0.813f, 0 };
  24.     const float3 kCoeffCb = { 0, -0.391f, 2.018f };
  25.     const float kCoeffY = 1.164f;
  26.     const float kBiasY = -16.0f / 255.0f;
  27.     const float kBiasC = -128.0f / 255.0f;
  28.  
  29.     float4 result = y * kCoeffY;
  30.     result.rgb += kCoeffCr * cr;
  31.     result.rgb += kCoeffCb * cb;
  32.     result.rgb += kCoeffY * kBiasY + (kCoeffCr + kCoeffCb) * kBiasC;    
  33.     
  34.     return result;
  35. }
  36.  
  37. float4 ConvertYCbCrToRGB_709(float y, float cb, float cr) {
  38.     const float3 kCoeffCr = { 1.793f, -0.533f, 0 };
  39.     const float3 kCoeffCb = { 0, -0.213f, 2.112f };
  40.     const float kCoeffY = 1.164f;
  41.     const float kBiasY = -16.0f / 255.0f;
  42.     const float kBiasC = -128.0f / 255.0f;
  43.  
  44.     float4 result = y * kCoeffY;
  45.     result.rgb += kCoeffCr * cr;
  46.     result.rgb += kCoeffCb * cb;
  47.     result.rgb += kCoeffY * kBiasY + (kCoeffCr + kCoeffCb) * kBiasC;    
  48.     
  49.     return result;
  50. }
  51.  
  52. #endif
  53.