1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 // File: rg_etc1.h - Fast, high quality ETC1 block packer/unpacker - Rich Geldreich <richgel99@gmail.com>
28 // Please see ZLIB license at the end of this file.
31 #include "vogl_core.h"
38 // Unpacks an 8-byte ETC1 compressed block to a block of 4x4 32bpp RGBA pixels.
39 // Returns false if the block is invalid. Invalid blocks will still be unpacked with clamping.
40 // This function is thread safe, and does not dynamically allocate any memory.
41 // If preserve_alpha is true, the alpha channel of the destination pixels will not be overwritten. Otherwise, alpha will be set to 255.
42 bool unpack_etc1_block(const void *pETC1_block, unsigned int *pDst_pixels_rgba, bool preserve_alpha = false);
44 // Quality setting = the higher the quality, the slower.
45 // 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).
53 struct etc1_pack_params
55 etc1_quality m_quality;
58 inline etc1_pack_params()
65 m_quality = cHighQuality;
70 // Important: pack_etc1_block_init() must be called before calling pack_etc1_block().
71 void pack_etc1_block_init();
73 // Packs a 4x4 block of 32bpp RGBA pixels to an 8-byte ETC1 block.
74 // 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.
75 // Returns squared error of result.
76 // This function is thread safe, and does not dynamically allocate any memory.
77 // pack_etc1_block() does not currently support "perceptual" colorspace metrics - it primarily optimizes for RGB RMSE.
78 unsigned int pack_etc1_block(void *pETC1_block, const unsigned int *pSrc_pixels_rgba, etc1_pack_params &pack_params);
80 } // namespace rg_etc1
84 //------------------------------------------------------------------------------
86 // rg_etc1 uses the ZLIB license:
87 // http://opensource.org/licenses/Zlib
89 // Copyright (c) 2012 Rich Geldreich
91 // This software is provided 'as-is', without any express or implied
92 // warranty. In no event will the authors be held liable for any damages
93 // arising from the use of this software.
95 // Permission is granted to anyone to use this software for any purpose,
96 // including commercial applications, and to alter it and redistribute it
97 // freely, subject to the following restrictions:
99 // 1. The origin of this software must not be misrepresented; you must not
100 // claim that you wrote the original software. If you use this software
101 // in a product, an acknowledgment in the product documentation would be
102 // appreciated but is not required.
104 // 2. Altered source versions must be plainly marked as such, and must not be
105 // misrepresented as being the original software.
107 // 3. This notice may not be removed or altered from any source distribution.
109 //------------------------------------------------------------------------------