]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/CompressDll/CompressDll.c
3c6fc8cb4d8e597cc4d5e90d6cd6ef55e1d9c3cf
[mirror_edk2.git] / Tools / Source / TianoTools / CompressDll / CompressDll.c
1 /** @file
2 Compression DLL used by PCD Tools
3
4 Copyright (c) 2006, Intel Corporation All rights reserved.
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 #include "CompressDll.h"
15 #include "EfiCompress.h"
16
17 extern
18 EFI_STATUS
19 Compress (
20 IN UINT8 *SrcBuffer,
21 IN UINT32 SrcSize,
22 IN UINT8 *DstBuffer,
23 IN OUT UINT32 *DstSize
24 );
25
26 JNIEXPORT jbyteArray JNICALL Java_org_tianocore_framework_tasks_Compress_CallCompress
27 (JNIEnv *env, jobject obj, jbyteArray SourceBuffer, jint SourceSize, jstring path)
28 {
29 char* DestBuffer;
30 int DestSize;
31 int Result;
32 char *InputBuffer;
33 jbyteArray OutputBuffer;
34 jbyte *TempByte;
35
36 DestSize = 0;
37 DestBuffer = NULL;
38
39 TempByte = (*env)->GetByteArrayElements(env, SourceBuffer, 0);
40 InputBuffer = (char*) TempByte;
41
42
43 //
44 // First call compress function and get need buffer size
45 //
46
47 Result = Compress (
48 (char*) InputBuffer,
49 SourceSize,
50 DestBuffer,
51 &DestSize
52 );
53
54 if (Result = EFI_BUFFER_TOO_SMALL) {
55 DestBuffer = malloc (DestSize);
56 }
57
58 //
59 // Second call compress and get the DestBuffer value
60 //
61 Result = Compress(
62 (char*) InputBuffer,
63 SourceSize,
64 DestBuffer,
65 &DestSize
66 );
67
68 //
69 // new a MV array to store the return compressed buffer
70 //
71 OutputBuffer = (*env)->NewByteArray(env, DestSize);
72 (*env)->SetByteArrayRegion(env, OutputBuffer,0, DestSize, (jbyte*) DestBuffer);
73
74 //
75 // Free Ouputbuffer.
76 //
77 free (DestBuffer);
78
79
80 if (Result != 0) {
81 return NULL;
82 } else {
83 return OutputBuffer;
84 }
85 }
86
87 #ifdef _MSC_VER
88 BOOLEAN
89 __stdcall
90 DllMainCRTStartup(
91 unsigned int hDllHandle,
92 unsigned int nReason,
93 void* Reserved
94 )
95 {
96 return TRUE;
97 }
98 #else
99 #ifdef __GNUC__
100 #endif
101 #endif
102