Skip to content

Commit

Permalink
Merge remote-tracking branch 'official/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Sep 11, 2024
2 parents 6fed7fd + 1e89182 commit 0471cb8
Show file tree
Hide file tree
Showing 8,388 changed files with 20,778 additions and 39,585 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "TMessagesProj/jni/libwebp"]
path = TMessagesProj/jni/libwebp
url = https://github.com/webmproject/libwebp
[submodule "TMessagesProj/jni/boringssl"]
path = TMessagesProj/jni/boringssl
url = https://github.com/google/boringssl
Expand Down
16 changes: 7 additions & 9 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ repositories {
}
}

def verName = "11.0.0"
def verCode = 1193
def verName = APP_VERSION_NAME
def verCode = 1194


def officialVer = "11.0.0"
def officialCode = 5143
def officialVer = APP_VERSION_NAME
def officialCode = APP_VERSION_CODE

def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json")

Expand Down Expand Up @@ -83,7 +83,7 @@ def nativeTarget = System.getenv("NATIVE_TARGET")
if (nativeTarget == null) nativeTarget = ""

android {
compileSdkVersion 33
compileSdkVersion 34
ndkVersion rootProject.ext.ndkVersion

defaultConfig.applicationId = "xyz.nextalone.nagram"
Expand Down Expand Up @@ -111,7 +111,7 @@ android {
defaultConfig {
minSdkVersion 21
//noinspection ExpiredTargetSdkVersion,OldTargetApi
targetSdkVersion 33
targetSdkVersion 34

versionName verName
versionCode verCode
Expand Down Expand Up @@ -276,7 +276,7 @@ dependencies {
//noinspection GradleDependency
implementation "com.googlecode.mp4parser:isoparser:1.0.6"

implementation "com.google.code.gson:gson:2.10"
implementation "com.google.code.gson:gson:2.11.0"
implementation "org.osmdroid:osmdroid-android:6.1.10"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0"
Expand Down Expand Up @@ -329,8 +329,6 @@ dependencies {
implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3'
// add splash screen
implementation("androidx.core:core-splashscreen:1.0.1")
// add for music tag flac...
implementation 'org:jaudiotagger:2.0.3'
// add for auto translate
implementation 'com.google.mlkit:language-id:17.0.5'
// add for emoji
Expand Down
373 changes: 123 additions & 250 deletions TMessagesProj/jni/CMakeLists.txt

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion TMessagesProj/jni/build_ffmpeg_clang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,21 @@ function build_one {
--enable-avresample \
--enable-swscale \
--enable-protocol=file \
--enable-decoder=opus \
--enable-decoder=h264 \
--enable-decoder=h265 \
--enable-decoder=mpeg4 \
--enable-decoder=mjpeg \
--enable-decoder=gif \
--enable-decoder=alac \
--enable-decoder=opus \
--enable-decoder=mp3 \
--enable-decoder=aac \
--enable-demuxer=mov \
--enable-demuxer=gif \
--enable-demuxer=ogg \
--enable-demuxer=matroska \
--enable-demuxer=mp3 \
--enable-demuxer=aac \
--enable-hwaccels \
$ADDITIONAL_CONFIGURE_FLAG

Expand Down
272 changes: 109 additions & 163 deletions TMessagesProj/jni/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
#include <unistd.h>
#include <android/bitmap.h>
#include <string>
#include <mozjpeg/java/org_libjpegturbo_turbojpeg_TJ.h>
#include <mozjpeg/jpeglib.h>
//#include <mozjpeg/java/org_libjpegturbo_turbojpeg_TJ.h>
//#include <mozjpeg/jpeglib.h>
#include <tgnet/FileLog.h>
#include <vector>
#include <algorithm>
#include "webp/decode.h"
#include "webp/encode.h"
#include "mozjpeg/turbojpeg.h"
//#include "mozjpeg/turbojpeg.h"
#include "c_utils.h"

extern "C" {
Expand Down Expand Up @@ -654,58 +652,6 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_unpinBitmap(JNIEnv *env, jc
AndroidBitmap_unlockPixels(env, bitmap);
}

JNIEXPORT jboolean Java_org_telegram_messenger_Utilities_loadWebpImage(JNIEnv *env, jclass clazz, jobject outputBitmap, jobject buffer, jint len, jobject options, jboolean unpin) {
if (!buffer) {
env->ThrowNew(jclass_NullPointerException, "Input buffer can not be null");
return 0;
}

jbyte *inputBuffer = (jbyte *) env->GetDirectBufferAddress(buffer);

int32_t bitmapWidth = 0;
int32_t bitmapHeight = 0;
if (!WebPGetInfo((uint8_t *)inputBuffer, len, &bitmapWidth, &bitmapHeight)) {
env->ThrowNew(jclass_RuntimeException, "Invalid WebP format");
return 0;
}

if (options && env->GetBooleanField(options, jclass_Options_inJustDecodeBounds) == JNI_TRUE) {
env->SetIntField(options, jclass_Options_outWidth, bitmapWidth);
env->SetIntField(options, jclass_Options_outHeight, bitmapHeight);
return 1;
}

if (!outputBitmap) {
env->ThrowNew(jclass_NullPointerException, "output bitmap can not be null");
return 0;
}

AndroidBitmapInfo bitmapInfo;
if (AndroidBitmap_getInfo(env, outputBitmap, &bitmapInfo) != ANDROID_BITMAP_RESUT_SUCCESS) {
env->ThrowNew(jclass_RuntimeException, "Failed to get Bitmap information");
return 0;
}

void *bitmapPixels = nullptr;
if (AndroidBitmap_lockPixels(env, outputBitmap, &bitmapPixels) != ANDROID_BITMAP_RESUT_SUCCESS) {
env->ThrowNew(jclass_RuntimeException, "Failed to lock Bitmap pixels");
return 0;
}

if (!WebPDecodeRGBAInto((uint8_t *) inputBuffer, len, (uint8_t *) bitmapPixels, bitmapInfo.height * bitmapInfo.stride, bitmapInfo.stride)) {
AndroidBitmap_unlockPixels(env, outputBitmap);
env->ThrowNew(jclass_RuntimeException, "Failed to decode webp image");
return 0;
}

if (unpin && AndroidBitmap_unlockPixels(env, outputBitmap) != ANDROID_BITMAP_RESUT_SUCCESS) {
env->ThrowNew(jclass_RuntimeException, "Failed to unlock Bitmap pixels");
return 0;
}

return 1;
}

#define SQUARE(i) ((i)*(i))

inline static void zeroClearInt(int *p, size_t count) {
Expand Down Expand Up @@ -1068,112 +1014,112 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_drawDitheredGradient(JNIEnv
}
}

JNIEXPORT jint Java_org_telegram_messenger_Utilities_saveProgressiveJpeg(JNIEnv *env, jclass clazz, jobject bitmap, jint width, jint height, jint stride, jint quality, jstring path) {
if (!bitmap || !path || !width || !height || !stride || stride != width * 4) {
return 0;
}
void *pixels = 0;
if (AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0) {
return 0;
}
if (pixels == NULL) {
return 0;
}
tjhandle handle = 0;
if ((handle = tjInitCompress()) == NULL) {
return 0;
}
const char *pathStr = env->GetStringUTFChars(path, 0);
if (pathStr == NULL) {
return 0;
}
std::string filePath = std::string(pathStr);
if (pathStr != 0) {
env->ReleaseStringUTFChars(path, pathStr);
}

const char *enabledValue = "1";
const char *disabledValue = "0";
setenv("TJ_OPTIMIZE", enabledValue, 1);
setenv("TJ_ARITHMETIC", disabledValue, 1);
setenv("TJ_PROGRESSIVE", enabledValue, 1);
setenv("TJ_REVERT", enabledValue, 1);

TJSAMP jpegSubsamp = TJSAMP::TJSAMP_420;
jint buffSize = (jint) tjBufSize(width, height, jpegSubsamp);
unsigned char *jpegBuf = new unsigned char[buffSize];
unsigned char *srcBuf = (unsigned char *) pixels;

int pf = org_libjpegturbo_turbojpeg_TJ_PF_RGBA;

jsize actualPitch = width * tjPixelSize[pf];
jsize arraySize = (height - 1) * actualPitch + (width) * tjPixelSize[pf];
unsigned long jpegSize = tjBufSize(width, height, jpegSubsamp);

if (tjCompress2(handle, srcBuf, width, stride, height, pf, &jpegBuf, &jpegSize, jpegSubsamp, quality, TJFLAG_ACCURATEDCT | TJFLAG_PROGRESSIVE | TJFLAG_NOREALLOC) == 0) {
FILE *f = fopen(filePath.c_str(), "wb");
if (f && fwrite(jpegBuf, sizeof(unsigned char), jpegSize, f) == jpegSize) {
fflush(f);
fsync(fileno(f));
} else {
jpegSize = -1;
}
fclose(f);
} else {
jpegSize = -1;
}
delete[] jpegBuf;
tjDestroy(handle);
AndroidBitmap_unlockPixels(env, bitmap);
return jpegSize;

/*struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
const char *pathStr = env->GetStringUTFChars(path, 0);
std::string filePath = std::string(pathStr);
if (pathStr != 0) {
env->ReleaseStringUTFChars(path, pathStr);
}
uint8_t *outBuffer = NULL;
unsigned long outSize = 0;
jpeg_mem_dest(&cinfo, &outBuffer, &outSize);
unsigned char *srcBuf = (unsigned char *) pixels;
cinfo.image_width = (uint32_t) width;
cinfo.image_height = (uint32_t) height;
cinfo.input_components = 4;
cinfo.in_color_space = JCS_EXT_RGBA;
jpeg_c_set_int_param(&cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST);
jpeg_set_defaults(&cinfo);
cinfo.arith_code = FALSE;
cinfo.dct_method = JDCT_ISLOW;
cinfo.optimize_coding = TRUE;
jpeg_set_quality(&cinfo, 78, 1);
jpeg_simple_progression(&cinfo);
jpeg_start_compress(&cinfo, 1);
JSAMPROW rowPointer[1];
while (cinfo.next_scanline < cinfo.image_height) {
rowPointer[0] = (JSAMPROW) (srcBuf + cinfo.next_scanline * stride);
jpeg_write_scanlines(&cinfo, rowPointer, 1);
}
jpeg_finish_compress(&cinfo);
FILE *f = fopen(filePath.c_str(), "wb");
if (f && fwrite(outBuffer, sizeof(uint8_t), outSize, f) == outSize) {
fflush(f);
fsync(fileno(f));
}
fclose(f);
jpeg_destroy_compress(&cinfo);
return outSize;*/
}
//JNIEXPORT jint Java_org_telegram_messenger_Utilities_saveProgressiveJpeg(JNIEnv *env, jclass clazz, jobject bitmap, jint width, jint height, jint stride, jint quality, jstring path) {
// if (!bitmap || !path || !width || !height || !stride || stride != width * 4) {
// return 0;
// }
// void *pixels = 0;
// if (AndroidBitmap_lockPixels(env, bitmap, &pixels) < 0) {
// return 0;
// }
// if (pixels == NULL) {
// return 0;
// }
// tjhandle handle = 0;
// if ((handle = tjInitCompress()) == NULL) {
// return 0;
// }
// const char *pathStr = env->GetStringUTFChars(path, 0);
// if (pathStr == NULL) {
// return 0;
// }
// std::string filePath = std::string(pathStr);
// if (pathStr != 0) {
// env->ReleaseStringUTFChars(path, pathStr);
// }
//
// const char *enabledValue = "1";
// const char *disabledValue = "0";
// setenv("TJ_OPTIMIZE", enabledValue, 1);
// setenv("TJ_ARITHMETIC", disabledValue, 1);
// setenv("TJ_PROGRESSIVE", enabledValue, 1);
// setenv("TJ_REVERT", enabledValue, 1);
//
// TJSAMP jpegSubsamp = TJSAMP::TJSAMP_420;
// jint buffSize = (jint) tjBufSize(width, height, jpegSubsamp);
// unsigned char *jpegBuf = new unsigned char[buffSize];
// unsigned char *srcBuf = (unsigned char *) pixels;
//
// int pf = org_libjpegturbo_turbojpeg_TJ_PF_RGBA;
//
// jsize actualPitch = width * tjPixelSize[pf];
// jsize arraySize = (height - 1) * actualPitch + (width) * tjPixelSize[pf];
// unsigned long jpegSize = tjBufSize(width, height, jpegSubsamp);
//
// if (tjCompress2(handle, srcBuf, width, stride, height, pf, &jpegBuf, &jpegSize, jpegSubsamp, quality, TJFLAG_ACCURATEDCT | TJFLAG_PROGRESSIVE | TJFLAG_NOREALLOC) == 0) {
// FILE *f = fopen(filePath.c_str(), "wb");
// if (f && fwrite(jpegBuf, sizeof(unsigned char), jpegSize, f) == jpegSize) {
// fflush(f);
// fsync(fileno(f));
// } else {
// jpegSize = -1;
// }
// fclose(f);
// } else {
// jpegSize = -1;
// }
// delete[] jpegBuf;
// tjDestroy(handle);
// AndroidBitmap_unlockPixels(env, bitmap);
// return jpegSize;
//
// /*struct jpeg_compress_struct cinfo;
// struct jpeg_error_mgr jerr;
// cinfo.err = jpeg_std_error(&jerr);
// jpeg_create_compress(&cinfo);
//
// const char *pathStr = env->GetStringUTFChars(path, 0);
// std::string filePath = std::string(pathStr);
// if (pathStr != 0) {
// env->ReleaseStringUTFChars(path, pathStr);
// }
//
// uint8_t *outBuffer = NULL;
// unsigned long outSize = 0;
// jpeg_mem_dest(&cinfo, &outBuffer, &outSize);
// unsigned char *srcBuf = (unsigned char *) pixels;
//
// cinfo.image_width = (uint32_t) width;
// cinfo.image_height = (uint32_t) height;
// cinfo.input_components = 4;
// cinfo.in_color_space = JCS_EXT_RGBA;
// jpeg_c_set_int_param(&cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST);
// jpeg_set_defaults(&cinfo);
// cinfo.arith_code = FALSE;
// cinfo.dct_method = JDCT_ISLOW;
// cinfo.optimize_coding = TRUE;
// jpeg_set_quality(&cinfo, 78, 1);
// jpeg_simple_progression(&cinfo);
// jpeg_start_compress(&cinfo, 1);
//
// JSAMPROW rowPointer[1];
// while (cinfo.next_scanline < cinfo.image_height) {
// rowPointer[0] = (JSAMPROW) (srcBuf + cinfo.next_scanline * stride);
// jpeg_write_scanlines(&cinfo, rowPointer, 1);
// }
//
// jpeg_finish_compress(&cinfo);
//
// FILE *f = fopen(filePath.c_str(), "wb");
// if (f && fwrite(outBuffer, sizeof(uint8_t), outSize, f) == outSize) {
// fflush(f);
// fsync(fileno(f));
// }
// fclose(f);
//
// jpeg_destroy_compress(&cinfo);
// return outSize;*/
//}

std::vector<std::pair<float, float>> gatherPositions(std::vector<std::pair<float, float>> list, int phase) {
std::vector<std::pair<float, float>> result(4);
Expand Down
1 change: 0 additions & 1 deletion TMessagesProj/jni/libwebp
Submodule libwebp deleted from 4619a4
Loading

0 comments on commit 0471cb8

Please sign in to comment.