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.h" | 8 #include "SkTextureCompressor.h" |
| 9 #include "SkTextureCompressor_ASTC.h" |
| 10 #include "SkTextureCompressor_LATC.h" |
9 #include "SkTextureCompressor_R11EAC.h" | 11 #include "SkTextureCompressor_R11EAC.h" |
10 #include "SkTextureCompressor_LATC.h" | |
11 | 12 |
12 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
13 #include "SkData.h" | 14 #include "SkData.h" |
14 #include "SkEndian.h" | 15 #include "SkEndian.h" |
15 | 16 |
16 #include "SkTextureCompression_opts.h" | 17 #include "SkTextureCompression_opts.h" |
17 | 18 |
18 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
19 | 20 |
20 namespace SkTextureCompressor { | 21 namespace SkTextureCompressor { |
21 | 22 |
22 int GetCompressedDataSize(Format fmt, int width, int height) { | 23 int GetCompressedDataSize(Format fmt, int width, int height) { |
| 24 int blockDimension = 0; |
| 25 int encodedBlockSize = 0; |
| 26 |
23 switch (fmt) { | 27 switch (fmt) { |
24 // These formats are 64 bits per 4x4 block. | 28 // These formats are 64 bits per 4x4 block. |
25 case kR11_EAC_Format: | 29 case kR11_EAC_Format: |
26 case kLATC_Format: | 30 case kLATC_Format: |
27 { | 31 blockDimension = 4; |
28 static const int kBlockDimension = 4; | 32 encodedBlockSize = 8; |
29 static const int kEncodedBlockSize = 8; | 33 break; |
30 | 34 |
31 if(((width % kBlockDimension) == 0) && ((height % kBlockDimension) =
= 0)) { | 35 // This format is 12x12 blocks to 128 bits. |
32 | 36 case kASTC_12x12_Format: |
33 const int blocksX = width / kBlockDimension; | 37 blockDimension = 12; |
34 const int blocksY = height / kBlockDimension; | 38 encodedBlockSize = 16; |
35 | 39 break; |
36 return blocksX * blocksY * kEncodedBlockSize; | |
37 } | |
38 | |
39 return -1; | |
40 } | |
41 | 40 |
42 default: | 41 default: |
43 SkFAIL("Unknown compressed format!"); | 42 SkFAIL("Unknown compressed format!"); |
44 return -1; | 43 return -1; |
45 } | 44 } |
| 45 |
| 46 if(((width % blockDimension) == 0) && ((height % blockDimension) == 0)) { |
| 47 const int blocksX = width / blockDimension; |
| 48 const int blocksY = height / blockDimension; |
| 49 |
| 50 return blocksX * blocksY * encodedBlockSize; |
| 51 } |
| 52 |
| 53 return -1; |
46 } | 54 } |
47 | 55 |
48 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol
orType, | 56 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol
orType, |
49 int width, int height, int rowBytes, Format format,
bool opt) { | 57 int width, int height, int rowBytes, Format format,
bool opt) { |
50 CompressionProc proc = NULL; | 58 CompressionProc proc = NULL; |
51 if (opt) { | 59 if (opt) { |
52 proc = SkTextureCompressorGetPlatformProc(srcColorType, format); | 60 proc = SkTextureCompressorGetPlatformProc(srcColorType, format); |
53 } | 61 } |
54 | 62 |
55 if (NULL == proc) { | 63 if (NULL == proc) { |
56 switch (srcColorType) { | 64 switch (srcColorType) { |
57 case kAlpha_8_SkColorType: | 65 case kAlpha_8_SkColorType: |
58 { | 66 { |
59 switch (format) { | 67 switch (format) { |
60 case kLATC_Format: | 68 case kLATC_Format: |
61 proc = CompressA8ToLATC; | 69 proc = CompressA8ToLATC; |
62 break; | 70 break; |
63 case kR11_EAC_Format: | 71 case kR11_EAC_Format: |
64 proc = CompressA8ToR11EAC; | 72 proc = CompressA8ToR11EAC; |
65 break; | 73 break; |
| 74 case kASTC_12x12_Format: |
| 75 proc = CompressA8To12x12ASTC; |
| 76 break; |
66 default: | 77 default: |
67 // Do nothing... | 78 // Do nothing... |
68 break; | 79 break; |
69 } | 80 } |
70 } | 81 } |
71 break; | 82 break; |
72 | 83 |
73 default: | 84 default: |
74 // Do nothing... | 85 // Do nothing... |
75 break; | 86 break; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return CreateR11EACBlitter(width, height, compressedBuffer); | 123 return CreateR11EACBlitter(width, height, compressedBuffer); |
113 | 124 |
114 default: | 125 default: |
115 return NULL; | 126 return NULL; |
116 } | 127 } |
117 | 128 |
118 return NULL; | 129 return NULL; |
119 } | 130 } |
120 | 131 |
121 } // namespace SkTextureCompressor | 132 } // namespace SkTextureCompressor |
OLD | NEW |