| Index: cc/resources/texture_compress/atc_dxt.h
|
| diff --git a/cc/resources/texture_compress/atc_dxt.h b/cc/resources/texture_compress/atc_dxt.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ecf181a9eba43dea2d9eb74e8bc2b7fc6f0d9303
|
| --- /dev/null
|
| +++ b/cc/resources/texture_compress/atc_dxt.h
|
| @@ -0,0 +1,122 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CC_RESOURCES_TEXTURE_COMPRESS_ATC_DXT_H_
|
| +#define CC_RESOURCES_TEXTURE_COMPRESS_ATC_DXT_H_
|
| +
|
| +#include <stdint.h>
|
| +
|
| +#include "cc/base/cc_export.h"
|
| +
|
| +#if defined(__GNUC__)
|
| +#define ALWAYS_INLINE inline __attribute__((always_inline))
|
| +#else
|
| +#define ALWAYS_INLINE inline
|
| +#endif
|
| +
|
| +namespace cc {
|
| +namespace texture_compress {
|
| +
|
| +enum Quality {
|
| + kQualityLow,
|
| + kQualityMedium,
|
| + kQualityHigh,
|
| +};
|
| +
|
| +// Types used to explicitly instantiate template functions.
|
| +struct TYPE_ATC {
|
| + static const uint32_t kConstantColorIndices = 0x55555555;
|
| +};
|
| +
|
| +struct TYPE_DXT {
|
| + static const uint32_t kConstantColorIndices = 0xaaaaaaaa;
|
| +};
|
| +
|
| +extern uint8_t g_o_match55[256][2];
|
| +extern uint8_t g_o_match66[256][2];
|
| +extern uint8_t g_o_match56[256][2];
|
| +
|
| +// Returns max and min base colors matching the given single color when solved
|
| +// via linear interpolation. Output format differs for ATC and DXT. See
|
| +// explicitly instantiated template functions below.
|
| +template <typename T>
|
| +inline uint16_t MatchSingleColorMax(int r, int g, int b);
|
| +template <typename T>
|
| +inline uint16_t MatchSingleColorMin(int r, int g, int b);
|
| +
|
| +template <>
|
| +inline uint16_t MatchSingleColorMax<TYPE_ATC>(int r, int g, int b) {
|
| + return (g_o_match55[r][0] << 11) | (g_o_match56[g][0] << 6) |
|
| + g_o_match55[b][0];
|
| +}
|
| +
|
| +template <>
|
| +inline uint16_t MatchSingleColorMin<TYPE_ATC>(int r, int g, int b) {
|
| + return (g_o_match55[r][1] << 11) | (g_o_match56[g][1] << 5) |
|
| + g_o_match55[b][1];
|
| +}
|
| +
|
| +template <>
|
| +inline uint16_t MatchSingleColorMax<TYPE_DXT>(int r, int g, int b) {
|
| + return (g_o_match55[r][0] << 11) | (g_o_match66[g][0] << 5) |
|
| + g_o_match55[b][0];
|
| +}
|
| +
|
| +template <>
|
| +inline uint16_t MatchSingleColorMin<TYPE_DXT>(int r, int g, int b) {
|
| + return (g_o_match55[r][1] << 11) | (g_o_match66[g][1] << 5) |
|
| + g_o_match55[b][1];
|
| +}
|
| +
|
| +// This converts the output data to either ATC or DXT format.
|
| +// See explicitly instantiated template functions below.
|
| +template <typename T>
|
| +inline void FormatFixup_Generic(uint16_t* max16,
|
| + uint16_t* min16,
|
| + uint32_t* mask);
|
| +
|
| +template <>
|
| +inline void FormatFixup_Generic<TYPE_ATC>(uint16_t* max16,
|
| + uint16_t* min16,
|
| + uint32_t* mask) {
|
| + // First color in ATC format is 555.
|
| + *max16 = (*max16 & 0x001f) | ((*max16 & 0xffC0) >> 1);
|
| +}
|
| +
|
| +template <>
|
| +inline void FormatFixup_Generic<TYPE_DXT>(uint16_t* max16,
|
| + uint16_t* min16,
|
| + uint32_t* mask) {
|
| + // Swap min/max colors if necessary.
|
| + if (*max16 < *min16) {
|
| + uint16_t t = *min16;
|
| + *min16 = *max16;
|
| + *max16 = t;
|
| + *mask ^= 0x55555555;
|
| + }
|
| +}
|
| +
|
| +CC_EXPORT void Init_ATC_DXT();
|
| +
|
| +CC_EXPORT void CompressATC_Generic(const uint8_t* src,
|
| + uint8_t* dst,
|
| + int width,
|
| + int height);
|
| +CC_EXPORT void CompressATCIA_Generic(const uint8_t* src,
|
| + uint8_t* dst,
|
| + int width,
|
| + int height);
|
| +CC_EXPORT void CompressDXT1_Generic(const uint8_t* src,
|
| + uint8_t* dst,
|
| + int width,
|
| + int height);
|
| +CC_EXPORT void CompressDXT5_Generic(const uint8_t* src,
|
| + uint8_t* dst,
|
| + int width,
|
| + int height);
|
| +
|
| +} // namespace texture_compress
|
| +} // namespace cc
|
| +
|
| +#endif // CC_RESOURCES_TEXTURE_COMPRESS_ATC_DXT_H_
|
|
|