X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.fastlz%2Fnative%2FjniWrapper.c;h=a2abf9515861fe053f2b3bbfed773a90c73d3ae2;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=6f497627a2907606121c3e701714d46831dfcf18;hpb=bb5a3edf299cb943999c72c69dd68fb740c8a506;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.fastlz/native/jniWrapper.c b/bundles/org.simantics.fastlz/native/jniWrapper.c index 6f497627a..a2abf9515 100644 --- a/bundles/org.simantics.fastlz/native/jniWrapper.c +++ b/bundles/org.simantics.fastlz/native/jniWrapper.c @@ -1,89 +1,89 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -#include "fastlz.h" -#include "lz4.h" -#include -#include "jni.h" -#include -#include - -JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_compress(JNIEnv* env, jclass clazz, - jobject input, jint inputOffset, jint length, - jobject output, jint outputOffset) { - void* inputAddress = (char*)(*env)->GetDirectBufferAddress(env, input) + inputOffset; - void* outputAddress = (char*)(*env)->GetDirectBufferAddress(env, output) + outputOffset; - return fastlz_compress(inputAddress, length, outputAddress); -} - -JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_decompress(JNIEnv* env, jclass clazz, - jobject input, jint inputOffset, jint length, - jobject output, jint outputOffset, jint maxout) { - void* inputAddress = (char*)(*env)->GetDirectBufferAddress(env, input) + inputOffset; - void* outputAddress = (char*)(*env)->GetDirectBufferAddress(env, output) + outputOffset; - return fastlz_decompress(inputAddress, length, outputAddress, maxout); -} - -#define INITIAL_SIZE 2000000 - -JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_decompressCluster(JNIEnv* env, jclass clazz, jobject deflated, jint deflatedSize, jint inflatedSize, jobjectArray arrays) { - - static char *inflateBuffer = 0; - static int inflateBufferSize = 0; - - int ll, il, bl; - - jlongArray longs; - jintArray ints; - jbyteArray bytes; - - char *input = (char*)(*env)->GetDirectBufferAddress(env, deflated); - char *address; - - if(inflateBufferSize < inflatedSize) { - if(!inflateBuffer) { - if(inflatedSize < INITIAL_SIZE) inflatedSize = INITIAL_SIZE; - inflateBuffer = malloc(inflatedSize); - inflateBufferSize = inflatedSize; - } else { - if(inflateBuffer) free(inflateBuffer); - inflateBuffer = malloc(inflatedSize); - inflateBufferSize = inflatedSize; - } - } - - address = inflateBuffer; - - fastlz_decompress(input, deflatedSize, inflateBuffer, inflateBufferSize); - - ll = *(int *)address; - longs = (*env)->NewLongArray(env, ll); - (*env)->SetLongArrayRegion(env, longs, 0, ll, (const jlong *)(address + 4)); - (*env)->SetObjectArrayElement(env, arrays, 0, longs); - - address += 4 + 8 * ll; - - il = *(int *)address; - ints = (*env)->NewIntArray(env, il); - (*env)->SetIntArrayRegion(env, ints, 0, il, (const jint *)(address + 4)); - (*env)->SetObjectArrayElement(env, arrays, 1, ints); - - address += 4 * il + 4; - - bl = *(int *)address; - bytes = (*env)->NewByteArray(env, bl); - (*env)->SetByteArrayRegion(env, bytes, 0, bl, (const jbyte *)(address + 4)); - (*env)->SetObjectArrayElement(env, arrays, 2, bytes); - - return 0; - -} - +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +#include "fastlz.h" +#include "lz4.h" +#include +#include "jni.h" +#include +#include + +JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_compress(JNIEnv* env, jclass clazz, + jobject input, jint inputOffset, jint length, + jobject output, jint outputOffset) { + void* inputAddress = (char*)(*env)->GetDirectBufferAddress(env, input) + inputOffset; + void* outputAddress = (char*)(*env)->GetDirectBufferAddress(env, output) + outputOffset; + return fastlz_compress(inputAddress, length, outputAddress); +} + +JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_decompress(JNIEnv* env, jclass clazz, + jobject input, jint inputOffset, jint length, + jobject output, jint outputOffset, jint maxout) { + void* inputAddress = (char*)(*env)->GetDirectBufferAddress(env, input) + inputOffset; + void* outputAddress = (char*)(*env)->GetDirectBufferAddress(env, output) + outputOffset; + return fastlz_decompress(inputAddress, length, outputAddress, maxout); +} + +#define INITIAL_SIZE 2000000 + +JNIEXPORT jint JNICALL Java_org_simantics_fastlz_FastLZ_decompressCluster(JNIEnv* env, jclass clazz, jobject deflated, jint deflatedSize, jint inflatedSize, jobjectArray arrays) { + + static char *inflateBuffer = 0; + static int inflateBufferSize = 0; + + int ll, il, bl; + + jlongArray longs; + jintArray ints; + jbyteArray bytes; + + char *input = (char*)(*env)->GetDirectBufferAddress(env, deflated); + char *address; + + if(inflateBufferSize < inflatedSize) { + if(!inflateBuffer) { + if(inflatedSize < INITIAL_SIZE) inflatedSize = INITIAL_SIZE; + inflateBuffer = malloc(inflatedSize); + inflateBufferSize = inflatedSize; + } else { + if(inflateBuffer) free(inflateBuffer); + inflateBuffer = malloc(inflatedSize); + inflateBufferSize = inflatedSize; + } + } + + address = inflateBuffer; + + fastlz_decompress(input, deflatedSize, inflateBuffer, inflateBufferSize); + + ll = *(int *)address; + longs = (*env)->NewLongArray(env, ll); + (*env)->SetLongArrayRegion(env, longs, 0, ll, (const jlong *)(address + 4)); + (*env)->SetObjectArrayElement(env, arrays, 0, longs); + + address += 4 + 8 * ll; + + il = *(int *)address; + ints = (*env)->NewIntArray(env, il); + (*env)->SetIntArrayRegion(env, ints, 0, il, (const jint *)(address + 4)); + (*env)->SetObjectArrayElement(env, arrays, 1, ints); + + address += 4 * il + 4; + + bl = *(int *)address; + bytes = (*env)->NewByteArray(env, bl); + (*env)->SetByteArrayRegion(env, bytes, 0, bl, (const jbyte *)(address + 4)); + (*env)->SetObjectArrayElement(env, arrays, 2, bytes); + + return 0; + +} +