Skip to content

Commit 85161a6

Browse files
committed
ncnn mat pixel affine family
1 parent 322095e commit 85161a6

7 files changed

Lines changed: 698 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ option(NCNN_THREADS "build with threads" ON)
4242
option(NCNN_BENCHMARK "print benchmark information for every layer" OFF)
4343
option(NCNN_PIXEL "convert and resize from/to image pixel" ON)
4444
option(NCNN_PIXEL_ROTATE "rotate image pixel orientation" ON)
45+
option(NCNN_PIXEL_AFFINE "warp affine image pixel" ON)
4546
option(NCNN_CMAKE_VERBOSE "print verbose cmake messages" OFF)
4647
option(NCNN_VULKAN "vulkan compute support" OFF)
4748
option(NCNN_VULKAN_ONLINE_SPIRV "online SPIR-V module compilation" ON)
@@ -83,7 +84,9 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc)")
8384
set(NCNN_TARGET_ARCH powerpc)
8485
else()
8586
set(NCNN_TARGET_ARCH x86)
86-
option(NCNN_AVX2 "optimize x86 platform with avx2" ON)
87+
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
88+
option(NCNN_AVX2 "optimize x86 platform with avx2" ON)
89+
endif()
8790
endif()
8891

8992
message(STATUS "Target arch: ${NCNN_TARGET_ARCH}")

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(ncnn_SRCS
3131
layer.cpp
3232
mat.cpp
3333
mat_pixel.cpp
34+
mat_pixel_affine.cpp
3435
mat_pixel_resize.cpp
3536
mat_pixel_rotate.cpp
3637
modelbin.cpp

src/mat.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,26 @@ void kanna_rotate_c4(const unsigned char* src, int srcw, int srch, int srcstride
571571
// image pixel kanna rotate, convenient wrapper for yuv420sp(nv21/nv12)
572572
void kanna_rotate_yuv420sp(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, int type);
573573
#endif // NCNN_PIXEL_ROTATE
574+
#if NCNN_PIXEL_AFFINE
575+
// resolve affine transform matrix from rotation angle, scale factor and x y offset
576+
void get_rotation_matrix(float angle, float scale, float dx, float dy, float* tm);
577+
// resolve affine transform matrix from two set of points, num_point must be >= 2
578+
void get_affine_transform(const float* points_from, const float* points_to, int num_point, float* tm);
579+
// resolve the inversion affine transform matrix
580+
void invert_affine_transform(const float* tm, float* tm_inv);
581+
// image pixel bilinear warpaffine, set -233 for transparent border color
582+
void warpaffine_bilinear_c1(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int v = 0);
583+
void warpaffine_bilinear_c2(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int v = 0);
584+
void warpaffine_bilinear_c3(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int v = 0);
585+
void warpaffine_bilinear_c4(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int v = 0);
586+
// image pixel bilinear warpaffine with stride(bytes-per-row) parameter, set -233 for transparent border color
587+
void warpaffine_bilinear_c1(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, const float* tm, int v = 0);
588+
void warpaffine_bilinear_c2(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, const float* tm, int v = 0);
589+
void warpaffine_bilinear_c3(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, const float* tm, int v = 0);
590+
void warpaffine_bilinear_c4(const unsigned char* src, int srcw, int srch, int srcstride, unsigned char* dst, int w, int h, int stride, const float* tm, int v = 0);
591+
// image pixel bilinear warpaffine, convenient wrapper for yuv420sp(nv21/nv12), set -233 for transparent border color
592+
void warpaffine_bilinear_yuv420sp(const unsigned char* src, int srcw, int srch, unsigned char* dst, int w, int h, const float* tm, int v = 0);
593+
#endif // NCNN_PIXEL_AFFINE
574594

575595
// type conversion
576596
// convert float to half precision floating point

0 commit comments

Comments
 (0)