Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Sep 1, 2014
2 parents 13d6cfa + 41557b2 commit 2e4b75e
Show file tree
Hide file tree
Showing 15 changed files with 655 additions and 153 deletions.
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,29 @@ A detailed description of the TBC and MBC formats can be found in FORMATS.
Usage: tileconv [options] infile [infile2 [...]]
Options:
-e Do not halt on errors.
-s Be silent.
-v Be verbose.
-t type Select pixel encoding type.
Supported types:
0: No pixel encoding
1: BC1/DXT1 (Default)
2: BC2/DXT3
3: BC3/DXT5
-u Do not apply tile compression.
-o outfile Select output file. (Works with single input file only!)
-d Use color dithering when converting to TIS or MOS.
-z MOS only: Decompress MBC into compressed MOS (MOSC).
-V Print version number and exit.
-e Do not halt on errors.
-s Be silent.
-v Be verbose.
-t type Select pixel encoding type.
Supported types:
0: No pixel encoding
1: BC1/DXT1 (Default)
2: BC2/DXT3
3: BC3/DXT5
-u Do not apply tile compression.
-o outfile Select output file. (Works with single input file only!)
-z MOS only: Decompress MBC into compressed MOS (MOSC).
-d Enable color dithering. (deprecated, use -q instead!)
-q level Specify quality vs. speed ratio when converting MBC->MOS
or TBC->TIS. Supported levels: 0..9 (Default: 4)
(0=fast and lower quality, 9=slow and higher quality)
Applied level-dependent features:
Dithering: levels 5 to 9
Posterization: levels 0 to 2
Additional techniques: levels 4 to 9
-j num Number of parallel jobs to speed up the conversion process.
Valid numbers: 0 (autodetect), 1..256 (Default: 0)
-V Print version number and exit.
Supported input file types: TIS, MOS, TBC, MBC
Note: You can mix and match input files of each supported type.
Expand Down
13 changes: 8 additions & 5 deletions tileconv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ include config.mk
CXX ?= g++
CXXFLAGS = -c -Wall -O2 -std=c++11 -I$(ZLIB_INCLUDE) -I$(SQUISH_INCLUDE) -I$(PNGQUANT_INCLUDE)
LDFLAGS = -L$(ZLIB_LIB) -L$(SQUISH_LIB) -L$(PNGQUANT_LIB)
SOURCES = tileconv.cpp convert.cpp version.cpp graphics.cpp tiledata.cpp compress.cpp colors.cpp fileio.cpp colorquant.cpp options.cpp
LIBS =-lz -lsquish -limagequant
SOURCES = tileconv.cpp convert.cpp version.cpp graphics.cpp tilethreadpool.cpp tiledata.cpp compress.cpp colors.cpp fileio.cpp colorquant.cpp options.cpp
SYSLIBS = -pthread
LIBS =-lz -lsquish -limagequant $(SYSLIBS)
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = tileconv
ifeq ($(OS),Windows_NT)
RM = del
LDFLAGS += -static
else
RM = rm
# Mac OS X does not support static linking
ifneq ($(shell uname -s),Darwin)
LDFLAGS += -static
ifeq ($(shell uname -s),Darwin)
# A few hacks to enable proper threading support in Mac OS X
CXXFLAGS += -D_GLIBCXX_USE_NANOSLEEP -D_GLIBCXX_USE_SCHED_YIELD
else
# Nothing to do for Linux (yet)
endif
endif

Expand Down
22 changes: 19 additions & 3 deletions tileconv/README
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TILECONV
~~~~~~~~

Version: 0.2
Author: Argent77

This tool allows you to compress or decompress TIS and MOS files provided by
Expand Down Expand Up @@ -34,8 +35,17 @@ Options:
3: BC3/DXT5
-u Do not apply tile compression.
-o outfile Select output file. (Works with single input file only!)
-d Use color dithering when converting to TIS or MOS.
-z MOS only: Decompress MBC into compressed MOS (MOSC).
-d Enable color dithering. (deprecated, use -q instead!)
-q level Specify quality vs. speed ratio when converting MBC->MOS
or TBC->TIS. Supported levels: 0..9 (Default: 4)
(0=fast and lower quality, 9=slow and higher quality)
Applied level-dependent features:
Dithering: levels 5 to 9
Posterization: levels 0 to 2
Additional techniques: levels 4 to 9
-j num Number of parallel jobs to speed up the conversion process.
Valid numbers: 0 (autodetect), 1..256 (Default: 0)
-V Print version number and exit.

Supported input file types: TIS, MOS, TBC, MBC
Expand Down Expand Up @@ -71,11 +81,17 @@ CONTACT
-------

If you have questions or comments please post them on Spellhold Studios
at http://www.shsforums.net/ or contact me by private message on the same forum.
at http://www.shsforums.net/topic/57588-tileconv-a-mostis-compressor/
or contact me by private message on the same forum.


