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 18, 2014
2 parents f3ba027 + 600b21d commit 7643da6
Show file tree
Hide file tree
Showing 49 changed files with 3,207 additions and 1,864 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The tool uses modern compression algorithms to achieve great compression ratios
- TBC files will be automatically decompressed into the TIS format.
- MOS files will be automatically compressed into the MBC format.
- MBC files will be automatically decompressed into the MOS format.
- MOZ files will be automatically decompressed into the MOS format.
- TIZ files will be automatically decompressed into the TIS format.

A detailed description of the TBC and MBC formats can be found in FORMATS.

Expand All @@ -29,7 +31,7 @@ Options:
-u Do not apply tile compression.
-o output Select output file or folder.
(Note: Output file works only with single input file!)
-z MOS only: Decompress MBC into compressed MOS (MOSC).
-z Decode MBC/MOZ into compressed MOS (MOSC).
-q Dec[Enc] Set quality levels for decoding and, optionally, encoding.
Supported levels: 0..9 (Defaults: 4 for decoding, 9 for encoding)
(0=fast and lower quality, 9=slow and higher quality)
Expand All @@ -54,31 +56,26 @@ Options:
-I Show file information and exit.
-V Print version number and exit.
Supported input file types: TIS, MOS, TBC, MBC
Supported input file types: TIS, MOS, TBC, MBC, TIZ, MOZ
Note: You can mix and match input files of each supported type.
```


### LICENSE

tileconv is distributed under the terms and conditions of the MIT license.
This license is specified at the top of each source file and must be preserved
in its entirety.
tileconv is distributed under the terms and conditions of the MIT license. This license is specified at the top of each source file and must be preserved in its entirety.


### BUILDING TILECONV
**Dependencies:**
- zlib (http://www.zlib.net/)
- libsquish (https://code.google.com/p/libsquish/)
- pngquant (https://github.com/pornel/pngquant/)
- libjpeg-turbo (http://libjpeg-turbo.virtualgl.org/)

External libraries and include files are assumed to be located in the
subfolders "zlib", "squish" and "pngquant". The libraries are providing their
own instructions how to compile them. Afterwards call "make" to build tileconv.
Note: You'll need a compiler that supports the C++11 standard.
External libraries and include files are assumed to be located in the subfolders "zlib", "squish", "pngquant" and "jpeg-turbo". The libraries are providing their own instructions how to compile them. libjpeg-turbo has to be compiled with the v8 API/ABI. Afterwards call "make" to build tileconv. **Note:** You'll need a compiler that supports the C++11 standard.

If you want to change paths for the external libraries or include files,
you can do so by modifying the file "config.mk" by hand.
If you want to change paths for the external libraries or include files, you can do so by modifying the file "config.mk" by hand.


### CONTACT
Expand Down
28 changes: 28 additions & 0 deletions tileconv/COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,31 @@ copyright notice and this permission notice appear in supporting
documentation. This software is provided "as is" without express or
implied warranty.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libjpeg-turbo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copyright (C)2009-2012, 2014 D. R. Commander. 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.
- Neither the name of the libjpeg-turbo Project nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

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 HOLDERS 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.
54 changes: 25 additions & 29 deletions tileconv/FORMATS
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
Description of the file formats TBC and MBC
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note: Using little-endian byte order for data fields.

Main Header (TBC):
Offset Size Description
0x0000 4 Signature ('TBC ')
0x0004 4 Version (currently supported: 'V1.0')
0x0008 4 Compression type (see below)
0x0008 4 Encoding type (see below)
0x000c 4 Tile count
0x0010 var Compressed Tile(s)

Main Header (MBC):
Offset Size Description
0x0000 4 Signature ('MBC ')
0x0004 4 Version (currently supported: 'V1.0')
0x0008 4 Compression type (see below)
0x0008 4 Encoding type (see below)
0x000c 4 Width
0x0010 4 Height
0x0014 var Compressed Tile(s)

Encoded Tile:
Offset Size Description
0x0000 2 Tile width (internally padded to a multiple of 4
for BCx pixel encodings)
0x0002 2 Tile height (internally padded to a multiple of 4
for BCx pixel encodings)
0x0004 var either BCx encoded pixel data or palette & pixel data
(depending on compression type)

Compressed Tile:
Offset Size Description
0x0000 4 Size of compressed data block
0x0004 var zlib compressed Encoded Tile (if compression type < 0x0100)
or unmodified Encoded Tile (if compression type >= 0x0100)

0x0000 4 Size of data block
0x0004 var data block (content depends on encoding type)

Supported compression types in format version V1.0:
0x0000 no pixel encoding, zlib compressed tiles
0x0001 BC1 (DXT1) pixel encoding, zlib compressed tiles
0x0002 BC2 (DXT3) pixel encoding, zlib compressed tiles
0x0003 BC3 (DXT5) pixel encoding, zlib compressed tiles
0x0100 no pixel encoding, no zlib compression
0x0101 BC1 (DXT1) pixel encoding, no zlib compression
0x0102 BC2 (DXT3) pixel encoding, no zlib compression
0x0103 BC3 (DXT5) pixel encoding, no zlib compression

Note: Compression types 0x0000 and 0x0100 store palette and indexed pixel data
as a contiguous block (1024+4096 bytes) for both formats TBC and MBC.

Note: Little-endian order is used for data fields.
Encoded Tile:
Offset Size Description
0x0000 2 Tile width
0x0002 2 Tile height
0x0004 var encoded pixel data
Note: Only used for fixed-rate data encoding types.


Encoding types supported by format version V1.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixed-rate data encoding types:
0x0000 no pixel encoding (unmodified palette and pixel data as contiguous block)
0x0001 BC1 (DXT1) pixel encoding
0x0002 BC2 (DXT3) pixel encoding
0x0003 BC3 (DXT5) pixel encoding
Encoding type bit 8:
- clear: Adding zlib compressed Encoded Tile to Compressed Tile structure
- set: Adding uncompressed Encoded Tile to Compressed Tile structure
19 changes: 11 additions & 8 deletions tileconv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
include config.mk

CXX ?= g++
CXXFLAGS = -c -Wall -O2 -std=c++11 -msse -mfpmath=sse -I$(ZLIB_INCLUDE) -I$(PNGQUANT_INCLUDE) -I$(SQUISH_INCLUDE)
LDFLAGS = -L$(ZLIB_LIB) -L$(PNGQUANT_LIB) -L$(SQUISH_LIB)
LIBS = -lz -limagequant -lsquish
CXXFLAGS = -c -Wall -O2 -std=c++11 -msse -mfpmath=sse -I$(ZLIB_INCLUDE) -I$(PNGQUANT_INCLUDE) -I$(SQUISH_INCLUDE) -I$(JPEG_INCLUDE)
LDFLAGS = -L$(ZLIB_LIB) -L$(PNGQUANT_LIB) -L$(SQUISH_LIB) -L$(JPEG_LIB)
LIBS = -lz -limagequant -lsquish -ljpeg
EXECUTABLE = tileconv

ifeq ($(OS),Windows_NT)
Expand All @@ -24,28 +24,31 @@ else
LIBS += -pthread
ifeq ($(shell uname -s),Darwin)
# A few hacks to enable proper threading support
CXXFLAGS += -D_GLIBCXX_USE_NANOSLEEP -D_GLIBCXX_USE_SCHED_YIELD
CXXFLAGS += -D_GLIBCXX_USE_NANOSLEEP
else
# Nothing to do for Linux (yet)
endif
endif

SOURCES = \
tileconv.cpp \
convert.cpp \
version.cpp \
graphics.cpp \
converter.cpp \
converter_raw.cpp \
converter_dxt.cpp \
converter_z.cpp \
converterfactory.cpp \
tilethreadpool_base.cpp \
tilethreadpool_posix.cpp \
tilethreadpool_win32.cpp \
tiledata.cpp \
compress.cpp \
jpeg.cpp \
colors.cpp \
fileio.cpp \
colorquant.cpp \
options.cpp \
dxtbase.cpp \
dxtsquish.cpp
options.cpp

OBJECTS = $(SOURCES:.cpp=.o)

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

Version: 0.4
Version: 0.5
Author: Argent77

This tool allows you to compress or decompress TIS and MOS files provided by
Expand All @@ -14,6 +14,8 @@ Supported conversions:
* TBC files will be automatically decompressed into the TIS format.
* MOS files will be automatically compressed into the MBC format.
* MBC files will be automatically decompressed into the MOS format.
* MOZ files will be automatically decompressed into the MOS format.
* TIZ files will be automatically decompressed into the TIS format.

A detailed description of the TBC and MBC formats can be found in FORMATS.

Expand All @@ -36,7 +38,7 @@ Options:
-u Do not apply tile compression.
-o output Select output file or folder.
(Note: Output file works only with single input file!)
-z MOS only: Decompress MBC into compressed MOS (MOSC).
-z Decode MBC/MOZ into compressed MOS (MOSC).
-q Dec[Enc] Set quality levels for decoding and, optionally, encoding.
Supported levels: 0..9 (Defaults: 4 for decoding, 9 for encoding)
(0=fast and lower quality, 9=slow and higher quality)
Expand All @@ -61,7 +63,7 @@ Options:
-I Show file information and exit.
-V Print version number and exit.

Supported input file types: TIS, MOS, TBC, MBC
Supported input file types: TIS, MOS, TBC, MBC, TIZ, MOZ
Note: You can mix and match input files of each supported type.


Expand All @@ -80,10 +82,12 @@ Dependencies:
- zlib (http://www.zlib.net/)
- pngquant (https://github.com/pornel/pngquant/)
- libsquish (https://code.google.com/p/libsquish/)
- libjpeg-turbo (http://libjpeg-turbo.virtualgl.org/)

External libraries and include files are assumed to be located in the
subfolders "zlib", "squish" and "pngquant". The libraries are providing their
own instructions how to compile them. Afterwards call "make" to build tileconv.
subfolders "zlib", "squish", "pngquant" and "jpeg-turbo". The libraries are
providing their own instructions how to compile them. libjpeg-turbo has to be
compiled with the v8 API/ABI. Afterwards call "make" to build tileconv.
Note: You'll need a compiler that supports the C++11 standard.

If you want to change paths for the external libraries or include files,
Expand Down Expand Up @@ -119,3 +123,8 @@ v0.4 (2014-09-09)
* Added output folder support
* Added option "-T" to treat unrecognized files as headerless TIS
* Added quality levels for encoding process

v0.5 (2014-09-18)
* Added TIZ/MOZ decompression support
* Option -T is recognized by option -I
* Incomplete output files are deleted on error
10 changes: 7 additions & 3 deletions tileconv/colorquant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ THE SOFTWARE.
#include <algorithm>
#include "colorquant.h"

namespace tc {

ColorQuant::ColorQuant() noexcept
: m_dithering(false)
, m_lastTransparent(false)
Expand Down Expand Up @@ -135,15 +137,15 @@ bool ColorQuant::quantize() noexcept
uint8_t *dstPal = (uint8_t*)m_palette;
for (unsigned i = 0; i < numCols; i++, dstPal += 4) {
liq_color px = pal->entries[i];
if (px.a < 255) {
dstPal[0] = dstPal[2] = dstPal[3] = 0;
if (px.a < m_minOpacity) {
dstPal[0] = dstPal[2] = 0;
dstPal[1] = 255;
} else {
dstPal[0] = px.r;
dstPal[1] = px.g;
dstPal[2] = px.b;
dstPal[3] = 0;
}
dstPal[3] = 0;
}

return true;
Expand Down Expand Up @@ -211,3 +213,5 @@ void ColorQuant::freeMemory() noexcept
m_liqResult = nullptr;
}
}

} // namespace tc
4 changes: 4 additions & 0 deletions tileconv/colorquant.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ THE SOFTWARE.

#include <lib/libimagequant.h>

namespace tc {

class ColorQuant
{
public:
Expand Down Expand Up @@ -139,4 +141,6 @@ class ColorQuant
liq_result *m_liqResult; // internally used, stores quantization data
};

} // namespace tc

#endif // _COLORQUANT_H_
Loading

0 comments on commit 7643da6

Please sign in to comment.