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