Update to 6.2.0 (1984)

https://github.com/DrKLO/Telegram/pull/1561
This commit is contained in:
DrKLO 2020-06-04 19:47:15 +03:00
parent f120800a7f
commit dceccae0b7
487 changed files with 23032 additions and 9363 deletions

View File

@ -4,7 +4,7 @@ ENV ANDROID_SDK_URL https://dl.google.com/android/repository/sdk-tools-linux-385
ENV ANDROID_API_LEVEL android-29 ENV ANDROID_API_LEVEL android-29
ENV ANDROID_BUILD_TOOLS_VERSION 29.0.3 ENV ANDROID_BUILD_TOOLS_VERSION 29.0.3
ENV ANDROID_HOME /usr/local/android-sdk-linux ENV ANDROID_HOME /usr/local/android-sdk-linux
ENV ANDROID_NDK_VERSION 20.0.5594570 ENV ANDROID_NDK_VERSION 21.1.6352462
ENV ANDROID_VERSION 29 ENV ANDROID_VERSION 29
ENV ANDROID_NDK_HOME ${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}/ ENV ANDROID_NDK_HOME ${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}/
ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools

View File

@ -25,15 +25,15 @@ dependencies {
compileOnly 'org.checkerframework:checker-qual:2.5.2' compileOnly 'org.checkerframework:checker-qual:2.5.2'
compileOnly 'org.checkerframework:checker-compat-qual:2.5.0' compileOnly 'org.checkerframework:checker-compat-qual:2.5.0'
implementation 'com.google.firebase:firebase-messaging:20.1.6' implementation 'com.google.firebase:firebase-messaging:20.2.0'
implementation 'com.google.firebase:firebase-config:19.1.4' implementation 'com.google.firebase:firebase-config:19.1.4'
implementation 'com.google.android.gms:play-services-maps:17.0.0' implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0' implementation 'com.google.android.gms:play-services-auth:18.0.0'
implementation 'com.google.android.gms:play-services-vision:16.2.0' implementation 'com.google.android.gms:play-services-vision:16.2.0'
implementation 'com.google.android.gms:play-services-wearable:17.0.0' implementation 'com.google.android.gms:play-services-wearable:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0' implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation "com.microsoft.appcenter:appcenter-distribute:3.1.0" implementation "com.microsoft.appcenter:appcenter-distribute:3.2.1"
implementation "com.microsoft.appcenter:appcenter-crashes:3.1.0" implementation "com.microsoft.appcenter:appcenter-crashes:3.2.1"
implementation 'com.googlecode.mp4parser:isoparser:1.0.6' implementation 'com.googlecode.mp4parser:isoparser:1.0.6'
implementation 'com.stripe:stripe-android:2.0.2' implementation 'com.stripe:stripe-android:2.0.2'
implementation files('libs/libgsaverification-client.aar') implementation files('libs/libgsaverification-client.aar')
@ -42,7 +42,7 @@ dependencies {
android { android {
compileSdkVersion 29 compileSdkVersion 29
buildToolsVersion '29.0.3' buildToolsVersion '29.0.3'
ndkVersion "20.0.5594570" ndkVersion "21.1.6352462"
defaultConfig.applicationId = "org.telegram.messenger" defaultConfig.applicationId = "org.telegram.messenger"
@ -102,6 +102,7 @@ android {
signingConfig signingConfigs.debug signingConfig signingConfigs.debug
applicationIdSuffix ".beta" applicationIdSuffix ".beta"
minifyEnabled true minifyEnabled true
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
packagingOptions { packagingOptions {
@ -124,12 +125,6 @@ android {
} }
}*/ }*/
debugMultidex {
initWith debug
minifyEnabled false
multiDexEnabled true
}
HA { HA {
debuggable false debuggable false
jniDebuggable false jniDebuggable false
@ -159,11 +154,6 @@ android {
manifest.srcFile 'config/debug/AndroidManifest.xml' manifest.srcFile 'config/debug/AndroidManifest.xml'
}*/ }*/
sourceSets.debugMultidex {
manifest.srcFile 'config/debug/AndroidManifest.xml'
java.srcDirs = ['src/multidex/java']
}
sourceSets.HA { sourceSets.HA {
manifest.srcFile 'config/debug/AndroidManifest.xml' manifest.srcFile 'config/debug/AndroidManifest.xml'
} }
@ -286,7 +276,7 @@ android {
} }
} }
defaultConfig.versionCode = 1947 defaultConfig.versionCode = 1984
def tgVoipDexFileName = "libtgvoip.dex" def tgVoipDexFileName = "libtgvoip.dex"
def tgVoipDexClasses = ["AudioRecordJNI", "AudioTrackJNI", "NativeTgVoipDelegate", "NativeTgVoipInstance", "TgVoipNativeLoader", "Resampler", "VLog"] def tgVoipDexClasses = ["AudioRecordJNI", "AudioTrackJNI", "NativeTgVoipDelegate", "NativeTgVoipInstance", "TgVoipNativeLoader", "Resampler", "VLog"]
@ -381,13 +371,13 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 28 targetSdkVersion 28
versionName "6.1.1" versionName "6.2.0"
vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi'] vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi']
externalNativeBuild { externalNativeBuild {
ndkBuild { ndkBuild {
arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-16", "--jobs=8" arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-16", "--jobs=8", "LOCAL_ARM_NEON:=false"
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64" abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
} }
} }

View File

@ -624,7 +624,7 @@ endif
LOCAL_SRC_FILES += \ LOCAL_SRC_FILES += \
./jni.c \ ./jni.c \
./audio.c \ ./audio.c \
./image.c \ ./image.cpp \
./video.c \ ./video.c \
./intro/IntroRenderer.c \ ./intro/IntroRenderer.c \
./utilities.cpp \ ./utilities.cpp \

View File

@ -30,6 +30,8 @@ static const std::string av_make_error_str(int errnum) {
jclass jclass_AnimatedFileDrawableStream; jclass jclass_AnimatedFileDrawableStream;
jmethodID jclass_AnimatedFileDrawableStream_read; jmethodID jclass_AnimatedFileDrawableStream_read;
jmethodID jclass_AnimatedFileDrawableStream_cancel; jmethodID jclass_AnimatedFileDrawableStream_cancel;
jmethodID jclass_AnimatedFileDrawableStream_isFinishedLoadingFile;
jmethodID jclass_AnimatedFileDrawableStream_getFinishedFilePath;
typedef struct VideoInfo { typedef struct VideoInfo {
@ -189,6 +191,20 @@ void requestFd(VideoInfo *info) {
attached = false; attached = false;
} }
jniEnv->CallIntMethod(info->stream, jclass_AnimatedFileDrawableStream_read, (jint) 0, (jint) 1); jniEnv->CallIntMethod(info->stream, jclass_AnimatedFileDrawableStream_read, (jint) 0, (jint) 1);
jboolean loaded = jniEnv->CallBooleanMethod(info->stream, jclass_AnimatedFileDrawableStream_isFinishedLoadingFile);
if (loaded) {
delete[] info->src;
jstring src = (jstring) jniEnv->CallObjectMethod(info->stream, jclass_AnimatedFileDrawableStream_getFinishedFilePath);
char const *srcString = jniEnv->GetStringUTFChars(src, 0);
size_t len = strlen(srcString);
info->src = new char[len + 1];
memcpy(info->src, srcString, len);
info->src[len] = '\0';
if (srcString != 0) {
jniEnv->ReleaseStringUTFChars(src, srcString);
}
}
if (attached) { if (attached) {
javaVm->DetachCurrentThread(); javaVm->DetachCurrentThread();
} }
@ -579,7 +595,7 @@ void Java_org_telegram_ui_Components_AnimatedFileDrawable_seekToMs(JNIEnv *env,
} }
} }
jint Java_org_telegram_ui_Components_AnimatedFileDrawable_getVideoFrame(JNIEnv *env, jclass clazz, jlong ptr, jobject bitmap, jintArray data, jint stride, jboolean preview) { jint Java_org_telegram_ui_Components_AnimatedFileDrawable_getVideoFrame(JNIEnv *env, jclass clazz, jlong ptr, jobject bitmap, jintArray data, jint stride, jboolean preview, jfloat start_time, jfloat end_time) {
if (ptr == NULL || bitmap == nullptr) { if (ptr == NULL || bitmap == nullptr) {
return 0; return 0;
} }
@ -592,9 +608,16 @@ jint Java_org_telegram_ui_Components_AnimatedFileDrawable_getVideoFrame(JNIEnv *
while (!info->stopped && triesCount != 0) { while (!info->stopped && triesCount != 0) {
if (info->pkt.size == 0) { if (info->pkt.size == 0) {
ret = av_read_frame(info->fmt_ctx, &info->pkt); ret = av_read_frame(info->fmt_ctx, &info->pkt);
//LOGD("got packet with size %d", info->pkt.size);
if (ret >= 0) { if (ret >= 0) {
info->orig_pkt = info->pkt; double pts = info->pkt.pts * av_q2d(info->video_stream->time_base);
if (end_time > 0 && info->pkt.stream_index == info->video_stream_idx && pts > end_time) {
av_packet_unref(&info->pkt);
info->pkt.data = NULL;
info->pkt.size = 0;
} else {
info->orig_pkt = info->pkt;
}
} }
} }
@ -624,7 +647,11 @@ jint Java_org_telegram_ui_Components_AnimatedFileDrawable_getVideoFrame(JNIEnv *
} }
if (!preview && got_frame == 0) { if (!preview && got_frame == 0) {
if (info->has_decoded_frames) { if (info->has_decoded_frames) {
if ((ret = av_seek_frame(info->fmt_ctx, info->video_stream_idx, 0, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_FRAME)) < 0) { int64_t start_from = 0;
if (start_time > 0) {
start_from = (int64_t)(start_time / av_q2d(info->video_stream->time_base));
}
if ((ret = av_seek_frame(info->fmt_ctx, info->video_stream_idx, start_from, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_FRAME)) < 0) {
LOGE("can't seek to begin of file %s, %s", info->src, av_err2str(ret)); LOGE("can't seek to begin of file %s, %s", info->src, av_err2str(ret));
return 0; return 0;
} else { } else {
@ -710,6 +737,14 @@ jint videoOnJNILoad(JavaVM *vm, JNIEnv *env) {
if (jclass_AnimatedFileDrawableStream_cancel == 0) { if (jclass_AnimatedFileDrawableStream_cancel == 0) {
return JNI_FALSE; return JNI_FALSE;
} }
jclass_AnimatedFileDrawableStream_isFinishedLoadingFile = env->GetMethodID(jclass_AnimatedFileDrawableStream, "isFinishedLoadingFile", "()Z");
if (jclass_AnimatedFileDrawableStream_isFinishedLoadingFile == 0) {
return JNI_FALSE;
}
jclass_AnimatedFileDrawableStream_getFinishedFilePath = env->GetMethodID(jclass_AnimatedFileDrawableStream, "getFinishedFilePath", "()Ljava/lang/String;");
if (jclass_AnimatedFileDrawableStream_getFinishedFilePath == 0) {
return JNI_FALSE;
}
return JNI_TRUE; return JNI_TRUE;
} }

View File

@ -7,10 +7,9 @@
#include <android/bitmap.h> #include <android/bitmap.h>
#include <libwebp/webp/decode.h> #include <libwebp/webp/decode.h>
#include <libwebp/webp/encode.h> #include <libwebp/webp/encode.h>
#include <malloc.h>
#include "c_utils.h" #include "c_utils.h"
#include "image.h"
extern "C" {
jclass jclass_NullPointerException; jclass jclass_NullPointerException;
jclass jclass_RuntimeException; jclass jclass_RuntimeException;
@ -19,39 +18,28 @@ jfieldID jclass_Options_inJustDecodeBounds;
jfieldID jclass_Options_outHeight; jfieldID jclass_Options_outHeight;
jfieldID jclass_Options_outWidth; jfieldID jclass_Options_outWidth;
const uint32_t PGPhotoEnhanceHistogramBins = 256;
const uint32_t PGPhotoEnhanceSegments = 4;
jclass createGlobarRef(JNIEnv *env, jclass class) {
if (class) {
return (*env)->NewGlobalRef(env, class);
}
return 0;
}
jint imageOnJNILoad(JavaVM *vm, JNIEnv *env) { jint imageOnJNILoad(JavaVM *vm, JNIEnv *env) {
jclass_NullPointerException = createGlobarRef(env, (*env)->FindClass(env, "java/lang/NullPointerException")); jclass_NullPointerException = (jclass) env->NewGlobalRef(env->FindClass("java/lang/NullPointerException"));
if (jclass_NullPointerException == 0) { if (jclass_NullPointerException == 0) {
return JNI_FALSE; return JNI_FALSE;
} }
jclass_RuntimeException = createGlobarRef(env, (*env)->FindClass(env, "java/lang/RuntimeException")); jclass_RuntimeException = (jclass) env->NewGlobalRef(env->FindClass("java/lang/RuntimeException"));
if (jclass_RuntimeException == 0) { if (jclass_RuntimeException == 0) {
return JNI_FALSE; return JNI_FALSE;
} }
jclass_Options = (jclass) env->NewGlobalRef(env->FindClass("android/graphics/BitmapFactory$Options"));
jclass_Options = createGlobarRef(env, (*env)->FindClass(env, "android/graphics/BitmapFactory$Options"));
if (jclass_Options == 0) { if (jclass_Options == 0) {
return JNI_FALSE; return JNI_FALSE;
} }
jclass_Options_inJustDecodeBounds = (*env)->GetFieldID(env, jclass_Options, "inJustDecodeBounds", "Z"); jclass_Options_inJustDecodeBounds = env->GetFieldID(jclass_Options, "inJustDecodeBounds", "Z");
if (jclass_Options_inJustDecodeBounds == 0) { if (jclass_Options_inJustDecodeBounds == 0) {
return JNI_FALSE; return JNI_FALSE;
} }
jclass_Options_outHeight = (*env)->GetFieldID(env, jclass_Options, "outHeight", "I"); jclass_Options_outHeight = env->GetFieldID(jclass_Options, "outHeight", "I");
if (jclass_Options_outHeight == 0) { if (jclass_Options_outHeight == 0) {
return JNI_FALSE; return JNI_FALSE;
} }
jclass_Options_outWidth = (*env)->GetFieldID(env, jclass_Options, "outWidth", "I"); jclass_Options_outWidth = env->GetFieldID(jclass_Options, "outWidth", "I");
if (jclass_Options_outWidth == 0) { if (jclass_Options_outWidth == 0) {
return JNI_FALSE; return JNI_FALSE;
} }
@ -65,7 +53,7 @@ static inline uint64_t getColors(const uint8_t *p) {
static inline uint64_t getColors565(const uint8_t *p) { static inline uint64_t getColors565(const uint8_t *p) {
uint16_t *ps = (uint16_t *) p; uint16_t *ps = (uint16_t *) p;
return ((((ps[0] & 0xF800) >> 11) * 255) / 31) + (((((ps[0] & 0x07E0) >> 5) * 255) / 63) << 16) + ((uint64_t) (((ps[0] & 0x001F) * 255) / 31) << 32); return ((((ps[0] & 0xF800) >> 11) * 255) / 31) + (((((ps[0] & 0x07E0) >> 5) * 255) / 63) << 16) + ((uint64_t)(((ps[0] & 0x001F) * 255) / 31) << 32);
} }
static void fastBlurMore(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t radius) { static void fastBlurMore(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t radius) {
@ -76,7 +64,7 @@ static void fastBlurMore(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int
return; return;
} }
uint64_t *rgb = malloc(w * h * sizeof(uint64_t)); uint64_t *rgb = new uint64_t[w * h];
if (rgb == NULL) { if (rgb == NULL) {
return; return;
} }
@ -98,7 +86,7 @@ static void fastBlurMore(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int
x = 0; x = 0;
#define update(start, middle, end) \ #define update(start, middle, end) \
rgb[y * w + x] = (rgbsum >> 6) & 0x00FF00FF00FF00FF; \ rgb[y * w + x] = (rgbsum >> 6) & 0x00FF00FF00FF00FF; \
rgballsum += getColors(&pix[yw + (start) * 4]) - 2 * getColors(&pix[yw + (middle) * 4]) + getColors(&pix[yw + (end) * 4]); \ rgballsum += getColors(&pix[yw + (start) * 4]) - 2 * getColors(&pix[yw + (middle) * 4]) + getColors(&pix[yw + (end) * 4]); \
rgbsum += rgballsum; \ rgbsum += rgballsum; \
@ -113,7 +101,7 @@ static void fastBlurMore(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int
while (x < w) { while (x < w) {
update (x - r1, x, w - 1); update (x - r1, x, w - 1);
} }
#undef update #undef update
yw += stride; yw += stride;
} }
@ -130,7 +118,7 @@ static void fastBlurMore(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int
y = 0; y = 0;
int32_t yi = x * 4; int32_t yi = x * 4;
#define update(start, middle, end) \ #define update(start, middle, end) \
int64_t res = rgbsum >> 6; \ int64_t res = rgbsum >> 6; \
pix[yi] = res; \ pix[yi] = res; \
pix[yi + 1] = res >> 16; \ pix[yi + 1] = res >> 16; \
@ -150,8 +138,10 @@ static void fastBlurMore(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int
while (y < h) { while (y < h) {
update (y - r1, y, h - 1); update (y - r1, y, h - 1);
} }
#undef update #undef update
} }
delete[] rgb;
} }
static void fastBlur(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t radius) { static void fastBlur(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t radius) {
@ -177,7 +167,7 @@ static void fastBlur(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t
return; return;
} }
uint64_t *rgb = malloc(w * h * sizeof(uint64_t)); uint64_t *rgb = new uint64_t[w * h];
if (rgb == NULL) { if (rgb == NULL) {
return; return;
} }
@ -199,7 +189,7 @@ static void fastBlur(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t
x = 0; x = 0;
#define update(start, middle, end) \ #define update(start, middle, end) \
rgb[y * w + x] = (rgbsum >> shift) & 0x00FF00FF00FF00FFLL; \ rgb[y * w + x] = (rgbsum >> shift) & 0x00FF00FF00FF00FFLL; \
rgballsum += getColors(&pix[yw + (start) * 4]) - 2 * getColors(&pix[yw + (middle) * 4]) + getColors(&pix[yw + (end) * 4]); \ rgballsum += getColors(&pix[yw + (start) * 4]) - 2 * getColors(&pix[yw + (middle) * 4]) + getColors(&pix[yw + (end) * 4]); \
rgbsum += rgballsum; \ rgbsum += rgballsum; \
@ -215,7 +205,7 @@ static void fastBlur(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t
update (x - r1, x, w - 1); update (x - r1, x, w - 1);
} }
#undef update #undef update
yw += stride; yw += stride;
} }
@ -232,7 +222,7 @@ static void fastBlur(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t
y = 0; y = 0;
int32_t yi = x * 4; int32_t yi = x * 4;
#define update(start, middle, end) \ #define update(start, middle, end) \
int64_t res = rgbsum >> shift; \ int64_t res = rgbsum >> shift; \
pix[yi] = res; \ pix[yi] = res; \
pix[yi + 1] = res >> 16; \ pix[yi + 1] = res >> 16; \
@ -252,10 +242,10 @@ static void fastBlur(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t
while (y < h) { while (y < h) {
update (y - r1, y, h - 1); update (y - r1, y, h - 1);
} }
#undef update #undef update
} }
free(rgb); delete[] rgb;
} }
static void fastBlurMore565(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t radius) { static void fastBlurMore565(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t radius) {
@ -266,7 +256,7 @@ static void fastBlurMore565(int32_t w, int32_t h, int32_t stride, uint8_t *pix,
return; return;
} }
uint64_t *rgb = malloc(w * h * sizeof(uint64_t)); uint64_t *rgb = new uint64_t[w * h];
if (rgb == NULL) { if (rgb == NULL) {
return; return;
} }
@ -340,6 +330,8 @@ static void fastBlurMore565(int32_t w, int32_t h, int32_t stride, uint8_t *pix,
} }
#undef update #undef update
} }
delete[] rgb;
} }
static void fastBlur565(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t radius) { static void fastBlur565(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int32_t radius) {
@ -365,7 +357,7 @@ static void fastBlur565(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int3
return; return;
} }
uint64_t *rgb = malloc(w * h * sizeof(uint64_t)); uint64_t *rgb = new uint64_t[w * h];
if (rgb == NULL) { if (rgb == NULL) {
return; return;
} }
@ -441,10 +433,10 @@ static void fastBlur565(int32_t w, int32_t h, int32_t stride, uint8_t *pix, int3
#undef update #undef update
} }
free(rgb); delete[] rgb;
} }
JNIEXPORT int Java_org_telegram_messenger_Utilities_needInvert(JNIEnv *env, jclass class, jobject bitmap, jint unpin, jint width, jint height, jint stride) { int Java_org_telegram_messenger_Utilities_needInvert(JNIEnv *env, jclass clazz, jobject bitmap, jint unpin, jint width, jint height, jint stride) {
if (!bitmap) { if (!bitmap) {
return 0; return 0;
} }
@ -471,9 +463,9 @@ JNIEXPORT int Java_org_telegram_messenger_Utilities_needInvert(JNIEnv *env, jcla
uint8_t a = pix[index + 3]; uint8_t a = pix[index + 3];
float alpha = a / 255.0f; float alpha = a / 255.0f;
uint8_t r = (uint8_t) (pix[index] * alpha); uint8_t r = (uint8_t)(pix[index] * alpha);
uint8_t g = (uint8_t) (pix[index + 1] * alpha); uint8_t g = (uint8_t)(pix[index + 1] * alpha);
uint8_t b = (uint8_t) (pix[index + 2] * alpha); uint8_t b = (uint8_t)(pix[index + 2] * alpha);
uint8_t cmax = (r > g) ? r : g; uint8_t cmax = (r > g) ? r : g;
if (b > cmax) { if (b > cmax) {
@ -510,7 +502,7 @@ JNIEXPORT int Java_org_telegram_messenger_Utilities_needInvert(JNIEnv *env, jcla
return hasAlpha && matching / total > 0.85; return hasAlpha && matching / total > 0.85;
} }
JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jclass class, jobject bitmap, jint radius, jint unpin, jint width, jint height, jint stride) { void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jclass clazz, jobject bitmap, jint radius, jint unpin, jint width, jint height, jint stride) {
if (!bitmap) { if (!bitmap) {
return; return;
} }
@ -525,15 +517,15 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jcl
} }
if (stride == width * 2) { if (stride == width * 2) {
if (radius <= 3) { if (radius <= 3) {
fastBlur565(width, height, stride, pixels, radius); fastBlur565(width, height, stride, (uint8_t *) pixels, radius);
} else { } else {
fastBlurMore565(width, height, stride, pixels, radius); fastBlurMore565(width, height, stride, (uint8_t *) pixels, radius);
} }
} else { } else {
if (radius <= 3) { if (radius <= 3) {
fastBlur(width, height, stride, pixels, radius); fastBlur(width, height, stride, (uint8_t *) pixels, radius);
} else { } else {
fastBlurMore(width, height, stride, pixels, radius); fastBlurMore(width, height, stride, (uint8_t *) pixels, radius);
} }
} }
if (unpin) { if (unpin) {
@ -541,7 +533,10 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jcl
} }
} }
JNIEXPORT void Java_org_telegram_messenger_Utilities_calcCDT(JNIEnv *env, jclass class, jobject hsvBuffer, jint width, jint height, jobject buffer) { const uint32_t PGPhotoEnhanceHistogramBins = 256;
const uint32_t PGPhotoEnhanceSegments = 4;
void Java_org_telegram_messenger_Utilities_calcCDT(JNIEnv *env, jclass clazz, jobject hsvBuffer, jint width, jint height, jobject buffer, jobject calcBuffer) {
float imageWidth = width; float imageWidth = width;
float imageHeight = height; float imageHeight = height;
float _clipLimit = 1.25f; float _clipLimit = 1.25f;
@ -551,160 +546,149 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_calcCDT(JNIEnv *env, jclass
uint32_t clipLimit = (uint32_t) MAX(1, _clipLimit * tileArea / (float) PGPhotoEnhanceHistogramBins); uint32_t clipLimit = (uint32_t) MAX(1, _clipLimit * tileArea / (float) PGPhotoEnhanceHistogramBins);
float scale = 255.0f / (float) tileArea; float scale = 255.0f / (float) tileArea;
unsigned char *bytes = (*env)->GetDirectBufferAddress(env, hsvBuffer); unsigned char *bytes = (unsigned char *) env->GetDirectBufferAddress(hsvBuffer);
uint32_t *calcBytes = (uint32_t *) env->GetDirectBufferAddress(calcBuffer);
unsigned char *result = (unsigned char *) env->GetDirectBufferAddress(buffer);
uint32_t **hist = calloc(totalSegments, sizeof(uint32_t *)); uint32_t *cdfsMin = calcBytes;
uint32_t **cdfs = calloc(totalSegments, sizeof(uint32_t *)); calcBytes += totalSegments;
uint32_t *cdfsMin = calloc(totalSegments, sizeof(uint32_t)); uint32_t *cdfsMax = calcBytes;
uint32_t *cdfsMax = calloc(totalSegments, sizeof(uint32_t)); calcBytes += totalSegments;
uint32_t *cdfs = calcBytes;
for (uint32_t a = 0; a < totalSegments; a++) { calcBytes += totalSegments * PGPhotoEnhanceHistogramBins;
hist[a] = calloc(PGPhotoEnhanceHistogramBins, sizeof(uint32_t)); uint32_t *hist = calcBytes;
cdfs[a] = calloc(PGPhotoEnhanceHistogramBins, sizeof(uint32_t)); memset(hist, 0, sizeof(uint32_t) * totalSegments * PGPhotoEnhanceHistogramBins);
}
float xMul = PGPhotoEnhanceSegments / imageWidth; float xMul = PGPhotoEnhanceSegments / imageWidth;
float yMul = PGPhotoEnhanceSegments / imageHeight; float yMul = PGPhotoEnhanceSegments / imageHeight;
for (uint32_t y = 0; y < imageHeight; y++) { uint32_t i, j;
uint32_t yOffset = y * width * 4;
for (uint32_t x = 0; x < imageWidth; x++) {
uint32_t index = x * 4 + yOffset;
uint32_t tx = (uint32_t)(x * xMul); for (i = 0; i < imageHeight; i++) {
uint32_t ty = (uint32_t)(y * yMul); uint32_t yOffset = i * width * 4;
for (j = 0; j < imageWidth; j++) {
uint32_t index = j * 4 + yOffset;
uint32_t tx = (uint32_t)(j * xMul);
uint32_t ty = (uint32_t)(i * yMul);
uint32_t t = ty * PGPhotoEnhanceSegments + tx; uint32_t t = ty * PGPhotoEnhanceSegments + tx;
hist[t][bytes[index + 2]]++; hist[t * PGPhotoEnhanceHistogramBins + bytes[index + 2]]++;
} }
} }
for (uint32_t i = 0; i < totalSegments; i++) { for (i = 0; i < totalSegments; i++) {
if (clipLimit > 0) { if (clipLimit > 0) {
uint32_t clipped = 0; uint32_t clipped = 0;
for (uint32_t j = 0; j < PGPhotoEnhanceHistogramBins; ++j) { for (j = 0; j < PGPhotoEnhanceHistogramBins; j++) {
if (hist[i][j] > clipLimit) { if (hist[i * PGPhotoEnhanceHistogramBins + j] > clipLimit) {
clipped += hist[i][j] - clipLimit; clipped += hist[i * PGPhotoEnhanceHistogramBins + j] - clipLimit;
hist[i][j] = clipLimit; hist[i * PGPhotoEnhanceHistogramBins + j] = clipLimit;
} }
} }
uint32_t redistBatch = clipped / PGPhotoEnhanceHistogramBins; uint32_t redistBatch = clipped / PGPhotoEnhanceHistogramBins;
uint32_t residual = clipped - redistBatch * PGPhotoEnhanceHistogramBins; uint32_t residual = clipped - redistBatch * PGPhotoEnhanceHistogramBins;
for (uint32_t j = 0; j < PGPhotoEnhanceHistogramBins; ++j) { for (j = 0; j < PGPhotoEnhanceHistogramBins; j++) {
hist[i][j] += redistBatch; hist[i * PGPhotoEnhanceHistogramBins + j] += redistBatch;
} if (j < residual) {
hist[i * PGPhotoEnhanceHistogramBins + j]++;
for (uint32_t j = 0; j < residual; ++j) { }
hist[i][j]++;
} }
} }
memcpy(cdfs[i], hist[i], PGPhotoEnhanceHistogramBins * sizeof(uint32_t)); memcpy(cdfs + i * PGPhotoEnhanceHistogramBins, hist + i * PGPhotoEnhanceHistogramBins, PGPhotoEnhanceHistogramBins * sizeof(uint32_t));
uint32_t hMin = PGPhotoEnhanceHistogramBins - 1; uint32_t hMin = PGPhotoEnhanceHistogramBins - 1;
for (uint32_t j = 0; j < hMin; ++j) { for (j = 0; j < hMin; ++j) {
if (cdfs[j] != 0) { if (cdfs[i * PGPhotoEnhanceHistogramBins + j] != 0) {
hMin = j; hMin = j;
} }
} }
uint32_t cdf = 0; uint32_t cdf = 0;
for (uint32_t j = hMin; j < PGPhotoEnhanceHistogramBins; ++j) { for (j = hMin; j < PGPhotoEnhanceHistogramBins; j++) {
cdf += cdfs[i][j]; cdf += cdfs[i * PGPhotoEnhanceHistogramBins + j];
cdfs[i][j] = (uint8_t) MIN(255, cdf * scale); cdfs[i * PGPhotoEnhanceHistogramBins + j] = (uint8_t) MIN(255, cdf * scale);
} }
cdfsMin[i] = cdfs[i][hMin]; cdfsMin[i] = cdfs[i * PGPhotoEnhanceHistogramBins + hMin];
cdfsMax[i] = cdfs[i][PGPhotoEnhanceHistogramBins - 1]; cdfsMax[i] = cdfs[i * PGPhotoEnhanceHistogramBins + PGPhotoEnhanceHistogramBins - 1];
} }
uint32_t resultSize = 4 * PGPhotoEnhanceHistogramBins * totalSegments; for (j = 0; j < totalSegments; j++) {
uint32_t resultBytesPerRow = 4 * PGPhotoEnhanceHistogramBins; uint32_t yOffset = j * PGPhotoEnhanceHistogramBins * 4;
for (i = 0; i < PGPhotoEnhanceHistogramBins; i++) {
unsigned char *result = (*env)->GetDirectBufferAddress(env, buffer);
for (uint32_t tile = 0; tile < totalSegments; tile++) {
uint32_t yOffset = tile * resultBytesPerRow;
for (uint32_t i = 0; i < PGPhotoEnhanceHistogramBins; i++) {
uint32_t index = i * 4 + yOffset; uint32_t index = i * 4 + yOffset;
result[index] = (uint8_t)cdfs[tile][i]; result[index] = (uint8_t) cdfs[j * PGPhotoEnhanceHistogramBins + i];
result[index + 1] = (uint8_t)cdfsMin[tile]; result[index + 1] = (uint8_t) cdfsMin[j];
result[index + 2] = (uint8_t)cdfsMax[tile]; result[index + 2] = (uint8_t) cdfsMax[j];
result[index + 3] = 255; result[index + 3] = 255;
} }
} }
for (uint32_t a = 0; a < totalSegments; a++) {
free(hist[a]);
free(cdfs[a]);
}
free(hist);
free(cdfs);
free(cdfsMax);
free(cdfsMin);
} }
JNIEXPORT jint Java_org_telegram_messenger_Utilities_pinBitmap(JNIEnv *env, jclass class, jobject bitmap) { jint Java_org_telegram_messenger_Utilities_pinBitmap(JNIEnv *env, jclass clazz, jobject bitmap) {
if (bitmap == NULL) { if (bitmap == nullptr) {
return 0; return 0;
} }
unsigned char *pixels; void *pixels;
return AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 ? 1 : 0; return AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 ? 1 : 0;
} }
JNIEXPORT void Java_org_telegram_messenger_Utilities_unpinBitmap(JNIEnv *env, jclass class, jobject bitmap) { void Java_org_telegram_messenger_Utilities_unpinBitmap(JNIEnv *env, jclass clazz, jobject bitmap) {
if (bitmap == NULL) { if (bitmap == NULL) {
return; return;
} }
AndroidBitmap_unlockPixels(env, bitmap); AndroidBitmap_unlockPixels(env, bitmap);
} }
JNIEXPORT jboolean Java_org_telegram_messenger_Utilities_loadWebpImage(JNIEnv *env, jclass class, jobject outputBitmap, jobject buffer, jint len, jobject options, jboolean unpin) { jboolean Java_org_telegram_messenger_Utilities_loadWebpImage(JNIEnv *env, jclass clazz, jobject outputBitmap, jobject buffer, jint len, jobject options, jboolean unpin) {
if (!buffer) { if (!buffer) {
(*env)->ThrowNew(env, jclass_NullPointerException, "Input buffer can not be null"); env->ThrowNew(jclass_NullPointerException, "Input buffer can not be null");
return 0; return 0;
} }
jbyte *inputBuffer = (*env)->GetDirectBufferAddress(env, buffer); jbyte *inputBuffer = (jbyte *) env->GetDirectBufferAddress(buffer);
int32_t bitmapWidth = 0; int32_t bitmapWidth = 0;
int32_t bitmapHeight = 0; int32_t bitmapHeight = 0;
if (!WebPGetInfo((uint8_t*)inputBuffer, len, &bitmapWidth, &bitmapHeight)) { if (!WebPGetInfo((uint8_t *)inputBuffer, len, &bitmapWidth, &bitmapHeight)) {
(*env)->ThrowNew(env, jclass_RuntimeException, "Invalid WebP format"); env->ThrowNew(jclass_RuntimeException, "Invalid WebP format");
return 0; return 0;
} }
if (options && (*env)->GetBooleanField(env, options, jclass_Options_inJustDecodeBounds) == JNI_TRUE) { if (options && env->GetBooleanField(options, jclass_Options_inJustDecodeBounds) == JNI_TRUE) {
(*env)->SetIntField(env, options, jclass_Options_outWidth, bitmapWidth); env->SetIntField(options, jclass_Options_outWidth, bitmapWidth);
(*env)->SetIntField(env, options, jclass_Options_outHeight, bitmapHeight); env->SetIntField(options, jclass_Options_outHeight, bitmapHeight);
return 1; return 1;
} }
if (!outputBitmap) { if (!outputBitmap) {
(*env)->ThrowNew(env, jclass_NullPointerException, "output bitmap can not be null"); env->ThrowNew(jclass_NullPointerException, "output bitmap can not be null");
return 0; return 0;
} }
AndroidBitmapInfo bitmapInfo; AndroidBitmapInfo bitmapInfo;
if (AndroidBitmap_getInfo(env, outputBitmap, &bitmapInfo) != ANDROID_BITMAP_RESUT_SUCCESS) { if (AndroidBitmap_getInfo(env, outputBitmap, &bitmapInfo) != ANDROID_BITMAP_RESUT_SUCCESS) {
(*env)->ThrowNew(env, jclass_RuntimeException, "Failed to get Bitmap information"); env->ThrowNew(jclass_RuntimeException, "Failed to get Bitmap information");
return 0; return 0;
} }
void *bitmapPixels = 0; void *bitmapPixels = 0;
if (AndroidBitmap_lockPixels(env, outputBitmap, &bitmapPixels) != ANDROID_BITMAP_RESUT_SUCCESS) { if (AndroidBitmap_lockPixels(env, outputBitmap, &bitmapPixels) != ANDROID_BITMAP_RESUT_SUCCESS) {
(*env)->ThrowNew(env, jclass_RuntimeException, "Failed to lock Bitmap pixels"); env->ThrowNew(jclass_RuntimeException, "Failed to lock Bitmap pixels");
return 0; return 0;
} }
if (!WebPDecodeRGBAInto((uint8_t*)inputBuffer, len, (uint8_t*)bitmapPixels, bitmapInfo.height * bitmapInfo.stride, bitmapInfo.stride)) { if (!WebPDecodeRGBAInto((uint8_t *) inputBuffer, len, (uint8_t *) bitmapPixels, bitmapInfo.height * bitmapInfo.stride, bitmapInfo.stride)) {
AndroidBitmap_unlockPixels(env, outputBitmap); AndroidBitmap_unlockPixels(env, outputBitmap);
(*env)->ThrowNew(env, jclass_RuntimeException, "Failed to decode webp image"); env->ThrowNew(jclass_RuntimeException, "Failed to decode webp image");
return 0; return 0;
} }
if (unpin && AndroidBitmap_unlockPixels(env, outputBitmap) != ANDROID_BITMAP_RESUT_SUCCESS) { if (unpin && AndroidBitmap_unlockPixels(env, outputBitmap) != ANDROID_BITMAP_RESUT_SUCCESS) {
(*env)->ThrowNew(env, jclass_RuntimeException, "Failed to unlock Bitmap pixels"); env->ThrowNew(jclass_RuntimeException, "Failed to unlock Bitmap pixels");
return 0; return 0;
} }
@ -712,16 +696,23 @@ JNIEXPORT jboolean Java_org_telegram_messenger_Utilities_loadWebpImage(JNIEnv *e
} }
#define SQUARE(i) ((i)*(i)) #define SQUARE(i) ((i)*(i))
inline static void zeroClearInt(int* p, size_t count) { memset(p, 0, sizeof(int) * count); }
JNIEXPORT void Java_org_telegram_messenger_Utilities_stackBlurBitmap(JNIEnv* env, jclass class, jobject bitmap, jint radius) { inline static void zeroClearInt(int *p, size_t count) {
if (radius < 1) return; memset(p, 0, sizeof(int) * count);
}
void Java_org_telegram_messenger_Utilities_stackBlurBitmap(JNIEnv *env, jclass clazz, jobject bitmap, jint radius) {
if (radius < 1) {
return;
}
AndroidBitmapInfo info; AndroidBitmapInfo info;
if (AndroidBitmap_getInfo(env, bitmap, &info) != ANDROID_BITMAP_RESULT_SUCCESS) if (AndroidBitmap_getInfo(env, bitmap, &info) != ANDROID_BITMAP_RESULT_SUCCESS) {
return; return;
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) }
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
return; return;
}
int w = info.width; int w = info.width;
int h = info.height; int h = info.height;
@ -749,17 +740,17 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_stackBlurBitmap(JNIEnv* env
zeroClearInt(vmin, MAX(w, h)); zeroClearInt(vmin, MAX(w, h));
// Large buffers // Large buffers
int *r = malloc(wh * sizeof(int)); int *r = new int[wh];
int *g = malloc(wh * sizeof(int)); int *g = new int[wh];
int *b = malloc(wh * sizeof(int)); int *b = new int[wh];
int *a = malloc(wh * sizeof(int)); int *a = new int[wh];
zeroClearInt(r, wh); zeroClearInt(r, wh);
zeroClearInt(g, wh); zeroClearInt(g, wh);
zeroClearInt(b, wh); zeroClearInt(b, wh);
zeroClearInt(a, wh); zeroClearInt(a, wh);
const size_t dvcount = 256 * divsum; const size_t dvcount = 256 * divsum;
int *dv = malloc(sizeof(int) * dvcount); int *dv = new int[dvcount];
int i; int i;
for (i = 0; (size_t) i < dvcount; i++) { for (i = 0; (size_t) i < dvcount; i++) {
dv[i] = (i / divsum); dv[i] = (i / divsum);
@ -769,7 +760,7 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_stackBlurBitmap(JNIEnv* env
int x, y; int x, y;
int *sir; int *sir;
int routsum, goutsum, boutsum, aoutsum; int routsum, goutsum, boutsum, aoutsum;
int rinsum, ginsum, binsum, ainsum; int rinsum, ginsum, binsum, ainsum;
int rsum, gsum, bsum, asum, p, yp; int rsum, gsum, bsum, asum, p, yp;
int stackpointer; int stackpointer;
int stackstart; int stackstart;
@ -955,38 +946,38 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_stackBlurBitmap(JNIEnv* env
} }
} }
free(r); delete[] r;
free(g); delete[] g;
free(b); delete[] b;
free(a); delete[] a;
free(dv); delete[] dv;
AndroidBitmap_unlockPixels(env, bitmap); AndroidBitmap_unlockPixels(env, bitmap);
} }
JNIEXPORT void Java_org_telegram_messenger_Utilities_drawDitheredGradient(JNIEnv* env, jclass class, jobject bitmap, jintArray colors, jint startX, jint startY, jint endX, jint endY) { void Java_org_telegram_messenger_Utilities_drawDitheredGradient(JNIEnv *env, jclass clazz, jobject bitmap, jintArray colors, jint startX, jint startY, jint endX, jint endY) {
AndroidBitmapInfo info; AndroidBitmapInfo info;
void* pixelsBuffer; void *pixelsBuffer;
int reason; int reason;
if ((reason = AndroidBitmap_getInfo(env, bitmap, &info)) != ANDROID_BITMAP_RESULT_SUCCESS) { if ((reason = AndroidBitmap_getInfo(env, bitmap, &info)) != ANDROID_BITMAP_RESULT_SUCCESS) {
(*env)->ThrowNew(env, jclass_RuntimeException, "AndroidBitmap_getInfo failed with a reason: " + reason); env->ThrowNew(jclass_RuntimeException, "AndroidBitmap_getInfo failed with a reason: " + reason);
return; return;
} }
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) { if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
(*env)->ThrowNew(env, jclass_RuntimeException, "Bitmap must be in ARGB_8888 format"); env->ThrowNew(jclass_RuntimeException, "Bitmap must be in ARGB_8888 format");
return; return;
} }
if ((reason = AndroidBitmap_lockPixels(env, bitmap, &pixelsBuffer)) != ANDROID_BITMAP_RESULT_SUCCESS) { if ((reason = AndroidBitmap_lockPixels(env, bitmap, &pixelsBuffer)) != ANDROID_BITMAP_RESULT_SUCCESS) {
(*env)->ThrowNew(env, jclass_RuntimeException, "AndroidBitmap_lockPixels failed with a reason: " + reason); env->ThrowNew(jclass_RuntimeException, "AndroidBitmap_lockPixels failed with a reason: " + reason);
return; return;
} }
uint8_t i, j, n; uint8_t i, j, n;
// gradient colors extracting // gradient colors extracting
jint *colorsBuffer = (*env)->GetIntArrayElements(env, colors, 0); jint *colorsBuffer = env->GetIntArrayElements(colors, 0);
uint8_t *colorsComponents = (uint8_t *) colorsBuffer; uint8_t *colorsComponents = (uint8_t *) colorsBuffer;
float colorsF[4][2]; float colorsF[4][2];
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@ -996,7 +987,7 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_drawDitheredGradient(JNIEnv
colorsF[n][j] = colorsComponents[j * 4 + i] / 255.F; colorsF[n][j] = colorsComponents[j * 4 + i] / 255.F;
} }
} }
(*env)->ReleaseIntArrayElements(env, colors, colorsBuffer, JNI_ABORT); env->ReleaseIntArrayElements(colors, colorsBuffer, JNI_ABORT);
// gradient vector // gradient vector
const int32_t vx = endX - startX; const int32_t vx = endX - startX;
@ -1004,9 +995,10 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_drawDitheredGradient(JNIEnv
const float vSquaredMag = vx * vx + vy * vy; const float vSquaredMag = vx * vx + vy * vy;
float noise, fraction, error, componentF; float noise, fraction, error, componentF;
float *pixelsComponentsF = malloc(info.height * info.stride * 4 * sizeof(float)); float *pixelsComponentsF = new float[info.height * info.stride * 4];
memset(pixelsComponentsF, 0, info.height * info.stride * 4 * sizeof(float)); memset(pixelsComponentsF, 0, info.height * info.stride * 4 * sizeof(float));
uint8_t *bitmapPixelsComponents = (uint8_t *) pixelsBuffer; uint8_t * bitmapPixelsComponents = (uint8_t * )
pixelsBuffer;
int32_t x, y; int32_t x, y;
int32_t offset; int32_t offset;
@ -1036,7 +1028,8 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_drawDitheredGradient(JNIEnv
// draw // draw
componentF = roundf(pixelsComponentsF[position] * 255.F); componentF = roundf(pixelsComponentsF[position] * 255.F);
bitmapPixelsComponents[position] = (uint8_t) componentF; bitmapPixelsComponents[position] = (uint8_t)
componentF;
// floyd-steinberg dithering // floyd-steinberg dithering
error = pixelsComponentsF[position] - componentF / 255.F; error = pixelsComponentsF[position] - componentF / 255.F;
@ -1056,10 +1049,12 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_drawDitheredGradient(JNIEnv
} }
} }
free(pixelsComponentsF); delete[] pixelsComponentsF;
if ((reason = AndroidBitmap_unlockPixels(env, bitmap)) != ANDROID_BITMAP_RESULT_SUCCESS) { if ((reason = AndroidBitmap_unlockPixels(env, bitmap)) != ANDROID_BITMAP_RESULT_SUCCESS) {
(*env)->ThrowNew(env, jclass_RuntimeException, "AndroidBitmap_unlockPixels failed with a reason: " + reason); env->ThrowNew(jclass_RuntimeException, "AndroidBitmap_unlockPixels failed with a reason: " + reason);
return; return;
} }
} }
}

