~gabriel1984sibiu/minitube/qt5.6

« back to all changes in this revision

Viewing changes to src/plugins/platforms/android/extract.cpp

  • Committer: Grevutiu Gabriel
  • Date: 2017-06-13 08:43:17 UTC
  • Revision ID: gabriel1984sibiu@gmail.com-20170613084317-ek0zqe0u9g3ocvi8
OriginalĀ upstreamĀ code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
 
4
** Contact: http://www.qt.io/licensing/
 
5
**
 
6
** This file is part of the plugins of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
24
**
 
25
** $QT_END_LICENSE$
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
 
 
30
 
 
31
#include <jni.h>
 
32
#include <android/log.h>
 
33
#include <extract.h>
 
34
#include <alloca.h>
 
35
 
 
36
#define LOG_TAG    "extractSyleInfo"
 
37
#define LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
 
38
 
 
39
extern "C" JNIEXPORT jintArray JNICALL Java_org_qtproject_qt5_android_ExtractStyle_extractNativeChunkInfo(JNIEnv * env, jobject, Res_png_9patch* chunk)
 
40
{
 
41
        Res_png_9patch::deserialize(chunk);
 
42
        //printChunkInformation(chunk);
 
43
        jintArray result;
 
44
        size_t size = 3+chunk->numXDivs+chunk->numYDivs+chunk->numColors;
 
45
        result = env->NewIntArray(size);
 
46
        if (!result)
 
47
            return 0;
 
48
 
 
49
        jint *data = (jint*)malloc(sizeof(jint)*size);
 
50
        size_t pos = 0;
 
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);
 
61
        free(data);
 
62
        return result;
 
63
}
 
64
 
 
65
extern "C" JNIEXPORT jintArray JNICALL Java_org_qtproject_qt5_android_ExtractStyle_extractChunkInfo(JNIEnv * env, jobject  obj, jbyteArray chunkObj)
 
66
{
 
67
        size_t chunkSize = env->GetArrayLength(chunkObj);
 
68
        void* storage = alloca(chunkSize);
 
69
        env->GetByteArrayRegion(chunkObj, 0, chunkSize,
 
70
                                reinterpret_cast<jbyte*>(storage));
 
71
 
 
72
        if (!env->ExceptionCheck())
 
73
            return Java_org_qtproject_qt5_android_ExtractStyle_extractNativeChunkInfo(env, obj, static_cast<Res_png_9patch*>(storage));
 
74
        else
 
75
            env->ExceptionClear();
 
76
        return 0;
 
77
}
 
78
 
 
79
// The following part was shamelessly stolen from ResourceTypes.cpp from Android's sources
 
80
/*
 
81
 * Copyright (C) 2005 The Android Open Source Project
 
82
 *
 
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
 
86
 *
 
87
 *      http://www.apache.org/licenses/LICENSE-2.0
 
88
 *
 
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.
 
94
 */
 
95
 
 
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
 
101
    }
 
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;
 
110
}
 
111
 
 
112
Res_png_9patch* Res_png_9patch::deserialize(const void* inData)
 
113
{
 
114
    if (sizeof(void*) != sizeof(int32_t)) {
 
115
        LOGE("Cannot deserialize on non 32-bit system\n");
 
116
        return NULL;
 
117
    }
 
118
    deserializeInternal(inData, (Res_png_9patch*) inData);
 
119
    return (Res_png_9patch*) inData;
 
120
}
 
121
 
 
122
extern "C" JNIEXPORT jintArray JNICALL Java_org_qtproject_qt5_android_ExtractStyle_extractNativeChunkInfo20(JNIEnv * env, jobject, long addr)
 
123
{
 
124
    Res_png_9patch20* chunk = reinterpret_cast<Res_png_9patch20*>(addr);
 
125
    Res_png_9patch20::deserialize(chunk);
 
126
    //printChunkInformation(chunk);
 
127
    jintArray result;
 
128
    size_t size = 3+chunk->numXDivs+chunk->numYDivs+chunk->numColors;
 
129
    result = env->NewIntArray(size);
 
130
    if (!result)
 
131
        return 0;
 
132
 
 
133
    jint *data = (jint*)malloc(sizeof(jint)*size);
 
134
    size_t pos = 0;
 
135
    data[pos++] = chunk->numXDivs;
 
136
    data[pos++] = chunk->numYDivs;
 
137
    data[pos++] = chunk->numColors;
 
138
 
 
139
    int32_t* xDivs = chunk->getXDivs();
 
140
    int32_t* yDivs = chunk->getYDivs();
 
141
    uint32_t* colors = chunk->getColors();
 
142
 
 
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);
 
150
    free(data);
 
151
    return result;
 
152
}
 
153
 
 
154
extern "C" JNIEXPORT jintArray JNICALL Java_org_qtproject_qt5_android_ExtractStyle_extractChunkInfo20(JNIEnv * env, jobject  obj, jbyteArray chunkObj)
 
155
{
 
156
    size_t chunkSize = env->GetArrayLength(chunkObj);
 
157
    void* storage = alloca(chunkSize);
 
158
    env->GetByteArrayRegion(chunkObj, 0, chunkSize,
 
159
                            reinterpret_cast<jbyte*>(storage));
 
160
 
 
161
    if (!env->ExceptionCheck())
 
162
        return Java_org_qtproject_qt5_android_ExtractStyle_extractNativeChunkInfo20(env, obj, long(storage));
 
163
    else
 
164
        env->ExceptionClear();
 
165
    return 0;
 
166
}
 
167
 
 
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));
 
172
}
 
173
 
 
174
Res_png_9patch20* Res_png_9patch20::deserialize(void* inData)
 
175
{
 
176
    Res_png_9patch20* patch = reinterpret_cast<Res_png_9patch20*>(inData);
 
177
    patch->wasDeserialized = true;
 
178
    fill9patchOffsets(patch);
 
179
    return patch;
 
180
}