mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
フォント圧縮テスト:compBLZとntrcompを切り替えることができるように変更。
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1816 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
f9c6e6d496
commit
b4e285d208
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
TARGET_FIRM = SYSTEMMENU
|
TARGET_FIRM = SYSTEMMENU
|
||||||
|
|
||||||
SUBDIRS = compBLZ_modified
|
SUBDIRS = compBLZ_modified \
|
||||||
|
ntrcomp
|
||||||
|
|
||||||
include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs
|
include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs
|
||||||
|
|
||||||
|
|||||||
@ -46,8 +46,10 @@ my $headerFile = "header.bin";
|
|||||||
my $digestFile = "sha1.bin";
|
my $digestFile = "sha1.bin";
|
||||||
my $signFile = "sign.bin";
|
my $signFile = "sign.bin";
|
||||||
my $tempFile = "temp.bin";
|
my $tempFile = "temp.bin";
|
||||||
my $compprog = "compBLZ.exe"; # 圧縮プログラム
|
my $compprog = "./compBLZ_modified/bin/compBLZ.exe"; # 圧縮プログラム
|
||||||
my $compoption = "-e \"\"";
|
my $compoption = "-e \"\"";
|
||||||
|
#my $compprog = "./ntrcomp/gcc/ntrcomp.exe";
|
||||||
|
#my $compoption = "-h8 -A32 -s";
|
||||||
|
|
||||||
# 後始末
|
# 後始末
|
||||||
sub deleteTemp {
|
sub deleteTemp {
|
||||||
@ -121,8 +123,7 @@ foreach ( @ARGV ) {
|
|||||||
# 圧縮
|
# 圧縮
|
||||||
# SDKのcompBLZ.exeは引数バグがあるためローカルに修正版を入れておく
|
# SDKのcompBLZ.exeは引数バグがあるためローカルに修正版を入れておく
|
||||||
my $compfile = "$_.comp";
|
my $compfile = "$_.comp";
|
||||||
#system ("${SDKROOT}/tools/bin/${compprog} $compoption $_ -o $compfile");
|
system ("${compprog} $compoption $_ -o $compfile");
|
||||||
system ("./compBLZ_modified/bin/${compprog} $compoption $_ -o $compfile");
|
|
||||||
|
|
||||||
# パディングの出力
|
# パディングの出力
|
||||||
#syswrite( INFO, pack( "x$padLen") );
|
#syswrite( INFO, pack( "x$padLen") );
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
rem
|
||||||
|
rem ***** SD起動ファイル作成ツール *****
|
||||||
|
rem
|
||||||
|
rem sdmc_launcher_writer.gcd が起動ファイルとして menu.srl しか受け付けないので
|
||||||
|
rem 引数として与えたファイルを menu.srl としてコピーする
|
||||||
|
rem
|
||||||
|
|
||||||
|
if "%1" equ "" (
|
||||||
|
echo 失敗しました。
|
||||||
|
echo ディレクトリごとドラッグアンドドロップしてください。
|
||||||
|
echo:
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
set progdir=%~dp0
|
||||||
|
|
||||||
|
del %progdir%\menu.srl
|
||||||
|
copy %1 %progdir%\menu.srl
|
||||||
@ -0,0 +1 @@
|
|||||||
|
NINTENDO PRIVATE
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
#! make -f
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Project: TwlSDK - build - tools - ntrcomp
|
||||||
|
# File: Makefile
|
||||||
|
#
|
||||||
|
# Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
#
|
||||||
|
# These coded instructions, statements, and computer programs contain
|
||||||
|
# proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
# Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
# not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
# in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
#
|
||||||
|
# $Date:: $
|
||||||
|
# $Rev$
|
||||||
|
# $Author$
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
TARGET_PLATFORM = NITRO
|
||||||
|
|
||||||
|
export TWLSDK_PLATFORM = NITRO
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||||
|
|
||||||
|
SUBDIRS += gcc
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/modulerules.x86
|
||||||
|
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
#! make -f
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Project: TwlSDK - build - tools - ntrcomp
|
||||||
|
# File: Makefile
|
||||||
|
#
|
||||||
|
# Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
#
|
||||||
|
# These coded instructions, statements, and computer programs contain
|
||||||
|
# proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
# Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
# not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
# in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
#
|
||||||
|
# $Date:: $
|
||||||
|
# $Rev$
|
||||||
|
# $Author$
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
TARGET_PLATFORM = NITRO
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||||
|
|
||||||
|
SUBDIRS += gcc
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/modulerules.x86
|
||||||
|
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
#! make -f
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Project: TwlSDK - build - tools - ntrcomp - gcc
|
||||||
|
# File: Makefile
|
||||||
|
#
|
||||||
|
# Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
#
|
||||||
|
# These coded instructions, statements, and computer programs contain
|
||||||
|
# proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
# Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
# not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
# in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
#
|
||||||
|
# $Date:: $
|
||||||
|
# $Rev$
|
||||||
|
# $Author$
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
TARGET_PLATFORM = NITRO
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||||
|
|
||||||
|
OBJECTS = ntcompress_main.o ntcompress_test.o nitroCompLib.o multipleCompLib.o rangeCoder.o
|
||||||
|
|
||||||
|
WIN32 ?= 1
|
||||||
|
|
||||||
|
ifneq ($(WIN32),0)
|
||||||
|
TARGETS = ntrcomp.exe
|
||||||
|
CC_X86 := gcc -mno-cygwin
|
||||||
|
else
|
||||||
|
TARGETS = ntrcomp
|
||||||
|
CC_X86 := gcc
|
||||||
|
endif
|
||||||
|
|
||||||
|
LDIRT_CLEAN = $(OBJECTS) $(TARGETS)
|
||||||
|
|
||||||
|
#INSTALL_DIR = $(NITRO_INSTALL_TOOLSDIR)/bin
|
||||||
|
#INSTALL_TARGETS = $(TARGETS)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# build
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
do-build: $(TARGETS)
|
||||||
|
|
||||||
|
$(TARGETS): $(OBJECTS)
|
||||||
|
$(CC_X86) $+ -o $@
|
||||||
|
|
||||||
|
ntcompress_main.o: ../src/ntcompress_main.c ../src/nitroCompLib.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
ntcompress_test.o: ../src/ntcompress_test.c ../src/nitroCompLib.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
nitroCompLib.o: ../src/nitroCompLib.c ../src/nitroCompLib.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
multipleCompLib.o: ../src/multipleCompLib.c ../src/multipleCompLib.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
rangeCoder.o: ../src/rangeCoder.c ../src/rangeCoder.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/modulerules.x86
|
||||||
|
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
#! make -f
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Project: TwlSDK - build - tools - ntrcomp - gcc
|
||||||
|
# File: Makefile
|
||||||
|
#
|
||||||
|
# Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
#
|
||||||
|
# These coded instructions, statements, and computer programs contain
|
||||||
|
# proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
# Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
# not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
# in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
#
|
||||||
|
# $Date:: $
|
||||||
|
# $Rev$
|
||||||
|
# $Author$
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
TARGET_PLATFORM = NITRO
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/commondefs
|
||||||
|
|
||||||
|
OBJECTS = ntcompress_main.o ntcompress_test.o nitroCompLib.o multipleCompLib.o rangeCoder.o
|
||||||
|
|
||||||
|
WIN32 ?= 1
|
||||||
|
|
||||||
|
ifneq ($(WIN32),0)
|
||||||
|
TARGETS = ntrcomp.exe
|
||||||
|
CC_X86 := gcc -mno-cygwin
|
||||||
|
else
|
||||||
|
TARGETS = ntrcomp
|
||||||
|
CC_X86 := gcc
|
||||||
|
endif
|
||||||
|
|
||||||
|
LDIRT_CLEAN = $(OBJECTS) $(TARGETS)
|
||||||
|
|
||||||
|
INSTALL_DIR = $(NITRO_INSTALL_TOOLSDIR)/bin
|
||||||
|
INSTALL_TARGETS = $(TARGETS)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# build
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
do-build: $(TARGETS)
|
||||||
|
|
||||||
|
$(TARGETS): $(OBJECTS)
|
||||||
|
$(CC_X86) $+ -o $@
|
||||||
|
|
||||||
|
ntcompress_main.o: ../src/ntcompress_main.c ../src/nitroCompLib.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
ntcompress_test.o: ../src/ntcompress_test.c ../src/nitroCompLib.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
nitroCompLib.o: ../src/nitroCompLib.c ../src/nitroCompLib.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
multipleCompLib.o: ../src/multipleCompLib.c ../src/multipleCompLib.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
rangeCoder.o: ../src/rangeCoder.c ../src/rangeCoder.h
|
||||||
|
$(CC_X86) -c $< -o $@
|
||||||
|
|
||||||
|
include $(TWLSDK_ROOT)/build/buildtools/modulerules.x86
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,55 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: NinTendo Compress tool
|
||||||
|
File: multipleCompLib.h
|
||||||
|
|
||||||
|
Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Date:: $
|
||||||
|
$Rev$
|
||||||
|
$Author$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// nitroCompLib.h : nitroCompLib.DLL のメイン ヘッダー ファイル
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __MULTIPLE_COMPLIB_H__
|
||||||
|
#define __MULTIPLE_COMPLIB_H__
|
||||||
|
|
||||||
|
//===========================================================================================
|
||||||
|
// インクルード
|
||||||
|
//===========================================================================================
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
//===========================================================================================
|
||||||
|
// プロトタイプ宣言
|
||||||
|
//===========================================================================================
|
||||||
|
// C++用
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
s32 LHCompRead( const u8* srcp, u32 srcSize, u8* dstp );
|
||||||
|
|
||||||
|
u32 LHCompWrite( const u8* srcp, s32 size, u8* dstp );
|
||||||
|
|
||||||
|
s32 LRCCompRead( const u8* srcp, u32 srcSize, u8* dstp );
|
||||||
|
|
||||||
|
u32 LRCCompWrite( const u8* srcp, u32 size, u8* dstp );
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __MULTIPLEX_COMPLIB_H__
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,127 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: NinTendo Compress tool
|
||||||
|
File: nitroCompLib.h
|
||||||
|
|
||||||
|
Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Date:: $
|
||||||
|
$Rev$
|
||||||
|
$Author$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// nitroCompLib.h : nitroCompLib.DLL のメイン ヘッダー ファイル
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef __NITROCOMPLIB_H__
|
||||||
|
#define __NITROCOMPLIB_H__
|
||||||
|
|
||||||
|
//===========================================================================================
|
||||||
|
// インクルード
|
||||||
|
//===========================================================================================
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define STDCALL __stdcall
|
||||||
|
#else
|
||||||
|
#define STDCALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//===========================================================================================
|
||||||
|
// プロトタイプ宣言
|
||||||
|
//===========================================================================================
|
||||||
|
// C++用
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//BOOL WINAPI DllMain( HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved);
|
||||||
|
u8* STDCALL nitroCompMalloc( u32 size );
|
||||||
|
void STDCALL nitroCompFree( u8 *p );
|
||||||
|
u32 STDCALL nitroCompress ( const u8 *srcp, u32 srcSize, u8 *dstp, char *compList, u8 rawHeader );
|
||||||
|
s32 STDCALL nitroDecompress( const u8 *srcp, u32 srcSize, u8 *dstp, s8 depth );
|
||||||
|
void STDCALL debugMemPrint ( FILE * fp, u8 *str, u32 size );
|
||||||
|
void STDCALL debugMemBitPrint( FILE * fp, u8 *str, u32 size );
|
||||||
|
int STDCALL matchingCheck( u8 *srcp, u32 srcSize, u8 *dstp, u32 dstSize );
|
||||||
|
u32 STDCALL nitroGetDecompFileSize( const void* srcp );
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//===========================================================================================
|
||||||
|
// 関数の使用法
|
||||||
|
//===========================================================================================
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// 圧縮後のデータを置くためのメモリ領域を確保
|
||||||
|
// 圧縮前のデータの2倍の領域を確保する
|
||||||
|
// 引数
|
||||||
|
// u32 size 圧縮前のデータサイズ
|
||||||
|
// u32 は符号無し整数型でたいていは、
|
||||||
|
// unsigned int (処理系依存)
|
||||||
|
// 返り値
|
||||||
|
// u8 * 圧縮後のデータ領域を指すポインタ
|
||||||
|
// (汎用ポインタなので、好きな型にキャスト)
|
||||||
|
// ではない
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//u8 *nitroCompMalloc(u32 size);
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// 圧縮後のデータを置いていたメモリ領域を解放
|
||||||
|
// 引数
|
||||||
|
// u8 *p 圧縮後のデータ領域を指すポインタ
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//void nitroCompFree(u8 *p);
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// データを圧縮する
|
||||||
|
// 圧縮方式、圧縮順序は引数compListを用いて指示する
|
||||||
|
// 引数
|
||||||
|
// u8 *srcp 圧縮対象データを指すポインタ
|
||||||
|
// u32 size 圧縮対象データのサイズ(単位はバイト)
|
||||||
|
// u8 *dstp 圧縮後のデータを保持するデータ領域を指すポインタ
|
||||||
|
// 十分な領域を確保しておく必要あり
|
||||||
|
// nitroCompMallocの返り値でよい
|
||||||
|
// char *compList 圧縮方式、圧縮順序を格納したリスト (C言語のヌル文字列)
|
||||||
|
// d8 : 8ビット差分フィルタ
|
||||||
|
// d16 : 16ビット差分フィルタ
|
||||||
|
// r : ランレングス符号化
|
||||||
|
// lx : LZ77.xには同一データ検索の開始点を示すオフセット
|
||||||
|
// : 2以上でなければならない.上限は255.
|
||||||
|
// h4 : 4ビット・ハフマン圧縮
|
||||||
|
// h8 : 8ビット・ハフマン圧縮
|
||||||
|
// u8 rawHeaderFlag 圧縮前のデータであることを示すヘッダ情報を付加するかどうかを
|
||||||
|
// 指示するフラグ.0であれば付加せず、1であれば、展開しきった
|
||||||
|
// データにもヘッダが付加される.
|
||||||
|
// 返り値
|
||||||
|
// 圧縮後のデータサイズ
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//u32 nitroCompress(u8 *srcp, u32 size, u8 *dstp, char *compList, u8 rawHeader);
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// データを展開する
|
||||||
|
// 展開方式、展開順序はデータのヘッダを見て判断する
|
||||||
|
// 引数
|
||||||
|
// u8 *srcp 展開対象データを指すポインタ
|
||||||
|
// u32 size 展開対象データのサイズ(単位はバイト)
|
||||||
|
// u8 *dstp 展開後のデータを保持するデータ領域を指すポインタ
|
||||||
|
// 十分な領域を確保しておく必要あり
|
||||||
|
// nitroCompMallocの返り値でよい
|
||||||
|
// u8 depth 展開する深さ(回数)
|
||||||
|
// 0未満の場合は、圧縮前データを示すヘッダ情報が得られるまで展開し続ける
|
||||||
|
// 返り値
|
||||||
|
// 展開後のデータサイズ
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
//u32 nitroDecompress(u8 *srcp, u32 size, u8 *dstp, s8 depth);
|
||||||
|
|
||||||
|
#endif // __NITROCOMPLIB_H__
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,661 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: NinTendo Compress tool
|
||||||
|
File: ntcompress_test.c
|
||||||
|
|
||||||
|
Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Date:: $
|
||||||
|
$Rev$
|
||||||
|
$Author$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if defined( _DEBUG )
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "nitroCompLib.h"
|
||||||
|
#include "multipleCompLib.h"
|
||||||
|
|
||||||
|
#define MAX_DATA_SIZE_EX 0x02000000 // 32MB
|
||||||
|
#define MAX_DATA_SIZE 0x00100000 // 1MB
|
||||||
|
//#define MAX_DATA_SIZE 0x100 // 256B
|
||||||
|
|
||||||
|
#define LOOP_CNT 100
|
||||||
|
#define LOOP_CNT_EX 4
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#define TestReport(...) (void)0
|
||||||
|
#else
|
||||||
|
#define TestReport printf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ASSERT assert
|
||||||
|
|
||||||
|
static u8* s_original;
|
||||||
|
|
||||||
|
static int TestInit( void );
|
||||||
|
static void TestLZ8( void );
|
||||||
|
static void TestRL8( void );
|
||||||
|
static void TestHuffman( void );
|
||||||
|
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
u64 x; // 乱数値
|
||||||
|
u64 mul; // 乗数
|
||||||
|
u64 add; // 加算する数
|
||||||
|
}
|
||||||
|
sRandContext;
|
||||||
|
|
||||||
|
static void InitRand32_(u64 seed)
|
||||||
|
{
|
||||||
|
sRandContext.x = seed;
|
||||||
|
sRandContext.mul = (1566083941LL << 32) + 1812433253LL;
|
||||||
|
sRandContext.add = 2531011;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 Rand32_(u32 max)
|
||||||
|
{
|
||||||
|
sRandContext.x = sRandContext.mul * sRandContext.x + sRandContext.add;
|
||||||
|
|
||||||
|
// 引数maxが定数ならばコンパイラにより最適化される。
|
||||||
|
if (max == 0)
|
||||||
|
{
|
||||||
|
return (u32)(sRandContext.x >> 32);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (u32)((((sRandContext.x >> 32) * (max >> 1)) >> 32) + (max >> 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int compare( const u8 a[], const u8 b[], int size )
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int equivalent_flag = 1;
|
||||||
|
for ( i = 0; i < size; ++i )
|
||||||
|
{
|
||||||
|
if ( a[i] != b[i] )
|
||||||
|
{
|
||||||
|
equivalent_flag = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return equivalent_flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// 元データ生成用関数
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
// LZ,Huffmanで圧縮されやすい元データを作成する。
|
||||||
|
static u32 makeOriginalDataForLZHuff( u32 seed )
|
||||||
|
{
|
||||||
|
u32 fsize;
|
||||||
|
u32 i;
|
||||||
|
|
||||||
|
TestReport("seed: %u\n", seed);
|
||||||
|
InitRand32_( seed );
|
||||||
|
(void)Rand32_( 0 );
|
||||||
|
fsize = Rand32_( MAX_DATA_SIZE );
|
||||||
|
if ( fsize <= 4 )
|
||||||
|
{
|
||||||
|
fsize += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( i = 0; i < fsize; ++i )
|
||||||
|
{
|
||||||
|
s_original[ i ] = (u8)(Rand32_(0x100) & 0xF0);
|
||||||
|
}
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// RL圧縮されやすい元データを作成する。
|
||||||
|
static u32 makeOriginalDataForRL( u32 seed )
|
||||||
|
{
|
||||||
|
u8 val;
|
||||||
|
u32 i;
|
||||||
|
u32 fsize;
|
||||||
|
|
||||||
|
TestReport("seed: %u\n", seed);
|
||||||
|
InitRand32_( seed );
|
||||||
|
(void)Rand32_( 0 );
|
||||||
|
fsize = Rand32_( MAX_DATA_SIZE );
|
||||||
|
if ( fsize <= 4 )
|
||||||
|
{
|
||||||
|
fsize += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( i = 0; i < fsize; ++i )
|
||||||
|
{
|
||||||
|
if ( (i % 4) == 0 )
|
||||||
|
{
|
||||||
|
val = (u8)Rand32_(0x100);
|
||||||
|
}
|
||||||
|
s_original[ i ] = val;
|
||||||
|
}
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 圧縮されにくい元データを作成する。
|
||||||
|
static u32 makeOriginalDataRand( u32 seed )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
u32 fsize;
|
||||||
|
|
||||||
|
TestReport("seed: %u\n", seed);
|
||||||
|
InitRand32_( seed );
|
||||||
|
(void)Rand32_( 0 );
|
||||||
|
fsize = Rand32_( MAX_DATA_SIZE );
|
||||||
|
if ( fsize <= 4 )
|
||||||
|
{
|
||||||
|
fsize += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( i = 0; i < fsize; ++i )
|
||||||
|
{
|
||||||
|
s_original[ i ] = (u8)Rand32_(0x100);
|
||||||
|
}
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// すべてが単一値の元データを作成する。
|
||||||
|
static u32 makeOriginalDataMonoValue( u32 seed )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
u32 fsize;
|
||||||
|
u8 val;
|
||||||
|
|
||||||
|
TestReport("seed: %u\n", seed);
|
||||||
|
InitRand32_( seed );
|
||||||
|
(void)Rand32_( 0 );
|
||||||
|
fsize = Rand32_( MAX_DATA_SIZE );
|
||||||
|
if ( fsize <= 4 )
|
||||||
|
{
|
||||||
|
fsize += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = (u8)Rand32_(0x100);
|
||||||
|
for ( i = 0; i < fsize; ++i )
|
||||||
|
{
|
||||||
|
s_original[ i ] = val;
|
||||||
|
}
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LZ,Huffmanで圧縮されやすい元データを作成する。
|
||||||
|
static u32 makeOriginalDataForLZHuffEx( u32 seed )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
u32 fsize;
|
||||||
|
|
||||||
|
TestReport("seed: %u\n", seed);
|
||||||
|
InitRand32_( seed );
|
||||||
|
fsize = Rand32_(MAX_DATA_SIZE_EX / 2) + (MAX_DATA_SIZE_EX / 2);
|
||||||
|
if ( fsize <= 4 )
|
||||||
|
{
|
||||||
|
fsize += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( i = 0; i < fsize; ++i )
|
||||||
|
{
|
||||||
|
s_original[ i ] = (u8)(Rand32_(0x100) & 0xF0);
|
||||||
|
}
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// RL圧縮されやすい元データを作成する。
|
||||||
|
static u32 makeOriginalDataForRLEx( u32 seed )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
u32 fsize;
|
||||||
|
u8 val;
|
||||||
|
|
||||||
|
TestReport("seed: %u\n", seed);
|
||||||
|
InitRand32_( seed );
|
||||||
|
fsize = Rand32_(MAX_DATA_SIZE_EX / 2) + (MAX_DATA_SIZE_EX / 2);
|
||||||
|
if ( fsize <= 4 )
|
||||||
|
{
|
||||||
|
fsize += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
val;
|
||||||
|
for ( i = 0; i < fsize; ++i )
|
||||||
|
{
|
||||||
|
if ( (i % 4) == 0 )
|
||||||
|
{
|
||||||
|
val = (u8)Rand32_(0x100);
|
||||||
|
}
|
||||||
|
s_original[ i ] = val;
|
||||||
|
}
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 圧縮されにくい元データを作成する。
|
||||||
|
static u32 makeOriginalDataRandEx( u32 seed )
|
||||||
|
{
|
||||||
|
u32 fsize;
|
||||||
|
u32 i;
|
||||||
|
|
||||||
|
TestReport("seed: %u\n", seed);
|
||||||
|
InitRand32_( seed );
|
||||||
|
fsize = Rand32_(MAX_DATA_SIZE_EX / 2) + (MAX_DATA_SIZE_EX / 2);
|
||||||
|
if ( fsize <= 4 )
|
||||||
|
{
|
||||||
|
fsize += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( i = 0; i < fsize; ++i )
|
||||||
|
{
|
||||||
|
s_original[ i ] = (u8)Rand32_(0x100);
|
||||||
|
}
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// すべてが単一値の元データを作成する。
|
||||||
|
static u32 makeOriginalDataMonoValueEx( u32 seed )
|
||||||
|
{
|
||||||
|
u32 fsize;
|
||||||
|
u32 i;
|
||||||
|
u8 val;
|
||||||
|
|
||||||
|
TestReport("seed: %u\n", seed);
|
||||||
|
InitRand32_( seed );
|
||||||
|
fsize = Rand32_(MAX_DATA_SIZE_EX / 2) + (MAX_DATA_SIZE_EX / 2);
|
||||||
|
if ( fsize <= 4 )
|
||||||
|
{
|
||||||
|
fsize += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = (u8)Rand32_(0x100);
|
||||||
|
for ( i = 0; i < fsize; ++i )
|
||||||
|
{
|
||||||
|
s_original[ i ] = val;
|
||||||
|
}
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef u32 (*MakeDataFunc)( u32 seed );
|
||||||
|
#define WATER_MARK 0xDeadBeaf
|
||||||
|
|
||||||
|
|
||||||
|
static void TestLZ8_template( MakeDataFunc makeDataFunc, u32 exFmt, u32 loop_cnt )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
for ( i = 0; i < loop_cnt; ++i )
|
||||||
|
{
|
||||||
|
u32 fsize = makeDataFunc( i );
|
||||||
|
|
||||||
|
u8* s_compressed = nitroCompMalloc( fsize );
|
||||||
|
u8* s_uncompressed = (u8*)malloc( fsize + 4 );
|
||||||
|
u32 sz;
|
||||||
|
|
||||||
|
TestReport("size = %d\n", fsize);
|
||||||
|
if ( ! exFmt )
|
||||||
|
{
|
||||||
|
sz = nitroCompress( s_original, fsize, s_compressed, "l2", 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sz = nitroCompress( s_original, fsize, s_compressed, "L2", 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( sz == 0 )
|
||||||
|
{
|
||||||
|
TestReport( "compress LZ fail size %d\n", fsize );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TestReport("compress LZ %d -> %d\n", fsize, sz );
|
||||||
|
*(u32*)(&s_uncompressed[ fsize ]) = WATER_MARK;
|
||||||
|
nitroDecompress( s_compressed, sz, s_uncompressed, 1 );
|
||||||
|
ASSERT( compare( s_original, s_uncompressed, (int)fsize ) );
|
||||||
|
// 展開時のオーバーアクセスをチェック
|
||||||
|
ASSERT( *(u32*)(&s_uncompressed[ fsize ]) == WATER_MARK );
|
||||||
|
}
|
||||||
|
|
||||||
|
nitroCompFree( s_compressed );
|
||||||
|
free( s_uncompressed );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestRL8_template( MakeDataFunc makeDataFunc, u32 loop_cnt )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
for ( i = 0; i < loop_cnt; ++i )
|
||||||
|
{
|
||||||
|
u32 fsize = makeDataFunc( i );
|
||||||
|
|
||||||
|
u8* s_compressed = nitroCompMalloc( fsize );
|
||||||
|
u8* s_uncompressed = (u8*)malloc( fsize + 4 );
|
||||||
|
u32 sz;
|
||||||
|
|
||||||
|
TestReport("size = %d\n", fsize);
|
||||||
|
sz = nitroCompress( s_original, fsize, s_compressed, "r", 0 );
|
||||||
|
|
||||||
|
if ( sz == 0 )
|
||||||
|
{
|
||||||
|
TestReport( "compress RL fail size %d\n", fsize );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TestReport("compress RL %d -> %d\n", fsize, sz );
|
||||||
|
*(u32*)(&s_uncompressed[ fsize ]) = WATER_MARK;
|
||||||
|
nitroDecompress( s_compressed, sz, s_uncompressed, 1 );
|
||||||
|
ASSERT( compare(s_original, s_uncompressed, (int)fsize) );
|
||||||
|
// 展開時のオーバーアクセスをチェック
|
||||||
|
ASSERT( *(u32*)(&s_uncompressed[ fsize ]) == WATER_MARK );
|
||||||
|
}
|
||||||
|
|
||||||
|
nitroCompFree( s_compressed );
|
||||||
|
free( s_uncompressed );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestHuffman_template( MakeDataFunc makeDataFunc, u8 encBit, u32 loop_cnt )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
for (i = 0; i < loop_cnt; ++i )
|
||||||
|
{
|
||||||
|
u32 fsize = makeDataFunc( i );
|
||||||
|
u8* s_compressed = nitroCompMalloc( fsize );
|
||||||
|
u8* s_uncompressed = (u8*)malloc( ((fsize + 0x3) & ~0x3) + 4 );
|
||||||
|
u32 sz;
|
||||||
|
|
||||||
|
TestReport("size = %d\n", fsize);
|
||||||
|
sz = nitroCompress( s_original, fsize, s_compressed, (encBit == 4 )? "h4" : "h8", 0 );
|
||||||
|
|
||||||
|
if ( sz == 0 )
|
||||||
|
{
|
||||||
|
TestReport( "compress Huff fail size %d\n", fsize );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TestReport("compress Huff %d -> %d\n", fsize, sz );
|
||||||
|
// ハフマン展開では末尾の4バイトアラインまではオーバーアクセスされ得る
|
||||||
|
// コードになっている
|
||||||
|
*(u32*)(&s_uncompressed[ (fsize + 0x3) & ~0x3 ]) = WATER_MARK;
|
||||||
|
nitroDecompress( s_compressed, sz, s_uncompressed, 1 );
|
||||||
|
ASSERT( compare(s_original, s_uncompressed, (int)fsize) );
|
||||||
|
// 展開時のオーバーアクセスをチェック
|
||||||
|
ASSERT( *(u32*)(&s_uncompressed[ (fsize + 0x3) & ~0x3 ]) == WATER_MARK );
|
||||||
|
}
|
||||||
|
nitroCompFree( s_compressed );
|
||||||
|
free( s_uncompressed );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void TestLH8_template( MakeDataFunc makeDataFunc, u32 exFmt, u32 loop_cnt )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
for ( i = 0; i < loop_cnt; ++i )
|
||||||
|
{
|
||||||
|
u32 fsize = makeDataFunc( i );
|
||||||
|
|
||||||
|
u8* s_compressed = nitroCompMalloc( fsize );
|
||||||
|
u8* s_uncompressed = (u8*)malloc( fsize + 4 );
|
||||||
|
u32 sz;
|
||||||
|
|
||||||
|
TestReport("size = %d\n", fsize);
|
||||||
|
sz = LHCompWrite( s_original, fsize, s_compressed );
|
||||||
|
|
||||||
|
if ( sz == 0 )
|
||||||
|
{
|
||||||
|
TestReport( "compress LH fail size %d\n", fsize );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TestReport("compress LH %d -> %d\n", fsize, sz );
|
||||||
|
*(u32*)(&s_uncompressed[ fsize ]) = WATER_MARK;
|
||||||
|
LHCompRead( s_compressed, sz, s_uncompressed );
|
||||||
|
ASSERT( compare(s_original, s_uncompressed, (int)fsize) );
|
||||||
|
// 展開時のオーバーアクセスをチェック
|
||||||
|
ASSERT( *(u32*)(&s_uncompressed[ fsize ]) == WATER_MARK );
|
||||||
|
}
|
||||||
|
|
||||||
|
nitroCompFree( s_compressed );
|
||||||
|
free( s_uncompressed );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void TestLRC8_template( MakeDataFunc makeDataFunc, u32 exFmt, u32 loop_cnt )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
for ( i = 0; i < loop_cnt; ++i )
|
||||||
|
{
|
||||||
|
u32 fsize = makeDataFunc( i );
|
||||||
|
|
||||||
|
u8* s_compressed = nitroCompMalloc( fsize );
|
||||||
|
u8* s_uncompressed = (u8*)malloc( fsize + 4 );
|
||||||
|
u32 sz;
|
||||||
|
|
||||||
|
TestReport("size = %d\n", fsize);
|
||||||
|
sz = LRCCompWrite( s_original, fsize, s_compressed );
|
||||||
|
|
||||||
|
if ( sz == 0 )
|
||||||
|
{
|
||||||
|
TestReport( "compress LRC fail size %d\n", fsize );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TestReport("compress LRC %d -> %d\n", fsize, sz );
|
||||||
|
*(u32*)(&s_uncompressed[ fsize ]) = WATER_MARK;
|
||||||
|
LRCCompRead( s_compressed, sz, s_uncompressed );
|
||||||
|
ASSERT( compare(s_original, s_uncompressed, (int)fsize) );
|
||||||
|
// 展開時のオーバーアクセスをチェック
|
||||||
|
ASSERT( *(u32*)(&s_uncompressed[ fsize ]) == WATER_MARK );
|
||||||
|
}
|
||||||
|
|
||||||
|
nitroCompFree( s_compressed );
|
||||||
|
free( s_uncompressed );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// テストメイン
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
static int TestInit( void )
|
||||||
|
{
|
||||||
|
time_t t;
|
||||||
|
s_original = (u8*)malloc( MAX_DATA_SIZE_EX + 4 );
|
||||||
|
makeOriginalDataRand( (u32)time( &t ) );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void TestLZ8_normal( void )
|
||||||
|
{
|
||||||
|
TestLZ8_template( makeOriginalDataForLZHuff, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestLZ8_random( void )
|
||||||
|
{
|
||||||
|
TestLZ8_template( makeOriginalDataRand, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestLZ8_mono( void )
|
||||||
|
{
|
||||||
|
TestLZ8_template( makeOriginalDataMonoValue, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLZ8EX_normal( void )
|
||||||
|
{
|
||||||
|
TestLZ8_template( makeOriginalDataForLZHuff, 1, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestLZ8EX_random( void )
|
||||||
|
{
|
||||||
|
TestLZ8_template( makeOriginalDataRand, 1, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestLZ8EX_mono( void )
|
||||||
|
{
|
||||||
|
TestLZ8_template( makeOriginalDataMonoValue, 1, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void TestRL8_normal( void )
|
||||||
|
{
|
||||||
|
TestRL8_template( makeOriginalDataForRL, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestRL8_random( void )
|
||||||
|
{
|
||||||
|
TestRL8_template( makeOriginalDataRand, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestRL8_mono( void )
|
||||||
|
{
|
||||||
|
TestRL8_template( makeOriginalDataMonoValue, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestHuffman8_normal( void )
|
||||||
|
{
|
||||||
|
TestHuffman_template( makeOriginalDataForLZHuff, 8, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestHuffman8_random( void )
|
||||||
|
{
|
||||||
|
TestHuffman_template( makeOriginalDataRand, 8, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestHuffman8_mono( void )
|
||||||
|
{
|
||||||
|
TestHuffman_template( makeOriginalDataMonoValue, 8, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestHuffman4_normal( void )
|
||||||
|
{
|
||||||
|
TestHuffman_template( makeOriginalDataForLZHuff, 4, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestHuffman4_random( void )
|
||||||
|
{
|
||||||
|
TestHuffman_template( makeOriginalDataRand, 4, LOOP_CNT );
|
||||||
|
}
|
||||||
|
static void TestHuffman4_mono( void )
|
||||||
|
{
|
||||||
|
TestHuffman_template( makeOriginalDataMonoValue, 4, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLZ_ex(void)
|
||||||
|
{
|
||||||
|
TestLZ8_template( makeOriginalDataForLZHuffEx, 0, LOOP_CNT_EX );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLZEX_ex(void)
|
||||||
|
{
|
||||||
|
TestLZ8_template( makeOriginalDataForLZHuffEx, 1, LOOP_CNT_EX );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestRL_ex(void)
|
||||||
|
{
|
||||||
|
TestRL8_template( makeOriginalDataForRLEx, LOOP_CNT_EX );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestHuffman8_ex(void)
|
||||||
|
{
|
||||||
|
TestHuffman_template( makeOriginalDataForLZHuffEx, 8, LOOP_CNT_EX );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestHuffman4_ex(void)
|
||||||
|
{
|
||||||
|
TestHuffman_template( makeOriginalDataForLZHuffEx, 4, LOOP_CNT_EX );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLH_normal(void)
|
||||||
|
{
|
||||||
|
TestLH8_template( makeOriginalDataForLZHuff, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLH_random(void)
|
||||||
|
{
|
||||||
|
TestLH8_template( makeOriginalDataRand, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLH_mono(void)
|
||||||
|
{
|
||||||
|
TestLH8_template( makeOriginalDataMonoValue, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLRC_normal(void)
|
||||||
|
{
|
||||||
|
TestLRC8_template( makeOriginalDataForLZHuff, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLRC_random(void)
|
||||||
|
{
|
||||||
|
TestLRC8_template( makeOriginalDataRand, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestLRC_mono(void)
|
||||||
|
{
|
||||||
|
TestLRC8_template( makeOriginalDataMonoValue, 0, LOOP_CNT );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined( _DEBUG ) */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: ntcompress_test
|
||||||
|
|
||||||
|
Description: テストメイン
|
||||||
|
|
||||||
|
Arguments: None.
|
||||||
|
|
||||||
|
Returns: None.
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
void ntcompress_test( void )
|
||||||
|
{
|
||||||
|
#if defined( _DEBUG )
|
||||||
|
TestInit();
|
||||||
|
|
||||||
|
TestLH_normal();
|
||||||
|
TestLH_random();
|
||||||
|
TestLH_mono ();
|
||||||
|
TestLRC_normal();
|
||||||
|
TestLRC_random();
|
||||||
|
TestLRC_mono ();
|
||||||
|
|
||||||
|
TestLZ8EX_normal();
|
||||||
|
TestLZ8EX_random();
|
||||||
|
TestLZ8EX_mono ();
|
||||||
|
TestLZ8_normal();
|
||||||
|
TestLZ8_random();
|
||||||
|
TestLZ8_mono ();
|
||||||
|
TestRL8_normal();
|
||||||
|
TestRL8_random();
|
||||||
|
TestRL8_mono ();
|
||||||
|
TestHuffman8_normal();
|
||||||
|
TestHuffman8_random();
|
||||||
|
TestHuffman8_mono ();
|
||||||
|
TestHuffman4_normal();
|
||||||
|
TestHuffman4_random();
|
||||||
|
TestHuffman4_mono ();
|
||||||
|
TestLZ_ex();
|
||||||
|
TestLZEX_ex();
|
||||||
|
TestRL_ex();
|
||||||
|
TestHuffman8_ex();
|
||||||
|
TestHuffman4_ex();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: NinTendo Compress tool
|
||||||
|
File: ntcompress_test.h
|
||||||
|
|
||||||
|
Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Date:: $
|
||||||
|
$Rev$
|
||||||
|
$Author$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
#ifndef NTCOMPRESS_TEST_H__
|
||||||
|
#define NTCOMPRESS_TEST_H__
|
||||||
|
|
||||||
|
void ntcompress_test( void );
|
||||||
|
|
||||||
|
#endif // NTCOMPRESS_TEST_H__
|
||||||
|
|
||||||
@ -0,0 +1,539 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: NinTendo Compress tool
|
||||||
|
File: rangeCoder.c
|
||||||
|
|
||||||
|
Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Date:: $
|
||||||
|
$Rev$
|
||||||
|
$Author$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "rangeCoder.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 freq[ 0x100 ];
|
||||||
|
u32 low_cnt[ 0x100 ];
|
||||||
|
u32 total;
|
||||||
|
}
|
||||||
|
RCCompressionInfo;
|
||||||
|
|
||||||
|
// レンジコーダ状態構造体
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 low;
|
||||||
|
u32 range;
|
||||||
|
u32 code; // 展開時のみ使用
|
||||||
|
u8 carry; // 圧縮時のみ使用
|
||||||
|
u32 carry_cnt; // 圧縮時のみ使用
|
||||||
|
}
|
||||||
|
RCState;
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_RANGE 0x80000000
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: RCInitInfo_
|
||||||
|
Description:
|
||||||
|
Arguments: info
|
||||||
|
Returns: None.
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
RCInitInfo_( RCCompressionInfo* info, BOOL adaptive )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
|
||||||
|
if ( adaptive )
|
||||||
|
// 適応型レンジコーダ
|
||||||
|
{
|
||||||
|
for ( i = 0; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
info->freq[ i ] = 1;
|
||||||
|
info->low_cnt[ i ] = i;
|
||||||
|
}
|
||||||
|
info->total = 0x100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// 静的レンジコーダ
|
||||||
|
{
|
||||||
|
for ( i = 0; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
info->freq[ i ] = 0;
|
||||||
|
info->low_cnt[ i ] = 0;
|
||||||
|
}
|
||||||
|
info->total = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: RCCount_
|
||||||
|
Description:
|
||||||
|
Arguments: info
|
||||||
|
srcp
|
||||||
|
size
|
||||||
|
Returns: None.
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
RCCount_( RCCompressionInfo* info, const u8* srcp, u32 size )
|
||||||
|
{
|
||||||
|
u32 srcCnt = 0;
|
||||||
|
u32 i;
|
||||||
|
|
||||||
|
while ( srcCnt < size )
|
||||||
|
{
|
||||||
|
info->freq[ srcp[ srcCnt ] ]++;
|
||||||
|
info->total++;
|
||||||
|
srcCnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0x10000へ正規化
|
||||||
|
#define NORMAL_FREQ 0x10000
|
||||||
|
{
|
||||||
|
f32 rate = (f32)NORMAL_FREQ / info->total;
|
||||||
|
u32 max_i = 0;
|
||||||
|
u32 max_freq = 0;
|
||||||
|
|
||||||
|
info->total = 0;
|
||||||
|
for ( i = 0; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
u32 orig = info->freq[ i ];
|
||||||
|
info->freq[ i ] = (u32)(rate * info->freq[ i ] + 0.5f);
|
||||||
|
if ( orig != 0 && info->freq[ i ] == 0 )
|
||||||
|
{
|
||||||
|
info->freq[ i ] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
info->total += info->freq[ i ];
|
||||||
|
if ( info->freq[ i ] >= max_freq )
|
||||||
|
{
|
||||||
|
max_i = i;
|
||||||
|
max_freq = info->freq[ i ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( info->total > NORMAL_FREQ )
|
||||||
|
{
|
||||||
|
info->freq[ max_i ] -= (info->total - NORMAL_FREQ);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info->freq[ max_i ] += (NORMAL_FREQ - info->total);
|
||||||
|
}
|
||||||
|
info->total = NORMAL_FREQ;
|
||||||
|
}
|
||||||
|
#undef NORMAL_FREQ
|
||||||
|
|
||||||
|
info->low_cnt[ 0 ] = 0;
|
||||||
|
|
||||||
|
for ( i = 1; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
info->low_cnt[ i ] = info->low_cnt[ i - 1 ] + info->freq[ i - 1 ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: RCAAddCount_
|
||||||
|
|
||||||
|
Description: 適応型レンジコーダの頻度テーブルを更新します。
|
||||||
|
|
||||||
|
Arguments: info
|
||||||
|
val
|
||||||
|
|
||||||
|
Returns: None.
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
RCAAddCount_( RCCompressionInfo* info, u8 val )
|
||||||
|
{
|
||||||
|
u32 i;
|
||||||
|
|
||||||
|
info->freq[ val ]++;
|
||||||
|
info->total++;
|
||||||
|
for ( i = val + 1; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
info->low_cnt[ i ]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// トータルが最大値を越えた場合には、再構成する。
|
||||||
|
if ( info->total >= 0x00010000 )
|
||||||
|
{
|
||||||
|
if ( info->freq[ 0 ] > 1 )
|
||||||
|
{
|
||||||
|
info->freq[ 0 ] = info->freq[ 0 ] / 2;
|
||||||
|
}
|
||||||
|
info->low_cnt[ 0 ] = 0;
|
||||||
|
info->total = info->freq[ 0 ];
|
||||||
|
|
||||||
|
for ( i = 1; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
if ( info->freq[ i ] > 1 )
|
||||||
|
{
|
||||||
|
info->freq[ i ] >>= 1;
|
||||||
|
}
|
||||||
|
info->low_cnt[ i ] = info->low_cnt[ i - 1 ] + info->freq[ i - 1 ];
|
||||||
|
info->total += info->freq[ i ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: RCCompWrite
|
||||||
|
|
||||||
|
Description: レンジコーダの圧縮(テーブル型)
|
||||||
|
|
||||||
|
Arguments: srcp
|
||||||
|
size
|
||||||
|
dstp
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
s32
|
||||||
|
RCCompWrite_( const u8* srcp, u32 size, u8* dstp, BOOL adaptive )
|
||||||
|
{
|
||||||
|
#define MIN_RANGE 0x01000000
|
||||||
|
static RCCompressionInfo sInfo;
|
||||||
|
u32 srcCnt = 0;
|
||||||
|
u32 dstCnt = 0;
|
||||||
|
u32 low, range;
|
||||||
|
u8 carry;
|
||||||
|
u32 carry_cnt;
|
||||||
|
u32 i;
|
||||||
|
|
||||||
|
// ワークの初期化
|
||||||
|
RCInitInfo_( &sInfo, adaptive );
|
||||||
|
|
||||||
|
if ( ! adaptive )
|
||||||
|
{
|
||||||
|
// 出現頻度を計算
|
||||||
|
RCCount_( &sInfo, srcp, size );
|
||||||
|
}
|
||||||
|
|
||||||
|
// 開始Rangeが0x80000000なので、初回いきなり桁上げが発生することはない
|
||||||
|
low = 0;
|
||||||
|
range = MAX_RANGE;
|
||||||
|
carry = 0;
|
||||||
|
carry_cnt = 0;
|
||||||
|
|
||||||
|
// ヘッダ出力
|
||||||
|
dstp[ dstCnt++ ] = LRC_CODE_HEADER;
|
||||||
|
if ( size > 0x1000000 )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = 0;
|
||||||
|
dstp[ dstCnt++ ] = 0;
|
||||||
|
dstp[ dstCnt++ ] = 0;
|
||||||
|
}
|
||||||
|
dstp[ dstCnt++ ] = (u8)( size );
|
||||||
|
dstp[ dstCnt++ ] = (u8)( size >> 8 );
|
||||||
|
dstp[ dstCnt++ ] = (u8)( size >> 16 );
|
||||||
|
if ( size > 0x1000000 )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = (u8)( size >> 24 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! adaptive )
|
||||||
|
{
|
||||||
|
// 頻度テーブルの出力(16bitリトルエンディアン)
|
||||||
|
for ( i = 0; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = (u8)( sInfo.freq[ i ] );
|
||||||
|
dstp[ dstCnt++ ] = (u8)( sInfo.freq[ i ] >> 8 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// コードの出力
|
||||||
|
while ( srcCnt < size )
|
||||||
|
{
|
||||||
|
u8 val = srcp[ srcCnt++ ];
|
||||||
|
u32 temp = range / sInfo.total;
|
||||||
|
u32 prevLow = low;
|
||||||
|
low = low + sInfo.low_cnt[ val ] * temp;
|
||||||
|
range = sInfo.freq[ val ] * temp;
|
||||||
|
|
||||||
|
if ( adaptive )
|
||||||
|
{
|
||||||
|
// 出現頻度テーブルを更新
|
||||||
|
RCAAddCount_( &sInfo, val );
|
||||||
|
}
|
||||||
|
|
||||||
|
// 桁上がりが発生する場合の処理
|
||||||
|
if ( prevLow > low )
|
||||||
|
{
|
||||||
|
// キャリーを1繰上げ
|
||||||
|
++carry;
|
||||||
|
// キャリーと(キャリーカウンタ - 1)分の0x00を出力します。
|
||||||
|
if ( carry_cnt > 1 )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = carry;
|
||||||
|
--carry_cnt;
|
||||||
|
carry = 0x00;
|
||||||
|
}
|
||||||
|
while ( carry_cnt > 1 )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = 0x00;
|
||||||
|
--carry_cnt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rangeの上位1バイトが空になったら桁上げ
|
||||||
|
while ( range < MIN_RANGE )
|
||||||
|
{
|
||||||
|
u8 candidate = (u8)( low >> 24 );
|
||||||
|
|
||||||
|
// 次のキャリーが0xFFの場合は更に桁上げがあり得るのでcarryを出力せずにcarry_cntだけ増やす
|
||||||
|
if ( candidate == 0xFF )
|
||||||
|
{
|
||||||
|
++carry_cnt;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// 次のキャリーが0xFFではない場合はcarryを出力する
|
||||||
|
{
|
||||||
|
// carryと(carry_cnt - 1)分の0xFFを出力する
|
||||||
|
if ( carry_cnt > 0 )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = carry;
|
||||||
|
--carry_cnt;
|
||||||
|
}
|
||||||
|
while ( carry_cnt > 0 )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = 0xFF;
|
||||||
|
--carry_cnt;
|
||||||
|
}
|
||||||
|
// 新しいcarryに置き換え
|
||||||
|
carry = candidate;
|
||||||
|
carry_cnt = 1;
|
||||||
|
}
|
||||||
|
low <<= 8;
|
||||||
|
range <<= 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( carry_cnt > 0 )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = carry;
|
||||||
|
--carry_cnt;
|
||||||
|
}
|
||||||
|
while ( carry_cnt > 0 )
|
||||||
|
{
|
||||||
|
dstp[ dstCnt++ ] = 0xFF;
|
||||||
|
--carry_cnt;
|
||||||
|
}
|
||||||
|
dstp[ dstCnt++ ] = (u8)( (low >> 24) & 0xFF );
|
||||||
|
dstp[ dstCnt++ ] = (u8)( (low >> 16) & 0xFF );
|
||||||
|
dstp[ dstCnt++ ] = (u8)( (low >> 8 ) & 0xFF );
|
||||||
|
dstp[ dstCnt++ ] = (u8)( (low >> 0 ) & 0xFF );
|
||||||
|
|
||||||
|
return dstCnt;
|
||||||
|
#undef MIN_RANGE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: RCACompWrite
|
||||||
|
|
||||||
|
Description: レンジコーダの圧縮(適応型)
|
||||||
|
|
||||||
|
Arguments: srcp
|
||||||
|
size
|
||||||
|
dstp
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
s32
|
||||||
|
RCCompWrite( const u8* srcp, u32 size, u8* dstp )
|
||||||
|
{
|
||||||
|
return RCCompWrite_( srcp, size, dstp, FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
s32
|
||||||
|
RCACompWrite( const u8* srcp, u32 size, u8* dstp )
|
||||||
|
{
|
||||||
|
return RCCompWrite_( srcp, size, dstp, TRUE );
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8
|
||||||
|
SearchRC_( RCCompressionInfo* info, u32 code, u32 range, u32 low )
|
||||||
|
{
|
||||||
|
#define TABLE_SIZE 0x100
|
||||||
|
u32 codeVal = code - low;
|
||||||
|
u32 i;
|
||||||
|
u32 temp = range / info->total;
|
||||||
|
u32 tempVal = codeVal / temp;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// TODO: とりあえず線形探索、二分探索にするべき
|
||||||
|
for ( i = 0; i < TABLE_SIZE - 1; i++ )
|
||||||
|
{
|
||||||
|
if ( info->low_cnt[ i + 1 ] > tempVal )
|
||||||
|
{
|
||||||
|
while ( info->freq[ i ] == 0 )
|
||||||
|
{
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
return (u8)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TABLE_SIZE - 1;
|
||||||
|
#else
|
||||||
|
// 二分探索
|
||||||
|
u32 left = 0;
|
||||||
|
u32 right = TABLE_SIZE - 1;
|
||||||
|
|
||||||
|
while ( left < right )
|
||||||
|
{
|
||||||
|
i = (left + right) / 2;
|
||||||
|
|
||||||
|
if ( info->low_cnt[ i ] > tempVal )
|
||||||
|
{
|
||||||
|
right = i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
left = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i = left;
|
||||||
|
while ( info->low_cnt[ i ] > tempVal )
|
||||||
|
{
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
return (u8)i;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: RCCompRead
|
||||||
|
|
||||||
|
Description: レンジコーダ展開(テーブル型)
|
||||||
|
|
||||||
|
Arguments: srcp
|
||||||
|
size
|
||||||
|
dstp
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
s32
|
||||||
|
RCCompRead_( const u8* srcp, u32 srcSize, u8* dstp, BOOL adaptive )
|
||||||
|
{
|
||||||
|
#define MIN_RANGE 0x01000000
|
||||||
|
static RCCompressionInfo sInfo;
|
||||||
|
|
||||||
|
u32 dstSize = *(u32*)srcp >> 8;
|
||||||
|
u32 dstCnt = 0;
|
||||||
|
u32 srcCnt = 0;
|
||||||
|
u32 i;
|
||||||
|
u32 code, range, low;
|
||||||
|
|
||||||
|
if ( srcSize < 4 )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
srcCnt = 4;
|
||||||
|
if ( dstSize == 0 )
|
||||||
|
{
|
||||||
|
dstSize = *(u32*)&srcp[ srcCnt ];
|
||||||
|
srcCnt += 4;
|
||||||
|
if ( srcSize < 8 )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( srcSize < sizeof(u16) * 0x100 + srcCnt )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ワークの初期化
|
||||||
|
if ( adaptive )
|
||||||
|
{
|
||||||
|
RCInitInfo_( &sInfo, TRUE );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sInfo.total = 0;
|
||||||
|
for ( i = 0; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
sInfo.freq[ i ] = *(u16*)&srcp[ srcCnt ];
|
||||||
|
srcCnt += 2;
|
||||||
|
sInfo.total += sInfo.freq[ i ];
|
||||||
|
}
|
||||||
|
sInfo.low_cnt[ 0 ] = 0;
|
||||||
|
for ( i = 1; i < 0x100; i++ )
|
||||||
|
{
|
||||||
|
sInfo.low_cnt[ i ] = sInfo.low_cnt[ i - 1 ] + sInfo.freq[ i - 1 ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
code = (u32)((srcp[ srcCnt ] << 24) | (srcp[ srcCnt + 1 ] << 16) |
|
||||||
|
(srcp[ srcCnt + 2 ] << 8) | (srcp[ srcCnt + 3 ]));
|
||||||
|
range = MAX_RANGE;
|
||||||
|
low = 0;
|
||||||
|
srcCnt += 4;
|
||||||
|
|
||||||
|
while ( dstCnt < dstSize )
|
||||||
|
{
|
||||||
|
u8 val = SearchRC_( &sInfo, code, range, low );
|
||||||
|
|
||||||
|
dstp[ dstCnt++ ] = val;
|
||||||
|
|
||||||
|
{
|
||||||
|
u32 tmp;
|
||||||
|
tmp = range / sInfo.total;
|
||||||
|
low = low + sInfo.low_cnt[ val ] * tmp;
|
||||||
|
range = sInfo.freq[ val ] * tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( adaptive )
|
||||||
|
{
|
||||||
|
// 出現頻度テーブルを更新
|
||||||
|
RCAAddCount_( &sInfo, val );
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( range < MIN_RANGE )
|
||||||
|
{
|
||||||
|
code <<= 8;
|
||||||
|
code += srcp[ srcCnt++ ];
|
||||||
|
range <<= 8;
|
||||||
|
low <<= 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dstSize;
|
||||||
|
#undef MIN_RANGE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: RCACompRead
|
||||||
|
|
||||||
|
Description: レンジコーダ展開(適応型)
|
||||||
|
|
||||||
|
Arguments: srcp
|
||||||
|
size
|
||||||
|
dstp
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
s32
|
||||||
|
RCCompRead( const u8* srcp, u32 srcSize, u8* dstp )
|
||||||
|
{
|
||||||
|
return RCCompRead_( srcp, srcSize, dstp, FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
s32
|
||||||
|
RCACompRead( const u8* srcp, u32 srcSize, u8* dstp )
|
||||||
|
{
|
||||||
|
return RCCompRead_( srcp, srcSize, dstp, TRUE );
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: NinTendo Compress tool
|
||||||
|
File: rangeCoder.h
|
||||||
|
|
||||||
|
Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Date:: $
|
||||||
|
$Rev$
|
||||||
|
$Author$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#ifndef __NTCOMPRESS_RANGE_CODER_H__
|
||||||
|
#define __NTCOMPRESS_RANGE_CODER_H__
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Name: RCCompWrite
|
||||||
|
|
||||||
|
Description: ƒŒƒ“ƒWƒR<EFBFBD>[ƒ_‚̈³<EFBFBD>k
|
||||||
|
|
||||||
|
Arguments: srcp
|
||||||
|
size
|
||||||
|
dstp
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
s32
|
||||||
|
RCCompWrite( const u8* srcp, u32 size, u8* dstp );
|
||||||
|
|
||||||
|
s32
|
||||||
|
RCCompRead( const u8* srcp, u32 srcSize, u8* dstp );
|
||||||
|
|
||||||
|
s32
|
||||||
|
RCACompWrite( const u8* srcp, u32 size, u8* dstp );
|
||||||
|
|
||||||
|
s32
|
||||||
|
RCACompRead( const u8* srcp, u32 srcSize, u8* dstp );
|
||||||
|
|
||||||
|
#endif // __NTCOMPRESS_RANGE_CODER_H__
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
/*---------------------------------------------------------------------------*
|
||||||
|
Project: NinTendo Compress tool
|
||||||
|
File: types.h
|
||||||
|
|
||||||
|
Copyright 2007 Nintendo. All rights reserved.
|
||||||
|
|
||||||
|
These coded instructions, statements, and computer programs contain
|
||||||
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
||||||
|
Company Ltd., and are protected by Federal copyright law. They may
|
||||||
|
not be disclosed to third parties or copied or duplicated in any form,
|
||||||
|
in whole or in part, without the prior written consent of Nintendo.
|
||||||
|
|
||||||
|
$Date:: $
|
||||||
|
$Rev$
|
||||||
|
$Author$
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef __NTCOMPRESS_TYPES_H__
|
||||||
|
#define __NTCOMPRESS_TYPES_H__
|
||||||
|
|
||||||
|
//===========================================================================================
|
||||||
|
// Œ^’è‹`
|
||||||
|
//===========================================================================================
|
||||||
|
typedef unsigned char u8;
|
||||||
|
typedef unsigned short u16;
|
||||||
|
typedef unsigned long u32;
|
||||||
|
typedef signed char s8;
|
||||||
|
typedef signed short s16;
|
||||||
|
typedef signed long s32;
|
||||||
|
typedef float f32;
|
||||||
|
typedef unsigned long BOOL;
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
#define DIFF_CODE_HEADER (0x80)
|
||||||
|
#define LZ_CODE_HEADER (0x10)
|
||||||
|
#define HUFF_CODE_HEADER (0x20)
|
||||||
|
#define RL_CODE_HEADER (0x30)
|
||||||
|
#define LH_CODE_HEADER (0x40)
|
||||||
|
#define LRC_CODE_HEADER (0x50)
|
||||||
|
#define CODE_HEADER_MASK (0xF0)
|
||||||
|
|
||||||
|
|
||||||
|
#if defined( __GNUC__ )
|
||||||
|
typedef unsigned long long int u64;
|
||||||
|
typedef signed long long int s64;
|
||||||
|
#define INLINE inline
|
||||||
|
#define ASSERT(x) (void)0
|
||||||
|
#else
|
||||||
|
#include <assert.h>
|
||||||
|
#define INLINE __inline
|
||||||
|
#define ASSERT assert
|
||||||
|
typedef unsigned __int64 u64;
|
||||||
|
typedef signed __int64 s64;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __NTCOMPRESS_TYPES_H__
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ntcompress", "ntcompress.vcproj", "{FA042C1E-4CB1-4B8A-87A6-B46B4222605E}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfiguration) = preSolution
|
||||||
|
Debug = Debug
|
||||||
|
Release = Release
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfiguration) = postSolution
|
||||||
|
{FA042C1E-4CB1-4B8A-87A6-B46B4222605E}.Debug.ActiveCfg = Debug|Win32
|
||||||
|
{FA042C1E-4CB1-4B8A-87A6-B46B4222605E}.Debug.Build.0 = Debug|Win32
|
||||||
|
{FA042C1E-4CB1-4B8A-87A6-B46B4222605E}.Release.ActiveCfg = Release|Win32
|
||||||
|
{FA042C1E-4CB1-4B8A-87A6-B46B4222605E}.Release.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@ -0,0 +1,179 @@
|
|||||||
|
<?xml version="1.0" encoding="shift_jis"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="7.10"
|
||||||
|
Name="ntcompress"
|
||||||
|
ProjectGUID="{FA042C1E-4CB1-4B8A-87A6-B46B4222605E}"
|
||||||
|
SccProjectName=""
|
||||||
|
SccLocalPath="">
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"/>
|
||||||
|
</Platforms>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="1"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||||
|
StringPooling="TRUE"
|
||||||
|
RuntimeLibrary="4"
|
||||||
|
EnableFunctionLevelLinking="TRUE"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Release/ntrcomp.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="TRUE"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile=".\Release/ntrcomp.exe"
|
||||||
|
LinkIncremental="1"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
ProgramDatabaseFile=".\Release/ntrcomp.pdb"
|
||||||
|
SubSystem="1"
|
||||||
|
TargetMachine="1"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
TypeLibraryName=".\Release/ntrcomp.tlb"
|
||||||
|
HeaderFileName=""/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="1041"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
OutputDirectory=".\Debug"
|
||||||
|
IntermediateDirectory=".\Debug"
|
||||||
|
ConfigurationType="1"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||||
|
BasicRuntimeChecks="3"
|
||||||
|
RuntimeLibrary="5"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Debug/ntrcomp.pch"
|
||||||
|
AssemblerListingLocation=".\Debug/"
|
||||||
|
ObjectFile=".\Debug/"
|
||||||
|
ProgramDataBaseFileName=".\Debug/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
DebugInformationFormat="4"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
OutputFile=".\Debug/ntrcomp.exe"
|
||||||
|
LinkIncremental="1"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
GenerateDebugInformation="TRUE"
|
||||||
|
ProgramDatabaseFile=".\Debug/ntrcomp.pdb"
|
||||||
|
SubSystem="1"
|
||||||
|
TargetMachine="1"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
TypeLibraryName=".\Debug/ntrcomp.tlb"
|
||||||
|
HeaderFileName=""/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="_DEBUG"
|
||||||
|
Culture="1041"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\multipleCompLib.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\multipleCompLib.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\nitroCompLib.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\nitroCompLib.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\ntcompress_main.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\ntcompress_test.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\ntcompress_test.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\rangeCoder.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\rangeCoder.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\types.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl">
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Resource Files"
|
||||||
|
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
||||||
Loading…
Reference in New Issue
Block a user