View File

@ -1,8 +0,0 @@
#ifndef image_h
#define image_h
#include <jni.h>
jint imageOnJNILoad(JavaVM *vm, JNIEnv *env);
#endif

View File

@ -10,11 +10,11 @@
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <libtgvoip/client/android/org_telegram_messenger_voip_TgVoip.h> #include <libtgvoip/client/android/org_telegram_messenger_voip_TgVoip.h>
#include "image.h"
#include "libtgvoip/client/android/tg_voip_jni.h" #include "libtgvoip/client/android/tg_voip_jni.h"
int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env); int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env);
int videoOnJNILoad(JavaVM *vm, JNIEnv *env); int videoOnJNILoad(JavaVM *vm, JNIEnv *env);
int imageOnJNILoad(JavaVM *vm, JNIEnv *env);
//int tonLibOnLoad(JavaVM *vm, JNIEnv *env); //int tonLibOnLoad(JavaVM *vm, JNIEnv *env);
jint JNI_OnLoad(JavaVM *vm, void *reserved) { jint JNI_OnLoad(JavaVM *vm, void *reserved) {

View File

@ -535,6 +535,9 @@ LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
{ {
// 1. create layer item // 1. create layer item
for (auto &i : mLayerData->mChildren) { for (auto &i : mLayerData->mChildren) {
if (i->type() != LOTData::Type::Layer) {
continue;
}
LOTLayerData *layerModel = static_cast<LOTLayerData *>(i.get()); LOTLayerData *layerModel = static_cast<LOTLayerData *>(i.get());
auto layerItem = LOTCompItem::createLayerItem(layerModel); auto layerItem = LOTCompItem::createLayerItem(layerModel);
if (layerItem) mLayers.push_back(std::move(layerItem)); if (layerItem) mLayers.push_back(std::move(layerItem));

View File

@ -201,10 +201,13 @@ void LOTGradient::populate(VGradientStops &stops, int frameNo)
int size = gradData.mGradient.size(); int size = gradData.mGradient.size();
float * ptr = gradData.mGradient.data(); float * ptr = gradData.mGradient.data();
int colorPoints = mColorPoints; int colorPoints = mColorPoints;
if (colorPoints == -1) { // for legacy bodymovin (ref: lottie-android) if (colorPoints < 0 || colorPoints * 4 > size) { // for legacy bodymovin (ref: lottie-android)
colorPoints = size / 4; colorPoints = size / 4;
} }
int opacityArraySize = size - colorPoints * 4; int opacityArraySize = size - colorPoints * 4;
if (opacityArraySize % 2 != 0 || colorPoints > opacityArraySize / 2 && opacityArraySize < 4) {
opacityArraySize = 0;
}
float *opacityPtr = ptr + (colorPoints * 4); float *opacityPtr = ptr + (colorPoints * 4);
stops.clear(); stops.clear();
int j = 0; int j = 0;
@ -257,6 +260,9 @@ void LOTGradient::populate(VGradientStops &stops, int frameNo)
stops.push_back(std::make_pair(colorStop, color.toColor())); stops.push_back(std::make_pair(colorStop, color.toColor()));
} }
ptr += 4; ptr += 4;
if (stops.empty()) {
stops.push_back(std::make_pair(0.0f, VColor(255, 255, 255, 255)));
}
} }
} }

