| 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; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 case kASTC_12x12_Format: | 153 case kASTC_12x12_Format: |
| 153 return CreateASTCBlitter(width, height, compressedBuffer); | 154 return CreateASTCBlitter(width, height, compressedBuffer); |
| 154 | 155 |
| 155 default: | 156 default: |
| 156 return NULL; | 157 return NULL; |
| 157 } | 158 } |
| 158 | 159 |
| 159 return NULL; | 160 return NULL; |
| 160 } | 161 } |
| 161 | 162 |
| 163 bool DecompressBufferFromFormat(uint8_t* dst, int dstRowBytes, const uint8_t* sr
c, |
| 164 int width, int height, Format format) { |
| 165 int dimX, dimY; |
| 166 GetBlockDimensions(format, &dimX, &dimY, true); |
| 167 |
| 168 if (width < 0 || ((width % dimX) != 0) || height < 0 || ((height % dimY) !=
0)) { |
| 169 return false; |
| 170 } |
| 171 |
| 172 switch(format) { |
| 173 case kLATC_Format: |
| 174 DecompressLATC(dst, dstRowBytes, src, width, height); |
| 175 return true; |
| 176 |
| 177 case kR11_EAC_Format: |
| 178 DecompressR11EAC(dst, dstRowBytes, src, width, height); |
| 179 return true; |
| 180 |
| 181 case kASTC_12x12_Format: |
| 182 // TODO(krajcevski) .. right now just fall through and return false. |
| 183 return false; |
| 184 } |
| 185 |
| 186 return false; |
| 187 } |
| 188 |
| 162 } // namespace SkTextureCompressor | 189 } // namespace SkTextureCompressor |
| OLD | NEW |