| 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" | 9 #include "SkTextureCompressor_ASTC.h" |
| 10 #include "SkTextureCompressor_LATC.h" | 10 #include "SkTextureCompressor_LATC.h" |
| 11 #include "SkTextureCompressor_R11EAC.h" | 11 #include "SkTextureCompressor_R11EAC.h" |
| 12 | 12 |
| 13 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
| 14 #include "SkData.h" | 14 #include "SkData.h" |
| 15 #include "SkEndian.h" | 15 #include "SkEndian.h" |
| 16 | 16 |
| 17 #include "SkTextureCompression_opts.h" | 17 #include "SkTextureCompression_opts.h" |
| 18 | 18 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
| 21 namespace SkTextureCompressor { | 21 namespace SkTextureCompressor { |
| 22 | 22 |
| 23 void GetBlockDimensions(Format format, int* dimX, int* dimY) { | 23 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { |
| 24 if (NULL == dimX || NULL == dimY) { | 24 if (NULL == dimX || NULL == dimY) { |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 | 27 |
| 28 if (SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { | 28 if (!matchSpec && SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { |
| 29 return; | 29 return; |
| 30 } | 30 } |
| 31 | 31 |
| 32 // No specialized arguments, return the dimensions as they are in the spec. |
| 32 switch(format) { | 33 switch(format) { |
| 33 // These formats are 64 bits per 4x4 block. | 34 // These formats are 64 bits per 4x4 block. |
| 34 default: | 35 default: |
| 35 SkDEBUGFAIL("Unknown compression format!"); | 36 SkDEBUGFAIL("Unknown compression format!"); |
| 36 // fall through | 37 // fall through |
| 37 case kR11_EAC_Format: | 38 case kR11_EAC_Format: |
| 38 case kLATC_Format: | 39 case kLATC_Format: |
| 39 *dimX = 4; | 40 *dimX = 4; |
| 40 *dimY = 4; | 41 *dimY = 4; |
| 41 break; | 42 break; |
| 42 | 43 |
| 43 // This format is 12x12 blocks to 128 bits. | 44 // This format is 12x12 blocks to 128 bits. |
| 44 case kASTC_12x12_Format: | 45 case kASTC_12x12_Format: |
| 45 *dimX = 12; | 46 *dimX = 12; |
| 46 *dimY = 12; | 47 *dimY = 12; |
| 47 break; | 48 break; |
| 48 } | 49 } |
| 49 } | 50 } |
| 50 | 51 |
| 51 int GetCompressedDataSize(Format fmt, int width, int height) { | 52 int GetCompressedDataSize(Format fmt, int width, int height) { |
| 52 int dimX, dimY; | 53 int dimX, dimY; |
| 53 GetBlockDimensions(fmt, &dimX, &dimY); | 54 GetBlockDimensions(fmt, &dimX, &dimY, true); |
| 55 |
| 54 int encodedBlockSize = 0; | 56 int encodedBlockSize = 0; |
| 55 | 57 |
| 56 switch (fmt) { | 58 switch (fmt) { |
| 57 // These formats are 64 bits per 4x4 block. | 59 // These formats are 64 bits per 4x4 block. |
| 58 case kR11_EAC_Format: | 60 case kR11_EAC_Format: |
| 59 case kLATC_Format: | 61 case kLATC_Format: |
| 60 encodedBlockSize = 8; | 62 encodedBlockSize = 8; |
| 61 break; | 63 break; |
| 62 | 64 |
| 63 // This format is 12x12 blocks to 128 bits. | 65 // This format is 12x12 blocks to 128 bits. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 case kASTC_12x12_Format: | 154 case kASTC_12x12_Format: |
| 153 return CreateASTCBlitter(width, height, compressedBuffer); | 155 return CreateASTCBlitter(width, height, compressedBuffer); |
| 154 | 156 |
| 155 default: | 157 default: |
| 156 return NULL; | 158 return NULL; |
| 157 } | 159 } |
| 158 | 160 |
| 159 return NULL; | 161 return NULL; |
| 160 } | 162 } |
| 161 | 163 |
| 164 bool DecompressBufferFromFormat(uint8_t* dst, int dstRowBytes, const uint8_t* sr
c, |
| 165 int width, int height, Format format) { |
| 166 int dimX, dimY; |
| 167 GetBlockDimensions(format, &dimX, &dimY, true); |
| 168 |
| 169 if (width < 0 || ((width % dimX) != 0) || height < 0 || ((height % dimY) !=
0)) { |
| 170 return false; |
| 171 } |
| 172 |
| 173 switch(format) { |
| 174 case kLATC_Format: |
| 175 DecompressLATC(dst, dstRowBytes, src, width, height); |
| 176 return true; |
| 177 |
| 178 case kR11_EAC_Format: |
| 179 DecompressR11EAC(dst, dstRowBytes, src, width, height); |
| 180 return true; |
| 181 |
| 182 case kASTC_12x12_Format: |
| 183 // TODO(krajcevski) .. right now just fall through and return false. |
| 184 return false; |
| 185 } |
| 186 |
| 187 return false; |
| 188 } |
| 189 |
| 162 } // namespace SkTextureCompressor | 190 } // namespace SkTextureCompressor |
| OLD | NEW |