Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
extract.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#
include
<
QtCore
/
QJniEnvironment
>
7
8
#
include
<
alloca
.
h
>
9
#
include
<
android
/
log
.
h
>
10
#
include
<
extract
.
h
>
11
#
include
<
jni
.
h
>
12
#
include
<
stdlib
.
h
>
13
14
#
define
LOG_TAG
"extractSyleInfo"
15
#
define
LOGE
(
...
)
__android_log_print
(
ANDROID_LOG_ERROR
,
LOG_TAG
,
__VA_ARGS__
)
16
17
// The following part was shamelessly stolen from ResourceTypes.cpp from Android's sources
18
/*
19
* Copyright (C) 2005 The Android Open Source Project
20
*
21
* Licensed under the Apache License, Version 2.0 (the "License");
22
* you may not use this file except in compliance with the License.
23
* You may obtain a copy of the License at
24
*
25
* http://www.apache.org/licenses/LICENSE-2.0
26
*
27
* Unless required by applicable law or agreed to in writing, software
28
* distributed under the License is distributed on an "AS IS" BASIS,
29
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
* See the License for the specific language governing permissions and
31
* limitations under the License.
32
*/
33
34
static
void
deserializeInternal
(
const
void
* inData, Res_png_9patch* outData) {
35
char
* patch = (
char
*) inData;
36
if
(inData != outData) {
37
memmove(&outData->wasDeserialized, patch, 4);
// copy wasDeserialized, numXDivs, numYDivs, numColors
38
memmove(&outData->paddingLeft, patch + 12, 4);
// copy wasDeserialized, numXDivs, numYDivs, numColors
39
}
40
outData->wasDeserialized =
true
;
41
char
* data = (
char
*)outData;
42
data +=
sizeof
(Res_png_9patch);
43
outData->xDivs = (int32_t*) data;
44
data += outData->numXDivs *
sizeof
(int32_t);
45
outData->yDivs = (int32_t*) data;
46
data += outData->numYDivs *
sizeof
(int32_t);
47
outData->colors = (uint32_t*) data;
48
}
49
50
Res_png_9patch* Res_png_9patch::deserialize(
const
void
* inData)
51
{
52
if
(
sizeof
(
void
*) !=
sizeof
(int32_t)) {
53
LOGE
(
"Cannot deserialize on non 32-bit system\n"
);
54
return
NULL;
55
}
56
deserializeInternal(inData, (Res_png_9patch*) inData);
57
return
(Res_png_9patch*) inData;
58
}
59
60
extern
"C"
JNIEXPORT jintArray JNICALL
61
Java_org_qtproject_qt_android_ExtractStyle_extractNativeChunkInfo20(JNIEnv *env, jobject,
long
addr)
62
{
63
Res_png_9patch20* chunk =
reinterpret_cast
<Res_png_9patch20*>(addr);
64
Res_png_9patch20::deserialize(chunk);
65
//printChunkInformation(chunk);
66
jintArray result;
67
size_t size = 3+chunk->numXDivs+chunk->numYDivs+chunk->numColors;
68
result = env->NewIntArray(size);
69
if
(!result)
70
return
0;
71
72
jint *data = (jint*)malloc(
sizeof
(jint)*size);
73
if
(!data)
74
return
0;
75
76
size_t pos = 0;
77
data[pos++] = chunk->numXDivs;
78
data[pos++] = chunk->numYDivs;
79
data[pos++] = chunk->numColors;
80
81
int32_t* xDivs = chunk->getXDivs();
82
int32_t* yDivs = chunk->getYDivs();
83
uint32_t* colors = chunk->getColors();
84
85
for
(
int
x = 0; x <chunk->numXDivs; x ++)
86
data[pos++]=xDivs[x];
87
for
(
int
y = 0; y <chunk->numYDivs; y ++)
88
data[pos++] = yDivs[y];
89
for
(
int
c = 0; c <chunk->numColors; c ++)
90
data[pos++] = colors[c];
91
env->SetIntArrayRegion(result, 0, size, data);
92
free(data);
93
return
result;
94
}
95
96
static
inline
void
fill9patchOffsets
(Res_png_9patch20* patch) {
97
patch->xDivsOffset =
sizeof
(Res_png_9patch20);
98
patch->yDivsOffset = patch->xDivsOffset + (patch->numXDivs *
sizeof
(int32_t));
99
patch->colorsOffset = patch->yDivsOffset + (patch->numYDivs *
sizeof
(int32_t));
100
}
101
102
Res_png_9patch20* Res_png_9patch20::deserialize(
void
* inData)
103
{
104
Res_png_9patch20* patch =
reinterpret_cast
<Res_png_9patch20*>(inData);
105
patch->wasDeserialized =
true
;
106
fill9patchOffsets(patch);
107
return
patch;
108
}
deserializeInternal
static void deserializeInternal(const void *inData, Res_png_9patch *outData)
Definition
extract.cpp:34
LOG_TAG
#define LOG_TAG
Definition
extract.cpp:14
fill9patchOffsets
static void fill9patchOffsets(Res_png_9patch20 *patch)
Definition
extract.cpp:96
LOGE
#define LOGE(...)
Definition
extract.cpp:15
qtbase
src
plugins
platforms
android
extract.cpp
Generated on
for Qt by
1.18.0