| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkTextureCompressor_ASTC.h" | 8 #include "SkTextureCompressor_ASTC.h" |
| 9 #include "SkTextureCompressor_Blitter.h" | 9 #include "SkTextureCompressor_Blitter.h" |
| 10 | 10 |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 while (nVals > 0) { | 786 while (nVals > 0) { |
| 787 | 787 |
| 788 if (nTrits > 0) { | 788 if (nTrits > 0) { |
| 789 SkASSERT(0 == nQuints); | 789 SkASSERT(0 == nQuints); |
| 790 | 790 |
| 791 int endBlockBit = startBit + 8 + 5*nBits; | 791 int endBlockBit = startBit + 8 + 5*nBits; |
| 792 if (endBlockBit > endBit) { | 792 if (endBlockBit > endBit) { |
| 793 endBlockBit = endBit; | 793 endBlockBit = endBit; |
| 794 } | 794 } |
| 795 | 795 |
| 796 decode_trit_block(dst, nBits, read_astc_bits(src, startBit, endBlock
Bit)); | 796 // Trit blocks are three values large. |
| 797 int trits[5]; |
| 798 decode_trit_block(trits, nBits, read_astc_bits(src, startBit, endBlo
ckBit)); |
| 799 memcpy(dst, trits, SkMin32(nVals, 5)*sizeof(int)); |
| 800 |
| 797 dst += 5; | 801 dst += 5; |
| 798 nVals -= 5; | 802 nVals -= 5; |
| 799 startBit = endBlockBit; | 803 startBit = endBlockBit; |
| 800 | 804 |
| 801 } else if (nQuints > 0) { | 805 } else if (nQuints > 0) { |
| 802 SkASSERT(0 == nTrits); | 806 SkASSERT(0 == nTrits); |
| 803 | 807 |
| 804 int endBlockBit = startBit + 7 + 3*nBits; | 808 int endBlockBit = startBit + 7 + 3*nBits; |
| 805 if (endBlockBit > endBit) { | 809 if (endBlockBit > endBit) { |
| 806 endBlockBit = endBit; | 810 endBlockBit = endBit; |
| 807 } | 811 } |
| 808 | 812 |
| 809 decode_quint_block(dst, nBits, read_astc_bits(src, startBit, endBloc
kBit)); | 813 // Quint blocks are three values large |
| 814 int quints[3]; |
| 815 decode_quint_block(quints, nBits, read_astc_bits(src, startBit, endB
lockBit)); |
| 816 memcpy(dst, quints, SkMin32(nVals, 3)*sizeof(int)); |
| 817 |
| 810 dst += 3; | 818 dst += 3; |
| 811 nVals -= 3; | 819 nVals -= 3; |
| 812 startBit = endBlockBit; | 820 startBit = endBlockBit; |
| 813 | 821 |
| 814 } else { | 822 } else { |
| 815 // Just read the bits, but don't read more than we have... | 823 // Just read the bits, but don't read more than we have... |
| 816 int endValBit = startBit + nBits; | 824 int endValBit = startBit + nBits; |
| 817 if (endValBit > endBit) { | 825 if (endValBit > endBit) { |
| 818 endValBit = endBit; | 826 endValBit = endBit; |
| 819 } | 827 } |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 break; | 1709 break; |
| 1702 | 1710 |
| 1703 default: | 1711 default: |
| 1704 SkDEBUGFAIL("Internal ASTC decoding error."); | 1712 SkDEBUGFAIL("Internal ASTC decoding error."); |
| 1705 break; | 1713 break; |
| 1706 } | 1714 } |
| 1707 | 1715 |
| 1708 // The rest of the CEM config will be between the dual plane bit selecto
r | 1716 // The rest of the CEM config will be between the dual plane bit selecto
r |
| 1709 // and the texel weight grid. | 1717 // and the texel weight grid. |
| 1710 const int lowCEM = static_cast<int>(read_astc_bits(fBlock, 23, 29)); | 1718 const int lowCEM = static_cast<int>(read_astc_bits(fBlock, 23, 29)); |
| 1711 SkASSERT(lastWeight - dualPlaneBitLoc > 31); | 1719 SkASSERT(lastWeight >= dualPlaneBitLoc); |
| 1720 SkASSERT(lastWeight - dualPlaneBitLoc < 31); |
| 1712 int fullCEM = static_cast<int>(read_astc_bits(fBlock, dualPlaneBitLoc, l
astWeight)); | 1721 int fullCEM = static_cast<int>(read_astc_bits(fBlock, dualPlaneBitLoc, l
astWeight)); |
| 1713 | 1722 |
| 1714 // Attach the config at the end of the weight grid to the CEM values | 1723 // Attach the config at the end of the weight grid to the CEM values |
| 1715 // in the beginning of the block. | 1724 // in the beginning of the block. |
| 1716 fullCEM = (fullCEM << 6) | lowCEM; | 1725 fullCEM = (fullCEM << 6) | lowCEM; |
| 1717 | 1726 |
| 1718 // Ignore the two least significant bits, since those are our baseCEM ab
ove. | 1727 // Ignore the two least significant bits, since those are our baseCEM ab
ove. |
| 1719 fullCEM = fullCEM >> 2; | 1728 fullCEM = fullCEM >> 2; |
| 1720 | 1729 |
| 1721 int C[kMaxPartitions]; // Next, decode C and M from the spec (Table C.2.
12) | 1730 int C[kMaxPartitions]; // Next, decode C and M from the spec (Table C.2.
12) |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2032 read_astc_block(&data, src); | 2041 read_astc_block(&data, src); |
| 2033 decompress_astc_block(reinterpret_cast<uint8_t*>(colorPtr + x), dstR
owBytes, data); | 2042 decompress_astc_block(reinterpret_cast<uint8_t*>(colorPtr + x), dstR
owBytes, data); |
| 2034 | 2043 |
| 2035 // ASTC encoded blocks are 16 bytes (128 bits) large. | 2044 // ASTC encoded blocks are 16 bytes (128 bits) large. |
| 2036 src += 16; | 2045 src += 16; |
| 2037 } | 2046 } |
| 2038 } | 2047 } |
| 2039 } | 2048 } |
| 2040 | 2049 |
| 2041 } // SkTextureCompressor | 2050 } // SkTextureCompressor |
| OLD | NEW |