Version history
---------------

v0.1 (2014-08-27)
v0.1 (2014-08-30)
* Initial release

v0.2 (2014-09-01)
* Greatly increased conversion speed
* Added new options "-q level" and "-j num"
* Deprecated option "-d"
23 changes: 7 additions & 16 deletions tileconv/colorquant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ bool ColorQuant::quantize() noexcept
if ((m_liqResult = liq_quantize_image(m_liqAttr, m_liqImage)) == nullptr) {
return false;
}
liq_set_dithering_level(m_liqResult, m_dithering ? 1.0f : 0.0f);

if (LIQ_OK != liq_write_remapped_image(m_liqResult, m_liqImage, m_target, m_targetSize)) {
return false;
Expand Down Expand Up @@ -153,39 +152,31 @@ bool ColorQuant::quantize() noexcept

void ColorQuant::setMaxColors(int colors) noexcept
{
if (colors < 2) colors = 2;
if (colors > 256) colors = 256;
m_maxColors = colors;
m_maxColors = std::max(2, std::min(256, colors));
}

void ColorQuant::setQuality(int min, int max) noexcept
{
if (min > max) { int tmp = min; min = max; max = tmp; }
if (min < 0) min = 0; if (min > max) min = max;
if (max > 100) max = 100;
if (max < min) max = min;
min = std::max(0, std::min(100, min));
max = std::max(0, std::min(100, max));
if (min > max) std::swap(min, max);
m_qualityMin = min;
m_qualityMax = max;
}

void ColorQuant::setSpeed(int speed) noexcept
{
if (speed < 0) speed = 0;
if (speed > 10) speed = 10;
m_speed = std::max(1, std::min(10, speed));
}

void ColorQuant::setMinOpacity(int min) noexcept
{
if (min < 0) min = 0;
if (min > 255) min = 255;
m_minOpacity = min;
m_minOpacity = std::max(0, std::min(255, min));
}

void ColorQuant::setPosterization(int bits) noexcept
{
if (bits < 0) bits = 0;
if (bits > 4) bits = 4;
m_posterization = bits;
m_posterization = std::max(0, std::min(4, bits));
}

double ColorQuant::getQuantizationError() noexcept
Expand Down
3 changes: 1 addition & 2 deletions tileconv/colors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ uint32_t Colors::ARGBToPal(uint8_t *src, uint8_t *dst, uint8_t *palette,
if (!quant.setSource(src, width, height)) return 0;
if (!quant.setTarget(dst, size)) return 0;
if (!quant.setPalette(palette, 1024)) return 0;
// quant.setPosterization(2); // optimizing for RGB565 colors
quant.setDithering(getOptions().isDithering());
quant.setSpeed(10 - getOptions().getQuality()); // speed is defined as "10 - quality"

if (!quant.quantize()) return 0;
if (getOptions().isVerbose()) {
Expand Down
4 changes: 4 additions & 0 deletions tileconv/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ bool Convert::execute() noexcept
if (!getOptions().isSilent()) {
std::printf("Converting TIS -> TBC\n");
std::printf("Input: \"%s\", output: \"%s\"\n", inputFile.c_str(), outputFile.c_str());
std::printf("Converting...\n");
}
if (!gfx.tisToTBC(inputFile, outputFile)) {
retVal = false;
Expand Down Expand Up @@ -116,6 +117,7 @@ bool Convert::execute() noexcept
if (!getOptions().isSilent()) {
std::printf("Converting MOS -> MBC\n");
std::printf("Input: \"%s\", output: \"%s\"\n", inputFile.c_str(), outputFile.c_str());
std::printf("Converting...\n");
}
if (!gfx.mosToMBC(inputFile, outputFile)) {
retVal = false;
Expand Down Expand Up @@ -145,6 +147,7 @@ bool Convert::execute() noexcept
if (!getOptions().isSilent()) {
std::printf("Converting TBC -> TIS\n");
std::printf("Input: \"%s\", output: \"%s\"\n", inputFile.c_str(), outputFile.c_str());
std::printf("Converting...\n");
}
if (!gfx.tbcToTIS(inputFile, outputFile)) {
retVal = false;
Expand Down Expand Up @@ -174,6 +177,7 @@ bool Convert::execute() noexcept
if (!getOptions().isSilent()) {
std::printf("Converting MBC -> MOS\n");
std::printf("Input: \"%s\", output: \"%s\"\n", inputFile.c_str(), outputFile.c_str());
std::printf("Converting...\n");
}
if (!gfx.mbcToMOS(inputFile, outputFile)) {
retVal = false;
Expand Down
Loading

0 comments on commit 2e4b75e

Please sign in to comment.