blob: a7afe0384b041f196b3bccb4baf1d66e32241d34 [file] [log] [blame]
krajcevskiae614402014-06-10 14:52:28 -07001/*
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
krajcevskieecc35f2014-06-20 11:43:00 -070011#include "SkImageInfo.h"
krajcevskiad1df152014-07-21 11:44:37 -070012#include "SkBlitter.h"
krajcevskieecc35f2014-06-20 11:43:00 -070013
krajcevskiae614402014-06-10 14:52:28 -070014class SkBitmap;
15class SkData;
16
17namespace SkTextureCompressor {
18 // Various texture compression formats that we support.
19 enum Format {
krajcevskif3d15dc2014-06-30 08:47:33 -070020 // Alpha only formats.
krajcevski6c354882014-07-22 07:44:00 -070021 kLATC_Format, // 4x4 blocks, compresses A8
22 kR11_EAC_Format, // 4x4 blocks, compresses A8
krajcevskiae614402014-06-10 14:52:28 -070023
krajcevskif3d15dc2014-06-30 08:47:33 -070024 kLast_Format = kR11_EAC_Format
krajcevskiae614402014-06-10 14:52:28 -070025 };
26 static const int kFormatCnt = kLast_Format + 1;
27
krajcevski6c354882014-07-22 07:44:00 -070028 // Returns the size of the compressed data given the width, height, and
29 // desired compression format. If the width and height are not an appropriate
30 // multiple of the block size, then this function returns an error (-1).
31 int GetCompressedDataSize(Format fmt, int width, int height);
32
krajcevskiae614402014-06-10 14:52:28 -070033 // Returns an SkData holding a blob of compressed data that corresponds
34 // to the bitmap. If the bitmap colorType cannot be compressed using the
35 // associated format, then we return NULL. The caller is responsible for
36 // calling unref() on the returned data.
37 SkData* CompressBitmapToFormat(const SkBitmap& bitmap, Format format);
krajcevskieecc35f2014-06-20 11:43:00 -070038
39 // Compresses the given src data into dst. The src data is assumed to be
40 // large enough to hold width*height pixels. The dst data is expected to
41 // be large enough to hold the compressed data according to the format.
42 bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcColorType,
krajcevski630598c2014-07-14 12:00:04 -070043 int width, int height, int rowBytes, Format format,
44 bool opt = true /* Use optimization if available */);
45
46 // This typedef defines what the nominal aspects of a compression function
47 // are. The typedef is not meant to be used by clients of the API, but rather
48 // allows SIMD optimized compression functions to be implemented.
49 typedef bool (*CompressionProc)(uint8_t* dst, const uint8_t* src,
50 int width, int height, int rowBytes);
krajcevskiad1df152014-07-21 11:44:37 -070051
krajcevski6c354882014-07-22 07:44:00 -070052 // Returns the blitter for the given compression format. Note, the blitter
53 // is intended to be used with the proper input. I.e. if you try to blit
54 // RGB source data into an R11 EAC texture, you're gonna have a bad time.
55 SkBlitter* CreateBlitterForFormat(int width, int height, void* compressedBuffer,
56 Format format);
krajcevskiae614402014-06-10 14:52:28 -070057}
58
59#endif