Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
immat0x1 committed Mar 14, 2023
1 parent 20f8182 commit 9ee2171
Show file tree
Hide file tree
Showing 48 changed files with 1,353 additions and 513 deletions.
125 changes: 0 additions & 125 deletions TMessagesProj/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,130 +49,6 @@ set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/b
add_library(libvpx STATIC IMPORTED)
set_target_properties(libvpx PROPERTIES IMPORTED_LOCATION ${CMAKE_HOME_DIRECTORY}/ffmpeg/${ANDROID_ABI}/libvpx.a)


#tgnet
add_library(mozjpeg STATIC
mozjpeg/cjpeg.c mozjpeg/cdjpeg.c mozjpeg/rdgif.c mozjpeg/rdppm.c mozjpeg/rdjpeg.c mozjpeg/rdswitch.c mozjpeg/rdbmp.c
mozjpeg/rdtarga.c mozjpeg/wrbmp.c mozjpeg/wrtarga.c mozjpeg/djpeg.c mozjpeg/cdjpeg.c mozjpeg/rdcolmap.c mozjpeg/rdswitch.c
mozjpeg/wrgif.c mozjpeg/wrppm.c mozjpeg/jpegtran.c mozjpeg/cdjpeg.c mozjpeg/rdswitch.c mozjpeg/transupp.c mozjpeg/turbojpeg.c
mozjpeg/jdatadst-tj.c mozjpeg/jdatasrc-tj.c mozjpeg/jcapimin.c mozjpeg/jcapistd.c mozjpeg/jccoefct.c mozjpeg/jccolor.c
mozjpeg/jcdctmgr.c mozjpeg/jchuff.c mozjpeg/jcext.c mozjpeg/jcicc.c mozjpeg/jcinit.c mozjpeg/jcmainct.c mozjpeg/jcmarker.c
mozjpeg/jcmaster.c mozjpeg/jcomapi.c mozjpeg/jcparam.c mozjpeg/jcphuff.c mozjpeg/jcprepct.c mozjpeg/jcsample.c
mozjpeg/jctrans.c mozjpeg/jdapimin.c mozjpeg/jdapistd.c mozjpeg/jdatadst.c mozjpeg/jdatasrc.c
mozjpeg/jdcoefct.c mozjpeg/jdcolor.c mozjpeg/jddctmgr.c mozjpeg/jdhuff.c mozjpeg/jdicc.c mozjpeg/jdinput.c
mozjpeg/jdmainct.c mozjpeg/jdmarker.c mozjpeg/jdmaster.c mozjpeg/jdmerge.c mozjpeg/jdphuff.c mozjpeg/jdpostct.c mozjpeg/jdsample.c
mozjpeg/jdtrans.c mozjpeg/jerror.c mozjpeg/jfdctflt.c mozjpeg/jfdctfst.c mozjpeg/jfdctint.c mozjpeg/jidctflt.c mozjpeg/jidctfst.c
mozjpeg/jidctint.c mozjpeg/jidctred.c mozjpeg/jquant1.c mozjpeg/jquant2.c mozjpeg/jutils.c mozjpeg/jmemmgr.c mozjpeg/jmemnobs.c)
target_compile_options(mozjpeg PUBLIC
-Os)
set_target_properties(mozjpeg PROPERTIES
ANDROID_ARM_MODE arm)
target_compile_definitions(mozjpeg PUBLIC
BMP_SUPPORTED GIF_SUPPORTED PPM_SUPPORTED TARGA_SUPPORTED)
target_include_directories(mozjpeg PUBLIC
mozjpeg
mozjpeg/simd/nasm)

