]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/CompressDll/CompressDll.c
dd0e209dcc40c677f8102e094d225c803e46faad
[mirror_edk2.git] / Tools / Source / TianoTools / CompressDll / CompressDll.c
1 #include "CompressDll.h"
2 #include "EfiCompress.h"
3
4 extern
5 EFI_STATUS
6 Compress (
7 IN UINT8 *SrcBuffer,
8 IN UINT32 SrcSize,
9 IN UINT8 *DstBuffer,
10 IN OUT UINT32 *DstSize
11 );
12
13 JNIEXPORT jbyteArray JNICALL Java_org_tianocore_framework_tasks_Compress_CallCompress
14 (JNIEnv *env, jobject obj, jbyteArray SourceBuffer, jint SourceSize, jstring path)
15 {
16 char* DestBuffer;
17 int DestSize;
18 int Result;
19 char *InputBuffer;
20 jbyteArray OutputBuffer;
21 jbyte *TempByte;
22
23 DestSize = 0;
24 DestBuffer = NULL;
25
26 TempByte = (*env)->GetByteArrayElements(env, SourceBuffer, 0);
27 InputBuffer = (char*) TempByte;
28
29
30 //
31 // First call compress function and get need buffer size
32 //
33
34 Result = Compress (
35 (char*) InputBuffer,
36 SourceSize,
37 DestBuffer,
38 &DestSize
39 );
40
41 if (Result = EFI_BUFFER_TOO_SMALL) {
42 DestBuffer = malloc (DestSize);
43 }
44
45 //
46 // Second call compress and get the DestBuffer value
47 //
48 Result = Compress(
49 (char*) InputBuffer,
50 SourceSize,
51 DestBuffer,
52 &DestSize
53 );
54
55 //
56 // new a MV array to store the return compressed buffer
57 //
58 OutputBuffer = (*env)->NewByteArray(env, DestSize);
59 (*env)->SetByteArrayRegion(env, OutputBuffer,0, DestSize, (jbyte*) DestBuffer);
60
61 //
62 // Free Ouputbuffer.
63 //
64 free (DestBuffer);
65
66
67 if (Result != 0) {
68 return NULL;
69 } else {
70 return OutputBuffer;
71 }
72 }
73
74 #ifdef _MSC_VER
75 BOOLEAN
76 __stdcall
77 DllMainCRTStartup(
78 unsigned int hDllHandle,
79 unsigned int nReason,
80 void* Reserved
81 )
82 {
83 return TRUE;
84 }
85 #else
86 #ifdef __GNUC__
87 #endif
88 #endif
89