summaryrefslogtreecommitdiff
path: root/src/static_libs/rg_etc/rg_etc1.h
diff options
context:
space:
mode:
authorRich Geldreich <richgel99@gmail.com>2014-02-07 16:48:08 +0900
committerCedric BAIL <cedric.bail@free.fr>2014-04-01 22:00:13 +0900
commit03b29127f1bf27ab38147308c5615c35c4ee5b65 (patch)
treebc8b2e19c8fdee830ae5cbdca8b97c066216a433 /src/static_libs/rg_etc/rg_etc1.h
parent9f5ea9cdae92128e586f49778ce99db7a7214689 (diff)
rg_etc: add original code from rg-etc1 project.
Code come from https://code.google.com/p/rg-etc1/ and is under Zlib license. The content of this directory will remain under that said license.
Diffstat (limited to 'src/static_libs/rg_etc/rg_etc1.h')
-rw-r--r--src/static_libs/rg_etc/rg_etc1.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/static_libs/rg_etc/rg_etc1.h b/src/static_libs/rg_etc/rg_etc1.h
new file mode 100644
index 0000000000..9a701506fd
--- /dev/null
+++ b/src/static_libs/rg_etc/rg_etc1.h
@@ -0,0 +1,76 @@
1// File: rg_etc1.h - Fast, high quality ETC1 block packer/unpacker - Rich Geldreich <richgel99@gmail.com>
2// Please see ZLIB license at the end of this file.
3#pragma once
4
5namespace rg_etc1
6{
7 // Unpacks an 8-byte ETC1 compressed block to a block of 4x4 32bpp RGBA pixels.
8 // Returns false if the block is invalid. Invalid blocks will still be unpacked with clamping.
9 // This function is thread safe, and does not dynamically allocate any memory.
10 // If preserve_alpha is true, the alpha channel of the destination pixels will not be overwritten. Otherwise, alpha will be set to 255.
11 bool unpack_etc1_block(const void *pETC1_block, unsigned int* pDst_pixels_rgba, bool preserve_alpha = false);
12
13 // Quality setting = the higher the quality, the slower.
14 // To pack large textures, it is highly recommended to call pack_etc1_block() in parallel, on different blocks, from multiple threads (particularly when using cHighQuality).
15 enum etc1_quality
16 {
17 cLowQuality,
18 cMediumQuality,
19 cHighQuality,
20 };
21
22 struct etc1_pack_params
23 {
24 etc1_quality m_quality;
25 bool m_dithering;
26
27 inline etc1_pack_params()
28 {
29 clear();
30 }
31
32 void clear()
33 {
34 m_quality = cHighQuality;
35 m_dithering = false;
36 }
37 };
38
39 // Important: pack_etc1_block_init() must be called before calling pack_etc1_block().
40 void pack_etc1_block_init();
41
42 // Packs a 4x4 block of 32bpp RGBA pixels to an 8-byte ETC1 block.
43 // 32-bit RGBA pixels must always be arranged as (R,G,B,A) (R first, A last) in memory, independent of platform endianness. A should always be 255.
44 // Returns squared error of result.
45 // This function is thread safe, and does not dynamically allocate any memory.
46 // pack_etc1_block() does not currently support "perceptual" colorspace metrics - it primarily optimizes for RGB RMSE.
47 unsigned int pack_etc1_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, etc1_pack_params& pack_params);
48
49} // namespace rg_etc1
50
51//------------------------------------------------------------------------------
52//
53// rg_etc1 uses the ZLIB license:
54// http://opensource.org/licenses/Zlib
55//
56// Copyright (c) 2012 Rich Geldreich
57//
58// This software is provided 'as-is', without any express or implied
59// warranty. In no event will the authors be held liable for any damages
60// arising from the use of this software.
61//
62// Permission is granted to anyone to use this software for any purpose,
63// including commercial applications, and to alter it and redistribute it
64// freely, subject to the following restrictions:
65//
66// 1. The origin of this software must not be misrepresented; you must not
67// claim that you wrote the original software. If you use this software
68// in a product, an acknowledgment in the product documentation would be
69// appreciated but is not required.
70//
71// 2. Altered source versions must be plainly marked as such, and must not be
72// misrepresented as being the original software.
73//
74// 3. This notice may not be removed or altered from any source distribution.
75//
76//------------------------------------------------------------------------------