Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126882
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/compress.cpp b/util/compress.cpp
new file mode 100644
index 00000000..6953960a
--- /dev/null
+++ b/util/compress.cpp
@@ -0,0 +1,28 @@
+#include <allegro.h>
+#include "compress.h"
+#include "memory.h"
+#include "globals.h"
+
+namespace Compress{
+
+void testCompression(unsigned char * input, int length){
+ unsigned char * data = new unsigned char[length*2];
+ PACKFILE_VTABLE table = Memory::makeTable();
+ Memory::memory memory(data, length*2);
+ PACKFILE * pack = pack_fopen_vtable(&table, &memory);
+
+ LZSS_PACK_DATA * lzss = create_lzss_pack_data();
+ int r = lzss_write(pack, lzss, length, input, 1);
+ if (r != 0){
+ // printf("lzss error %d: %s!\n", r, ustrerror(errno));
+ exit(-1);
+ }
+ free_lzss_pack_data(lzss);
+ pack_fclose(pack);
+
+ Global::debug(0) << "Compressed " << length << " to " << memory.getSize() << " ratio is " << ((double)memory.getSize() / length) << std::endl;
+
+ delete[] data;
+}
+
+}
diff --git a/util/compress.h b/util/compress.h
new file mode 100644
index 00000000..1fe9ffde
--- /dev/null
+++ b/util/compress.h
@@ -0,0 +1,8 @@
+#ifndef _paintown_compress_h
+#define _paintown_compress_h
+
+namespace Compress{
+ void testCompression(unsigned char * data, int length);
+}
+
+#endif
diff --git a/util/memory.h b/util/memory.h
index b8aa783b..dd3fd2d2 100644
--- a/util/memory.h
+++ b/util/memory.h
@@ -1,121 +1,126 @@
#ifndef _paintown_3ac0ba2587944345f2241085269c24f8
#define _paintown_3ac0ba2587944345f2241085269c24f8
#include <allegro.h>
namespace Memory{
struct memory{
memory(unsigned char * stream, int length):
stream(stream),
position(stream),
length(length){
}
+
+ int getSize() const {
+ return position - stream;
+ }
+
/* points to the head */
unsigned char * stream;
/* points to the current position */
unsigned char * position;
int length;
};
static int pf_fclose(void *userdata){
return 0;
/* nothing */
}
static int pf_getc(void *userdata){
memory * m = (memory*) userdata;
if (m->position < m->stream + m->length){
unsigned char x = *m->position;
m->position += 1;
return x;
}
return EOF;
}
static int pf_ungetc(int c, void *userdata){
memory * m = (memory*) userdata;
if (m->position > m->stream){
m->position -= 1;
return c;
} else {
return EOF;
}
}
static long pf_fread(void *p, long n, void *userdata){
memory *m = (memory*) userdata;
unsigned char *cp = (unsigned char *)p;
long i;
int c;
for (i=0; i<n; i++) {
if ((c = pf_getc(m)) == EOF)
break;
*(cp++) = c;
}
return i;
}
static int pf_putc(int c, void *userdata){
memory * m = (memory*) userdata;
if (m->position < m->stream + m->length){
*m->position = c;
m->position += 1;
return c;
}
return EOF;
}
static long pf_fwrite(const void *p, long n, void *userdata){
memory *m = (memory*) userdata;
const unsigned char * cp = (const unsigned char *) p;
long i;
int c;
for (i=0; i<n; i++) {
if ((c = pf_putc(cp[i], userdata)) == EOF)
break;
}
return i;
}
static int pf_fseek(void *userdata, int offset){
memory * m = (memory*) userdata;
if (offset >= 0 && offset < m->length){
m->position = m->stream + offset;
return 0;
} else {
return -1;
}
}
static int pf_feof(void *userdata){
memory * m = (memory*) userdata;
return m->position >= m->stream + m->length;
}
static int pf_ferror(void *userdata){
memory * m = (memory*) userdata;
return m->position < m->stream || m->position >= m->stream + m->length;
}
static PACKFILE_VTABLE makeTable(){
PACKFILE_VTABLE table;
table.pf_fclose = Memory::pf_fclose;
table.pf_getc = Memory::pf_getc;
table.pf_ungetc = Memory::pf_ungetc;
table.pf_fread = Memory::pf_fread;
table.pf_putc = Memory::pf_putc;
table.pf_fwrite = Memory::pf_fwrite;
table.pf_fseek = Memory::pf_fseek;
table.pf_feof = Memory::pf_feof;
table.pf_ferror = Memory::pf_ferror;
return table;
}
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 1:26 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69238
Default Alt Text
(4 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline