krajcevski | ae61440 | 2014-06-10 14:52:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkTextureCompressor_DEFINED |
| 9 | #define SkTextureCompressor_DEFINED |
| 10 | |
krajcevski | eecc35f | 2014-06-20 11:43:00 -0700 | [diff] [blame] | 11 | #include "SkImageInfo.h" |
| 12 | |
krajcevski | ae61440 | 2014-06-10 14:52:28 -0700 | [diff] [blame] | 13 | class SkBitmap; |
| 14 | class SkData; |
| 15 | |
| 16 | namespace SkTextureCompressor { |
| 17 | // Various texture compression formats that we support. |
| 18 | enum Format { |
krajcevski | f3d15dc | 2014-06-30 08:47:33 -0700 | [diff] [blame] | 19 | // Alpha only formats. |
krajcevski | ae61440 | 2014-06-10 14:52:28 -0700 | [diff] [blame] | 20 | kLATC_Format, |
krajcevski | f3d15dc | 2014-06-30 08:47:33 -0700 | [diff] [blame] | 21 | kR11_EAC_Format, |
krajcevski | ae61440 | 2014-06-10 14:52:28 -0700 | [diff] [blame] | 22 | |
krajcevski | f3d15dc | 2014-06-30 08:47:33 -0700 | [diff] [blame] | 23 | kLast_Format = kR11_EAC_Format |
krajcevski | ae61440 | 2014-06-10 14:52:28 -0700 | [diff] [blame] | 24 | }; |
| 25 | static const int kFormatCnt = kLast_Format + 1; |
| 26 | |
| 27 | // Returns an SkData holding a blob of compressed data that corresponds |
| 28 | // to the bitmap. If the bitmap colorType cannot be compressed using the |
| 29 | // associated format, then we return NULL. The caller is responsible for |
| 30 | // calling unref() on the returned data. |
| 31 | SkData* CompressBitmapToFormat(const SkBitmap& bitmap, Format format); |
krajcevski | eecc35f | 2014-06-20 11:43:00 -0700 | [diff] [blame] | 32 | |
| 33 | // Compresses the given src data into dst. The src data is assumed to be |
| 34 | // large enough to hold width*height pixels. The dst data is expected to |
| 35 | // be large enough to hold the compressed data according to the format. |
| 36 | bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcColorType, |
krajcevski | 630598c | 2014-07-14 12:00:04 -0700 | [diff] [blame^] | 37 | int width, int height, int rowBytes, Format format, |
| 38 | bool opt = true /* Use optimization if available */); |
| 39 | |
| 40 | // This typedef defines what the nominal aspects of a compression function |
| 41 | // are. The typedef is not meant to be used by clients of the API, but rather |
| 42 | // allows SIMD optimized compression functions to be implemented. |
| 43 | typedef bool (*CompressionProc)(uint8_t* dst, const uint8_t* src, |
| 44 | int width, int height, int rowBytes); |
krajcevski | ae61440 | 2014-06-10 14:52:28 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | #endif |