1
/****************************************************************************
3
** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
4
** Contact: http://www.qt.io/licensing/
6
** This file is part of the plugins of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL3-COMM$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and The Qt Company. For licensing terms
14
** and conditions see http://www.qt.io/terms-conditions. For further
15
** information use the contact form at http://www.qt.io/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 3 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 3 requirements
23
** will be met: https://www.gnu.org/licenses/lgpl.html.
27
****************************************************************************/
32
#include <android/log.h>
36
#define LOG_TAG "extractSyleInfo"
37
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
39
extern "C" JNIEXPORT jintArray JNICALL Java_org_qtproject_qt5_android_ExtractStyle_extractNativeChunkInfo(JNIEnv * env, jobject, Res_png_9patch* chunk)
41
Res_png_9patch::deserialize(chunk);
42
//printChunkInformation(chunk);
44
size_t size = 3+chunk->numXDivs+chunk->numYDivs+chunk->numColors;
45
result = env->NewIntArray(size);
49
jint *data = (jint*)malloc(sizeof(jint)*size);
51
data[pos++]=chunk->numXDivs;
52
data[pos++]=chunk->numYDivs;
53
data[pos++]=chunk->numColors;
54
for (int x = 0; x <chunk->numXDivs; x ++)
55
data[pos++]=chunk->xDivs[x];
56
for (int y = 0; y <chunk->numYDivs; y ++)
57
data[pos++]=chunk->yDivs[y];
58
for (int c = 0; c <chunk->numColors; c ++)
59
data[pos++]=chunk->colors[c];
60
env->SetIntArrayRegion(result, 0, size, data);
65
extern "C" JNIEXPORT jintArray JNICALL Java_org_qtproject_qt5_android_ExtractStyle_extractChunkInfo(JNIEnv * env, jobject obj, jbyteArray chunkObj)
67
size_t chunkSize = env->GetArrayLength(chunkObj);
68
void* storage = alloca(chunkSize);
69
env->GetByteArrayRegion(chunkObj, 0, chunkSize,
70
reinterpret_cast<jbyte*>(storage));
72
if (!env->ExceptionCheck())
73
return Java_org_qtproject_qt5_android_ExtractStyle_extractNativeChunkInfo(env, obj, static_cast<Res_png_9patch*>(storage));
75
env->ExceptionClear();
79
// The following part was shamelessly stolen from ResourceTypes.cpp from Android's sources
81
* Copyright (C) 2005 The Android Open Source Project
83
* Licensed under the Apache License, Version 2.0 (the "License");
84
* you may not use this file except in compliance with the License.
85
* You may obtain a copy of the License at
87
* http://www.apache.org/licenses/LICENSE-2.0
89
* Unless required by applicable law or agreed to in writing, software
90
* distributed under the License is distributed on an "AS IS" BASIS,
91
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
92
* See the License for the specific language governing permissions and
93
* limitations under the License.
96
static void deserializeInternal(const void* inData, Res_png_9patch* outData) {
97
char* patch = (char*) inData;
98
if (inData != outData) {
99
memmove(&outData->wasDeserialized, patch, 4); // copy wasDeserialized, numXDivs, numYDivs, numColors
100
memmove(&outData->paddingLeft, patch + 12, 4); // copy wasDeserialized, numXDivs, numYDivs, numColors
102
outData->wasDeserialized = true;
103
char* data = (char*)outData;
104
data += sizeof(Res_png_9patch);
105
outData->xDivs = (int32_t*) data;
106
data += outData->numXDivs * sizeof(int32_t);
107
outData->yDivs = (int32_t*) data;
108
data += outData->numYDivs * sizeof(int32_t);
109
outData->colors = (uint32_t*) data;
112
Res_png_9patch* Res_png_9patch::deserialize(const void* inData)
114
if (sizeof(void*) != sizeof(int32_t)) {
115
LOGE("Cannot deserialize on non 32-bit system\n");
118
deserializeInternal(inData, (Res_png_9patch*) inData);
119
return (Res_png_9patch*) inData;
122
extern "C" JNIEXPORT jintArray JNICALL Java_org_qtproject_qt5_android_ExtractStyle_extractNativeChunkInfo20(JNIEnv * env, jobject, long addr)
124
Res_png_9patch20* chunk = reinterpret_cast<Res_png_9patch20*>(addr);
125
Res_png_9patch20::deserialize(chunk);
126
//printChunkInformation(chunk);
128
size_t size = 3+chunk->numXDivs+chunk->numYDivs+chunk->numColors;
129
result = env->NewIntArray(size);
133
jint *data = (jint*)malloc(sizeof(jint)*size);
135
data[pos++] = chunk->numXDivs;
136
data[pos++] = chunk->numYDivs;
137
data[pos++] = chunk->numColors;
139
int32_t* xDivs = chunk->getXDivs();
140
int32_t* yDivs = chunk->getYDivs();
141
uint32_t* colors = chunk->getColors();
143
for (int x = 0; x <chunk->numXDivs; x ++)
144
data[pos++]=xDivs[x];
145
for (int y = 0; y <chunk->numYDivs; y ++)
146
data[pos++] = yDivs[y];
147
for (int c = 0; c <chunk->numColors; c ++)
148
data[pos++] = colors[c];
149
env->SetIntArrayRegion(result, 0, size, data);
154
extern "C" JNIEXPORT jintArray JNICALL Java_org_qtproject_qt5_android_ExtractStyle_extractChunkInfo20(JNIEnv * env, jobject obj, jbyteArray chunkObj)
156
size_t chunkSize = env->GetArrayLength(chunkObj);
157
void* storage = alloca(chunkSize);
158
env->GetByteArrayRegion(chunkObj, 0, chunkSize,
159
reinterpret_cast<jbyte*>(storage));
161
if (!env->ExceptionCheck())
162
return Java_org_qtproject_qt5_android_ExtractStyle_extractNativeChunkInfo20(env, obj, long(storage));
164
env->ExceptionClear();
168
static inline void fill9patchOffsets(Res_png_9patch20* patch) {
169
patch->xDivsOffset = sizeof(Res_png_9patch20);
170
patch->yDivsOffset = patch->xDivsOffset + (patch->numXDivs * sizeof(int32_t));
171
patch->colorsOffset = patch->yDivsOffset + (patch->numYDivs * sizeof(int32_t));
174
Res_png_9patch20* Res_png_9patch20::deserialize(void* inData)
176
Res_png_9patch20* patch = reinterpret_cast<Res_png_9patch20*>(inData);
177
patch->wasDeserialized = true;
178
fill9patchOffsets(patch);