Skip to content

Commit 77974ac

Browse files
committed
Merge branch 'refs/heads/requireAndroid9-1' into BiLi_PC_Gamer
# Conflicts: # app/src/main/java/com/hippo/ehviewer/EhApplication.java
2 parents 3cb2ff2 + e787d4d commit 77974ac

File tree

161 files changed

+24148
-921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+24148
-921
lines changed

app/build.gradle

+16-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
testNamespace 'com.hippo.ehviewer.debug'
1313
compileSdk 34
1414
// buildToolsVersion "30.0.3"
15-
// ndkVersion '23.1.7779620'
15+
ndkVersion '25.1.8937393'
1616

1717
flavorDimensions "distribute"
1818
productFlavors {
@@ -26,7 +26,7 @@ android {
2626

2727
defaultConfig {
2828
applicationId "com.xjs.ehviewer"
29-
minSdkVersion 23
29+
minSdkVersion 28
3030
//noinspection ExpiredTargetSdkVersion
3131
targetSdkVersion 29
3232
versionCode 111
@@ -41,6 +41,7 @@ android {
4141
}
4242
externalNativeBuild {
4343
cmake {
44+
// path 'src/main/cpp/CMakeLists.txt'
4445
cppFlags ''
4546
}
4647
}
@@ -76,8 +77,8 @@ android {
7677
// }
7778

7879
compileOptions {
79-
sourceCompatibility JavaVersion.VERSION_11
80-
targetCompatibility JavaVersion.VERSION_11
80+
sourceCompatibility JavaVersion.VERSION_16
81+
targetCompatibility JavaVersion.VERSION_16
8182
}
8283

8384
buildFeatures {
@@ -134,6 +135,8 @@ dependencies {
134135
implementation "androidx.preference:preference:1.0.0"
135136
implementation 'androidx.recyclerview:recyclerview:1.2.0'
136137
implementation 'org.conscrypt:conscrypt-android:2.5.1'
138+
// https://mvnrepository.com/artifact/androidx.core/core-ktx
139+
implementation 'androidx.core:core-ktx:1.13.1'
137140
// implementation 'com.android.support:recyclerview-v7:25.0.1'
138141

139142
// https://mvnrepository.com/artifact/com.fpliu.ndk.pkg.prefab.android.21/libpng
@@ -156,27 +159,27 @@ dependencies {
156159
implementation 'com.github.seven332:animator:0.1.0'
157160
// implementation 'com.github.seven332:beerbelly:0.2.0'
158161
// implementation 'com.github.seven332:conaco:0.2.0'
159-
implementation 'com.github.seven332:beerbelly:0.1.4'
160-
implementation 'com.github.seven332:conaco:0.1.5-eh'
162+
// implementation 'com.github.seven332:beerbelly:0.1.4'
163+
// implementation 'com.github.seven332:conaco:0.1.5-eh'
161164
implementation 'com.github.seven332:drawerlayout:ea2bb388f0'
162165
implementation 'com.github.seven332:easyrecyclerview:0.1.1'
163166
// 分页组件
164167
implementation 'com.github.xiaojieonly:Pagination_Sxj:8d2c34d8f53927aeaa1d405d8653969379cb37ec'
165168
// implementation 'com.github.xiaojieonly:Pagination_Sxj:d8253ceefd6b02b73f9e9485cbb7dd89a6b89ba3'
166169
// 为方便扩展代码直接迁移至项目内
167170
// implementation 'com.github.seven332:glgallery:0.1.2'
168-
implementation 'com.github.seven332:glview:0.1.0'
169-
implementation 'com.github.seven332:glview-image:0.1.0'
171+
// implementation 'com.github.seven332:glview:0.1.0'
172+
// implementation 'com.github.seven332:glview-image:0.1.0'
170173
implementation 'com.github.seven332:hotspot:0.1.0'
171-
implementation 'com.github.seven332:image:0.1.12'
174+
// implementation 'com.github.seven332:image:0.1.12'
172175
implementation 'com.github.seven332:refreshlayout:0.1.0'
173176
implementation 'com.github.seven332:ripple:0.1.2'
174177
implementation 'com.github.seven332:streampipe:0.1.0'
175178
implementation 'com.github.seven332:tuxiang:0.1.6'
176-
implementation 'com.github.seven332:unifile:9ec57bcd8f'
177-
implementation 'com.github.seven332:yorozuya:0.1.2'
178-
implementation 'com.github.seven332:yorozuya-thread:0.1.1'
179-
implementation 'com.github.seven332:yorozuya-collect:0.1.4'
179+
// implementation 'com.github.seven332:unifile:9ec57bcd8f'
180+
// implementation 'com.github.seven332:yorozuya:0.1.2'
181+
// implementation 'com.github.seven332:yorozuya-thread:0.1.1'
182+
// implementation 'com.github.seven332:yorozuya-collect:0.1.4'
180183

181184

182185
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:1.0.0'

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<uses-permission android:name="android.permission.INTERNET" />
2121
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
22+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
2223
<uses-permission android:name="android.permission.WAKE_LOCK" />
2324
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
2425
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

app/src/main/cpp/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Sets the minimum version of CMake required to build the native library.
55

6-
cmake_minimum_required(VERSION 3.4.1)
6+
cmake_minimum_required(VERSION 3.14)
77

88
project("ehviewer")
99

@@ -17,6 +17,9 @@ add_library( # Sets the name of the library.
1717

1818
# Sets the library as a shared library.
1919
SHARED
20+
gifutils.c
21+
fdutils.c
22+
image.c
2023
gif/native-lib.cpp
2124
gif/dgif_lib.c
2225
gif/gifalloc.c)
@@ -46,4 +49,5 @@ target_link_libraries( # Specifies the target library.
4649
# Links the target library to the log library
4750
# included in the NDK.
4851
${log-lib}
49-
${jnigraphics-lib})
52+
${jnigraphics-lib}
53+
GLESv2)

app/src/main/cpp/ehviewer.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2022 Tarsin Norbin
3+
*
4+
* This file is part of EhViewer
5+
*
6+
* EhViewer is free software: you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* EhViewer is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* EhViewer. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef EHVIEWER_EHVIEWER_H
21+
#define EHVIEWER_EHVIEWER_H
22+
23+
#define EH_UNUSED(x) (void)x
24+
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG ,__VA_ARGS__)
25+
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG ,__VA_ARGS__)
26+
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG ,__VA_ARGS__)
27+
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG ,__VA_ARGS__)
28+
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG ,__VA_ARGS__)
29+
#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG ,__VA_ARGS__)
30+
31+
#define madvise_log_if_error(addr, len, advice) \
32+
if (madvise(addr, len, advice)) \
33+
LOGE("%s%p%s%zu%s%d%s%s%s", "madvise addr:", addr, "len:", len, "with advice ", advice, " failed with error: ", strerror(errno), ", Ignored")
34+
35+
#endif /* EHVIEWER_EHVIEWER_H */

app/src/main/cpp/fdutils.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <jni.h>
2+
3+
JNIEXPORT jint JNICALL
4+
Java_com_hippo_Native_getFd(JNIEnv *env, jclass clazz, jobject fileDescriptor) {
5+
jint fd = -1;
6+
jclass fdClass = (*env)->FindClass(env, "java/io/FileDescriptor");
7+
8+
if (fdClass != NULL) {
9+
jfieldID fdClassDescriptorFieldID = (*env)->GetFieldID(env, fdClass, "descriptor", "I");
10+
if (fdClassDescriptorFieldID != NULL && fileDescriptor != NULL) {
11+
fd = (*env)->GetIntField(env, fileDescriptor, fdClassDescriptorFieldID);
12+
}
13+
}
14+
15+
return fd;
16+
}

app/src/main/cpp/gifutils.c

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2023 Tarsin Norbin
3+
*
4+
* This file is part of EhViewer
5+
*
6+
* EhViewer is free software: you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* EhViewer is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* EhViewer. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <jni.h>
21+
#include <string.h>
22+
#include <stdbool.h>
23+
#include <android/log.h>
24+
#include <sys/stat.h>
25+
#include <sys/mman.h>
26+
27+
#define LOG_TAG "gifUtils"
28+
29+
#include "ehviewer.h"
30+
31+
#define GIF_HEADER_87A "GIF87a"
32+
#define GIF_HEADER_89A "GIF89a"
33+
34+
static int FRAME_DELAY_START_MARKER = 0x0021F904;
35+
36+
typedef signed char byte;
37+
38+
#define FRAME_DELAY_START_MARKER ((byte*)(&FRAME_DELAY_START_MARKER))
39+
#define MINIMUM_FRAME_DELAY 2
40+
#define DEFAULT_FRAME_DELAY 10
41+
42+
static inline bool isGif(void *addr) {
43+
return !memcmp(addr, GIF_HEADER_87A, 6) || !memcmp(addr, GIF_HEADER_89A, 6);
44+
}
45+
46+
static void doRewrite(byte *addr, size_t size) {
47+
if (size < 7 || !isGif(addr)) return;
48+
for (size_t i = 0; i < size - 8; i++) {
49+
// TODO: Optimize this hex find with SIMD?
50+
if (addr[i] == FRAME_DELAY_START_MARKER[3] && addr[i + 1] == FRAME_DELAY_START_MARKER[2] &&
51+
addr[i + 2] == FRAME_DELAY_START_MARKER[1] &&
52+
addr[i + 3] == FRAME_DELAY_START_MARKER[0]) {
53+
byte *end = addr + i + 4;
54+
if (end[4] != 0) continue;
55+
int frameDelay = end[2] << 8 | end[1];
56+
if (frameDelay > MINIMUM_FRAME_DELAY)
57+
break; // Quit if the first block looks normal, for performance
58+
end[1] = DEFAULT_FRAME_DELAY;
59+
end[2] = 0;
60+
}
61+
}
62+
}
63+
64+
JNIEXPORT void JNICALL
65+
Java_com_hippo_lib_image_ImageKt_rewriteGifSource(JNIEnv *env, jclass clazz, jobject buffer) {
66+
byte *addr = (*env)->GetDirectBufferAddress(env, buffer);
67+
size_t size = (*env)->GetDirectBufferCapacity(env, buffer);
68+
doRewrite(addr, size);
69+
}
70+
71+
JNIEXPORT void JNICALL
72+
Java_com_hippo_lib_image_ImageKt_rewriteGifSource2(JNIEnv *env, jclass clazz, jint fd) {
73+
struct stat64 st;
74+
fstat64(fd, &st);
75+
size_t size = st.st_size;
76+
byte *addr = mmap64(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
77+
if (addr == MAP_FAILED) return;
78+
doRewrite(addr, size);
79+
munmap(addr, size);
80+
}

0 commit comments

Comments
 (0)