EtcIndividualTrys.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /*
  17. EtcIndividualTrys.cpp
  18. Gathers the results of the various encoding trys for both halves of a 4x4 block for Individual mode
  19. */
  20. #include "EtcConfig.h"
  21. #include "EtcIndividualTrys.h"
  22. #include <assert.h>
  23. namespace Etc
  24. {
  25. // ----------------------------------------------------------------------------------------------------
  26. // construct a list of trys (encoding attempts)
  27. //
  28. // a_frgbaColor1 is the basecolor for the first half
  29. // a_frgbaColor2 is the basecolor for the second half
  30. // a_pauiPixelMapping1 is the pixel order for the first half
  31. // a_pauiPixelMapping2 is the pixel order for the second half
  32. // a_uiRadius is the amount to vary the base colors
  33. //
  34. IndividualTrys::IndividualTrys(ColorFloatRGBA a_frgbaColor1, ColorFloatRGBA a_frgbaColor2,
  35. const unsigned int *a_pauiPixelMapping1,
  36. const unsigned int *a_pauiPixelMapping2,
  37. unsigned int a_uiRadius)
  38. {
  39. assert(a_uiRadius <= MAX_RADIUS);
  40. ColorFloatRGBA frgbaQuantizedColor1 = a_frgbaColor1.QuantizeR4G4B4();
  41. ColorFloatRGBA frgbaQuantizedColor2 = a_frgbaColor2.QuantizeR4G4B4();
  42. // quantize base colors
  43. // ensure that trys with a_uiRadius don't overflow
  44. int iRed1 = MoveAwayFromEdge(frgbaQuantizedColor1.IntRed(15.0f), a_uiRadius);
  45. int iGreen1 = MoveAwayFromEdge(frgbaQuantizedColor1.IntGreen(15.0f), a_uiRadius);
  46. int iBlue1 = MoveAwayFromEdge(frgbaQuantizedColor1.IntBlue(15.0f), a_uiRadius);
  47. int iRed2 = MoveAwayFromEdge(frgbaQuantizedColor2.IntRed(15.0f), a_uiRadius);
  48. int iGreen2 = MoveAwayFromEdge(frgbaQuantizedColor2.IntGreen(15.0f), a_uiRadius);
  49. int iBlue2 = MoveAwayFromEdge(frgbaQuantizedColor2.IntBlue(15.0f), a_uiRadius);
  50. m_half1.Init(iRed1, iGreen1, iBlue1, a_pauiPixelMapping1, a_uiRadius);
  51. m_half2.Init(iRed2, iGreen2, iBlue2, a_pauiPixelMapping2, a_uiRadius);
  52. }
  53. // ----------------------------------------------------------------------------------------------------
  54. //
  55. void IndividualTrys::Half::Init(int a_iRed, int a_iGreen, int a_iBlue,
  56. const unsigned int *a_pauiPixelMapping, unsigned int a_uiRadius)
  57. {
  58. m_iRed = a_iRed;
  59. m_iGreen = a_iGreen;
  60. m_iBlue = a_iBlue;
  61. m_pauiPixelMapping = a_pauiPixelMapping;
  62. m_uiRadius = a_uiRadius;
  63. m_uiTrys = 0;
  64. }
  65. // ----------------------------------------------------------------------------------------------------
  66. //
  67. } // namespace Etc