Skip to content

Instantly share code, notes, and snippets.

View michelerenzullo's full-sized avatar

Michele Renzullo michelerenzullo

View GitHub Profile
@michelerenzullo
michelerenzullo / Reflect_101.cpp
Last active October 14, 2022 12:22
Reflect 101 a 2D matrix or multi channel image, performant as cv::copyMakeBorder, and it receives as input the pad for top,bottom,left,right margin
template<typename T, int C>
void Reflect_101(const T* const input, T* output, int pad_top, int pad_bottom, int pad_left, int pad_right, const int* original_size) {
// This function padd a 2D matrix or a multichannel image with the specified top,bottom,left,right pad and it applies
// a reflect 101 like cv::copyMakeBorder, the main (and only) difference is the following constraint to prevent out of buffer reading
pad_top = std::min(pad_top, original_size[0] - 1);
pad_bottom = std::min(pad_bottom, original_size[0] - 1);
pad_left = std::min(pad_left, original_size[1] - 1);
pad_right = std::min(pad_right, original_size[1] - 1);
@michelerenzullo
michelerenzullo / deinterleave_RGB_blocks.cpp
Last active November 1, 2022 18:40
Cache-friendly deinterleave RGB image - Comparison between standard and deinterleave for blocks
// DEINTERLEAVE RGB Image
template<typename T, typename U>
inline void deinterleave_BGR(const T* const interleaved_BGR, U** const deinterleaved_BGR, const uint32_t nsize) {
constexpr uint32_t block = 262144 / (3 * std::max(sizeof(T), sizeof(U)));
constexpr float round = std::is_integral_v<U> ? std::is_integral_v<T> ? 0 : 0.5f : 0;
#pragma omp parallel for
for (int32_t x = 0; x < nsize; x += block)
@michelerenzullo
michelerenzullo / FBB_reflection.cpp
Last active September 28, 2022 00:34
Fast Box Blur + reflected padding without memory waste repo: https://github.com/michelerenzullo/FastBoxBlur
template<typename T, int C>
void horizontal_blur_kernel_reflect(const T* in, T* out, const int w, const int h, const int ksize)
{
// change the local variable types depending on the template type for faster calculations
using calc_type = std::conditional_t<std::is_integral_v<T>, uint32_t, float>;
int r = 0.5f * (ksize - 1);
r = std::min(r, w - 1);
const float iarr = 1.f / (r + r + 1);
@michelerenzullo
michelerenzullo / random.smali
Last active June 25, 2022 02:59
smali function to patch bytes in a target library - SSL Unpinning in Workplace 372.0.0.20.107-378066467 arm64 by Meta
.method public static patcher()V
.locals 4
.line 15
new-instance v0, Ljava/io/File;
const-string v1, "/data/data/com.facebook.work/lib-compressed/libxplat_fizz_client_protocolAndroid.so"
invoke-direct {v0, v1}, Ljava/io/File;-><init>(Ljava/lang/String;)V
.line 16
@michelerenzullo
michelerenzullo / invoke_copyFiles.smali
Created January 17, 2021 17:22
invoke copyFiles function with the 3 arguments, v169.3.0.30.135
iget-object v3, v0, LX/AzF;->A0H:Landroid/content/Context;
new-instance v1, Ljava/lang/StringBuilder;
invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
invoke-virtual {v3}, Landroid/content/Context;->getFilesDir()Ljava/io/File;
move-result-object v2
invoke-virtual {v2}, Ljava/io/File;->toString()Ljava/lang/String;
move-result-object v2
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
const-string v2, "/ard_fe/"
invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
@michelerenzullo
michelerenzullo / exportList_function.smali
Last active March 10, 2021 21:41
smali exportList function
.method public static exportList(Ljava/lang/String;Ljava/lang/String;)V
.registers 8
:try_start_0
new-instance v0, Ljava/io/File;
new-instance v1, Ljava/lang/StringBuilder;
invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
invoke-static {}, Landroid/os/Environment;->getExternalStorageDirectory()Ljava/io/File;
@michelerenzullo
michelerenzullo / copyFiles_function.smali
Last active March 10, 2021 21:42
smali copyFiles function
.method public static copyFiles(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
.registers 11
new-instance v0, Ljava/io/File;
invoke-static {}, Landroid/os/Environment;->getExternalStorageDirectory()Ljava/io/File;
move-result-object v1
const-string v2, "Download/Effects"