| 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 #ifndef SkTextureCompressor_DEFINED |   8 #ifndef SkTextureCompressor_DEFINED | 
|   9 #define SkTextureCompressor_DEFINED |   9 #define SkTextureCompressor_DEFINED | 
|  10  |  10  | 
|  11 #include "SkImageInfo.h" |  11 #include "SkImageInfo.h" | 
|  12 #include "SkBlitter.h" |  12 #include "SkBlitter.h" | 
|  13  |  13  | 
|  14 class SkBitmap; |  14 class SkBitmap; | 
|  15 class SkData; |  15 class SkData; | 
|  16  |  16  | 
|  17 namespace SkTextureCompressor { |  17 namespace SkTextureCompressor { | 
|  18     // Various texture compression formats that we support. |  18     // Various texture compression formats that we support. | 
|  19     enum Format { |  19     enum Format { | 
|  20         // Alpha only formats. |  20         // Alpha only formats. | 
|  21         kLATC_Format,       // 4x4 blocks, compresses A8 |  21         kLATC_Format,       // 4x4 blocks, (de)compresses A8 | 
|  22         kR11_EAC_Format,    // 4x4 blocks, compresses A8 |  22         kR11_EAC_Format,    // 4x4 blocks, (de)compresses A8 | 
|  23         kASTC_12x12_Format, // 12x12 blocks, compresses A8 |  23  | 
 |  24         // RGB only formats | 
 |  25         kETC1_Format,       // 4x4 blocks, compresses RGB 565, decompresses 8-bi
    t RGB | 
 |  26                             //    NOTE: ETC1 supports 8-bit RGB compression, but
     we | 
 |  27                             //    currently don't have any RGB8 SkColorTypes. We
     could | 
 |  28                             //    support 8-bit RGBA but we would have to prepro
    cess the | 
 |  29                             //    bitmap to insert alphas. | 
 |  30  | 
 |  31         // Multi-purpose formats | 
 |  32         kASTC_12x12_Format, // 12x12 blocks, compresses A8, decompresses RGBA | 
|  24  |  33  | 
|  25         kLast_Format = kASTC_12x12_Format |  34         kLast_Format = kASTC_12x12_Format | 
|  26     }; |  35     }; | 
|  27     static const int kFormatCnt = kLast_Format + 1; |  36     static const int kFormatCnt = kLast_Format + 1; | 
|  28  |  37  | 
|  29     // Returns the size of the compressed data given the width, height, and |  38     // Returns the size of the compressed data given the width, height, and | 
|  30     // desired compression format. If the width and height are not an appropriat
    e |  39     // desired compression format. If the width and height are not an appropriat
    e | 
|  31     // multiple of the block size, then this function returns an error (-1). |  40     // multiple of the block size, then this function returns an error (-1). | 
|  32     int GetCompressedDataSize(Format fmt, int width, int height); |  41     int GetCompressedDataSize(Format fmt, int width, int height); | 
|  33  |  42  | 
|  34     // Returns an SkData holding a blob of compressed data that corresponds |  43     // Returns an SkData holding a blob of compressed data that corresponds | 
|  35     // to the bitmap. If the bitmap colorType cannot be compressed using the  |  44     // to the bitmap. If the bitmap colorType cannot be compressed using the  | 
|  36     // associated format, then we return NULL. The caller is responsible for |  45     // associated format, then we return NULL. The caller is responsible for | 
|  37     // calling unref() on the returned data. |  46     // calling unref() on the returned data. | 
|  38     SkData* CompressBitmapToFormat(const SkBitmap& bitmap, Format format); |  47     SkData* CompressBitmapToFormat(const SkBitmap& bitmap, Format format); | 
|  39  |  48  | 
|  40     // Compresses the given src data into dst. The src data is assumed to be |  49     // Compresses the given src data into dst. The src data is assumed to be | 
|  41     // large enough to hold width*height pixels. The dst data is expected to |  50     // large enough to hold width*height pixels. The dst data is expected to | 
|  42     // be large enough to hold the compressed data according to the format. |  51     // be large enough to hold the compressed data according to the format. | 
|  43     bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType sr
    cColorType, |  52     bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType sr
    cColorType, | 
|  44                                 int width, int height, int rowBytes, Format form
    at, |  53                                 int width, int height, int rowBytes, Format form
    at, | 
|  45                                 bool opt = true /* Use optimization if available
     */); |  54                                 bool opt = true /* Use optimization if available
     */); | 
|  46  |  55  | 
|  47     // Decompresses the given src data from the format specified into the |  56     // Decompresses the given src data from the format specified into the | 
|  48     // destination buffer. The width and height of the data passed corresponds |  57     // destination buffer. The width and height of the data passed corresponds | 
|  49     // to the width and height of the uncompressed image. The destination buffer
     (dst) |  58     // to the width and height of the uncompressed image. The destination buffer
     (dst) | 
|  50     // is assumed to be large enough to hold the entire decompressed image. The |  59     // is assumed to be large enough to hold the entire decompressed image. The | 
|  51     // decompressed image colors are determined based on the passed format: |  60     // decompressed image colors are determined based on the passed format. | 
|  52     // |  | 
|  53     // LATC -> Alpha 8 |  | 
|  54     // R11_EAC -> Alpha 8 |  | 
|  55     // ASTC -> RGBA |  | 
|  56     // |  61     // | 
|  57     // Note, CompressBufferToFormat compresses A8 data into ASTC. However, |  62     // Note, CompressBufferToFormat compresses A8 data into ASTC. However, | 
|  58     // general ASTC data encodes RGBA data, so that is what the decompressor |  63     // general ASTC data encodes RGBA data, so that is what the decompressor | 
|  59     // operates on. |  64     // operates on. | 
|  60     // |  65     // | 
|  61     // Returns true if successfully decompresses the src data. |  66     // Returns true if successfully decompresses the src data. | 
|  62     bool DecompressBufferFromFormat(uint8_t* dst, int dstRowBytes, const uint8_t
    * src, |  67     bool DecompressBufferFromFormat(uint8_t* dst, int dstRowBytes, const uint8_t
    * src, | 
|  63                                     int width, int height, Format format); |  68                                     int width, int height, Format format); | 
|  64  |  69  | 
|  65     // This typedef defines what the nominal aspects of a compression function |  70     // This typedef defines what the nominal aspects of a compression function | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  77     // Returns the desired dimensions of the block size for the given format. Th
    ese dimensions |  82     // Returns the desired dimensions of the block size for the given format. Th
    ese dimensions | 
|  78     // don't necessarily correspond to the specification's dimensions, since the
    re may |  83     // don't necessarily correspond to the specification's dimensions, since the
    re may | 
|  79     // be specialized algorithms that operate on multiple blocks at once. If the |  84     // be specialized algorithms that operate on multiple blocks at once. If the | 
|  80     // flag 'matchSpec' is true, then the actual dimensions from the specificati
    on are |  85     // flag 'matchSpec' is true, then the actual dimensions from the specificati
    on are | 
|  81     // returned. If the flag is false, then these dimensions reflect the appropr
    iate operable |  86     // returned. If the flag is false, then these dimensions reflect the appropr
    iate operable | 
|  82     // dimensions of the compression functions. |  87     // dimensions of the compression functions. | 
|  83     void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec 
    = false); |  88     void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec 
    = false); | 
|  84 } |  89 } | 
|  85  |  90  | 
|  86 #endif |  91 #endif | 
| OLD | NEW |