View File

@ -155,7 +155,7 @@ bool VGradientCache::generateGradientColorTable(const VGradientStops &stops,
colorTable[pos++] = curColor; colorTable[pos++] = curColor;
while (fpos <= curr->first) { while (fpos <= curr->first && pos < size) {
colorTable[pos] = colorTable[pos - 1]; colorTable[pos] = colorTable[pos - 1];
pos++; pos++;
fpos += incr; fpos += incr;

View File

@ -125,6 +125,10 @@ ConnectionsManager::~ConnectionsManager() {
close(epolFd); close(epolFd);
epolFd = 0; epolFd = 0;
} }
if (pipeFd != nullptr) {
delete[] pipeFd;
pipeFd = nullptr;
}
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex);
} }
@ -1645,6 +1649,7 @@ void ConnectionsManager::initDatacenters() {
if (datacenters.find(2) == datacenters.end()) { if (datacenters.find(2) == datacenters.end()) {
datacenter = new Datacenter(instanceNum, 2); datacenter = new Datacenter(instanceNum, 2);
datacenter->addAddressAndPort("149.154.167.51", 443, 0, ""); datacenter->addAddressAndPort("149.154.167.51", 443, 0, "");
datacenter->addAddressAndPort("95.161.76.100", 443, 0, "");
datacenter->addAddressAndPort("2001:67c:4e8:f002:0000:0000:0000:000a", 443, 1, ""); datacenter->addAddressAndPort("2001:67c:4e8:f002:0000:0000:0000:000a", 443, 1, "");
datacenters[2] = datacenter; datacenters[2] = datacenter;
} }
@ -2309,8 +2314,6 @@ void ConnectionsManager::processRequestQueue(uint32_t connectionTypes, uint32_t
if (genericConnection != nullptr && !sessionsToDestroy.empty() && genericConnection->getConnectionToken() != 0) { if (genericConnection != nullptr && !sessionsToDestroy.empty() && genericConnection->getConnectionToken() != 0) {
std::vector<int64_t>::iterator iter = sessionsToDestroy.begin(); std::vector<int64_t>::iterator iter = sessionsToDestroy.begin();
sessionsToDestroy.erase(iter);
if (abs(currentTime - lastDestroySessionRequestTime) > 2) { if (abs(currentTime - lastDestroySessionRequestTime) > 2) {
lastDestroySessionRequestTime = currentTime; lastDestroySessionRequestTime = currentTime;
TL_destroy_session *request = new TL_destroy_session(); TL_destroy_session *request = new TL_destroy_session();
@ -2324,6 +2327,7 @@ void ConnectionsManager::processRequestQueue(uint32_t connectionTypes, uint32_t
networkMessage->message->seqno = genericConnection->generateMessageSeqNo(false); networkMessage->message->seqno = genericConnection->generateMessageSeqNo(false);
addMessageToDatacenter(defaultDatacenter->getDatacenterId(), networkMessage, genericMessagesToDatacenters); addMessageToDatacenter(defaultDatacenter->getDatacenterId(), networkMessage, genericMessagesToDatacenters);
} }
sessionsToDestroy.erase(iter);
} }
} }

View File

@ -196,7 +196,7 @@ private:
std::vector<ConnectionSocket *> activeConnectionsCopy; std::vector<ConnectionSocket *> activeConnectionsCopy;
int epolFd; int epolFd;
int eventFd; int eventFd;
int *pipeFd; int *pipeFd = nullptr;
NativeByteBuffer *networkBuffer; NativeByteBuffer *networkBuffer;
requestsList requestsQueue; requestsList requestsQueue;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 922 B

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 926 B

After

Width:  |  Height:  |  Size: 927 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 969 B

After

Width:  |  Height:  |  Size: 969 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1012 B

After

Width:  |  Height:  |  Size: 1016 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 711 B

After

Width:  |  Height:  |  Size: 709 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 897 B

After

Width:  |  Height:  |  Size: 894 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 923 B

After

Width:  |  Height:  |  Size: 927 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 926 B

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1015 B

After

Width:  |  Height:  |  Size: 1015 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 845 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 932 B

After

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 932 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 803 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 761 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 764 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 707 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Some files were not shown because too many files have changed in this diff Show More