aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <davidxli@google.com>2011-03-18 18:34:04 -0700
committerDavid Li <davidxli@google.com>2011-03-18 18:34:04 -0700
commit9aa010b07e889f790418b15ef5ad23ba72074020 (patch)
treedc2219aa5911a578df2d750289c3ffa0dbaccd28
parentdeeb0cf271beb1c4d118bcb5f251e24ad4a9f2a4 (diff)
downloadliblzf-9aa010b07e889f790418b15ef5ad23ba72074020.tar.gz
Make files and Java port
Change-Id: Ie12545d21e391b7b5c9f7acbdd32344839e32876 Signed-off-by: David Li <davidxli@google.com>
-rw-r--r--Android.mk36
-rw-r--r--CleanSpec.mk51
-rw-r--r--src/org/liblzf/CLZF.java70
3 files changed, 122 insertions, 35 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..2cce0dc
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,36 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+libLZF_SRC_FILES := \
+ lzf_c.c \
+ lzf_d.c
+
+# Static library for host
+# ========================================================
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := liblzf
+LOCAL_SRC_FILES := $(libLZF_SRC_FILES)
+
+include $(BUILD_HOST_STATIC_LIBRARY)
+
+
+# Static library for target
+# ========================================================
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := liblzf
+LOCAL_SRC_FILES := $(libLZF_SRC_FILES)
+
+include $(BUILD_STATIC_LIBRARY)
+
+# JAR for host
+# ========================================================
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_MODULE := liblzf
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100644
index 0000000..5f27c8c
--- /dev/null
+++ b/CleanSpec.mk
@@ -0,0 +1,51 @@
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list. These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list. E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libLZF_intermediates)
+
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
diff --git a/src/org/liblzf/CLZF.java b/src/org/liblzf/CLZF.java
index 710419a..c555be2 100644
--- a/src/org/liblzf/CLZF.java
+++ b/src/org/liblzf/CLZF.java
@@ -36,10 +36,9 @@
* of this file under either the BSD or the GPL.
*/
-using System;
+// ported from C# to Java
-namespace LZF.NET
-{
+package org.liblzf;
/// <summary>
/// Summary description for CLZF.
@@ -47,7 +46,8 @@ namespace LZF.NET
public class CLZF
{
// CRC32 data & function
- UInt32 []crc_32_tab = new UInt32[256]
+ /*
+ static int []crc_32_tab = new int[]
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
@@ -103,18 +103,18 @@ namespace LZF.NET
0x2d02ef8d
};
- public UInt32 crc32(UInt32 OldCRC,byte NewData)
+ public int crc32(int OldCRC,byte NewData)
{
return crc_32_tab[(OldCRC & 0xff) ^ NewData] ^ (OldCRC >> 8);
}
-
+ */
/// <summary>
/// LZF Compressor
/// </summary>
- UInt32 HLOG=14;
- UInt32 HSIZE=(1<<14);
+ static int HLOG=14;
+ static int HSIZE=(1<<14);
/*
* don't play with this unless you benchmark!
@@ -122,21 +122,21 @@ namespace LZF.NET
* the hashing function might seem strange, just believe me
* it works ;)
*/
- UInt32 MAX_LIT=(1 << 5);
- UInt32 MAX_OFF=(1 << 13);
- UInt32 MAX_REF=((1 << 8) + (1 << 3));
+ static int MAX_LIT=(1 << 5);
+ static int MAX_OFF=(1 << 13);
+ static int MAX_REF=((1 << 8) + (1 << 3));
- UInt32 FRST(byte[] Array,UInt32 ptr)
+ static int FRST(byte[] Array,int ptr)
{
- return (UInt32)(((Array[ptr]) << 8) | Array[ptr+1]);
+ return (int)((((Array[ptr]) << 8) & 0xff00) | (Array[ptr+1] & 0xff));
}
- UInt32 NEXT(UInt32 v,byte[] Array,UInt32 ptr)
+ static int NEXT(int v,byte[] Array,int ptr)
{
- return ((v) << 8) | Array[ptr+2];
+ return ((v) << 8) | (Array[ptr+2] & 0xff);
}
- UInt32 IDX(UInt32 h)
+ static int IDX(int h)
{
return ((((h ^ (h << 5)) >> (int) (3*8 - HLOG)) - h*5) & (HSIZE - 1));
}
@@ -150,24 +150,24 @@ namespace LZF.NET
*
*/
- public int lzf_compress (byte[] in_data, int in_len,byte[] out_data, int out_len)
+ public static int lzf_compress (byte[] in_data, int in_len,byte[] out_data, int out_len)
{
int c;
- long []htab=new long[1<<14];
+ int []htab=new int[1<<14];
for (c=0;c<1<<14;c++)
{
htab[c]=0;
}
- long hslot;
- UInt32 iidx = 0;
- UInt32 oidx = 0;
+ int hslot;
+ int iidx = 0;
+ int oidx = 0;
//byte *in_end = ip + in_len;
//byte *out_end = op + out_len;
- long reference;
+ int reference;
- UInt32 hval = FRST (in_data,iidx);
- long off;
+ int hval = FRST (in_data,iidx);
+ int off;
int lit = 0;
for (;;)
@@ -177,7 +177,7 @@ namespace LZF.NET
hval = NEXT (hval, in_data,iidx);
hslot = IDX (hval);
reference = htab[hslot];
- htab[hslot] = (long)iidx;
+ htab[hslot] = (int)iidx;
if ((off = iidx - reference - 1) < MAX_OFF
&& iidx + 4 < in_len
@@ -188,8 +188,8 @@ namespace LZF.NET
)
{
/* match found at *reference++ */
- UInt32 len = 2;
- UInt32 maxlen = (UInt32)in_len - iidx - len;
+ int len = 2;
+ int maxlen = in_len - iidx - len;
maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;
if (oidx + lit + 1 + 3 >= out_len)
@@ -274,14 +274,14 @@ namespace LZF.NET
/// <summary>
/// LZF Decompressor
/// </summary>
- public int lzf_decompress ( byte[] in_data, int in_len, byte[] out_data, int out_len)
+ public static int lzf_decompress ( byte[] in_data, int in_len, byte[] out_data, int out_len)
{
- UInt32 iidx=0;
- UInt32 oidx=0;
+ int iidx=0;
+ int oidx=0;
do
{
- UInt32 ctrl = in_data[iidx++];
+ int ctrl = in_data[iidx++] & 0xff;
if (ctrl < (1 << 5)) /* literal run */
{
@@ -299,14 +299,14 @@ namespace LZF.NET
}
else /* back reference */
{
- UInt32 len = ctrl >> 5;
+ int len = ctrl >> 5;
int reference = (int)(oidx - ((ctrl & 0x1f) << 8) - 1);
if (len == 7)
- len += in_data[iidx++];
+ len += in_data[iidx++] & 0xff;
- reference -= in_data[iidx++];
+ reference -= in_data[iidx++] & 0xff;
if (oidx + len + 2 > out_len)
{
@@ -340,5 +340,5 @@ namespace LZF.NET
//
}
}
-}
+