if (${ANDROID_ABI} STREQUAL "armeabi-v7a")
target_sources(mozjpeg PRIVATE
mozjpeg/simd/arm/jsimd_neon.S
mozjpeg/simd/arm/jsimd.c)
target_compile_definitions(mozjpeg PUBLIC
SIZEOF_SIZE_T=4)
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
target_sources(mozjpeg PRIVATE
mozjpeg/simd/arm64/jsimd_neon.S
mozjpeg/simd/arm64/jsimd.c)
target_compile_definitions(mozjpeg PUBLIC
SIZEOF_SIZE_T=8)
elseif(${ANDROID_ABI} STREQUAL "x86")
set(CMAKE_ASM_NASM_COMPILER_ARG1 "${CMAKE_ASM_NASM_COMPILER_ARG1} -DPIC")
target_sources(mozjpeg PRIVATE
mozjpeg/simd/i386/jsimd.c
mozjpeg/simd/i386/jsimdcpu.asm
mozjpeg/simd/i386/jfdctflt-3dn.asm
mozjpeg/simd/i386/jidctflt-3dn.asm
mozjpeg/simd/i386/jquant-3dn.asm
mozjpeg/simd/i386/jccolor-mmx.asm
mozjpeg/simd/i386/jcgray-mmx.asm
mozjpeg/simd/i386/jcsample-mmx.asm
mozjpeg/simd/i386/jdcolor-mmx.asm
mozjpeg/simd/i386/jdmerge-mmx.asm
mozjpeg/simd/i386/jdsample-mmx.asm
mozjpeg/simd/i386/jfdctfst-mmx.asm
mozjpeg/simd/i386/jfdctint-mmx.asm
mozjpeg/simd/i386/jidctfst-mmx.asm
mozjpeg/simd/i386/jidctint-mmx.asm
mozjpeg/simd/i386/jidctred-mmx.asm
mozjpeg/simd/i386/jquant-mmx.asm
mozjpeg/simd/i386/jfdctflt-sse.asm
mozjpeg/simd/i386/jidctflt-sse.asm
mozjpeg/simd/i386/jquant-sse.asm
mozjpeg/simd/i386/jccolor-sse2.asm
mozjpeg/simd/i386/jcgray-sse2.asm
mozjpeg/simd/i386/jchuff-sse2.asm
mozjpeg/simd/i386/jcphuff-sse2.asm
mozjpeg/simd/i386/jcsample-sse2.asm
mozjpeg/simd/i386/jdcolor-sse2.asm
mozjpeg/simd/i386/jdmerge-sse2.asm
mozjpeg/simd/i386/jdsample-sse2.asm
mozjpeg/simd/i386/jfdctfst-sse2.asm
mozjpeg/simd/i386/jfdctint-sse2.asm
mozjpeg/simd/i386/jidctflt-sse2.asm
mozjpeg/simd/i386/jidctfst-sse2.asm
mozjpeg/simd/i386/jidctint-sse2.asm
mozjpeg/simd/i386/jidctred-sse2.asm
mozjpeg/simd/i386/jquantf-sse2.asm
mozjpeg/simd/i386/jquanti-sse2.asm
mozjpeg/simd/i386/jccolor-avx2.asm
mozjpeg/simd/i386/jcgray-avx2.asm
mozjpeg/simd/i386/jcsample-avx2.asm
mozjpeg/simd/i386/jdcolor-avx2.asm
mozjpeg/simd/i386/jdmerge-avx2.asm
mozjpeg/simd/i386/jdsample-avx2.asm
mozjpeg/simd/i386/jfdctint-avx2.asm
mozjpeg/simd/i386/jidctint-avx2.asm
mozjpeg/simd/i386/jquanti-avx2.asm)
target_compile_definitions(mozjpeg PUBLIC
SIZEOF_SIZE_T=4)
elseif(${ANDROID_ABI} STREQUAL "x86_64")
set(CMAKE_ASM_NASM_COMPILER_ARG1 "${CMAKE_ASM_NASM_COMPILER_ARG1} -DPIC")
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DELF")
set(CMAKE_ASM_NASM_DEBUG_FORMAT "dwarf2")
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -D__x86_64__")
target_sources(mozjpeg PRIVATE
mozjpeg/simd/x86_64/jsimd.c
mozjpeg/simd/x86_64/jsimdcpu.asm
mozjpeg/simd/x86_64/jfdctflt-sse.asm
mozjpeg/simd/x86_64/jccolor-sse2.asm
mozjpeg/simd/x86_64/jcgray-sse2.asm
mozjpeg/simd/x86_64/jchuff-sse2.asm
mozjpeg/simd/x86_64/jcphuff-sse2.asm
mozjpeg/simd/x86_64/jcsample-sse2.asm
mozjpeg/simd/x86_64/jdcolor-sse2.asm
mozjpeg/simd/x86_64/jdmerge-sse2.asm
mozjpeg/simd/x86_64/jdsample-sse2.asm
mozjpeg/simd/x86_64/jfdctfst-sse2.asm
mozjpeg/simd/x86_64/jfdctint-sse2.asm
mozjpeg/simd/x86_64/jidctflt-sse2.asm
mozjpeg/simd/x86_64/jidctfst-sse2.asm
mozjpeg/simd/x86_64/jidctint-sse2.asm
mozjpeg/simd/x86_64/jidctred-sse2.asm
mozjpeg/simd/x86_64/jquantf-sse2.asm
mozjpeg/simd/x86_64/jquanti-sse2.asm
mozjpeg/simd/x86_64/jccolor-avx2.asm
mozjpeg/simd/x86_64/jcgray-avx2.asm
mozjpeg/simd/x86_64/jcsample-avx2.asm
mozjpeg/simd/x86_64/jdcolor-avx2.asm
mozjpeg/simd/x86_64/jdmerge-avx2.asm
mozjpeg/simd/x86_64/jdsample-avx2.asm
mozjpeg/simd/x86_64/jfdctint-avx2.asm
mozjpeg/simd/x86_64/jidctint-avx2.asm
mozjpeg/simd/x86_64/jquanti-avx2.asm)
target_compile_definitions(mozjpeg PUBLIC
SIZEOF_SIZE_T=8)
endif()

