ConvectionKernels_BCCommon.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. #ifndef __CVTT_BCCOMMON_H__
  3. #define __CVTT_BCCOMMON_H__
  4. #include "ConvectionKernels_AggregatedError.h"
  5. #include "ConvectionKernels_ParallelMath.h"
  6. namespace cvtt
  7. {
  8. namespace Internal
  9. {
  10. class BCCommon
  11. {
  12. public:
  13. typedef ParallelMath::Float MFloat;
  14. typedef ParallelMath::UInt16 MUInt16;
  15. typedef ParallelMath::UInt15 MUInt15;
  16. typedef ParallelMath::AInt16 MAInt16;
  17. typedef ParallelMath::SInt16 MSInt16;
  18. typedef ParallelMath::SInt32 MSInt32;
  19. static int TweakRoundsForRange(int range);
  20. template<int TVectorSize>
  21. static void ComputeErrorLDR(uint32_t flags, const MUInt15 reconstructed[TVectorSize], const MUInt15 original[TVectorSize], int numRealChannels, AggregatedError<TVectorSize> &aggError)
  22. {
  23. for (int ch = 0; ch < numRealChannels; ch++)
  24. aggError.Add(ParallelMath::SqDiffUInt8(reconstructed[ch], original[ch]), ch);
  25. }
  26. template<int TVectorSize>
  27. static void ComputeErrorLDR(uint32_t flags, const MUInt15 reconstructed[TVectorSize], const MUInt15 original[TVectorSize], AggregatedError<TVectorSize> &aggError)
  28. {
  29. ComputeErrorLDR<TVectorSize>(flags, reconstructed, original, TVectorSize, aggError);
  30. }
  31. template<int TVectorSize>
  32. static MFloat ComputeErrorLDRSimple(uint32_t flags, const MUInt15 reconstructed[TVectorSize], const MUInt15 original[TVectorSize], int numRealChannels, const float *channelWeightsSq)
  33. {
  34. AggregatedError<TVectorSize> aggError;
  35. ComputeErrorLDR<TVectorSize>(flags, reconstructed, original, numRealChannels, aggError);
  36. return aggError.Finalize(flags, channelWeightsSq);
  37. }
  38. template<int TVectorSize>
  39. static MFloat ComputeErrorHDRFast(uint32_t flags, const MSInt16 reconstructed[TVectorSize], const MSInt16 original[TVectorSize], const float channelWeightsSq[TVectorSize])
  40. {
  41. MFloat error = ParallelMath::MakeFloatZero();
  42. if (flags & Flags::Uniform)
  43. {
  44. for (int ch = 0; ch < TVectorSize; ch++)
  45. error = error + ParallelMath::SqDiffSInt16(reconstructed[ch], original[ch]);
  46. }
  47. else
  48. {
  49. for (int ch = 0; ch < TVectorSize; ch++)
  50. error = error + ParallelMath::SqDiffSInt16(reconstructed[ch], original[ch]) * ParallelMath::MakeFloat(channelWeightsSq[ch]);
  51. }
  52. return error;
  53. }
  54. template<int TVectorSize>
  55. static MFloat ComputeErrorHDRSlow(uint32_t flags, const MSInt16 reconstructed[TVectorSize], const MSInt16 original[TVectorSize], const float channelWeightsSq[TVectorSize])
  56. {
  57. MFloat error = ParallelMath::MakeFloatZero();
  58. if (flags & Flags::Uniform)
  59. {
  60. for (int ch = 0; ch < TVectorSize; ch++)
  61. error = error + ParallelMath::SqDiff2CL(reconstructed[ch], original[ch]);
  62. }
  63. else
  64. {
  65. for (int ch = 0; ch < TVectorSize; ch++)
  66. error = error + ParallelMath::SqDiff2CL(reconstructed[ch], original[ch]) * ParallelMath::MakeFloat(channelWeightsSq[ch]);
  67. }
  68. return error;
  69. }
  70. template<int TChannelCount>
  71. static void PreWeightPixelsLDR(MFloat preWeightedPixels[16][TChannelCount], const MUInt15 pixels[16][TChannelCount], const float channelWeights[TChannelCount])
  72. {
  73. for (int px = 0; px < 16; px++)
  74. {
  75. for (int ch = 0; ch < TChannelCount; ch++)
  76. preWeightedPixels[px][ch] = ParallelMath::ToFloat(pixels[px][ch]) * channelWeights[ch];
  77. }
  78. }
  79. template<int TChannelCount>
  80. static void PreWeightPixelsHDR(MFloat preWeightedPixels[16][TChannelCount], const MSInt16 pixels[16][TChannelCount], const float channelWeights[TChannelCount])
  81. {
  82. for (int px = 0; px < 16; px++)
  83. {
  84. for (int ch = 0; ch < TChannelCount; ch++)
  85. preWeightedPixels[px][ch] = ParallelMath::ToFloat(pixels[px][ch]) * channelWeights[ch];
  86. }
  87. }
  88. };
  89. }
  90. }
  91. #endif