Smoke:
* cache for low res (deactivating high res for now) * new way of view3d rendering of smoke (no longer 3 axes) -using 3dtexture now (introduced into gpu/intern) * introducing LZO and LZMA libs into extern (makefiles missing for now) * reducing memory usage after simulating for the frame ended (freeing temporary buffers) * splitting smoke into 2 modifier for the cache-sake (it cannot handle more than 1 cache on the same modifier-index) * no color on gui anymore * fixing non-power-of-2 resolutions (hopefully) * fixing select-deselect of domain drawing bug * fixing drawobject.c coding style (making Ton happy) ;-) HINT #1: If scons doesn't work -> cmakefiles are up-to-date, couldn't test scons (but i tried to mantain them, too) CODERS HINT #1: we really need a way to disable adding all modifiers through "Add Modifiers" dropdown! WARNING #1: before applying this commit, deactivate your SMOKE DOMAIN in your old files and save them then. You can open them then savely after that. WARNING #2: File and cache format of smoke can be changed, this is not final!
This commit is contained in:
Vendored
+3
@@ -37,3 +37,6 @@ ADD_SUBDIRECTORY(glew)
|
||||
IF(WITH_OPENJPEG)
|
||||
ADD_SUBDIRECTORY(libopenjpeg)
|
||||
ENDIF(WITH_OPENJPEG)
|
||||
|
||||
ADD_SUBDIRECTORY(lzo)
|
||||
ADD_SUBDIRECTORY(lzma)
|
||||
|
||||
Vendored
+2
-2
@@ -22,5 +22,5 @@ if env['WITH_BF_REDCODE'] and env['BF_REDCODE_LIB'] == '':
|
||||
if env['OURPLATFORM'] == 'linux2':
|
||||
SConscript(['binreloc/SConscript']);
|
||||
|
||||
# FFTW not needed atm - dg
|
||||
# SConscript(['fftw/SConscript'])
|
||||
SConscript(['lzo/SConscript'])
|
||||
SConscript(['lzma/SConscript'])
|
||||
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
/* 7zBuf.c -- Byte Buffer
|
||||
2008-03-28
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#include "7zBuf.h"
|
||||
|
||||
void Buf_Init(CBuf *p)
|
||||
{
|
||||
p->data = 0;
|
||||
p->size = 0;
|
||||
}
|
||||
|
||||
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)
|
||||
{
|
||||
p->size = 0;
|
||||
if (size == 0)
|
||||
{
|
||||
p->data = 0;
|
||||
return 1;
|
||||
}
|
||||
p->data = (Byte *)alloc->Alloc(alloc, size);
|
||||
if (p->data != 0)
|
||||
{
|
||||
p->size = size;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Buf_Free(CBuf *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->data);
|
||||
p->data = 0;
|
||||
p->size = 0;
|
||||
}
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
/* 7zBuf.h -- Byte Buffer
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_BUF_H
|
||||
#define __7Z_BUF_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Byte *data;
|
||||
size_t size;
|
||||
} CBuf;
|
||||
|
||||
void Buf_Init(CBuf *p);
|
||||
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
|
||||
void Buf_Free(CBuf *p, ISzAlloc *alloc);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Byte *data;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
} CDynBuf;
|
||||
|
||||
void DynBuf_Construct(CDynBuf *p);
|
||||
void DynBuf_SeekToBeg(CDynBuf *p);
|
||||
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);
|
||||
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);
|
||||
|
||||
#endif
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
/* 7zBuf2.c -- Byte Buffer
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include <string.h>
|
||||
#include "7zBuf.h"
|
||||
|
||||
void DynBuf_Construct(CDynBuf *p)
|
||||
{
|
||||
p->data = 0;
|
||||
p->size = 0;
|
||||
p->pos = 0;
|
||||
}
|
||||
|
||||
void DynBuf_SeekToBeg(CDynBuf *p)
|
||||
{
|
||||
p->pos = 0;
|
||||
}
|
||||
|
||||
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)
|
||||
{
|
||||
if (size > p->size - p->pos)
|
||||
{
|
||||
size_t newSize = p->pos + size;
|
||||
Byte *data;
|
||||
newSize += newSize / 4;
|
||||
data = (Byte *)alloc->Alloc(alloc, newSize);
|
||||
if (data == 0)
|
||||
return 0;
|
||||
p->size = newSize;
|
||||
memcpy(data, p->data, p->pos);
|
||||
alloc->Free(alloc, p->data);
|
||||
p->data = data;
|
||||
}
|
||||
memcpy(p->data + p->pos, buf, size);
|
||||
p->pos += size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->data);
|
||||
p->data = 0;
|
||||
p->size = 0;
|
||||
p->pos = 0;
|
||||
}
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
/* 7zCrc.c -- CRC32 calculation
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#include "7zCrc.h"
|
||||
|
||||
#define kCrcPoly 0xEDB88320
|
||||
UInt32 g_CrcTable[256];
|
||||
|
||||
void MY_FAST_CALL CrcGenerateTable(void)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 r = i;
|
||||
int j;
|
||||
for (j = 0; j < 8; j++)
|
||||
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
|
||||
g_CrcTable[i] = r;
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
|
||||
{
|
||||
const Byte *p = (const Byte *)data;
|
||||
for (; size > 0 ; size--, p++)
|
||||
v = CRC_UPDATE_BYTE(v, *p);
|
||||
return v;
|
||||
}
|
||||
|
||||
UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
|
||||
{
|
||||
return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
/* 7zCrc.h -- CRC32 calculation
|
||||
2008-03-13
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __7Z_CRC_H
|
||||
#define __7Z_CRC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
extern UInt32 g_CrcTable[];
|
||||
|
||||
void MY_FAST_CALL CrcGenerateTable(void);
|
||||
|
||||
#define CRC_INIT_VAL 0xFFFFFFFF
|
||||
#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)
|
||||
#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
|
||||
|
||||
UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
|
||||
UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
|
||||
|
||||
#endif
|
||||
Vendored
+263
@@ -0,0 +1,263 @@
|
||||
/* 7zFile.c -- File IO
|
||||
2008-11-22 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "7zFile.h"
|
||||
|
||||
#ifndef USE_WINDOWS_FILE
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
/*
|
||||
ReadFile and WriteFile functions in Windows have BUG:
|
||||
If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
|
||||
from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
|
||||
(Insufficient system resources exist to complete the requested service).
|
||||
Probably in some version of Windows there are problems with other sizes:
|
||||
for 32 MB (maybe also for 16 MB).
|
||||
And message can be "Network connection was lost"
|
||||
*/
|
||||
|
||||
#define kChunkSizeMax (1 << 22)
|
||||
|
||||
#endif
|
||||
|
||||
void File_Construct(CSzFile *p)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
p->handle = INVALID_HANDLE_VALUE;
|
||||
#else
|
||||
p->file = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
p->handle = CreateFileA(name,
|
||||
writeMode ? GENERIC_WRITE : GENERIC_READ,
|
||||
FILE_SHARE_READ, NULL,
|
||||
writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
|
||||
#else
|
||||
p->file = fopen(name, writeMode ? "wb+" : "rb");
|
||||
return (p->file != 0) ? 0 : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }
|
||||
WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }
|
||||
|
||||
WRes File_Close(CSzFile *p)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
if (p->handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (!CloseHandle(p->handle))
|
||||
return GetLastError();
|
||||
p->handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
#else
|
||||
if (p->file != NULL)
|
||||
{
|
||||
int res = fclose(p->file);
|
||||
if (res != 0)
|
||||
return res;
|
||||
p->file = NULL;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
WRes File_Read(CSzFile *p, void *data, size_t *size)
|
||||
{
|
||||
size_t originalSize = *size;
|
||||
if (originalSize == 0)
|
||||
return 0;
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
*size = 0;
|
||||
do
|
||||
{
|
||||
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
|
||||
DWORD processed = 0;
|
||||
BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
|
||||
data = (void *)((Byte *)data + processed);
|
||||
originalSize -= processed;
|
||||
*size += processed;
|
||||
if (!res)
|
||||
return GetLastError();
|
||||
if (processed == 0)
|
||||
break;
|
||||
}
|
||||
while (originalSize > 0);
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
*size = fread(data, 1, originalSize, p->file);
|
||||
if (*size == originalSize)
|
||||
return 0;
|
||||
return ferror(p->file);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
WRes File_Write(CSzFile *p, const void *data, size_t *size)
|
||||
{
|
||||
size_t originalSize = *size;
|
||||
if (originalSize == 0)
|
||||
return 0;
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
*size = 0;
|
||||
do
|
||||
{
|
||||
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
|
||||
DWORD processed = 0;
|
||||
BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
|
||||
data = (void *)((Byte *)data + processed);
|
||||
originalSize -= processed;
|
||||
*size += processed;
|
||||
if (!res)
|
||||
return GetLastError();
|
||||
if (processed == 0)
|
||||
break;
|
||||
}
|
||||
while (originalSize > 0);
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
*size = fwrite(data, 1, originalSize, p->file);
|
||||
if (*size == originalSize)
|
||||
return 0;
|
||||
return ferror(p->file);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
LARGE_INTEGER value;
|
||||
DWORD moveMethod;
|
||||
value.LowPart = (DWORD)*pos;
|
||||
value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */
|
||||
switch (origin)
|
||||
{
|
||||
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
|
||||
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
|
||||
case SZ_SEEK_END: moveMethod = FILE_END; break;
|
||||
default: return ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
|
||||
if (value.LowPart == 0xFFFFFFFF)
|
||||
{
|
||||
WRes res = GetLastError();
|
||||
if (res != NO_ERROR)
|
||||
return res;
|
||||
}
|
||||
*pos = ((Int64)value.HighPart << 32) | value.LowPart;
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
int moveMethod;
|
||||
int res;
|
||||
switch (origin)
|
||||
{
|
||||
case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
|
||||
case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
|
||||
case SZ_SEEK_END: moveMethod = SEEK_END; break;
|
||||
default: return 1;
|
||||
}
|
||||
res = fseek(p->file, (long)*pos, moveMethod);
|
||||
*pos = ftell(p->file);
|
||||
return res;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
WRes File_GetLength(CSzFile *p, UInt64 *length)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
DWORD sizeHigh;
|
||||
DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
|
||||
if (sizeLow == 0xFFFFFFFF)
|
||||
{
|
||||
DWORD res = GetLastError();
|
||||
if (res != NO_ERROR)
|
||||
return res;
|
||||
}
|
||||
*length = (((UInt64)sizeHigh) << 32) + sizeLow;
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
long pos = ftell(p->file);
|
||||
int res = fseek(p->file, 0, SEEK_END);
|
||||
*length = ftell(p->file);
|
||||
fseek(p->file, pos, SEEK_SET);
|
||||
return res;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* ---------- FileSeqInStream ---------- */
|
||||
|
||||
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CFileSeqInStream *p = (CFileSeqInStream *)pp;
|
||||
return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
|
||||
}
|
||||
|
||||
void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
|
||||
{
|
||||
p->s.Read = FileSeqInStream_Read;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- FileInStream ---------- */
|
||||
|
||||
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CFileInStream *p = (CFileInStream *)pp;
|
||||
return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
|
||||
}
|
||||
|
||||
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
|
||||
{
|
||||
CFileInStream *p = (CFileInStream *)pp;
|
||||
return File_Seek(&p->file, pos, origin);
|
||||
}
|
||||
|
||||
void FileInStream_CreateVTable(CFileInStream *p)
|
||||
{
|
||||
p->s.Read = FileInStream_Read;
|
||||
p->s.Seek = FileInStream_Seek;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- FileOutStream ---------- */
|
||||
|
||||
static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
|
||||
{
|
||||
CFileOutStream *p = (CFileOutStream *)pp;
|
||||
File_Write(&p->file, data, &size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void FileOutStream_CreateVTable(CFileOutStream *p)
|
||||
{
|
||||
p->s.Write = FileOutStream_Write;
|
||||
}
|
||||
Vendored
+74
@@ -0,0 +1,74 @@
|
||||
/* 7zFile.h -- File IO
|
||||
2008-11-22 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_FILE_H
|
||||
#define __7Z_FILE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#define USE_WINDOWS_FILE
|
||||
#endif
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
|
||||
/* ---------- File ---------- */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
HANDLE handle;
|
||||
#else
|
||||
FILE *file;
|
||||
#endif
|
||||
} CSzFile;
|
||||
|
||||
void File_Construct(CSzFile *p);
|
||||
WRes InFile_Open(CSzFile *p, const char *name);
|
||||
WRes OutFile_Open(CSzFile *p, const char *name);
|
||||
WRes File_Close(CSzFile *p);
|
||||
|
||||
/* reads max(*size, remain file's size) bytes */
|
||||
WRes File_Read(CSzFile *p, void *data, size_t *size);
|
||||
|
||||
/* writes *size bytes */
|
||||
WRes File_Write(CSzFile *p, const void *data, size_t *size);
|
||||
|
||||
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);
|
||||
WRes File_GetLength(CSzFile *p, UInt64 *length);
|
||||
|
||||
|
||||
/* ---------- FileInStream ---------- */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
CSzFile file;
|
||||
} CFileSeqInStream;
|
||||
|
||||
void FileSeqInStream_CreateVTable(CFileSeqInStream *p);
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeekInStream s;
|
||||
CSzFile file;
|
||||
} CFileInStream;
|
||||
|
||||
void FileInStream_CreateVTable(CFileInStream *p);
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqOutStream s;
|
||||
CSzFile file;
|
||||
} CFileOutStream;
|
||||
|
||||
void FileOutStream_CreateVTable(CFileOutStream *p);
|
||||
|
||||
#endif
|
||||
Vendored
+169
@@ -0,0 +1,169 @@
|
||||
/* 7zStream.c -- 7z Stream functions
|
||||
2008-11-23 : Igor Pavlov : Public domain */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
|
||||
{
|
||||
while (size != 0)
|
||||
{
|
||||
size_t processed = size;
|
||||
RINOK(stream->Read(stream, buf, &processed));
|
||||
if (processed == 0)
|
||||
return errorType;
|
||||
buf = (void *)((Byte *)buf + processed);
|
||||
size -= processed;
|
||||
}
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
|
||||
{
|
||||
return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
|
||||
}
|
||||
|
||||
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
|
||||
{
|
||||
size_t processed = 1;
|
||||
RINOK(stream->Read(stream, buf, &processed));
|
||||
return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
|
||||
}
|
||||
|
||||
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
|
||||
{
|
||||
Int64 t = offset;
|
||||
return stream->Seek(stream, &t, SZ_SEEK_SET);
|
||||
}
|
||||
|
||||
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
|
||||
{
|
||||
void *lookBuf;
|
||||
if (*size == 0)
|
||||
return SZ_OK;
|
||||
RINOK(stream->Look(stream, &lookBuf, size));
|
||||
memcpy(buf, lookBuf, *size);
|
||||
return stream->Skip(stream, *size);
|
||||
}
|
||||
|
||||
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
|
||||
{
|
||||
while (size != 0)
|
||||
{
|
||||
size_t processed = size;
|
||||
RINOK(stream->Read(stream, buf, &processed));
|
||||
if (processed == 0)
|
||||
return errorType;
|
||||
buf = (void *)((Byte *)buf + processed);
|
||||
size -= processed;
|
||||
}
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
|
||||
{
|
||||
return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
|
||||
}
|
||||
|
||||
static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)
|
||||
{
|
||||
SRes res = SZ_OK;
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
size_t size2 = p->size - p->pos;
|
||||
if (size2 == 0 && *size > 0)
|
||||
{
|
||||
p->pos = 0;
|
||||
size2 = LookToRead_BUF_SIZE;
|
||||
res = p->realStream->Read(p->realStream, p->buf, &size2);
|
||||
p->size = size2;
|
||||
}
|
||||
if (size2 < *size)
|
||||
*size = size2;
|
||||
*buf = p->buf + p->pos;
|
||||
return res;
|
||||
}
|
||||
|
||||
static SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)
|
||||
{
|
||||
SRes res = SZ_OK;
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
size_t size2 = p->size - p->pos;
|
||||
if (size2 == 0 && *size > 0)
|
||||
{
|
||||
p->pos = 0;
|
||||
if (*size > LookToRead_BUF_SIZE)
|
||||
*size = LookToRead_BUF_SIZE;
|
||||
res = p->realStream->Read(p->realStream, p->buf, size);
|
||||
size2 = p->size = *size;
|
||||
}
|
||||
if (size2 < *size)
|
||||
*size = size2;
|
||||
*buf = p->buf + p->pos;
|
||||
return res;
|
||||
}
|
||||
|
||||
static SRes LookToRead_Skip(void *pp, size_t offset)
|
||||
{
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
p->pos += offset;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
size_t rem = p->size - p->pos;
|
||||
if (rem == 0)
|
||||
return p->realStream->Read(p->realStream, buf, size);
|
||||
if (rem > *size)
|
||||
rem = *size;
|
||||
memcpy(buf, p->buf + p->pos, rem);
|
||||
p->pos += rem;
|
||||
*size = rem;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
|
||||
{
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
p->pos = p->size = 0;
|
||||
return p->realStream->Seek(p->realStream, pos, origin);
|
||||
}
|
||||
|
||||
void LookToRead_CreateVTable(CLookToRead *p, int lookahead)
|
||||
{
|
||||
p->s.Look = lookahead ?
|
||||
LookToRead_Look_Lookahead :
|
||||
LookToRead_Look_Exact;
|
||||
p->s.Skip = LookToRead_Skip;
|
||||
p->s.Read = LookToRead_Read;
|
||||
p->s.Seek = LookToRead_Seek;
|
||||
}
|
||||
|
||||
void LookToRead_Init(CLookToRead *p)
|
||||
{
|
||||
p->pos = p->size = 0;
|
||||
}
|
||||
|
||||
static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CSecToLook *p = (CSecToLook *)pp;
|
||||
return LookInStream_LookRead(p->realStream, buf, size);
|
||||
}
|
||||
|
||||
void SecToLook_CreateVTable(CSecToLook *p)
|
||||
{
|
||||
p->s.Read = SecToLook_Read;
|
||||
}
|
||||
|
||||
static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CSecToRead *p = (CSecToRead *)pp;
|
||||
return p->realStream->Read(p->realStream, buf, size);
|
||||
}
|
||||
|
||||
void SecToRead_CreateVTable(CSecToRead *p)
|
||||
{
|
||||
p->s.Read = SecToRead_Read;
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
#define MY_VER_MAJOR 4
|
||||
#define MY_VER_MINOR 65
|
||||
#define MY_VER_BUILD 0
|
||||
#define MY_VERSION "4.65"
|
||||
#define MY_DATE "2009-02-03"
|
||||
#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
|
||||
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE
|
||||
Vendored
+127
@@ -0,0 +1,127 @@
|
||||
/* Alloc.c -- Memory allocation functions
|
||||
2008-09-24
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Alloc.h"
|
||||
|
||||
/* #define _SZ_ALLOC_DEBUG */
|
||||
|
||||
/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
#include <stdio.h>
|
||||
int g_allocCount = 0;
|
||||
int g_allocCountMid = 0;
|
||||
int g_allocCountBig = 0;
|
||||
#endif
|
||||
|
||||
void *MyAlloc(size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
{
|
||||
void *p = malloc(size);
|
||||
fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p);
|
||||
return p;
|
||||
}
|
||||
#else
|
||||
return malloc(size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MyFree(void *address)
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address);
|
||||
#endif
|
||||
free(address);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void *MidAlloc(size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++);
|
||||
#endif
|
||||
return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
void MidFree(void *address)
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
|
||||
#endif
|
||||
if (address == 0)
|
||||
return;
|
||||
VirtualFree(address, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
#ifndef MEM_LARGE_PAGES
|
||||
#undef _7ZIP_LARGE_PAGES
|
||||
#endif
|
||||
|
||||
#ifdef _7ZIP_LARGE_PAGES
|
||||
SIZE_T g_LargePageSize = 0;
|
||||
typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
|
||||
#endif
|
||||
|
||||
void SetLargePageSize()
|
||||
{
|
||||
#ifdef _7ZIP_LARGE_PAGES
|
||||
SIZE_T size = 0;
|
||||
GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
|
||||
GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
|
||||
if (largePageMinimum == 0)
|
||||
return;
|
||||
size = largePageMinimum();
|
||||
if (size == 0 || (size & (size - 1)) != 0)
|
||||
return;
|
||||
g_LargePageSize = size;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void *BigAlloc(size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
|
||||
#endif
|
||||
|
||||
#ifdef _7ZIP_LARGE_PAGES
|
||||
if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
|
||||
{
|
||||
void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
|
||||
MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
|
||||
if (res != 0)
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
void BigFree(void *address)
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
|
||||
#endif
|
||||
|
||||
if (address == 0)
|
||||
return;
|
||||
VirtualFree(address, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
#endif
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
/* Alloc.h -- Memory allocation functions
|
||||
2008-03-13
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __COMMON_ALLOC_H
|
||||
#define __COMMON_ALLOC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *MyAlloc(size_t size);
|
||||
void MyFree(void *address);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void SetLargePageSize();
|
||||
|
||||
void *MidAlloc(size_t size);
|
||||
void MidFree(void *address);
|
||||
void *BigAlloc(size_t size);
|
||||
void BigFree(void *address);
|
||||
|
||||
#else
|
||||
|
||||
#define MidAlloc(size) MyAlloc(size)
|
||||
#define MidFree(address) MyFree(address)
|
||||
#define BigAlloc(size) MyAlloc(size)
|
||||
#define BigFree(address) MyFree(address)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+132
@@ -0,0 +1,132 @@
|
||||
/* Bcj2.c -- Converter for x86 code (BCJ2)
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bcj2.h"
|
||||
|
||||
#ifdef _LZMA_PROB32
|
||||
#define CProb UInt32
|
||||
#else
|
||||
#define CProb UInt16
|
||||
#endif
|
||||
|
||||
#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)
|
||||
#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))
|
||||
|
||||
#define kNumTopBits 24
|
||||
#define kTopValue ((UInt32)1 << kNumTopBits)
|
||||
|
||||
#define kNumBitModelTotalBits 11
|
||||
#define kBitModelTotal (1 << kNumBitModelTotalBits)
|
||||
#define kNumMoveBits 5
|
||||
|
||||
#define RC_READ_BYTE (*buffer++)
|
||||
#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }
|
||||
#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \
|
||||
{ int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}
|
||||
|
||||
#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }
|
||||
|
||||
#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
|
||||
#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;
|
||||
#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;
|
||||
|
||||
int Bcj2_Decode(
|
||||
const Byte *buf0, SizeT size0,
|
||||
const Byte *buf1, SizeT size1,
|
||||
const Byte *buf2, SizeT size2,
|
||||
const Byte *buf3, SizeT size3,
|
||||
Byte *outBuf, SizeT outSize)
|
||||
{
|
||||
CProb p[256 + 2];
|
||||
SizeT inPos = 0, outPos = 0;
|
||||
|
||||
const Byte *buffer, *bufferLim;
|
||||
UInt32 range, code;
|
||||
Byte prevByte = 0;
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)
|
||||
p[i] = kBitModelTotal >> 1;
|
||||
|
||||
buffer = buf3;
|
||||
bufferLim = buffer + size3;
|
||||
RC_INIT2
|
||||
|
||||
if (outSize == 0)
|
||||
return SZ_OK;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte b;
|
||||
CProb *prob;
|
||||
UInt32 bound;
|
||||
UInt32 ttt;
|
||||
|
||||
SizeT limit = size0 - inPos;
|
||||
if (outSize - outPos < limit)
|
||||
limit = outSize - outPos;
|
||||
while (limit != 0)
|
||||
{
|
||||
Byte b = buf0[inPos];
|
||||
outBuf[outPos++] = b;
|
||||
if (IsJ(prevByte, b))
|
||||
break;
|
||||
inPos++;
|
||||
prevByte = b;
|
||||
limit--;
|
||||
}
|
||||
|
||||
if (limit == 0 || outPos == outSize)
|
||||
break;
|
||||
|
||||
b = buf0[inPos++];
|
||||
|
||||
if (b == 0xE8)
|
||||
prob = p + prevByte;
|
||||
else if (b == 0xE9)
|
||||
prob = p + 256;
|
||||
else
|
||||
prob = p + 257;
|
||||
|
||||
IF_BIT_0(prob)
|
||||
{
|
||||
UPDATE_0(prob)
|
||||
prevByte = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 dest;
|
||||
const Byte *v;
|
||||
UPDATE_1(prob)
|
||||
if (b == 0xE8)
|
||||
{
|
||||
v = buf1;
|
||||
if (size1 < 4)
|
||||
return SZ_ERROR_DATA;
|
||||
buf1 += 4;
|
||||
size1 -= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
v = buf2;
|
||||
if (size2 < 4)
|
||||
return SZ_ERROR_DATA;
|
||||
buf2 += 4;
|
||||
size2 -= 4;
|
||||
}
|
||||
dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |
|
||||
((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);
|
||||
outBuf[outPos++] = (Byte)dest;
|
||||
if (outPos == outSize)
|
||||
break;
|
||||
outBuf[outPos++] = (Byte)(dest >> 8);
|
||||
if (outPos == outSize)
|
||||
break;
|
||||
outBuf[outPos++] = (Byte)(dest >> 16);
|
||||
if (outPos == outSize)
|
||||
break;
|
||||
outBuf[outPos++] = prevByte = (Byte)(dest >> 24);
|
||||
}
|
||||
}
|
||||
return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;
|
||||
}
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
/* Bcj2.h -- Converter for x86 code (BCJ2)
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __BCJ2_H
|
||||
#define __BCJ2_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/*
|
||||
Conditions:
|
||||
outSize <= FullOutputSize,
|
||||
where FullOutputSize is full size of output stream of x86_2 filter.
|
||||
|
||||
If buf0 overlaps outBuf, there are two required conditions:
|
||||
1) (buf0 >= outBuf)
|
||||
2) (buf0 + size0 >= outBuf + FullOutputSize).
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
SZ_ERROR_DATA - Data error
|
||||
*/
|
||||
|
||||
int Bcj2_Decode(
|
||||
const Byte *buf0, SizeT size0,
|
||||
const Byte *buf1, SizeT size1,
|
||||
const Byte *buf2, SizeT size2,
|
||||
const Byte *buf3, SizeT size3,
|
||||
Byte *outBuf, SizeT outSize);
|
||||
|
||||
#endif
|
||||
Vendored
+133
@@ -0,0 +1,133 @@
|
||||
/* Bra.c -- Converters for RISC code
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bra.h"
|
||||
|
||||
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
SizeT i;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
size -= 4;
|
||||
ip += 8;
|
||||
for (i = 0; i <= size; i += 4)
|
||||
{
|
||||
if (data[i + 3] == 0xEB)
|
||||
{
|
||||
UInt32 dest;
|
||||
UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
|
||||
src <<= 2;
|
||||
if (encoding)
|
||||
dest = ip + (UInt32)i + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)i);
|
||||
dest >>= 2;
|
||||
data[i + 2] = (Byte)(dest >> 16);
|
||||
data[i + 1] = (Byte)(dest >> 8);
|
||||
data[i + 0] = (Byte)dest;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
SizeT i;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
size -= 4;
|
||||
ip += 4;
|
||||
for (i = 0; i <= size; i += 2)
|
||||
{
|
||||
if ((data[i + 1] & 0xF8) == 0xF0 &&
|
||||
(data[i + 3] & 0xF8) == 0xF8)
|
||||
{
|
||||
UInt32 dest;
|
||||
UInt32 src =
|
||||
(((UInt32)data[i + 1] & 0x7) << 19) |
|
||||
((UInt32)data[i + 0] << 11) |
|
||||
(((UInt32)data[i + 3] & 0x7) << 8) |
|
||||
(data[i + 2]);
|
||||
|
||||
src <<= 1;
|
||||
if (encoding)
|
||||
dest = ip + (UInt32)i + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)i);
|
||||
dest >>= 1;
|
||||
|
||||
data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
|
||||
data[i + 0] = (Byte)(dest >> 11);
|
||||
data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
|
||||
data[i + 2] = (Byte)dest;
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
SizeT i;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
size -= 4;
|
||||
for (i = 0; i <= size; i += 4)
|
||||
{
|
||||
if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
|
||||
{
|
||||
UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
|
||||
((UInt32)data[i + 1] << 16) |
|
||||
((UInt32)data[i + 2] << 8) |
|
||||
((UInt32)data[i + 3] & (~3));
|
||||
|
||||
UInt32 dest;
|
||||
if (encoding)
|
||||
dest = ip + (UInt32)i + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)i);
|
||||
data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3));
|
||||
data[i + 1] = (Byte)(dest >> 16);
|
||||
data[i + 2] = (Byte)(dest >> 8);
|
||||
data[i + 3] &= 0x3;
|
||||
data[i + 3] |= dest;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
UInt32 i;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
size -= 4;
|
||||
for (i = 0; i <= size; i += 4)
|
||||
{
|
||||
if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||
|
||||
data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)
|
||||
{
|
||||
UInt32 src =
|
||||
((UInt32)data[i + 0] << 24) |
|
||||
((UInt32)data[i + 1] << 16) |
|
||||
((UInt32)data[i + 2] << 8) |
|
||||
((UInt32)data[i + 3]);
|
||||
UInt32 dest;
|
||||
|
||||
src <<= 2;
|
||||
if (encoding)
|
||||
dest = ip + i + src;
|
||||
else
|
||||
dest = src - (ip + i);
|
||||
dest >>= 2;
|
||||
|
||||
dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
|
||||
|
||||
data[i + 0] = (Byte)(dest >> 24);
|
||||
data[i + 1] = (Byte)(dest >> 16);
|
||||
data[i + 2] = (Byte)(dest >> 8);
|
||||
data[i + 3] = (Byte)dest;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
/* Bra.h -- Branch converters for executables
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __BRA_H
|
||||
#define __BRA_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/*
|
||||
These functions convert relative addresses to absolute addresses
|
||||
in CALL instructions to increase the compression ratio.
|
||||
|
||||
In:
|
||||
data - data buffer
|
||||
size - size of data
|
||||
ip - current virtual Instruction Pinter (IP) value
|
||||
state - state variable for x86 converter
|
||||
encoding - 0 (for decoding), 1 (for encoding)
|
||||
|
||||
Out:
|
||||
state - state variable for x86 converter
|
||||
|
||||
Returns:
|
||||
The number of processed bytes. If you call these functions with multiple calls,
|
||||
you must start next call with first byte after block of processed bytes.
|
||||
|
||||
Type Endian Alignment LookAhead
|
||||
|
||||
x86 little 1 4
|
||||
ARMT little 2 2
|
||||
ARM little 4 0
|
||||
PPC big 4 0
|
||||
SPARC big 4 0
|
||||
IA64 little 16 0
|
||||
|
||||
size must be >= Alignment + LookAhead, if it's not last block.
|
||||
If (size < Alignment + LookAhead), converter returns 0.
|
||||
|
||||
Example:
|
||||
|
||||
UInt32 ip = 0;
|
||||
for ()
|
||||
{
|
||||
; size must be >= Alignment + LookAhead, if it's not last block
|
||||
SizeT processed = Convert(data, size, ip, 1);
|
||||
data += processed;
|
||||
size -= processed;
|
||||
ip += processed;
|
||||
}
|
||||
*/
|
||||
|
||||
#define x86_Convert_Init(state) { state = 0; }
|
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
|
||||
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
|
||||
#endif
|
||||
Vendored
+85
@@ -0,0 +1,85 @@
|
||||
/* Bra86.c -- Converter for x86 code (BCJ)
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bra.h"
|
||||
|
||||
#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
|
||||
|
||||
const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
|
||||
const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
|
||||
|
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
|
||||
{
|
||||
SizeT bufferPos = 0, prevPosT;
|
||||
UInt32 prevMask = *state & 0x7;
|
||||
if (size < 5)
|
||||
return 0;
|
||||
ip += 5;
|
||||
prevPosT = (SizeT)0 - 1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte *p = data + bufferPos;
|
||||
Byte *limit = data + size - 4;
|
||||
for (; p < limit; p++)
|
||||
if ((*p & 0xFE) == 0xE8)
|
||||
break;
|
||||
bufferPos = (SizeT)(p - data);
|
||||
if (p >= limit)
|
||||
break;
|
||||
prevPosT = bufferPos - prevPosT;
|
||||
if (prevPosT > 3)
|
||||
prevMask = 0;
|
||||
else
|
||||
{
|
||||
prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
|
||||
if (prevMask != 0)
|
||||
{
|
||||
Byte b = p[4 - kMaskToBitNumber[prevMask]];
|
||||
if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
|
||||
{
|
||||
prevPosT = bufferPos;
|
||||
prevMask = ((prevMask << 1) & 0x7) | 1;
|
||||
bufferPos++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
prevPosT = bufferPos;
|
||||
|
||||
if (Test86MSByte(p[4]))
|
||||
{
|
||||
UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
|
||||
UInt32 dest;
|
||||
for (;;)
|
||||
{
|
||||
Byte b;
|
||||
int index;
|
||||
if (encoding)
|
||||
dest = (ip + (UInt32)bufferPos) + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)bufferPos);
|
||||
if (prevMask == 0)
|
||||
break;
|
||||
index = kMaskToBitNumber[prevMask] * 8;
|
||||
b = (Byte)(dest >> (24 - index));
|
||||
if (!Test86MSByte(b))
|
||||
break;
|
||||
src = dest ^ ((1 << (32 - index)) - 1);
|
||||
}
|
||||
p[4] = (Byte)(~(((dest >> 24) & 1) - 1));
|
||||
p[3] = (Byte)(dest >> 16);
|
||||
p[2] = (Byte)(dest >> 8);
|
||||
p[1] = (Byte)dest;
|
||||
bufferPos += 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevMask = ((prevMask << 1) & 0x7) | 1;
|
||||
bufferPos++;
|
||||
}
|
||||
}
|
||||
prevPosT = bufferPos - prevPosT;
|
||||
*state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
|
||||
return bufferPos;
|
||||
}
|
||||
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
/* BraIA64.c -- Converter for IA-64 code
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bra.h"
|
||||
|
||||
static const Byte kBranchTable[32] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 4, 6, 6, 0, 0, 7, 7,
|
||||
4, 4, 0, 0, 4, 4, 0, 0
|
||||
};
|
||||
|
||||
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
SizeT i;
|
||||
if (size < 16)
|
||||
return 0;
|
||||
size -= 16;
|
||||
for (i = 0; i <= size; i += 16)
|
||||
{
|
||||
UInt32 instrTemplate = data[i] & 0x1F;
|
||||
UInt32 mask = kBranchTable[instrTemplate];
|
||||
UInt32 bitPos = 5;
|
||||
int slot;
|
||||
for (slot = 0; slot < 3; slot++, bitPos += 41)
|
||||
{
|
||||
UInt32 bytePos, bitRes;
|
||||
UInt64 instruction, instNorm;
|
||||
int j;
|
||||
if (((mask >> slot) & 1) == 0)
|
||||
continue;
|
||||
bytePos = (bitPos >> 3);
|
||||
bitRes = bitPos & 0x7;
|
||||
instruction = 0;
|
||||
for (j = 0; j < 6; j++)
|
||||
instruction += (UInt64)data[i + j + bytePos] << (8 * j);
|
||||
|
||||
instNorm = instruction >> bitRes;
|
||||
if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
|
||||
{
|
||||
UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
|
||||
UInt32 dest;
|
||||
src |= ((UInt32)(instNorm >> 36) & 1) << 20;
|
||||
|
||||
src <<= 4;
|
||||
|
||||
if (encoding)
|
||||
dest = ip + (UInt32)i + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)i);
|
||||
|
||||
dest >>= 4;
|
||||
|
||||
instNorm &= ~((UInt64)(0x8FFFFF) << 13);
|
||||
instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
|
||||
instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
|
||||
|
||||
instruction &= (1 << bitRes) - 1;
|
||||
instruction |= (instNorm << bitRes);
|
||||
for (j = 0; j < 6; j++)
|
||||
data[i + j + bytePos] = (Byte)(instruction >> (8 * j));
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
# $Id$
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2006, Blender Foundation
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
#
|
||||
# Contributor(s): Daniel Genrich
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
SET(INC . )
|
||||
|
||||
FILE(GLOB SRC ./*.c)
|
||||
|
||||
|
||||
|
||||
BLENDERLIB(bf_lzma "${SRC}" "${INC}")
|
||||
#, libtype='blender', priority = 0 )
|
||||
Vendored
+69
@@ -0,0 +1,69 @@
|
||||
/* CpuArch.h
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __CPUARCH_H
|
||||
#define __CPUARCH_H
|
||||
|
||||
/*
|
||||
LITTLE_ENDIAN_UNALIGN means:
|
||||
1) CPU is LITTLE_ENDIAN
|
||||
2) it's allowed to make unaligned memory accesses
|
||||
if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
|
||||
about these properties of platform.
|
||||
*/
|
||||
|
||||
#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
|
||||
#define LITTLE_ENDIAN_UNALIGN
|
||||
#endif
|
||||
|
||||
#ifdef LITTLE_ENDIAN_UNALIGN
|
||||
|
||||
#define GetUi16(p) (*(const UInt16 *)(p))
|
||||
#define GetUi32(p) (*(const UInt32 *)(p))
|
||||
#define GetUi64(p) (*(const UInt64 *)(p))
|
||||
#define SetUi32(p, d) *(UInt32 *)(p) = (d);
|
||||
|
||||
#else
|
||||
|
||||
#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
|
||||
|
||||
#define GetUi32(p) ( \
|
||||
((const Byte *)(p))[0] | \
|
||||
((UInt32)((const Byte *)(p))[1] << 8) | \
|
||||
((UInt32)((const Byte *)(p))[2] << 16) | \
|
||||
((UInt32)((const Byte *)(p))[3] << 24))
|
||||
|
||||
#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
|
||||
|
||||
#define SetUi32(p, d) { UInt32 _x_ = (d); \
|
||||
((Byte *)(p))[0] = (Byte)_x_; \
|
||||
((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
|
||||
((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
|
||||
((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
|
||||
|
||||
#pragma intrinsic(_byteswap_ulong)
|
||||
#pragma intrinsic(_byteswap_uint64)
|
||||
#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
|
||||
#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
|
||||
|
||||
#else
|
||||
|
||||
#define GetBe32(p) ( \
|
||||
((UInt32)((const Byte *)(p))[0] << 24) | \
|
||||
((UInt32)((const Byte *)(p))[1] << 16) | \
|
||||
((UInt32)((const Byte *)(p))[2] << 8) | \
|
||||
((const Byte *)(p))[3] )
|
||||
|
||||
#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
|
||||
|
||||
#endif
|
||||
|
||||
#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
|
||||
|
||||
#endif
|
||||
Vendored
+751
@@ -0,0 +1,751 @@
|
||||
/* LzFind.c -- Match finder for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "LzFind.h"
|
||||
#include "LzHash.h"
|
||||
|
||||
#define kEmptyHashValue 0
|
||||
#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
|
||||
#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
|
||||
#define kNormalizeMask (~(kNormalizeStepMin - 1))
|
||||
#define kMaxHistorySize ((UInt32)3 << 30)
|
||||
|
||||
#define kStartMaxLen 3
|
||||
|
||||
static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
if (!p->directInput)
|
||||
{
|
||||
alloc->Free(alloc, p->bufferBase);
|
||||
p->bufferBase = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
|
||||
|
||||
static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
|
||||
{
|
||||
UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
|
||||
if (p->directInput)
|
||||
{
|
||||
p->blockSize = blockSize;
|
||||
return 1;
|
||||
}
|
||||
if (p->bufferBase == 0 || p->blockSize != blockSize)
|
||||
{
|
||||
LzInWindow_Free(p, alloc);
|
||||
p->blockSize = blockSize;
|
||||
p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
|
||||
}
|
||||
return (p->bufferBase != 0);
|
||||
}
|
||||
|
||||
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
|
||||
Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
|
||||
|
||||
UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
|
||||
|
||||
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
|
||||
{
|
||||
p->posLimit -= subValue;
|
||||
p->pos -= subValue;
|
||||
p->streamPos -= subValue;
|
||||
}
|
||||
|
||||
static void MatchFinder_ReadBlock(CMatchFinder *p)
|
||||
{
|
||||
if (p->streamEndWasReached || p->result != SZ_OK)
|
||||
return;
|
||||
for (;;)
|
||||
{
|
||||
Byte *dest = p->buffer + (p->streamPos - p->pos);
|
||||
size_t size = (p->bufferBase + p->blockSize - dest);
|
||||
if (size == 0)
|
||||
return;
|
||||
p->result = p->stream->Read(p->stream, dest, &size);
|
||||
if (p->result != SZ_OK)
|
||||
return;
|
||||
if (size == 0)
|
||||
{
|
||||
p->streamEndWasReached = 1;
|
||||
return;
|
||||
}
|
||||
p->streamPos += (UInt32)size;
|
||||
if (p->streamPos - p->pos > p->keepSizeAfter)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MatchFinder_MoveBlock(CMatchFinder *p)
|
||||
{
|
||||
memmove(p->bufferBase,
|
||||
p->buffer - p->keepSizeBefore,
|
||||
(size_t)(p->streamPos - p->pos + p->keepSizeBefore));
|
||||
p->buffer = p->bufferBase + p->keepSizeBefore;
|
||||
}
|
||||
|
||||
int MatchFinder_NeedMove(CMatchFinder *p)
|
||||
{
|
||||
/* if (p->streamEndWasReached) return 0; */
|
||||
return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
|
||||
}
|
||||
|
||||
void MatchFinder_ReadIfRequired(CMatchFinder *p)
|
||||
{
|
||||
if (p->streamEndWasReached)
|
||||
return;
|
||||
if (p->keepSizeAfter >= p->streamPos - p->pos)
|
||||
MatchFinder_ReadBlock(p);
|
||||
}
|
||||
|
||||
static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
|
||||
{
|
||||
if (MatchFinder_NeedMove(p))
|
||||
MatchFinder_MoveBlock(p);
|
||||
MatchFinder_ReadBlock(p);
|
||||
}
|
||||
|
||||
static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
|
||||
{
|
||||
p->cutValue = 32;
|
||||
p->btMode = 1;
|
||||
p->numHashBytes = 4;
|
||||
/* p->skipModeBits = 0; */
|
||||
p->directInput = 0;
|
||||
p->bigHash = 0;
|
||||
}
|
||||
|
||||
#define kCrcPoly 0xEDB88320
|
||||
|
||||
void MatchFinder_Construct(CMatchFinder *p)
|
||||
{
|
||||
UInt32 i;
|
||||
p->bufferBase = 0;
|
||||
p->directInput = 0;
|
||||
p->hash = 0;
|
||||
MatchFinder_SetDefaultSettings(p);
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 r = i;
|
||||
int j;
|
||||
for (j = 0; j < 8; j++)
|
||||
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
|
||||
p->crc[i] = r;
|
||||
}
|
||||
}
|
||||
|
||||
static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->hash);
|
||||
p->hash = 0;
|
||||
}
|
||||
|
||||
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
MatchFinder_FreeThisClassMemory(p, alloc);
|
||||
LzInWindow_Free(p, alloc);
|
||||
}
|
||||
|
||||
static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
|
||||
{
|
||||
size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
|
||||
if (sizeInBytes / sizeof(CLzRef) != num)
|
||||
return 0;
|
||||
return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
|
||||
}
|
||||
|
||||
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
|
||||
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
|
||||
ISzAlloc *alloc)
|
||||
{
|
||||
UInt32 sizeReserv;
|
||||
if (historySize > kMaxHistorySize)
|
||||
{
|
||||
MatchFinder_Free(p, alloc);
|
||||
return 0;
|
||||
}
|
||||
sizeReserv = historySize >> 1;
|
||||
if (historySize > ((UInt32)2 << 30))
|
||||
sizeReserv = historySize >> 2;
|
||||
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
|
||||
|
||||
p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
|
||||
p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
|
||||
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
|
||||
if (LzInWindow_Create(p, sizeReserv, alloc))
|
||||
{
|
||||
UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;
|
||||
UInt32 hs;
|
||||
p->matchMaxLen = matchMaxLen;
|
||||
{
|
||||
p->fixedHashSize = 0;
|
||||
if (p->numHashBytes == 2)
|
||||
hs = (1 << 16) - 1;
|
||||
else
|
||||
{
|
||||
hs = historySize - 1;
|
||||
hs |= (hs >> 1);
|
||||
hs |= (hs >> 2);
|
||||
hs |= (hs >> 4);
|
||||
hs |= (hs >> 8);
|
||||
hs >>= 1;
|
||||
/* hs >>= p->skipModeBits; */
|
||||
hs |= 0xFFFF; /* don't change it! It's required for Deflate */
|
||||
if (hs > (1 << 24))
|
||||
{
|
||||
if (p->numHashBytes == 3)
|
||||
hs = (1 << 24) - 1;
|
||||
else
|
||||
hs >>= 1;
|
||||
}
|
||||
}
|
||||
p->hashMask = hs;
|
||||
hs++;
|
||||
if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
|
||||
if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
|
||||
if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
|
||||
hs += p->fixedHashSize;
|
||||
}
|
||||
|
||||
{
|
||||
UInt32 prevSize = p->hashSizeSum + p->numSons;
|
||||
UInt32 newSize;
|
||||
p->historySize = historySize;
|
||||
p->hashSizeSum = hs;
|
||||
p->cyclicBufferSize = newCyclicBufferSize;
|
||||
p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);
|
||||
newSize = p->hashSizeSum + p->numSons;
|
||||
if (p->hash != 0 && prevSize == newSize)
|
||||
return 1;
|
||||
MatchFinder_FreeThisClassMemory(p, alloc);
|
||||
p->hash = AllocRefs(newSize, alloc);
|
||||
if (p->hash != 0)
|
||||
{
|
||||
p->son = p->hash + p->hashSizeSum;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
MatchFinder_Free(p, alloc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void MatchFinder_SetLimits(CMatchFinder *p)
|
||||
{
|
||||
UInt32 limit = kMaxValForNormalize - p->pos;
|
||||
UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
|
||||
if (limit2 < limit)
|
||||
limit = limit2;
|
||||
limit2 = p->streamPos - p->pos;
|
||||
if (limit2 <= p->keepSizeAfter)
|
||||
{
|
||||
if (limit2 > 0)
|
||||
limit2 = 1;
|
||||
}
|
||||
else
|
||||
limit2 -= p->keepSizeAfter;
|
||||
if (limit2 < limit)
|
||||
limit = limit2;
|
||||
{
|
||||
UInt32 lenLimit = p->streamPos - p->pos;
|
||||
if (lenLimit > p->matchMaxLen)
|
||||
lenLimit = p->matchMaxLen;
|
||||
p->lenLimit = lenLimit;
|
||||
}
|
||||
p->posLimit = p->pos + limit;
|
||||
}
|
||||
|
||||
void MatchFinder_Init(CMatchFinder *p)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < p->hashSizeSum; i++)
|
||||
p->hash[i] = kEmptyHashValue;
|
||||
p->cyclicBufferPos = 0;
|
||||
p->buffer = p->bufferBase;
|
||||
p->pos = p->streamPos = p->cyclicBufferSize;
|
||||
p->result = SZ_OK;
|
||||
p->streamEndWasReached = 0;
|
||||
MatchFinder_ReadBlock(p);
|
||||
MatchFinder_SetLimits(p);
|
||||
}
|
||||
|
||||
static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
|
||||
{
|
||||
return (p->pos - p->historySize - 1) & kNormalizeMask;
|
||||
}
|
||||
|
||||
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
UInt32 value = items[i];
|
||||
if (value <= subValue)
|
||||
value = kEmptyHashValue;
|
||||
else
|
||||
value -= subValue;
|
||||
items[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
static void MatchFinder_Normalize(CMatchFinder *p)
|
||||
{
|
||||
UInt32 subValue = MatchFinder_GetSubValue(p);
|
||||
MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
|
||||
MatchFinder_ReduceOffsets(p, subValue);
|
||||
}
|
||||
|
||||
static void MatchFinder_CheckLimits(CMatchFinder *p)
|
||||
{
|
||||
if (p->pos == kMaxValForNormalize)
|
||||
MatchFinder_Normalize(p);
|
||||
if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
|
||||
MatchFinder_CheckAndMoveAndRead(p);
|
||||
if (p->cyclicBufferPos == p->cyclicBufferSize)
|
||||
p->cyclicBufferPos = 0;
|
||||
MatchFinder_SetLimits(p);
|
||||
}
|
||||
|
||||
static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
|
||||
UInt32 *distances, UInt32 maxLen)
|
||||
{
|
||||
son[_cyclicBufferPos] = curMatch;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
return distances;
|
||||
{
|
||||
const Byte *pb = cur - delta;
|
||||
curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
|
||||
if (pb[maxLen] == cur[maxLen] && *pb == *cur)
|
||||
{
|
||||
UInt32 len = 0;
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
if (maxLen < len)
|
||||
{
|
||||
*distances++ = maxLen = len;
|
||||
*distances++ = delta - 1;
|
||||
if (len == lenLimit)
|
||||
return distances;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
|
||||
UInt32 *distances, UInt32 maxLen)
|
||||
{
|
||||
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
||||
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
|
||||
UInt32 len0 = 0, len1 = 0;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
{
|
||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
||||
return distances;
|
||||
}
|
||||
{
|
||||
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
|
||||
const Byte *pb = cur - delta;
|
||||
UInt32 len = (len0 < len1 ? len0 : len1);
|
||||
if (pb[len] == cur[len])
|
||||
{
|
||||
if (++len != lenLimit && pb[len] == cur[len])
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
if (maxLen < len)
|
||||
{
|
||||
*distances++ = maxLen = len;
|
||||
*distances++ = delta - 1;
|
||||
if (len == lenLimit)
|
||||
{
|
||||
*ptr1 = pair[0];
|
||||
*ptr0 = pair[1];
|
||||
return distances;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pb[len] < cur[len])
|
||||
{
|
||||
*ptr1 = curMatch;
|
||||
ptr1 = pair + 1;
|
||||
curMatch = *ptr1;
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr0 = curMatch;
|
||||
ptr0 = pair;
|
||||
curMatch = *ptr0;
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
|
||||
{
|
||||
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
||||
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
|
||||
UInt32 len0 = 0, len1 = 0;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
{
|
||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
||||
return;
|
||||
}
|
||||
{
|
||||
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
|
||||
const Byte *pb = cur - delta;
|
||||
UInt32 len = (len0 < len1 ? len0 : len1);
|
||||
if (pb[len] == cur[len])
|
||||
{
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
{
|
||||
if (len == lenLimit)
|
||||
{
|
||||
*ptr1 = pair[0];
|
||||
*ptr0 = pair[1];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pb[len] < cur[len])
|
||||
{
|
||||
*ptr1 = curMatch;
|
||||
ptr1 = pair + 1;
|
||||
curMatch = *ptr1;
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr0 = curMatch;
|
||||
ptr0 = pair;
|
||||
curMatch = *ptr0;
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MOVE_POS \
|
||||
++p->cyclicBufferPos; \
|
||||
p->buffer++; \
|
||||
if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
|
||||
|
||||
#define MOVE_POS_RET MOVE_POS return offset;
|
||||
|
||||
static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
|
||||
|
||||
#define GET_MATCHES_HEADER2(minLen, ret_op) \
|
||||
UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
|
||||
lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
|
||||
cur = p->buffer;
|
||||
|
||||
#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
|
||||
#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)
|
||||
|
||||
#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
|
||||
|
||||
#define GET_MATCHES_FOOTER(offset, maxLen) \
|
||||
offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
|
||||
distances + offset, maxLen) - distances); MOVE_POS_RET;
|
||||
|
||||
#define SKIP_FOOTER \
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
|
||||
|
||||
static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(2)
|
||||
HASH2_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = 0;
|
||||
GET_MATCHES_FOOTER(offset, 1)
|
||||
}
|
||||
|
||||
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = 0;
|
||||
GET_MATCHES_FOOTER(offset, 2)
|
||||
}
|
||||
|
||||
static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, delta2, maxLen, offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
|
||||
HASH3_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[hash2Value];
|
||||
curMatch = p->hash[kFix3HashSize + hashValue];
|
||||
|
||||
p->hash[hash2Value] =
|
||||
p->hash[kFix3HashSize + hashValue] = p->pos;
|
||||
|
||||
|
||||
maxLen = 2;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[0] = maxLen;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
GET_MATCHES_FOOTER(offset, maxLen)
|
||||
}
|
||||
|
||||
static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
|
||||
GET_MATCHES_HEADER(4)
|
||||
|
||||
HASH4_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[ hash2Value];
|
||||
delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
|
||||
maxLen = 1;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
distances[0] = maxLen = 2;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
}
|
||||
if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
|
||||
{
|
||||
maxLen = 3;
|
||||
distances[offset + 1] = delta3 - 1;
|
||||
offset += 2;
|
||||
delta2 = delta3;
|
||||
}
|
||||
if (offset != 0)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[offset - 2] = maxLen;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
if (maxLen < 3)
|
||||
maxLen = 3;
|
||||
GET_MATCHES_FOOTER(offset, maxLen)
|
||||
}
|
||||
|
||||
static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
|
||||
GET_MATCHES_HEADER(4)
|
||||
|
||||
HASH4_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[ hash2Value];
|
||||
delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
|
||||
maxLen = 1;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
distances[0] = maxLen = 2;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
}
|
||||
if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
|
||||
{
|
||||
maxLen = 3;
|
||||
distances[offset + 1] = delta3 - 1;
|
||||
offset += 2;
|
||||
delta2 = delta3;
|
||||
}
|
||||
if (offset != 0)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[offset - 2] = maxLen;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
if (maxLen < 3)
|
||||
maxLen = 3;
|
||||
offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
|
||||
distances + offset, maxLen) - (distances));
|
||||
MOVE_POS_RET
|
||||
}
|
||||
|
||||
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
|
||||
distances, 2) - (distances));
|
||||
MOVE_POS_RET
|
||||
}
|
||||
|
||||
static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(2)
|
||||
HASH2_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value;
|
||||
SKIP_HEADER(3)
|
||||
HASH3_CALC;
|
||||
curMatch = p->hash[kFix3HashSize + hashValue];
|
||||
p->hash[hash2Value] =
|
||||
p->hash[kFix3HashSize + hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value, hash3Value;
|
||||
SKIP_HEADER(4)
|
||||
HASH4_CALC;
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] = p->pos;
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value, hash3Value;
|
||||
SKIP_HEADER(4)
|
||||
HASH4_CALC;
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
|
||||
{
|
||||
vTable->Init = (Mf_Init_Func)MatchFinder_Init;
|
||||
vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
|
||||
vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
|
||||
vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
|
||||
if (!p->btMode)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
|
||||
}
|
||||
else if (p->numHashBytes == 2)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
|
||||
}
|
||||
else if (p->numHashBytes == 3)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
|
||||
}
|
||||
else
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
|
||||
}
|
||||
}
|
||||
Vendored
+107
@@ -0,0 +1,107 @@
|
||||
/* LzFind.h -- Match finder for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZFIND_H
|
||||
#define __LZFIND_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
typedef UInt32 CLzRef;
|
||||
|
||||
typedef struct _CMatchFinder
|
||||
{
|
||||
Byte *buffer;
|
||||
UInt32 pos;
|
||||
UInt32 posLimit;
|
||||
UInt32 streamPos;
|
||||
UInt32 lenLimit;
|
||||
|
||||
UInt32 cyclicBufferPos;
|
||||
UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
|
||||
|
||||
UInt32 matchMaxLen;
|
||||
CLzRef *hash;
|
||||
CLzRef *son;
|
||||
UInt32 hashMask;
|
||||
UInt32 cutValue;
|
||||
|
||||
Byte *bufferBase;
|
||||
ISeqInStream *stream;
|
||||
int streamEndWasReached;
|
||||
|
||||
UInt32 blockSize;
|
||||
UInt32 keepSizeBefore;
|
||||
UInt32 keepSizeAfter;
|
||||
|
||||
UInt32 numHashBytes;
|
||||
int directInput;
|
||||
int btMode;
|
||||
/* int skipModeBits; */
|
||||
int bigHash;
|
||||
UInt32 historySize;
|
||||
UInt32 fixedHashSize;
|
||||
UInt32 hashSizeSum;
|
||||
UInt32 numSons;
|
||||
SRes result;
|
||||
UInt32 crc[256];
|
||||
} CMatchFinder;
|
||||
|
||||
#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
|
||||
#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
|
||||
|
||||
#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
|
||||
|
||||
int MatchFinder_NeedMove(CMatchFinder *p);
|
||||
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
|
||||
void MatchFinder_MoveBlock(CMatchFinder *p);
|
||||
void MatchFinder_ReadIfRequired(CMatchFinder *p);
|
||||
|
||||
void MatchFinder_Construct(CMatchFinder *p);
|
||||
|
||||
/* Conditions:
|
||||
historySize <= 3 GB
|
||||
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
|
||||
*/
|
||||
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
|
||||
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
|
||||
ISzAlloc *alloc);
|
||||
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
|
||||
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
|
||||
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
|
||||
|
||||
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
|
||||
UInt32 *distances, UInt32 maxLen);
|
||||
|
||||
/*
|
||||
Conditions:
|
||||
Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
|
||||
Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
|
||||
*/
|
||||
|
||||
typedef void (*Mf_Init_Func)(void *object);
|
||||
typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
|
||||
typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
|
||||
typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
|
||||
typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
|
||||
typedef void (*Mf_Skip_Func)(void *object, UInt32);
|
||||
|
||||
typedef struct _IMatchFinder
|
||||
{
|
||||
Mf_Init_Func Init;
|
||||
Mf_GetIndexByte_Func GetIndexByte;
|
||||
Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
|
||||
Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
|
||||
Mf_GetMatches_Func GetMatches;
|
||||
Mf_Skip_Func Skip;
|
||||
} IMatchFinder;
|
||||
|
||||
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
|
||||
|
||||
void MatchFinder_Init(CMatchFinder *p);
|
||||
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
|
||||
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
|
||||
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
|
||||
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
|
||||
|
||||
#endif
|
||||
Vendored
+793
@@ -0,0 +1,793 @@
|
||||
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "LzHash.h"
|
||||
|
||||
#include "LzFindMt.h"
|
||||
|
||||
void MtSync_Construct(CMtSync *p)
|
||||
{
|
||||
p->wasCreated = False;
|
||||
p->csWasInitialized = False;
|
||||
p->csWasEntered = False;
|
||||
Thread_Construct(&p->thread);
|
||||
Event_Construct(&p->canStart);
|
||||
Event_Construct(&p->wasStarted);
|
||||
Event_Construct(&p->wasStopped);
|
||||
Semaphore_Construct(&p->freeSemaphore);
|
||||
Semaphore_Construct(&p->filledSemaphore);
|
||||
}
|
||||
|
||||
void MtSync_GetNextBlock(CMtSync *p)
|
||||
{
|
||||
if (p->needStart)
|
||||
{
|
||||
p->numProcessedBlocks = 1;
|
||||
p->needStart = False;
|
||||
p->stopWriting = False;
|
||||
p->exit = False;
|
||||
Event_Reset(&p->wasStarted);
|
||||
Event_Reset(&p->wasStopped);
|
||||
|
||||
Event_Set(&p->canStart);
|
||||
Event_Wait(&p->wasStarted);
|
||||
}
|
||||
else
|
||||
{
|
||||
CriticalSection_Leave(&p->cs);
|
||||
p->csWasEntered = False;
|
||||
p->numProcessedBlocks++;
|
||||
Semaphore_Release1(&p->freeSemaphore);
|
||||
}
|
||||
Semaphore_Wait(&p->filledSemaphore);
|
||||
CriticalSection_Enter(&p->cs);
|
||||
p->csWasEntered = True;
|
||||
}
|
||||
|
||||
/* MtSync_StopWriting must be called if Writing was started */
|
||||
|
||||
void MtSync_StopWriting(CMtSync *p)
|
||||
{
|
||||
UInt32 myNumBlocks = p->numProcessedBlocks;
|
||||
if (!Thread_WasCreated(&p->thread) || p->needStart)
|
||||
return;
|
||||
p->stopWriting = True;
|
||||
if (p->csWasEntered)
|
||||
{
|
||||
CriticalSection_Leave(&p->cs);
|
||||
p->csWasEntered = False;
|
||||
}
|
||||
Semaphore_Release1(&p->freeSemaphore);
|
||||
|
||||
Event_Wait(&p->wasStopped);
|
||||
|
||||
while (myNumBlocks++ != p->numProcessedBlocks)
|
||||
{
|
||||
Semaphore_Wait(&p->filledSemaphore);
|
||||
Semaphore_Release1(&p->freeSemaphore);
|
||||
}
|
||||
p->needStart = True;
|
||||
}
|
||||
|
||||
void MtSync_Destruct(CMtSync *p)
|
||||
{
|
||||
if (Thread_WasCreated(&p->thread))
|
||||
{
|
||||
MtSync_StopWriting(p);
|
||||
p->exit = True;
|
||||
if (p->needStart)
|
||||
Event_Set(&p->canStart);
|
||||
Thread_Wait(&p->thread);
|
||||
Thread_Close(&p->thread);
|
||||
}
|
||||
if (p->csWasInitialized)
|
||||
{
|
||||
CriticalSection_Delete(&p->cs);
|
||||
p->csWasInitialized = False;
|
||||
}
|
||||
|
||||
Event_Close(&p->canStart);
|
||||
Event_Close(&p->wasStarted);
|
||||
Event_Close(&p->wasStopped);
|
||||
Semaphore_Close(&p->freeSemaphore);
|
||||
Semaphore_Close(&p->filledSemaphore);
|
||||
|
||||
p->wasCreated = False;
|
||||
}
|
||||
|
||||
#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
|
||||
|
||||
static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
|
||||
{
|
||||
if (p->wasCreated)
|
||||
return SZ_OK;
|
||||
|
||||
RINOK_THREAD(CriticalSection_Init(&p->cs));
|
||||
p->csWasInitialized = True;
|
||||
|
||||
RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));
|
||||
RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));
|
||||
RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
|
||||
|
||||
RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));
|
||||
RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));
|
||||
|
||||
p->needStart = True;
|
||||
|
||||
RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));
|
||||
p->wasCreated = True;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
static SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
|
||||
{
|
||||
SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);
|
||||
if (res != SZ_OK)
|
||||
MtSync_Destruct(p);
|
||||
return res;
|
||||
}
|
||||
|
||||
void MtSync_Init(CMtSync *p) { p->needStart = True; }
|
||||
|
||||
#define kMtMaxValForNormalize 0xFFFFFFFF
|
||||
|
||||
#define DEF_GetHeads2(name, v, action) \
|
||||
static void GetHeads ## name(const Byte *p, UInt32 pos, \
|
||||
UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \
|
||||
{ action; for (; numHeads != 0; numHeads--) { \
|
||||
const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++; } }
|
||||
|
||||
#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)
|
||||
|
||||
DEF_GetHeads2(2, (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )
|
||||
DEF_GetHeads(3, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
|
||||
DEF_GetHeads(4, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)
|
||||
DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
|
||||
DEF_GetHeads(5, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)
|
||||
|
||||
void HashThreadFunc(CMatchFinderMt *mt)
|
||||
{
|
||||
CMtSync *p = &mt->hashSync;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 numProcessedBlocks = 0;
|
||||
Event_Wait(&p->canStart);
|
||||
Event_Set(&p->wasStarted);
|
||||
for (;;)
|
||||
{
|
||||
if (p->exit)
|
||||
return;
|
||||
if (p->stopWriting)
|
||||
{
|
||||
p->numProcessedBlocks = numProcessedBlocks;
|
||||
Event_Set(&p->wasStopped);
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
CMatchFinder *mf = mt->MatchFinder;
|
||||
if (MatchFinder_NeedMove(mf))
|
||||
{
|
||||
CriticalSection_Enter(&mt->btSync.cs);
|
||||
CriticalSection_Enter(&mt->hashSync.cs);
|
||||
{
|
||||
const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);
|
||||
const Byte *afterPtr;
|
||||
MatchFinder_MoveBlock(mf);
|
||||
afterPtr = MatchFinder_GetPointerToCurrentPos(mf);
|
||||
mt->pointerToCurPos -= beforePtr - afterPtr;
|
||||
mt->buffer -= beforePtr - afterPtr;
|
||||
}
|
||||
CriticalSection_Leave(&mt->btSync.cs);
|
||||
CriticalSection_Leave(&mt->hashSync.cs);
|
||||
continue;
|
||||
}
|
||||
|
||||
Semaphore_Wait(&p->freeSemaphore);
|
||||
|
||||
MatchFinder_ReadIfRequired(mf);
|
||||
if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))
|
||||
{
|
||||
UInt32 subValue = (mf->pos - mf->historySize - 1);
|
||||
MatchFinder_ReduceOffsets(mf, subValue);
|
||||
MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);
|
||||
}
|
||||
{
|
||||
UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;
|
||||
UInt32 num = mf->streamPos - mf->pos;
|
||||
heads[0] = 2;
|
||||
heads[1] = num;
|
||||
if (num >= mf->numHashBytes)
|
||||
{
|
||||
num = num - mf->numHashBytes + 1;
|
||||
if (num > kMtHashBlockSize - 2)
|
||||
num = kMtHashBlockSize - 2;
|
||||
mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);
|
||||
heads[0] += num;
|
||||
}
|
||||
mf->pos += num;
|
||||
mf->buffer += num;
|
||||
}
|
||||
}
|
||||
|
||||
Semaphore_Release1(&p->filledSemaphore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
|
||||
{
|
||||
MtSync_GetNextBlock(&p->hashSync);
|
||||
p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;
|
||||
p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];
|
||||
p->hashNumAvail = p->hashBuf[p->hashBufPos++];
|
||||
}
|
||||
|
||||
#define kEmptyHashValue 0
|
||||
|
||||
/* #define MFMT_GM_INLINE */
|
||||
|
||||
#ifdef MFMT_GM_INLINE
|
||||
|
||||
#define NO_INLINE MY_FAST_CALL
|
||||
|
||||
Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
|
||||
UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 *distances = _distances + 1;
|
||||
UInt32 curMatch = pos - *hash++;
|
||||
|
||||
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
||||
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
|
||||
UInt32 len0 = 0, len1 = 0;
|
||||
UInt32 cutValue = _cutValue;
|
||||
UInt32 maxLen = _maxLen;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
{
|
||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
||||
break;
|
||||
}
|
||||
{
|
||||
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
|
||||
const Byte *pb = cur - delta;
|
||||
UInt32 len = (len0 < len1 ? len0 : len1);
|
||||
if (pb[len] == cur[len])
|
||||
{
|
||||
if (++len != lenLimit && pb[len] == cur[len])
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
if (maxLen < len)
|
||||
{
|
||||
*distances++ = maxLen = len;
|
||||
*distances++ = delta - 1;
|
||||
if (len == lenLimit)
|
||||
{
|
||||
*ptr1 = pair[0];
|
||||
*ptr0 = pair[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pb[len] < cur[len])
|
||||
{
|
||||
*ptr1 = curMatch;
|
||||
ptr1 = pair + 1;
|
||||
curMatch = *ptr1;
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr0 = curMatch;
|
||||
ptr0 = pair;
|
||||
curMatch = *ptr0;
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
pos++;
|
||||
_cyclicBufferPos++;
|
||||
cur++;
|
||||
{
|
||||
UInt32 num = (UInt32)(distances - _distances);
|
||||
*_distances = num - 1;
|
||||
_distances += num;
|
||||
limit -= num;
|
||||
}
|
||||
}
|
||||
while (limit > 0 && --size != 0);
|
||||
*posRes = pos;
|
||||
return limit;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 numProcessed = 0;
|
||||
UInt32 curPos = 2;
|
||||
UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);
|
||||
distances[1] = p->hashNumAvail;
|
||||
while (curPos < limit)
|
||||
{
|
||||
if (p->hashBufPos == p->hashBufPosLimit)
|
||||
{
|
||||
MatchFinderMt_GetNextBlock_Hash(p);
|
||||
distances[1] = numProcessed + p->hashNumAvail;
|
||||
if (p->hashNumAvail >= p->numHashBytes)
|
||||
continue;
|
||||
for (; p->hashNumAvail != 0; p->hashNumAvail--)
|
||||
distances[curPos++] = 0;
|
||||
break;
|
||||
}
|
||||
{
|
||||
UInt32 size = p->hashBufPosLimit - p->hashBufPos;
|
||||
UInt32 lenLimit = p->matchMaxLen;
|
||||
UInt32 pos = p->pos;
|
||||
UInt32 cyclicBufferPos = p->cyclicBufferPos;
|
||||
if (lenLimit >= p->hashNumAvail)
|
||||
lenLimit = p->hashNumAvail;
|
||||
{
|
||||
UInt32 size2 = p->hashNumAvail - lenLimit + 1;
|
||||
if (size2 < size)
|
||||
size = size2;
|
||||
size2 = p->cyclicBufferSize - cyclicBufferPos;
|
||||
if (size2 < size)
|
||||
size = size2;
|
||||
}
|
||||
#ifndef MFMT_GM_INLINE
|
||||
while (curPos < limit && size-- != 0)
|
||||
{
|
||||
UInt32 *startDistances = distances + curPos;
|
||||
UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],
|
||||
pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
|
||||
startDistances + 1, p->numHashBytes - 1) - startDistances);
|
||||
*startDistances = num - 1;
|
||||
curPos += num;
|
||||
cyclicBufferPos++;
|
||||
pos++;
|
||||
p->buffer++;
|
||||
}
|
||||
#else
|
||||
{
|
||||
UInt32 posRes;
|
||||
curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
|
||||
distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);
|
||||
p->hashBufPos += posRes - pos;
|
||||
cyclicBufferPos += posRes - pos;
|
||||
p->buffer += posRes - pos;
|
||||
pos = posRes;
|
||||
}
|
||||
#endif
|
||||
|
||||
numProcessed += pos - p->pos;
|
||||
p->hashNumAvail -= pos - p->pos;
|
||||
p->pos = pos;
|
||||
if (cyclicBufferPos == p->cyclicBufferSize)
|
||||
cyclicBufferPos = 0;
|
||||
p->cyclicBufferPos = cyclicBufferPos;
|
||||
}
|
||||
}
|
||||
distances[0] = curPos;
|
||||
}
|
||||
|
||||
void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)
|
||||
{
|
||||
CMtSync *sync = &p->hashSync;
|
||||
if (!sync->needStart)
|
||||
{
|
||||
CriticalSection_Enter(&sync->cs);
|
||||
sync->csWasEntered = True;
|
||||
}
|
||||
|
||||
BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);
|
||||
|
||||
if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)
|
||||
{
|
||||
UInt32 subValue = p->pos - p->cyclicBufferSize;
|
||||
MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);
|
||||
p->pos -= subValue;
|
||||
}
|
||||
|
||||
if (!sync->needStart)
|
||||
{
|
||||
CriticalSection_Leave(&sync->cs);
|
||||
sync->csWasEntered = False;
|
||||
}
|
||||
}
|
||||
|
||||
void BtThreadFunc(CMatchFinderMt *mt)
|
||||
{
|
||||
CMtSync *p = &mt->btSync;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 blockIndex = 0;
|
||||
Event_Wait(&p->canStart);
|
||||
Event_Set(&p->wasStarted);
|
||||
for (;;)
|
||||
{
|
||||
if (p->exit)
|
||||
return;
|
||||
if (p->stopWriting)
|
||||
{
|
||||
p->numProcessedBlocks = blockIndex;
|
||||
MtSync_StopWriting(&mt->hashSync);
|
||||
Event_Set(&p->wasStopped);
|
||||
break;
|
||||
}
|
||||
Semaphore_Wait(&p->freeSemaphore);
|
||||
BtFillBlock(mt, blockIndex++);
|
||||
Semaphore_Release1(&p->filledSemaphore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MatchFinderMt_Construct(CMatchFinderMt *p)
|
||||
{
|
||||
p->hashBuf = 0;
|
||||
MtSync_Construct(&p->hashSync);
|
||||
MtSync_Construct(&p->btSync);
|
||||
}
|
||||
|
||||
void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->hashBuf);
|
||||
p->hashBuf = 0;
|
||||
}
|
||||
|
||||
void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
|
||||
{
|
||||
MtSync_Destruct(&p->hashSync);
|
||||
MtSync_Destruct(&p->btSync);
|
||||
MatchFinderMt_FreeMem(p, alloc);
|
||||
}
|
||||
|
||||
#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)
|
||||
#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
|
||||
|
||||
static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; }
|
||||
static unsigned MY_STD_CALL BtThreadFunc2(void *p)
|
||||
{
|
||||
Byte allocaDummy[0x180];
|
||||
int i = 0;
|
||||
for (i = 0; i < 16; i++)
|
||||
allocaDummy[i] = (Byte)i;
|
||||
BtThreadFunc((CMatchFinderMt *)p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
|
||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)
|
||||
{
|
||||
CMatchFinder *mf = p->MatchFinder;
|
||||
p->historySize = historySize;
|
||||
if (kMtBtBlockSize <= matchMaxLen * 4)
|
||||
return SZ_ERROR_PARAM;
|
||||
if (p->hashBuf == 0)
|
||||
{
|
||||
p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));
|
||||
if (p->hashBuf == 0)
|
||||
return SZ_ERROR_MEM;
|
||||
p->btBuf = p->hashBuf + kHashBufferSize;
|
||||
}
|
||||
keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);
|
||||
keepAddBufferAfter += kMtHashBlockSize;
|
||||
if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))
|
||||
return SZ_ERROR_MEM;
|
||||
|
||||
RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));
|
||||
RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
/* Call it after ReleaseStream / SetStream */
|
||||
void MatchFinderMt_Init(CMatchFinderMt *p)
|
||||
{
|
||||
CMatchFinder *mf = p->MatchFinder;
|
||||
p->btBufPos = p->btBufPosLimit = 0;
|
||||
p->hashBufPos = p->hashBufPosLimit = 0;
|
||||
MatchFinder_Init(mf);
|
||||
p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);
|
||||
p->btNumAvailBytes = 0;
|
||||
p->lzPos = p->historySize + 1;
|
||||
|
||||
p->hash = mf->hash;
|
||||
p->fixedHashSize = mf->fixedHashSize;
|
||||
p->crc = mf->crc;
|
||||
|
||||
p->son = mf->son;
|
||||
p->matchMaxLen = mf->matchMaxLen;
|
||||
p->numHashBytes = mf->numHashBytes;
|
||||
p->pos = mf->pos;
|
||||
p->buffer = mf->buffer;
|
||||
p->cyclicBufferPos = mf->cyclicBufferPos;
|
||||
p->cyclicBufferSize = mf->cyclicBufferSize;
|
||||
p->cutValue = mf->cutValue;
|
||||
}
|
||||
|
||||
/* ReleaseStream is required to finish multithreading */
|
||||
void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
|
||||
{
|
||||
MtSync_StopWriting(&p->btSync);
|
||||
/* p->MatchFinder->ReleaseStream(); */
|
||||
}
|
||||
|
||||
void MatchFinderMt_Normalize(CMatchFinderMt *p)
|
||||
{
|
||||
MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);
|
||||
p->lzPos = p->historySize + 1;
|
||||
}
|
||||
|
||||
void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
|
||||
{
|
||||
UInt32 blockIndex;
|
||||
MtSync_GetNextBlock(&p->btSync);
|
||||
blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);
|
||||
p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;
|
||||
p->btBufPosLimit += p->btBuf[p->btBufPos++];
|
||||
p->btNumAvailBytes = p->btBuf[p->btBufPos++];
|
||||
if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)
|
||||
MatchFinderMt_Normalize(p);
|
||||
}
|
||||
|
||||
const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)
|
||||
{
|
||||
return p->pointerToCurPos;
|
||||
}
|
||||
|
||||
#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);
|
||||
|
||||
UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)
|
||||
{
|
||||
GET_NEXT_BLOCK_IF_REQUIRED;
|
||||
return p->btNumAvailBytes;
|
||||
}
|
||||
|
||||
Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)
|
||||
{
|
||||
return p->pointerToCurPos[index];
|
||||
}
|
||||
|
||||
UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, curMatch2;
|
||||
UInt32 *hash = p->hash;
|
||||
const Byte *cur = p->pointerToCurPos;
|
||||
UInt32 lzPos = p->lzPos;
|
||||
MT_HASH2_CALC
|
||||
|
||||
curMatch2 = hash[hash2Value];
|
||||
hash[hash2Value] = lzPos;
|
||||
|
||||
if (curMatch2 >= matchMinPos)
|
||||
if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
|
||||
{
|
||||
*distances++ = 2;
|
||||
*distances++ = lzPos - curMatch2 - 1;
|
||||
}
|
||||
return distances;
|
||||
}
|
||||
|
||||
UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, hash3Value, curMatch2, curMatch3;
|
||||
UInt32 *hash = p->hash;
|
||||
const Byte *cur = p->pointerToCurPos;
|
||||
UInt32 lzPos = p->lzPos;
|
||||
MT_HASH3_CALC
|
||||
|
||||
curMatch2 = hash[ hash2Value];
|
||||
curMatch3 = hash[kFix3HashSize + hash3Value];
|
||||
|
||||
hash[ hash2Value] =
|
||||
hash[kFix3HashSize + hash3Value] =
|
||||
lzPos;
|
||||
|
||||
if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
|
||||
{
|
||||
distances[1] = lzPos - curMatch2 - 1;
|
||||
if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
|
||||
{
|
||||
distances[0] = 3;
|
||||
return distances + 2;
|
||||
}
|
||||
distances[0] = 2;
|
||||
distances += 2;
|
||||
}
|
||||
if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
|
||||
{
|
||||
*distances++ = 3;
|
||||
*distances++ = lzPos - curMatch3 - 1;
|
||||
}
|
||||
return distances;
|
||||
}
|
||||
|
||||
/*
|
||||
UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;
|
||||
UInt32 *hash = p->hash;
|
||||
const Byte *cur = p->pointerToCurPos;
|
||||
UInt32 lzPos = p->lzPos;
|
||||
MT_HASH4_CALC
|
||||
|
||||
curMatch2 = hash[ hash2Value];
|
||||
curMatch3 = hash[kFix3HashSize + hash3Value];
|
||||
curMatch4 = hash[kFix4HashSize + hash4Value];
|
||||
|
||||
hash[ hash2Value] =
|
||||
hash[kFix3HashSize + hash3Value] =
|
||||
hash[kFix4HashSize + hash4Value] =
|
||||
lzPos;
|
||||
|
||||
if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
|
||||
{
|
||||
distances[1] = lzPos - curMatch2 - 1;
|
||||
if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
|
||||
{
|
||||
distances[0] = (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;
|
||||
return distances + 2;
|
||||
}
|
||||
distances[0] = 2;
|
||||
distances += 2;
|
||||
}
|
||||
if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
|
||||
{
|
||||
distances[1] = lzPos - curMatch3 - 1;
|
||||
if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])
|
||||
{
|
||||
distances[0] = 4;
|
||||
return distances + 2;
|
||||
}
|
||||
distances[0] = 3;
|
||||
distances += 2;
|
||||
}
|
||||
|
||||
if (curMatch4 >= matchMinPos)
|
||||
if (
|
||||
cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&
|
||||
cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]
|
||||
)
|
||||
{
|
||||
*distances++ = 4;
|
||||
*distances++ = lzPos - curMatch4 - 1;
|
||||
}
|
||||
return distances;
|
||||
}
|
||||
*/
|
||||
|
||||
#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
|
||||
|
||||
UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
|
||||
{
|
||||
const UInt32 *btBuf = p->btBuf + p->btBufPos;
|
||||
UInt32 len = *btBuf++;
|
||||
p->btBufPos += 1 + len;
|
||||
p->btNumAvailBytes--;
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < len; i += 2)
|
||||
{
|
||||
*distances++ = *btBuf++;
|
||||
*distances++ = *btBuf++;
|
||||
}
|
||||
}
|
||||
INCREASE_LZ_POS
|
||||
return len;
|
||||
}
|
||||
|
||||
UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
|
||||
{
|
||||
const UInt32 *btBuf = p->btBuf + p->btBufPos;
|
||||
UInt32 len = *btBuf++;
|
||||
p->btBufPos += 1 + len;
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
if (p->btNumAvailBytes-- >= 4)
|
||||
len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Condition: there are matches in btBuf with length < p->numHashBytes */
|
||||
UInt32 *distances2;
|
||||
p->btNumAvailBytes--;
|
||||
distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);
|
||||
do
|
||||
{
|
||||
*distances2++ = *btBuf++;
|
||||
*distances2++ = *btBuf++;
|
||||
}
|
||||
while ((len -= 2) != 0);
|
||||
len = (UInt32)(distances2 - (distances));
|
||||
}
|
||||
INCREASE_LZ_POS
|
||||
return len;
|
||||
}
|
||||
|
||||
#define SKIP_HEADER2 do { GET_NEXT_BLOCK_IF_REQUIRED
|
||||
#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;
|
||||
#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);
|
||||
|
||||
void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)
|
||||
{
|
||||
SKIP_HEADER2 { p->btNumAvailBytes--;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
|
||||
void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
|
||||
{
|
||||
SKIP_HEADER(2)
|
||||
UInt32 hash2Value;
|
||||
MT_HASH2_CALC
|
||||
hash[hash2Value] = p->lzPos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
|
||||
void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
|
||||
{
|
||||
SKIP_HEADER(3)
|
||||
UInt32 hash2Value, hash3Value;
|
||||
MT_HASH3_CALC
|
||||
hash[kFix3HashSize + hash3Value] =
|
||||
hash[ hash2Value] =
|
||||
p->lzPos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
|
||||
/*
|
||||
void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
|
||||
{
|
||||
SKIP_HEADER(4)
|
||||
UInt32 hash2Value, hash3Value, hash4Value;
|
||||
MT_HASH4_CALC
|
||||
hash[kFix4HashSize + hash4Value] =
|
||||
hash[kFix3HashSize + hash3Value] =
|
||||
hash[ hash2Value] =
|
||||
p->lzPos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
*/
|
||||
|
||||
void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
|
||||
{
|
||||
vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;
|
||||
vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;
|
||||
vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;
|
||||
vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;
|
||||
switch(p->MatchFinder->numHashBytes)
|
||||
{
|
||||
case 2:
|
||||
p->GetHeadsFunc = GetHeads2;
|
||||
p->MixMatchesFunc = (Mf_Mix_Matches)0;
|
||||
vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;
|
||||
break;
|
||||
case 3:
|
||||
p->GetHeadsFunc = GetHeads3;
|
||||
p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;
|
||||
vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;
|
||||
break;
|
||||
default:
|
||||
/* case 4: */
|
||||
p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;
|
||||
/* p->GetHeadsFunc = GetHeads4; */
|
||||
p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;
|
||||
vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;
|
||||
break;
|
||||
/*
|
||||
default:
|
||||
p->GetHeadsFunc = GetHeads5;
|
||||
p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;
|
||||
vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;
|
||||
break;
|
||||
*/
|
||||
}
|
||||
}
|
||||
Vendored
+97
@@ -0,0 +1,97 @@
|
||||
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZFINDMT_H
|
||||
#define __LZFINDMT_H
|
||||
|
||||
#include "Threads.h"
|
||||
#include "LzFind.h"
|
||||
|
||||
#define kMtHashBlockSize (1 << 13)
|
||||
#define kMtHashNumBlocks (1 << 3)
|
||||
#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
|
||||
|
||||
#define kMtBtBlockSize (1 << 14)
|
||||
#define kMtBtNumBlocks (1 << 6)
|
||||
#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
|
||||
|
||||
typedef struct _CMtSync
|
||||
{
|
||||
Bool wasCreated;
|
||||
Bool needStart;
|
||||
Bool exit;
|
||||
Bool stopWriting;
|
||||
|
||||
CThread thread;
|
||||
CAutoResetEvent canStart;
|
||||
CAutoResetEvent wasStarted;
|
||||
CAutoResetEvent wasStopped;
|
||||
CSemaphore freeSemaphore;
|
||||
CSemaphore filledSemaphore;
|
||||
Bool csWasInitialized;
|
||||
Bool csWasEntered;
|
||||
CCriticalSection cs;
|
||||
UInt32 numProcessedBlocks;
|
||||
} CMtSync;
|
||||
|
||||
typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
|
||||
|
||||
/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
|
||||
#define kMtCacheLineDummy 128
|
||||
|
||||
typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
|
||||
UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
|
||||
|
||||
typedef struct _CMatchFinderMt
|
||||
{
|
||||
/* LZ */
|
||||
const Byte *pointerToCurPos;
|
||||
UInt32 *btBuf;
|
||||
UInt32 btBufPos;
|
||||
UInt32 btBufPosLimit;
|
||||
UInt32 lzPos;
|
||||
UInt32 btNumAvailBytes;
|
||||
|
||||
UInt32 *hash;
|
||||
UInt32 fixedHashSize;
|
||||
UInt32 historySize;
|
||||
const UInt32 *crc;
|
||||
|
||||
Mf_Mix_Matches MixMatchesFunc;
|
||||
|
||||
/* LZ + BT */
|
||||
CMtSync btSync;
|
||||
Byte btDummy[kMtCacheLineDummy];
|
||||
|
||||
/* BT */
|
||||
UInt32 *hashBuf;
|
||||
UInt32 hashBufPos;
|
||||
UInt32 hashBufPosLimit;
|
||||
UInt32 hashNumAvail;
|
||||
|
||||
CLzRef *son;
|
||||
UInt32 matchMaxLen;
|
||||
UInt32 numHashBytes;
|
||||
UInt32 pos;
|
||||
Byte *buffer;
|
||||
UInt32 cyclicBufferPos;
|
||||
UInt32 cyclicBufferSize; /* it must be historySize + 1 */
|
||||
UInt32 cutValue;
|
||||
|
||||
/* BT + Hash */
|
||||
CMtSync hashSync;
|
||||
/* Byte hashDummy[kMtCacheLineDummy]; */
|
||||
|
||||
/* Hash */
|
||||
Mf_GetHeads GetHeadsFunc;
|
||||
CMatchFinder *MatchFinder;
|
||||
} CMatchFinderMt;
|
||||
|
||||
void MatchFinderMt_Construct(CMatchFinderMt *p);
|
||||
void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
|
||||
SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
|
||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
|
||||
void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
|
||||
void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
|
||||
|
||||
#endif
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
/* LzHash.h -- HASH functions for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZHASH_H
|
||||
#define __LZHASH_H
|
||||
|
||||
#define kHash2Size (1 << 10)
|
||||
#define kHash3Size (1 << 16)
|
||||
#define kHash4Size (1 << 20)
|
||||
|
||||
#define kFix3HashSize (kHash2Size)
|
||||
#define kFix4HashSize (kHash2Size + kHash3Size)
|
||||
#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
|
||||
|
||||
#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
|
||||
|
||||
#define HASH3_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
|
||||
|
||||
#define HASH4_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
|
||||
|
||||
#define HASH5_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
|
||||
hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
|
||||
hash4Value &= (kHash4Size - 1); }
|
||||
|
||||
/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
|
||||
#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
|
||||
|
||||
|
||||
#define MT_HASH2_CALC \
|
||||
hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
|
||||
|
||||
#define MT_HASH3_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
|
||||
|
||||
#define MT_HASH4_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
|
||||
|
||||
#endif
|
||||
Vendored
+1007
File diff suppressed because it is too large
Load Diff
Vendored
+223
@@ -0,0 +1,223 @@
|
||||
/* LzmaDec.h -- LZMA Decoder
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZMADEC_H
|
||||
#define __LZMADEC_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/* #define _LZMA_PROB32 */
|
||||
/* _LZMA_PROB32 can increase the speed on some CPUs,
|
||||
but memory usage for CLzmaDec::probs will be doubled in that case */
|
||||
|
||||
#ifdef _LZMA_PROB32
|
||||
#define CLzmaProb UInt32
|
||||
#else
|
||||
#define CLzmaProb UInt16
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------- LZMA Properties ---------- */
|
||||
|
||||
#define LZMA_PROPS_SIZE 5
|
||||
|
||||
typedef struct _CLzmaProps
|
||||
{
|
||||
unsigned lc, lp, pb;
|
||||
UInt32 dicSize;
|
||||
} CLzmaProps;
|
||||
|
||||
/* LzmaProps_Decode - decodes properties
|
||||
Returns:
|
||||
SZ_OK
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
*/
|
||||
|
||||
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
|
||||
|
||||
|
||||
/* ---------- LZMA Decoder state ---------- */
|
||||
|
||||
/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
|
||||
Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
|
||||
|
||||
#define LZMA_REQUIRED_INPUT_MAX 20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CLzmaProps prop;
|
||||
CLzmaProb *probs;
|
||||
Byte *dic;
|
||||
const Byte *buf;
|
||||
UInt32 range, code;
|
||||
SizeT dicPos;
|
||||
SizeT dicBufSize;
|
||||
UInt32 processedPos;
|
||||
UInt32 checkDicSize;
|
||||
unsigned state;
|
||||
UInt32 reps[4];
|
||||
unsigned remainLen;
|
||||
int needFlush;
|
||||
int needInitState;
|
||||
UInt32 numProbs;
|
||||
unsigned tempBufSize;
|
||||
Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
|
||||
} CLzmaDec;
|
||||
|
||||
#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
|
||||
|
||||
void LzmaDec_Init(CLzmaDec *p);
|
||||
|
||||
/* There are two types of LZMA streams:
|
||||
0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
|
||||
1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA_FINISH_ANY, /* finish at any point */
|
||||
LZMA_FINISH_END /* block must be finished at the end */
|
||||
} ELzmaFinishMode;
|
||||
|
||||
/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
|
||||
|
||||
You must use LZMA_FINISH_END, when you know that current output buffer
|
||||
covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
|
||||
|
||||
If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
|
||||
and output value of destLen will be less than output buffer size limit.
|
||||
You can check status result also.
|
||||
|
||||
You can use multiple checks to test data integrity after full decompression:
|
||||
1) Check Result and "status" variable.
|
||||
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
|
||||
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
|
||||
You must use correct finish mode in that case. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
|
||||
LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
|
||||
LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
|
||||
LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
|
||||
} ELzmaStatus;
|
||||
|
||||
/* ELzmaStatus is used only as output value for function call */
|
||||
|
||||
|
||||
/* ---------- Interfaces ---------- */
|
||||
|
||||
/* There are 3 levels of interfaces:
|
||||
1) Dictionary Interface
|
||||
2) Buffer Interface
|
||||
3) One Call Interface
|
||||
You can select any of these interfaces, but don't mix functions from different
|
||||
groups for same object. */
|
||||
|
||||
|
||||
/* There are two variants to allocate state for Dictionary Interface:
|
||||
1) LzmaDec_Allocate / LzmaDec_Free
|
||||
2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
|
||||
You can use variant 2, if you set dictionary buffer manually.
|
||||
For Buffer Interface you must always use variant 1.
|
||||
|
||||
LzmaDec_Allocate* can return:
|
||||
SZ_OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
*/
|
||||
|
||||
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
|
||||
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
|
||||
|
||||
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
|
||||
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
|
||||
|
||||
/* ---------- Dictionary Interface ---------- */
|
||||
|
||||
/* You can use it, if you want to eliminate the overhead for data copying from
|
||||
dictionary to some other external buffer.
|
||||
You must work with CLzmaDec variables directly in this interface.
|
||||
|
||||
STEPS:
|
||||
LzmaDec_Constr()
|
||||
LzmaDec_Allocate()
|
||||
for (each new stream)
|
||||
{
|
||||
LzmaDec_Init()
|
||||
while (it needs more decompression)
|
||||
{
|
||||
LzmaDec_DecodeToDic()
|
||||
use data from CLzmaDec::dic and update CLzmaDec::dicPos
|
||||
}
|
||||
}
|
||||
LzmaDec_Free()
|
||||
*/
|
||||
|
||||
/* LzmaDec_DecodeToDic
|
||||
|
||||
The decoding to internal dictionary buffer (CLzmaDec::dic).
|
||||
You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (dicLimit).
|
||||
LZMA_FINISH_ANY - Decode just dicLimit bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after dicLimit.
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_NEEDS_MORE_INPUT
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
*/
|
||||
|
||||
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
|
||||
|
||||
|
||||
/* ---------- Buffer Interface ---------- */
|
||||
|
||||
/* It's zlib-like interface.
|
||||
See LzmaDec_DecodeToDic description for information about STEPS and return results,
|
||||
but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
|
||||
to work with CLzmaDec variables manually.
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
*/
|
||||
|
||||
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
|
||||
|
||||
|
||||
/* ---------- One Call Interface ---------- */
|
||||
|
||||
/* LzmaDecode
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
|
||||
*/
|
||||
|
||||
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
|
||||
ELzmaStatus *status, ISzAlloc *alloc);
|
||||
|
||||
#endif
|
||||
Vendored
+2281
File diff suppressed because it is too large
Load Diff
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
/* LzmaEnc.h -- LZMA Encoder
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZMAENC_H
|
||||
#define __LZMAENC_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
#define LZMA_PROPS_SIZE 5
|
||||
|
||||
typedef struct _CLzmaEncProps
|
||||
{
|
||||
int level; /* 0 <= level <= 9 */
|
||||
UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
|
||||
(1 << 12) <= dictSize <= (1 << 30) for 64-bit version
|
||||
default = (1 << 24) */
|
||||
int lc; /* 0 <= lc <= 8, default = 3 */
|
||||
int lp; /* 0 <= lp <= 4, default = 0 */
|
||||
int pb; /* 0 <= pb <= 4, default = 2 */
|
||||
int algo; /* 0 - fast, 1 - normal, default = 1 */
|
||||
int fb; /* 5 <= fb <= 273, default = 32 */
|
||||
int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
|
||||
int numHashBytes; /* 2, 3 or 4, default = 4 */
|
||||
UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
|
||||
unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
|
||||
int numThreads; /* 1 or 2, default = 2 */
|
||||
} CLzmaEncProps;
|
||||
|
||||
void LzmaEncProps_Init(CLzmaEncProps *p);
|
||||
void LzmaEncProps_Normalize(CLzmaEncProps *p);
|
||||
UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
|
||||
|
||||
|
||||
/* ---------- CLzmaEncHandle Interface ---------- */
|
||||
|
||||
/* LzmaEnc_* functions can return the following exit codes:
|
||||
Returns:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater in props
|
||||
SZ_ERROR_WRITE - Write callback error.
|
||||
SZ_ERROR_PROGRESS - some break from progress callback
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
*/
|
||||
|
||||
typedef void * CLzmaEncHandle;
|
||||
|
||||
CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
|
||||
void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
|
||||
SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
|
||||
SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
|
||||
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
|
||||
/* ---------- One Call Interface ---------- */
|
||||
|
||||
/* LzmaEncode
|
||||
Return code:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater
|
||||
SZ_ERROR_OUTPUT_EOF - output buffer overflow
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
*/
|
||||
|
||||
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
|
||||
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
|
||||
#endif
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
/* LzmaLib.c -- LZMA library wrapper
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#include "LzmaEnc.h"
|
||||
#include "LzmaDec.h"
|
||||
#include "Alloc.h"
|
||||
#include "LzmaLib.h"
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
||||
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
|
||||
MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
|
||||
unsigned char *outProps, size_t *outPropsSize,
|
||||
int level, /* 0 <= level <= 9, default = 5 */
|
||||
unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */
|
||||
int lc, /* 0 <= lc <= 8, default = 3 */
|
||||
int lp, /* 0 <= lp <= 4, default = 0 */
|
||||
int pb, /* 0 <= pb <= 4, default = 2 */
|
||||
int fb, /* 5 <= fb <= 273, default = 32 */
|
||||
int numThreads /* 1 or 2, default = 2 */
|
||||
)
|
||||
{
|
||||
CLzmaEncProps props;
|
||||
LzmaEncProps_Init(&props);
|
||||
props.level = level;
|
||||
props.dictSize = dictSize;
|
||||
props.lc = lc;
|
||||
props.lp = lp;
|
||||
props.pb = pb;
|
||||
props.fb = fb;
|
||||
props.numThreads = numThreads;
|
||||
|
||||
return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,
|
||||
NULL, &g_Alloc, &g_Alloc);
|
||||
}
|
||||
|
||||
|
||||
MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,
|
||||
const unsigned char *props, size_t propsSize)
|
||||
{
|
||||
ELzmaStatus status;
|
||||
return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);
|
||||
}
|
||||
Vendored
+135
@@ -0,0 +1,135 @@
|
||||
/* LzmaLib.h -- LZMA library interface
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __LZMALIB_H
|
||||
#define __LZMALIB_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MY_EXTERN_C extern "C"
|
||||
#else
|
||||
#define MY_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL
|
||||
|
||||
#define LZMA_PROPS_SIZE 5
|
||||
|
||||
/*
|
||||
RAM requirements for LZMA:
|
||||
for compression: (dictSize * 11.5 + 6 MB) + state_size
|
||||
for decompression: dictSize + state_size
|
||||
state_size = (4 + (1.5 << (lc + lp))) KB
|
||||
by default (lc=3, lp=0), state_size = 16 KB.
|
||||
|
||||
LZMA properties (5 bytes) format
|
||||
Offset Size Description
|
||||
0 1 lc, lp and pb in encoded form.
|
||||
1 4 dictSize (little endian).
|
||||
*/
|
||||
|
||||
/*
|
||||
LzmaCompress
|
||||
------------
|
||||
|
||||
outPropsSize -
|
||||
In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
|
||||
Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
|
||||
|
||||
LZMA Encoder will use defult values for any parameter, if it is
|
||||
-1 for any from: level, loc, lp, pb, fb, numThreads
|
||||
0 for dictSize
|
||||
|
||||
level - compression level: 0 <= level <= 9;
|
||||
|
||||
level dictSize algo fb
|
||||
0: 16 KB 0 32
|
||||
1: 64 KB 0 32
|
||||
2: 256 KB 0 32
|
||||
3: 1 MB 0 32
|
||||
4: 4 MB 0 32
|
||||
5: 16 MB 1 32
|
||||
6: 32 MB 1 32
|
||||
7+: 64 MB 1 64
|
||||
|
||||
The default value for "level" is 5.
|
||||
|
||||
algo = 0 means fast method
|
||||
algo = 1 means normal method
|
||||
|
||||
dictSize - The dictionary size in bytes. The maximum value is
|
||||
128 MB = (1 << 27) bytes for 32-bit version
|
||||
1 GB = (1 << 30) bytes for 64-bit version
|
||||
The default value is 16 MB = (1 << 24) bytes.
|
||||
It's recommended to use the dictionary that is larger than 4 KB and
|
||||
that can be calculated as (1 << N) or (3 << N) sizes.
|
||||
|
||||
lc - The number of literal context bits (high bits of previous literal).
|
||||
It can be in the range from 0 to 8. The default value is 3.
|
||||
Sometimes lc=4 gives the gain for big files.
|
||||
|
||||
lp - The number of literal pos bits (low bits of current position for literals).
|
||||
It can be in the range from 0 to 4. The default value is 0.
|
||||
The lp switch is intended for periodical data when the period is equal to 2^lp.
|
||||
For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
|
||||
better to set lc=0, if you change lp switch.
|
||||
|
||||
pb - The number of pos bits (low bits of current position).
|
||||
It can be in the range from 0 to 4. The default value is 2.
|
||||
The pb switch is intended for periodical data when the period is equal 2^pb.
|
||||
|
||||
fb - Word size (the number of fast bytes).
|
||||
It can be in the range from 5 to 273. The default value is 32.
|
||||
Usually, a big number gives a little bit better compression ratio and
|
||||
slower compression process.
|
||||
|
||||
numThreads - The number of thereads. 1 or 2. The default value is 2.
|
||||
Fast mode (algo = 0) can use only 1 thread.
|
||||
|
||||
Out:
|
||||
destLen - processed output size
|
||||
Returns:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater
|
||||
SZ_ERROR_OUTPUT_EOF - output buffer overflow
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
*/
|
||||
|
||||
MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
|
||||
unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
|
||||
int level, /* 0 <= level <= 9, default = 5 */
|
||||
unsigned dictSize, /* default = (1 << 24) */
|
||||
int lc, /* 0 <= lc <= 8, default = 3 */
|
||||
int lp, /* 0 <= lp <= 4, default = 0 */
|
||||
int pb, /* 0 <= pb <= 4, default = 2 */
|
||||
int fb, /* 5 <= fb <= 273, default = 32 */
|
||||
int numThreads /* 1 or 2, default = 2 */
|
||||
);
|
||||
|
||||
/*
|
||||
LzmaUncompress
|
||||
--------------
|
||||
In:
|
||||
dest - output data
|
||||
destLen - output data size
|
||||
src - input data
|
||||
srcLen - input data size
|
||||
Out:
|
||||
destLen - processed output size
|
||||
srcLen - processed input size
|
||||
Returns:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation arror
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src)
|
||||
*/
|
||||
|
||||
MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
|
||||
const unsigned char *props, size_t propsSize);
|
||||
|
||||
#endif
|
||||
Vendored
+109
@@ -0,0 +1,109 @@
|
||||
/* Threads.c -- multithreading library
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#include "Threads.h"
|
||||
#include <process.h>
|
||||
|
||||
static WRes GetError()
|
||||
{
|
||||
DWORD res = GetLastError();
|
||||
return (res) ? (WRes)(res) : 1;
|
||||
}
|
||||
|
||||
WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }
|
||||
WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }
|
||||
|
||||
static WRes MyCloseHandle(HANDLE *h)
|
||||
{
|
||||
if (*h != NULL)
|
||||
if (!CloseHandle(*h))
|
||||
return GetError();
|
||||
*h = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
|
||||
{
|
||||
unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */
|
||||
thread->handle =
|
||||
/* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */
|
||||
(HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);
|
||||
/* maybe we must use errno here, but probably GetLastError() is also OK. */
|
||||
return HandleToWRes(thread->handle);
|
||||
}
|
||||
|
||||
WRes WaitObject(HANDLE h)
|
||||
{
|
||||
return (WRes)WaitForSingleObject(h, INFINITE);
|
||||
}
|
||||
|
||||
WRes Thread_Wait(CThread *thread)
|
||||
{
|
||||
if (thread->handle == NULL)
|
||||
return 1;
|
||||
return WaitObject(thread->handle);
|
||||
}
|
||||
|
||||
WRes Thread_Close(CThread *thread)
|
||||
{
|
||||
return MyCloseHandle(&thread->handle);
|
||||
}
|
||||
|
||||
WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
|
||||
{
|
||||
p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);
|
||||
return HandleToWRes(p->handle);
|
||||
}
|
||||
|
||||
WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)
|
||||
{ return Event_Create(p, TRUE, initialSignaled); }
|
||||
WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)
|
||||
{ return ManualResetEvent_Create(p, 0); }
|
||||
|
||||
WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
|
||||
{ return Event_Create(p, FALSE, initialSignaled); }
|
||||
WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)
|
||||
{ return AutoResetEvent_Create(p, 0); }
|
||||
|
||||
WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }
|
||||
WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }
|
||||
WRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }
|
||||
WRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }
|
||||
|
||||
|
||||
WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
|
||||
{
|
||||
p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);
|
||||
return HandleToWRes(p->handle);
|
||||
}
|
||||
|
||||
WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
|
||||
{
|
||||
return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));
|
||||
}
|
||||
WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
|
||||
{
|
||||
return Semaphore_Release(p, (LONG)releaseCount, NULL);
|
||||
}
|
||||
WRes Semaphore_Release1(CSemaphore *p)
|
||||
{
|
||||
return Semaphore_ReleaseN(p, 1);
|
||||
}
|
||||
|
||||
WRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }
|
||||
WRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }
|
||||
|
||||
WRes CriticalSection_Init(CCriticalSection *p)
|
||||
{
|
||||
/* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */
|
||||
__try
|
||||
{
|
||||
InitializeCriticalSection(p);
|
||||
/* InitializeCriticalSectionAndSpinCount(p, 0); */
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER) { return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vendored
+68
@@ -0,0 +1,68 @@
|
||||
/* Threads.h -- multithreading library
|
||||
2008-11-22 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_THRESDS_H
|
||||
#define __7Z_THRESDS_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
typedef struct _CThread
|
||||
{
|
||||
HANDLE handle;
|
||||
} CThread;
|
||||
|
||||
#define Thread_Construct(thread) (thread)->handle = NULL
|
||||
#define Thread_WasCreated(thread) ((thread)->handle != NULL)
|
||||
|
||||
typedef unsigned THREAD_FUNC_RET_TYPE;
|
||||
#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
|
||||
#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
|
||||
|
||||
WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
|
||||
WRes Thread_Wait(CThread *thread);
|
||||
WRes Thread_Close(CThread *thread);
|
||||
|
||||
typedef struct _CEvent
|
||||
{
|
||||
HANDLE handle;
|
||||
} CEvent;
|
||||
|
||||
typedef CEvent CAutoResetEvent;
|
||||
typedef CEvent CManualResetEvent;
|
||||
|
||||
#define Event_Construct(event) (event)->handle = NULL
|
||||
#define Event_IsCreated(event) ((event)->handle != NULL)
|
||||
|
||||
WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
|
||||
WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
|
||||
WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
|
||||
WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
|
||||
WRes Event_Set(CEvent *event);
|
||||
WRes Event_Reset(CEvent *event);
|
||||
WRes Event_Wait(CEvent *event);
|
||||
WRes Event_Close(CEvent *event);
|
||||
|
||||
|
||||
typedef struct _CSemaphore
|
||||
{
|
||||
HANDLE handle;
|
||||
} CSemaphore;
|
||||
|
||||
#define Semaphore_Construct(p) (p)->handle = NULL
|
||||
|
||||
WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
|
||||
WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
|
||||
WRes Semaphore_Release1(CSemaphore *p);
|
||||
WRes Semaphore_Wait(CSemaphore *p);
|
||||
WRes Semaphore_Close(CSemaphore *p);
|
||||
|
||||
|
||||
typedef CRITICAL_SECTION CCriticalSection;
|
||||
|
||||
WRes CriticalSection_Init(CCriticalSection *p);
|
||||
#define CriticalSection_Delete(p) DeleteCriticalSection(p)
|
||||
#define CriticalSection_Enter(p) EnterCriticalSection(p)
|
||||
#define CriticalSection_Leave(p) LeaveCriticalSection(p)
|
||||
|
||||
#endif
|
||||
|
||||
Vendored
+208
@@ -0,0 +1,208 @@
|
||||
/* Types.h -- Basic types
|
||||
2008-11-23 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_TYPES_H
|
||||
#define __7Z_TYPES_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define SZ_OK 0
|
||||
|
||||
#define SZ_ERROR_DATA 1
|
||||
#define SZ_ERROR_MEM 2
|
||||
#define SZ_ERROR_CRC 3
|
||||
#define SZ_ERROR_UNSUPPORTED 4
|
||||
#define SZ_ERROR_PARAM 5
|
||||
#define SZ_ERROR_INPUT_EOF 6
|
||||
#define SZ_ERROR_OUTPUT_EOF 7
|
||||
#define SZ_ERROR_READ 8
|
||||
#define SZ_ERROR_WRITE 9
|
||||
#define SZ_ERROR_PROGRESS 10
|
||||
#define SZ_ERROR_FAIL 11
|
||||
#define SZ_ERROR_THREAD 12
|
||||
|
||||
#define SZ_ERROR_ARCHIVE 16
|
||||
#define SZ_ERROR_NO_ARCHIVE 17
|
||||
|
||||
typedef int SRes;
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef DWORD WRes;
|
||||
#else
|
||||
typedef int WRes;
|
||||
#endif
|
||||
|
||||
#ifndef RINOK
|
||||
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
|
||||
#endif
|
||||
|
||||
typedef unsigned char Byte;
|
||||
typedef short Int16;
|
||||
typedef unsigned short UInt16;
|
||||
|
||||
#ifdef _LZMA_UINT32_IS_ULONG
|
||||
typedef long Int32;
|
||||
typedef unsigned long UInt32;
|
||||
#else
|
||||
typedef int Int32;
|
||||
typedef unsigned int UInt32;
|
||||
#endif
|
||||
|
||||
#ifdef _SZ_NO_INT_64
|
||||
|
||||
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
|
||||
NOTES: Some code will work incorrectly in that case! */
|
||||
|
||||
typedef long Int64;
|
||||
typedef unsigned long UInt64;
|
||||
|
||||
#else
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 Int64;
|
||||
typedef unsigned __int64 UInt64;
|
||||
#else
|
||||
typedef long long int Int64;
|
||||
typedef unsigned long long int UInt64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _LZMA_NO_SYSTEM_SIZE_T
|
||||
typedef UInt32 SizeT;
|
||||
#else
|
||||
typedef size_t SizeT;
|
||||
#endif
|
||||
|
||||
typedef int Bool;
|
||||
#define True 1
|
||||
#define False 0
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#if _MSC_VER >= 1300
|
||||
#define MY_NO_INLINE __declspec(noinline)
|
||||
#else
|
||||
#define MY_NO_INLINE
|
||||
#endif
|
||||
|
||||
#define MY_CDECL __cdecl
|
||||
#define MY_STD_CALL __stdcall
|
||||
#define MY_FAST_CALL MY_NO_INLINE __fastcall
|
||||
|
||||
#else
|
||||
|
||||
#define MY_CDECL
|
||||
#define MY_STD_CALL
|
||||
#define MY_FAST_CALL
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* The following interfaces use first parameter as pointer to structure */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
} ISeqInStream;
|
||||
|
||||
/* it can return SZ_ERROR_INPUT_EOF */
|
||||
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
|
||||
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
|
||||
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t (*Write)(void *p, const void *buf, size_t size);
|
||||
/* Returns: result - the number of actually written bytes.
|
||||
(result < size) means error */
|
||||
} ISeqOutStream;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SZ_SEEK_SET = 0,
|
||||
SZ_SEEK_CUR = 1,
|
||||
SZ_SEEK_END = 2
|
||||
} ESzSeek;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
|
||||
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||
} ISeekInStream;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Look)(void *p, void **buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) > input(*size)) is not allowed
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
SRes (*Skip)(void *p, size_t offset);
|
||||
/* offset must be <= output(*size) of Look */
|
||||
|
||||
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||
/* reads directly (without buffer). It's same as ISeqInStream::Read */
|
||||
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||
} ILookInStream;
|
||||
|
||||
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
|
||||
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
|
||||
|
||||
/* reads via ILookInStream::Read */
|
||||
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
|
||||
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
|
||||
|
||||
#define LookToRead_BUF_SIZE (1 << 14)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ILookInStream s;
|
||||
ISeekInStream *realStream;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
Byte buf[LookToRead_BUF_SIZE];
|
||||
} CLookToRead;
|
||||
|
||||
void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
|
||||
void LookToRead_Init(CLookToRead *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
ILookInStream *realStream;
|
||||
} CSecToLook;
|
||||
|
||||
void SecToLook_CreateVTable(CSecToLook *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
ILookInStream *realStream;
|
||||
} CSecToRead;
|
||||
|
||||
void SecToRead_CreateVTable(CSecToRead *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
/* Returns: result. (result != SZ_OK) means break.
|
||||
Value (UInt64)(Int64)-1 for size means unknown value. */
|
||||
} ICompressProgress;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *(*Alloc)(void *p, size_t size);
|
||||
void (*Free)(void *p, void *address); /* address can be 0 */
|
||||
} ISzAlloc;
|
||||
|
||||
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
|
||||
#define IAlloc_Free(p, a) (p)->Free((p), a)
|
||||
|
||||
#endif
|
||||
Vendored
+236
@@ -0,0 +1,236 @@
|
||||
HISTORY of the LZMA SDK
|
||||
-----------------------
|
||||
|
||||
4.65 2009-02-03
|
||||
-------------------------
|
||||
- Some minor fixes
|
||||
|
||||
|
||||
4.63 2008-12-31
|
||||
-------------------------
|
||||
- Some minor fixes
|
||||
|
||||
|
||||
4.61 beta 2008-11-23
|
||||
-------------------------
|
||||
- The bug in ANSI-C LZMA Decoder was fixed:
|
||||
If encoded stream was corrupted, decoder could access memory
|
||||
outside of allocated range.
|
||||
- Some changes in ANSI-C 7z Decoder interfaces.
|
||||
- LZMA SDK is placed in the public domain.
|
||||
|
||||
|
||||
4.60 beta 2008-08-19
|
||||
-------------------------
|
||||
- Some minor fixes.
|
||||
|
||||
|
||||
4.59 beta 2008-08-13
|
||||
-------------------------
|
||||
- The bug was fixed:
|
||||
LZMA Encoder in fast compression mode could access memory outside of
|
||||
allocated range in some rare cases.
|
||||
|
||||
|
||||
4.58 beta 2008-05-05
|
||||
-------------------------
|
||||
- ANSI-C LZMA Decoder was rewritten for speed optimizations.
|
||||
- ANSI-C LZMA Encoder was included to LZMA SDK.
|
||||
- C++ LZMA code now is just wrapper over ANSI-C code.
|
||||
|
||||
|
||||
4.57 2007-12-12
|
||||
-------------------------
|
||||
- Speed optimizations in Ñ++ LZMA Decoder.
|
||||
- Small changes for more compatibility with some C/C++ compilers.
|
||||
|
||||
|
||||
4.49 beta 2007-07-05
|
||||
-------------------------
|
||||
- .7z ANSI-C Decoder:
|
||||
- now it supports BCJ and BCJ2 filters
|
||||
- now it supports files larger than 4 GB.
|
||||
- now it supports "Last Write Time" field for files.
|
||||
- C++ code for .7z archives compressing/decompressing from 7-zip
|
||||
was included to LZMA SDK.
|
||||
|
||||
|
||||
4.43 2006-06-04
|
||||
-------------------------
|
||||
- Small changes for more compatibility with some C/C++ compilers.
|
||||
|
||||
|
||||
4.42 2006-05-15
|
||||
-------------------------
|
||||
- Small changes in .h files in ANSI-C version.
|
||||
|
||||
|
||||
4.39 beta 2006-04-14
|
||||
-------------------------
|
||||
- The bug in versions 4.33b:4.38b was fixed:
|
||||
C++ version of LZMA encoder could not correctly compress
|
||||
files larger than 2 GB with HC4 match finder (-mfhc4).
|
||||
|
||||
|
||||
4.37 beta 2005-04-06
|
||||
-------------------------
|
||||
- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined.
|
||||
|
||||
|
||||
4.35 beta 2005-03-02
|
||||
-------------------------
|
||||
- The bug was fixed in C++ version of LZMA Decoder:
|
||||
If encoded stream was corrupted, decoder could access memory
|
||||
outside of allocated range.
|
||||
|
||||
|
||||
4.34 beta 2006-02-27
|
||||
-------------------------
|
||||
- Compressing speed and memory requirements for compressing were increased
|
||||
- LZMA now can use only these match finders: HC4, BT2, BT3, BT4
|
||||
|
||||
|
||||
4.32 2005-12-09
|
||||
-------------------------
|
||||
- Java version of LZMA SDK was included
|
||||
|
||||
|
||||
4.30 2005-11-20
|
||||
-------------------------
|
||||
- Compression ratio was improved in -a2 mode
|
||||
- Speed optimizations for compressing in -a2 mode
|
||||
- -fb switch now supports values up to 273
|
||||
- The bug in 7z_C (7zIn.c) was fixed:
|
||||
It used Alloc/Free functions from different memory pools.
|
||||
So if program used two memory pools, it worked incorrectly.
|
||||
- 7z_C: .7z format supporting was improved
|
||||
- LZMA# SDK (C#.NET version) was included
|
||||
|
||||
|
||||
4.27 (Updated) 2005-09-21
|
||||
-------------------------
|
||||
- Some GUIDs/interfaces in C++ were changed.
|
||||
IStream.h:
|
||||
ISequentialInStream::Read now works as old ReadPart
|
||||
ISequentialOutStream::Write now works as old WritePart
|
||||
|
||||
|
||||
4.27 2005-08-07
|
||||
-------------------------
|
||||
- The bug in LzmaDecodeSize.c was fixed:
|
||||
if _LZMA_IN_CB and _LZMA_OUT_READ were defined,
|
||||
decompressing worked incorrectly.
|
||||
|
||||
|
||||
4.26 2005-08-05
|
||||
-------------------------
|
||||
- Fixes in 7z_C code and LzmaTest.c:
|
||||
previous versions could work incorrectly,
|
||||
if malloc(0) returns 0
|
||||
|
||||
|
||||
4.23 2005-06-29
|
||||
-------------------------
|
||||
- Small fixes in C++ code
|
||||
|
||||
|
||||
4.22 2005-06-10
|
||||
-------------------------
|
||||
- Small fixes
|
||||
|
||||
|
||||
4.21 2005-06-08
|
||||
-------------------------
|
||||
- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed
|
||||
- New additional version of ANSI-C LZMA Decoder with zlib-like interface:
|
||||
- LzmaStateDecode.h
|
||||
- LzmaStateDecode.c
|
||||
- LzmaStateTest.c
|
||||
- ANSI-C LZMA Decoder now can decompress files larger than 4 GB
|
||||
|
||||
|
||||
4.17 2005-04-18
|
||||
-------------------------
|
||||
- New example for RAM->RAM compressing/decompressing:
|
||||
LZMA + BCJ (filter for x86 code):
|
||||
- LzmaRam.h
|
||||
- LzmaRam.cpp
|
||||
- LzmaRamDecode.h
|
||||
- LzmaRamDecode.c
|
||||
- -f86 switch for lzma.exe
|
||||
|
||||
|
||||
4.16 2005-03-29
|
||||
-------------------------
|
||||
- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder):
|
||||
If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,
|
||||
decoder could access memory outside of allocated range.
|
||||
- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).
|
||||
Old version of LZMA Decoder now is in file LzmaDecodeSize.c.
|
||||
LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c
|
||||
- Small speed optimization in LZMA C++ code
|
||||
- filter for SPARC's code was added
|
||||
- Simplified version of .7z ANSI-C Decoder was included
|
||||
|
||||
|
||||
4.06 2004-09-05
|
||||
-------------------------
|
||||
- The bug in v4.05 was fixed:
|
||||
LZMA-Encoder didn't release output stream in some cases.
|
||||
|
||||
|
||||
4.05 2004-08-25
|
||||
-------------------------
|
||||
- Source code of filters for x86, IA-64, ARM, ARM-Thumb
|
||||
and PowerPC code was included to SDK
|
||||
- Some internal minor changes
|
||||
|
||||
|
||||
4.04 2004-07-28
|
||||
-------------------------
|
||||
- More compatibility with some C++ compilers
|
||||
|
||||
|
||||
4.03 2004-06-18
|
||||
-------------------------
|
||||
- "Benchmark" command was added. It measures compressing
|
||||
and decompressing speed and shows rating values.
|
||||
Also it checks hardware errors.
|
||||
|
||||
|
||||
4.02 2004-06-10
|
||||
-------------------------
|
||||
- C++ LZMA Encoder/Decoder code now is more portable
|
||||
and it can be compiled by GCC on Linux.
|
||||
|
||||
|
||||
4.01 2004-02-15
|
||||
-------------------------
|
||||
- Some detection of data corruption was enabled.
|
||||
LzmaDecode.c / RangeDecoderReadByte
|
||||
.....
|
||||
{
|
||||
rd->ExtraBytes = 1;
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
|
||||
4.00 2004-02-13
|
||||
-------------------------
|
||||
- Original version of LZMA SDK
|
||||
|
||||
|
||||
|
||||
HISTORY of the LZMA
|
||||
-------------------
|
||||
2001-2008: Improvements to LZMA compressing/decompressing code,
|
||||
keeping compatibility with original LZMA format
|
||||
1996-2001: Development of LZMA compression format
|
||||
|
||||
Some milestones:
|
||||
|
||||
2001-08-30: LZMA compression was added to 7-Zip
|
||||
1999-01-02: First version of 7-Zip was released
|
||||
|
||||
|
||||
End of document
|
||||
Vendored
+594
@@ -0,0 +1,594 @@
|
||||
LZMA SDK 4.65
|
||||
-------------
|
||||
|
||||
LZMA SDK provides the documentation, samples, header files, libraries,
|
||||
and tools you need to develop applications that use LZMA compression.
|
||||
|
||||
LZMA is default and general compression method of 7z format
|
||||
in 7-Zip compression program (www.7-zip.org). LZMA provides high
|
||||
compression ratio and very fast decompression.
|
||||
|
||||
LZMA is an improved version of famous LZ77 compression algorithm.
|
||||
It was improved in way of maximum increasing of compression ratio,
|
||||
keeping high decompression speed and low memory requirements for
|
||||
decompressing.
|
||||
|
||||
|
||||
|
||||
LICENSE
|
||||
-------
|
||||
|
||||
LZMA SDK is written and placed in the public domain by Igor Pavlov.
|
||||
|
||||
|
||||
LZMA SDK Contents
|
||||
-----------------
|
||||
|
||||
LZMA SDK includes:
|
||||
|
||||
- ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing
|
||||
- Compiled file->file LZMA compressing/decompressing program for Windows system
|
||||
|
||||
|
||||
UNIX/Linux version
|
||||
------------------
|
||||
To compile C++ version of file->file LZMA encoding, go to directory
|
||||
C++/7zip/Compress/LZMA_Alone
|
||||
and call make to recompile it:
|
||||
make -f makefile.gcc clean all
|
||||
|
||||
In some UNIX/Linux versions you must compile LZMA with static libraries.
|
||||
To compile with static libraries, you can use
|
||||
LIB = -lm -static
|
||||
|
||||
|
||||
Files
|
||||
---------------------
|
||||
lzma.txt - LZMA SDK description (this file)
|
||||
7zFormat.txt - 7z Format description
|
||||
7zC.txt - 7z ANSI-C Decoder description
|
||||
methods.txt - Compression method IDs for .7z
|
||||
lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
|
||||
history.txt - history of the LZMA SDK
|
||||
|
||||
|
||||
Source code structure
|
||||
---------------------
|
||||
|
||||
C/ - C files
|
||||
7zCrc*.* - CRC code
|
||||
Alloc.* - Memory allocation functions
|
||||
Bra*.* - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
|
||||
LzFind.* - Match finder for LZ (LZMA) encoders
|
||||
LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding
|
||||
LzHash.h - Additional file for LZ match finder
|
||||
LzmaDec.* - LZMA decoding
|
||||
LzmaEnc.* - LZMA encoding
|
||||
LzmaLib.* - LZMA Library for DLL calling
|
||||
Types.h - Basic types for another .c files
|
||||
Threads.* - The code for multithreading.
|
||||
|
||||
LzmaLib - LZMA Library (.DLL for Windows)
|
||||
|
||||
LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).
|
||||
|
||||
Archive - files related to archiving
|
||||
7z - 7z ANSI-C Decoder
|
||||
|
||||
CPP/ -- CPP files
|
||||
|
||||
Common - common files for C++ projects
|
||||
Windows - common files for Windows related code
|
||||
|
||||
7zip - files related to 7-Zip Project
|
||||
|
||||
Common - common files for 7-Zip
|
||||
|
||||
Compress - files related to compression/decompression
|
||||
|
||||
Copy - Copy coder
|
||||
RangeCoder - Range Coder (special code of compression/decompression)
|
||||
LZMA - LZMA compression/decompression on C++
|
||||
LZMA_Alone - file->file LZMA compression/decompression
|
||||
Branch - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
|
||||
|
||||
Archive - files related to archiving
|
||||
|
||||
Common - common files for archive handling
|
||||
7z - 7z C++ Encoder/Decoder
|
||||
|
||||
Bundles - Modules that are bundles of other modules
|
||||
|
||||
Alone7z - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2
|
||||
Format7zR - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2
|
||||
Format7zExtractR - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.
|
||||
|
||||
UI - User Interface files
|
||||
|
||||
Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll
|
||||
Common - Common UI files
|
||||
Console - Code for console archiver
|
||||
|
||||
|
||||
|
||||
CS/ - C# files
|
||||
7zip
|
||||
Common - some common files for 7-Zip
|
||||
Compress - files related to compression/decompression
|
||||
LZ - files related to LZ (Lempel-Ziv) compression algorithm
|
||||
LZMA - LZMA compression/decompression
|
||||
LzmaAlone - file->file LZMA compression/decompression
|
||||
RangeCoder - Range Coder (special code of compression/decompression)
|
||||
|
||||
Java/ - Java files
|
||||
SevenZip
|
||||
Compression - files related to compression/decompression
|
||||
LZ - files related to LZ (Lempel-Ziv) compression algorithm
|
||||
LZMA - LZMA compression/decompression
|
||||
RangeCoder - Range Coder (special code of compression/decompression)
|
||||
|
||||
|
||||
C/C++ source code of LZMA SDK is part of 7-Zip project.
|
||||
7-Zip source code can be downloaded from 7-Zip's SourceForge page:
|
||||
|
||||
http://sourceforge.net/projects/sevenzip/
|
||||
|
||||
|
||||
|
||||
LZMA features
|
||||
-------------
|
||||
- Variable dictionary size (up to 1 GB)
|
||||
- Estimated compressing speed: about 2 MB/s on 2 GHz CPU
|
||||
- Estimated decompressing speed:
|
||||
- 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64
|
||||
- 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC
|
||||
- Small memory requirements for decompressing (16 KB + DictionarySize)
|
||||
- Small code size for decompressing: 5-8 KB
|
||||
|
||||
LZMA decoder uses only integer operations and can be
|
||||
implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
|
||||
|
||||
Some critical operations that affect the speed of LZMA decompression:
|
||||
1) 32*16 bit integer multiply
|
||||
2) Misspredicted branches (penalty mostly depends from pipeline length)
|
||||
3) 32-bit shift and arithmetic operations
|
||||
|
||||
The speed of LZMA decompressing mostly depends from CPU speed.
|
||||
Memory speed has no big meaning. But if your CPU has small data cache,
|
||||
overall weight of memory speed will slightly increase.
|
||||
|
||||
|
||||
How To Use
|
||||
----------
|
||||
|
||||
Using LZMA encoder/decoder executable
|
||||
--------------------------------------
|
||||
|
||||
Usage: LZMA <e|d> inputFile outputFile [<switches>...]
|
||||
|
||||
e: encode file
|
||||
|
||||
d: decode file
|
||||
|
||||
b: Benchmark. There are two tests: compressing and decompressing
|
||||
with LZMA method. Benchmark shows rating in MIPS (million
|
||||
instructions per second). Rating value is calculated from
|
||||
measured speed and it is normalized with Intel's Core 2 results.
|
||||
Also Benchmark checks possible hardware errors (RAM
|
||||
errors in most cases). Benchmark uses these settings:
|
||||
(-a1, -d21, -fb32, -mfbt4). You can change only -d parameter.
|
||||
Also you can change the number of iterations. Example for 30 iterations:
|
||||
LZMA b 30
|
||||
Default number of iterations is 10.
|
||||
|
||||
<Switches>
|
||||
|
||||
|
||||
-a{N}: set compression mode 0 = fast, 1 = normal
|
||||
default: 1 (normal)
|
||||
|
||||
d{N}: Sets Dictionary size - [0, 30], default: 23 (8MB)
|
||||
The maximum value for dictionary size is 1 GB = 2^30 bytes.
|
||||
Dictionary size is calculated as DictionarySize = 2^N bytes.
|
||||
For decompressing file compressed by LZMA method with dictionary
|
||||
size D = 2^N you need about D bytes of memory (RAM).
|
||||
|
||||
-fb{N}: set number of fast bytes - [5, 273], default: 128
|
||||
Usually big number gives a little bit better compression ratio
|
||||
and slower compression process.
|
||||
|
||||
-lc{N}: set number of literal context bits - [0, 8], default: 3
|
||||
Sometimes lc=4 gives gain for big files.
|
||||
|
||||
-lp{N}: set number of literal pos bits - [0, 4], default: 0
|
||||
lp switch is intended for periodical data when period is
|
||||
equal 2^N. For example, for 32-bit (4 bytes)
|
||||
periodical data you can use lp=2. Often it's better to set lc0,
|
||||
if you change lp switch.
|
||||
|
||||
-pb{N}: set number of pos bits - [0, 4], default: 2
|
||||
pb switch is intended for periodical data
|
||||
when period is equal 2^N.
|
||||
|
||||
-mf{MF_ID}: set Match Finder. Default: bt4.
|
||||
Algorithms from hc* group doesn't provide good compression
|
||||
ratio, but they often works pretty fast in combination with
|
||||
fast mode (-a0).
|
||||
|
||||
Memory requirements depend from dictionary size
|
||||
(parameter "d" in table below).
|
||||
|
||||
MF_ID Memory Description
|
||||
|
||||
bt2 d * 9.5 + 4MB Binary Tree with 2 bytes hashing.
|
||||
bt3 d * 11.5 + 4MB Binary Tree with 3 bytes hashing.
|
||||
bt4 d * 11.5 + 4MB Binary Tree with 4 bytes hashing.
|
||||
hc4 d * 7.5 + 4MB Hash Chain with 4 bytes hashing.
|
||||
|
||||
-eos: write End Of Stream marker. By default LZMA doesn't write
|
||||
eos marker, since LZMA decoder knows uncompressed size
|
||||
stored in .lzma file header.
|
||||
|
||||
-si: Read data from stdin (it will write End Of Stream marker).
|
||||
-so: Write data to stdout
|
||||
|
||||
|
||||
Examples:
|
||||
|
||||
1) LZMA e file.bin file.lzma -d16 -lc0
|
||||
|
||||
compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)
|
||||
and 0 literal context bits. -lc0 allows to reduce memory requirements
|
||||
for decompression.
|
||||
|
||||
|
||||
2) LZMA e file.bin file.lzma -lc0 -lp2
|
||||
|
||||
compresses file.bin to file.lzma with settings suitable
|
||||
for 32-bit periodical data (for example, ARM or MIPS code).
|
||||
|
||||
3) LZMA d file.lzma file.bin
|
||||
|
||||
decompresses file.lzma to file.bin.
|
||||
|
||||
|
||||
Compression ratio hints
|
||||
-----------------------
|
||||
|
||||
Recommendations
|
||||
---------------
|
||||
|
||||
To increase the compression ratio for LZMA compressing it's desirable
|
||||
to have aligned data (if it's possible) and also it's desirable to locate
|
||||
data in such order, where code is grouped in one place and data is
|
||||
grouped in other place (it's better than such mixing: code, data, code,
|
||||
data, ...).
|
||||
|
||||
|
||||
Filters
|
||||
-------
|
||||
You can increase the compression ratio for some data types, using
|
||||
special filters before compressing. For example, it's possible to
|
||||
increase the compression ratio on 5-10% for code for those CPU ISAs:
|
||||
x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
|
||||
|
||||
You can find C source code of such filters in C/Bra*.* files
|
||||
|
||||
You can check the compression ratio gain of these filters with such
|
||||
7-Zip commands (example for ARM code):
|
||||
No filter:
|
||||
7z a a1.7z a.bin -m0=lzma
|
||||
|
||||
With filter for little-endian ARM code:
|
||||
7z a a2.7z a.bin -m0=arm -m1=lzma
|
||||
|
||||
It works in such manner:
|
||||
Compressing = Filter_encoding + LZMA_encoding
|
||||
Decompressing = LZMA_decoding + Filter_decoding
|
||||
|
||||
Compressing and decompressing speed of such filters is very high,
|
||||
so it will not increase decompressing time too much.
|
||||
Moreover, it reduces decompression time for LZMA_decoding,
|
||||
since compression ratio with filtering is higher.
|
||||
|
||||
These filters convert CALL (calling procedure) instructions
|
||||
from relative offsets to absolute addresses, so such data becomes more
|
||||
compressible.
|
||||
|
||||
For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
|
||||
|
||||
|
||||
LZMA compressed file format
|
||||
---------------------------
|
||||
Offset Size Description
|
||||
0 1 Special LZMA properties (lc,lp, pb in encoded form)
|
||||
1 4 Dictionary size (little endian)
|
||||
5 8 Uncompressed size (little endian). -1 means unknown size
|
||||
13 Compressed data
|
||||
|
||||
|
||||
ANSI-C LZMA Decoder
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.
|
||||
If you want to use old interfaces you can download previous version of LZMA SDK
|
||||
from sourceforge.net site.
|
||||
|
||||
To use ANSI-C LZMA Decoder you need the following files:
|
||||
1) LzmaDec.h + LzmaDec.c + Types.h
|
||||
LzmaUtil/LzmaUtil.c is example application that uses these files.
|
||||
|
||||
|
||||
Memory requirements for LZMA decoding
|
||||
-------------------------------------
|
||||
|
||||
Stack usage of LZMA decoding function for local variables is not
|
||||
larger than 200-400 bytes.
|
||||
|
||||
LZMA Decoder uses dictionary buffer and internal state structure.
|
||||
Internal state structure consumes
|
||||
state_size = (4 + (1.5 << (lc + lp))) KB
|
||||
by default (lc=3, lp=0), state_size = 16 KB.
|
||||
|
||||
|
||||
How To decompress data
|
||||
----------------------
|
||||
|
||||
LZMA Decoder (ANSI-C version) now supports 2 interfaces:
|
||||
1) Single-call Decompressing
|
||||
2) Multi-call State Decompressing (zlib-like interface)
|
||||
|
||||
You must use external allocator:
|
||||
Example:
|
||||
void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }
|
||||
void SzFree(void *p, void *address) { p = p; free(address); }
|
||||
ISzAlloc alloc = { SzAlloc, SzFree };
|
||||
|
||||
You can use p = p; operator to disable compiler warnings.
|
||||
|
||||
|
||||
Single-call Decompressing
|
||||
-------------------------
|
||||
When to use: RAM->RAM decompressing
|
||||
Compile files: LzmaDec.h + LzmaDec.c + Types.h
|
||||
Compile defines: no defines
|
||||
Memory Requirements:
|
||||
- Input buffer: compressed size
|
||||
- Output buffer: uncompressed size
|
||||
- LZMA Internal Structures: state_size (16 KB for default settings)
|
||||
|
||||
Interface:
|
||||
int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
|
||||
ELzmaStatus *status, ISzAlloc *alloc);
|
||||
In:
|
||||
dest - output data
|
||||
destLen - output data size
|
||||
src - input data
|
||||
srcLen - input data size
|
||||
propData - LZMA properties (5 bytes)
|
||||
propSize - size of propData buffer (5 bytes)
|
||||
finishMode - It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
You can use LZMA_FINISH_END, when you know that
|
||||
current output buffer covers last bytes of stream.
|
||||
alloc - Memory allocator.
|
||||
|
||||
Out:
|
||||
destLen - processed output size
|
||||
srcLen - processed input size
|
||||
|
||||
Output:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
|
||||
|
||||
If LZMA decoder sees end_marker before reaching output limit, it returns OK result,
|
||||
and output value of destLen will be less than output buffer size limit.
|
||||
|
||||
You can use multiple checks to test data integrity after full decompression:
|
||||
1) Check Result and "status" variable.
|
||||
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
|
||||
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
|
||||
You must use correct finish mode in that case. */
|
||||
|
||||
|
||||
Multi-call State Decompressing (zlib-like interface)
|
||||
----------------------------------------------------
|
||||
|
||||
When to use: file->file decompressing
|
||||
Compile files: LzmaDec.h + LzmaDec.c + Types.h
|
||||
|
||||
Memory Requirements:
|
||||
- Buffer for input stream: any size (for example, 16 KB)
|
||||
- Buffer for output stream: any size (for example, 16 KB)
|
||||
- LZMA Internal Structures: state_size (16 KB for default settings)
|
||||
- LZMA dictionary (dictionary size is encoded in LZMA properties header)
|
||||
|
||||
1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:
|
||||
unsigned char header[LZMA_PROPS_SIZE + 8];
|
||||
ReadFile(inFile, header, sizeof(header)
|
||||
|
||||
2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties
|
||||
|
||||
CLzmaDec state;
|
||||
LzmaDec_Constr(&state);
|
||||
res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
|
||||
if (res != SZ_OK)
|
||||
return res;
|
||||
|
||||
3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop
|
||||
|
||||
LzmaDec_Init(&state);
|
||||
for (;;)
|
||||
{
|
||||
...
|
||||
int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
4) Free all allocated structures
|
||||
LzmaDec_Free(&state, &g_Alloc);
|
||||
|
||||
For full code example, look at C/LzmaUtil/LzmaUtil.c code.
|
||||
|
||||
|
||||
How To compress data
|
||||
--------------------
|
||||
|
||||
Compile files: LzmaEnc.h + LzmaEnc.c + Types.h +
|
||||
LzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h
|
||||
|
||||
Memory Requirements:
|
||||
- (dictSize * 11.5 + 6 MB) + state_size
|
||||
|
||||
Lzma Encoder can use two memory allocators:
|
||||
1) alloc - for small arrays.
|
||||
2) allocBig - for big arrays.
|
||||
|
||||
For example, you can use Large RAM Pages (2 MB) in allocBig allocator for
|
||||
better compression speed. Note that Windows has bad implementation for
|
||||
Large RAM Pages.
|
||||
It's OK to use same allocator for alloc and allocBig.
|
||||
|
||||
|
||||
Single-call Compression with callbacks
|
||||
--------------------------------------
|
||||
|
||||
Check C/LzmaUtil/LzmaUtil.c as example,
|
||||
|
||||
When to use: file->file decompressing
|
||||
|
||||
1) you must implement callback structures for interfaces:
|
||||
ISeqInStream
|
||||
ISeqOutStream
|
||||
ICompressProgress
|
||||
ISzAlloc
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
||||
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
|
||||
CFileSeqInStream inStream;
|
||||
CFileSeqOutStream outStream;
|
||||
|
||||
inStream.funcTable.Read = MyRead;
|
||||
inStream.file = inFile;
|
||||
outStream.funcTable.Write = MyWrite;
|
||||
outStream.file = outFile;
|
||||
|
||||
|
||||
2) Create CLzmaEncHandle object;
|
||||
|
||||
CLzmaEncHandle enc;
|
||||
|
||||
enc = LzmaEnc_Create(&g_Alloc);
|
||||
if (enc == 0)
|
||||
return SZ_ERROR_MEM;
|
||||
|
||||
|
||||
3) initialize CLzmaEncProps properties;
|
||||
|
||||
LzmaEncProps_Init(&props);
|
||||
|
||||
Then you can change some properties in that structure.
|
||||
|
||||
4) Send LZMA properties to LZMA Encoder
|
||||
|
||||
res = LzmaEnc_SetProps(enc, &props);
|
||||
|
||||
5) Write encoded properties to header
|
||||
|
||||
Byte header[LZMA_PROPS_SIZE + 8];
|
||||
size_t headerSize = LZMA_PROPS_SIZE;
|
||||
UInt64 fileSize;
|
||||
int i;
|
||||
|
||||
res = LzmaEnc_WriteProperties(enc, header, &headerSize);
|
||||
fileSize = MyGetFileLength(inFile);
|
||||
for (i = 0; i < 8; i++)
|
||||
header[headerSize++] = (Byte)(fileSize >> (8 * i));
|
||||
MyWriteFileAndCheck(outFile, header, headerSize)
|
||||
|
||||
6) Call encoding function:
|
||||
res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
|
||||
NULL, &g_Alloc, &g_Alloc);
|
||||
|
||||
7) Destroy LZMA Encoder Object
|
||||
LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
|
||||
|
||||
|
||||
If callback function return some error code, LzmaEnc_Encode also returns that code.
|
||||
|
||||
|
||||
Single-call RAM->RAM Compression
|
||||
--------------------------------
|
||||
|
||||
Single-call RAM->RAM Compression is similar to Compression with callbacks,
|
||||
but you provide pointers to buffers instead of pointers to stream callbacks:
|
||||
|
||||
HRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
|
||||
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
|
||||
Return code:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater
|
||||
SZ_ERROR_OUTPUT_EOF - output buffer overflow
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
|
||||
|
||||
|
||||
LZMA Defines
|
||||
------------
|
||||
|
||||
_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.
|
||||
|
||||
_LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for
|
||||
some structures will be doubled in that case.
|
||||
|
||||
_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler and long is 32-bit.
|
||||
|
||||
_LZMA_NO_SYSTEM_SIZE_T - Define it if you don't want to use size_t type.
|
||||
|
||||
|
||||
C++ LZMA Encoder/Decoder
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
C++ LZMA code use COM-like interfaces. So if you want to use it,
|
||||
you can study basics of COM/OLE.
|
||||
C++ LZMA code is just wrapper over ANSI-C code.
|
||||
|
||||
|
||||
C++ Notes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),
|
||||
you must check that you correctly work with "new" operator.
|
||||
7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.
|
||||
So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:
|
||||
operator new(size_t size)
|
||||
{
|
||||
void *p = ::malloc(size);
|
||||
if (p == 0)
|
||||
throw CNewException();
|
||||
return p;
|
||||
}
|
||||
If you use MSCV that throws exception for "new" operator, you can compile without
|
||||
"NewHandler.cpp". So standard exception will be used. Actually some code of
|
||||
7-Zip catches any exception in internal code and converts it to HRESULT code.
|
||||
So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.
|
||||
|
||||
---
|
||||
|
||||
http://www.7-zip.org
|
||||
http://www.7-zip.org/sdk.html
|
||||
http://www.7-zip.org/support.html
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
# $Id$
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# The Original Code is Copyright (C) 2006, Blender Foundation
|
||||
# All rights reserved.
|
||||
#
|
||||
# The Original Code is: all of this file.
|
||||
#
|
||||
# Contributor(s): Daniel Genrich
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
SET(INC include)
|
||||
|
||||
FILE(GLOB SRC minilzo/*.c)
|
||||
|
||||
|
||||
|
||||
BLENDERLIB(bf_minilzo "${SRC}" "${INC}")
|
||||
#, libtype='blender', priority = 0 )
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/python
|
||||
Import ('env')
|
||||
|
||||
sources = env.Glob('minilzo/*.c')
|
||||
|
||||
defs = ''
|
||||
incs = ' include '
|
||||
|
||||
env.BlenderLib ('bf_minilzo', sources, Split(incs), Split(defs), libtype=['intern'], priority=[40] )
|
||||
Vendored
+340
@@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
Vendored
+113
@@ -0,0 +1,113 @@
|
||||
#
|
||||
# a very simple Makefile for miniLZO
|
||||
#
|
||||
# Copyright (C) 1996-2008 Markus F.X.J. Oberhumer
|
||||
#
|
||||
|
||||
PROGRAM = testmini
|
||||
SOURCES = testmini.c minilzo.c
|
||||
|
||||
default:
|
||||
@echo "Please choose one of the following targets:"
|
||||
@echo " gcc: gcc"
|
||||
@echo " unix: hpux hpux9"
|
||||
@echo " win32: win32-bc win32-cygwin win32-dm win32-lccwin32"
|
||||
@echo " win32-intelc win32-mingw win32-vc win32-watcomc"
|
||||
@echo " dos16: dos16-bc dos16-mc dos16-wc"
|
||||
@echo " dos32: dos32-djgpp2 dos32-wc"
|
||||
|
||||
|
||||
# Make sure that minilzo.h, lzoconf.h and lzodefs.h are in the
|
||||
# current dircectory. Otherwise you may want to adjust CPPFLAGS.
|
||||
##CPPFLAGS = -I../include/lzo -I.
|
||||
|
||||
GCC_CFLAGS = -s -Wall -O2 -fomit-frame-pointer
|
||||
|
||||
|
||||
#
|
||||
# gcc (generic)
|
||||
#
|
||||
|
||||
gcc:
|
||||
gcc $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM) $(SOURCES)
|
||||
|
||||
cc:
|
||||
cc $(CPPFLAGS) -o $(PROGRAM) $(SOURCES)
|
||||
|
||||
|
||||
#
|
||||
# UNIX
|
||||
#
|
||||
|
||||
hpux:
|
||||
cc -Ae $(CPPFLAGS) -o $(PROGRAM) $(SOURCES)
|
||||
|
||||
hpux9:
|
||||
cc -Aa -D_HPUX_SOURCE $(CPPFLAGS) -o $(PROGRAM) $(SOURCES)
|
||||
|
||||
|
||||
#
|
||||
# Windows (32-bit)
|
||||
#
|
||||
|
||||
win32-borlandc win32-bc:
|
||||
bcc32 -O2 -d -w -w-aus $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
win32-cygwin32 win32-cygwin:
|
||||
gcc -mcygwin $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES)
|
||||
|
||||
win32-digitalmars win32-dm:
|
||||
dmc -mn -o -w- $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
win32-intelc win32-ic:
|
||||
icl -nologo -MD -W3 -O2 -GF $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
win32-lccwin32:
|
||||
@echo "NOTE: need lcc 2002-07-25 or newer, older versions have bugs"
|
||||
lc -A -unused -O $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
win32-mingw32 win32-mingw:
|
||||
gcc -mno-cygwin $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES)
|
||||
|
||||
win32-visualc win32-vc:
|
||||
cl -nologo -MD -W3 -O2 -GF $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
win32-watcomc win32-wc:
|
||||
wcl386 -bt=nt -zq -mf -5r -zc -w5 -oneatx $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
|
||||
#
|
||||
# DOS (16-bit)
|
||||
#
|
||||
|
||||
dos16-borlandc dos16-bc:
|
||||
bcc -ml -w -d -O -4 $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
dos16-microsoftc dos16-msc dos16-mc:
|
||||
cl -nologo -f- -AL -O -G2 -W3 $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
dos16-watcomc dos16-wc:
|
||||
wcl -zq -ml -bt=dos -l=dos -ox -w5 $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
|
||||
#
|
||||
# DOS (32-bit)
|
||||
#
|
||||
|
||||
dos32-djgpp2 dos32-dj2:
|
||||
gcc $(CPPFLAGS) $(GCC_CFLAGS) -o $(PROGRAM).exe $(SOURCES)
|
||||
|
||||
dos32-watcomc dos32-wc:
|
||||
wcl386 -zq -mf -bt=dos -l=dos4g -5r -ox -zc $(CPPFLAGS) $(SOURCES)
|
||||
|
||||
|
||||
#
|
||||
# other targets
|
||||
#
|
||||
|
||||
clean:
|
||||
rm -f $(PROGRAM) $(PROGRAM).exe $(PROGRAM).map $(PROGRAM).tds
|
||||
rm -f *.err *.o *.obj
|
||||
|
||||
.PHONY: default clean
|
||||
|
||||
Vendored
+123
@@ -0,0 +1,123 @@
|
||||
|
||||
============================================================================
|
||||
miniLZO -- mini subset of the LZO real-time data compression library
|
||||
============================================================================
|
||||
|
||||
Author : Markus Franz Xaver Johannes Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
Version : 2.03
|
||||
Date : 30 Apr 2008
|
||||
|
||||
I've created miniLZO for projects where it is inconvenient to
|
||||
include (or require) the full LZO source code just because you
|
||||
want to add a little bit of data compression to your application.
|
||||
|
||||
miniLZO implements the LZO1X-1 compressor and both the standard and
|
||||
safe LZO1X decompressor. Apart from fast compression it also useful
|
||||
for situations where you want to use pre-compressed data files (which
|
||||
must have been compressed with LZO1X-999).
|
||||
|
||||
miniLZO consists of one C source file and three header files:
|
||||
minilzo.c
|
||||
minilzo.h, lzoconf.h, lzodefs.h
|
||||
|
||||
To use miniLZO just copy these files into your source directory, add
|
||||
minilzo.c to your Makefile and #include minilzo.h from your program.
|
||||
Note: you also must distribute this file (`README.LZO') with your project.
|
||||
|
||||
minilzo.o compiles to about 6 kB (using gcc or Visual C on a i386), and
|
||||
the sources are about 30 kB when packed with zip - so there's no more
|
||||
excuse that your application doesn't support data compression :-)
|
||||
|
||||
For more information, documentation, example programs and other support
|
||||
files (like Makefiles and build scripts) please download the full LZO
|
||||
package from
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
Have fun,
|
||||
Markus
|
||||
|
||||
|
||||
P.S. minilzo.c is generated automatically from the LZO sources and
|
||||
therefore functionality is completely identical
|
||||
|
||||
|
||||
Appendix A: building miniLZO
|
||||
----------------------------
|
||||
miniLZO is written such a way that it should compile and run
|
||||
out-of-the-box on most machines.
|
||||
|
||||
If you are running on a very unusual architecture and lzo_init() fails then
|
||||
you should first recompile with `-DLZO_DEBUG' to see what causes the failure.
|
||||
The most probable case is something like `sizeof(char *) != sizeof(long)'.
|
||||
After identifying the problem you can compile by adding some defines
|
||||
like `-DSIZEOF_CHAR_P=8' to your Makefile.
|
||||
|
||||
The best solution is (of course) using Autoconf - if your project uses
|
||||
Autoconf anyway just add `-DMINILZO_HAVE_CONFIG_H' to your compiler
|
||||
flags when compiling minilzo.c. See the LZO distribution for an example
|
||||
how to set up configure.in.
|
||||
|
||||
|
||||
Appendix B: list of public functions available in miniLZO
|
||||
---------------------------------------------------------
|
||||
Library initialization
|
||||
lzo_init()
|
||||
|
||||
Compression
|
||||
lzo1x_1_compress()
|
||||
|
||||
Decompression
|
||||
lzo1x_decompress()
|
||||
lzo1x_decompress_safe()
|
||||
|
||||
Checksum functions
|
||||
lzo_adler32()
|
||||
|
||||
Version functions
|
||||
lzo_version()
|
||||
lzo_version_string()
|
||||
lzo_version_date()
|
||||
|
||||
Portable (but slow) string functions
|
||||
lzo_memcmp()
|
||||
lzo_memcpy()
|
||||
lzo_memmove()
|
||||
lzo_memset()
|
||||
|
||||
|
||||
Appendix C: suggested macros for `configure.in' when using Autoconf
|
||||
-------------------------------------------------------------------
|
||||
Checks for typedefs and structures
|
||||
AC_CHECK_TYPE(ptrdiff_t,long)
|
||||
AC_TYPE_SIZE_T
|
||||
AC_CHECK_SIZEOF(short)
|
||||
AC_CHECK_SIZEOF(int)
|
||||
AC_CHECK_SIZEOF(long)
|
||||
AC_CHECK_SIZEOF(long long)
|
||||
AC_CHECK_SIZEOF(__int64)
|
||||
AC_CHECK_SIZEOF(void *)
|
||||
AC_CHECK_SIZEOF(size_t)
|
||||
AC_CHECK_SIZEOF(ptrdiff_t)
|
||||
|
||||
Checks for compiler characteristics
|
||||
AC_C_CONST
|
||||
|
||||
Checks for library functions
|
||||
AC_CHECK_FUNCS(memcmp memcpy memmove memset)
|
||||
|
||||
|
||||
Appendix D: Copyright
|
||||
---------------------
|
||||
LZO and miniLZO are Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
2003, 2004, 2005, 2006, 2007, 2008 Markus Franz Xaver Johannes Oberhumer
|
||||
|
||||
LZO and miniLZO are distributed under the terms of the GNU General
|
||||
Public License (GPL). See the file COPYING.
|
||||
|
||||
Special licenses for commercial and other applications which
|
||||
are not willing to accept the GNU General Public License
|
||||
are available by contacting the author.
|
||||
|
||||
|
||||
Vendored
+417
@@ -0,0 +1,417 @@
|
||||
/* lzoconf.h -- configuration for the LZO real-time data compression library
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __LZOCONF_H_INCLUDED
|
||||
#define __LZOCONF_H_INCLUDED
|
||||
|
||||
#define LZO_VERSION 0x2030
|
||||
#define LZO_VERSION_STRING "2.03"
|
||||
#define LZO_VERSION_DATE "Apr 30 2008"
|
||||
|
||||
/* internal Autoconf configuration file - only used when building LZO */
|
||||
#if defined(LZO_HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// LZO requires a conforming <limits.h>
|
||||
************************************************************************/
|
||||
|
||||
#if !defined(CHAR_BIT) || (CHAR_BIT != 8)
|
||||
# error "invalid CHAR_BIT"
|
||||
#endif
|
||||
#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX)
|
||||
# error "check your compiler installation"
|
||||
#endif
|
||||
#if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1)
|
||||
# error "your limits.h macros are broken"
|
||||
#endif
|
||||
|
||||
/* get OS and architecture defines */
|
||||
#ifndef __LZODEFS_H_INCLUDED
|
||||
#include "lzodefs.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// some core defines
|
||||
************************************************************************/
|
||||
|
||||
#if !defined(LZO_UINT32_C)
|
||||
# if (UINT_MAX < LZO_0xffffffffL)
|
||||
# define LZO_UINT32_C(c) c ## UL
|
||||
# else
|
||||
# define LZO_UINT32_C(c) ((c) + 0U)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* memory checkers */
|
||||
#if !defined(__LZO_CHECKER)
|
||||
# if defined(__BOUNDS_CHECKING_ON)
|
||||
# define __LZO_CHECKER 1
|
||||
# elif defined(__CHECKER__)
|
||||
# define __LZO_CHECKER 1
|
||||
# elif defined(__INSURE__)
|
||||
# define __LZO_CHECKER 1
|
||||
# elif defined(__PURIFY__)
|
||||
# define __LZO_CHECKER 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// integral and pointer types
|
||||
************************************************************************/
|
||||
|
||||
/* lzo_uint should match size_t */
|
||||
#if !defined(LZO_UINT_MAX)
|
||||
# if defined(LZO_ABI_LLP64) /* WIN64 */
|
||||
# if defined(LZO_OS_WIN64)
|
||||
typedef unsigned __int64 lzo_uint;
|
||||
typedef __int64 lzo_int;
|
||||
# else
|
||||
typedef unsigned long long lzo_uint;
|
||||
typedef long long lzo_int;
|
||||
# endif
|
||||
# define LZO_UINT_MAX 0xffffffffffffffffull
|
||||
# define LZO_INT_MAX 9223372036854775807LL
|
||||
# define LZO_INT_MIN (-1LL - LZO_INT_MAX)
|
||||
# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */
|
||||
typedef unsigned int lzo_uint;
|
||||
typedef int lzo_int;
|
||||
# define LZO_UINT_MAX UINT_MAX
|
||||
# define LZO_INT_MAX INT_MAX
|
||||
# define LZO_INT_MIN INT_MIN
|
||||
# elif (ULONG_MAX >= LZO_0xffffffffL)
|
||||
typedef unsigned long lzo_uint;
|
||||
typedef long lzo_int;
|
||||
# define LZO_UINT_MAX ULONG_MAX
|
||||
# define LZO_INT_MAX LONG_MAX
|
||||
# define LZO_INT_MIN LONG_MIN
|
||||
# else
|
||||
# error "lzo_uint"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Integral types with 32 bits or more. */
|
||||
#if !defined(LZO_UINT32_MAX)
|
||||
# if (UINT_MAX >= LZO_0xffffffffL)
|
||||
typedef unsigned int lzo_uint32;
|
||||
typedef int lzo_int32;
|
||||
# define LZO_UINT32_MAX UINT_MAX
|
||||
# define LZO_INT32_MAX INT_MAX
|
||||
# define LZO_INT32_MIN INT_MIN
|
||||
# elif (ULONG_MAX >= LZO_0xffffffffL)
|
||||
typedef unsigned long lzo_uint32;
|
||||
typedef long lzo_int32;
|
||||
# define LZO_UINT32_MAX ULONG_MAX
|
||||
# define LZO_INT32_MAX LONG_MAX
|
||||
# define LZO_INT32_MIN LONG_MIN
|
||||
# else
|
||||
# error "lzo_uint32"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The larger type of lzo_uint and lzo_uint32. */
|
||||
#if (LZO_UINT_MAX >= LZO_UINT32_MAX)
|
||||
# define lzo_xint lzo_uint
|
||||
#else
|
||||
# define lzo_xint lzo_uint32
|
||||
#endif
|
||||
|
||||
/* Memory model that allows to access memory at offsets of lzo_uint. */
|
||||
#if !defined(__LZO_MMODEL)
|
||||
# if (LZO_UINT_MAX <= UINT_MAX)
|
||||
# define __LZO_MMODEL
|
||||
# elif defined(LZO_HAVE_MM_HUGE_PTR)
|
||||
# define __LZO_MMODEL_HUGE 1
|
||||
# define __LZO_MMODEL __huge
|
||||
# else
|
||||
# define __LZO_MMODEL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* no typedef here because of const-pointer issues */
|
||||
#define lzo_bytep unsigned char __LZO_MMODEL *
|
||||
#define lzo_charp char __LZO_MMODEL *
|
||||
#define lzo_voidp void __LZO_MMODEL *
|
||||
#define lzo_shortp short __LZO_MMODEL *
|
||||
#define lzo_ushortp unsigned short __LZO_MMODEL *
|
||||
#define lzo_uint32p lzo_uint32 __LZO_MMODEL *
|
||||
#define lzo_int32p lzo_int32 __LZO_MMODEL *
|
||||
#define lzo_uintp lzo_uint __LZO_MMODEL *
|
||||
#define lzo_intp lzo_int __LZO_MMODEL *
|
||||
#define lzo_xintp lzo_xint __LZO_MMODEL *
|
||||
#define lzo_voidpp lzo_voidp __LZO_MMODEL *
|
||||
#define lzo_bytepp lzo_bytep __LZO_MMODEL *
|
||||
/* deprecated - use `lzo_bytep' instead of `lzo_byte *' */
|
||||
#define lzo_byte unsigned char __LZO_MMODEL
|
||||
|
||||
typedef int lzo_bool;
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// function types
|
||||
************************************************************************/
|
||||
|
||||
/* name mangling */
|
||||
#if !defined(__LZO_EXTERN_C)
|
||||
# ifdef __cplusplus
|
||||
# define __LZO_EXTERN_C extern "C"
|
||||
# else
|
||||
# define __LZO_EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* calling convention */
|
||||
#if !defined(__LZO_CDECL)
|
||||
# define __LZO_CDECL __lzo_cdecl
|
||||
#endif
|
||||
|
||||
/* DLL export information */
|
||||
#if !defined(__LZO_EXPORT1)
|
||||
# define __LZO_EXPORT1
|
||||
#endif
|
||||
#if !defined(__LZO_EXPORT2)
|
||||
# define __LZO_EXPORT2
|
||||
#endif
|
||||
|
||||
/* __cdecl calling convention for public C and assembly functions */
|
||||
#if !defined(LZO_PUBLIC)
|
||||
# define LZO_PUBLIC(_rettype) __LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_CDECL
|
||||
#endif
|
||||
#if !defined(LZO_EXTERN)
|
||||
# define LZO_EXTERN(_rettype) __LZO_EXTERN_C LZO_PUBLIC(_rettype)
|
||||
#endif
|
||||
#if !defined(LZO_PRIVATE)
|
||||
# define LZO_PRIVATE(_rettype) static _rettype __LZO_CDECL
|
||||
#endif
|
||||
|
||||
/* function types */
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_compress_t) ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem );
|
||||
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_decompress_t) ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem );
|
||||
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_optimize_t) ( lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem );
|
||||
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_compress_dict_t)(const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem,
|
||||
const lzo_bytep dict, lzo_uint dict_len );
|
||||
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_decompress_dict_t)(const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem,
|
||||
const lzo_bytep dict, lzo_uint dict_len );
|
||||
|
||||
|
||||
/* Callback interface. Currently only the progress indicator ("nprogress")
|
||||
* is used, but this may change in a future release. */
|
||||
|
||||
struct lzo_callback_t;
|
||||
typedef struct lzo_callback_t lzo_callback_t;
|
||||
#define lzo_callback_p lzo_callback_t __LZO_MMODEL *
|
||||
|
||||
/* malloc & free function types */
|
||||
typedef lzo_voidp (__LZO_CDECL *lzo_alloc_func_t)
|
||||
(lzo_callback_p self, lzo_uint items, lzo_uint size);
|
||||
typedef void (__LZO_CDECL *lzo_free_func_t)
|
||||
(lzo_callback_p self, lzo_voidp ptr);
|
||||
|
||||
/* a progress indicator callback function */
|
||||
typedef void (__LZO_CDECL *lzo_progress_func_t)
|
||||
(lzo_callback_p, lzo_uint, lzo_uint, int);
|
||||
|
||||
struct lzo_callback_t
|
||||
{
|
||||
/* custom allocators (set to 0 to disable) */
|
||||
lzo_alloc_func_t nalloc; /* [not used right now] */
|
||||
lzo_free_func_t nfree; /* [not used right now] */
|
||||
|
||||
/* a progress indicator callback function (set to 0 to disable) */
|
||||
lzo_progress_func_t nprogress;
|
||||
|
||||
/* NOTE: the first parameter "self" of the nalloc/nfree/nprogress
|
||||
* callbacks points back to this struct, so you are free to store
|
||||
* some extra info in the following variables. */
|
||||
lzo_voidp user1;
|
||||
lzo_xint user2;
|
||||
lzo_xint user3;
|
||||
};
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// error codes and prototypes
|
||||
************************************************************************/
|
||||
|
||||
/* Error codes for the compression/decompression functions. Negative
|
||||
* values are errors, positive values will be used for special but
|
||||
* normal events.
|
||||
*/
|
||||
#define LZO_E_OK 0
|
||||
#define LZO_E_ERROR (-1)
|
||||
#define LZO_E_OUT_OF_MEMORY (-2) /* [not used right now] */
|
||||
#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */
|
||||
#define LZO_E_INPUT_OVERRUN (-4)
|
||||
#define LZO_E_OUTPUT_OVERRUN (-5)
|
||||
#define LZO_E_LOOKBEHIND_OVERRUN (-6)
|
||||
#define LZO_E_EOF_NOT_FOUND (-7)
|
||||
#define LZO_E_INPUT_NOT_CONSUMED (-8)
|
||||
#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */
|
||||
|
||||
|
||||
#ifndef lzo_sizeof_dict_t
|
||||
# define lzo_sizeof_dict_t ((unsigned)sizeof(lzo_bytep))
|
||||
#endif
|
||||
|
||||
/* lzo_init() should be the first function you call.
|
||||
* Check the return code !
|
||||
*
|
||||
* lzo_init() is a macro to allow checking that the library and the
|
||||
* compiler's view of various types are consistent.
|
||||
*/
|
||||
#define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\
|
||||
(int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\
|
||||
(int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\
|
||||
(int)sizeof(lzo_callback_t))
|
||||
LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int);
|
||||
|
||||
/* version functions (useful for shared libraries) */
|
||||
LZO_EXTERN(unsigned) lzo_version(void);
|
||||
LZO_EXTERN(const char *) lzo_version_string(void);
|
||||
LZO_EXTERN(const char *) lzo_version_date(void);
|
||||
LZO_EXTERN(const lzo_charp) _lzo_version_string(void);
|
||||
LZO_EXTERN(const lzo_charp) _lzo_version_date(void);
|
||||
|
||||
/* string functions */
|
||||
LZO_EXTERN(int)
|
||||
lzo_memcmp(const lzo_voidp _s1, const lzo_voidp _s2, lzo_uint _len);
|
||||
LZO_EXTERN(lzo_voidp)
|
||||
lzo_memcpy(lzo_voidp _dest, const lzo_voidp _src, lzo_uint _len);
|
||||
LZO_EXTERN(lzo_voidp)
|
||||
lzo_memmove(lzo_voidp _dest, const lzo_voidp _src, lzo_uint _len);
|
||||
LZO_EXTERN(lzo_voidp)
|
||||
lzo_memset(lzo_voidp _s, int _c, lzo_uint _len);
|
||||
|
||||
/* checksum functions */
|
||||
LZO_EXTERN(lzo_uint32)
|
||||
lzo_adler32(lzo_uint32 _adler, const lzo_bytep _buf, lzo_uint _len);
|
||||
LZO_EXTERN(lzo_uint32)
|
||||
lzo_crc32(lzo_uint32 _c, const lzo_bytep _buf, lzo_uint _len);
|
||||
LZO_EXTERN(const lzo_uint32p)
|
||||
lzo_get_crc32_table(void);
|
||||
|
||||
/* misc. */
|
||||
LZO_EXTERN(int) _lzo_config_check(void);
|
||||
typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u;
|
||||
typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u;
|
||||
typedef union { void *vp; lzo_bytep bp; lzo_uint32 u32; long l; } lzo_align_t;
|
||||
|
||||
/* align a char pointer on a boundary that is a multiple of `size' */
|
||||
LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp _ptr, lzo_uint _size);
|
||||
#define LZO_PTR_ALIGN_UP(_ptr,_size) \
|
||||
((_ptr) + (lzo_uint) __lzo_align_gap((const lzo_voidp)(_ptr),(lzo_uint)(_size)))
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// deprecated macros - only for backward compatibility with LZO v1.xx
|
||||
************************************************************************/
|
||||
|
||||
#if defined(LZO_CFG_COMPAT)
|
||||
|
||||
#define __LZOCONF_H 1
|
||||
|
||||
#if defined(LZO_ARCH_I086)
|
||||
# define __LZO_i386 1
|
||||
#elif defined(LZO_ARCH_I386)
|
||||
# define __LZO_i386 1
|
||||
#endif
|
||||
|
||||
#if defined(LZO_OS_DOS16)
|
||||
# define __LZO_DOS 1
|
||||
# define __LZO_DOS16 1
|
||||
#elif defined(LZO_OS_DOS32)
|
||||
# define __LZO_DOS 1
|
||||
#elif defined(LZO_OS_WIN16)
|
||||
# define __LZO_WIN 1
|
||||
# define __LZO_WIN16 1
|
||||
#elif defined(LZO_OS_WIN32)
|
||||
# define __LZO_WIN 1
|
||||
#endif
|
||||
|
||||
#define __LZO_CMODEL
|
||||
#define __LZO_DMODEL
|
||||
#define __LZO_ENTRY __LZO_CDECL
|
||||
#define LZO_EXTERN_CDECL LZO_EXTERN
|
||||
#define LZO_ALIGN LZO_PTR_ALIGN_UP
|
||||
|
||||
#define lzo_compress_asm_t lzo_compress_t
|
||||
#define lzo_decompress_asm_t lzo_decompress_t
|
||||
|
||||
#endif /* LZO_CFG_COMPAT */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/* vim:set ts=4 et: */
|
||||
Vendored
+1807
File diff suppressed because it is too large
Load Diff
Vendored
+4112
File diff suppressed because it is too large
Load Diff
Vendored
+112
@@ -0,0 +1,112 @@
|
||||
/* minilzo.h -- mini subset of the LZO real-time data compression library
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
*/
|
||||
|
||||
/*
|
||||
* NOTE:
|
||||
* the full LZO package can be found at
|
||||
* http://www.oberhumer.com/opensource/lzo/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MINILZO_H
|
||||
#define __MINILZO_H
|
||||
|
||||
#define MINILZO_VERSION 0x2030
|
||||
|
||||
#ifdef __LZOCONF_H
|
||||
# error "you cannot use both LZO and miniLZO"
|
||||
#endif
|
||||
|
||||
#undef LZO_HAVE_CONFIG_H
|
||||
#include "lzoconf.h"
|
||||
|
||||
#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION)
|
||||
# error "version mismatch in header files"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
|
||||
/* Memory required for the wrkmem parameter.
|
||||
* When the required size is 0, you can also pass a NULL pointer.
|
||||
*/
|
||||
|
||||
#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
|
||||
#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t))
|
||||
#define LZO1X_MEM_DECOMPRESS (0)
|
||||
|
||||
|
||||
/* compression */
|
||||
LZO_EXTERN(int)
|
||||
lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem );
|
||||
|
||||
/* decompression */
|
||||
LZO_EXTERN(int)
|
||||
lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem /* NOT USED */ );
|
||||
|
||||
/* safe decompression with overrun testing */
|
||||
LZO_EXTERN(int)
|
||||
lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem /* NOT USED */ );
|
||||
|
||||
|
||||
#define LZO_OUT_LEN(size) ((size) + (size) / 16 + 64 + 3)
|
||||
|
||||
#define LZO_HEAP_ALLOC(var,size) \
|
||||
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ]
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
Vendored
+11
-4
@@ -20,7 +20,7 @@
|
||||
* The Original Code is Copyright (C) 2009 by Daniel Genrich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): None
|
||||
* Contributor(s): Daniel Genrich
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
@@ -32,6 +32,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// export
|
||||
void smoke_export(struct FLUID_3D *fluid, float *dt, float *dx, float **dens, float **densold, float **heat, float **heatold, float **vx, float **vy, float **vz, float **vxold, float **vyold, float **vzold, unsigned char **obstacles);
|
||||
|
||||
// low res
|
||||
struct FLUID_3D *smoke_init(int *res, float *p0, float dt);
|
||||
void smoke_free(struct FLUID_3D *fluid);
|
||||
|
||||
@@ -57,11 +61,14 @@ void smoke_turbulence_free(struct WTURBULENCE *wt);
|
||||
void smoke_turbulence_step(struct WTURBULENCE *wt, struct FLUID_3D *fluid);
|
||||
|
||||
float *smoke_turbulence_get_density(struct WTURBULENCE *wt);
|
||||
void smoke_turbulence_get_res(struct WTURBULENCE *wt, int *res);
|
||||
void smoke_turbulence_get_res(struct WTURBULENCE *wt, unsigned int *res);
|
||||
void smoke_turbulence_set_noise(struct WTURBULENCE *wt, int type);
|
||||
void smoke_initWaveletBlenderRNA(struct WTURBULENCE *wt, float *strength);
|
||||
void smoke_turbulence_initBlenderRNA(struct WTURBULENCE *wt, float *strength);
|
||||
|
||||
void smoke_dissolve_wavelet(struct WTURBULENCE *wt, int speed, int log);
|
||||
void smoke_turbulence_dissolve(struct WTURBULENCE *wt, int speed, int log);
|
||||
|
||||
// export
|
||||
void smoke_turbulence_export(struct WTURBULENCE *wt, float **dens, float **densold, float **tcu, float **tcv, float **tcw);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -75,8 +75,6 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) :
|
||||
// allocate arrays
|
||||
_totalCells = _xRes * _yRes * _zRes;
|
||||
_slabSize = _xRes * _yRes;
|
||||
_divergence = new float[_totalCells];
|
||||
_pressure = new float[_totalCells];
|
||||
_xVelocity = new float[_totalCells];
|
||||
_yVelocity = new float[_totalCells];
|
||||
_zVelocity = new float[_totalCells];
|
||||
@@ -86,20 +84,11 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) :
|
||||
_xForce = new float[_totalCells];
|
||||
_yForce = new float[_totalCells];
|
||||
_zForce = new float[_totalCells];
|
||||
_vorticity = new float[_totalCells];
|
||||
_density = new float[_totalCells];
|
||||
_densityOld = new float[_totalCells];
|
||||
_heat = new float[_totalCells];
|
||||
_heatOld = new float[_totalCells];
|
||||
_residual = new float[_totalCells];
|
||||
_direction = new float[_totalCells];
|
||||
_q = new float[_totalCells];
|
||||
_obstacles = new unsigned char[_totalCells];
|
||||
_xVorticity = new float[_totalCells];
|
||||
_yVorticity = new float[_totalCells];
|
||||
_zVorticity = new float[_totalCells];
|
||||
_h = new float[_totalCells];
|
||||
_Precond = new float[_totalCells];
|
||||
_obstacles = new unsigned char[_totalCells]; // set 0 at end of step
|
||||
|
||||
// DG TODO: check if alloc went fine
|
||||
|
||||
@@ -109,8 +98,6 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) :
|
||||
_densityOld[x] = 0.0f;
|
||||
_heat[x] = 0.0f;
|
||||
_heatOld[x] = 0.0f;
|
||||
_divergence[x] = 0.0f;
|
||||
_pressure[x] = 0.0f;
|
||||
_xVelocity[x] = 0.0f;
|
||||
_yVelocity[x] = 0.0f;
|
||||
_zVelocity[x] = 0.0f;
|
||||
@@ -120,19 +107,11 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) :
|
||||
_xForce[x] = 0.0f;
|
||||
_yForce[x] = 0.0f;
|
||||
_zForce[x] = 0.0f;
|
||||
_xVorticity[x] = 0.0f;
|
||||
_yVorticity[x] = 0.0f;
|
||||
_zVorticity[x] = 0.0f;
|
||||
_residual[x] = 0.0f;
|
||||
_q[x] = 0.0f;
|
||||
_direction[x] = 0.0f;
|
||||
_h[x] = 0.0f;
|
||||
_Precond[x] = 0.0f;
|
||||
_obstacles[x] = false;
|
||||
}
|
||||
|
||||
// set side obstacles
|
||||
int index;
|
||||
size_t index;
|
||||
for (int y = 0; y < _yRes; y++) // z
|
||||
for (int x = 0; x < _xRes; x++)
|
||||
{
|
||||
@@ -177,8 +156,6 @@ FLUID_3D::FLUID_3D(int *res, float *p0, float dt) :
|
||||
|
||||
FLUID_3D::~FLUID_3D()
|
||||
{
|
||||
if (_divergence) delete[] _divergence;
|
||||
if (_pressure) delete[] _pressure;
|
||||
if (_xVelocity) delete[] _xVelocity;
|
||||
if (_yVelocity) delete[] _yVelocity;
|
||||
if (_zVelocity) delete[] _zVelocity;
|
||||
@@ -188,23 +165,14 @@ FLUID_3D::~FLUID_3D()
|
||||
if (_xForce) delete[] _xForce;
|
||||
if (_yForce) delete[] _yForce;
|
||||
if (_zForce) delete[] _zForce;
|
||||
if (_residual) delete[] _residual;
|
||||
if (_direction) delete[] _direction;
|
||||
if (_q) delete[] _q;
|
||||
if (_density) delete[] _density;
|
||||
if (_densityOld) delete[] _densityOld;
|
||||
if (_heat) delete[] _heat;
|
||||
if (_heatOld) delete[] _heatOld;
|
||||
if (_xVorticity) delete[] _xVorticity;
|
||||
if (_yVorticity) delete[] _yVorticity;
|
||||
if (_zVorticity) delete[] _zVorticity;
|
||||
if (_vorticity) delete[] _vorticity;
|
||||
if (_h) delete[] _h;
|
||||
if (_Precond) delete[] _Precond;
|
||||
if (_obstacles) delete[] _obstacles;
|
||||
// if (_wTurbulence) delete _wTurbulence;
|
||||
|
||||
printf("deleted fluid\n");
|
||||
// printf("deleted fluid\n");
|
||||
}
|
||||
|
||||
// init direct access functions from blender
|
||||
@@ -263,6 +231,8 @@ void FLUID_3D::step()
|
||||
*/
|
||||
_totalTime += _dt;
|
||||
_totalSteps++;
|
||||
|
||||
memset(_obstacles, 0, sizeof(unsigned char)*_xRes*_yRes*_zRes);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -300,7 +270,7 @@ void FLUID_3D::artificialDamping(float* field) {
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void FLUID_3D::copyBorderAll(float* field)
|
||||
{
|
||||
int index;
|
||||
size_t index;
|
||||
for (int y = 0; y < _yRes; y++)
|
||||
for (int x = 0; x < _xRes; x++)
|
||||
{
|
||||
@@ -367,9 +337,16 @@ void FLUID_3D::addForce()
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void FLUID_3D::project()
|
||||
{
|
||||
int index, x, y, z;
|
||||
int x, y, z;
|
||||
size_t index;
|
||||
|
||||
setObstacleBoundaries();
|
||||
float *_pressure = new float[_totalCells];
|
||||
float *_divergence = new float[_totalCells];
|
||||
|
||||
memset(_pressure, 0, sizeof(float)*_totalCells);
|
||||
memset(_divergence, 0, sizeof(float)*_totalCells);
|
||||
|
||||
setObstacleBoundaries(_pressure);
|
||||
|
||||
// copy out the boundaries
|
||||
if(DOMAIN_BC_LEFT == 0) setNeumannX(_xVelocity, _res);
|
||||
@@ -414,7 +391,7 @@ void FLUID_3D::project()
|
||||
// solve Poisson equation
|
||||
solvePressurePre(_pressure, _divergence, _obstacles);
|
||||
|
||||
setObstaclePressure();
|
||||
setObstaclePressure(_pressure);
|
||||
|
||||
// project out solution
|
||||
float invDx = 1.0f / _dx;
|
||||
@@ -430,6 +407,9 @@ void FLUID_3D::project()
|
||||
_zVelocity[index] -= 0.5f * (_pressure[index + _slabSize] - _pressure[index - _slabSize]) * invDx;
|
||||
}
|
||||
}
|
||||
|
||||
if (_pressure) delete[] _pressure;
|
||||
if (_divergence) delete[] _divergence;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -465,7 +445,7 @@ void FLUID_3D::addObstacle(OBSTACLE* obstacle)
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// calculate the obstacle directional types
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void FLUID_3D::setObstaclePressure()
|
||||
void FLUID_3D::setObstaclePressure(float *_pressure)
|
||||
{
|
||||
// tag remaining obstacle blocks
|
||||
for (int z = 1, index = _slabSize + _xRes + 1;
|
||||
@@ -539,7 +519,7 @@ void FLUID_3D::setObstaclePressure()
|
||||
}
|
||||
}
|
||||
|
||||
void FLUID_3D::setObstacleBoundaries()
|
||||
void FLUID_3D::setObstacleBoundaries(float *_pressure)
|
||||
{
|
||||
// cull degenerate obstacles , move to addObstacle?
|
||||
for (int z = 1, index = _slabSize + _xRes + 1;
|
||||
@@ -600,6 +580,18 @@ void FLUID_3D::addVorticity()
|
||||
int x,y,z,index;
|
||||
if(_vorticityEps<=0.) return;
|
||||
|
||||
float *_xVorticity, *_yVorticity, *_zVorticity, *_vorticity;
|
||||
|
||||
_xVorticity = new float[_totalCells];
|
||||
_yVorticity = new float[_totalCells];
|
||||
_zVorticity = new float[_totalCells];
|
||||
_vorticity = new float[_totalCells];
|
||||
|
||||
memset(_xVorticity, 0, sizeof(float)*_totalCells);
|
||||
memset(_yVorticity, 0, sizeof(float)*_totalCells);
|
||||
memset(_zVorticity, 0, sizeof(float)*_totalCells);
|
||||
memset(_vorticity, 0, sizeof(float)*_totalCells);
|
||||
|
||||
// calculate vorticity
|
||||
float gridSize = 0.5f / _dx;
|
||||
index = _slabSize + _xRes + 1;
|
||||
@@ -662,6 +654,11 @@ void FLUID_3D::addVorticity()
|
||||
_zForce[index] += (N[0] * _yVorticity[index] - N[1] * _xVorticity[index]) * _dx * eps;
|
||||
}
|
||||
}
|
||||
|
||||
if (_xVorticity) delete[] _xVorticity;
|
||||
if (_yVorticity) delete[] _yVorticity;
|
||||
if (_zVorticity) delete[] _zVorticity;
|
||||
if (_vorticity) delete[] _vorticity;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -64,7 +64,7 @@ class FLUID_3D
|
||||
// dimensions
|
||||
int _xRes, _yRes, _zRes, _maxRes;
|
||||
Vec3Int _res;
|
||||
int _totalCells;
|
||||
size_t _totalCells;
|
||||
int _slabSize;
|
||||
float _dx;
|
||||
float _p0[3];
|
||||
@@ -81,7 +81,6 @@ class FLUID_3D
|
||||
float* _densityOld;
|
||||
float* _heat;
|
||||
float* _heatOld;
|
||||
float* _pressure;
|
||||
float* _xVelocity;
|
||||
float* _yVelocity;
|
||||
float* _zVelocity;
|
||||
@@ -91,19 +90,9 @@ class FLUID_3D
|
||||
float* _xForce;
|
||||
float* _yForce;
|
||||
float* _zForce;
|
||||
float* _divergence;
|
||||
float* _xVorticity;
|
||||
float* _yVorticity;
|
||||
float* _zVorticity;
|
||||
float* _vorticity;
|
||||
float* _h;
|
||||
float* _Precond;
|
||||
unsigned char* _obstacles;
|
||||
|
||||
// CG fields
|
||||
float* _residual;
|
||||
float* _direction;
|
||||
float* _q;
|
||||
int _iterations;
|
||||
|
||||
// simulation constants
|
||||
@@ -134,8 +123,8 @@ class FLUID_3D
|
||||
void solveHeat(float* field, float* b, unsigned char* skip);
|
||||
|
||||
// handle obstacle boundaries
|
||||
void setObstacleBoundaries();
|
||||
void setObstaclePressure();
|
||||
void setObstacleBoundaries(float *_pressure);
|
||||
void setObstaclePressure(float *_pressure);
|
||||
|
||||
public:
|
||||
// advection, accessed e.g. by WTURBULENCE class
|
||||
|
||||
@@ -28,10 +28,17 @@ void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip)
|
||||
{
|
||||
int x, y, z;
|
||||
size_t index;
|
||||
float *_q, *_Precond, *_h, *_residual, *_direction;
|
||||
|
||||
// i = 0
|
||||
int i = 0;
|
||||
|
||||
_residual = new float[_totalCells]; // set 0
|
||||
_direction = new float[_totalCells]; // set 0
|
||||
_q = new float[_totalCells]; // set 0
|
||||
_h = new float[_totalCells]; // set 0
|
||||
_Precond = new float[_totalCells]; // set 0
|
||||
|
||||
memset(_residual, 0, sizeof(float)*_xRes*_yRes*_zRes);
|
||||
memset(_q, 0, sizeof(float)*_xRes*_yRes*_zRes);
|
||||
memset(_direction, 0, sizeof(float)*_xRes*_yRes*_zRes);
|
||||
@@ -191,11 +198,18 @@ void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip)
|
||||
i++;
|
||||
}
|
||||
// cout << i << " iterations converged to " << sqrt(maxR) << endl;
|
||||
|
||||
if (_h) delete[] _h;
|
||||
if (_Precond) delete[] _Precond;
|
||||
if (_residual) delete[] _residual;
|
||||
if (_direction) delete[] _direction;
|
||||
if (_q) delete[] _q;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// solve the poisson equation with CG
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#if 0
|
||||
void FLUID_3D::solvePressure(float* field, float* b, unsigned char* skip)
|
||||
{
|
||||
int x, y, z;
|
||||
@@ -344,6 +358,7 @@ void FLUID_3D::solvePressure(float* field, float* b, unsigned char* skip)
|
||||
}
|
||||
// cout << i << " iterations converged to " << maxR << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// solve the heat equation with CG
|
||||
@@ -353,10 +368,15 @@ void FLUID_3D::solveHeat(float* field, float* b, unsigned char* skip)
|
||||
int x, y, z;
|
||||
size_t index;
|
||||
const float heatConst = _dt * _heatDiffusion / (_dx * _dx);
|
||||
float *_q, *_residual, *_direction;
|
||||
|
||||
// i = 0
|
||||
int i = 0;
|
||||
|
||||
_residual = new float[_totalCells]; // set 0
|
||||
_direction = new float[_totalCells]; // set 0
|
||||
_q = new float[_totalCells]; // set 0
|
||||
|
||||
memset(_residual, 0, sizeof(float)*_xRes*_yRes*_zRes);
|
||||
memset(_q, 0, sizeof(float)*_xRes*_yRes*_zRes);
|
||||
memset(_direction, 0, sizeof(float)*_xRes*_yRes*_zRes);
|
||||
@@ -496,5 +516,9 @@ void FLUID_3D::solveHeat(float* field, float* b, unsigned char* skip)
|
||||
i++;
|
||||
}
|
||||
// cout << i << " iterations converged to " << maxR << endl;
|
||||
|
||||
if (_residual) delete[] _residual;
|
||||
if (_direction) delete[] _direction;
|
||||
if (_q) delete[] _q;
|
||||
}
|
||||
|
||||
|
||||
+259
-222
@@ -81,25 +81,9 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no
|
||||
_densityBig = new float[_totalCellsBig];
|
||||
_densityBigOld = new float[_totalCellsBig];
|
||||
|
||||
// allocate high resolution velocity field. Note that this is only
|
||||
// necessary because we use MacCormack advection. For semi-Lagrangian
|
||||
// advection, these arrays are not necessary.
|
||||
_tempBig1 = _tempBig2 =
|
||||
_bigUx = _bigUy = _bigUz = NULL;
|
||||
_tempBig1 = new float[_totalCellsBig];
|
||||
_tempBig2 = new float[_totalCellsBig];
|
||||
_bigUx = new float[_totalCellsBig];
|
||||
_bigUy = new float[_totalCellsBig];
|
||||
_bigUz = new float[_totalCellsBig];
|
||||
|
||||
for(int i = 0; i < _totalCellsBig; i++) {
|
||||
_densityBig[i] =
|
||||
_densityBigOld[i] =
|
||||
_bigUx[i] =
|
||||
_bigUy[i] =
|
||||
_bigUz[i] =
|
||||
_tempBig1[i] =
|
||||
_tempBig2[i] = 0.;
|
||||
_densityBigOld[i] = 0.;
|
||||
}
|
||||
|
||||
// allocate & init texture coordinates
|
||||
@@ -154,12 +138,6 @@ WTURBULENCE::~WTURBULENCE() {
|
||||
delete[] _densityBig;
|
||||
delete[] _densityBigOld;
|
||||
|
||||
delete[] _bigUx;
|
||||
delete[] _bigUy;
|
||||
delete[] _bigUz;
|
||||
delete[] _tempBig1;
|
||||
delete[] _tempBig2;
|
||||
|
||||
delete[] _tcU;
|
||||
delete[] _tcV;
|
||||
delete[] _tcW;
|
||||
@@ -315,7 +293,7 @@ static float minDz(int x, int y, int z, float* input, Vec3Int res)
|
||||
// handle texture coordinates (advection, reset, eigenvalues),
|
||||
// Beware -- uses big density maccormack as temporary arrays
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void WTURBULENCE::advectTextureCoordinates (float dtOrg, float* xvel, float* yvel, float* zvel) {
|
||||
void WTURBULENCE::advectTextureCoordinates (float dtOrg, float* xvel, float* yvel, float* zvel, float *_tempBig1, float *_tempBig2) {
|
||||
// advection
|
||||
SWAP_POINTERS(_tcTemp, _tcU);
|
||||
FLUID_3D::copyBorderX(_tcTemp, _resSm);
|
||||
@@ -602,12 +580,32 @@ Vec3 WTURBULENCE::WVelocityWithJacobian(Vec3 orgPos, float* xUnwarped, float* yU
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void WTURBULENCE::stepTurbulenceReadable(float dtOrg, float* xvel, float* yvel, float* zvel, unsigned char *obstacles)
|
||||
{
|
||||
// big velocity macCormack fields
|
||||
float* _bigUx;
|
||||
float* _bigUy;
|
||||
float* _bigUz;
|
||||
|
||||
// temp arrays for BFECC and MacCormack - they have more convenient
|
||||
// names in the actual implementations
|
||||
float* _tempBig1;
|
||||
float* _tempBig2;
|
||||
|
||||
// allocate high resolution velocity field. Note that this is only
|
||||
// necessary because we use MacCormack advection. For semi-Lagrangian
|
||||
// advection, these arrays are not necessary.
|
||||
_tempBig1 = new float[_totalCellsBig];
|
||||
_tempBig2 = new float[_totalCellsBig];
|
||||
|
||||
// enlarge timestep to match grid
|
||||
const float dt = dtOrg * _amplify;
|
||||
const float invAmp = 1.0f / _amplify;
|
||||
|
||||
_bigUx = new float[_totalCellsBig];
|
||||
_bigUy = new float[_totalCellsBig];
|
||||
_bigUz = new float[_totalCellsBig];
|
||||
|
||||
// prepare textures
|
||||
advectTextureCoordinates(dtOrg, xvel,yvel,zvel);
|
||||
advectTextureCoordinates(dtOrg, xvel,yvel,zvel, _tempBig1, _tempBig2);
|
||||
|
||||
// compute eigenvalues of the texture coordinates
|
||||
computeEigenvalues();
|
||||
@@ -744,6 +742,13 @@ void WTURBULENCE::stepTurbulenceReadable(float dtOrg, float* xvel, float* yvel,
|
||||
IMAGE::dumpPBRT(_totalStepsBig, pbrtPrefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]);
|
||||
*/
|
||||
_totalStepsBig++;
|
||||
|
||||
delete[] _bigUx;
|
||||
delete[] _bigUy;
|
||||
delete[] _bigUz;
|
||||
|
||||
delete[] _tempBig1;
|
||||
delete[] _tempBig2;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -752,225 +757,257 @@ void WTURBULENCE::stepTurbulenceReadable(float dtOrg, float* xvel, float* yvel,
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void WTURBULENCE::stepTurbulenceFull(float dtOrg, float* xvel, float* yvel, float* zvel, unsigned char *obstacles)
|
||||
{
|
||||
// enlarge timestep to match grid
|
||||
const float dt = dtOrg * _amplify;
|
||||
const float invAmp = 1.0f / _amplify;
|
||||
// big velocity macCormack fields
|
||||
float* _bigUx;
|
||||
float* _bigUy;
|
||||
float* _bigUz;
|
||||
|
||||
// prepare textures
|
||||
advectTextureCoordinates(dtOrg, xvel,yvel,zvel);
|
||||
// temp arrays for BFECC and MacCormack - they have more convenient
|
||||
// names in the actual implementations
|
||||
float* _tempBig1;
|
||||
float* _tempBig2;
|
||||
|
||||
// do wavelet decomposition of energy
|
||||
computeEnergy(xvel, yvel, zvel, obstacles);
|
||||
decomposeEnergy();
|
||||
// allocate high resolution velocity field. Note that this is only
|
||||
// necessary because we use MacCormack advection. For semi-Lagrangian
|
||||
// advection, these arrays are not necessary.
|
||||
_tempBig1 = new float[_totalCellsBig];
|
||||
_tempBig2 = new float[_totalCellsBig];
|
||||
|
||||
// zero out coefficients inside of the obstacle
|
||||
for (int x = 0; x < _totalCellsSm; x++)
|
||||
if (obstacles[x]) _energy[x] = 0.f;
|
||||
// enlarge timestep to match grid
|
||||
const float dt = dtOrg * _amplify;
|
||||
const float invAmp = 1.0f / _amplify;
|
||||
|
||||
// parallel region setup
|
||||
float maxVelMagThreads[8] = { -1., -1., -1., -1., -1., -1., -1., -1. };
|
||||
#if PARALLEL==1
|
||||
#pragma omp parallel
|
||||
#endif
|
||||
{ float maxVelMag1 = 0.;
|
||||
#if PARALLEL==1
|
||||
const int id = omp_get_thread_num(); /*, num = omp_get_num_threads(); */
|
||||
#endif
|
||||
_bigUx = new float[_totalCellsBig];
|
||||
_bigUy = new float[_totalCellsBig];
|
||||
_bigUz = new float[_totalCellsBig];
|
||||
|
||||
// vector noise main loop
|
||||
#if PARALLEL==1
|
||||
#pragma omp for schedule(static)
|
||||
#endif
|
||||
for (int zSmall = 0; zSmall < _zResSm; zSmall++)
|
||||
for (int ySmall = 0; ySmall < _yResSm; ySmall++)
|
||||
for (int xSmall = 0; xSmall < _xResSm; xSmall++)
|
||||
{
|
||||
const int indexSmall = xSmall + ySmall * _xResSm + zSmall * _slabSizeSm;
|
||||
// prepare textures
|
||||
advectTextureCoordinates(dtOrg, xvel,yvel,zvel, _tempBig1, _tempBig2);
|
||||
|
||||
// compute jacobian
|
||||
float jacobian[3][3] = {
|
||||
{ minDx(xSmall, ySmall, zSmall, _tcU, _resSm), minDx(xSmall, ySmall, zSmall, _tcV, _resSm), minDx(xSmall, ySmall, zSmall, _tcW, _resSm) } ,
|
||||
{ minDy(xSmall, ySmall, zSmall, _tcU, _resSm), minDy(xSmall, ySmall, zSmall, _tcV, _resSm), minDy(xSmall, ySmall, zSmall, _tcW, _resSm) } ,
|
||||
{ minDz(xSmall, ySmall, zSmall, _tcU, _resSm), minDz(xSmall, ySmall, zSmall, _tcV, _resSm), minDz(xSmall, ySmall, zSmall, _tcW, _resSm) }
|
||||
};
|
||||
// do wavelet decomposition of energy
|
||||
computeEnergy(xvel, yvel, zvel, obstacles);
|
||||
decomposeEnergy();
|
||||
|
||||
// get LU factorization of texture jacobian and apply
|
||||
// it to unit vectors
|
||||
JAMA::LU<float> LU = computeLU3x3(jacobian);
|
||||
float xUnwarped[] = {1.0f, 0.0f, 0.0f};
|
||||
float yUnwarped[] = {0.0f, 1.0f, 0.0f};
|
||||
float zUnwarped[] = {0.0f, 0.0f, 1.0f};
|
||||
float xWarped[] = {1.0f, 0.0f, 0.0f};
|
||||
float yWarped[] = {0.0f, 1.0f, 0.0f};
|
||||
float zWarped[] = {0.0f, 0.0f, 1.0f};
|
||||
bool nonSingular = LU.isNonsingular();
|
||||
#if 0
|
||||
// UNUSED
|
||||
float eigMax = 10.0f;
|
||||
float eigMin = 0.1f;
|
||||
#endif
|
||||
if (nonSingular)
|
||||
{
|
||||
solveLU3x3(LU, xUnwarped, xWarped);
|
||||
solveLU3x3(LU, yUnwarped, yWarped);
|
||||
solveLU3x3(LU, zUnwarped, zWarped);
|
||||
// zero out coefficients inside of the obstacle
|
||||
for (int x = 0; x < _totalCellsSm; x++)
|
||||
if (obstacles[x]) _energy[x] = 0.f;
|
||||
|
||||
// compute the eigenvalues while we have the Jacobian available
|
||||
Vec3 eigenvalues = Vec3(1.);
|
||||
computeEigenvalues3x3( &eigenvalues[0], jacobian);
|
||||
_eigMax[indexSmall] = MAX3V(eigenvalues);
|
||||
_eigMin[indexSmall] = MIN3V(eigenvalues);
|
||||
}
|
||||
|
||||
// make sure to skip one on the beginning and end
|
||||
int xStart = (xSmall == 0) ? 1 : 0;
|
||||
int xEnd = (xSmall == _xResSm - 1) ? _amplify - 1 : _amplify;
|
||||
int yStart = (ySmall == 0) ? 1 : 0;
|
||||
int yEnd = (ySmall == _yResSm - 1) ? _amplify - 1 : _amplify;
|
||||
int zStart = (zSmall == 0) ? 1 : 0;
|
||||
int zEnd = (zSmall == _zResSm - 1) ? _amplify - 1 : _amplify;
|
||||
|
||||
for (int zBig = zStart; zBig < zEnd; zBig++)
|
||||
for (int yBig = yStart; yBig < yEnd; yBig++)
|
||||
for (int xBig = xStart; xBig < xEnd; xBig++)
|
||||
{
|
||||
const int x = xSmall * _amplify + xBig;
|
||||
const int y = ySmall * _amplify + yBig;
|
||||
const int z = zSmall * _amplify + zBig;
|
||||
|
||||
// get unit position for both fine and coarse grid
|
||||
const Vec3 pos = Vec3(x,y,z);
|
||||
const Vec3 posSm = pos * invAmp;
|
||||
|
||||
// get grid index for both fine and coarse grid
|
||||
const int index = x + y *_xResBig + z *_slabSizeBig;
|
||||
|
||||
// get a linearly interpolated velocity and texcoords
|
||||
// from the coarse grid
|
||||
Vec3 vel = INTERPOLATE::lerp3dVec( xvel,yvel,zvel,
|
||||
posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm);
|
||||
Vec3 uvw = INTERPOLATE::lerp3dVec( _tcU,_tcV,_tcW,
|
||||
posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm);
|
||||
// parallel region setup
|
||||
float maxVelMagThreads[8] = { -1., -1., -1., -1., -1., -1., -1., -1. };
|
||||
|
||||
// multiply the texture coordinate by _resSm so that turbulence
|
||||
// synthesis begins at the first octave that the coarse grid
|
||||
// cannot capture
|
||||
Vec3 texCoord = Vec3(uvw[0] * _resSm[0],
|
||||
uvw[1] * _resSm[1],
|
||||
uvw[2] * _resSm[2]);
|
||||
#if PARALLEL==1
|
||||
#pragma omp parallel
|
||||
#endif
|
||||
{ float maxVelMag1 = 0.;
|
||||
#if PARALLEL==1
|
||||
const int id = omp_get_thread_num(); /*, num = omp_get_num_threads(); */
|
||||
#endif
|
||||
|
||||
// retrieve wavelet energy at highest frequency
|
||||
float energy = INTERPOLATE::lerp3d(
|
||||
_highFreqEnergy, posSm[0],posSm[1],posSm[2], _xResSm, _yResSm, _zResSm);
|
||||
// vector noise main loop
|
||||
#if PARALLEL==1
|
||||
#pragma omp for schedule(static)
|
||||
#endif
|
||||
for (int zSmall = 0; zSmall < _zResSm; zSmall++)
|
||||
for (int ySmall = 0; ySmall < _yResSm; ySmall++)
|
||||
for (int xSmall = 0; xSmall < _xResSm; xSmall++)
|
||||
{
|
||||
const int indexSmall = xSmall + ySmall * _xResSm + zSmall * _slabSizeSm;
|
||||
|
||||
// base amplitude for octave 0
|
||||
float coefficient = sqrtf(2.0f * fabs(energy));
|
||||
const float amplitude = *_strength * fabs(0.5 * coefficient) * persistence;
|
||||
// compute jacobian
|
||||
float jacobian[3][3] = {
|
||||
{ minDx(xSmall, ySmall, zSmall, _tcU, _resSm), minDx(xSmall, ySmall, zSmall, _tcV, _resSm), minDx(xSmall, ySmall, zSmall, _tcW, _resSm) } ,
|
||||
{ minDy(xSmall, ySmall, zSmall, _tcU, _resSm), minDy(xSmall, ySmall, zSmall, _tcV, _resSm), minDy(xSmall, ySmall, zSmall, _tcW, _resSm) } ,
|
||||
{ minDz(xSmall, ySmall, zSmall, _tcU, _resSm), minDz(xSmall, ySmall, zSmall, _tcV, _resSm), minDz(xSmall, ySmall, zSmall, _tcW, _resSm) }
|
||||
};
|
||||
|
||||
// add noise to velocity, but only if the turbulence is
|
||||
// sufficiently undeformed, and the energy is large enough
|
||||
// to make a difference
|
||||
const bool addNoise = _eigMax[indexSmall] < 2. &&
|
||||
_eigMin[indexSmall] > 0.5;
|
||||
if (addNoise && amplitude > _cullingThreshold) {
|
||||
// base amplitude for octave 0
|
||||
float amplitudeScaled = amplitude;
|
||||
// get LU factorization of texture jacobian and apply
|
||||
// it to unit vectors
|
||||
JAMA::LU<float> LU = computeLU3x3(jacobian);
|
||||
float xUnwarped[] = {1.0f, 0.0f, 0.0f};
|
||||
float yUnwarped[] = {0.0f, 1.0f, 0.0f};
|
||||
float zUnwarped[] = {0.0f, 0.0f, 1.0f};
|
||||
float xWarped[] = {1.0f, 0.0f, 0.0f};
|
||||
float yWarped[] = {0.0f, 1.0f, 0.0f};
|
||||
float zWarped[] = {0.0f, 0.0f, 1.0f};
|
||||
bool nonSingular = LU.isNonsingular();
|
||||
|
||||
for (int octave = 0; octave < _octaves; octave++)
|
||||
{
|
||||
// multiply the vector noise times the maximum allowed
|
||||
// noise amplitude at this octave, and add it to the total
|
||||
vel += WVelocityWithJacobian(texCoord, &xUnwarped[0], &yUnwarped[0], &zUnwarped[0]) * amplitudeScaled;
|
||||
#if 0
|
||||
// UNUSED
|
||||
float eigMax = 10.0f;
|
||||
float eigMin = 0.1f;
|
||||
#endif
|
||||
|
||||
// scale coefficient for next octave
|
||||
amplitudeScaled *= persistence;
|
||||
texCoord *= 2.0f;
|
||||
}
|
||||
}
|
||||
if (nonSingular)
|
||||
{
|
||||
solveLU3x3(LU, xUnwarped, xWarped);
|
||||
solveLU3x3(LU, yUnwarped, yWarped);
|
||||
solveLU3x3(LU, zUnwarped, zWarped);
|
||||
|
||||
// Store velocity + turbulence in big grid for maccormack step
|
||||
//
|
||||
// If you wanted to save memory, you would instead perform a
|
||||
// semi-Lagrangian backtrace for the current grid cell here. Then
|
||||
// you could just throw the velocity away.
|
||||
_bigUx[index] = vel[0];
|
||||
_bigUy[index] = vel[1];
|
||||
_bigUz[index] = vel[2];
|
||||
// compute the eigenvalues while we have the Jacobian available
|
||||
Vec3 eigenvalues = Vec3(1.);
|
||||
computeEigenvalues3x3( &eigenvalues[0], jacobian);
|
||||
_eigMax[indexSmall] = MAX3V(eigenvalues);
|
||||
_eigMin[indexSmall] = MIN3V(eigenvalues);
|
||||
}
|
||||
|
||||
// compute the velocity magnitude for substepping later
|
||||
const float velMag = _bigUx[index] * _bigUx[index] +
|
||||
_bigUy[index] * _bigUy[index] +
|
||||
_bigUz[index] * _bigUz[index];
|
||||
if (velMag > maxVelMag1) maxVelMag1 = velMag;
|
||||
// make sure to skip one on the beginning and end
|
||||
int xStart = (xSmall == 0) ? 1 : 0;
|
||||
int xEnd = (xSmall == _xResSm - 1) ? _amplify - 1 : _amplify;
|
||||
int yStart = (ySmall == 0) ? 1 : 0;
|
||||
int yEnd = (ySmall == _yResSm - 1) ? _amplify - 1 : _amplify;
|
||||
int zStart = (zSmall == 0) ? 1 : 0;
|
||||
int zEnd = (zSmall == _zResSm - 1) ? _amplify - 1 : _amplify;
|
||||
|
||||
for (int zBig = zStart; zBig < zEnd; zBig++)
|
||||
for (int yBig = yStart; yBig < yEnd; yBig++)
|
||||
for (int xBig = xStart; xBig < xEnd; xBig++)
|
||||
{
|
||||
const int x = xSmall * _amplify + xBig;
|
||||
const int y = ySmall * _amplify + yBig;
|
||||
const int z = zSmall * _amplify + zBig;
|
||||
|
||||
// zero out velocity inside obstacles
|
||||
float obsCheck = INTERPOLATE::lerp3dToFloat(
|
||||
obstacles, posSm[0], posSm[1], posSm[2], _xResSm, _yResSm, _zResSm);
|
||||
if (obsCheck > 0.95)
|
||||
_bigUx[index] = _bigUy[index] = _bigUz[index] = 0.;
|
||||
} // xyz
|
||||
// get unit position for both fine and coarse grid
|
||||
const Vec3 pos = Vec3(x,y,z);
|
||||
const Vec3 posSm = pos * invAmp;
|
||||
|
||||
#if PARALLEL==1
|
||||
maxVelMagThreads[id] = maxVelMag1;
|
||||
#else
|
||||
maxVelMagThreads[0] = maxVelMag1;
|
||||
#endif
|
||||
}
|
||||
} // omp
|
||||
|
||||
// compute maximum over threads
|
||||
float maxVelMag = maxVelMagThreads[0];
|
||||
#if PARALLEL==1
|
||||
for (int i = 1; i < 8; i++)
|
||||
if (maxVelMag < maxVelMagThreads[i])
|
||||
maxVelMag = maxVelMagThreads[i];
|
||||
#endif
|
||||
// get grid index for both fine and coarse grid
|
||||
const int index = x + y *_xResBig + z *_slabSizeBig;
|
||||
|
||||
// prepare density for an advection
|
||||
SWAP_POINTERS(_densityBig, _densityBigOld);
|
||||
// get a linearly interpolated velocity and texcoords
|
||||
// from the coarse grid
|
||||
Vec3 vel = INTERPOLATE::lerp3dVec( xvel,yvel,zvel,
|
||||
posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm);
|
||||
Vec3 uvw = INTERPOLATE::lerp3dVec( _tcU,_tcV,_tcW,
|
||||
posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm);
|
||||
|
||||
// based on the maximum velocity present, see if we need to substep,
|
||||
// but cap the maximum number of substeps to 5
|
||||
const int maxSubSteps = 25;
|
||||
const int maxVel = 5;
|
||||
maxVelMag = sqrt(maxVelMag) * dt;
|
||||
int totalSubsteps = (int)(maxVelMag / (float)maxVel);
|
||||
totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps;
|
||||
// printf("totalSubsteps: %d\n", totalSubsteps);
|
||||
totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps;
|
||||
const float dtSubdiv = dt / (float)totalSubsteps;
|
||||
// multiply the texture coordinate by _resSm so that turbulence
|
||||
// synthesis begins at the first octave that the coarse grid
|
||||
// cannot capture
|
||||
Vec3 texCoord = Vec3(uvw[0] * _resSm[0],
|
||||
uvw[1] * _resSm[1],
|
||||
uvw[2] * _resSm[2]);
|
||||
|
||||
// set boundaries of big velocity grid
|
||||
FLUID_3D::setZeroX(_bigUx, _resBig);
|
||||
FLUID_3D::setZeroY(_bigUy, _resBig);
|
||||
FLUID_3D::setZeroZ(_bigUz, _resBig);
|
||||
// retrieve wavelet energy at highest frequency
|
||||
float energy = INTERPOLATE::lerp3d(
|
||||
_highFreqEnergy, posSm[0],posSm[1],posSm[2], _xResSm, _yResSm, _zResSm);
|
||||
|
||||
// do the MacCormack advection, with substepping if necessary
|
||||
for(int substep = 0; substep < totalSubsteps; substep++)
|
||||
{
|
||||
FLUID_3D::advectFieldMacCormack(dtSubdiv, _bigUx, _bigUy, _bigUz,
|
||||
_densityBigOld, _densityBig, _tempBig1, _tempBig2, _resBig, NULL);
|
||||
// base amplitude for octave 0
|
||||
float coefficient = sqrtf(2.0f * fabs(energy));
|
||||
const float amplitude = *_strength * fabs(0.5 * coefficient) * persistence;
|
||||
|
||||
if (substep < totalSubsteps - 1)
|
||||
SWAP_POINTERS(_densityBig, _densityBigOld);
|
||||
} // substep
|
||||
|
||||
// wipe the density borders
|
||||
FLUID_3D::setZeroBorder(_densityBig, _resBig);
|
||||
|
||||
// reset texture coordinates now in preparation for next timestep
|
||||
// Shouldn't do this before generating the noise because then the
|
||||
// eigenvalues stored do not reflect the underlying texture coordinates
|
||||
resetTextureCoordinates();
|
||||
|
||||
// output files
|
||||
// string prefix = string("./amplified.preview/density_bigxy_");
|
||||
// FLUID_3D::writeImageSliceXY(_densityBig, _resBig, _resBig[2]/2, prefix, _totalStepsBig, 1.0f);
|
||||
//string df3prefix = string("./df3/density_big_");
|
||||
//IMAGE::dumpDF3(_totalStepsBig, df3prefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]);
|
||||
// string pbrtPrefix = string("./pbrt/density_big_");
|
||||
// IMAGE::dumpPBRT(_totalStepsBig, pbrtPrefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]);
|
||||
|
||||
_totalStepsBig++;
|
||||
// add noise to velocity, but only if the turbulence is
|
||||
// sufficiently undeformed, and the energy is large enough
|
||||
// to make a difference
|
||||
const bool addNoise = _eigMax[indexSmall] < 2. &&
|
||||
_eigMin[indexSmall] > 0.5;
|
||||
|
||||
if (addNoise && amplitude > _cullingThreshold) {
|
||||
// base amplitude for octave 0
|
||||
float amplitudeScaled = amplitude;
|
||||
|
||||
for (int octave = 0; octave < _octaves; octave++)
|
||||
{
|
||||
// multiply the vector noise times the maximum allowed
|
||||
// noise amplitude at this octave, and add it to the total
|
||||
vel += WVelocityWithJacobian(texCoord, &xUnwarped[0], &yUnwarped[0], &zUnwarped[0]) * amplitudeScaled;
|
||||
|
||||
// scale coefficient for next octave
|
||||
amplitudeScaled *= persistence;
|
||||
texCoord *= 2.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// Store velocity + turbulence in big grid for maccormack step
|
||||
//
|
||||
// If you wanted to save memory, you would instead perform a
|
||||
// semi-Lagrangian backtrace for the current grid cell here. Then
|
||||
// you could just throw the velocity away.
|
||||
_bigUx[index] = vel[0];
|
||||
_bigUy[index] = vel[1];
|
||||
_bigUz[index] = vel[2];
|
||||
|
||||
// compute the velocity magnitude for substepping later
|
||||
const float velMag = _bigUx[index] * _bigUx[index] +
|
||||
_bigUy[index] * _bigUy[index] +
|
||||
_bigUz[index] * _bigUz[index];
|
||||
if (velMag > maxVelMag1) maxVelMag1 = velMag;
|
||||
|
||||
// zero out velocity inside obstacles
|
||||
float obsCheck = INTERPOLATE::lerp3dToFloat(
|
||||
obstacles, posSm[0], posSm[1], posSm[2], _xResSm, _yResSm, _zResSm);
|
||||
|
||||
if (obsCheck > 0.95)
|
||||
_bigUx[index] = _bigUy[index] = _bigUz[index] = 0.;
|
||||
} // xyz
|
||||
|
||||
#if PARALLEL==1
|
||||
maxVelMagThreads[id] = maxVelMag1;
|
||||
#else
|
||||
maxVelMagThreads[0] = maxVelMag1;
|
||||
#endif
|
||||
}
|
||||
} // omp
|
||||
|
||||
// compute maximum over threads
|
||||
float maxVelMag = maxVelMagThreads[0];
|
||||
#if PARALLEL==1
|
||||
for (int i = 1; i < 8; i++)
|
||||
if (maxVelMag < maxVelMagThreads[i])
|
||||
maxVelMag = maxVelMagThreads[i];
|
||||
#endif
|
||||
|
||||
// prepare density for an advection
|
||||
SWAP_POINTERS(_densityBig, _densityBigOld);
|
||||
|
||||
// based on the maximum velocity present, see if we need to substep,
|
||||
// but cap the maximum number of substeps to 5
|
||||
const int maxSubSteps = 25;
|
||||
const int maxVel = 5;
|
||||
maxVelMag = sqrt(maxVelMag) * dt;
|
||||
int totalSubsteps = (int)(maxVelMag / (float)maxVel);
|
||||
totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps;
|
||||
// printf("totalSubsteps: %d\n", totalSubsteps);
|
||||
totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps;
|
||||
const float dtSubdiv = dt / (float)totalSubsteps;
|
||||
|
||||
// set boundaries of big velocity grid
|
||||
FLUID_3D::setZeroX(_bigUx, _resBig);
|
||||
FLUID_3D::setZeroY(_bigUy, _resBig);
|
||||
FLUID_3D::setZeroZ(_bigUz, _resBig);
|
||||
|
||||
// do the MacCormack advection, with substepping if necessary
|
||||
for(int substep = 0; substep < totalSubsteps; substep++)
|
||||
{
|
||||
FLUID_3D::advectFieldMacCormack(dtSubdiv, _bigUx, _bigUy, _bigUz,
|
||||
_densityBigOld, _densityBig, _tempBig1, _tempBig2, _resBig, NULL);
|
||||
|
||||
if (substep < totalSubsteps - 1)
|
||||
SWAP_POINTERS(_densityBig, _densityBigOld);
|
||||
} // substep
|
||||
|
||||
// wipe the density borders
|
||||
FLUID_3D::setZeroBorder(_densityBig, _resBig);
|
||||
|
||||
// reset texture coordinates now in preparation for next timestep
|
||||
// Shouldn't do this before generating the noise because then the
|
||||
// eigenvalues stored do not reflect the underlying texture coordinates
|
||||
resetTextureCoordinates();
|
||||
|
||||
// output files
|
||||
// string prefix = string("./amplified.preview/density_bigxy_");
|
||||
// FLUID_3D::writeImageSliceXY(_densityBig, _resBig, _resBig[2]/2, prefix, _totalStepsBig, 1.0f);
|
||||
//string df3prefix = string("./df3/density_big_");
|
||||
//IMAGE::dumpDF3(_totalStepsBig, df3prefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]);
|
||||
// string pbrtPrefix = string("./pbrt/density_big_");
|
||||
// IMAGE::dumpPBRT(_totalStepsBig, pbrtPrefix, _densityBig, _resBig[0],_resBig[1],_resBig[2]);
|
||||
|
||||
_totalStepsBig++;
|
||||
|
||||
delete[] _bigUx;
|
||||
delete[] _bigUy;
|
||||
delete[] _bigUz;
|
||||
|
||||
delete[] _tempBig1;
|
||||
delete[] _tempBig2;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class WTURBULENCE
|
||||
void stepTurbulenceFull(float dt, float* xvel, float* yvel, float* zvel, unsigned char *obstacles);
|
||||
|
||||
// texcoord functions
|
||||
void advectTextureCoordinates(float dtOrg, float* xvel, float* yvel, float* zvel);
|
||||
void advectTextureCoordinates (float dtOrg, float* xvel, float* yvel, float* zvel, float *_tempBig1, float *_tempBig2);
|
||||
void resetTextureCoordinates();
|
||||
|
||||
void computeEnergy(float* xvel, float* yvel, float* zvel, unsigned char *obstacles);
|
||||
@@ -73,7 +73,7 @@ class WTURBULENCE
|
||||
// is accessed on through rna gui
|
||||
float *_strength;
|
||||
|
||||
protected:
|
||||
// protected:
|
||||
// enlargement factor from original velocity field / simulation
|
||||
// _Big = _amplify * _Sm
|
||||
int _amplify;
|
||||
@@ -111,26 +111,17 @@ class WTURBULENCE
|
||||
float* _densityBig;
|
||||
float* _densityBigOld;
|
||||
|
||||
// big velocity macCormack fields
|
||||
float* _bigUx;
|
||||
float* _bigUy;
|
||||
float* _bigUz;
|
||||
// temp arrays for BFECC and MacCormack - they have more convenient
|
||||
// names in the actual implementations
|
||||
float* _tempBig1;
|
||||
float* _tempBig2;
|
||||
|
||||
// texture coordinates for noise
|
||||
float* _tcU;
|
||||
float* _tcV;
|
||||
float* _tcW;
|
||||
float* _tcTemp;
|
||||
|
||||
float* _eigMin;
|
||||
float* _eigMax;
|
||||
float* _eigMin; // no save -dg
|
||||
float* _eigMax; // no save -dg
|
||||
|
||||
// wavelet decomposition of velocity energies
|
||||
float* _energy;
|
||||
float* _energy; // no save -dg
|
||||
|
||||
// noise data
|
||||
float* _noiseTile;
|
||||
@@ -140,7 +131,7 @@ class WTURBULENCE
|
||||
int _totalStepsBig;
|
||||
|
||||
// highest frequency component of wavelet decomposition
|
||||
float* _highFreqEnergy;
|
||||
float* _highFreqEnergy; // no save -dg
|
||||
|
||||
void computeEigenvalues();
|
||||
void decomposeEnergy();
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* The Original Code is Copyright (C) 2009 by Daniel Genrich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): None
|
||||
* Contributor(s): Daniel Genrich
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
@@ -137,7 +137,7 @@ extern "C" void smoke_dissolve(FLUID_3D *fluid, int speed, int log)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void smoke_dissolve_wavelet(WTURBULENCE *wt, int speed, int log)
|
||||
extern "C" void smoke_turbulence_dissolve(WTURBULENCE *wt, int speed, int log)
|
||||
{
|
||||
float *density = wt->getDensityBig();
|
||||
Vec3Int r = wt->getResBig();
|
||||
@@ -172,7 +172,7 @@ extern "C" void smoke_dissolve_wavelet(WTURBULENCE *wt, int speed, int log)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void smoke_initWaveletBlenderRNA(WTURBULENCE *wt, float *strength)
|
||||
extern "C" void smoke_turbulence_initBlenderRNA(WTURBULENCE *wt, float *strength)
|
||||
{
|
||||
wt->initBlenderRNA(strength);
|
||||
}
|
||||
@@ -181,6 +181,36 @@ template < class T > inline T ABS( T a ) {
|
||||
return (0 < a) ? a : -a ;
|
||||
}
|
||||
|
||||
extern "C" void smoke_export(FLUID_3D *fluid, float *dt, float *dx, float **dens, float **densold, float **heat, float **heatold, float **vx, float **vy, float **vz, float **vxold, float **vyold, float **vzold, unsigned char **obstacles)
|
||||
{
|
||||
*dens = fluid->_density;
|
||||
*densold = fluid->_densityOld;
|
||||
*heat = fluid->_heat;
|
||||
*heatold = fluid->_heatOld;
|
||||
*vx = fluid->_xVelocity;
|
||||
*vy = fluid->_yVelocity;
|
||||
*vz = fluid->_zVelocity;
|
||||
*vxold = fluid->_xVelocityOld;
|
||||
*vyold = fluid->_yVelocityOld;
|
||||
*vzold = fluid->_zVelocityOld;
|
||||
*obstacles = fluid->_obstacles;
|
||||
dt = &(fluid->_dt);
|
||||
dx = &(fluid->_dx);
|
||||
|
||||
}
|
||||
|
||||
extern "C" void smoke_turbulence_export(WTURBULENCE *wt, float **dens, float **densold, float **tcu, float **tcv, float **tcw)
|
||||
{
|
||||
if(!wt)
|
||||
return;
|
||||
|
||||
*dens = wt->_densityBig;
|
||||
*densold = wt->_densityBigOld;
|
||||
*tcu = wt->_tcU;
|
||||
*tcv = wt->_tcV;
|
||||
*tcw = wt->_tcW;
|
||||
}
|
||||
|
||||
extern "C" float *smoke_get_density(FLUID_3D *fluid)
|
||||
{
|
||||
return fluid->_density;
|
||||
@@ -193,17 +223,17 @@ extern "C" float *smoke_get_heat(FLUID_3D *fluid)
|
||||
|
||||
extern "C" float *smoke_get_velocity_x(FLUID_3D *fluid)
|
||||
{
|
||||
return fluid->_xVorticity;
|
||||
return fluid->_xVelocity;
|
||||
}
|
||||
|
||||
extern "C" float *smoke_get_velocity_y(FLUID_3D *fluid)
|
||||
{
|
||||
return fluid->_yVorticity;
|
||||
return fluid->_yVelocity;
|
||||
}
|
||||
|
||||
extern "C" float *smoke_get_velocity_z(FLUID_3D *fluid)
|
||||
{
|
||||
return fluid->_zVorticity;
|
||||
return fluid->_zVelocity;
|
||||
}
|
||||
|
||||
extern "C" float *smoke_turbulence_get_density(WTURBULENCE *wt)
|
||||
@@ -211,14 +241,13 @@ extern "C" float *smoke_turbulence_get_density(WTURBULENCE *wt)
|
||||
return wt ? wt->getDensityBig() : NULL;
|
||||
}
|
||||
|
||||
extern "C" void smoke_turbulence_get_res(WTURBULENCE *wt, int *res)
|
||||
extern "C" void smoke_turbulence_get_res(WTURBULENCE *wt, unsigned int *res)
|
||||
{
|
||||
if(wt)
|
||||
{
|
||||
Vec3Int r = wt->getResBig();
|
||||
res[0] = r[0];
|
||||
res[1] = r[1];
|
||||
res[2] = r[2];
|
||||
res[0] = wt->_resBig[0];
|
||||
res[1] = wt->_resBig[1];
|
||||
res[2] = wt->_resBig[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
|
||||
import bpy
|
||||
|
||||
def smoke_panel_enabled_low(smd):
|
||||
if smd.smoke_type == 'TYPE_DOMAIN':
|
||||
return smd.domain.point_cache.baked==False
|
||||
return True
|
||||
|
||||
class PhysicButtonsPanel(bpy.types.Panel):
|
||||
__space_type__ = "PROPERTIES"
|
||||
__region_type__ = "WINDOW"
|
||||
@@ -38,6 +43,8 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel):
|
||||
split.itemL()
|
||||
|
||||
if md:
|
||||
|
||||
# layout.enabled = smoke_panel_enabled(md)
|
||||
layout.itemR(md, "smoke_type", expand=True)
|
||||
|
||||
if md.smoke_type == 'TYPE_DOMAIN':
|
||||
@@ -49,13 +56,6 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel):
|
||||
col = split.column()
|
||||
col.itemL(text="Resolution:")
|
||||
col.itemR(domain, "maxres", text="Divisions")
|
||||
|
||||
col.itemL(text="Display:")
|
||||
col.itemR(domain, "visibility", text="Resolution")
|
||||
col.itemR(domain, "color", slider=True)
|
||||
sub = col.column()
|
||||
sub.active = domain.highres
|
||||
sub.itemR(domain, "viewhighres")
|
||||
|
||||
col = split.column()
|
||||
col.itemL(text="Behavior:")
|
||||
@@ -88,43 +88,7 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel):
|
||||
|
||||
#elif md.smoke_type == 'TYPE_COLL':
|
||||
# layout.itemS()
|
||||
|
||||
class PHYSICS_PT_smoke_highres(PhysicButtonsPanel):
|
||||
__label__ = "Smoke High Resolution"
|
||||
__default_closed__ = True
|
||||
|
||||
def poll(self, context):
|
||||
md = context.smoke
|
||||
if md:
|
||||
return (md.smoke_type == 'TYPE_DOMAIN')
|
||||
|
||||
return False
|
||||
|
||||
def draw_header(self, context):
|
||||
layout = self.layout
|
||||
|
||||
high = context.smoke.domain_settings
|
||||
|
||||
layout.itemR(high, "highres", text="")
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
high = context.smoke.domain_settings
|
||||
|
||||
layout.active = high.highres
|
||||
|
||||
split = layout.split()
|
||||
|
||||
col = split.column()
|
||||
col.itemL(text="Resolution:")
|
||||
col.itemR(high, "amplify", text="Divisions")
|
||||
|
||||
sub = split.column()
|
||||
sub.itemL(text="Noise Method:")
|
||||
sub.row().itemR(high, "noise_type", text="")
|
||||
sub.itemR(high, "strength")
|
||||
|
||||
|
||||
class PHYSICS_PT_smoke_groups(PhysicButtonsPanel):
|
||||
__label__ = "Smoke Groups"
|
||||
__default_closed__ = True
|
||||
@@ -153,7 +117,168 @@ class PHYSICS_PT_smoke_groups(PhysicButtonsPanel):
|
||||
col = split.column()
|
||||
col.itemL(text="Collision Group:")
|
||||
col.itemR(group, "coll_group", text="")
|
||||
|
||||
class PHYSICS_PT_smoke_cache(PhysicButtonsPanel):
|
||||
__label__ = "Smoke Cache"
|
||||
__default_closed__ = True
|
||||
|
||||
def poll(self, context):
|
||||
md = context.smoke
|
||||
if md:
|
||||
return (md.smoke_type == 'TYPE_DOMAIN')
|
||||
|
||||
return False
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
md = context.smoke
|
||||
|
||||
if md.smoke_type == 'TYPE_DOMAIN':
|
||||
|
||||
domain = md.domain_settings
|
||||
cache = domain.point_cache
|
||||
|
||||
layout.set_context_pointer("PointCache", cache)
|
||||
|
||||
row = layout.row()
|
||||
row.template_list(cache, "point_cache_list", cache, "active_point_cache_index")
|
||||
col = row.column(align=True)
|
||||
col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="")
|
||||
col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="")
|
||||
|
||||
row = layout.row()
|
||||
row.itemR(cache, "name")
|
||||
|
||||
row = layout.row()
|
||||
row.itemR(cache, "start_frame")
|
||||
row.itemR(cache, "end_frame")
|
||||
|
||||
row = layout.row()
|
||||
|
||||
if cache.baked == True:
|
||||
row.itemO("ptcache.free_bake", text="Free Bake")
|
||||
else:
|
||||
row.item_booleanO("ptcache.bake", "bake", True, text="Bake")
|
||||
|
||||
subrow = row.row()
|
||||
subrow.enabled = cache.frames_skipped or cache.outdated
|
||||
subrow.itemO("ptcache.bake", "bake", False, text="Calculate to Current Frame")
|
||||
|
||||
row = layout.row()
|
||||
#row.enabled = smoke_panel_enabled(psys)
|
||||
row.itemO("ptcache.bake_from_cache", text="Current Cache to Bake")
|
||||
|
||||
row = layout.row()
|
||||
#row.enabled = smoke_panel_enabled(psys)
|
||||
|
||||
layout.itemL(text=cache.info)
|
||||
|
||||
layout.itemS()
|
||||
|
||||
row = layout.row()
|
||||
row.itemO("ptcache.bake_all", "bake", True, text="Bake All Dynamics")
|
||||
row.itemO("ptcache.free_bake_all", text="Free All Bakes")
|
||||
layout.itemO("ptcache.bake_all", "bake", False, text="Update All Dynamics to current frame")
|
||||
|
||||
class PHYSICS_PT_smoke_highres(PhysicButtonsPanel):
|
||||
__label__ = "Smoke High Resolution"
|
||||
__default_closed__ = True
|
||||
|
||||
def poll(self, context):
|
||||
md = context.smoke
|
||||
if md:
|
||||
return (md.smoke_type == 'TYPE_DOMAIN')
|
||||
|
||||
return False
|
||||
|
||||
def draw_header(self, context):
|
||||
layout = self.layout
|
||||
|
||||
high = context.smoke.domain_settings
|
||||
|
||||
layout.itemR(high, "highres", text="")
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
md = context.smoke_hr
|
||||
|
||||
if md:
|
||||
|
||||
split = layout.split()
|
||||
|
||||
col = split.column()
|
||||
col.itemL(text="Resolution:")
|
||||
col.itemR(md, "amplify", text="Divisions")
|
||||
|
||||
sub = split.column()
|
||||
sub.itemL(text="Noise Method:")
|
||||
sub.row().itemR(md, "noise_type", text="")
|
||||
sub.itemR(md, "strength")
|
||||
sub.itemR(md, "show_highres")
|
||||
|
||||
class PHYSICS_PT_smoke_cache_highres(PhysicButtonsPanel):
|
||||
__label__ = "Smoke Cache"
|
||||
__default_closed__ = True
|
||||
|
||||
def poll(self, context):
|
||||
return (context.smoke_hr != None)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
md = context.smoke_hr
|
||||
|
||||
if md:
|
||||
|
||||
cache = md.point_cache
|
||||
|
||||
layout.set_context_pointer("PointCache", cache)
|
||||
|
||||
row = layout.row()
|
||||
row.template_list(cache, "point_cache_list", cache, "active_point_cache_index")
|
||||
col = row.column(align=True)
|
||||
col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="")
|
||||
col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="")
|
||||
|
||||
row = layout.row()
|
||||
row.itemR(cache, "name")
|
||||
|
||||
row = layout.row()
|
||||
row.itemR(cache, "start_frame")
|
||||
row.itemR(cache, "end_frame")
|
||||
|
||||
row = layout.row()
|
||||
|
||||
if cache.baked == True:
|
||||
row.itemO("ptcache.free_bake", text="Free Bake")
|
||||
else:
|
||||
row.item_booleanO("ptcache.bake", "bake", True, text="Bake")
|
||||
|
||||
subrow = row.row()
|
||||
subrow.enabled = cache.frames_skipped or cache.outdated
|
||||
subrow.itemO("ptcache.bake", "bake", False, text="Calculate to Current Frame")
|
||||
|
||||
row = layout.row()
|
||||
#row.enabled = smoke_panel_enabled(psys)
|
||||
row.itemO("ptcache.bake_from_cache", text="Current Cache to Bake")
|
||||
|
||||
row = layout.row()
|
||||
#row.enabled = smoke_panel_enabled(psys)
|
||||
|
||||
layout.itemL(text=cache.info)
|
||||
|
||||
layout.itemS()
|
||||
|
||||
row = layout.row()
|
||||
row.itemO("ptcache.bake_all", "bake", True, text="Bake All Dynamics")
|
||||
row.itemO("ptcache.free_bake_all", text="Free All Bakes")
|
||||
layout.itemO("ptcache.bake_all", "bake", False, text="Update All Dynamics to current frame")
|
||||
|
||||
|
||||
bpy.types.register(PHYSICS_PT_smoke)
|
||||
bpy.types.register(PHYSICS_PT_smoke_highres)
|
||||
bpy.types.register(PHYSICS_PT_smoke_cache)
|
||||
bpy.types.register(PHYSICS_PT_smoke_groups)
|
||||
#bpy.types.register(PHYSICS_PT_smoke_highres)
|
||||
#bpy.types.register(PHYSICS_PT_smoke_cache_highres)
|
||||
|
||||
@@ -60,8 +60,8 @@
|
||||
#define PTCACHE_TYPE_SOFTBODY 0
|
||||
#define PTCACHE_TYPE_PARTICLES 1
|
||||
#define PTCACHE_TYPE_CLOTH 2
|
||||
#define PTCACHE_TYPE_SMOKE_DOMAIN_LOW 3
|
||||
#define PTCACHE_TYPE_SMOKE_DOMAIN_HIGH 4
|
||||
#define PTCACHE_TYPE_SMOKE_DOMAIN 3
|
||||
#define PTCACHE_TYPE_SMOKE_HIGHRES 4
|
||||
|
||||
/* PTCache read return code */
|
||||
#define PTCACHE_READ_EXACT 1
|
||||
@@ -158,7 +158,7 @@ void BKE_ptcache_make_particle_key(struct ParticleKey *key, int index, void **da
|
||||
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
|
||||
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
|
||||
void BKE_ptcache_id_from_cloth(PTCacheID *pid, struct Object *ob, struct ClothModifierData *clmd);
|
||||
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num);
|
||||
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd);
|
||||
|
||||
void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob);
|
||||
|
||||
|
||||
@@ -32,24 +32,17 @@
|
||||
#ifndef BKE_SMOKE_H_
|
||||
#define BKE_SMOKE_H_
|
||||
|
||||
typedef int (*bresenham_callback) (float *input, int res[3], int *pixel, float *tRay);
|
||||
|
||||
void smokeModifier_do(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, int useRenderParams, int isFinalCalc);
|
||||
|
||||
void smokeModifier_free (struct SmokeModifierData *smd);
|
||||
void smokeModifier_reset(struct SmokeModifierData *smd);
|
||||
void smokeModifier_createType(struct SmokeModifierData *smd);
|
||||
|
||||
void smoke_set_tray(struct SmokeModifierData *smd, size_t index, float transparency);
|
||||
float smoke_get_tray(struct SmokeModifierData *smd, size_t index);
|
||||
float smoke_get_tvox(struct SmokeModifierData *smd, size_t index);
|
||||
void smoke_set_tvox(struct SmokeModifierData *smd, size_t index, float tvox);
|
||||
// high res modifier
|
||||
void smokeHRModifier_do(struct SmokeHRModifierData *shrmd, struct Scene *scene, struct Object *ob, int useRenderParams, int isFinalCalc);
|
||||
void smokeHRModifier_free(struct SmokeHRModifierData *shrmd);
|
||||
|
||||
void smoke_set_bigtray(struct SmokeModifierData *smd, size_t index, float transparency);
|
||||
float smoke_get_bigtray(struct SmokeModifierData *smd, size_t index);
|
||||
float smoke_get_bigtvox(struct SmokeModifierData *smd, size_t index);
|
||||
void smoke_set_bigtvox(struct SmokeModifierData *smd, size_t index, float tvox);
|
||||
|
||||
long long smoke_get_mem_req(int xres, int yres, int zres, int amplify);
|
||||
void smoke_prepare_View(struct SmokeModifierData *smd, float *light);
|
||||
void smoke_prepare_bigView(struct SmokeModifierData *smd, float *light);
|
||||
|
||||
#endif /* BKE_SMOKE_H_ */
|
||||
|
||||
@@ -34,6 +34,8 @@ SET(INC
|
||||
../nodes ../../../extern/glew/include ../gpu ../makesrna ../../../intern/smoke/extern
|
||||
../../../intern/bsp/extern ../blenfont
|
||||
../../../intern/audaspace/intern
|
||||
../../../extern/lzo/minilzo
|
||||
../../../extern/lzma
|
||||
${ZLIB_INC}
|
||||
)
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ incs += ' #/extern/bullet2/src'
|
||||
incs += ' #/intern/opennl/extern #/intern/bsp/extern'
|
||||
incs += ' ../gpu #/extern/glew/include'
|
||||
incs += ' #/intern/smoke/extern'
|
||||
incs += ' #/extern/lzo/minilzo'
|
||||
incs += ' #/extern/lzma'
|
||||
incs += ' #/intern/audaspace/intern'
|
||||
|
||||
incs += ' ' + env['BF_OPENGL_INC']
|
||||
|
||||
@@ -5801,26 +5801,6 @@ static void smokeModifier_initData(ModifierData *md)
|
||||
smd->coll = NULL;
|
||||
smd->type = 0;
|
||||
smd->time = -1;
|
||||
|
||||
/*
|
||||
smd->fluid = NULL;
|
||||
smd->maxres = 48;
|
||||
smd->amplify = 4;
|
||||
smd->omega = 0.5;
|
||||
smd->time = 0;
|
||||
smd->flags = 0;
|
||||
smd->noise = MOD_SMOKE_NOISEWAVE;
|
||||
smd->visibility = 1;
|
||||
|
||||
// init 3dview buffer
|
||||
smd->tvox = NULL;
|
||||
smd->tray = NULL;
|
||||
smd->tvoxbig = NULL;
|
||||
smd->traybig = NULL;
|
||||
smd->viewsettings = 0;
|
||||
smd->bind = NULL;
|
||||
smd->max_textures = 0;
|
||||
*/
|
||||
}
|
||||
|
||||
static void smokeModifier_freeData(ModifierData *md)
|
||||
@@ -5884,6 +5864,50 @@ static void smokeModifier_updateDepgraph(
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* Smoke High Resolution */
|
||||
|
||||
static void smokeHRModifier_initData(ModifierData *md)
|
||||
{
|
||||
SmokeHRModifierData *shrmd = (SmokeHRModifierData*) md;
|
||||
|
||||
shrmd->wt = NULL;
|
||||
shrmd->time = -1;
|
||||
shrmd->strength = 2.0f;
|
||||
shrmd->amplify = 1;
|
||||
shrmd->noise = MOD_SMOKE_NOISEWAVE;
|
||||
shrmd->point_cache = BKE_ptcache_add(&shrmd->ptcaches);
|
||||
shrmd->point_cache->flag |= PTCACHE_DISK_CACHE;
|
||||
shrmd->point_cache->step = 1;
|
||||
}
|
||||
|
||||
static void smokeHRModifier_freeData(ModifierData *md)
|
||||
{
|
||||
SmokeHRModifierData *shrmd = (SmokeHRModifierData*) md;
|
||||
|
||||
smokeHRModifier_free (shrmd);
|
||||
}
|
||||
|
||||
static void smokeHRModifier_deformVerts(
|
||||
ModifierData *md, Object *ob, DerivedMesh *derivedData,
|
||||
float (*vertexCos)[3], int numVerts, int useRenderParams, int isFinalCalc)
|
||||
{
|
||||
SmokeHRModifierData *shrmd = (SmokeHRModifierData*) md;
|
||||
smokeHRModifier_do(shrmd, md->scene, ob, useRenderParams, isFinalCalc);
|
||||
}
|
||||
|
||||
static int smokeHRModifier_dependsOnTime(ModifierData *md)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void smokeHRModifier_updateDepgraph(
|
||||
ModifierData *md, DagForest *forest, Scene *scene, Object *ob,
|
||||
DagNode *obNode)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/* Cloth */
|
||||
|
||||
static void clothModifier_initData(ModifierData *md)
|
||||
@@ -8580,10 +8604,23 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
|
||||
mti->type = eModifierTypeType_OnlyDeform;
|
||||
mti->initData = smokeModifier_initData;
|
||||
mti->freeData = smokeModifier_freeData;
|
||||
mti->flags = eModifierTypeFlag_AcceptsMesh;
|
||||
mti->flags = eModifierTypeFlag_AcceptsMesh
|
||||
| eModifierTypeFlag_UsesPointCache
|
||||
| eModifierTypeFlag_Single;
|
||||
mti->deformVerts = smokeModifier_deformVerts;
|
||||
mti->dependsOnTime = smokeModifier_dependsOnTime;
|
||||
mti->updateDepgraph = smokeModifier_updateDepgraph;
|
||||
|
||||
mti = INIT_TYPE(SmokeHR);
|
||||
mti->type = eModifierTypeType_OnlyDeform;
|
||||
mti->initData = smokeHRModifier_initData;
|
||||
mti->freeData = smokeHRModifier_freeData;
|
||||
mti->flags = eModifierTypeFlag_AcceptsMesh
|
||||
| eModifierTypeFlag_UsesPointCache
|
||||
| eModifierTypeFlag_Single;
|
||||
mti->deformVerts = smokeHRModifier_deformVerts;
|
||||
mti->dependsOnTime = smokeHRModifier_dependsOnTime;
|
||||
mti->updateDepgraph = smokeHRModifier_updateDepgraph;
|
||||
|
||||
mti = INIT_TYPE(Cloth);
|
||||
mti->type = eModifierTypeType_Nonconstructive;
|
||||
|
||||
@@ -59,7 +59,12 @@
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
|
||||
/* both in intern */
|
||||
#include "smoke_API.h"
|
||||
#include "minilzo.h"
|
||||
|
||||
#include "LzmaLib.h"
|
||||
|
||||
|
||||
/* needed for directory lookup */
|
||||
#ifndef WIN32
|
||||
@@ -469,43 +474,116 @@ void BKE_ptcache_id_from_particles(PTCacheID *pid, Object *ob, ParticleSystem *p
|
||||
pid->info_types= (1<<BPHYS_DATA_TIMES);
|
||||
}
|
||||
|
||||
#if 0 // XXX smoke pointcache stuff breaks compiling now
|
||||
/* Smoke functions */
|
||||
static int ptcache_totpoint_smoke(void *smoke_v)
|
||||
{
|
||||
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
|
||||
SmokeDomainSettings *sds = smd->domain;
|
||||
|
||||
if(sds->fluid)
|
||||
{
|
||||
if(sds->fluid) {
|
||||
return sds->res[0]*sds->res[1]*sds->res[2];
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ptcache_totpoint_smoke_turbulence(void *smoke_v)
|
||||
{
|
||||
SmokeHRModifierData *shrmd= (SmokeHRModifierData *)smoke_v;
|
||||
|
||||
if(shrmd->wt) {
|
||||
/*
|
||||
unsigned int res[3];
|
||||
|
||||
smoke_turbulence_get_res(sds->wt, res);
|
||||
return res[0]*res[1]*res[2];
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// forward decleration
|
||||
static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, int size);
|
||||
|
||||
static int ptcache_compress_write(PTCacheFile *pf, unsigned char *in, unsigned int in_len, unsigned char *out, int mode)
|
||||
{
|
||||
int r;
|
||||
unsigned char compressed;
|
||||
LZO_HEAP_ALLOC(wrkmem, LZO1X_MEM_COMPRESS);
|
||||
unsigned int out_len = LZO_OUT_LEN(in_len);
|
||||
unsigned char *props = MEM_callocN(16*sizeof(char), "tmp");
|
||||
size_t sizeOfIt = 5;
|
||||
|
||||
if(mode == 1) {
|
||||
r = lzo1x_1_compress(in, (lzo_uint)in_len, out, (lzo_uint *)&out_len, wrkmem);
|
||||
if (!(r == LZO_E_OK) || (out_len >= in_len))
|
||||
compressed = 0;
|
||||
else
|
||||
compressed = 1;
|
||||
}
|
||||
else if(mode == 2) {
|
||||
|
||||
r = LzmaCompress(out, (size_t *)&out_len, in, in_len,//assume sizeof(char)==1....
|
||||
props, &sizeOfIt, 5, 1 << 24, 3, 0, 2, 32, 2);
|
||||
|
||||
if(!(r == SZ_OK) || (out_len >= in_len))
|
||||
compressed = 0;
|
||||
else
|
||||
compressed = 2;
|
||||
}
|
||||
|
||||
ptcache_file_write(pf, &compressed, 1, sizeof(unsigned char));
|
||||
if(compressed) {
|
||||
ptcache_file_write(pf, &out_len, 1, sizeof(unsigned int));
|
||||
ptcache_file_write(pf, out, out_len, sizeof(unsigned char));
|
||||
}
|
||||
else
|
||||
ptcache_file_write(pf, in, in_len, sizeof(unsigned char));
|
||||
|
||||
if(compressed == 2)
|
||||
{
|
||||
ptcache_file_write(pf, &sizeOfIt, 1, sizeof(unsigned int));
|
||||
ptcache_file_write(pf, props, sizeOfIt, sizeof(unsigned char));
|
||||
}
|
||||
|
||||
MEM_freeN(props);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v)
|
||||
{
|
||||
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
|
||||
SmokeDomainSettings *sds = smd->domain;
|
||||
|
||||
if(sds->fluid)
|
||||
{
|
||||
if(sds->fluid) {
|
||||
size_t res = sds->res[0]*sds->res[1]*sds->res[2];
|
||||
float *dens, *densold, *heat, *heatold, *vx, *vy, *vz;
|
||||
|
||||
smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz);
|
||||
|
||||
ptcache_file_write(pf, dens, res, sizeof(float));
|
||||
ptcache_file_write(pf, densold, res, sizeof(float));
|
||||
ptcache_file_write(pf, heat, res, sizeof(float));
|
||||
ptcache_file_write(pf, heatold, res, sizeof(float));
|
||||
ptcache_file_write(pf, vx, res, sizeof(float));
|
||||
ptcache_file_write(pf, vy, res, sizeof(float));
|
||||
ptcache_file_write(pf, vz, res, sizeof(float));
|
||||
float dt, dx, *dens, *densold, *heat, *heatold, *vx, *vy, *vz, *vxold, *vyold, *vzold;
|
||||
unsigned char *obstacles;
|
||||
unsigned int in_len = sizeof(float)*(unsigned int)res;
|
||||
unsigned char *out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len)*4, "pointcache_lzo_buffer");
|
||||
int mode = res >= 1000000 ? 2 : 1;
|
||||
|
||||
smoke_export(sds->fluid, &dt, &dx, &dens, &densold, &heat, &heatold, &vx, &vy, &vz, &vxold, &vyold, &vzold, &obstacles);
|
||||
|
||||
ptcache_compress_write(pf, (unsigned char *)sds->view3d, in_len*4, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)dens, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)densold, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)heat, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)heatold, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)vx, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)vy, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)vz, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)vxold, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)vyold, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)vzold, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)obstacles, (unsigned int)res, out, mode);
|
||||
ptcache_file_write(pf, &dt, 1, sizeof(float));
|
||||
ptcache_file_write(pf, &dx, 1, sizeof(float));
|
||||
|
||||
MEM_freeN(out);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -513,32 +591,134 @@ static int ptcache_write_smoke(PTCacheFile *pf, void *smoke_v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ptcache_write_smoke_turbulence(PTCacheFile *pf, void *smoke_v)
|
||||
{
|
||||
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
|
||||
SmokeDomainSettings *sds = smd->domain;
|
||||
/*
|
||||
if(sds->wt) {
|
||||
unsigned int res_big[3];
|
||||
size_t res = sds->res[0]*sds->res[1]*sds->res[2];
|
||||
float *dens, *densold, *tcu, *tcv, *tcw;
|
||||
unsigned int in_len = sizeof(float)*(unsigned int)res;
|
||||
unsigned int in_len_big = sizeof(float) * (unsigned int)res_big;
|
||||
unsigned char *out;
|
||||
int mode;
|
||||
|
||||
smoke_turbulence_get_res(sds->wt, res_big);
|
||||
mode = res_big[0]*res_big[1]*res_big[2] >= 1000000 ? 2 : 1;
|
||||
|
||||
smoke_turbulence_export(sds->wt, &dens, &densold, &tcu, &tcv, &tcw);
|
||||
|
||||
out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len_big), "pointcache_lzo_buffer");
|
||||
|
||||
ptcache_compress_write(pf, (unsigned char *)dens, in_len_big, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)densold, in_len_big, out, mode);
|
||||
|
||||
MEM_freeN(out);
|
||||
out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len), "pointcache_lzo_buffer");
|
||||
ptcache_compress_write(pf, (unsigned char *)tcu, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)tcv, in_len, out, mode);
|
||||
ptcache_compress_write(pf, (unsigned char *)tcw, in_len, out, mode);
|
||||
MEM_freeN(out);
|
||||
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
// forward decleration
|
||||
static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size);
|
||||
|
||||
static int ptcache_compress_read(PTCacheFile *pf, unsigned char *result, unsigned int len)
|
||||
{
|
||||
int r;
|
||||
unsigned char compressed = 0;
|
||||
unsigned int in_len;
|
||||
unsigned int out_len = len;
|
||||
unsigned char *in;
|
||||
unsigned char *props = MEM_callocN(16*sizeof(char), "tmp");
|
||||
size_t sizeOfIt = 5;
|
||||
|
||||
ptcache_file_read(pf, &compressed, 1, sizeof(unsigned char));
|
||||
if(compressed) {
|
||||
ptcache_file_read(pf, &in_len, 1, sizeof(unsigned int));
|
||||
in = (unsigned char *)MEM_callocN(sizeof(unsigned char)*in_len, "pointcache_compressed_buffer");
|
||||
ptcache_file_read(pf, in, in_len, sizeof(unsigned char));
|
||||
|
||||
if(compressed == 1)
|
||||
r = lzo1x_decompress(in, (lzo_uint)in_len, result, (lzo_uint *)&out_len, NULL);
|
||||
else if(compressed == 2)
|
||||
{
|
||||
size_t leni = in_len, leno = out_len;
|
||||
ptcache_file_read(pf, &sizeOfIt, 1, sizeof(unsigned int));
|
||||
ptcache_file_read(pf, props, sizeOfIt, sizeof(unsigned char));
|
||||
r = LzmaUncompress(result, &leno, in, &leni, props, sizeOfIt);
|
||||
}
|
||||
|
||||
MEM_freeN(in);
|
||||
}
|
||||
else {
|
||||
ptcache_file_read(pf, result, len, sizeof(unsigned char));
|
||||
}
|
||||
|
||||
MEM_freeN(props);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void ptcache_read_smoke(PTCacheFile *pf, void *smoke_v)
|
||||
{
|
||||
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
|
||||
SmokeDomainSettings *sds = smd->domain;
|
||||
|
||||
if(sds->fluid)
|
||||
{
|
||||
if(sds->fluid) {
|
||||
size_t res = sds->res[0]*sds->res[1]*sds->res[2];
|
||||
float *dens, *densold, *heat, *heatold, *vx, *vy, *vz;
|
||||
float dt, dx, *dens, *densold, *heat, *heatold, *vx, *vy, *vz, *vxold, *vyold, *vzold;
|
||||
unsigned char *obstacles;
|
||||
unsigned int out_len = (unsigned int)res * sizeof(float);
|
||||
|
||||
smoke_export(sds->fluid, &dens, &densold, &heat, &heatold, &vx, &vy, &vz);
|
||||
smoke_export(sds->fluid, &dt, &dx, &dens, &densold, &heat, &heatold, &vx, &vy, &vz, &vxold, &vyold, &vzold, &obstacles);
|
||||
|
||||
ptcache_file_read(pf, dens, res, sizeof(float));
|
||||
ptcache_file_read(pf, densold, res, sizeof(float));
|
||||
ptcache_file_read(pf, heat, res, sizeof(float));
|
||||
ptcache_file_read(pf, heatold, res, sizeof(float));
|
||||
ptcache_file_read(pf, vx, res, sizeof(float));
|
||||
ptcache_file_read(pf, vy, res, sizeof(float));
|
||||
ptcache_file_read(pf, vz, res, sizeof(float));
|
||||
|
||||
ptcache_compress_read(pf, (unsigned char *)sds->view3d, out_len*4);
|
||||
ptcache_compress_read(pf, (unsigned char*)dens, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)densold, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)heat, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)heatold, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)vx, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)vy, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)vz, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)vxold, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)vyold, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)vzold, out_len);
|
||||
ptcache_compress_read(pf, (unsigned char*)obstacles, (unsigned int)res);
|
||||
ptcache_file_read(pf, &dt, 1, sizeof(float));
|
||||
ptcache_file_read(pf, &dx, 1, sizeof(float));
|
||||
}
|
||||
}
|
||||
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd, int num)
|
||||
|
||||
static void ptcache_read_smoke_turbulence(PTCacheFile *pf, void *smoke_v)
|
||||
{
|
||||
SmokeModifierData *smd= (SmokeModifierData *)smoke_v;
|
||||
SmokeDomainSettings *sds = smd->domain;
|
||||
/*
|
||||
if(sds->fluid) {
|
||||
unsigned int res[3];
|
||||
float *dens, *densold, *tcu, *tcv, *tcw;
|
||||
unsigned int out_len = sizeof(float)*(unsigned int)res;
|
||||
|
||||
smoke_turbulence_get_res(sds->wt, res);
|
||||
|
||||
smoke_turbulence_export(sds->wt, &dens, &densold, &tcu, &tcv, &tcw);
|
||||
|
||||
ptcache_compress_read(pf, (unsigned char*)dens, out_len);
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd)
|
||||
{
|
||||
SmokeDomainSettings *sds = smd->domain;
|
||||
|
||||
@@ -547,24 +727,21 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo
|
||||
pid->ob= ob;
|
||||
pid->calldata= smd;
|
||||
|
||||
// if(num == 0)
|
||||
pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_LOW;
|
||||
// else if(num == 1)
|
||||
// pid->type= PTCACHE_TYPE_SMOKE_DOMAIN_HIGH;
|
||||
|
||||
pid->type= PTCACHE_TYPE_SMOKE_DOMAIN;
|
||||
pid->stack_index= modifiers_indexInObject(ob, (ModifierData *)smd);
|
||||
|
||||
pid->cache= sds->point_cache;
|
||||
pid->cache_ptr= &sds->point_cache;
|
||||
pid->ptcaches= &sds->ptcaches;
|
||||
|
||||
|
||||
pid->totpoint= pid->totwrite= ptcache_totpoint_smoke;
|
||||
|
||||
pid->write_elem= NULL;
|
||||
pid->read_elem= NULL;
|
||||
|
||||
pid->read_stream = ptcache_read_smoke;
|
||||
pid->write_stream = ptcache_write_smoke;
|
||||
|
||||
pid->interpolate_elem= NULL;
|
||||
|
||||
pid->write_header= ptcache_write_basic_header;
|
||||
@@ -573,7 +750,6 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo
|
||||
pid->data_types= (1<<BPHYS_DATA_LOCATION); // bogus values tot make pointcache happy
|
||||
pid->info_types= 0;
|
||||
}
|
||||
#endif // XXX smoke poitcache stuff breaks compiling
|
||||
|
||||
void BKE_ptcache_id_from_cloth(PTCacheID *pid, Object *ob, ClothModifierData *clmd)
|
||||
{
|
||||
@@ -633,18 +809,15 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob)
|
||||
BKE_ptcache_id_from_cloth(pid, ob, (ClothModifierData*)md);
|
||||
BLI_addtail(lb, pid);
|
||||
}
|
||||
/*
|
||||
// enabled on next commit
|
||||
if(md->type == eModifierType_Smoke) {
|
||||
SmokeModifierData *smd = (SmokeModifierData *)md;
|
||||
if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
|
||||
{
|
||||
pid= MEM_callocN(sizeof(PTCacheID), "PTCacheID");
|
||||
BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md, 0);
|
||||
BKE_ptcache_id_from_smoke(pid, ob, (SmokeModifierData*)md);
|
||||
BLI_addtail(lb, pid);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1140,13 +1313,13 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
|
||||
if(use_old) {
|
||||
if(pid->read_elem && ptcache_file_read(pf, (void*)old_data1, 1, old_elemsize))
|
||||
pid->read_elem(i, pid->calldata, NULL, frs_sec, cfra, old_data1);
|
||||
else
|
||||
else if(pid->read_elem)
|
||||
{ error = 1; break; }
|
||||
}
|
||||
else {
|
||||
if(pid->read_elem && (pm || ptcache_file_read_data(pf)))
|
||||
pid->read_elem(*index, pid->calldata, pm ? pm->cur : pf->cur, frs_sec, cfra1 ? (float)cfra1 : (float)cfrai, NULL);
|
||||
else
|
||||
else if(pid->read_elem)
|
||||
{ error = 1; break; }
|
||||
}
|
||||
|
||||
@@ -1185,7 +1358,7 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
|
||||
else
|
||||
{ error = 1; break; }
|
||||
}
|
||||
else
|
||||
else if(pid->read_elem)
|
||||
{ error = 1; break; }
|
||||
}
|
||||
else {
|
||||
@@ -1197,7 +1370,7 @@ int BKE_ptcache_read_cache(PTCacheID *pid, float cfra, float frs_sec)
|
||||
else
|
||||
{ error = 1; break; }
|
||||
}
|
||||
else
|
||||
else if(pid->read_elem)
|
||||
{ error = 1; break; }
|
||||
}
|
||||
|
||||
@@ -1639,8 +1812,11 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode)
|
||||
sbFreeSimulation(pid->calldata);
|
||||
else if(pid->type == PTCACHE_TYPE_PARTICLES)
|
||||
psys_reset(pid->calldata, PSYS_RESET_DEPSGRAPH);
|
||||
else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN_LOW)
|
||||
else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN)
|
||||
{
|
||||
smokeModifier_reset(pid->calldata);
|
||||
printf("reset PTCACHE_TYPE_SMOKE_DOMAIN\n");
|
||||
}
|
||||
}
|
||||
if(clear)
|
||||
BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
|
||||
@@ -1689,17 +1865,14 @@ int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
|
||||
BKE_ptcache_id_from_cloth(&pid, ob, (ClothModifierData*)md);
|
||||
reset |= BKE_ptcache_id_reset(scene, &pid, mode);
|
||||
}
|
||||
/*
|
||||
// enabled on next commit
|
||||
if(md->type == eModifierType_Smoke) {
|
||||
SmokeModifierData *smd = (SmokeModifierData *)md;
|
||||
if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
|
||||
{
|
||||
BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md, 0);
|
||||
BKE_ptcache_id_from_smoke(&pid, ob, (SmokeModifierData*)md);
|
||||
reset |= BKE_ptcache_id_reset(scene, &pid, mode);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return reset;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* smokehighres.c
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): Daniel Genrich
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* Part of the code copied from elbeem fluid library, copyright by Nils Thuerey */
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_listBase.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_smoke_types.h"
|
||||
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_smoke.h"
|
||||
#include "BKE_pointcache.h"
|
||||
|
||||
#include "smoke_API.h"
|
||||
|
||||
// we need different handling for the high-res feature
|
||||
/*
|
||||
if(bigdensity)
|
||||
{
|
||||
// init all surrounding cells according to amplification, too
|
||||
int i, j, k;
|
||||
|
||||
smoke_turbulence_get_res(smd->domain->wt, bigres);
|
||||
|
||||
for(i = 0; i < smd->domain->amplify + 1; i++)
|
||||
for(j = 0; j < smd->domain->amplify + 1; j++)
|
||||
for(k = 0; k < smd->domain->amplify + 1; k++)
|
||||
{
|
||||
index = smoke_get_index((smd->domain->amplify + 1)* cell[0] + i, bigres[0], (smd->domain->amplify + 1)* cell[1] + j, bigres[1], (smd->domain->amplify + 1)* cell[2] + k);
|
||||
bigdensity[index] = sfs->density;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
static void smokeHRinit(SmokeHRModifierData *shrmd, SmokeDomainSettings *sds)
|
||||
{
|
||||
if(!shrmd->wt)
|
||||
{
|
||||
shrmd->wt = smoke_turbulence_init(sds->res, shrmd->amplify + 1, shrmd->noise);
|
||||
smoke_turbulence_initBlenderRNA(shrmd->wt, &shrmd->strength);
|
||||
}
|
||||
}
|
||||
|
||||
void smokeHRModifier_free(SmokeHRModifierData *shrmd)
|
||||
{
|
||||
if(shrmd->wt)
|
||||
smoke_turbulence_free(shrmd->wt);
|
||||
|
||||
BKE_ptcache_free_list(&shrmd->ptcaches);
|
||||
shrmd->point_cache = NULL;
|
||||
}
|
||||
|
||||
void smokeHRModifier_do(SmokeHRModifierData *shrmd, Scene *scene, Object *ob, int useRenderParams, int isFinalCalc)
|
||||
{
|
||||
ModifierData *md = NULL;
|
||||
SmokeModifierData *smd = NULL;
|
||||
SmokeDomainSettings *sds = NULL;
|
||||
|
||||
// find underlaying smoke domain
|
||||
smd = (SmokeModifierData *)modifiers_findByType(ob, eModifierType_Smoke);
|
||||
if(!(smd && smd->type == MOD_SMOKE_TYPE_DOMAIN))
|
||||
return;
|
||||
|
||||
sds = smd->domain;
|
||||
|
||||
smokeHRinit(shrmd, sds);
|
||||
|
||||
// smoke_turbulence_dissolve(shrmd->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
|
||||
|
||||
// smoke_turbulence_step(shrmd->wt, sds->fluid);
|
||||
}
|
||||
|
||||
|
||||
// update necessary information for 3dview ("high res" option)
|
||||
void smoke_prepare_bigView(SmokeHRModifierData *shrmd, float *light)
|
||||
{
|
||||
float *density = NULL;
|
||||
size_t i = 0;
|
||||
int bigres[3];
|
||||
/*
|
||||
smoke_turbulence_get_res(shrmd->wt, bigres);
|
||||
|
||||
if(!smd->domain->traybig)
|
||||
{
|
||||
// TRay is for self shadowing
|
||||
smd->domain->traybig = MEM_callocN(sizeof(float)*bigres[0]*bigres[1]*bigres[2], "Smoke_tRayBig");
|
||||
}
|
||||
if(!smd->domain->tvoxbig)
|
||||
{
|
||||
// TVox is for tranaparency
|
||||
smd->domain->tvoxbig = MEM_callocN(sizeof(float)*bigres[0]*bigres[1]*bigres[2], "Smoke_tVoxBig");
|
||||
}
|
||||
|
||||
density = smoke_turbulence_get_density(smd->domain->wt);
|
||||
for (i = 0; i < bigres[0] * bigres[1] * bigres[2]; i++)
|
||||
{
|
||||
// Transparency computation
|
||||
// formula taken from "Visual Simulation of Smoke" / Fedkiw et al. pg. 4
|
||||
// T_vox = exp(-C_ext * h)
|
||||
// C_ext/sigma_t = density * C_ext
|
||||
smoke_set_bigtvox(smd, i, exp(-density[i] * 7.0 * smd->domain->dx / (smd->domain->amplify + 1)) );
|
||||
}
|
||||
smoke_calc_transparency(smd, light, 1);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -65,20 +65,22 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
#ifndef M_PI_2
|
||||
#define M_PI_2 1.57079632679489661923
|
||||
#endif
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.41421356237309504880
|
||||
#endif
|
||||
#ifndef M_SQRT1_2
|
||||
#define M_SQRT1_2 0.70710678118654752440
|
||||
#endif
|
||||
#ifndef M_1_PI
|
||||
#define M_1_PI 0.318309886183790671538
|
||||
# ifndef _WIN64
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
#ifndef M_PI_2
|
||||
#define M_PI_2 1.57079632679489661923
|
||||
#endif
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.41421356237309504880
|
||||
#endif
|
||||
#ifndef M_SQRT1_2
|
||||
#define M_SQRT1_2 0.70710678118654752440
|
||||
#endif
|
||||
#ifndef M_1_PI
|
||||
#define M_1_PI 0.318309886183790671538
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MAXPATHLEN MAX_PATH
|
||||
|
||||
@@ -3669,8 +3669,6 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
|
||||
else if (md->type==eModifierType_Smoke) {
|
||||
SmokeModifierData *smd = (SmokeModifierData*) md;
|
||||
|
||||
smd->point_cache = NULL;
|
||||
|
||||
if(smd->type==MOD_SMOKE_TYPE_DOMAIN)
|
||||
{
|
||||
smd->flow = NULL;
|
||||
@@ -3679,23 +3677,10 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
|
||||
smd->domain->smd = smd;
|
||||
|
||||
smd->domain->fluid = NULL;
|
||||
smd->domain->wt = NULL;
|
||||
smd->domain->tvox = NULL;
|
||||
smd->domain->tray = NULL;
|
||||
smd->domain->tvoxbig = NULL;
|
||||
smd->domain->traybig = NULL;
|
||||
smd->domain->bind = NULL;
|
||||
smd->domain->max_textures= 0;
|
||||
smd->domain->view3d = NULL;
|
||||
smd->domain->tex = NULL;
|
||||
|
||||
// do_versions trick
|
||||
if(smd->domain->strength < 1.0)
|
||||
smd->domain->strength = 2.0;
|
||||
|
||||
// reset 3dview
|
||||
if(smd->domain->viewsettings < MOD_SMOKE_VIEW_USEBIG)
|
||||
smd->domain->viewsettings = 0;
|
||||
else
|
||||
smd->domain->viewsettings = MOD_SMOKE_VIEW_USEBIG;
|
||||
direct_link_pointcache_list(fd, &smd->domain->ptcaches, &smd->domain->point_cache);
|
||||
}
|
||||
else if(smd->type==MOD_SMOKE_TYPE_FLOW)
|
||||
{
|
||||
|
||||
@@ -1126,14 +1126,17 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
|
||||
else if(md->type==eModifierType_Smoke) {
|
||||
SmokeModifierData *smd = (SmokeModifierData*) md;
|
||||
|
||||
if(smd->type==MOD_SMOKE_TYPE_DOMAIN)
|
||||
if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
|
||||
writestruct(wd, DATA, "SmokeDomainSettings", 1, smd->domain);
|
||||
else if(smd->type==MOD_SMOKE_TYPE_FLOW)
|
||||
else if(smd->type & MOD_SMOKE_TYPE_FLOW)
|
||||
writestruct(wd, DATA, "SmokeFlowSettings", 1, smd->flow);
|
||||
/*
|
||||
else if(smd->type==MOD_SMOKE_TYPE_COLL)
|
||||
else if(smd->type & MOD_SMOKE_TYPE_COLL)
|
||||
writestruct(wd, DATA, "SmokeCollSettings", 1, smd->coll);
|
||||
*/
|
||||
|
||||
if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
|
||||
write_pointcaches(wd, &smd->domain->ptcaches);
|
||||
}
|
||||
else if(md->type==eModifierType_Fluidsim) {
|
||||
FluidsimModifierData *fluidmd = (FluidsimModifierData*) md;
|
||||
|
||||
@@ -161,6 +161,13 @@ int ED_object_modifier_remove(ReportList *reports, Scene *scene, Object *ob, Mod
|
||||
|
||||
DAG_scene_sort(scene);
|
||||
}
|
||||
else if(md->type == eModifierType_Smoke) {
|
||||
ModifierData *tmd = modifiers_findByType(ob, eModifierType_SmokeHR);
|
||||
if(tmd) {
|
||||
BLI_remlink(&ob->modifiers, tmd);
|
||||
modifier_free(tmd);
|
||||
}
|
||||
}
|
||||
|
||||
BLI_remlink(&ob->modifiers, md);
|
||||
modifier_free(md);
|
||||
|
||||
@@ -553,7 +553,7 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
|
||||
"world", "object", "mesh", "armature", "lattice", "curve",
|
||||
"meta_ball", "lamp", "camera", "material", "material_slot",
|
||||
"texture", "texture_slot", "bone", "edit_bone", "particle_system",
|
||||
"cloth", "soft_body", "fluid", "smoke", "collision", "brush", NULL};
|
||||
"cloth", "soft_body", "fluid", "smoke", "smoke_hr", "collision", "brush", NULL};
|
||||
|
||||
CTX_data_dir_set(result, dir);
|
||||
return 1;
|
||||
@@ -697,6 +697,16 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(CTX_data_equals(member, "smoke_hr")) {
|
||||
PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
|
||||
|
||||
if(ptr && ptr->data) {
|
||||
Object *ob= ptr->data;
|
||||
ModifierData *md= modifiers_findByType(ob, eModifierType_SmokeHR);
|
||||
CTX_data_pointer_set(result, &ob->id, &RNA_SmokeHRModifier, md);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(CTX_data_equals(member, "collision")) {
|
||||
PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
|
||||
|
||||
|
||||
@@ -5309,356 +5309,20 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
|
||||
}
|
||||
|
||||
/* draw code for smoke */
|
||||
if((md = modifiers_findByType(ob, eModifierType_Smoke)))
|
||||
{
|
||||
SmokeModifierData *smd = (SmokeModifierData *)md;
|
||||
|
||||
// draw collision objects
|
||||
if((smd->type & MOD_SMOKE_TYPE_COLL) && smd->coll)
|
||||
{
|
||||
/*SmokeCollSettings *scs = smd->coll;
|
||||
if(scs->points)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
wmLoadMatrix(rv3d->viewmat);
|
||||
|
||||
if(col || (ob->flag & SELECT)) cpack(0xFFFFFF);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
|
||||
// glPointSize(3.0);
|
||||
bglBegin(GL_POINTS);
|
||||
|
||||
for(i = 0; i < scs->numpoints; i++)
|
||||
{
|
||||
bglVertex3fv(&scs->points[3*i]);
|
||||
}
|
||||
|
||||
bglEnd();
|
||||
glPointSize(1.0);
|
||||
|
||||
wmMultMatrix(ob->obmat);
|
||||
glDisable(GL_BLEND);
|
||||
glDepthMask(GL_TRUE);
|
||||
if(col) cpack(col);
|
||||
|
||||
if(((SmokeHRModifierData *)(md = modifiers_findByType(ob, eModifierType_SmokeHR)) && (((SmokeHRModifierData *)md)->flags & MOD_SMOKE_SHOWHIGHRES))) {
|
||||
// GPU_create_smoke(smd);
|
||||
// draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->res);
|
||||
// GPU_free_smoke(smd);
|
||||
}
|
||||
else {
|
||||
md = modifiers_findByType(ob, eModifierType_Smoke);
|
||||
if (md) {
|
||||
SmokeModifierData *smd = (SmokeModifierData *)md;
|
||||
if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
|
||||
GPU_create_smoke(smd);
|
||||
draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->res);
|
||||
GPU_free_smoke(smd);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// only draw domains
|
||||
if(smd->domain && smd->domain->fluid)
|
||||
{
|
||||
int x, y, z, i;
|
||||
float viewnormal[3];
|
||||
int mainaxis[3] = {0,0,0};
|
||||
float align = 0, signed_align = 0;
|
||||
int max_textures = 0, counter_textures = 0;
|
||||
float *buffer = NULL;
|
||||
int res[3];
|
||||
float bigfactor = 1.0;
|
||||
int big = (smd->domain->flags & MOD_SMOKE_HIGHRES) && (smd->domain->viewsettings & MOD_SMOKE_VIEW_USEBIG);
|
||||
int new = 0;
|
||||
int have_lamp = 0;
|
||||
|
||||
// GUI sent redraw event
|
||||
if(smd->domain->flags & MOD_SMOKE_VIEW_REDRAWNICE)
|
||||
{
|
||||
new = 1;
|
||||
smd->domain->flags &= ~MOD_SMOKE_VIEW_REDRAWNICE;
|
||||
}
|
||||
|
||||
if(!big)
|
||||
{
|
||||
res[0] = smd->domain->res[0];
|
||||
res[1] = smd->domain->res[1];
|
||||
res[2] = smd->domain->res[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
smoke_turbulence_get_res(smd->domain->wt, res);
|
||||
bigfactor = 1.0 / (smd->domain->amplify + 1);
|
||||
}
|
||||
|
||||
wmLoadMatrix(rv3d->viewmat);
|
||||
|
||||
if(col || (ob->flag & SELECT)) cpack(0xFFFFFF); /* for visibility, also while wpaint */
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
// get view vector
|
||||
VECCOPY(viewnormal, rv3d->viewinv[2]);
|
||||
Normalize(viewnormal);
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
if(ABS(viewnormal[i]) > align)
|
||||
{
|
||||
mainaxis[0] = i;
|
||||
align = ABS(viewnormal[i]);
|
||||
signed_align = viewnormal[i];
|
||||
}
|
||||
}
|
||||
mainaxis[1] = (mainaxis[0] + 1) % 3;
|
||||
mainaxis[2] = (mainaxis[0] + 2) % 3;
|
||||
|
||||
if(!smd->domain->bind)
|
||||
{
|
||||
smd->domain->bind = MEM_callocN(sizeof(GLuint)*256, "Smoke_bind");
|
||||
if(big)
|
||||
smd->domain->viewsettings |= MOD_SMOKE_VIEW_CHANGETOBIG;
|
||||
new = 3;
|
||||
}
|
||||
|
||||
// check if view axis / mode has been changed
|
||||
if(smd->domain->viewsettings)
|
||||
{
|
||||
if(big)
|
||||
{
|
||||
if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_BIG))
|
||||
new = 2;
|
||||
else if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_CHANGETOBIG))
|
||||
new = 1;
|
||||
|
||||
smd->domain->viewsettings |= MOD_SMOKE_VIEW_CHANGETOBIG;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_SMALL))
|
||||
new = 2;
|
||||
else if(smd->domain->viewsettings & MOD_SMOKE_VIEW_CHANGETOBIG)
|
||||
new = 1;
|
||||
|
||||
smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_CHANGETOBIG;
|
||||
}
|
||||
|
||||
if(!new)
|
||||
{
|
||||
if((mainaxis[0] == 0) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_X))
|
||||
new = 1;
|
||||
else if((mainaxis[0] == 1) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_Y))
|
||||
new = 1;
|
||||
else if((mainaxis[0] == 2) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_Z))
|
||||
new = 1;
|
||||
|
||||
// printf("check axis\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
new = 3;
|
||||
|
||||
if(new > 1)
|
||||
{
|
||||
float light[3] = {0.0,0.0,0.0}; // TODO: take real LAMP coordinates - dg
|
||||
Base *base_tmp = NULL;
|
||||
|
||||
for(base_tmp = scene->base.first; base_tmp; base_tmp= base_tmp->next)
|
||||
{
|
||||
if(base_tmp->object->type == OB_LAMP)
|
||||
{
|
||||
Lamp *la = (Lamp *)base_tmp->object->data;
|
||||
|
||||
if(la->type == LA_LOCAL)
|
||||
{
|
||||
VECCOPY(light, base_tmp->object->obmat[3]);
|
||||
have_lamp = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!big && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_SMALL))
|
||||
{
|
||||
smoke_prepare_View(smd, light);
|
||||
// printf("prepared View!\n");
|
||||
}
|
||||
else if(big && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_BIG))
|
||||
{
|
||||
smoke_prepare_bigView(smd, light);
|
||||
// printf("prepared bigView!\n");
|
||||
}
|
||||
}
|
||||
|
||||
// printf("big: %d, new: %d\n", big, new);
|
||||
|
||||
// only create buffer if we need to create new textures
|
||||
if(new)
|
||||
buffer = MEM_mallocN(sizeof(float)*res[mainaxis[1]]*res[mainaxis[2]]*4, "SmokeDrawBuffer");
|
||||
|
||||
if(buffer || smd->domain->viewsettings)
|
||||
{
|
||||
int mod_texture = 0;
|
||||
|
||||
// printf("if(buffer || smd->domain->viewsettings)\n");
|
||||
|
||||
max_textures = (res[mainaxis[0]] > 256) ? 256 : res[mainaxis[0]];
|
||||
|
||||
if(!smd->domain->viewsettings) // new frame or new start
|
||||
{
|
||||
smd->domain->max_textures = max_textures;
|
||||
glGenTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind);
|
||||
new = 1;
|
||||
// printf("glGenTextures\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(new)
|
||||
{
|
||||
// printf("glDeleteTextures\n");
|
||||
glDeleteTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind);
|
||||
smd->domain->max_textures = max_textures;
|
||||
glGenTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind);
|
||||
}
|
||||
}
|
||||
|
||||
mod_texture = MAX3(1, smd->domain->visibility, (int)(res[mainaxis[0]] / smd->domain->max_textures ));
|
||||
|
||||
// align order of billboards to be front or backview (e.g. +x or -x axis)
|
||||
if(signed_align < 0)
|
||||
{
|
||||
z = res[mainaxis[0]] - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
z = 0;
|
||||
}
|
||||
|
||||
for (; signed_align > 0 ? (z < res[mainaxis[0]]) : (z >= 0); signed_align > 0 ? z++ : z--) // 2
|
||||
{
|
||||
float quad[4][3];
|
||||
|
||||
if(new)
|
||||
{
|
||||
for (y = 0; y < res[mainaxis[1]]; y++) // 1
|
||||
{
|
||||
for (x = 0; x < res[mainaxis[2]]; x++) // 0
|
||||
{
|
||||
size_t index;
|
||||
size_t image_index;
|
||||
float tray, tvox;
|
||||
|
||||
image_index = smoke_get_index2d(y, res[mainaxis[1]], x);
|
||||
|
||||
if(mainaxis[0] == 0)
|
||||
{
|
||||
// mainaxis[1] == 1, mainaxis[2] == 2
|
||||
index = smoke_get_index(z, res[mainaxis[0]], y, res[mainaxis[1]], x);
|
||||
}
|
||||
else if(mainaxis[0] == 1)
|
||||
{
|
||||
// mainaxis[1] == 2, mainaxis[2] == 0
|
||||
index = smoke_get_index(x, res[mainaxis[2]], z, res[mainaxis[0]], y);
|
||||
}
|
||||
else // mainaxis[0] == 2
|
||||
{
|
||||
// mainaxis[1] == 0, mainaxis[2] == 1
|
||||
index = smoke_get_index(y, res[mainaxis[1]], x, res[mainaxis[2]], z);
|
||||
}
|
||||
|
||||
if(!big)
|
||||
{
|
||||
tvox = smoke_get_tvox(smd, index);
|
||||
tray = smoke_get_tray(smd, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
tvox = smoke_get_bigtvox(smd, index);
|
||||
tray = smoke_get_bigtray(smd, index);
|
||||
}
|
||||
|
||||
if(!have_lamp)
|
||||
tray = 1.0;
|
||||
|
||||
// fill buffer with luminance and alpha
|
||||
// 1 - T_vox
|
||||
buffer[image_index*4 + 3] = 1.0 - tvox; // 0 = transparent => d.h. tvox = 1
|
||||
|
||||
// L_vox = Omega * L_light * (1 - T_vox) * T_ray
|
||||
buffer[image_index*4] = buffer[image_index*4 + 1] = buffer[image_index*4 + 2] = smd->domain->omega * 1.0 * tvox * tray;
|
||||
}
|
||||
}
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, smd->domain->bind[counter_textures]);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
if(new)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, res[mainaxis[1]], res[mainaxis[2]], 0, GL_RGBA, GL_FLOAT, buffer);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
|
||||
}
|
||||
|
||||
if((z % mod_texture) == 0 )
|
||||
{
|
||||
// botttom left
|
||||
quad[3][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
|
||||
quad[3][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + smd->domain->dx * bigfactor * 0.5;
|
||||
quad[3][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + smd->domain->dx * bigfactor * 0.5;
|
||||
|
||||
// top right
|
||||
quad[1][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
|
||||
quad[1][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + (res[mainaxis[1]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
|
||||
quad[1][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + (res[mainaxis[2]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
|
||||
|
||||
// top left
|
||||
quad[2][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
|
||||
quad[2][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + smd->domain->dx * bigfactor * 0.5;
|
||||
quad[2][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + (res[mainaxis[2]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
|
||||
|
||||
// bottom right
|
||||
quad[0][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
|
||||
quad[0][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + (res[mainaxis[1]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
|
||||
quad[0][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + smd->domain->dx * bigfactor * 0.5;
|
||||
|
||||
glBegin(GL_QUADS); // Start Drawing Quads
|
||||
|
||||
glTexCoord2f(1.0f, 0.0f);
|
||||
glVertex3fv(quad[0]); // Left And Up 1 Unit (Top Left)
|
||||
glTexCoord2f(1.0f, 1.0f);
|
||||
glVertex3fv(quad[1]); // Right And Up 1 Unit (Top Right)
|
||||
glTexCoord2f(0.0f, 1.0f);
|
||||
glVertex3fv(quad[2]); // Right And Down One Unit (Bottom Right)
|
||||
glTexCoord2f(0.0f, 0.0f);
|
||||
glVertex3fv(quad[3]); // Left And Down One Unit (Bottom Left)
|
||||
|
||||
glEnd();
|
||||
}
|
||||
counter_textures++;
|
||||
}
|
||||
}
|
||||
if(buffer)
|
||||
{
|
||||
MEM_freeN(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
// set correct flag for viewsettings
|
||||
if(1)
|
||||
{
|
||||
// do not clear BIG/SMALL flag
|
||||
smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_X;
|
||||
smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_Y;
|
||||
smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_Z;
|
||||
|
||||
// set what caches we have
|
||||
if(big)
|
||||
smd->domain->viewsettings |= MOD_SMOKE_VIEW_BIG;
|
||||
else
|
||||
smd->domain->viewsettings |= MOD_SMOKE_VIEW_SMALL;
|
||||
|
||||
if(mainaxis[0] == 0)
|
||||
smd->domain->viewsettings |= MOD_SMOKE_VIEW_X;
|
||||
else if(mainaxis[0] == 1)
|
||||
smd->domain->viewsettings |= MOD_SMOKE_VIEW_Y;
|
||||
else if(mainaxis[0] == 2)
|
||||
smd->domain->viewsettings |= MOD_SMOKE_VIEW_Z;
|
||||
}
|
||||
|
||||
wmMultMatrix(ob->obmat);
|
||||
glDisable(GL_BLEND);
|
||||
glDepthMask(GL_TRUE);
|
||||
if(col) cpack(col);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Daniel Genrich
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "IMB_imbuf.h"
|
||||
|
||||
|
||||
#include "MTC_matrixops.h"
|
||||
|
||||
#include "DNA_armature_types.h"
|
||||
#include "DNA_boid_types.h"
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_constraint_types.h" // for drawing constraint
|
||||
#include "DNA_effect_types.h"
|
||||
#include "DNA_lamp_types.h"
|
||||
#include "DNA_lattice_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_meta_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_object_force.h"
|
||||
#include "DNA_object_fluidsim.h"
|
||||
#include "DNA_particle_types.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_smoke_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_arithb.h"
|
||||
#include "BLI_editVert.h"
|
||||
#include "BLI_edgehash.h"
|
||||
#include "BLI_rand.h"
|
||||
|
||||
#include "BKE_anim.h" //for the where_on_path function
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_constraint.h" // for the get_constraint_target function
|
||||
#include "BKE_DerivedMesh.h"
|
||||
#include "BKE_deform.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_font.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_key.h"
|
||||
#include "BKE_lattice.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_mball.h"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_paint.h"
|
||||
#include "BKE_particle.h"
|
||||
#include "BKE_property.h"
|
||||
#include "BKE_smoke.h"
|
||||
#include "BKE_unit.h"
|
||||
#include "BKE_utildefines.h"
|
||||
#include "smoke_API.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
#include "GPU_draw.h"
|
||||
#include "GPU_material.h"
|
||||
#include "GPU_extensions.h"
|
||||
|
||||
#include "ED_mesh.h"
|
||||
#include "ED_particle.h"
|
||||
#include "ED_screen.h"
|
||||
#include "ED_types.h"
|
||||
#include "ED_util.h"
|
||||
|
||||
#include "UI_resources.h"
|
||||
#include "UI_interface_icons.h"
|
||||
|
||||
#include "WM_api.h"
|
||||
#include "BLF_api.h"
|
||||
|
||||
#include "GPU_extensions.h"
|
||||
|
||||
#include "view3d_intern.h" // own include
|
||||
|
||||
struct GPUTexture;
|
||||
|
||||
/* draw slices of smoke is adapted from c++ code authored by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */
|
||||
static float cv[][3] = {
|
||||
{1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f},
|
||||
{1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}
|
||||
};
|
||||
|
||||
// edges have the form edges[n][0][xyz] + t*edges[n][1][xyz]
|
||||
static float edges[12][2][3] = {
|
||||
{{1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}},
|
||||
{{-1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}},
|
||||
{{-1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}},
|
||||
{{1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}},
|
||||
|
||||
{{1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}},
|
||||
{{-1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}},
|
||||
{{-1.0f, -1.0f, -1.0f}, {0.0f, 1.0f, 0.0f}},
|
||||
{{1.0f, -1.0f, -1.0f}, {0.0f, 1.0f, 0.0f}},
|
||||
|
||||
{{-1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}},
|
||||
{{-1.0f, -1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}},
|
||||
{{-1.0f, -1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}},
|
||||
{{-1.0f, 1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}}
|
||||
};
|
||||
|
||||
int intersect_edges(float *points, float a, float b, float c, float d)
|
||||
{
|
||||
int i;
|
||||
float t;
|
||||
int numpoints = 0;
|
||||
|
||||
for (i=0; i<12; i++) {
|
||||
t = -(a*edges[i][0][0] + b*edges[i][0][1] + c*edges[i][0][2] + d)
|
||||
/ (a*edges[i][1][0] + b*edges[i][1][1] + c*edges[i][1][2]);
|
||||
if ((t>0)&&(t<2)) {
|
||||
points[numpoints * 3 + 0] = edges[i][0][0] + edges[i][1][0]*t;
|
||||
points[numpoints * 3 + 1] = edges[i][0][1] + edges[i][1][1]*t;
|
||||
points[numpoints * 3 + 2] = edges[i][0][2] + edges[i][1][2]*t;
|
||||
numpoints++;
|
||||
}
|
||||
}
|
||||
return numpoints;
|
||||
}
|
||||
|
||||
static int convex(float *p0, float *up, float *a, float *b)
|
||||
{
|
||||
// Vec3 va = a-p0, vb = b-p0;
|
||||
float va[3], vb[3], tmp[3];
|
||||
VECSUB(va, a, p0);
|
||||
VECSUB(vb, b, p0);
|
||||
Crossf(tmp, va, vb);
|
||||
return INPR(up, tmp) >= 0;
|
||||
}
|
||||
|
||||
// copied from gpu_extension.c
|
||||
static int is_pow2(int n)
|
||||
{
|
||||
return ((n)&(n-1))==0;
|
||||
}
|
||||
|
||||
static int larger_pow2(int n)
|
||||
{
|
||||
if (is_pow2(n))
|
||||
return n;
|
||||
|
||||
while(!is_pow2(n))
|
||||
n= n&(n-1);
|
||||
|
||||
return n*2;
|
||||
}
|
||||
|
||||
void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture *tex, int res[3])
|
||||
{
|
||||
Object *ob = base->object;
|
||||
RegionView3D *rv3d= ar->regiondata;
|
||||
|
||||
float viewnormal[3];
|
||||
// int res[3];
|
||||
int i, j, n;
|
||||
float d, d0, dd;
|
||||
float *points = NULL;
|
||||
int numpoints = 0;
|
||||
float cor[3] = {1.,1.,1.};
|
||||
|
||||
/*
|
||||
res[0] = smd->domain->res[0];
|
||||
res[1] = smd->domain->res[1];
|
||||
res[2] = smd->domain->res[2];
|
||||
*/
|
||||
|
||||
wmLoadMatrix(rv3d->viewmat);
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_TEXTURE_3D);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// get view vector
|
||||
VECCOPY(viewnormal, rv3d->viewinv[2]);
|
||||
Normalize(viewnormal);
|
||||
|
||||
// find cube vertex that is closest to the viewer
|
||||
for (i=0; i<8; i++) {
|
||||
float x,y,z;
|
||||
|
||||
x = cv[i][0] + viewnormal[0];
|
||||
y = cv[i][1] + viewnormal[1];
|
||||
z = cv[i][2] + viewnormal[2];
|
||||
|
||||
if ((x>=-1.0f)&&(x<=1.0f)
|
||||
&&(y>=-1.0f)&&(y<=1.0f)
|
||||
&&(z>=-1.0f)&&(z<=1.0f)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GPU_texture_bind(tex, 0);
|
||||
|
||||
cor[0] = (float)res[0]/(float)larger_pow2(res[0]);
|
||||
cor[1] = (float)res[1]/(float)larger_pow2(res[1]);
|
||||
cor[2] = (float)res[2]/(float)larger_pow2(res[2]);
|
||||
|
||||
// our slices are defined by the plane equation a*x + b*y +c*z + d = 0
|
||||
// (a,b,c), the plane normal, are given by viewdir
|
||||
// d is the parameter along the view direction. the first d is given by
|
||||
// inserting previously found vertex into the plane equation
|
||||
d0 = -(viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]);
|
||||
dd = 2.0*d0/64.0f;
|
||||
n = 0;
|
||||
|
||||
// printf("d0: %f, dd: %f\n", d0, dd);
|
||||
|
||||
points = MEM_callocN(sizeof(float)*12*3, "smoke_points_preview");
|
||||
|
||||
for (d = d0; d > -d0; d -= dd) {
|
||||
float p0[3];
|
||||
// intersect_edges returns the intersection points of all cube edges with
|
||||
// the given plane that lie within the cube
|
||||
numpoints = intersect_edges(points, viewnormal[0], viewnormal[1], viewnormal[2], d);
|
||||
|
||||
if (numpoints > 2) {
|
||||
VECCOPY(p0, points);
|
||||
|
||||
// sort points to get a convex polygon
|
||||
for(i = 1; i < numpoints - 1; i++)
|
||||
{
|
||||
for(j = i + 1; j < numpoints; j++)
|
||||
{
|
||||
if(convex(p0, viewnormal, &points[j * 3], &points[i * 3]))
|
||||
{
|
||||
float tmp2[3];
|
||||
VECCOPY(tmp2, &points[i * 3]);
|
||||
VECCOPY(&points[i * 3], &points[j * 3]);
|
||||
VECCOPY(&points[j * 3], tmp2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glBegin(GL_POLYGON);
|
||||
for (i = 0; i < numpoints; i++) {
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glTexCoord3d((points[i * 3 + 0] + 1.0)*cor[0]/2.0, (points[i * 3 + 1] + 1)*cor[1]/2.0, (points[i * 3 + 2] + 1.0)*cor[2]/2.0);
|
||||
glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
MEM_freeN(points);
|
||||
|
||||
wmMultMatrix(ob->obmat);
|
||||
|
||||
glDisable(GL_TEXTURE_3D);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
@@ -156,6 +156,9 @@ void VIEW3D_OT_snap_menu(struct wmOperatorType *ot);
|
||||
ARegion *view3d_has_buttons_region(ScrArea *sa);
|
||||
ARegion *view3d_has_tools_region(ScrArea *sa);
|
||||
|
||||
/* draw_volume.c */
|
||||
void draw_volume(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct Base *base, struct GPUTexture *tex, int res[3]);
|
||||
|
||||
|
||||
#endif /* ED_VIEW3D_INTERN_H */
|
||||
|
||||
|
||||
@@ -112,6 +112,10 @@ int GPU_verify_image(struct Image *ima, int tftile, int tfmode, int compare, int
|
||||
void GPU_free_image(struct Image *ima);
|
||||
void GPU_free_images(void);
|
||||
|
||||
/* smoke drawing functions */
|
||||
void GPU_free_smoke(struct SmokeModifierData *smd);
|
||||
void GPU_create_smoke(struct SmokeModifierData *smd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -73,6 +73,7 @@ int GPU_print_error(char *str);
|
||||
|
||||
GPUTexture *GPU_texture_create_1D(int w, float *pixels);
|
||||
GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels);
|
||||
GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels);
|
||||
GPUTexture *GPU_texture_create_depth(int w, int h);
|
||||
GPUTexture *GPU_texture_from_blender(struct Image *ima,
|
||||
struct ImageUser *iuser, double time, int mipmap);
|
||||
|
||||
@@ -38,9 +38,11 @@
|
||||
#include "DNA_lamp_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_node_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_smoke_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
|
||||
@@ -744,6 +746,23 @@ int GPU_update_image_time(Image *ima, double time)
|
||||
return inc;
|
||||
}
|
||||
|
||||
|
||||
void GPU_free_smoke(SmokeModifierData *smd)
|
||||
{
|
||||
if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain)
|
||||
{
|
||||
if(smd->domain->tex)
|
||||
GPU_texture_free(smd->domain->tex);
|
||||
smd->domain->tex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void GPU_create_smoke(SmokeModifierData *smd)
|
||||
{
|
||||
if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain && !smd->domain->tex)
|
||||
smd->domain->tex = GPU_texture_create_3D(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2], smd->domain->view3d);
|
||||
}
|
||||
|
||||
void GPU_free_image(Image *ima)
|
||||
{
|
||||
/* free regular image binding */
|
||||
|
||||
@@ -312,6 +312,78 @@ static GPUTexture *GPU_texture_create_nD(int w, int h, int n, float *fpixels, in
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
||||
GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
|
||||
{
|
||||
GPUTexture *tex;
|
||||
GLenum type, format, internalformat;
|
||||
void *pixels = NULL;
|
||||
|
||||
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
||||
tex->w = w;
|
||||
tex->h = h;
|
||||
tex->depth = depth;
|
||||
tex->number = -1;
|
||||
tex->refcount = 1;
|
||||
tex->target = GL_TEXTURE_3D;
|
||||
|
||||
glGenTextures(1, &tex->bindcode);
|
||||
|
||||
if (!tex->bindcode) {
|
||||
fprintf(stderr, "GPUTexture: texture create failed: %d\n",
|
||||
(int)glGetError());
|
||||
GPU_texture_free(tex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// if (!GLEW_ARB_texture_non_power_of_two)
|
||||
{
|
||||
tex->w = larger_pow2(tex->w);
|
||||
tex->h = larger_pow2(tex->h);
|
||||
tex->depth = larger_pow2(tex->depth);
|
||||
}
|
||||
|
||||
tex->number = 0;
|
||||
glBindTexture(tex->target, tex->bindcode);
|
||||
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
format = GL_RGBA;
|
||||
internalformat = GL_RGBA8;
|
||||
|
||||
if (fpixels)
|
||||
pixels = GPU_texture_convert_pixels(w*h*depth, fpixels);
|
||||
|
||||
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, 0);
|
||||
|
||||
if (fpixels) {
|
||||
glTexSubImage3D(tex->target, 0, 0, 0, 0, w, h, depth, format, type, pixels);
|
||||
|
||||
/*
|
||||
if (tex->w > w)
|
||||
GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w-w, tex->h);
|
||||
if (tex->h > h)
|
||||
GPU_glTexSubImageEmpty(tex->target, format, 0, h, w, tex->h-h);
|
||||
*/
|
||||
}
|
||||
|
||||
// glTexImage3D(tex->target, 0, GL_RGBA, w, h, depth, 0, GL_RGBA, GL_FLOAT, fpixels);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R,GL_CLAMP_TO_BORDER);
|
||||
|
||||
|
||||
if (pixels)
|
||||
MEM_freeN(pixels);
|
||||
|
||||
if (tex)
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, int mipmap)
|
||||
{
|
||||
GPUTexture *tex;
|
||||
|
||||
@@ -42,6 +42,7 @@ typedef enum ModifierType {
|
||||
eModifierType_Multires,
|
||||
eModifierType_Surface,
|
||||
eModifierType_Smoke,
|
||||
eModifierType_SmokeHR,
|
||||
NUM_MODIFIER_TYPES
|
||||
} ModifierType;
|
||||
|
||||
@@ -252,9 +253,36 @@ typedef struct SmokeModifierData {
|
||||
struct SmokeCollSettings *coll; /* collision objects */
|
||||
float time;
|
||||
int type; /* domain, inflow, outflow, ... */
|
||||
struct PointCache *point_cache; /* definition is in DNA_object_force.h */
|
||||
} SmokeModifierData;
|
||||
|
||||
|
||||
/* noise */
|
||||
#define MOD_SMOKE_NOISEWAVE (1<<0)
|
||||
#define MOD_SMOKE_NOISEFFT (1<<1)
|
||||
#define MOD_SMOKE_NOISECURL (1<<2)
|
||||
|
||||
/* flags */
|
||||
#define MOD_SMOKE_SHOWHIGHRES (1<<0) /* show high resolution */
|
||||
|
||||
typedef struct SmokeHRModifierData {
|
||||
ModifierData modifier;
|
||||
|
||||
struct WTURBULENCE *wt; // WTURBULENCE object, if active
|
||||
struct PointCache *point_cache; /* definition is in DNA_object_force.h */
|
||||
struct ListBase ptcaches;
|
||||
struct GPUTexture *tex;
|
||||
float *view3d; /* voxel data for display */
|
||||
unsigned int v3dnum; /* number of frame in view3d buffer */
|
||||
float time;
|
||||
float strength;
|
||||
int res[3];
|
||||
int maxres;
|
||||
short noise; /* noise type: wave, curl, anisotropic */
|
||||
short pad;
|
||||
int amplify;
|
||||
int flags;
|
||||
} SmokeHRModifierData;
|
||||
|
||||
typedef struct DisplaceModifierData {
|
||||
ModifierData modifier;
|
||||
|
||||
|
||||
@@ -30,24 +30,12 @@
|
||||
#define DNA_SMOKE_TYPES_H
|
||||
|
||||
/* flags */
|
||||
#define MOD_SMOKE_HIGHRES (1<<1) /* compute high resolution */
|
||||
#define MOD_SMOKE_HIGHRES (1<<1) /* enable high resolution */
|
||||
#define MOD_SMOKE_DISSOLVE (1<<2) /* let smoke dissolve */
|
||||
#define MOD_SMOKE_DISSOLVE_LOG (1<<3) /* using 1/x for dissolve */
|
||||
|
||||
/* noise */
|
||||
#define MOD_SMOKE_NOISEWAVE (1<<0)
|
||||
#define MOD_SMOKE_NOISEFFT (1<<1)
|
||||
#define MOD_SMOKE_NOISECURL (1<<2)
|
||||
/* viewsettings */
|
||||
#define MOD_SMOKE_VIEW_X (1<<0)
|
||||
#define MOD_SMOKE_VIEW_Y (1<<1)
|
||||
#define MOD_SMOKE_VIEW_Z (1<<2)
|
||||
#define MOD_SMOKE_VIEW_SMALL (1<<3)
|
||||
#define MOD_SMOKE_VIEW_BIG (1<<4)
|
||||
#define MOD_SMOKE_VIEW_CHANGETOBIG (1<<5)
|
||||
#define MOD_SMOKE_VIEW_REDRAWNICE (1<<6)
|
||||
#define MOD_SMOKE_VIEW_REDRAWALL (1<<7)
|
||||
#define MOD_SMOKE_VIEW_USEBIG (1<<8)
|
||||
/* nothing so far */
|
||||
|
||||
typedef struct SmokeDomainSettings {
|
||||
struct SmokeModifierData *smd; /* for fast RNA access */
|
||||
@@ -55,33 +43,27 @@ typedef struct SmokeDomainSettings {
|
||||
struct Group *fluid_group;
|
||||
struct Group *eff_group; // effector group for e.g. wind force
|
||||
struct Group *coll_group; // collision objects group
|
||||
unsigned int *bind;
|
||||
float *tvox;
|
||||
float *tray;
|
||||
float *tvoxbig;
|
||||
float *traybig;
|
||||
struct GPUTexture *tex;
|
||||
float *view3d; /* voxel data for display */
|
||||
unsigned int v3dnum; /* number of frame in view3d buffer */
|
||||
float p0[3]; /* start point of BB */
|
||||
float p1[3]; /* end point of BB */
|
||||
float dx; /* edge length of one cell */
|
||||
float firstframe;
|
||||
float lastframe;
|
||||
float omega; /* smoke color - from 0 to 1 */
|
||||
float temp; /* fluid temperature */
|
||||
float tempAmb; /* ambient temperature */
|
||||
float alpha;
|
||||
float beta;
|
||||
int res[3]; /* domain resolution */
|
||||
int amplify; /* wavelet amplification */
|
||||
int maxres; /* longest axis on the BB gets this resolution assigned */
|
||||
int flags; /* show up-res or low res, etc */
|
||||
int visibility; /* how many billboards to show (every 2nd, 3rd, 4th,..) */
|
||||
int viewsettings;
|
||||
int max_textures;
|
||||
short noise; /* noise type: wave, curl, anisotropic */
|
||||
short diss_percent;
|
||||
short pad;
|
||||
int diss_speed;/* in frames */
|
||||
float strength;
|
||||
struct WTURBULENCE *wt; // WTURBULENCE object, if active
|
||||
struct PointCache *point_cache; /* definition is in DNA_object_force.h */
|
||||
struct ListBase ptcaches;
|
||||
} SmokeDomainSettings;
|
||||
|
||||
|
||||
|
||||
@@ -387,6 +387,7 @@ extern StructRNA RNA_SmokeCollSettings;
|
||||
extern StructRNA RNA_SmokeDomainSettings;
|
||||
extern StructRNA RNA_SmokeFlowSettings;
|
||||
extern StructRNA RNA_SmokeModifier;
|
||||
extern StructRNA RNA_SmokeHRModifier;
|
||||
extern StructRNA RNA_SmoothModifier;
|
||||
extern StructRNA RNA_SoftBodyModifier;
|
||||
extern StructRNA RNA_SoftBodySettings;
|
||||
|
||||
@@ -68,6 +68,7 @@ EnumPropertyItem modifier_type_items[] ={
|
||||
{eModifierType_Shrinkwrap, "SHRINKWRAP", ICON_MOD_SHRINKWRAP, "Shrinkwrap", ""},
|
||||
{eModifierType_SimpleDeform, "SIMPLE_DEFORM", ICON_MOD_SIMPLEDEFORM, "Simple Deform", ""},
|
||||
{eModifierType_Smoke, "SMOKE", 0, "Smoke", ""},
|
||||
{eModifierType_SmokeHR, "SMOKE_HR", 0, "SmokeHR", ""},
|
||||
{eModifierType_Smooth, "SMOOTH", ICON_MOD_SMOOTH, "Smooth", ""},
|
||||
{eModifierType_Softbody, "SOFT_BODY", ICON_MOD_SOFT, "Soft Body", ""},
|
||||
{eModifierType_Subsurf, "SUBSURF", ICON_MOD_SUBSURF, "Subdivision Surface", ""},
|
||||
@@ -156,6 +157,8 @@ static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr)
|
||||
return &RNA_SurfaceModifier;
|
||||
case eModifierType_Smoke:
|
||||
return &RNA_SmokeModifier;
|
||||
case eModifierType_SmokeHR:
|
||||
return &RNA_SmokeHRModifier;
|
||||
default:
|
||||
return &RNA_Modifier;
|
||||
}
|
||||
@@ -181,19 +184,30 @@ static void rna_Smoke_set_type(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
SmokeModifierData *smd= (SmokeModifierData *)ptr->data;
|
||||
Object *ob= (Object*)ptr->id.data;
|
||||
|
||||
// nothing changed
|
||||
if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
|
||||
return;
|
||||
|
||||
smokeModifier_free(smd); // XXX TODO: completely free all 3 pointers
|
||||
smokeModifier_createType(smd); // create regarding of selected type
|
||||
// particle_system_slot_add_exec(C, NULL);
|
||||
// particle_system_slot_remove_exec(C, NULL);
|
||||
|
||||
if(smd->type == MOD_SMOKE_TYPE_DOMAIN)
|
||||
if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
|
||||
ob->dt = OB_WIRE;
|
||||
|
||||
// update dependancy since a domain - other type switch could have happened
|
||||
rna_Modifier_dependency_update(C, ptr);
|
||||
}
|
||||
|
||||
static void rna_SmokeHR_reset(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
// SmokeDomainSettings *settings = (SmokeDomainSettings*)ptr->data;
|
||||
|
||||
// smokeModifier_reset(settings->smd);
|
||||
|
||||
// rna_Smoke_update(C, ptr);
|
||||
}
|
||||
|
||||
static void rna_ExplodeModifier_vgroup_get(PointerRNA *ptr, char *value)
|
||||
{
|
||||
ExplodeModifierData *emd= (ExplodeModifierData*)ptr->data;
|
||||
@@ -1499,6 +1513,55 @@ static void rna_def_modifier_cloth(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Point Cache", "");
|
||||
}
|
||||
|
||||
static void rna_def_modifier_smoke_highresolution(BlenderRNA *brna)
|
||||
{
|
||||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
|
||||
static EnumPropertyItem prop_noise_type_items[] = {
|
||||
{MOD_SMOKE_NOISEWAVE, "NOISEWAVE", 0, "Wavelet", ""},
|
||||
#if FFTW3 == 1
|
||||
{MOD_SMOKE_NOISEFFT, "NOISEFFT", 0, "FFT", ""},
|
||||
#endif
|
||||
/* {MOD_SMOKE_NOISECURL, "NOISECURL", 0, "Curl", ""}, */
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
srna= RNA_def_struct(brna, "SmokeHRModifier", "Modifier");
|
||||
RNA_def_struct_ui_text(srna, "Smoke High Resolution Modifier", "Smoke high resolution simulation modifier.");
|
||||
RNA_def_struct_sdna(srna, "SmokeHRModifierData");
|
||||
|
||||
prop= RNA_def_property(srna, "show_highres", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_SHOWHIGHRES);
|
||||
RNA_def_property_ui_text(prop, "High res", "Show high resolution (using amplification).");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
|
||||
|
||||
prop= RNA_def_property(srna, "noise_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "noise");
|
||||
RNA_def_property_enum_items(prop, prop_noise_type_items);
|
||||
RNA_def_property_ui_text(prop, "Noise Method", "Noise method which is used for creating the high resolution");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_SmokeHR_reset");
|
||||
|
||||
prop= RNA_def_property(srna, "amplify", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_int_sdna(prop, NULL, "amplify");
|
||||
RNA_def_property_range(prop, 1, 10);
|
||||
RNA_def_property_ui_range(prop, 1, 10, 1, 0);
|
||||
RNA_def_property_ui_text(prop, "Amplification", "Enhance the resolution of smoke by this factor using noise.");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_SmokeHR_reset");
|
||||
|
||||
prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "strength");
|
||||
RNA_def_property_range(prop, 1.0, 10.0);
|
||||
RNA_def_property_ui_range(prop, 1.0, 10.0, 1, 2);
|
||||
RNA_def_property_ui_text(prop, "Strength", "Strength of wavelet noise");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_SmokeHR_reset");
|
||||
|
||||
prop= RNA_def_property(srna, "point_cache", PROP_POINTER, PROP_NEVER_NULL);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "point_cache");
|
||||
RNA_def_property_struct_type(prop, "PointCache");
|
||||
RNA_def_property_ui_text(prop, "Point Cache", "");
|
||||
|
||||
}
|
||||
|
||||
static void rna_def_modifier_smoke(BlenderRNA *brna)
|
||||
{
|
||||
StructRNA *srna;
|
||||
@@ -1915,6 +1978,7 @@ void RNA_def_modifier(BlenderRNA *brna)
|
||||
rna_def_modifier_multires(brna);
|
||||
rna_def_modifier_surface(brna);
|
||||
rna_def_modifier_smoke(brna);
|
||||
rna_def_modifier_smoke_highresolution(brna);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -78,11 +78,28 @@ static void rna_Smoke_reset_dependancy(bContext *C, PointerRNA *ptr)
|
||||
rna_Smoke_dependency_update(C, ptr);
|
||||
}
|
||||
|
||||
static void rna_Smoke_enable_HR(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
SmokeDomainSettings *settings = (SmokeDomainSettings*)ptr->data;
|
||||
Object *ob = (Object*)ptr->id.data;
|
||||
|
||||
if(settings->flags & MOD_SMOKE_HIGHRES)
|
||||
BLI_addtail(&ob->modifiers, modifier_new(eModifierType_SmokeHR));
|
||||
else
|
||||
{
|
||||
ModifierData *tmd = modifiers_findByType(ob, eModifierType_SmokeHR);
|
||||
if(tmd) {
|
||||
BLI_remlink(&ob->modifiers, tmd);
|
||||
modifier_free(tmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_Smoke_redraw(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
SmokeDomainSettings *settings = (SmokeDomainSettings*)ptr->data;
|
||||
|
||||
settings->flags |= MOD_SMOKE_VIEW_REDRAWNICE;
|
||||
// settings->flags |= MOD_SMOKE_VIEW_REDRAWNICE;
|
||||
}
|
||||
|
||||
static char *rna_SmokeDomainSettings_path(PointerRNA *ptr)
|
||||
@@ -116,14 +133,6 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
|
||||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
|
||||
static EnumPropertyItem prop_noise_type_items[] = {
|
||||
{MOD_SMOKE_NOISEWAVE, "NOISEWAVE", 0, "Wavelet", ""},
|
||||
#if FFTW3 == 1
|
||||
{MOD_SMOKE_NOISEFFT, "NOISEFFT", 0, "FFT", ""},
|
||||
#endif
|
||||
/* {MOD_SMOKE_NOISECURL, "NOISECURL", 0, "Curl", ""}, */
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
srna = RNA_def_struct(brna, "SmokeDomainSettings", NULL);
|
||||
RNA_def_struct_ui_text(srna, "Domain Settings", "Smoke domain settings.");
|
||||
RNA_def_struct_sdna(srna, "SmokeDomainSettings");
|
||||
@@ -136,56 +145,19 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Max Res", "Maximal resolution used in the fluid domain.");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
|
||||
|
||||
prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "omega");
|
||||
RNA_def_property_range(prop, 0.02, 1.0);
|
||||
RNA_def_property_ui_range(prop, 0.02, 1.0, 0.02, 2);
|
||||
RNA_def_property_ui_text(prop, "Color", "Smoke color (0 = black, 1 = white).");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Smoke_redraw");
|
||||
|
||||
prop= RNA_def_property(srna, "amplify", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_int_sdna(prop, NULL, "amplify");
|
||||
RNA_def_property_range(prop, 1, 10);
|
||||
RNA_def_property_ui_range(prop, 1, 10, 1, 0);
|
||||
RNA_def_property_ui_text(prop, "Amplification", "Enhance the resolution of smoke by this factor using noise.");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
|
||||
|
||||
prop= RNA_def_property(srna, "highres", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_HIGHRES);
|
||||
RNA_def_property_ui_text(prop, "High res", "Enable high resolution (using amplification).");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
|
||||
|
||||
prop= RNA_def_property(srna, "viewhighres", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "viewsettings", MOD_SMOKE_VIEW_USEBIG);
|
||||
RNA_def_property_ui_text(prop, "Show High Resolution", "Show high resolution (using amplification).");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_redraw");
|
||||
|
||||
prop= RNA_def_property(srna, "noise_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "noise");
|
||||
RNA_def_property_enum_items(prop, prop_noise_type_items);
|
||||
RNA_def_property_ui_text(prop, "Noise Method", "Noise method which is used for creating the high resolution");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
|
||||
|
||||
prop= RNA_def_property(srna, "visibility", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_int_sdna(prop, NULL, "visibility");
|
||||
RNA_def_property_range(prop, 1, 15);
|
||||
RNA_def_property_ui_range(prop, 1, 15, 1, 0);
|
||||
RNA_def_property_ui_text(prop, "Display", "How much of the resolution should be shown during preview (every 2nd, 3rd, etc).");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Smoke_redraw");
|
||||
|
||||
prop= RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "alpha");
|
||||
RNA_def_property_range(prop, -5.0, 5.0);
|
||||
RNA_def_property_ui_range(prop, -5.0, 5.0, 0.02, 5);
|
||||
RNA_def_property_ui_text(prop, "Gravity", "Higher value results in sinking smoke");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL);
|
||||
|
||||
prop= RNA_def_property(srna, "beta", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "beta");
|
||||
RNA_def_property_range(prop, -5.0, 5.0);
|
||||
RNA_def_property_ui_range(prop, -5.0, 5.0, 0.02, 5);
|
||||
RNA_def_property_ui_text(prop, "Heat", "Higher value results in faster rising smoke.");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL);
|
||||
|
||||
prop= RNA_def_property(srna, "coll_group", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "coll_group");
|
||||
@@ -208,13 +180,6 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Effector Group", "Limit effectors to this group.");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset_dependancy");
|
||||
|
||||
prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_float_sdna(prop, NULL, "strength");
|
||||
RNA_def_property_range(prop, 1.0, 10.0);
|
||||
RNA_def_property_ui_range(prop, 1.0, 10.0, 1, 2);
|
||||
RNA_def_property_ui_text(prop, "Strength", "Strength of wavelet noise");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
|
||||
|
||||
prop= RNA_def_property(srna, "dissolve_speed", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_int_sdna(prop, NULL, "diss_speed");
|
||||
RNA_def_property_range(prop, 1.0, 100.0);
|
||||
@@ -222,6 +187,11 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Dissolve Speed", "Dissolve Speed");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL);
|
||||
|
||||
prop= RNA_def_property(srna, "highres", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_HIGHRES);
|
||||
RNA_def_property_ui_text(prop, "High Resolution Smoke", "Enable high resolution smoke");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_enable_HR");
|
||||
|
||||
prop= RNA_def_property(srna, "dissolve_smoke", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_DISSOLVE);
|
||||
RNA_def_property_ui_text(prop, "Dissolve Smoke", "Enable smoke to disappear over time.");
|
||||
@@ -231,6 +201,11 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_DISSOLVE_LOG);
|
||||
RNA_def_property_ui_text(prop, "Logarithmic dissolve", "Using 1/x ");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL);
|
||||
|
||||
prop= RNA_def_property(srna, "point_cache", PROP_POINTER, PROP_NEVER_NULL);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "point_cache");
|
||||
RNA_def_property_struct_type(prop, "PointCache");
|
||||
RNA_def_property_ui_text(prop, "Point Cache", "");
|
||||
}
|
||||
|
||||
static void rna_def_smoke_flow_settings(BlenderRNA *brna)
|
||||
|
||||
@@ -319,6 +319,8 @@ IF(UNIX)
|
||||
bf_dummy
|
||||
bf_bullet
|
||||
bf_smoke
|
||||
bf_minilzo
|
||||
bf_lzma
|
||||
bf_common
|
||||
bf_ketsji
|
||||
bf_logic
|
||||
|
||||
Reference in New Issue
Block a user