#tgnet
add_library(tgnet STATIC
tgnet/ApiScheme.cpp
Expand Down Expand Up @@ -714,7 +590,6 @@ target_link_libraries(${NATIVE_LIB}
tgvoip
tgcalls
tgcalls_tp
mozjpeg
tgnet
lz4
webp
Expand Down
106 changes: 0 additions & 106 deletions TMessagesProj/jni/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <cmath>
#include <unistd.h>
#include <android/bitmap.h>
#include <string>
#include <mozjpeg/java/org_libjpegturbo_turbojpeg_TJ.h>
#include <mozjpeg/jpeglib.h>
#include <tgnet/FileLog.h>
#include <vector>
Expand Down Expand Up @@ -1065,110 +1063,6 @@ 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);
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);
for (int i = 0; i < 4; i++) {
Expand Down
35 changes: 34 additions & 1 deletion TMessagesProj/jni/tgnet/ConnectionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,42 @@ ConnectionsManager& ConnectionsManager::getInstance(int32_t instanceNum) {
static ConnectionsManager instance3(3);
return instance3;
case 4:
default:
static ConnectionsManager instance4(4);
return instance4;
case 5:
static ConnectionsManager instance5(5);
return instance5;
case 6:
static ConnectionsManager instance6(6);
return instance6;
case 7:
static ConnectionsManager instance7(7);
return instance7;
case 8:
static ConnectionsManager instance8(8);
return instance8;
case 9:
static ConnectionsManager instance9(9);
return instance9;
case 10:
static ConnectionsManager instance10(10);
return instance10;
case 11:
static ConnectionsManager instance11(11);
return instance11;
case 12:
static ConnectionsManager instance12(12);
return instance12;
case 13:
static ConnectionsManager instance13(13);
return instance13;
case 14:
static ConnectionsManager instance14(14);
return instance14;
case 15:
default:
static ConnectionsManager instance15(15);
return instance15;
}
}

Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/jni/tgnet/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define DOWNLOAD_CONNECTIONS_COUNT 2
#define UPLOAD_CONNECTIONS_COUNT 4
#define CONNECTION_BACKGROUND_KEEP_TIME 10000
#define MAX_ACCOUNT_COUNT 5
#define MAX_ACCOUNT_COUNT 16
#define USE_DELEGATE_HOST_RESOLVE

#define USE_IPV4_ONLY 0
Expand Down
Binary file modified TMessagesProj/libs/arm64-v8a/libtmessages.43.so
Binary file not shown.
Loading

0 comments on commit 9ee2171

Please sign in to comment.