EtcColor.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2015 The Etc2Comp Authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <math.h>
  18. namespace Etc
  19. {
  20. inline float LogToLinear(float a_fLog)
  21. {
  22. static const float ALPHA = 0.055f;
  23. static const float ONE_PLUS_ALPHA = 1.0f + ALPHA;
  24. if (a_fLog <= 0.04045f)
  25. {
  26. return a_fLog / 12.92f;
  27. }
  28. else
  29. {
  30. return powf((a_fLog + ALPHA) / ONE_PLUS_ALPHA, 2.4f);
  31. }
  32. }
  33. inline float LinearToLog(float &a_fLinear)
  34. {
  35. static const float ALPHA = 0.055f;
  36. static const float ONE_PLUS_ALPHA = 1.0f + ALPHA;
  37. if (a_fLinear <= 0.0031308f)
  38. {
  39. return 12.92f * a_fLinear;
  40. }
  41. else
  42. {
  43. return ONE_PLUS_ALPHA * powf(a_fLinear, (1.0f/2.4f)) - ALPHA;
  44. }
  45. }
  46. class ColorR8G8B8A8
  47. {
  48. public:
  49. unsigned char ucR;
  50. unsigned char ucG;
  51. unsigned char ucB;
  52. unsigned char ucA;
  53. };
  54. }