EtcSortedBlockList.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. namespace Etc
  18. {
  19. class Block4x4;
  20. class SortedBlockList
  21. {
  22. public:
  23. class Link
  24. {
  25. public:
  26. inline void Init(Block4x4 *a_pblock)
  27. {
  28. m_pblock = a_pblock;
  29. m_plinkNext = nullptr;
  30. }
  31. inline Block4x4 * GetBlock(void)
  32. {
  33. return m_pblock;
  34. }
  35. inline void SetNext(Link *a_plinkNext)
  36. {
  37. m_plinkNext = a_plinkNext;
  38. }
  39. inline Link * GetNext(void)
  40. {
  41. return m_plinkNext;
  42. }
  43. inline Link * Advance(unsigned int a_uiSteps = 1)
  44. {
  45. Link *plink = this;
  46. for (unsigned int uiStep = 0; uiStep < a_uiSteps; uiStep++)
  47. {
  48. if (plink == nullptr)
  49. {
  50. break;
  51. }
  52. plink = plink->m_plinkNext;
  53. }
  54. return plink;
  55. }
  56. private:
  57. Block4x4 *m_pblock;
  58. Link *m_plinkNext;
  59. };
  60. SortedBlockList(unsigned int a_uiImageBlocks, unsigned int a_uiBuckets);
  61. ~SortedBlockList(void);
  62. void AddBlock(Block4x4 *a_pblock);
  63. void Sort(void);
  64. inline Link * GetLinkToFirstBlock(void)
  65. {
  66. return m_plinkFirst;
  67. }
  68. inline unsigned int GetNumberOfAddedBlocks(void)
  69. {
  70. return m_uiAddedBlocks;
  71. }
  72. inline unsigned int GetNumberOfSortedBlocks(void)
  73. {
  74. return m_uiSortedBlocks;
  75. }
  76. void Print(void);
  77. private:
  78. void InitBuckets(void);
  79. class Bucket
  80. {
  81. public:
  82. Link *plinkFirst;
  83. Link *plinkLast;
  84. };
  85. unsigned int m_uiImageBlocks;
  86. int m_iBuckets;
  87. unsigned int m_uiAddedBlocks;
  88. unsigned int m_uiSortedBlocks;
  89. Link *m_palinkPool;
  90. Bucket *m_pabucket;
  91. float m_fMaxError;
  92. Link *m_plinkFirst;
  93. Link *m_plinkLast;
  94. };
  95. } // namespace Etc