Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9bc2ac3e27 | |||
| 1ff067147d | |||
| 0dfba013b1 |
@@ -1,2 +0,0 @@
|
|||||||
*.o
|
|
||||||
crnlib/crunch
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# Change Log
|
|
||||||
|
|
||||||
## [0.1.4] - 2012-11-24
|
|
||||||
### Added
|
|
||||||
* KTX file format
|
|
||||||
* Basic ETC1 support
|
|
||||||
* Simple makefile
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
* Various DDS format fixes
|
|
||||||
|
|
||||||
## [0.1.3] - 2012-04-26
|
|
||||||
### Added
|
|
||||||
* Ported to Linux (tested on Ubuntu x86 w/Codeblocks). Note that a few features of the cmd line tool don't work yet (eg. -timestamp)
|
|
||||||
|
|
||||||
[0.1.4]: https://github.com/BinomialLLC/crunch
|
|
||||||
[0.1.3]: https://github.com/BinomialLLC/crunch
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10
-3
@@ -1,6 +1,8 @@
|
|||||||
COMPILE_OPTIONS = -O3 -fomit-frame-pointer -ffast-math -fno-math-errno -g -fno-strict-aliasing -Wall -Wno-unused-value -Wno-unused -march=core2
|
COMPILE_OPTIONS = -O3 -fomit-frame-pointer -ffast-math -fno-math-errno -g -fPIC -fno-strict-aliasing -Wall -Wno-unused-value -Wno-unused -march=core2
|
||||||
LINKER_OPTIONS = -lpthread -g
|
LINKER_OPTIONS = -lpthread -g
|
||||||
|
|
||||||
|
LIBCRUNCH = libcrunch.a
|
||||||
|
|
||||||
OBJECTS = \
|
OBJECTS = \
|
||||||
crn_arealist.o \
|
crn_arealist.o \
|
||||||
crn_assert.o \
|
crn_assert.o \
|
||||||
@@ -82,6 +84,9 @@ all: crunch
|
|||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
g++ $< -o $@ -c $(COMPILE_OPTIONS)
|
g++ $< -o $@ -c $(COMPILE_OPTIONS)
|
||||||
|
|
||||||
|
$(LIBCRUNCH): $(OBJECTS)
|
||||||
|
ar rcs $(LIBCRUNCH) $(OBJECTS)
|
||||||
|
|
||||||
crunch.o: ../crunch/crunch.cpp
|
crunch.o: ../crunch/crunch.cpp
|
||||||
g++ $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS)
|
g++ $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS)
|
||||||
|
|
||||||
@@ -91,6 +96,8 @@ corpus_gen.o: ../crunch/corpus_gen.cpp
|
|||||||
corpus_test.o: ../crunch/corpus_test.cpp
|
corpus_test.o: ../crunch/corpus_test.cpp
|
||||||
g++ $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS)
|
g++ $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS)
|
||||||
|
|
||||||
crunch: $(OBJECTS) crunch.o corpus_gen.o corpus_test.o
|
crunch: $(LIBCRUNCH) crunch.o corpus_gen.o corpus_test.o
|
||||||
g++ $(OBJECTS) crunch.o corpus_gen.o corpus_test.o -o crunch $(LINKER_OPTIONS)
|
g++ crunch.o corpus_gen.o corpus_test.o -o crunch $(LIBCRUNCH) $(LINKER_OPTIONS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(LIBCRUNCH) crunch *.o
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace crnlib
|
namespace crnlib
|
||||||
{
|
{
|
||||||
const char *g_copyright_str = "Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC";
|
const char *g_copyright_str = "Copyright (c) 2010-2012 Rich Geldreich and Tenacious Software LLC";
|
||||||
const char *g_sig_str = "C8cfRlaorj0wLtnMSxrBJxTC85rho2L9hUZKHcBL";
|
const char *g_sig_str = "C8cfRlaorj0wLtnMSxrBJxTC85rho2L9hUZKHcBL";
|
||||||
|
|
||||||
} // namespace crnlib
|
} // namespace crnlib
|
||||||
|
|||||||
+14
-14
@@ -112,9 +112,9 @@ namespace crnlib
|
|||||||
uint weight = m_unique_colors[i].m_weight;
|
uint weight = m_unique_colors[i].m_weight;
|
||||||
total_weight += weight;
|
total_weight += weight;
|
||||||
|
|
||||||
tot_r += m_unique_colors[i].m_color.r * static_cast<uint64>(weight);
|
tot_r += m_unique_colors[i].m_color.r * weight;
|
||||||
tot_g += m_unique_colors[i].m_color.g * static_cast<uint64>(weight);
|
tot_g += m_unique_colors[i].m_color.g * weight;
|
||||||
tot_b += m_unique_colors[i].m_color.b * static_cast<uint64>(weight);
|
tot_b += m_unique_colors[i].m_color.b * weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint half_total_weight = total_weight >> 1;
|
const uint half_total_weight = total_weight >> 1;
|
||||||
@@ -494,7 +494,7 @@ namespace crnlib
|
|||||||
ll[2] = (ll[0]*2+ll[1])/3;
|
ll[2] = (ll[0]*2+ll[1])/3;
|
||||||
ll[3] = (ll[0]+ll[1]*2)/3;
|
ll[3] = (ll[0]+ll[1]*2)/3;
|
||||||
|
|
||||||
uint64 error_to_beat = 0;
|
uint error_to_beat = 0;
|
||||||
uint min_color_weight = 0;
|
uint min_color_weight = 0;
|
||||||
uint max_color_weight = 0;
|
uint max_color_weight = 0;
|
||||||
for (uint i = 0; i < m_unique_colors.size(); i++)
|
for (uint i = 0; i < m_unique_colors.size(); i++)
|
||||||
@@ -503,7 +503,7 @@ namespace crnlib
|
|||||||
uint w = m_unique_colors[i].m_weight;
|
uint w = m_unique_colors[i].m_weight;
|
||||||
|
|
||||||
int delta = ll[m_best_solution.m_selectors[i]] - c;
|
int delta = ll[m_best_solution.m_selectors[i]] - c;
|
||||||
error_to_beat += static_cast<int64>(w) * (delta * delta);
|
error_to_beat += (int)w * (delta * delta);
|
||||||
|
|
||||||
if (c == min_color[comp_index])
|
if (c == min_color[comp_index])
|
||||||
min_color_weight += w;
|
min_color_weight += w;
|
||||||
@@ -561,11 +561,11 @@ namespace crnlib
|
|||||||
tl[2] = (tl[0]*2+tl[1])/3;
|
tl[2] = (tl[0]*2+tl[1])/3;
|
||||||
tl[3] = (tl[0]+tl[1]*2)/3;
|
tl[3] = (tl[0]+tl[1]*2)/3;
|
||||||
|
|
||||||
uint64 trial_error = 0;
|
uint trial_error = 0;
|
||||||
for (uint i = 0; i < m_unique_colors.size(); i++)
|
for (uint i = 0; i < m_unique_colors.size(); i++)
|
||||||
{
|
{
|
||||||
int delta = tl[m_best_solution.m_selectors[i]] - m_unique_colors[i].m_color[comp_index];
|
int delta = tl[m_best_solution.m_selectors[i]] - m_unique_colors[i].m_color[comp_index];
|
||||||
trial_error += static_cast<int64>(m_unique_colors[i].m_weight) * (delta * delta);
|
trial_error += m_unique_colors[i].m_weight * (delta * delta);
|
||||||
if (trial_error >= error_to_beat)
|
if (trial_error >= error_to_beat)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -599,7 +599,7 @@ namespace crnlib
|
|||||||
for (uint i = 0; i < m_unique_colors.size(); i++)
|
for (uint i = 0; i < m_unique_colors.size(); i++)
|
||||||
{
|
{
|
||||||
int delta = tl[m_best_solution.m_selectors[i]] - m_unique_colors[i].m_color[comp_index];
|
int delta = tl[m_best_solution.m_selectors[i]] - m_unique_colors[i].m_color[comp_index];
|
||||||
error_to_beat += static_cast<int64>(m_unique_colors[i].m_weight) * (delta * delta);
|
error_to_beat += m_unique_colors[i].m_weight * (delta * delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // better
|
} // better
|
||||||
@@ -1582,7 +1582,7 @@ namespace crnlib
|
|||||||
err = color_distance(true, c, colors[3], false);
|
err = color_distance(true, c, colors[3], false);
|
||||||
if (err < best_error) { best_error = err; best_color_index = 3; }
|
if (err < best_error) { best_error = err; best_color_index = 3; }
|
||||||
|
|
||||||
trial_error += best_error * static_cast<uint64>(m_unique_colors[unique_color_index].m_weight);
|
trial_error += best_error * m_unique_colors[unique_color_index].m_weight;
|
||||||
if (trial_error >= solution.m_error)
|
if (trial_error >= solution.m_error)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1607,7 +1607,7 @@ namespace crnlib
|
|||||||
err = color_distance(false, c, colors[3], false);
|
err = color_distance(false, c, colors[3], false);
|
||||||
if (err < best_error) { best_error = err; best_color_index = 3; }
|
if (err < best_error) { best_error = err; best_color_index = 3; }
|
||||||
|
|
||||||
trial_error += best_error * static_cast<uint64>(m_unique_colors[unique_color_index].m_weight);
|
trial_error += best_error * m_unique_colors[unique_color_index].m_weight;
|
||||||
if (trial_error >= solution.m_error)
|
if (trial_error >= solution.m_error)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1634,7 +1634,7 @@ namespace crnlib
|
|||||||
err = color_distance(true, c, colors[2], false);
|
err = color_distance(true, c, colors[2], false);
|
||||||
if (err < best_error) { best_error = err; best_color_index = 2; }
|
if (err < best_error) { best_error = err; best_color_index = 2; }
|
||||||
|
|
||||||
trial_error += best_error * static_cast<uint64>(m_unique_colors[unique_color_index].m_weight);
|
trial_error += best_error * m_unique_colors[unique_color_index].m_weight;
|
||||||
if (trial_error >= solution.m_error)
|
if (trial_error >= solution.m_error)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1656,7 +1656,7 @@ namespace crnlib
|
|||||||
err = color_distance(false, c, colors[2], false);
|
err = color_distance(false, c, colors[2], false);
|
||||||
if (err < best_error) { best_error = err; best_color_index = 2; }
|
if (err < best_error) { best_error = err; best_color_index = 2; }
|
||||||
|
|
||||||
trial_error += best_error * static_cast<uint64>(m_unique_colors[unique_color_index].m_weight);
|
trial_error += best_error * m_unique_colors[unique_color_index].m_weight;
|
||||||
if (trial_error >= solution.m_error)
|
if (trial_error >= solution.m_error)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1781,7 +1781,7 @@ namespace crnlib
|
|||||||
|
|
||||||
uint best_error = color_distance(m_perceptual, c, colors[best_color_index], false);
|
uint best_error = color_distance(m_perceptual, c, colors[best_color_index], false);
|
||||||
|
|
||||||
trial_error += best_error * static_cast<uint64>(m_unique_colors[unique_color_index].m_weight);
|
trial_error += best_error * m_unique_colors[unique_color_index].m_weight;
|
||||||
if (trial_error >= solution.m_error)
|
if (trial_error >= solution.m_error)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1814,7 +1814,7 @@ namespace crnlib
|
|||||||
|
|
||||||
uint best_error = color_distance(m_perceptual, c, colors[best_color_index], false);
|
uint best_error = color_distance(m_perceptual, c, colors[best_color_index], false);
|
||||||
|
|
||||||
trial_error += best_error * static_cast<uint64>(m_unique_colors[unique_color_index].m_weight);
|
trial_error += best_error * m_unique_colors[unique_color_index].m_weight;
|
||||||
if (trial_error >= solution.m_error)
|
if (trial_error >= solution.m_error)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -1305,7 +1305,7 @@ namespace crnlib
|
|||||||
*pActualComps = 0;
|
*pActualComps = 0;
|
||||||
|
|
||||||
if ((req_comps < 1) || (req_comps > 4))
|
if ((req_comps < 1) || (req_comps > 4))
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
mipmapped_texture tex;
|
mipmapped_texture tex;
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,12 @@ namespace crnlib
|
|||||||
|
|
||||||
template<typename T> inline T square(T value) { return value * value; }
|
template<typename T> inline T square(T value) { return value * value; }
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#if CRNLIB_64BIT_POINTERS==0
|
||||||
inline bool is_power_of_2(uint32 x) { return x && ((x & (x - 1U)) == 0U); }
|
inline bool is_power_of_2(uint32 x) { return x && ((x & (x - 1U)) == 0U); }
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
inline bool is_power_of_2(uint64 x) { return x && ((x & (x - 1U)) == 0U); }
|
inline bool is_power_of_2(uint64 x) { return x && ((x & (x - 1U)) == 0U); }
|
||||||
|
|
||||||
template<typename T> inline T align_up_value(T x, uint alignment)
|
template<typename T> inline T align_up_value(T x, uint alignment)
|
||||||
@@ -80,6 +85,8 @@ namespace crnlib
|
|||||||
return align_up_value(x, alignment) - x;
|
return align_up_value(x, alignment) - x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#if CRNLIB_64BIT_POINTERS==0
|
||||||
// From "Hackers Delight"
|
// From "Hackers Delight"
|
||||||
inline uint32 next_pow2(uint32 val)
|
inline uint32 next_pow2(uint32 val)
|
||||||
{
|
{
|
||||||
@@ -91,6 +98,8 @@ namespace crnlib
|
|||||||
val |= val >> 1;
|
val |= val >> 1;
|
||||||
return val + 1;
|
return val + 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
inline uint64 next_pow2(uint64 val)
|
inline uint64 next_pow2(uint64 val)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ namespace crnlib
|
|||||||
|
|
||||||
inline T* alloc_group(bool nofail = false)
|
inline T* alloc_group(bool nofail = false)
|
||||||
{
|
{
|
||||||
T* p = static_cast<T*>(sparse_array_traits<T, Log2N>::alloc_space(N * sizeof(T)));
|
T* p = static_cast<T*>(alloc_space(N * sizeof(T)));
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
{
|
{
|
||||||
@@ -365,7 +365,7 @@ namespace crnlib
|
|||||||
CRNLIB_FAIL("Out of memory");
|
CRNLIB_FAIL("Out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
sparse_array_traits<T, Log2N>::construct_group(p);
|
construct_group(p);
|
||||||
|
|
||||||
m_num_active_groups++;
|
m_num_active_groups++;
|
||||||
|
|
||||||
@@ -379,20 +379,20 @@ namespace crnlib
|
|||||||
CRNLIB_ASSERT(m_num_active_groups);
|
CRNLIB_ASSERT(m_num_active_groups);
|
||||||
m_num_active_groups--;
|
m_num_active_groups--;
|
||||||
|
|
||||||
sparse_array_traits<T, Log2N>::destruct_group(p);
|
destruct_group(p);
|
||||||
|
|
||||||
sparse_array_traits<T, Log2N>::free_space(p);
|
free_space(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void init_default()
|
inline void init_default()
|
||||||
{
|
{
|
||||||
sparse_array_traits<T, Log2N>::construct_element(reinterpret_cast<T*>(m_default));
|
construct_element(reinterpret_cast<T*>(m_default));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void deinit_default()
|
inline void deinit_default()
|
||||||
{
|
{
|
||||||
sparse_array_traits<T, Log2N>::destruct_element(reinterpret_cast<T*>(m_default));
|
destruct_element(reinterpret_cast<T*>(m_default));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -52,6 +52,7 @@ namespace crnlib
|
|||||||
} // namespace crnlib
|
} // namespace crnlib
|
||||||
|
|
||||||
using namespace crnlib;
|
using namespace crnlib;
|
||||||
|
using crnlib::uint;
|
||||||
|
|
||||||
const char* crn_get_format_string(crn_format fmt)
|
const char* crn_get_format_string(crn_format fmt)
|
||||||
{
|
{
|
||||||
@@ -172,7 +173,7 @@ void *crn_compress(const crn_comp_params &comp_params, crn_uint32 &compressed_si
|
|||||||
if (pActual_bitrate) *pActual_bitrate = 0.0f;
|
if (pActual_bitrate) *pActual_bitrate = 0.0f;
|
||||||
|
|
||||||
if (!comp_params.check())
|
if (!comp_params.check())
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
crnlib::vector<uint8> crn_file_data;
|
crnlib::vector<uint8> crn_file_data;
|
||||||
if (!create_compressed_texture(comp_params, crn_file_data, pActual_quality_level, pActual_bitrate))
|
if (!create_compressed_texture(comp_params, crn_file_data, pActual_quality_level, pActual_bitrate))
|
||||||
@@ -189,7 +190,7 @@ void *crn_compress(const crn_comp_params &comp_params, const crn_mipmap_params &
|
|||||||
if (pActual_bitrate) *pActual_bitrate = 0.0f;
|
if (pActual_bitrate) *pActual_bitrate = 0.0f;
|
||||||
|
|
||||||
if ((!comp_params.check()) || (!mip_params.check()))
|
if ((!comp_params.check()) || (!mip_params.check()))
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
crnlib::vector<uint8> crn_file_data;
|
crnlib::vector<uint8> crn_file_data;
|
||||||
if (!create_compressed_texture(comp_params, mip_params, crn_file_data, pActual_quality_level, pActual_bitrate))
|
if (!create_compressed_texture(comp_params, mip_params, crn_file_data, pActual_quality_level, pActual_bitrate))
|
||||||
|
|||||||
+3
-3
@@ -176,7 +176,7 @@ public:
|
|||||||
console::printf("-%s", pixel_format_helpers::get_pixel_format_string(fmt));
|
console::printf("-%s", pixel_format_helpers::get_pixel_format_string(fmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
console::printf("\nFor bugs, support, or feedback: info@binomial.info");
|
console::printf("\nFor bugs, support, or feedback: richgel99@gmail.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool convert(const char* pCommand_line)
|
bool convert(const char* pCommand_line)
|
||||||
@@ -1253,8 +1253,8 @@ static bool check_for_option(int argc, char *argv[], const char *pOption)
|
|||||||
|
|
||||||
static void print_title()
|
static void print_title()
|
||||||
{
|
{
|
||||||
console::printf("crunch: Advanced DXTn Texture Compressor - https://github.com/BinomialLLC/crunch");
|
console::printf("crunch: Advanced DXTn Texture Compressor - http://code.google.com/p/crunch");
|
||||||
console::printf("Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC");
|
console::printf("Copyright (c) 2010-2012 Rich Geldreich and Tenacious Software LLC");
|
||||||
console::printf("crnlib version v%u.%02u %s Built %s, %s", CRNLIB_VERSION / 100U, CRNLIB_VERSION % 100U, crnlib_is_x64() ? "x64" : "x86", __DATE__, __TIME__);
|
console::printf("crnlib version v%u.%02u %s Built %s, %s", CRNLIB_VERSION / 100U, CRNLIB_VERSION % 100U, crnlib_is_x64() ? "x64" : "x86", __DATE__, __TIME__);
|
||||||
console::printf("");
|
console::printf("");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
/* Copyright (c) 2013, Evan Parker, Brandon Jones. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
|
||||||
list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
|
||||||
|
|
||||||
#define PLATFORM_NACL // This disables use of 64 bit integers, among other things.
|
|
||||||
|
|
||||||
#include <stddef.h> // For NULL, size_t
|
|
||||||
#include <cstring> // for malloc etc
|
|
||||||
|
|
||||||
#include "crn_decomp.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
unsigned int crn_get_width(void *src, unsigned int src_size);
|
|
||||||
unsigned int crn_get_height(void *src, unsigned int src_size);
|
|
||||||
unsigned int crn_get_levels(void *src, unsigned int src_size);
|
|
||||||
unsigned int crn_get_dxt_format(void *src, unsigned int src_size);
|
|
||||||
unsigned int crn_get_bytes_per_block(void *src, unsigned int src_size);
|
|
||||||
unsigned int crn_get_uncompressed_size(void *p, unsigned int size, unsigned int level);
|
|
||||||
void crn_decompress(void *src, unsigned int src_size, void *dst, unsigned int dst_size, unsigned int firstLevel, unsigned int levelCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int crn_get_width(void *src, unsigned int src_size) {
|
|
||||||
crnd::crn_texture_info tex_info;
|
|
||||||
crnd::crnd_get_texture_info(static_cast<crn_uint8*>(src), src_size, &tex_info);
|
|
||||||
return tex_info.m_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int crn_get_height(void *src, unsigned int src_size) {
|
|
||||||
crnd::crn_texture_info tex_info;
|
|
||||||
crnd::crnd_get_texture_info(static_cast<crn_uint8*>(src), src_size, &tex_info);
|
|
||||||
return tex_info.m_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int crn_get_levels(void *src, unsigned int src_size) {
|
|
||||||
crnd::crn_texture_info tex_info;
|
|
||||||
crnd::crnd_get_texture_info(static_cast<crn_uint8*>(src), src_size, &tex_info);
|
|
||||||
return tex_info.m_levels;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int crn_get_dxt_format(void *src, unsigned int src_size) {
|
|
||||||
crnd::crn_texture_info tex_info;
|
|
||||||
crnd::crnd_get_texture_info(static_cast<crn_uint8*>(src), src_size, &tex_info);
|
|
||||||
return tex_info.m_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int crn_get_bytes_per_block(void *src, unsigned int src_size) {
|
|
||||||
crnd::crn_texture_info tex_info;
|
|
||||||
crnd::crnd_get_texture_info(static_cast<crn_uint8*>(src), src_size, &tex_info);
|
|
||||||
return crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int crn_get_uncompressed_size(void *src, unsigned int src_size, unsigned int level) {
|
|
||||||
crnd::crn_texture_info tex_info;
|
|
||||||
crnd::crnd_get_texture_info(static_cast<crn_uint8*>(src), src_size, &tex_info);
|
|
||||||
const crn_uint32 width = tex_info.m_width >> level;
|
|
||||||
const crn_uint32 height = tex_info.m_height >> level;
|
|
||||||
const crn_uint32 blocks_x = (width + 3) >> 2;
|
|
||||||
const crn_uint32 blocks_y = (height + 3) >> 2;
|
|
||||||
const crn_uint32 row_pitch = blocks_x * crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format);
|
|
||||||
const crn_uint32 total_face_size = row_pitch * blocks_y;
|
|
||||||
return total_face_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void crn_decompress(void *src, unsigned int src_size, void *dst, unsigned int dst_size, unsigned int firstLevel, unsigned int levelCount) {
|
|
||||||
crnd::crn_texture_info tex_info;
|
|
||||||
crnd::crnd_get_texture_info(static_cast<crn_uint8*>(src), src_size, &tex_info);
|
|
||||||
|
|
||||||
crn_uint32 width = tex_info.m_width >> firstLevel;
|
|
||||||
crn_uint32 height = tex_info.m_height >> firstLevel;
|
|
||||||
crn_uint32 bytes_per_block = crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format);
|
|
||||||
|
|
||||||
void *pDecomp_images[1];
|
|
||||||
pDecomp_images[0] = dst;
|
|
||||||
|
|
||||||
crnd::crnd_unpack_context pContext =
|
|
||||||
crnd::crnd_unpack_begin(static_cast<crn_uint8*>(src), src_size);
|
|
||||||
|
|
||||||
for (int i = firstLevel; i < firstLevel + levelCount; ++i) {
|
|
||||||
crn_uint32 blocks_x = (width + 3) >> 2;
|
|
||||||
crn_uint32 blocks_y = (height + 3) >> 2;
|
|
||||||
crn_uint32 row_pitch = blocks_x * bytes_per_block;
|
|
||||||
crn_uint32 total_level_size = row_pitch * blocks_y;
|
|
||||||
|
|
||||||
crnd::crnd_unpack_level(pContext, pDecomp_images, total_level_size, row_pitch, i);
|
|
||||||
pDecomp_images[0] = (char*)pDecomp_images[0] + total_level_size;
|
|
||||||
|
|
||||||
width = width >> 1;
|
|
||||||
height = height >> 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
crnd::crnd_unpack_end(pContext);
|
|
||||||
}
|
|
||||||
@@ -33,7 +33,7 @@ const int cDefaultCRNQualityLevel = 128;
|
|||||||
static int print_usage()
|
static int print_usage()
|
||||||
{
|
{
|
||||||
printf("Description: Simple crnlib API example program.\n");
|
printf("Description: Simple crnlib API example program.\n");
|
||||||
printf("Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC\n");
|
printf("Copyright (c) 2010-2011 Tenacious Software LLC\n");
|
||||||
printf("Usage: example1 [mode: i/c/d] [source_file] [options]\n");
|
printf("Usage: example1 [mode: i/c/d] [source_file] [options]\n");
|
||||||
printf("\nModes:\n");
|
printf("\nModes:\n");
|
||||||
printf("c: Compress to .DDS or .CRN using the crn_compress() func. in crnlib.h\n");
|
printf("c: Compress to .DDS or .CRN using the crn_compress() func. in crnlib.h\n");
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ using namespace crnlib;
|
|||||||
static int print_usage()
|
static int print_usage()
|
||||||
{
|
{
|
||||||
printf("Description: Transcodes .CRN to .DDS files using crn_decomp.h.\n");
|
printf("Description: Transcodes .CRN to .DDS files using crn_decomp.h.\n");
|
||||||
printf("Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC\n");
|
printf("Copyright (c) 2010-2011 Tenacious Software LLC\n");
|
||||||
printf("Usage: example2 [source_file] [options]\n");
|
printf("Usage: example2 [source_file] [options]\n");
|
||||||
printf("\nOptions:\n");
|
printf("\nOptions:\n");
|
||||||
printf("-out filename - Force output filename.\n");
|
printf("-out filename - Force output filename.\n");
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const uint cDXTBlockSize = 4;
|
|||||||
static int print_usage()
|
static int print_usage()
|
||||||
{
|
{
|
||||||
printf("Description: Simple .DDS DXTn block compression using crnlib.\n");
|
printf("Description: Simple .DDS DXTn block compression using crnlib.\n");
|
||||||
printf("Copyright (c) 2010-2016 Binomial LLC\n");
|
printf("Copyright (c) 2010-2011 Tenacious Software LLC\n");
|
||||||
printf("Usage: example3 [source_file] [options]\n");
|
printf("Usage: example3 [source_file] [options]\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Note: This simple example is not multithreaded, so it's not going to be\n");
|
printf("Note: This simple example is not multithreaded, so it's not going to be\n");
|
||||||
|
|||||||
+7
-11
@@ -1,5 +1,5 @@
|
|||||||
// File: crn_decomp.h - Fast CRN->DXTc texture transcoder header file library
|
// File: crn_decomp.h - Fast CRN->DXTc texture transcoder header file library
|
||||||
// Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
|
// Copyright (c) 2010-2012 Rich Geldreich and Tenacious Software LLC
|
||||||
// See Copyright Notice and license at the end of this file.
|
// See Copyright Notice and license at the end of this file.
|
||||||
//
|
//
|
||||||
// This single header file contains *all* of the code necessary to unpack .CRN files to raw DXTn bits.
|
// This single header file contains *all* of the code necessary to unpack .CRN files to raw DXTn bits.
|
||||||
@@ -374,14 +374,10 @@ namespace crnd
|
|||||||
|
|
||||||
const uint32 cIntBits = 32U;
|
const uint32 cIntBits = 32U;
|
||||||
|
|
||||||
#ifdef _WIN64
|
#if CRNLIB_64BIT_POINTERS
|
||||||
typedef uint64 ptr_bits;
|
typedef uint64 ptr_bits;
|
||||||
#else
|
#else
|
||||||
#ifdef __x86_64__
|
typedef uint32 ptr_bits;
|
||||||
typedef uint64 ptr_bits;
|
|
||||||
#else
|
|
||||||
typedef uint32 ptr_bits;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename T> struct int_traits { enum { cMin = crnd::cINT32_MIN, cMax = crnd::cINT32_MAX, cSigned = true }; };
|
template<typename T> struct int_traits { enum { cMin = crnd::cINT32_MIN, cMax = crnd::cINT32_MAX, cSigned = true }; };
|
||||||
@@ -2823,15 +2819,15 @@ namespace crnd
|
|||||||
*pSize = 0;
|
*pSize = 0;
|
||||||
|
|
||||||
if ((!pData) || (data_size < cCRNHeaderMinSize))
|
if ((!pData) || (data_size < cCRNHeaderMinSize))
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
crn_header tmp_header;
|
crn_header tmp_header;
|
||||||
const crn_header* pHeader = crnd_get_header(tmp_header, pData, data_size);
|
const crn_header* pHeader = crnd_get_header(tmp_header, pData, data_size);
|
||||||
if (!pHeader)
|
if (!pHeader)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
if (level_index >= pHeader->m_levels)
|
if (level_index >= pHeader->m_levels)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
uint32 cur_level_ofs = pHeader->m_level_ofs[level_index];
|
uint32 cur_level_ofs = pHeader->m_level_ofs[level_index];
|
||||||
|
|
||||||
@@ -4816,7 +4812,7 @@ namespace crnd
|
|||||||
// crn_decomp.h uses the ZLIB license:
|
// crn_decomp.h uses the ZLIB license:
|
||||||
// http://opensource.org/licenses/Zlib
|
// http://opensource.org/licenses/Zlib
|
||||||
//
|
//
|
||||||
// Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
|
// Copyright (c) 2010-2012 Rich Geldreich and Tenacious Software LLC
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied
|
// This software is provided 'as-is', without any express or implied
|
||||||
// warranty. In no event will the authors be held liable for any damages
|
// warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
// File: crnlib.h - Advanced DXTn texture compression library.
|
// File: crnlib.h - Advanced DXTn texture compression library.
|
||||||
// Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
|
// Copyright (c) 2010-2012 Rich Geldreich and Tenacious Software LLC
|
||||||
// See copyright notice and license at the end of this file.
|
// See copyright notice and license at the end of this file.
|
||||||
//
|
//
|
||||||
// This header file contains the public crnlib declarations for DXTn,
|
// This header file contains the public crnlib declarations for DXTn,
|
||||||
@@ -619,7 +619,7 @@ bool crn_decompress_block(const void *pSrc_block, crn_uint32 *pDst_pixels, crn_f
|
|||||||
// crnlib uses the ZLIB license:
|
// crnlib uses the ZLIB license:
|
||||||
// http://opensource.org/licenses/Zlib
|
// http://opensource.org/licenses/Zlib
|
||||||
//
|
//
|
||||||
// Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
|
// Copyright (c) 2010-2012 Rich Geldreich and Tenacious Software LLC
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied
|
// This software is provided 'as-is', without any express or implied
|
||||||
// warranty. In no event will the authors be held liable for any damages
|
// warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
crunch/crnlib uses the ZLIB license:
|
crunch/crnlib uses the ZLIB license:
|
||||||
http://opensource.org/licenses/Zlib
|
http://opensource.org/licenses/Zlib
|
||||||
|
|
||||||
Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
|
Copyright (c) 2010-2012 Rich Geldreich and Tenacious Software LLC
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
+59
-59
@@ -1,7 +1,7 @@
|
|||||||
crunch/crnlib v1.04 - Advanced DXTn texture compression library
|
crunch/crnlib v1.04 - Advanced DXTn texture compression library
|
||||||
Copyright (C) 2010-2017 Richard Geldreich, Jr. and Binomial LLC http://binomial.info
|
Copyright (C) 2010-2012 Rich Geldreich and Tenacious Software LLC
|
||||||
|
|
||||||
For bugs or support contact Binomial <info@binomial.info>.
|
For bugs or support contact Rich Geldreich <richgel99@gmail.com>.
|
||||||
|
|
||||||
This software uses the ZLIB license, which is located in license.txt.
|
This software uses the ZLIB license, which is located in license.txt.
|
||||||
http://opensource.org/licenses/Zlib
|
http://opensource.org/licenses/Zlib
|
||||||
@@ -12,14 +12,31 @@ written by Igor Pavlov (LZMA), RYG (crn_ryg_dxt*), and Sean Barrett (stb_image.c
|
|||||||
If you use this software in a product, an acknowledgment in the product
|
If you use this software in a product, an acknowledgment in the product
|
||||||
documentation would be highly appreciated but is not required.
|
documentation would be highly appreciated but is not required.
|
||||||
|
|
||||||
Note: crunch originally used to live on Google Code: https://code.google.com/p/crunch/
|
New for v1.04 [11/24/12]: KTX file format, basic ETC1 support, DDS format fixes, simple makefile
|
||||||
|
------------------------------------------------
|
||||||
|
|
||||||
## Overview
|
Lots of higher level changes to get crnlib into a state where I can carry it forward to
|
||||||
|
support other file and texture compression formats. No major codec-level changes.
|
||||||
|
I've regression tested the codec writing .CRN and RDO .DDS files at various bitrates.
|
||||||
|
Everything seems OK, but with all the changes I made to support KTX and other formats like ETC1
|
||||||
|
I'm still worried about bugs.
|
||||||
|
|
||||||
|
New for v1.03 [4/26/12]: crnlib more portable, Linux Port
|
||||||
|
------------------------------------------------
|
||||||
|
|
||||||
|
v1.03 has been ported to Linux. It's still a work in progress. A few features
|
||||||
|
of the command line tool don't work under Linux yet (such as -timestamp),
|
||||||
|
but the core functionality (compression/decompression/transcoding) should work
|
||||||
|
OK. I'm currently testing crnlib/crunch with Codeblocks 10.05 under Ubuntu x86.
|
||||||
|
|
||||||
|
Overview
|
||||||
|
--------
|
||||||
|
|
||||||
crnlib is a lossy texture compression library for developers that ship
|
crnlib is a lossy texture compression library for developers that ship
|
||||||
content using the DXT1/5/N or 3DC compressed color/normal map/cubemap
|
content using the DXT1/5/N or 3DC compressed color/normal map/cubemap
|
||||||
mipmapped texture formats. It was written by the same author as the open
|
mipmapped texture formats. It was written by the same author as the open
|
||||||
source [LZHAM compression library](http://code.google.com/p/lzham/).
|
source LZHAM lossless data compression library:
|
||||||
|
http://code.google.com/p/lzham/
|
||||||
|
|
||||||
It can compress mipmapped 2D textures, normal maps, and cubemaps to
|
It can compress mipmapped 2D textures, normal maps, and cubemaps to
|
||||||
approx. 1-1.25 bits/texel, and normal maps to 1.75-2 bits/texel. The
|
approx. 1-1.25 bits/texel, and normal maps to 1.75-2 bits/texel. The
|
||||||
@@ -48,17 +65,21 @@ It also supports several popular swizzled variants (several are
|
|||||||
also supported by AMD's Compressonator):
|
also supported by AMD's Compressonator):
|
||||||
DXT5_XGBR, DXT5_xGxR, DXT5_AGBR, and DXT5_CCxY (experimental luma-chroma YCoCg).
|
DXT5_XGBR, DXT5_xGxR, DXT5_AGBR, and DXT5_CCxY (experimental luma-chroma YCoCg).
|
||||||
|
|
||||||
## Recommended Software
|
Recommended Software
|
||||||
|
--------------------
|
||||||
|
|
||||||
AMD's [Compressonator tool](https://github.com/GPUOpen-Tools/Compressonator)
|
AMD's Compressonator tool is recommended to view the .DDS files created by
|
||||||
is recommended to view the .DDS files created by the crunch tool and the included example projects.
|
the crunch tool and the included example projects:
|
||||||
|
|
||||||
|
http://developer.amd.com/gpu/compressonator/pages/default.aspx
|
||||||
|
|
||||||
Note: Some of the swizzled DXTn .DDS output formats (such as DXT5_xGBR)
|
Note: Some of the swizzled DXTn .DDS output formats (such as DXT5_xGBR)
|
||||||
read/written by the crunch tool or examples deviate from the DX9 DDS
|
read/written by the crunch tool or examples deviate from the DX9 DDS
|
||||||
standard, so DXSDK tools such as DXTEX.EXE won't load them at all or
|
standard, so DXSDK tools such as DXTEX.EXE won't load them at all or
|
||||||
they won't be properly displayed.
|
they won't be properly displayed.
|
||||||
|
|
||||||
## Compression Algorithm Details
|
Compression Algorithm Details
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
The compression process employed in creating both .CRN and
|
The compression process employed in creating both .CRN and
|
||||||
clustered .DDS files utilizes a very high quality, scalable DXTn
|
clustered .DDS files utilizes a very high quality, scalable DXTn
|
||||||
@@ -79,7 +100,8 @@ version will also utilize adaptive binary arithmetic coding and higher
|
|||||||
order context modeling using already developed tech from the my LZHAM
|
order context modeling using already developed tech from the my LZHAM
|
||||||
compression library.
|
compression library.
|
||||||
|
|
||||||
## Supported File Formats
|
Supported File Formats
|
||||||
|
----------------------
|
||||||
|
|
||||||
crnlib supports two compressed texture file formats. The first
|
crnlib supports two compressed texture file formats. The first
|
||||||
format (clustered .DDS) is simple to integrate into an existing project
|
format (clustered .DDS) is simple to integrate into an existing project
|
||||||
@@ -89,8 +111,7 @@ the second, higher quality custom format (.CRN) requires a few
|
|||||||
typically straightforward engine modifications to integrate the
|
typically straightforward engine modifications to integrate the
|
||||||
.CRN->DXTn transcoder header file library into your tools/engine.
|
.CRN->DXTn transcoder header file library into your tools/engine.
|
||||||
|
|
||||||
### .DDS
|
.DDS
|
||||||
|
|
||||||
crnlib can compress textures to standard DX9-style .DDS files using
|
crnlib can compress textures to standard DX9-style .DDS files using
|
||||||
clustered DXTn compression, which is a subset of the approach used to
|
clustered DXTn compression, which is a subset of the approach used to
|
||||||
create .CRN files.(For completeness, crnlib also supports vanilla, block
|
create .CRN files.(For completeness, crnlib also supports vanilla, block
|
||||||
@@ -111,8 +132,7 @@ data.)
|
|||||||
Clustered .DDS files are intended to be the simplest/fastest way to
|
Clustered .DDS files are intended to be the simplest/fastest way to
|
||||||
integrate crnlib's tech into a project.
|
integrate crnlib's tech into a project.
|
||||||
|
|
||||||
### .CRN
|
.CRN
|
||||||
|
|
||||||
The second, better, option is to compress your textures to .CRN files
|
The second, better, option is to compress your textures to .CRN files
|
||||||
using crnlib. To read the resulting .CRN data, you must add the .CRN
|
using crnlib. To read the resulting .CRN data, you must add the .CRN
|
||||||
transcoder library (located in the included single file, stand-alone
|
transcoder library (located in the included single file, stand-alone
|
||||||
@@ -124,7 +144,7 @@ further lossless compression because they're already highly compressed.
|
|||||||
.CRN files are a bit more difficult/risky to integrate into a project, but
|
.CRN files are a bit more difficult/risky to integrate into a project, but
|
||||||
the resulting compression ratio and quality is superior vs. clustered .DDS files.
|
the resulting compression ratio and quality is superior vs. clustered .DDS files.
|
||||||
|
|
||||||
### .KTX
|
.KTX
|
||||||
|
|
||||||
crnlib and crunch can read/write the .KTX file format in various pixel formats.
|
crnlib and crunch can read/write the .KTX file format in various pixel formats.
|
||||||
Rate distortion optimization (clustered DXTc compression) is not yet supported
|
Rate distortion optimization (clustered DXTc compression) is not yet supported
|
||||||
@@ -136,7 +156,8 @@ found that support .KTX are fairly (to very) buggy, or are limited to only a han
|
|||||||
of pixel formats, so there's no guarantee that the .KTX files written by crnlib can
|
of pixel formats, so there's no guarantee that the .KTX files written by crnlib can
|
||||||
be reliably read by other tools.
|
be reliably read by other tools.
|
||||||
|
|
||||||
## Building the Examples
|
Building the Examples
|
||||||
|
---------------------
|
||||||
|
|
||||||
This release contains the source code and projects for three simple
|
This release contains the source code and projects for three simple
|
||||||
example projects:
|
example projects:
|
||||||
@@ -147,14 +168,11 @@ VS2005, VS2010, and gcc 4.5.0 (TDM GCC+MinGW). A codeblocks 10.05
|
|||||||
workspace and project file is also included, but compiling crnlib this
|
workspace and project file is also included, but compiling crnlib this
|
||||||
way hasn't been tested much.
|
way hasn't been tested much.
|
||||||
|
|
||||||
### example1
|
example1: Demonstrates how to use crnlib's high-level C-helper
|
||||||
|
|
||||||
Demonstrates how to use crnlib's high-level C-helper
|
|
||||||
compression/decompression/transcoding functions in inc/crnlib.h. It's a
|
compression/decompression/transcoding functions in inc/crnlib.h. It's a
|
||||||
fairly complete example of crnlib's functionality.
|
fairly complete example of crnlib's functionality.
|
||||||
|
|
||||||
### example2
|
example2: Shows how to transcodec .CRN files to .DDS using *only*
|
||||||
Shows how to transcodec .CRN files to .DDS using **only**
|
|
||||||
the functionality in inc/crn_decomp.h. It does not link against against
|
the functionality in inc/crn_decomp.h. It does not link against against
|
||||||
crnlib.lib or depend on it in any way. (Note: The complete source code,
|
crnlib.lib or depend on it in any way. (Note: The complete source code,
|
||||||
approx. 4800 lines, to the CRN transcoder is included in inc/crn_decomp.h.)
|
approx. 4800 lines, to the CRN transcoder is included in inc/crn_decomp.h.)
|
||||||
@@ -162,15 +180,15 @@ approx. 4800 lines, to the CRN transcoder is included in inc/crn_decomp.h.)
|
|||||||
example2 is intended to show how simple it is to integrate CRN textures
|
example2 is intended to show how simple it is to integrate CRN textures
|
||||||
into your application.
|
into your application.
|
||||||
|
|
||||||
### example3
|
example3: Shows how to use the regular, low-level DXTn block compressor
|
||||||
Shows how to use the regular, low-level DXTn block compressor
|
|
||||||
functions in inc/crnlib.h. This functionality is included for
|
functions in inc/crnlib.h. This functionality is included for
|
||||||
completeness. (Your engine or toolchain most likely already has its own
|
completeness. (Your engine or toolchain most likely already has its own
|
||||||
DXTn compressor. crnlib's compressor is typically very competitive or
|
DXTn compressor. crnlib's compressor is typically very competitive or
|
||||||
superior to most available closed and open source CPU-based
|
superior to most available closed and open source CPU-based
|
||||||
compressors.)
|
compressors.)
|
||||||
|
|
||||||
## Creating Compressed Textures from the Command Line (crunch.exe)
|
Creating Compressed Textures from the Command Line (crunch.exe)
|
||||||
|
---------------------------------------------------------------
|
||||||
|
|
||||||
The simplest way to create compressed textures using crnlib is to
|
The simplest way to create compressed textures using crnlib is to
|
||||||
integrate the bin\crunch.exe or bin\crunch_x64.exe) command line tool
|
integrate the bin\crunch.exe or bin\crunch_x64.exe) command line tool
|
||||||
@@ -187,25 +205,25 @@ form under inc/crn_decomp.h.
|
|||||||
Here are a few example crunch.exe command lines:
|
Here are a few example crunch.exe command lines:
|
||||||
|
|
||||||
1. Compress blah.tga to blah.dds using normal DXT1 compression:
|
1. Compress blah.tga to blah.dds using normal DXT1 compression:
|
||||||
* `crunch -file blah.tga -fileformat dds -dxt1`
|
crunch -file blah.tga -fileformat dds -dxt1
|
||||||
|
|
||||||
2. Compress blah.tga to blah.dds using clustered DXT1 at an effective bitrate of 1.5 bits/texel, display image statistic:
|
2. Compress blah.tga to blah.dds using clustered DXT1 at an effective bitrate of 1.5 bits/texel, display image statistic:
|
||||||
* `crunch -file blah.tga -fileformat dds -dxt1 -bitrate 1.5 -imagestats`
|
crunch -file blah.tga -fileformat dds -dxt1 -bitrate 1.5 -imagestats
|
||||||
|
|
||||||
3. Compress blah.tga to blah.dds using clustered DXT1 at quality level 100 (from [0,255]), with no mipmaps, display LZMA statistics:
|
3. Compress blah.tga to blah.dds using clustered DXT1 at quality level 100 (from [0,255]), with no mipmaps, display LZMA statistics:
|
||||||
* `crunch -file blah.tga -fileformat dds -dxt1 -quality 100 -mipmode none -lzmastats`
|
crunch -file blah.tga -fileformat dds -dxt1 -quality 100 -mipmode none -lzmastats
|
||||||
|
|
||||||
3. Compress blah.tga to blah.crn using clustered DXT1 at a bitrate of 1.2 bits/texel, no mipmaps:
|
3. Compress blah.tga to blah.crn using clustered DXT1 at a bitrate of 1.2 bits/texel, no mipmaps:
|
||||||
* `crunch -file blah.tga -dxt1 -bitrate 1.2 -mipmode none`
|
crunch -file blah.tga -dxt1 -bitrate 1.2 -mipmode none
|
||||||
|
|
||||||
4. Decompress blah.dds to a .tga file:
|
4. Decompress blah.dds to a .tga file:
|
||||||
* `crunch -file blah.dds -fileformat tga`
|
crunch -file blah.dds -fileformat tga
|
||||||
|
|
||||||
5. Transcode blah.crn to a .dds file:
|
5. Transcode blah.crn to a .dds file:
|
||||||
* `crunch -file blah.crn`
|
crunch -file blah.crn
|
||||||
|
|
||||||
6. Decompress blah.crn, writing each mipmap level to a separate .tga file:
|
6. Decompress blah.crn, writing each mipmap level to a separate .tga file:
|
||||||
* `crunch -split -file blah.crn -fileformat tga`
|
crunch -split -file blah.crn -fileformat tga
|
||||||
|
|
||||||
crunch.exe can do a lot more, like rescale/crop images before
|
crunch.exe can do a lot more, like rescale/crop images before
|
||||||
compression, convert images from one file format to another, compare
|
compression, convert images from one file format to another, compare
|
||||||
@@ -217,7 +235,8 @@ time to address. This version of crunch.exe has some reduced
|
|||||||
functionality compared to an earlier eval release. For example, XML file
|
functionality compared to an earlier eval release. For example, XML file
|
||||||
support is not included in this version.
|
support is not included in this version.
|
||||||
|
|
||||||
## Using crnlib
|
Using crnlib
|
||||||
|
------------
|
||||||
|
|
||||||
The most flexible and powerful way of using crnlib is to integrate the
|
The most flexible and powerful way of using crnlib is to integrate the
|
||||||
library into your editor/toolchain/etc. and directly supply it your
|
library into your editor/toolchain/etc. and directly supply it your
|
||||||
@@ -226,40 +245,30 @@ inc/crnlib.h.
|
|||||||
|
|
||||||
To compress, you basically fill in a few structs in and call one function:
|
To compress, you basically fill in a few structs in and call one function:
|
||||||
|
|
||||||
```c
|
void *crn_compress(const crn_comp_params &comp_params, crn_uint32 &compressed_size, crn_uint32 *pActual_quality_level = NULL, float *pActual_bitrate = NULL);
|
||||||
void *crn_compress( const crn_comp_params &comp_params,
|
|
||||||
crn_uint32 &compressed_size,
|
|
||||||
crn_uint32 *pActual_quality_level = NULL,
|
|
||||||
float *pActual_bitrate = NULL);
|
|
||||||
```
|
|
||||||
|
|
||||||
Or, if you want crnlib to also generate mipmaps, you call this function:
|
Or, if you want crnlib to also generate mipmaps, you call this function:
|
||||||
|
|
||||||
```c
|
void *crn_compress(const crn_comp_params &comp_params, const crn_mipmap_params &mip_params, crn_uint32 &compressed_size, crn_uint32 *pActual_quality_level = NULL, float *pActual_bitrate = NULL);
|
||||||
void *crn_compress( const crn_comp_params &comp_params,
|
|
||||||
const crn_mipmap_params &mip_params,
|
|
||||||
crn_uint32 &compressed_size,
|
|
||||||
crn_uint32 *pActual_quality_level = NULL,
|
|
||||||
float *pActual_bitrate = NULL);
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also transcode/uncompress .DDS/.CRN files to raw 32bpp images
|
You can also transcode/uncompress .DDS/.CRN files to raw 32bpp images
|
||||||
using `crn_decompress_crn_to_dds()` and `crn_decompress_dds_to_images()`.
|
using crn_decompress_crn_to_dds() and crn_decompress_dds_to_images().
|
||||||
|
|
||||||
Internally, crnlib just uses inc/crn_decomp.h to transcode textures to
|
Internally, crnlib just uses inc/crn_decomp.h to transcode textures to
|
||||||
DXTn. If you only need to transcode .CRN format files to raw DXTn bits
|
DXTn. If you only need to transcode .CRN format files to raw DXTn bits
|
||||||
at runtime (and not compress), you don't actually need to compile or
|
at runtime (and not compress), you don't actually need to compile or
|
||||||
link against crnlib at all. Just include inc/crn_decomp.h, which
|
link against crnlib at all. Just include inc/crn_decomp.h, which
|
||||||
contains a completely self-contained CRN transcoder in the "crnd"
|
contains a completely self-contained CRN transcoder in the "crnd"
|
||||||
namespace. The `crnd_get_texture_info()`, `crnd_unpack_begin()`,
|
namespace. The crnd_get_texture_info(), crnd_unpack_begin(),
|
||||||
`crnd_unpack_level()`, etc. functions are all you need to efficiently get
|
crnd_unpack_level(), etc. functions are all you need to efficiently get
|
||||||
at the raw DXTn bits, which can be directly supplied to whatever API or
|
at the raw DXTn bits, which can be directly supplied to whatever API or
|
||||||
GPU you're using. (See example2.)
|
GPU you're using. (See example2.)
|
||||||
|
|
||||||
Important note: When compiling under native client, be sure to define
|
Important note: When compiling under native client, be sure to define
|
||||||
the `PLATFORM_NACL` macro before including the `inc/crn_decomp.h` header file library.
|
the PLATFORM_NACL macro before including the inc/crn_decomp.h header file library.
|
||||||
|
|
||||||
## Known Issues/Bugs
|
Known Issues/Bugs
|
||||||
|
-----------------
|
||||||
|
|
||||||
* crnlib currently assumes you'll be further losslessly compressing its
|
* crnlib currently assumes you'll be further losslessly compressing its
|
||||||
output .DDS files using LZMA. However, some engines use weaker codecs
|
output .DDS files using LZMA. However, some engines use weaker codecs
|
||||||
@@ -296,12 +305,3 @@ hasn't been tuned for max. quality yet.
|
|||||||
supported when writing to .DDS, not .KTX. Also, only plain block by block
|
supported when writing to .DDS, not .KTX. Also, only plain block by block
|
||||||
compression is supported when writing to ETC1, and .CRN does not support ETC1.
|
compression is supported when writing to ETC1, and .CRN does not support ETC1.
|
||||||
|
|
||||||
## Compile to Javascript with Emscripten
|
|
||||||
|
|
||||||
Download and install Emscripten:
|
|
||||||
http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html
|
|
||||||
|
|
||||||
From the root directory, run:
|
|
||||||
```c
|
|
||||||
emcc -O3 emscripten/crn.cpp -I./inc -s EXPORTED_FUNCTIONS="['_malloc', '_free', '_crn_get_width', '_crn_get_height', '_crn_get_levels', '_crn_get_dxt_format', '_crn_get_bytes_per_block', '_crn_get_uncompressed_size', '_crn_decompress']" -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s ALLOW_MEMORY_GROWTH=1 --memory-init-file 0 -o crunch.js
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user