Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
34static 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
50Res_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
60extern "C" JNIEXPORT jintArray JNICALL
61Java_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 size_t pos = 0;
74 data[pos++] = chunk->numXDivs;
75 data[pos++] = chunk->numYDivs;
76 data[pos++] = chunk->numColors;
77
78 int32_t* xDivs = chunk->getXDivs();
79 int32_t* yDivs = chunk->getYDivs();
80 uint32_t* colors = chunk->getColors();
81
82 for (int x = 0; x <chunk->numXDivs; x ++)
83 data[pos++]=xDivs[x];
84 for (int y = 0; y <chunk->numYDivs; y ++)
85 data[pos++] = yDivs[y];
86 for (int c = 0; c <chunk->numColors; c ++)
87 data[pos++] = colors[c];
88 env->SetIntArrayRegion(result, 0, size, data);
89 free(data);
90 return result;
91}
92
93static inline void fill9patchOffsets(Res_png_9patch20* patch) {
94 patch->xDivsOffset = sizeof(Res_png_9patch20);
95 patch->yDivsOffset = patch->xDivsOffset + (patch->numXDivs * sizeof(int32_t));
96 patch->colorsOffset = patch->yDivsOffset + (patch->numYDivs * sizeof(int32_t));
97}
98
99Res_png_9patch20* Res_png_9patch20::deserialize(void* inData)
100{
101 Res_png_9patch20* patch = reinterpret_cast<Res_png_9patch20*>(inData);
102 patch->wasDeserialized = true;
103 fill9patchOffsets(patch);
104 return patch;
105}
static void deserializeInternal(const void *inData, Res_png_9patch *outData)
Definition extract.cpp:34
#define LOG_TAG
Definition extract.cpp:14
static void fill9patchOffsets(Res_png_9patch20 *patch)
Definition extract.cpp:93
#define LOGE(...)
Definition extract.cpp:15