OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_RESOURCES_TEXTURE_COMPRESS_ATC_DXT_H_ |
| 6 #define CC_RESOURCES_TEXTURE_COMPRESS_ATC_DXT_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "cc/base/cc_export.h" |
| 11 |
| 12 #if defined(__GNUC__) |
| 13 #define ALWAYS_INLINE inline __attribute__((always_inline)) |
| 14 #else |
| 15 #define ALWAYS_INLINE inline |
| 16 #endif |
| 17 |
| 18 namespace cc { |
| 19 namespace texture_compress { |
| 20 |
| 21 enum Quality { |
| 22 kQualityLow, |
| 23 kQualityMedium, |
| 24 kQualityHigh, |
| 25 }; |
| 26 |
| 27 // Types used to explicitly instantiate template functions. |
| 28 struct TYPE_ATC { |
| 29 static const uint32_t kConstantColorIndices = 0x55555555; |
| 30 }; |
| 31 |
| 32 struct TYPE_DXT { |
| 33 static const uint32_t kConstantColorIndices = 0xaaaaaaaa; |
| 34 }; |
| 35 |
| 36 extern uint8_t g_o_match55[256][2]; |
| 37 extern uint8_t g_o_match66[256][2]; |
| 38 extern uint8_t g_o_match56[256][2]; |
| 39 |
| 40 // Returns max and min base colors matching the given single color when solved |
| 41 // via linear interpolation. Output format differs for ATC and DXT. See |
| 42 // explicitly instantiated template functions below. |
| 43 template <typename T> |
| 44 inline uint16_t MatchSingleColorMax(int r, int g, int b); |
| 45 template <typename T> |
| 46 inline uint16_t MatchSingleColorMin(int r, int g, int b); |
| 47 |
| 48 template <> |
| 49 inline uint16_t MatchSingleColorMax<TYPE_ATC>(int r, int g, int b) { |
| 50 return (g_o_match55[r][0] << 11) | (g_o_match56[g][0] << 6) | |
| 51 g_o_match55[b][0]; |
| 52 } |
| 53 |
| 54 template <> |
| 55 inline uint16_t MatchSingleColorMin<TYPE_ATC>(int r, int g, int b) { |
| 56 return (g_o_match55[r][1] << 11) | (g_o_match56[g][1] << 5) | |
| 57 g_o_match55[b][1]; |
| 58 } |
| 59 |
| 60 template <> |
| 61 inline uint16_t MatchSingleColorMax<TYPE_DXT>(int r, int g, int b) { |
| 62 return (g_o_match55[r][0] << 11) | (g_o_match66[g][0] << 5) | |
| 63 g_o_match55[b][0]; |
| 64 } |
| 65 |
| 66 template <> |
| 67 inline uint16_t MatchSingleColorMin<TYPE_DXT>(int r, int g, int b) { |
| 68 return (g_o_match55[r][1] << 11) | (g_o_match66[g][1] << 5) | |
| 69 g_o_match55[b][1]; |
| 70 } |
| 71 |
| 72 // This converts the output data to either ATC or DXT format. |
| 73 // See explicitly instantiated template functions below. |
| 74 template <typename T> |
| 75 inline void FormatFixup_Generic(uint16_t* max16, |
| 76 uint16_t* min16, |
| 77 uint32_t* mask); |
| 78 |
| 79 template <> |
| 80 inline void FormatFixup_Generic<TYPE_ATC>(uint16_t* max16, |
| 81 uint16_t* min16, |
| 82 uint32_t* mask) { |
| 83 // First color in ATC format is 555. |
| 84 *max16 = (*max16 & 0x001f) | ((*max16 & 0xffC0) >> 1); |
| 85 } |
| 86 |
| 87 template <> |
| 88 inline void FormatFixup_Generic<TYPE_DXT>(uint16_t* max16, |
| 89 uint16_t* min16, |
| 90 uint32_t* mask) { |
| 91 // Swap min/max colors if necessary. |
| 92 if (*max16 < *min16) { |
| 93 uint16_t t = *min16; |
| 94 *min16 = *max16; |
| 95 *max16 = t; |
| 96 *mask ^= 0x55555555; |
| 97 } |
| 98 } |
| 99 |
| 100 CC_EXPORT void Init_ATC_DXT(); |
| 101 |
| 102 CC_EXPORT void CompressATC_Generic(const uint8_t* src, |
| 103 uint8_t* dst, |
| 104 int width, |
| 105 int height); |
| 106 CC_EXPORT void CompressATCIA_Generic(const uint8_t* src, |
| 107 uint8_t* dst, |
| 108 int width, |
| 109 int height); |
| 110 CC_EXPORT void CompressDXT1_Generic(const uint8_t* src, |
| 111 uint8_t* dst, |
| 112 int width, |
| 113 int height); |
| 114 CC_EXPORT void CompressDXT5_Generic(const uint8_t* src, |
| 115 uint8_t* dst, |
| 116 int width, |
| 117 int height); |
| 118 |
| 119 } // namespace texture_compress |
| 120 } // namespace cc |
| 121 |
| 122 #endif // CC_RESOURCES_TEXTURE_COMPRESS_ATC_DXT_H_ |
OLD | NEW |