| 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) { |
| 24 if (NULL == dimX || NULL == dimY) { |
| 25 return; |
| 26 } |
| 27 |
| 28 if (SkTextureCompressorGetPlatformDims(format, dimX, dimY)) { |
| 29 return; |
| 30 } |
| 31 |
| 32 switch(format) { |
| 33 // These formats are 64 bits per 4x4 block. |
| 34 default: |
| 35 SkDEBUGFAIL("Unknown compression format!"); |
| 36 // fall through |
| 37 case kR11_EAC_Format: |
| 38 case kLATC_Format: |
| 39 *dimX = 4; |
| 40 *dimY = 4; |
| 41 break; |
| 42 |
| 43 // This format is 12x12 blocks to 128 bits. |
| 44 case kASTC_12x12_Format: |
| 45 *dimX = 12; |
| 46 *dimY = 12; |
| 47 break; |
| 48 } |
| 49 } |
| 50 |
| 23 int GetCompressedDataSize(Format fmt, int width, int height) { | 51 int GetCompressedDataSize(Format fmt, int width, int height) { |
| 24 int blockDimension = 0; | 52 int dimX, dimY; |
| 53 GetBlockDimensions(fmt, &dimX, &dimY); |
| 25 int encodedBlockSize = 0; | 54 int encodedBlockSize = 0; |
| 26 | 55 |
| 27 switch (fmt) { | 56 switch (fmt) { |
| 28 // These formats are 64 bits per 4x4 block. | 57 // These formats are 64 bits per 4x4 block. |
| 29 case kR11_EAC_Format: | 58 case kR11_EAC_Format: |
| 30 case kLATC_Format: | 59 case kLATC_Format: |
| 31 blockDimension = 4; | |
| 32 encodedBlockSize = 8; | 60 encodedBlockSize = 8; |
| 33 break; | 61 break; |
| 34 | 62 |
| 35 // This format is 12x12 blocks to 128 bits. | 63 // This format is 12x12 blocks to 128 bits. |
| 36 case kASTC_12x12_Format: | 64 case kASTC_12x12_Format: |
| 37 blockDimension = 12; | |
| 38 encodedBlockSize = 16; | 65 encodedBlockSize = 16; |
| 39 break; | 66 break; |
| 40 | 67 |
| 41 default: | 68 default: |
| 42 SkFAIL("Unknown compressed format!"); | 69 SkFAIL("Unknown compressed format!"); |
| 43 return -1; | 70 return -1; |
| 44 } | 71 } |
| 45 | 72 |
| 46 if(((width % blockDimension) == 0) && ((height % blockDimension) == 0)) { | 73 if(((width % dimX) == 0) && ((height % dimY) == 0)) { |
| 47 const int blocksX = width / blockDimension; | 74 const int blocksX = width / dimX; |
| 48 const int blocksY = height / blockDimension; | 75 const int blocksY = height / dimY; |
| 49 | 76 |
| 50 return blocksX * blocksY * encodedBlockSize; | 77 return blocksX * blocksY * encodedBlockSize; |
| 51 } | 78 } |
| 52 | 79 |
| 53 return -1; | 80 return -1; |
| 54 } | 81 } |
| 55 | 82 |
| 56 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol
orType, | 83 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol
orType, |
| 57 int width, int height, int rowBytes, Format format,
bool opt) { | 84 int width, int height, int rowBytes, Format format,
bool opt) { |
| 58 CompressionProc proc = NULL; | 85 CompressionProc proc = NULL; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 return CreateR11EACBlitter(width, height, compressedBuffer); | 150 return CreateR11EACBlitter(width, height, compressedBuffer); |
| 124 | 151 |
| 125 default: | 152 default: |
| 126 return NULL; | 153 return NULL; |
| 127 } | 154 } |
| 128 | 155 |
| 129 return NULL; | 156 return NULL; |
| 130 } | 157 } |
| 131 | 158 |
| 132 } // namespace SkTextureCompressor | 159 } // namespace SkTextureCompressor |
| OLD | NEW |