Changeset 821
- Timestamp:
- May 6, 2016, 3:06:29 PM (9 years ago)
- Location:
- soft/giet_vm/applications/rosenfeld
- Files:
-
- 5 added
- 6 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/Makefile
r805 r821 31 31 C_DEBUG_FLAGS = -O0 32 32 C_OPTIM_FLAGS = -std=c99 -O2 -fstrict-aliasing 33 C_OS_FLAGS = -DGTODay -DTARGET_OS=LINUX 33 C_OS_FLAGS = -DGTODay -DTARGET_OS=LINUX -D_GNU_SOURCE 34 34 C_CONFIG_FLAGS = -DCLI 35 35 C_INC_FLAGS = -I$(INC_PATH) -Inrc2/include 36 36 CFLAGSCPU = 37 37 38 LDFLAGS := -Lnrc2 -Wl,--start-group -lnrc2x -lm - Wl,--end-group38 LDFLAGS := -Lnrc2 -Wl,--start-group -lnrc2x -lm -lpthread -Wl,--end-group 39 39 40 40 endif … … 52 52 53 53 SRC_FILE = $(wildcard $(SRC_PATH)/*.c) 54 INC_FILE = $(wildcard $( SRC_PATH)/*.h)54 INC_FILE = $(wildcard $(INC_PATH)/*.h) 55 55 56 56 #SRC = $(addprefix $(SRC_PATH)/,$(FILE)) … … 66 66 $(LD) -o $@ $^ $(LDFLAGS) 67 67 68 $(OBJ_PATH)/%.o: $(SRC_PATH)/%.c $(INC_FILE) nrc2/libnrc2x.a ../../build/libs/libuser.a 68 $(OBJ_PATH)/%.o: $(SRC_PATH)/%.c $(INC_FILE) nrc2/libnrc2x.a ../../build/libs/libuser.a nrc2/include/nrc_os_config.h 69 69 $(CC) -c $(CFLAGS) -o $@ $< 70 70 -
soft/giet_vm/applications/rosenfeld/include/ecc_common.h
r772 r821 6 6 #define _ECC_COMMON_H_ 7 7 8 #ifdef __cplusplus 9 #pragma message ("C++") 10 extern "C" { 11 #endif 12 13 //#include <stdio.h> 14 //#include <stdlib.h> 15 //#include <math.h> 16 17 //#include "def.h" 18 //#include "nrc.h" 19 //#include "util.h" 20 //#include "palette.h" 8 #include <stdbool.h> 21 9 22 10 // ------------------------------------------ 23 11 // -- valeur des parametres des benchmarks -- 24 12 // ------------------------------------------ 25 //#define ENABLE_GLOBAL_PARAM 26 //#ifdef ENABLE_GLOBAL_PARAM 13 27 14 #define ECC_G0 1 28 15 #define ECC_G1 16 … … 207 194 uint32 mt19937_uint32(uint32 a, uint32 b); 208 195 209 BOOLstrto_Bool(char *str);196 bool strto_Bool(char *str); 210 197 211 198 void check_no_write(uint32 **T, int i0, int i1, int j0, int j1); -
soft/giet_vm/applications/rosenfeld/include/ecc_features.h
r772 r821 16 16 #define __ECC_FEATURES_H__ 17 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #ifdef VERBOSE_PRAGMA 23 //#pragma message("- include ecc_features.h") 24 #endif 25 26 #define REGION_STATS1 27 28 //#define REGION_STATS2 29 //#define REGION_STATS3 30 //#define REGION_STATS4 31 32 #define Warning 33 #define Error 18 #if PARMERGE 19 #include <pthread.h> 20 #endif 21 34 22 35 23 // ------------------------------------------------------------------------ … … 46 34 uint32 S; 47 35 48 uint16 x; // abscisse du centre d'inertie x = Sx / S49 uint16 y; // ordonnee du centre d'inertie y = Sy / S50 51 36 uint32 Sx; 52 37 uint32 Sy; 53 54 #ifdef REGION_STATS2 55 //uint64 Sx2; 56 //uint64 Sxy; 57 //uint64 Sy2; 58 59 //uint32 Mx2; 60 //uint32 Mxy; 61 //uint32 My2; 62 63 double teta; // direction principale 64 #endif 65 66 #ifdef REGION_STATS3 67 //uint64 Sx3; 68 //uint64 Sx2y; 69 //uint64 Sxy2; 70 //uint64 Sy3; 71 72 //uint64 Mx3; 73 //uint64 Mx2y; 74 //uint64 Mxy2; 75 //uint64 My3; 76 #endif 38 #if PARMERGE 39 pthread_spinlock_t lock; 40 #endif 41 77 42 } RegionStats; 78 43 … … 112 77 */ 113 78 79 80 114 81 /* ------------------------------ */ 115 82 /* --- RegionStats after 2009 --- */ … … 118 85 119 86 RegionStats* RegionStatsVector (int i0, int i1); 87 #if TARGET_OS == GIETVM 88 RegionStats * remote_RegionStatsVector (int i0, int i1, int x, int y); 89 #endif 120 90 RegionStats* RegionStatsVector0 (int i0, int i1); 121 91 void free_RegionStatsVector (RegionStats *v, int i0, int i1); … … 219 189 220 190 void RegionStats_Save_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, char *filename); 221 void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name );191 void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name, int * start_index); 222 192 // affichage des Stats pour les etiquettes roots/ancetres de leur composante (pour algo Suzuki) 223 193 … … 235 205 void sortv_ui32matrix_col(uint32 **m, int i0, int i1, int j0, int j1, int col); 236 206 void RegionStats_SortFeatures(RegionStats *Stats, uint32 nemax); 237 238 // version paralleles avec OpenMP2 ou OpenMP4 239 void imageFeaturesComputation_omp0(uint32 **E, int height, int width, RegionStats *Stats); // wrong 240 void imageFeaturesComputation_omp2(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 2.0 critical 241 void imageFeaturesComputation_omp3(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 2.0 critical + atomic 242 void imageFeaturesComputation_omp4(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 3.0 task + OpenMP 4.0 depend 243 void imageFeaturesComputation_omp5(uint32 **E, int height, int width, uint16* Xmin, uint16* Xmax, uint16* Ymin, uint16* Ymax, uint32* S, uint32* Sx, uint32* Sy); 244 207 245 208 int RegionStats_Compare(RegionStats *S1, RegionStats *S2); 246 209 int RegionStatsVector_Compare(RegionStats *S1, int i0, int i1, RegionStats *S2); -
soft/giet_vm/applications/rosenfeld/include/mca.h
r805 r821 14 14 #define __MCA_H__ 15 15 16 #include <user_lock.h> 16 #include "ecc_features.h" 17 18 #include "nrc_os_config.h" 19 20 #if TARGET_OS == GIETVM 21 #include <user_lock.h> 22 #include <user_barrier.h> 23 #elif TARGET_OS == LINUX 24 #include <pthread.h> 25 #endif 17 26 18 27 19 #ifdef __cplusplus 20 #ifdef VERBOSE_PRAGMA 21 #pragma message ("C++") 22 #endif 23 extern "C" { 24 #endif 28 // QM : using mutex lock instead of mutexlock, 29 // because apparently mutexlocks cause a bug in valgrind 30 // (solved but the installed version is not recent enough) 31 // cf. https://bugs.kde.org/show_bug.cgi?id=336435 32 pthread_mutex_t print_lock; 25 33 26 user_lock_t print_lock; 27 28 #define MCA_VERBOSE0(X) ({ \ 29 lock_acquire(&print_lock); \ 30 X; \ 31 lock_release(&print_lock); \ 34 #define MCA_VERBOSE0(X) ({ \ 35 pthread_mutex_lock(&print_lock); \ 36 X; \ 37 pthread_mutex_unlock(&print_lock); \ 32 38 }) 33 #define MCA_VERBOSE1(X) ({ \ 34 lock_acquire(&print_lock); \ 35 X; \ 36 lock_release(&print_lock); \ 39 #define MCA_VERBOSE1(X) ({ \ 40 pthread_mutex_lock(&print_lock); \ 41 X; \ 42 pthread_mutex_unlock(&print_lock); \ 43 }) 44 #define MCA_DISPLAY0(X) ({ \ 45 pthread_mutex_lock(&print_lock); \ 46 X; \ 47 pthread_mutex_unlock(&print_lock); \ 48 }) 49 #define MCA_DISPLAY1(X) ({ \ 50 pthread_mutex_lock(&print_lock); \ 51 X; \ 52 pthread_mutex_unlock(&print_lock); \ 37 53 }) 38 54 39 55 40 //#define MCA_VERBOSE2(X) X 41 #define MCA_VERBOSE2(X) 56 #define MCA_VERBOSE2(X) 57 /* 58 #define MCA_VERBOSE2(X) ({ \ 59 pthread_mutex_lock(&print_lock); \ 60 X; \ 61 pthread_mutex_unlock(&print_lock); \ 62 }) 63 */ 64 65 #define MCA_DISPLAY2(X) 42 66 43 67 … … 56 80 57 81 uint32 e0, e1; // indice pour chaque bande 58 uint32 ne; // indice max d'etiquettes utilise par bande82 uint32 ne; // indice max d'etiquettes utilise par bande 59 83 60 int alpha; // puissance de 2 >= a la taille d'un bloc 61 //uint32 *I; 62 uint32 *T; // table d'quivalence table (Rosenfeld) ou d'indices (Warp) 63 uint32 **D; // distributed table (instanciee dans chaque worker) 84 int alpha; // puissance de 2 >= a la taille d'un bloc 85 uint32 * T; // table d'quivalence table (Rosenfeld) ou d'indices (Warp) 86 uint32 ** D; // distributed table (instanciee dans chaque worker) 64 87 65 //RegionStats *Stats; 88 RegionStats * stats; 89 RegionStats ** F; 66 90 67 91 struct sMCA * mca; // pointeur vers le maitre (pour les esclaves) 68 92 struct sMCA ** mcas; // tableau de pointeurs vers les workers 93 94 // For pyramidal barriers 95 int nb_level; 96 pthread_barrier_t * barriers; 69 97 } MCA; 70 98 71 99 void MCA_Error(char * msg); 72 100 … … 77 105 void MCA_Set_ImageL(MCA * mca, uint32 ** E); 78 106 79 void 80 void 107 void MCA_Set_Size(MCA * mca, int width, int height); 108 void MCA_Set_NP(MCA * mca, int np); 81 109 82 110 uint32 MCA_CalcMaxLabels(int connection, uint32 height, uint32 width); … … 99 127 void MCA_Warp(MCA * mca); 100 128 101 #ifdef __cplusplus102 }103 #endif104 129 105 130 #endif // __MCA_H__ -
soft/giet_vm/applications/rosenfeld/include/mca_matrix_dist.h
r805 r821 13 13 uint32 ** dist_ui32matrix(int i0, int i1, int j0, int j1); 14 14 void free_dist_ui32matrix(uint32 ** m, int i0, int i1, int j0, int j1); 15 #if TARGET_OS == GIETVM 16 uint32 ** remote_dist_ui32matrix(int i0, int i1, int j0, int j1, int x, int y); 17 #endif 15 18 16 19 #ifdef __cplusplus -
soft/giet_vm/applications/rosenfeld/include/mca_rosenfeld.h
r805 r821 16 16 #include "mca.h" 17 17 18 #ifdef __cplusplus19 #ifdef VERBOSE_PRAGMA20 #pragma message ("C++")21 #endif22 extern "C" {23 #endif24 25 18 uint32 line0Labeling_Rosenfeld (uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne); 26 19 uint32 lineLabeling_DT_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne); … … 29 22 void solveTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1); 30 23 31 void MCA_Label_Rosenfeld(MCA * mca); 24 void * MCA_Label_Rosenfeld(void * arg); 25 void * MCA_Label_Features_Rosenfeld(void * arg); 32 26 33 #ifdef __cplusplus34 }35 #endif36 37 27 #endif // __MCA_ROSENFELD_H__ 38 28 -
soft/giet_vm/applications/rosenfeld/nrc2/Makefile
r798 r821 7 7 8 8 # -- File list ---------- 9 FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c, nrhisto.c, nrio0.c, nrio1.c, nrio2.c, nr kernel.c, nrlinalg.c, nrlut.c, nrmem1.c, nrmem1x.c, nrmem2.c, nrmem2x.c, nrset1.c, nrset2.c, nrset2x.c, nrsort1.c, nrsort2.c, nrwrap1.c, nrwrap2.c9 FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c, nrhisto.c, nrio0.c, nrio1.c, nrio2.c, nrlinalg.c, nrlut.c, nrmem1.c, nrmem1x.c, nrmem2.c, nrmem2x.c, nrset1.c, nrset2.c, nrset2x.c, nrsort1.c, nrsort2.c, nrwrap1.c, nrwrap2.c 10 10 11 11 12 TARGET ?= linux 12 13 13 14 # -- Paths ---------- … … 15 16 OBJ_PATH = obj 16 17 INC_PATH = include 18 19 ifeq ($(TARGET),giet-vm) 20 21 CC = mipsel-unknown-elf-gcc 22 AR = mipsel-unknown-elf-ar 23 RANLIB = mipsel-unknown-elf-ranlib 24 AS = mipsel-unknown-elf-as 25 OD = mipsel-unknown-elf-objdump 26 OCPY = mipsel-unknown-elf-objcopy 27 LD = mipsel-unknown-elf-ld 28 NM = mipsel-unknown-elf-nm 17 29 18 30 … … 22 34 C_CONFIG_FLAGS = -DCLI 23 35 C_INC_FLAGS = -I$(INC_PATH) -I../../.. -I../../../giet_libs 36 CFLAGSCPU := -mips32 -EL -G0 -mhard-float 37 38 endif 39 40 ifeq ($(TARGET),linux) 41 42 CC = gcc 43 LD = gcc 44 AR = ar 45 RANLIB = ranlib 46 47 C_DEBUG_FLAGS = -O0 48 C_OPTIMISATION_FLAGS = -std=c99 -O2 -fstrict-aliasing 49 C_OS_FLAGS = -DGTODay -DTARGET_OS=LINUX 50 C_CONFIG_FLAGS = -DCLI 51 C_INC_FLAGS = -I$(INC_PATH) 52 53 endif 54 24 55 25 56 # -- Flags ---------- … … 30 61 # CC tools and parameters 31 62 #------------------------------------------------------------------------------ 32 CC = mipsel-unknown-elf-gcc33 AR = mipsel-unknown-elf-ar -cr34 RANLIB = mipsel-unknown-elf-ranlib35 AS = mipsel-unknown-elf-as36 OD = mipsel-unknown-elf-objdump37 OCPY = mipsel-unknown-elf-objcopy38 LD = mipsel-unknown-elf-ld39 NM = mipsel-unknown-elf-nm40 63 41 64 CFLAGSW := -Wredundant-decls -Wdisabled-optimization -Winline -Wpointer-arith -Wsign-compare -Wendif-labels 42 CFLAGSCPU := -mips32 -EL -G0 -mhard-float43 65 CFLAGS := $(CFLAGS) -g -Wall -fomit-frame-pointer $(CFLAGSW) $(CFLAGSCPU) -fno-builtin -ffreestanding 44 66 … … 55 77 56 78 $(PRODUCT): $(OBJS) 57 $(AR) $@ $^79 $(AR) -cr $@ $^ 58 80 $(RANLIB) $@ 59 81 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc.h
r772 r821 11 11 #define __NRALLOC_H__ 12 12 13 #ifdef __cplusplus14 #pragma message ("C++")15 extern "C" {16 #endif17 18 #ifdef VERBOSE_PRAGMA19 //#pragma message ("- *** include nralloc.h ***")20 #endif21 13 22 14 #include "nralloc1.h" … … 24 16 #include "nralloc3.h" 25 17 26 #ifdef __cplusplus 27 } 28 #endif 18 #endif /* __NRALLOC_H__ */ 29 19 30 #endif /* __NRALLOC_H__ */ -
soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc1.h
r772 r821 11 11 #define __NRALLOC1_H__ 12 12 13 #ifdef __cplusplus 14 #pragma message ("C++") 15 extern "C" { 16 #endif 17 18 #ifdef VERBOSE_PRAGMA 19 //#pragma message ("- *** include nralloc1.h ***") 20 #endif 13 #include <stdint.h> 21 14 22 23 //NR_END est maintenant defini dans nrutil.h 24 25 #define NR_END 0 26 #define FREE_ARG char* 27 28 //long nr_end = NR_END; 29 30 //void nrerror(char error_text[]); 31 //void nrerror(char *format, ...); 32 //void Error (char *format, ...); 33 //void Warning(char *format, ...); 15 #include "nrc_os_config.h" 16 #include "nrtype.h" 34 17 35 18 /* … … 39 22 */ 40 23 41 // do: allocate a float vector with subscript range v[nl..nh] 24 #define type_vector(t) \ 25 t * short_name(t,,vector)(int32_t nl, int32_t nh) 42 26 43 //IMAGE_EXPORT(byte*) bvector(long nl, long nh); 44 IMAGE_EXPORT(sint8*) si8vector(long nl, long nh); 45 IMAGE_EXPORT(uint8*) ui8vector(long nl, long nh); 46 IMAGE_EXPORT(sint16*) si16vector(long nl, long nh); 47 IMAGE_EXPORT(uint16*) ui16vector(long nl, long nh); 48 IMAGE_EXPORT(sint32*) si32vector(long nl, long nh); 49 IMAGE_EXPORT(uint32*) ui32vector(long nl, long nh); 50 IMAGE_EXPORT(sint64*) si64vector(long nl, long nh); 51 IMAGE_EXPORT(uint64*) ui64vector(long nl, long nh); 27 type_vector(int8_t); 28 type_vector(uint8_t); 29 type_vector(int16_t); 30 type_vector(uint16_t); 31 type_vector(int32_t); 32 type_vector(uint32_t); 33 type_vector(int64_t); 34 type_vector(uint64_t); 35 type_vector(float); 36 type_vector(double); 37 type_vector(rgb8); 38 type_vector(rgbx8); 39 type_vector(rgb32); 40 type_vector(void_p); 52 41 53 IMAGE_EXPORT(float32*) f32vector(long nl, long nh);54 IMAGE_EXPORT(float64*) f64vector(long nl, long nh);55 42 56 IMAGE_EXPORT(rgb8*) rgb8vector(long nl, long nh);57 IMAGE_EXPORT(rgbx8*) rgbx8vector(long nl, long nh);58 IMAGE_EXPORT(rgb32*) rgb32vector(long nl, long nh);59 43 60 IMAGE_EXPORT(void**) vvector(long nl, long nh); 44 #if TARGET_OS == GIETVM 45 #define remote_type_vector(t) \ 46 t * short_name(t,remote_,vector)(int32_t nl, int32_t nh, int32_t x, int32_t y) 47 48 remote_type_vector(int8_t); 49 remote_type_vector(uint8_t); 50 remote_type_vector(int16_t); 51 remote_type_vector(uint16_t); 52 remote_type_vector(int32_t); 53 remote_type_vector(uint32_t); 54 remote_type_vector(int64_t); 55 remote_type_vector(uint64_t); 56 remote_type_vector(float); 57 remote_type_vector(double); 58 remote_type_vector(rgb8); 59 remote_type_vector(rgbx8); 60 remote_type_vector(rgb32); 61 remote_type_vector(void_p); 62 63 //void ** remote_vvector(long nl, long nh, int x, int y); 64 #endif 65 66 #define type_vector0(t) \ 67 t * short_name(t,,vector0)(int32_t nl, int32_t nh) 68 69 type_vector0(int8_t); 70 type_vector0(uint8_t); 71 type_vector0(int16_t); 72 type_vector0(uint16_t); 73 type_vector0(int32_t); 74 type_vector0(uint32_t); 75 type_vector0(int64_t); 76 type_vector0(uint64_t); 77 type_vector0(float); 78 type_vector0(double); 79 type_vector0(rgb8); 80 type_vector0(rgbx8); 81 type_vector0(rgb32); 82 type_vector0(void_p); 83 84 #define realloc_type_vector(t) \ 85 t * short_name(t,realloc_,vector)(t * v, int32_t nl, int32_t nh) 86 87 realloc_type_vector(int8_t); 88 realloc_type_vector(uint8_t); 89 realloc_type_vector(int16_t); 90 realloc_type_vector(uint16_t); 91 realloc_type_vector(int32_t); 92 realloc_type_vector(uint32_t); 93 realloc_type_vector(int64_t); 94 realloc_type_vector(uint64_t); 95 realloc_type_vector(float); 96 realloc_type_vector(double); 97 realloc_type_vector(rgb8); 98 realloc_type_vector(rgbx8); 99 realloc_type_vector(rgb32); 100 realloc_type_vector(void_p); 101 102 103 #define free_type_vector(t) \ 104 void short_name(t,free_,vector)(t * v, long nl, long nh) 105 106 free_type_vector(int8_t); 107 free_type_vector(uint8_t); 108 free_type_vector(int16_t); 109 free_type_vector(uint16_t); 110 free_type_vector(int32_t); 111 free_type_vector(uint32_t); 112 free_type_vector(int64_t); 113 free_type_vector(uint64_t); 114 free_type_vector(float); 115 free_type_vector(double); 116 free_type_vector(rgb8); 117 free_type_vector(rgbx8); 118 free_type_vector(rgb32); 119 free_type_vector(void_p); 120 121 61 122 62 123 /* 63 * --------------- 64 * --- vector0 --- 65 * --------------- 66 */ 67 68 // do: allocate a vector and set it to 0 69 70 //IMAGE_EXPORT(byte*) bvector0(long nl, long nh); 71 IMAGE_EXPORT(sint8*) si8vector0(long nl, long nh); 72 IMAGE_EXPORT(uint8*) ui8vector0(long nl, long nh); 73 IMAGE_EXPORT(sint16*) si16vector0(long nl, long nh); 74 IMAGE_EXPORT(uint16*) ui16vector0(long nl, long nh); 75 IMAGE_EXPORT(sint32*) si32vector0(long nl, long nh); 76 IMAGE_EXPORT(uint32*) ui32vector0(long nl, long nh); 77 78 IMAGE_EXPORT(float32*) f32vector0(long nl, long nh); 79 IMAGE_EXPORT(float64*) f64vector0(long nl, long nh); 80 81 IMAGE_EXPORT(rgb8*) rgb8vector0(long nl, long nh); 82 IMAGE_EXPORT(rgbx8*) rgbx8vector0(long nl, long nh); 83 IMAGE_EXPORT(rgb32*) rgb32vector0(long nl, long nh); 84 85 IMAGE_EXPORT(void**) vvector0(long nl, long nh); 86 /* 87 * ---------------------- 88 * --- realloc_vector --- 89 * ---------------------- 90 */ 91 92 // realloc a vector to [nl..nh] 93 IMAGE_EXPORT(void**) realloc_vvector(void **v, long nl, long nh); 94 95 /* 96 * ------------------- 97 * --- free_vector --- 98 * ------------------- 99 */ 100 101 //IMAGE_EXPORT(void) free_bvector (byte *v, long nl, long nh); 102 IMAGE_EXPORT(void) free_si8vector (sint8 *v, long nl, long nh); 103 IMAGE_EXPORT(void) free_ui8vector (uint8 *v, long nl, long nh); 104 IMAGE_EXPORT(void) free_si16vector (sint16 *v, long nl, long nh); 105 IMAGE_EXPORT(void) free_ui16vector (uint16 *v, long nl, long nh); 106 IMAGE_EXPORT(void) free_si32vector (sint32 *v, long nl, long nh); 107 IMAGE_EXPORT(void) free_ui32vector (uint32 *v, long nl, long nh); 108 IMAGE_EXPORT(void) free_si64vector (sint64 *v, long nl, long nh); 109 IMAGE_EXPORT(void) free_ui64vector (uint64 *v, long nl, long nh); 110 111 IMAGE_EXPORT(void) free_f32vector (float32 *v, long nl, long nh); 112 IMAGE_EXPORT(void) free_f64vector (float64 *v, long nl, long nh); 113 114 IMAGE_EXPORT(void) free_rgb8vector (rgb8 *v, long nl, long nh); 115 IMAGE_EXPORT(void) free_rgbx8vector(rgbx8 *v, long nl, long nh); 116 IMAGE_EXPORT(void) free_rgb32vector(rgb32 *v, long nl, long nh); 117 118 IMAGE_EXPORT(void) free_vvector (void **v, long nl, long nh); 119 120 #ifdef __cplusplus 121 } 122 #endif 124 void ** vvector(long nl, long nh); 125 void ** vvector0(long nl, long nh); 126 void ** realloc_vvector(void ** v, long nl, long nh); 127 void free_vvector(void ** v, long nl, long nh); 128 */ 123 129 124 130 #endif /* __NRALLOC1_H__ */ 131 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc2.h
r772 r821 16 16 #define __NRALLOC2_H__ 17 17 18 #ifdef __cplusplus 19 #pragma message ("C++") 20 extern "C" { 21 #endif 22 23 #ifdef VERBOSE_PRAGMA 24 //#pragma message ("- *** include nralloc2.h ***") 25 #endif 18 #include "nrc_os_config.h" 26 19 27 20 /* … … 31 24 */ 32 25 33 IMAGE_EXPORT(sint8**) si8matrix(long nrl, long nrh, long ncl, long nch);34 IMAGE_EXPORT(uint8**) ui8matrix(long nrl, long nrh, long ncl, long nch);35 IMAGE_EXPORT(sint16**) si16matrix(long nrl, long nrh, long ncl, long nch);36 IMAGE_EXPORT(uint16**) ui16matrix(long nrl, long nrh, long ncl, long nch);37 IMAGE_EXPORT(sint32**) si32matrix(long nrl, long nrh, long ncl, long nch);38 IMAGE_EXPORT(uint32**) ui32matrix(long nrl, long nrh, long ncl, long nch);39 IMAGE_EXPORT(sint64**) si64matrix(long nrl, long nrh, long ncl, long nch);40 IMAGE_EXPORT(uint64**) ui64matrix(long nrl, long nrh, long ncl, long nch);41 26 42 IMAGE_EXPORT(float32**) f32matrix(long nrl, long nrh, long ncl, long nch); 43 IMAGE_EXPORT(float64**) f64matrix(long nrl, long nrh, long ncl, long nch); 27 #undef type_matrix 28 #define type_matrix(t) \ 29 t ** short_name(t,,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) 44 30 45 IMAGE_EXPORT(complex32**) c32matrix(long nrl, long nrh, long ncl, long nch);46 IMAGE_EXPORT(complex64**) c64matrix(long nrl, long nrh, long ncl, long nch);47 31 48 IMAGE_EXPORT(rgb8**) rgb8matrix(long nrl, long nrh, long ncl, long nch); 49 IMAGE_EXPORT(rgbx8**) rgbx8matrix(long nrl, long nrh, long ncl, long nch); 50 //IMAGE_EXPORT(rgb32**) rgb32matrix(long nrl, long nrh, long ncl, long nch); 51 //IMAGE_EXPORT(rgbx32**) rgbx32matrix(long nrl, long nrh, long ncl, long nch); 32 type_matrix(int8_t); 33 type_matrix(uint8_t); 34 type_matrix(int16_t); 35 type_matrix(uint16_t); 36 type_matrix(int32_t); 37 type_matrix(uint32_t); 38 type_matrix(int64_t); 39 type_matrix(uint64_t); 40 type_matrix(float); 41 type_matrix(double); 42 type_matrix(void_p); 43 type_matrix(rgb8); 44 type_matrix(rgbx8); 45 type_matrix(rgb32); 46 type_matrix(rgbx32); 47 type_matrix(complex32); 48 type_matrix(complex64); 52 49 53 /*54 * ---------------55 * --- matrix0 ---56 * ---------------57 */58 50 59 IMAGE_EXPORT(sint8**) si8matrix0(long nrl, long nrh, long ncl, long nch); 60 IMAGE_EXPORT(uint8**) ui8matrix0(long nrl, long nrh, long ncl, long nch); 61 IMAGE_EXPORT(sint16**) si16matrix0(long nrl, long nrh, long ncl, long nch); 62 IMAGE_EXPORT(uint16**) ui16matrix0(long nrl, long nrh, long ncl, long nch); 63 IMAGE_EXPORT(sint32**) i32matrix0(long nrl, long nrh, long ncl, long nch); 64 IMAGE_EXPORT(uint32**) ui32matrix0(long nrl, long nrh, long ncl, long nch); 65 IMAGE_EXPORT(sint64**) si64matrix0(long nrl, long nrh, long ncl, long nch); 66 IMAGE_EXPORT(uint64**) ui64matrix0(long nrl, long nrh, long ncl, long nch); 67 IMAGE_EXPORT(rgb8**) rgb8matrix0(long nrl, long nrh, long ncl, long nch); 68 IMAGE_EXPORT(rgbx8**) rgbx8matrix0(long nrl, long nrh, long ncl, long nch); 69 IMAGE_EXPORT(rgb32**) rgb32matrix0(long nrl, long nrh, long ncl, long nch); 70 IMAGE_EXPORT(rgbx32**) rgbx32matrix0(long nrl, long nrh, long ncl, long nch); 51 #undef type_matrix0 52 #define type_matrix0(t) \ 53 t ** short_name(t,,matrix0)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) 71 54 72 IMAGE_EXPORT(float32**) f32matrix0(long nrl, long nrh, long ncl, long nch);73 IMAGE_EXPORT(float64**) f64matrix0(long nrl, long nrh, long ncl, long nch);74 55 75 /* 76 * ------------------- 77 * --- free_matrix --- 78 * ------------------- 79 */ 56 type_matrix0(int8_t); 57 type_matrix0(uint8_t); 58 type_matrix0(int16_t); 59 type_matrix0(uint16_t); 60 type_matrix0(int32_t); 61 type_matrix0(uint32_t); 62 type_matrix0(int64_t); 63 type_matrix0(uint64_t); 64 type_matrix0(float); 65 type_matrix0(double); 66 type_matrix0(void_p); 67 type_matrix0(rgb8); 68 type_matrix0(rgbx8); 69 type_matrix0(rgb32); 70 type_matrix0(rgbx32); 71 type_matrix0(complex32); 72 type_matrix0(complex64); 80 73 81 IMAGE_EXPORT(void) free_si8matrix (sint8 **m, long nrl, long nrh, long ncl, long nch);82 IMAGE_EXPORT(void) free_ui8matrix (uint8 **m, long nrl, long nrh, long ncl, long nch);83 IMAGE_EXPORT(void) free_si16matrix (sint16 **m, long nrl, long nrh, long ncl, long nch);84 IMAGE_EXPORT(void) free_ui16matrix (uint16 **m, long nrl, long nrh, long ncl, long nch);85 IMAGE_EXPORT(void) free_si32matrix (sint32 **m, long nrl, long nrh, long ncl, long nch);86 IMAGE_EXPORT(void) free_ui32matrix (uint32 **m, long nrl, long nrh, long ncl, long nch);87 IMAGE_EXPORT(void) free_si64matrix (sint64 **m, long nrl, long nrh, long ncl, long nch);88 IMAGE_EXPORT(void) free_ui64matrix (uint64 **m, long nrl, long nrh, long ncl, long nch);89 74 90 IMAGE_EXPORT(void) free_f32matrix (float32 **m, long nrl, long nrh, long ncl, long nch); 91 IMAGE_EXPORT(void) free_f64matrix (float64 **m, long nrl, long nrh, long ncl, long nch); 92 IMAGE_EXPORT(void) free_c32matrix (complex32 **m, long nrl, long nrh, long ncl, long nch); 93 IMAGE_EXPORT(void) free_c64matrix (complex64 **m, long nrl, long nrh, long ncl, long nch); 75 #if TARGET_OS == GIETVM 94 76 95 IMAGE_EXPORT(void) free_rgb8matrix (rgb8 **m, long nrl, long nrh, long ncl, long nch); 96 IMAGE_EXPORT(void) free_rgbx8matrix (rgbx8 **m, long nrl, long nrh, long ncl, long nch); 97 IMAGE_EXPORT(void) free_rgb32matrix (rgb32 **m, long nrl, long nrh, long ncl, long nch); 98 IMAGE_EXPORT(void) free_rgbx32matrix(rgbx32 **m, long nrl, long nrh, long ncl, long nch); 77 #undef remote_type_matrix 78 #define remote_type_matrix(t) \ 79 t ** short_name(t,remote_,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) 99 80 100 #ifdef __cplusplus 101 } 81 remote_type_matrix(int8_t); 82 remote_type_matrix(uint8_t); 83 remote_type_matrix(int16_t); 84 remote_type_matrix(uint16_t); 85 remote_type_matrix(int32_t); 86 remote_type_matrix(uint32_t); 87 remote_type_matrix(int64_t); 88 remote_type_matrix(uint64_t); 89 remote_type_matrix(float); 90 remote_type_matrix(double); 91 remote_type_matrix(void_p); 92 remote_type_matrix(rgb8); 93 remote_type_matrix(rgbx8); 94 remote_type_matrix(rgb32); 95 remote_type_matrix(rgbx32); 96 remote_type_matrix(complex32); 97 remote_type_matrix(complex64); 98 102 99 #endif 103 100 101 102 #undef free_type_matrix 103 #define free_type_matrix(t) \ 104 void short_name(t,free_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) 105 106 free_type_matrix(int8_t); 107 free_type_matrix(uint8_t); 108 free_type_matrix(int16_t); 109 free_type_matrix(uint16_t); 110 free_type_matrix(int32_t); 111 free_type_matrix(uint32_t); 112 free_type_matrix(int64_t); 113 free_type_matrix(uint64_t); 114 free_type_matrix(float); 115 free_type_matrix(double); 116 free_type_matrix(void_p); 117 free_type_matrix(rgb8); 118 free_type_matrix(rgbx8); 119 free_type_matrix(rgb32); 120 free_type_matrix(rgbx32); 121 free_type_matrix(complex32); 122 free_type_matrix(complex64); 123 124 104 125 #endif /* __NRALLOC2_H__ */ 126 127 // Local Variables: 128 // tab-width: 4 129 // c-basic-offset: 4 130 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 131 // indent-tabs-mode: nil 132 // End: 133 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 134 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc2x.h
r772 r821 16 16 #define __NRALLOC2X_H__ 17 17 18 #ifdef __cplusplus19 #pragma message ("C++")20 extern "C" {21 #endif22 23 #ifdef VERBOSE_PRAGMA24 //#pragma message ("- *** include nralloc2x.h ***")25 #endif26 18 19 #include "nrc_os_config.h" 27 20 #include "nrtype.h" 28 21 #include "nrtypex.h" 29 22 30 /* ---------------------------------- */31 /* --- composite user type matrix --- */32 /* ---------------------------------- */33 34 IMAGE_EXPORT(si16Point**) si16Pmatrix(long nrl, long nrh, long ncl, long nch);35 IMAGE_EXPORT(ui16Point**) ui16Pmatrix(long nrl, long nrh, long ncl, long nch);36 IMAGE_EXPORT(si32Point**) si32Pmatrix(long nrl, long nrh, long ncl, long nch);37 IMAGE_EXPORT(ui32Point**) ui32Pmatrix(long nrl, long nrh, long ncl, long nch);38 IMAGE_EXPORT(f32Point**) f32Pmatrix(long nrl, long nrh, long ncl, long nch);39 40 IMAGE_EXPORT(si16Triplet**) si16Tmatrix(long nrl, long nrh, long ncl, long nch);41 IMAGE_EXPORT(ui16Triplet**) ui16Tmatrix(long nrl, long nrh, long ncl, long nch);42 IMAGE_EXPORT(si32Triplet**) si32Tmatrix(long nrl, long nrh, long ncl, long nch);43 IMAGE_EXPORT(ui32Triplet**) ui32Tmatrix(long nrl, long nrh, long ncl, long nch);44 IMAGE_EXPORT(f32Triplet**) f32Tmatrix(long nrl, long nrh, long ncl, long nch);45 46 IMAGE_EXPORT(void) free_si16Pmatrix(si16Point **m, long nrl, long nrh, long ncl, long nch);47 IMAGE_EXPORT(void) free_ui16Pmatrix(ui16Point **m, long nrl, long nrh, long ncl, long nch);48 IMAGE_EXPORT(void) free_si32Pmatrix(si32Point **m, long nrl, long nrh, long ncl, long nch);49 IMAGE_EXPORT(void) free_ui32Pmatrix(ui32Point **m, long nrl, long nrh, long ncl, long nch);50 IMAGE_EXPORT(void) free_f32Pmatrix(f32Point **m, long nrl, long nrh, long ncl, long nch);51 52 IMAGE_EXPORT(void) free_si16Tmatrix(si16Triplet **m, long nrl, long nrh, long ncl, long nch);53 IMAGE_EXPORT(void) free_ui16Tmatrix(ui16Triplet **m, long nrl, long nrh, long ncl, long nch);54 IMAGE_EXPORT(void) free_si32Tmatrix(si32Triplet **m, long nrl, long nrh, long ncl, long nch);55 IMAGE_EXPORT(void) free_ui32Tmatrix(ui32Triplet **m, long nrl, long nrh, long ncl, long nch);56 IMAGE_EXPORT(void) free_f32Tmatrix ( f32Triplet **m, long nrl, long nrh, long ncl, long nch);57 23 58 24 /* ----------------- */ … … 60 26 /* ----------------- */ 61 27 62 IMAGE_EXPORT(byte**) btrimatrix(long nrl, long nrh, long ncl, long nch, long step); 63 IMAGE_EXPORT(sint16**) si16trimatrix(long nrl, long nrh, long ncl, long nch, long step); 64 IMAGE_EXPORT(uint16**) ui16trimatrix(long nrl, long nrh, long ncl, long nch, long step); 65 IMAGE_EXPORT(sint32**) si32trimatrix(long nrl, long nrh, long ncl, long nch, long step); 66 IMAGE_EXPORT(uint32**) ui32trimatrix(long nrl, long nrh, long ncl, long nch, long step); 67 IMAGE_EXPORT(float32**) f32trimatrix(long nrl, long nrh, long ncl, long nch, long step); 68 IMAGE_EXPORT(float64**) f64trimatrix(long nrl, long nrh, long ncl, long nch, long step); 28 #define type_trimatrix(t) \ 29 t ** short_name(t,,trimatrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t step) 69 30 70 #ifdef __cplusplus 71 } 72 #endif 31 type_trimatrix(int8_t); 32 type_trimatrix(uint8_t); 33 type_trimatrix(int16_t); 34 type_trimatrix(uint16_t); 35 type_trimatrix(int32_t); 36 type_trimatrix(uint32_t); 37 type_trimatrix(float); 38 type_trimatrix(double); 39 73 40 74 41 #endif /* __NRALLOC2X_H__ */ 42 43 // Local Variables: 44 // tab-width: 4 45 // c-basic-offset: 4 46 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 47 // indent-tabs-mode: nil 48 // End: 49 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 50 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nralloc3.h
r772 r821 13 13 #define __NRALLOC3_H__ 14 14 15 #ifdef __cplusplus 16 #pragma message ("C++") 17 extern "C" { 18 #endif 19 20 #ifdef VERBOSE_PRAGMA 21 //#pragma message ("- *** include nralloc3.h ***") 22 #endif 15 #include "nrc_os_config.h" 23 16 24 double*** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh); 25 void free_d3tensor(double ***t,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 17 //double*** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh); 18 //void free_d3tensor(double ***t,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 19 20 #define type_cube(t) \ 21 t *** short_name(t,,cube)(int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ 26 22 27 23 24 type_cube(int8_t); 25 type_cube(uint8_t); 26 type_cube(int16_t); 27 type_cube(uint16_t); 28 type_cube(int32_t); 29 type_cube(uint32_t); 30 type_cube(int64_t); 31 type_cube(uint64_t); 32 type_cube(float); 33 type_cube(double); 34 type_cube(rgb8); 35 type_cube(rgbx8); 28 36 29 IMAGE_EXPORT(sint8***) si8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 30 IMAGE_EXPORT(uint8***) ui8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 31 IMAGE_EXPORT(sint16***) si16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 32 IMAGE_EXPORT(uint16***) ui16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 33 IMAGE_EXPORT(sint32***) si32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 34 IMAGE_EXPORT(uint32***) ui32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 35 IMAGE_EXPORT(float32***) f32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 36 IMAGE_EXPORT(float64***) f64cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 37 IMAGE_EXPORT(rgb8***) rgb8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 38 IMAGE_EXPORT(rgbx8***) rgbx8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch); 37 #define free_type_cube(t) \ 38 void short_name(t,free_,cube)(t *** c, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh) \ 39 39 40 IMAGE_EXPORT(void) free_si8cube (sint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 41 IMAGE_EXPORT(void) free_ui8cube (uint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 42 IMAGE_EXPORT(void) free_si16cube (sint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 43 IMAGE_EXPORT(void) free_ui16cube (uint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 44 IMAGE_EXPORT(void) free_si32cube (sint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 45 IMAGE_EXPORT(void) free_ui32cube (uint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 46 IMAGE_EXPORT(void) free_f32cube (float32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 47 IMAGE_EXPORT(void) free_f64cube (float64 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 48 IMAGE_EXPORT(void) free_rgb8cube (rgb8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 49 IMAGE_EXPORT(void) free_rgbx8cube(rgbx8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 40 free_type_cube(int8_t); 41 free_type_cube(uint8_t); 42 free_type_cube(int16_t); 43 free_type_cube(uint16_t); 44 free_type_cube(int32_t); 45 free_type_cube(uint32_t); 46 free_type_cube(int64_t); 47 free_type_cube(uint64_t); 48 free_type_cube(float); 49 free_type_cube(double); 50 free_type_cube(rgb8); 51 free_type_cube(rgbx8); 50 52 51 #ifdef __cplusplus52 }53 #endif54 53 55 54 #endif /* __NRALLOC3_H__ */ 55 56 // Local Variables: 57 // tab-width: 4 58 // c-basic-offset: 4 59 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 60 // indent-tabs-mode: nil 61 // End: 62 63 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 64 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith0.h
r772 r821 11 11 #define __NRARITH0_H__ 12 12 13 #ifdef __cplusplus14 #pragma message ("C++")15 extern "C" {16 #endif17 18 #ifdef VERBOSE_PRAGMA19 //#pragma message(" -include nrarith0.h")20 #endif21 22 13 /* ---------- */ 23 14 /* -- Swap -- */ 24 15 /* ---------- */ 25 16 26 ROUTINE(void) i8swap(int8 *a, int8 *b); 27 ROUTINE(void) i16swap(int16 *a, int16 *b); 28 ROUTINE(void) i32swap(int32 *a, int32 *b); 29 ROUTINE(void) i64swap(int64 *a, int64 *b); 30 ROUTINE(void) f32swap(float32 *a, float32 *b); 31 ROUTINE(void) f64swap(float64 *a, float64 *b); 32 ROUTINE(void) rgb8swap(rgb8 *a, rgb8 *b); 33 ROUTINE(void) rgbx8swap(rgbx8 *a, rgbx8 *b); 17 #define type_swap(t) \ 18 void short_name(t,,swap)(t * a, t * b) 19 20 type_swap(int8_t); 21 type_swap(int16_t); 22 type_swap(int32_t); 23 type_swap(int64_t); 24 type_swap(float); 25 type_swap(double); 26 type_swap(rgb8); 27 type_swap(rgbx8); 28 34 29 35 30 /* --------- */ … … 37 32 /* --------- */ 38 33 39 ROUTINE(float32) f32min (float32 x1, float32 x2); 40 ROUTINE(float32) f32min2(float32 x1, float32 x2); 41 ROUTINE(float32) f32min3(float32 x1, float32 x2, float32 x3); 42 ROUTINE(float32) f32min4(float32 x1, float32 x2, float32 x3, float32 x4); 43 ROUTINE(float32) f32min5(float32 x1, float32 x2, float32 x3, float32 x4, float32 x5); 34 #define type_min(t) \ 35 t short_name(t,,min)(t x1, t x2); \ 36 t short_name(t,,min2)(t x1, t x2); \ 37 t short_name(t,,min3)(t x1, t x2, t x3); \ 38 t short_name(t,,min4)(t x1, t x2, t x3, t x4); \ 39 t short_name(t,,min5)(t x1, t x2, t x3, t x4, t x5) \ 44 40 45 ROUTINE(float64) f64min (float64 x1, float64 x2); 46 ROUTINE(float64) f64min2(float64 x1, float64 x2); 47 ROUTINE(float64) f64min3(float64 x1, float64 x2, float64 x3); 48 ROUTINE(float64) f64min4(float64 x1, float64 x2, float64 x3, float64 x4); 49 ROUTINE(float64) f64min5(float64 x1, float64 x2, float64 x3, float64 x4, float64 x5); 41 type_min(float); 42 type_min(double); 43 type_min(int8_t); 44 type_min(uint8_t); 45 type_min(int16_t); 46 type_min(uint16_t); 47 type_min(int32_t); 48 type_min(uint32_t); 49 type_min(rgb8); 50 50 51 ROUTINE(byte) bmin (byte x1, byte x2);52 ROUTINE(byte) bmin2(byte x1, byte x2);53 ROUTINE(byte) bmin3(byte x1, byte x2, byte x3);54 ROUTINE(byte) bmin4(byte x1, byte x2, byte x3, byte x4);55 ROUTINE(byte) bmin5(byte x1, byte x2, byte x3, byte x4, byte x5);56 57 ROUTINE(uint16) ui16min (uint16 x1, uint16 x2);58 ROUTINE(uint16) ui16min2(uint16 x1, uint16 x2);59 ROUTINE(uint16) ui16min3(uint16 x1, uint16 x2, uint16 x3);60 ROUTINE(uint16) ui16min4(uint16 x1, uint16 x2, uint16 x3, uint16 x4);61 ROUTINE(uint16) ui16min5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5);62 63 ROUTINE(int32) i32min (int32 x1, int32 x2);64 ROUTINE(int32) i32min2(int32 x1, int32 x2);65 ROUTINE(int32) i32min3(int32 x1, int32 x2, int32 x3);66 ROUTINE(int32) i32min4(int32 x1, int32 x2, int32 x3, int32 x4);67 ROUTINE(int32) i32min5(int32 x1, int32 x2, int32 x3, int32 x4, int32 x5);68 69 ROUTINE(rgb8) rgb8min (rgb8 x1, rgb8 x2);70 ROUTINE(rgb8) rgb8min2(rgb8 x1, rgb8 x2);71 ROUTINE(rgb8) rgb8min3(rgb8 x1, rgb8 x2, rgb8 x3);72 ROUTINE(rgb8) rgb8min4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4);73 ROUTINE(rgb8) rgb8min5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5);74 51 75 52 /* --------- */ 76 53 /* -- Max -- */ 77 54 /* --------- */ 78 ROUTINE(float32) f32max (float32 x1, float32 x2);79 ROUTINE(float32) f32max2(float32 x1, float32 x2);80 ROUTINE(float32) f32max3(float32 x1, float32 x2, float32 x3);81 ROUTINE(float32) f32max4(float32 x1, float32 x2, float32 x3, float32 x4);82 ROUTINE(float32) f32max5(float32 x1, float32 x2, float32 x3, float32 x4, float32 x5);83 55 84 ROUTINE(float64) f64max (float64 x1, float64 x2); 85 ROUTINE(float64) f64max2(float64 x1, float64 x2); 86 ROUTINE(float64) f64max3(float64 x1, float64 x2, float64 x3); 87 ROUTINE(float64) f64max4(float64 x1, float64 x2, float64 x3, float64 x4); 88 ROUTINE(float64) f64max5(float64 x1, float64 x2, float64 x3, float64 x4, float64 x5); 56 #define type_max(t) \ 57 t short_name(t,,max)(t x1, t x2); \ 58 t short_name(t,,max2)(t x1, t x2); \ 59 t short_name(t,,max3)(t x1, t x2, t x3); \ 60 t short_name(t,,max4)(t x1, t x2, t x3, t x4); \ 61 t short_name(t,,max5)(t x1, t x2, t x3, t x4, t x5) \ 89 62 90 ROUTINE(byte) bmax (byte x1, byte x2); 91 ROUTINE(byte) bmax2(byte x1, byte x2); 92 ROUTINE(byte) bmax3(byte x1, byte x2, byte x3); 93 ROUTINE(byte) bmax4(byte x1, byte x2, byte x3, byte x4); 94 ROUTINE(byte) bmax5(byte x1, byte x2, byte x3, byte x4, byte x5); 63 type_max(float); 64 type_max(double); 65 type_max(int8_t); 66 type_max(uint8_t); 67 type_max(int16_t); 68 type_max(uint16_t); 69 type_max(int32_t); 70 type_max(uint32_t); 71 type_max(rgb8); 95 72 96 ROUTINE(uint16) ui16max (uint16 x1, uint16 x2);97 ROUTINE(uint16) ui16max2(uint16 x1, uint16 x2);98 ROUTINE(uint16) ui16max3(uint16 x1, uint16 x2, uint16 x3);99 ROUTINE(uint16) ui16max4(uint16 x1, uint16 x2, uint16 x3, uint16 x4);100 ROUTINE(uint16) ui16max5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5);101 102 ROUTINE(int32) i32max (int32 x1, int32 x2);103 ROUTINE(int32) i32max2(int32 x1, int32 x2);104 ROUTINE(int32) i32max3(int32 x1, int32 x2, int32 x3);105 ROUTINE(int32) i32max4(int32 x1, int32 x2, int32 x3, int32 x4);106 ROUTINE(int32) i32max5(int32 x1, int32 x2, int32 x3, int32 x4, int32 x5);107 108 ROUTINE(rgb8) rgb8max (rgb8 x1, rgb8 x2);109 ROUTINE(rgb8) rgb8max2(rgb8 x1, rgb8 x2);110 ROUTINE(rgb8) rgb8max3(rgb8 x1, rgb8 x2, rgb8 x3);111 ROUTINE(rgb8) rgb8max4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4);112 ROUTINE(rgb8) rgb8max5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5);113 73 114 74 /* ----------- */ … … 116 76 /* ----------- */ 117 77 118 ROUTINE(byte) ibit(int32 x, int n);119 ROUTINE(int32) sym_int32(int32x);120 ROUTINE(int) myLog2(int x);121 ROUTINE(int) next_power2(int x);122 ROUTINE(int) myGCD(int u, int v);123 ROUTINE(int) myLCM(int u, int v);78 int32_t i32bit(int32_t x, int32_t n); 79 int32_t sym_int32(int32_t x); 80 int32_t myLog2(int32_t x); 81 int32_t next_power2(int32_t x); 82 int32_t myGCD(int32_t u, int32_t v); 83 int32_t myLCM(int32_t u, int32_t v); 124 84 125 #ifdef __cplusplus126 }127 85 #endif 128 86 129 #else 130 //#pragma message(" Warning : attempt to re-include nrarith0.h") 131 #endif 87 // Local Variables: 88 // tab-width: 4 89 // c-basic-offset: 4 90 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 91 // indent-tabs-mode: nil 92 // End: 132 93 94 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 95 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith1.h
r772 r821 11 11 #define _NRARITH1_H_ 12 12 13 #ifdef __cplusplus 14 #ifdef PRAGMA_VERBOSE 15 #pragma message ("C++") 16 #endif 17 extern "C" { 18 #endif 19 20 #ifdef PRAGMA_VERBOSE 21 //#pragma message("- include nrarith1.h") 22 #endif 23 24 /* ======================================================================== */ 25 /* === Beta reduction ===================================================== */ 26 /* ======================================================================== */ 27 28 IMAGE_EXPORT(int32) sum_bvector (byte *v, long nl, long nh); 29 IMAGE_EXPORT(int32) sum_si16vector (sint16 *v, long nl, long nh); 30 IMAGE_EXPORT(int32) sum_si32vector (sint32 *v, long nl, long nh); 31 IMAGE_EXPORT(float) sum_f32vector (float32 *v, long nl, long nh); 32 33 // ================== 34 // === min_vector === 35 // ================== 36 37 IMAGE_EXPORT(sint8) min_si8vector (sint8 *v, long nl, long nh); 38 IMAGE_EXPORT(uint8) min_ui8vector (uint8 *v, long nl, long nh); 39 IMAGE_EXPORT(sint16) min_si16vector (sint16 *v, long nl, long nh); 40 IMAGE_EXPORT(uint16) min_ui16vector (uint16 *v, long nl, long nh); 41 IMAGE_EXPORT(sint32) min_si32vector (sint32 *v, long nl, long nh); 42 IMAGE_EXPORT(uint32) min_ui32vector (uint32 *v, long nl, long nh); 43 IMAGE_EXPORT(float32) min_f32vector (float32 *v, long nl, long nh); 44 IMAGE_EXPORT(float64) min_f64vector (float64 *v, long nl, long nh); 45 46 // ================== 47 // === max_vector === 48 // ================== 49 50 IMAGE_EXPORT(sint8) max_si8vector (sint8 *v, long nl, long nh); 51 IMAGE_EXPORT(uint8) max_ui8vector (uint8 *v, long nl, long nh); 52 IMAGE_EXPORT(sint16) max_si16vector (sint16 *v, long nl, long nh); 53 IMAGE_EXPORT(uint16) max_ui16vector (uint16 *v, long nl, long nh); 54 IMAGE_EXPORT(sint32) max_si32vector (sint32 *v, long nl, long nh); 55 IMAGE_EXPORT(uint32) max_ui32vector (uint32 *v, long nl, long nh); 56 57 IMAGE_EXPORT(float32) max_f32vector (float32 *v, long nl, long nh); 58 IMAGE_EXPORT(float64) max_f64vector (float64 *v, long nl, long nh); 59 60 // ====================== 61 // === min_vector_pos === 62 // ====================== 63 64 IMAGE_EXPORT(sint8) min_si8vector_pos (sint8 *v, long nl, long nh, int *pos); 65 IMAGE_EXPORT(uint8) min_ui8vector_pos (uint8 *v, long nl, long nh, int *pos); 66 IMAGE_EXPORT(sint16) min_si16vector_pos (sint16 *v, long nl, long nh, int *pos); 67 IMAGE_EXPORT(uint16) min_ui16vector_pos (uint16 *v, long nl, long nh, int *pos); 68 IMAGE_EXPORT(sint32) min_si32vector_pos (sint32 *v, long nl, long nh, int *pos); 69 IMAGE_EXPORT(uint32) min_ui32vector_pos (uint32 *v, long nl, long nh, int *pos); 70 71 IMAGE_EXPORT(float32)min_f32vector_pos (float32 *v, long nl, long nh, int *pos); 72 IMAGE_EXPORT(float64)min_f64vector_pos (float64 *v, long nl, long nh, int *pos); 73 74 // ====================== 75 // === max_vector_pos === 76 // ====================== 77 78 IMAGE_EXPORT(sint8) max_si8vector_pos (sint8 *v, long nl, long nh, int *pos); 79 IMAGE_EXPORT(uint8) max_ui8vector_pos (uint8 *v, long nl, long nh, int *pos); 80 IMAGE_EXPORT(sint16) max_si16vector_pos (sint16 *v, long nl, long nh, int *pos); 81 IMAGE_EXPORT(uint16) max_ui16vector_pos (uint16 *v, long nl, long nh, int *pos); 82 IMAGE_EXPORT(sint32) max_si32vector_pos (sint32 *v, long nl, long nh, int *pos); 83 IMAGE_EXPORT(uint32) max_ui32vector_pos (uint32 *v, long nl, long nh, int *pos); 84 85 IMAGE_EXPORT(float32)max_f32vector_pos (float32 *v, long nl, long nh, int *pos); 86 IMAGE_EXPORT(float64)max_f64vector_pos (float64 *v, long nl, long nh, int *pos); 13 /* 14 * ------------------ 15 * --- sum_vector --- 16 * ------------------ 17 */ 18 19 #define sum_type_vector(t,r) \ 20 r short_name(t,sum_,vector)(t * v, int32_t nl, int32_t nh) 21 22 sum_type_vector(int8_t, int32_t); 23 sum_type_vector(uint8_t, uint32_t); 24 sum_type_vector(int16_t, int32_t); 25 sum_type_vector(uint16_t, uint32_t); 26 sum_type_vector(int32_t, int32_t); 27 sum_type_vector(uint32_t, uint32_t); 28 sum_type_vector(float, float); 29 sum_type_vector(double, double); 30 31 /* 32 * ------------------ 33 * --- min_vector --- 34 * ------------------ 35 */ 36 37 #define min_type_vector(t) \ 38 t short_name(t,min_,vector)(t * v, int32_t nl, int32_t nh) 39 40 min_type_vector(int8_t); 41 min_type_vector(uint8_t); 42 min_type_vector(int16_t); 43 min_type_vector(uint16_t); 44 min_type_vector(int32_t); 45 min_type_vector(uint32_t); 46 min_type_vector(float); 47 min_type_vector(double); 48 49 50 /* 51 * ------------------ 52 * --- max_vector --- 53 * ------------------ 54 */ 55 56 #define max_type_vector(t) \ 57 t short_name(t,max_,vector)(t * v, int32_t nl, int32_t nh) 58 59 max_type_vector(int8_t); 60 max_type_vector(uint8_t); 61 max_type_vector(int16_t); 62 max_type_vector(uint16_t); 63 max_type_vector(int32_t); 64 max_type_vector(uint32_t); 65 max_type_vector(float); 66 max_type_vector(double); 67 68 69 /* 70 * ---------------------- 71 * --- min_vector_pos --- 72 * ---------------------- 73 */ 74 75 76 #define min_type_vector_pos(t) \ 77 t short_name(t,min_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) 78 79 min_type_vector_pos(int8_t); 80 min_type_vector_pos(uint8_t); 81 min_type_vector_pos(int16_t); 82 min_type_vector_pos(uint16_t); 83 min_type_vector_pos(int32_t); 84 min_type_vector_pos(uint32_t); 85 min_type_vector_pos(float); 86 min_type_vector_pos(double); 87 88 89 /* 90 * ---------------------- 91 * --- max_vector_pos --- 92 * ---------------------- 93 */ 94 95 #define max_type_vector_pos(t) \ 96 t short_name(t,max_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) 97 98 max_type_vector_pos(int8_t); 99 max_type_vector_pos(uint8_t); 100 max_type_vector_pos(int16_t); 101 max_type_vector_pos(uint16_t); 102 max_type_vector_pos(int32_t); 103 max_type_vector_pos(uint32_t); 104 max_type_vector_pos(float); 105 max_type_vector_pos(double); 106 87 107 88 108 // ============= … … 90 110 // ============= 91 111 92 IMAGE_EXPORT(void) beta_sum_rgb32vector (rgb32 *S,long nl,long nh, rgb32 *D); 93 IMAGE_EXPORT(void) beta_average_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D); 94 95 IMAGE_EXPORT(void) add_i32vector(int32 *S1, long nl,long nh, int32 *S2, int32 *D); 96 IMAGE_EXPORT(void) sub_i32vector(int32 *S1, long nl,long nh, int32 *S2, int32 *D); 97 98 IMAGE_EXPORT(void) cumulleft_i32vector (int32 *S, long nl, long nh, int32 *D); 99 IMAGE_EXPORT(void) cumulleft_rgb32vector(rgb32 *S, long nl, long nh, rgb32 *D); 100 101 IMAGE_EXPORT(void) cumulright_i32vector (int32 *S, long nl, long nh, int32 *D); 102 IMAGE_EXPORT(void) cumulright_rgb32vector(rgb32 *S, long nl, long nh, rgb32 *D); 103 104 IMAGE_EXPORT(void) mulc_i32vector (int32 *S, long nl, long nh, int32 c, int32 *D); 105 IMAGE_EXPORT(void) mulc_rgb32vector (rgb32 *S, long nl, long nh, int32 c, rgb32 *D); 106 IMAGE_EXPORT(void) divc_i32vector (int32 *S, long nl, long nh, int32 c, int32 *D); 107 IMAGE_EXPORT(void) divc_rgb32vector (rgb32 *S, long nl, long nh, int32 c, rgb32 *D); 108 109 IMAGE_EXPORT(void) mulfrac_i32vector (int32 *S, long nl, long nh, int32 a, int32 b, int32 *D); 110 IMAGE_EXPORT(void) mulfrac_rgb32vector(rgb32 *S, long nl, long nh, int32 a, int32 b, rgb32 *D); 111 112 #ifdef __cplusplus 113 } 114 #endif 112 #define add_type_vector(t) \ 113 void short_name(t,add_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) 114 115 add_type_vector(int8_t); 116 add_type_vector(uint8_t); 117 add_type_vector(int16_t); 118 add_type_vector(uint16_t); 119 add_type_vector(int32_t); 120 add_type_vector(uint32_t); 121 add_type_vector(float); 122 add_type_vector(double); 123 124 #define sub_type_vector(t) \ 125 void short_name(t,sub_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) 126 127 sub_type_vector(int8_t); 128 sub_type_vector(uint8_t); 129 sub_type_vector(int16_t); 130 sub_type_vector(uint16_t); 131 sub_type_vector(int32_t); 132 sub_type_vector(uint32_t); 133 sub_type_vector(float); 134 sub_type_vector(double); 135 136 #define mulc_type_vector(t) \ 137 void short_name(t,mulc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D) 138 139 mulc_type_vector(int8_t); 140 mulc_type_vector(uint8_t); 141 mulc_type_vector(int16_t); 142 mulc_type_vector(uint16_t); 143 mulc_type_vector(int32_t); 144 mulc_type_vector(uint32_t); 145 mulc_type_vector(float); 146 mulc_type_vector(double); 147 148 #define divc_type_vector(t) \ 149 void short_name(t,divc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D) 150 151 divc_type_vector(int8_t); 152 divc_type_vector(uint8_t); 153 divc_type_vector(int16_t); 154 divc_type_vector(uint16_t); 155 divc_type_vector(int32_t); 156 divc_type_vector(uint32_t); 157 divc_type_vector(float); 158 divc_type_vector(double); 159 160 161 #define cumulleft_type_vector(t) \ 162 void short_name(t,cumulleft_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) 163 164 cumulleft_type_vector(int8_t); 165 cumulleft_type_vector(uint8_t); 166 cumulleft_type_vector(int16_t); 167 cumulleft_type_vector(uint16_t); 168 cumulleft_type_vector(int32_t); 169 cumulleft_type_vector(uint32_t); 170 cumulleft_type_vector(float); 171 cumulleft_type_vector(double); 172 173 #define cumulright_type_vector(t) \ 174 void short_name(t,cumulright_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) 175 176 cumulright_type_vector(int8_t); 177 cumulright_type_vector(uint8_t); 178 cumulright_type_vector(int16_t); 179 cumulright_type_vector(uint16_t); 180 cumulright_type_vector(int32_t); 181 cumulright_type_vector(uint32_t); 182 cumulright_type_vector(float); 183 cumulright_type_vector(double); 184 185 186 #define mulfrac_type_vector(t) \ 187 void short_name(t,mulfrac_,vector)(t * S, int32_t nl, int32_t nh, int32_t a, int32_t b, t * D) 188 189 mulfrac_type_vector(int8_t); 190 mulfrac_type_vector(uint8_t); 191 mulfrac_type_vector(int16_t); 192 mulfrac_type_vector(uint16_t); 193 mulfrac_type_vector(int32_t); 194 mulfrac_type_vector(uint32_t); 195 mulfrac_type_vector(float); 196 mulfrac_type_vector(double); 197 198 199 200 void beta_sum_rgb32vector (rgb32 * S, int32_t nl, int32_t nh, rgb32 * D); 201 void beta_average_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D); 202 void cumulleft_rgb32vector (rgb32 * S, int32_t nl, int32_t nh, rgb32 * D); 203 void cumulright_rgb32vector (rgb32 * S, int32_t nl, int32_t nh, rgb32 * D); 204 void mulc_rgb32vector (rgb32 * S, int32_t nl, int32_t nh, int32 c, rgb32 * D); 205 void divc_rgb32vector (rgb32 * S, int32_t nl, int32_t nh, int32 c, rgb32 * D); 206 void mulfrac_rgb32vector (rgb32 * S, int32_t nl, int32_t nh, int32 a, int32 b, rgb32 * D); 207 115 208 116 209 #endif /* _NRARITH1_H_ */ 210 211 // Local Variables: 212 // tab-width: 4 213 // c-basic-offset: 4 214 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 215 // indent-tabs-mode: nil 216 // End: 217 218 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 219 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith2.h
r772 r821 11 11 #define _NRARITH2_H_ 12 12 13 #ifdef __cplusplus 14 #ifdef PRAGMA_VERBOSE 15 #pragma message ("C++") 16 #endif 17 extern "C" { 18 #endif 19 20 #ifdef PRAGMA_VERBOSE 21 //#pragma message("- include nrarith.h") 22 #endif 13 #include "nrc_os_config.h" 23 14 24 15 /* ------------------ */ … … 26 17 /* ------------------ */ 27 18 28 IMAGE_EXPORT(sint8) min_si8matrix (sint8 **m, long nrl,long nrh,long ncl, long nch); 29 IMAGE_EXPORT(uint8) min_ui8matrix (uint8 **m, long nrl,long nrh,long ncl, long nch); 30 IMAGE_EXPORT(sint16) min_si16matrix (sint16 **m, long nrl,long nrh,long ncl, long nch); 31 IMAGE_EXPORT(uint16) min_ui16matrix (uint16 **m, long nrl,long nrh,long ncl, long nch); 32 IMAGE_EXPORT(sint32) min_si32matrix (sint32 **m, long nrl,long nrh,long ncl, long nch); 33 IMAGE_EXPORT(uint32) min_ui32matrix (uint32 **m, long nrl,long nrh,long ncl, long nch); 34 IMAGE_EXPORT(sint64) min_si64matrix (sint64 **m, long nrl,long nrh,long ncl, long nch); 35 IMAGE_EXPORT(uint64) min_ui64matrix (uint64 **m, long nrl,long nrh,long ncl, long nch); 36 IMAGE_EXPORT(float32) min_f32matrix (float32 **m, long nrl,long nrh,long ncl, long nch); 37 IMAGE_EXPORT(float64) min_f64matrix (float64 **m, long nrl,long nrh,long ncl, long nch); 19 #define min_type_matrix(t) \ 20 t short_name(t,min_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) 21 22 min_type_matrix(int8_t); 23 min_type_matrix(uint8_t); 24 min_type_matrix(int16_t); 25 min_type_matrix(uint16_t); 26 min_type_matrix(int32_t); 27 min_type_matrix(uint32_t); 28 min_type_matrix(int64_t); 29 min_type_matrix(uint64_t); 30 min_type_matrix(float); 31 min_type_matrix(double); 32 38 33 39 34 /* ------------------ */ … … 41 36 /* ------------------ */ 42 37 43 IMAGE_EXPORT(sint8) max_si8matrix (sint8 **m, long nrl,long nrh,long ncl, long nch); 44 IMAGE_EXPORT(uint8) max_ui8matrix (uint8 **m, long nrl,long nrh,long ncl, long nch); 45 IMAGE_EXPORT(sint16) max_si16matrix (sint16 **m, long nrl,long nrh,long ncl, long nch); 46 IMAGE_EXPORT(uint16) max_ui16matrix (uint16 **m, long nrl,long nrh,long ncl, long nch); 47 IMAGE_EXPORT(sint32) max_si32matrix (sint32 **m, long nrl,long nrh,long ncl, long nch); 48 IMAGE_EXPORT(uint32) max_ui32matrix (uint32 **m, long nrl,long nrh,long ncl, long nch); 49 IMAGE_EXPORT(sint64) max_si64matrix (sint64 **m, long nrl,long nrh,long ncl, long nch); 50 IMAGE_EXPORT(uint64) max_ui64matrix (uint64 **m, long nrl,long nrh,long ncl, long nch); 51 IMAGE_EXPORT(float32) max_f32matrix (float32 **m, long nrl,long nrh,long ncl, long nch); 52 IMAGE_EXPORT(float64) max_f64matrix (float64 **m, long nrl,long nrh,long ncl, long nch); 38 #define max_type_matrix(t) \ 39 t short_name(t,max_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) 40 41 max_type_matrix(int8_t); 42 max_type_matrix(uint8_t); 43 max_type_matrix(int16_t); 44 max_type_matrix(uint16_t); 45 max_type_matrix(int32_t); 46 max_type_matrix(uint32_t); 47 max_type_matrix(int64_t); 48 max_type_matrix(uint64_t); 49 max_type_matrix(float); 50 max_type_matrix(double); 51 53 52 54 53 /* ------------------ */ … … 56 55 /* ------------------ */ 57 56 58 IMAGE_EXPORT(void) add_si8matrix (sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 **Y, sint8 **Z); 59 IMAGE_EXPORT(void) add_ui8matrix (uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 **Y, uint8 **Z); 60 IMAGE_EXPORT(void) add_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y, sint16 **Z); 61 IMAGE_EXPORT(void) add_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y, uint16 **Z); 62 IMAGE_EXPORT(void) add_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y, sint32 **Z); 63 IMAGE_EXPORT(void) add_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y, uint32 **Z); 64 IMAGE_EXPORT(void) add_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y, sint64 **Z); 65 IMAGE_EXPORT(void) add_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y, uint64 **Z); 66 67 IMAGE_EXPORT(void) add_f32matrix (float32 **X, long nrl,long nrh,long ncl, long nch, float32 **Y, float32 **Z); 68 IMAGE_EXPORT(void) add_f64matrix (float64 **X, long nrl,long nrh,long ncl, long nch, float64 **Y, float64 **Z); 69 70 IMAGE_EXPORT(void) add_rgb8matrix (rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z); 71 IMAGE_EXPORT(void) add_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z); 57 #define add_type_matrix(t) \ 58 void short_name(t,add_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) 59 60 add_type_matrix(int8_t); 61 add_type_matrix(uint8_t); 62 add_type_matrix(int16_t); 63 add_type_matrix(uint16_t); 64 add_type_matrix(int32_t); 65 add_type_matrix(uint32_t); 66 add_type_matrix(int64_t); 67 add_type_matrix(uint64_t); 68 add_type_matrix(float); 69 add_type_matrix(double); 70 71 void add_rgb8matrix (rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z); 72 void add_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z); 73 72 74 73 75 /* -------------------- */ … … 75 77 /* -------------------- */ 76 78 77 IMAGE_EXPORT(void) addc_si8matrix (sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 y, sint8 **Z); 78 IMAGE_EXPORT(void) addc_ui8matrix (uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 y, uint8 **Z); 79 IMAGE_EXPORT(void) addc_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16 **Z); 80 IMAGE_EXPORT(void) addc_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16 **Z); 81 IMAGE_EXPORT(void) addc_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32 **Z); 82 IMAGE_EXPORT(void) addc_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32 **Z); 83 IMAGE_EXPORT(void) addc_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64 **Z); 84 IMAGE_EXPORT(void) addc_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64 **Z); 85 86 IMAGE_EXPORT(void) addc_f32matrix (float32 **X, long nrl,long nrh,long ncl, long nch, float32 y, float32 **Z); 87 IMAGE_EXPORT(void) addc_f64matrix (float64 **X, long nrl,long nrh,long ncl, long nch, float64 y, float64 **Z); 88 89 IMAGE_EXPORT(void) addc_rgb8matrix (rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 y, rgb8 **Z); 90 IMAGE_EXPORT(void) addc_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 y, rgbx8 **Z); 79 #define addc_type_matrix(t) \ 80 void short_name(t,addc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) 81 82 addc_type_matrix(int8_t); 83 addc_type_matrix(uint8_t); 84 addc_type_matrix(int16_t); 85 addc_type_matrix(uint16_t); 86 addc_type_matrix(int32_t); 87 addc_type_matrix(uint32_t); 88 addc_type_matrix(int64_t); 89 addc_type_matrix(uint64_t); 90 addc_type_matrix(float); 91 addc_type_matrix(double); 92 93 void addc_rgb8matrix (rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z); 94 void addc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z); 95 91 96 92 97 /* ----------- */ … … 94 99 /* ----------- */ 95 100 96 IMAGE_EXPORT(void) sub_si8matrix (sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 **Y, sint8 **Z); 97 IMAGE_EXPORT(void) sub_ui8matrix (uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 **Y, uint8 **Z); 98 IMAGE_EXPORT(void) sub_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y, sint16 **Z); 99 IMAGE_EXPORT(void) sub_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y, uint16 **Z); 100 IMAGE_EXPORT(void) sub_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y, sint32 **Z); 101 IMAGE_EXPORT(void) sub_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y, uint32 **Z); 102 IMAGE_EXPORT(void) sub_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y, sint64 **Z); 103 IMAGE_EXPORT(void) sub_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y, uint64 **Z); 104 105 IMAGE_EXPORT(void) sub_f32matrix (float32 **X, long nrl,long nrh,long ncl, long nch, float32 **Y, float32 **Z); 106 IMAGE_EXPORT(void) sub_f64matrix (float64 **X, long nrl,long nrh,long ncl, long nch, float64 **Y, float64 **Z); 107 108 IMAGE_EXPORT(void) sub_rgb8matrix (rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z); 109 IMAGE_EXPORT(void) sub_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z); 101 #define sub_type_matrix(t) \ 102 void short_name(t,sub_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) 103 104 sub_type_matrix(int8_t); 105 sub_type_matrix(uint8_t); 106 sub_type_matrix(int16_t); 107 sub_type_matrix(uint16_t); 108 sub_type_matrix(int32_t); 109 sub_type_matrix(uint32_t); 110 sub_type_matrix(int64_t); 111 sub_type_matrix(uint64_t); 112 sub_type_matrix(float); 113 sub_type_matrix(double); 114 115 void sub_rgb8matrix (rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z); 116 void sub_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z); 117 110 118 111 119 /* --------------------- */ … … 113 121 /* --------------------- */ 114 122 115 IMAGE_EXPORT(void) subc_si8matrix (sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 y, sint8 **Z); 116 IMAGE_EXPORT(void) subc_ui8matrix (uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 y, uint8 **Z); 117 IMAGE_EXPORT(void) subc_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16 **Z); 118 IMAGE_EXPORT(void) subc_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16 **Z); 119 IMAGE_EXPORT(void) subc_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32 **Z); 120 IMAGE_EXPORT(void) subc_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32 **Z); 121 IMAGE_EXPORT(void) subc_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64 **Z); 122 IMAGE_EXPORT(void) subc_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64 **Z); 123 124 IMAGE_EXPORT(void) subc_f32matrix (float32 **X, long nrl,long nrh,long ncl, long nch, float32 y, float32 **Z); 125 IMAGE_EXPORT(void) subc_f64matrix (float64 **X, long nrl,long nrh,long ncl, long nch, float64 y, float64 **Z); 126 127 IMAGE_EXPORT(void) subc_rgb8matrix (rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 y, rgb8 **Z); 128 IMAGE_EXPORT(void) subc_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 y, rgbx8 **Z); 129 130 /* --------------------- */ 131 /* --- Sub constante --- */ 123 #define subc_type_matrix(t) \ 124 void short_name(t,subc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) 125 126 subc_type_matrix(int8_t); 127 subc_type_matrix(uint8_t); 128 subc_type_matrix(int16_t); 129 subc_type_matrix(uint16_t); 130 subc_type_matrix(int32_t); 131 subc_type_matrix(uint32_t); 132 subc_type_matrix(int64_t); 133 subc_type_matrix(uint64_t); 134 subc_type_matrix(float); 135 subc_type_matrix(double); 136 137 void subc_rgb8matrix (rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z); 138 void subc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z); 139 140 /* --------------------- */ 141 /* --- Mul constante --- */ 132 142 /* --------------------- */ 133 143 134 144 // Z = X * y 135 IMAGE_EXPORT(void) mulc_si8matrix (sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 y, sint8 **Z); 136 IMAGE_EXPORT(void) mulc_ui8matrix (uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 y, uint8 **Z); 137 IMAGE_EXPORT(void) mulc_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16 **Z); 138 IMAGE_EXPORT(void) mulc_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16 **Z); 139 IMAGE_EXPORT(void) mulc_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32 **Z); 140 IMAGE_EXPORT(void) mulc_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32 **Z); 141 IMAGE_EXPORT(void) mulc_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64 **Z); 142 IMAGE_EXPORT(void) mulc_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64 **Z); 143 144 IMAGE_EXPORT(void) mulc_f32matrix (float32 **X, long nrl,long nrh,long ncl, long nch, float32 y, float32 **Z); 145 IMAGE_EXPORT(void) mulc_f64matrix (float64 **X, long nrl,long nrh,long ncl, long nch, float64 y, float64 **Z); 146 147 IMAGE_EXPORT(void) mulc_rgb8matrix (rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 y, rgb8 **Z); 148 IMAGE_EXPORT(void) mulc_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 y, rgbx8 **Z); 145 146 #define mulc_type_matrix(t) \ 147 void short_name(t,mulc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) 148 149 mulc_type_matrix(int8_t); 150 mulc_type_matrix(uint8_t); 151 mulc_type_matrix(int16_t); 152 mulc_type_matrix(uint16_t); 153 mulc_type_matrix(int32_t); 154 mulc_type_matrix(uint32_t); 155 mulc_type_matrix(int64_t); 156 mulc_type_matrix(uint64_t); 157 mulc_type_matrix(float); 158 mulc_type_matrix(double); 159 160 void mulc_rgb8matrix (rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z); 161 void mulc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z); 162 149 163 150 164 /* --------------- */ 151 165 /* --- MulFrac --- */ 152 166 /* --------------- */ 153 // m2 = (a*m1)/b 154 IMAGE_EXPORT(void) mulfrac_bmatrix (byte **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, byte **m2); 155 IMAGE_EXPORT(void) mulfrac_si16matrix (sint16 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, sint16 **m2); 156 IMAGE_EXPORT(void) mulfrac_ui16matrix (uint16 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, uint16 **m2); 157 IMAGE_EXPORT(void) mulfrac_si32matrix (sint32 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, sint32 **m2); 158 IMAGE_EXPORT(void) mulfrac_ui32matrix (uint32 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, uint32 **m2); 159 IMAGE_EXPORT(void) mulfrac_rgb8matrix (rgb8 **m1, long nrl,long nrh,long ncl, long nch, rgb32 a, rgb32 b, rgb8 **m2); 160 IMAGE_EXPORT(void) mulfrac_rgbx8matrix(rgbx8 **m1, long nrl,long nrh,long ncl, long nch, rgbx32 a, rgbx32 b, rgbx8 **m2); 161 162 IMAGE_EXPORT(void) mulfrack_rgb8matrix (rgb8 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, rgb8 **m2); 163 IMAGE_EXPORT(void) mulfrack_rgbx8matrix(rgbx8 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 b, rgbx8 **m2); 167 168 // m2 = (a * m1) / b 169 170 #define mulfrac_type_matrix(t) \ 171 void short_name(t,mulfrac_,matrix)(t ** X, int32_t nrl, int32_t nrh, \ 172 int32_t ncl, int32_t nch, int32_t a, int32_t b, t ** Y) 173 174 mulfrac_type_matrix(int8_t); 175 mulfrac_type_matrix(uint8_t); 176 mulfrac_type_matrix(int16_t); 177 mulfrac_type_matrix(uint16_t); 178 mulfrac_type_matrix(int32_t); 179 mulfrac_type_matrix(uint32_t); 180 mulfrac_type_matrix(int64_t); 181 mulfrac_type_matrix(uint64_t); 182 mulfrac_type_matrix(float); 183 mulfrac_type_matrix(double); 184 185 void mulfrack_rgb8matrix (rgb8 ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32 a, int32 b, rgb8 ** m2); 186 void mulfrack_rgbx8matrix(rgbx8 ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32 a, int32 b, rgbx8 ** m2); 187 164 188 165 189 /* ---------------- */ 166 190 /* --- MulShift --- */ 167 191 /* ---------------- */ 168 // m3 = (a*m1)>>s 169 IMAGE_EXPORT(void) mulshift_bmatrix (byte **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, byte **m2); 170 IMAGE_EXPORT(void) mulshift_i16matrix (int16 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, int16 **m2); 171 IMAGE_EXPORT(void) mulshift_ui16matrix (uint16 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, uint16 **m2); 172 IMAGE_EXPORT(void) mulshift_i32matrix (int32 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, int32 **m2); 173 IMAGE_EXPORT(void) mulshift_ui32matrix (uint32 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, uint32 **m2); 174 IMAGE_EXPORT(void) mulshift_rgb8matrix (rgb8 **m1, long nrl,long nrh,long ncl, long nch, rgb32 a, rgb32 s, rgb8 **m2); 175 IMAGE_EXPORT(void) mulshift_rgbx8matrix(rgbx8 **m1, long nrl,long nrh,long ncl, long nch, rgbx32 a, rgbx32 s, rgbx8 **m2); 176 177 IMAGE_EXPORT(void) mulshiftk_rgb8matrix (rgb8 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, rgb8 **m2); 178 IMAGE_EXPORT(void) mulshiftk_rgbx8matrix(rgbx8 **m1, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, rgbx8 **m2); 179 180 IMAGE_EXPORT(void) quadratic_error_si16matrix(sint16 **m1,long nrl,long nrh,long ncl, long nch, sint16 **m2, sint16 **m3); 181 182 183 #ifdef __cplusplus 184 } 185 #endif 192 // m3 = (a * m1) >> s 193 194 #define mulshift_type_matrix(t) \ 195 void short_name(t,mulshift_,matrix)(t ** X, int32_t nrl, int32_t nrh, \ 196 int32_t ncl, int32_t nch, int32_t a, int32_t s, t ** Y) 197 198 mulshift_type_matrix(int8_t); 199 mulshift_type_matrix(uint8_t); 200 mulshift_type_matrix(int16_t); 201 mulshift_type_matrix(uint16_t); 202 mulshift_type_matrix(int32_t); 203 mulshift_type_matrix(uint32_t); 204 mulshift_type_matrix(int64_t); 205 mulshift_type_matrix(uint64_t); 206 mulshift_type_matrix(float); 207 mulshift_type_matrix(double); 208 209 void mulshift_rgb8matrix (rgb8 **m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 a, rgb32 s, rgb8 ** m2); 210 void mulshift_rgbx8matrix(rgbx8 **m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 s, rgbx8 ** m2); 211 212 void mulshiftk_rgb8matrix (rgb8 ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32 a, int32 s, rgb8 ** m2); 213 void mulshiftk_rgbx8matrix(rgbx8 ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32 a, int32 s, rgbx8 ** m2); 214 215 void quadratic_error_si16matrix(sint16 ** m1, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, sint16 ** m2, sint16 ** m3); 216 186 217 187 218 #endif /* _NRARITH2_H_ */ 219 220 // Local Variables: 221 // tab-width: 4 222 // c-basic-offset: 4 223 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 224 // indent-tabs-mode: nil 225 // End: 226 227 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 228 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nrarith2x.h
r772 r821 11 11 #define _NRARITH2X_H_ 12 12 13 #ifdef __cplusplus 14 #ifdef PRAGMA_VERBOSE 15 #pragma message ("C++") 16 #endif 17 extern "C" { 18 #endif 13 // Add conditionnel 19 14 20 #ifdef PRAGMA_VERBOSE 21 #pragma message("- include nrarith2x.h") 22 #endif 15 #define addcnz_type_matrix(t) \ 16 void short_name(t,addcnz_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) 17 18 addcnz_type_matrix(int8_t); 19 addcnz_type_matrix(uint8_t); 20 addcnz_type_matrix(int16_t); 21 addcnz_type_matrix(uint16_t); 22 addcnz_type_matrix(int32_t); 23 addcnz_type_matrix(uint32_t); 24 addcnz_type_matrix(int64_t); 25 addcnz_type_matrix(uint64_t); 26 addcnz_type_matrix(float); 27 addcnz_type_matrix(double); 23 28 24 29 25 // Add conditionnel 26 IMAGE_EXPORT(void) addc_bmatrix (byte **src,long nrl,long nrh,long ncl, long nch, byte cte, byte **dst); 27 IMAGE_EXPORT(void) addc_smatrix (sint16 **src,long nrl,long nrh,long ncl, long nch, short cte, sint16 **dst); 28 IMAGE_EXPORT(void) addc_usmatrix(uint16 **src,long nrl,long nrh,long ncl, long nch, short cte, uint16 **dst); 30 #define addandc_type_matrix(t) \ 31 void short_name(t,addandc_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) 29 32 30 IMAGE_EXPORT(void) addandc_bmatrix (byte **src,long nrl,long nrh,long ncl, long nch, byte cte, byte **dst); 31 IMAGE_EXPORT(void) addandc_si16matrix (sint16 **src,long nrl,long nrh,long ncl, long nch, short cte, sint16 **dst); 32 IMAGE_EXPORT(void) addandc_ui16matrix (uint16 **src,long nrl,long nrh,long ncl, long nch, short cte, uint16 **dst); 33 addandc_type_matrix(int8_t); 34 addandc_type_matrix(uint8_t); 35 addandc_type_matrix(int16_t); 36 addandc_type_matrix(uint16_t); 37 addandc_type_matrix(int32_t); 38 addandc_type_matrix(uint32_t); 39 addandc_type_matrix(int64_t); 40 addandc_type_matrix(uint64_t); 41 addandc_type_matrix(float); 42 addandc_type_matrix(double); 33 43 34 IMAGE_EXPORT(void) addcnz_bmatrix(byte **src,long nrl,long nrh,long ncl, long nch, byte cte, byte **dst);35 44 36 IMAGE_EXPORT(int) count_bmatrix(byte **m, long nrl,long nrh,long ncl, long nch); 37 /* 38 * renvoie la somme des points de la matrice 39 */ 45 /* renvoie la somme des points de la matrice */ 40 46 41 #ifdef __cplusplus 42 } 43 #endif 47 #define sum_type_matrix(t,rt) \ 48 rt short_name(t,sum_,matrix)(t ** m, int32_t nrl, int32_t nrh,int32_t ncl, int32_t nch) 49 50 sum_type_matrix(int8_t, int32_t); 51 sum_type_matrix(uint8_t, uint32_t); 52 sum_type_matrix(int16_t, int32_t); 53 sum_type_matrix(uint16_t, uint32_t); 54 sum_type_matrix(int32_t, int64_t); 55 sum_type_matrix(uint32_t, uint64_t); 56 sum_type_matrix(int64_t, int64_t); 57 sum_type_matrix(uint64_t, uint64_t); 58 sum_type_matrix(float, float); 59 sum_type_matrix(double, double); 60 61 44 62 45 63 #endif /* _NRUTIL_H_ */ 64 65 // Local Variables: 66 // tab-width: 4 67 // c-basic-offset: 4 68 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 69 // indent-tabs-mode: nil 70 // End: 71 72 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 73 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nrc_os_config.h
r798 r821 7 7 #define printf(...) giet_tty_printf(__VA_ARGS__) 8 8 9 #define open(x, y) giet_fat_open(x, y) 10 #define close(x) giet_fat_close(x) 11 #define read(x, y, z) giet_fat_read(x, y, z) 12 #define write(x, y, z) giet_fat_write(x, y, z) 13 #define fprintf(x, ...) giet_fat_fprintf(x, __VA_ARGS__) 14 #define fscanf(x, ...) ; 15 #define exit(x) giet_pthread_exit(NULL) 16 #else 9 #define open(x, y) giet_fat_open(x, y) 10 #define close(x) giet_fat_close(x) 11 #define read(x, y, z) giet_fat_read(x, y, z) 12 #define write(x, y, z) giet_fat_write(x, y, z) 13 #define fprintf(x, ...) giet_fat_fprintf(x, __VA_ARGS__) 14 //#define fscanf(x, ...) ; 15 #define exit(x) giet_pthread_exit(NULL) 16 17 #define pthread_barrier_t giet_barrier_t 18 #define pthread_spinlock_t user_lock_t 19 #define pthread_spin_lock(x) lock_acquire(x) 20 #define pthread_spin_unlock(x) lock_release(x) 21 #define pthread_spin_init(x, y) lock_init(x) 22 #define pthread_mutexlock_t user_lock_t 23 #define pthread_mutex_lock(x) lock_acquire(x) 24 #define pthread_mutex_unlock(x) lock_release(x) 25 #define pthread_mutex_init(x, y) lock_init(x) 26 #define pthread_barrier_init(x,y,z) barrier_init(x, z) 27 #define pthread_barrier_wait(x) barrier_wait(x) 28 #define pthread_barrier_destroy(x) 29 #define pthread_create(x,y,z,t) giet_pthread_create(x,y,z,t) 30 #define pthread_join(x,y) giet_pthread_join(x,y) 17 31 #endif 18 32 -
soft/giet_vm/applications/rosenfeld/nrc2/include/nrkernel.h
r772 r821 11 11 #define __NRKERNEL_H__ 12 12 13 #ifdef __cplusplus 14 #pragma message ("C++") 15 extern "C" { 16 #endif 17 18 #ifdef VERBOSE_PRAGMA 19 //#pragma message ("- *** include nrkernel.h ***") 13 14 #if TARGET_OS == GIETVM 15 #define nrerror(...) ({ \ 16 printf("*** NRC Runtime Error:\n "); \ 17 printf(__VA_ARGS__); \ 18 exit(1); \ 19 }) 20 #else 21 #define nrerror(...) ({ \ 22 fprintf(stderr, "*** NRC Runtime Error:\n "); \ 23 fprintf(stderr, __VA_ARGS__); \ 24 exit(1); \ 25 }) 20 26 #endif 21 27 22 void nrerror(char error_text[]);23 void nrerror0(char error_text[]);24 void nrerror1(char *format, ...);25 26 void Error (char *format, ...);27 void Warning(char *format, ...);28 28 29 29 30 #ifdef __cplusplus31 }32 #endif33 30 34 31 #endif // __NRKERNEL_H__ -
soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h
r772 r821 16 16 #define _NRTYPE_H_ 17 17 18 #ifdef __cplusplus 19 #pragma message ("C++") 20 extern "C" { 21 #endif 22 23 #define VERBOSE_PRAGMA 24 25 #ifdef VERBOSE_PRAGMA 26 //#pragma message ("- include nrtype.h") 27 #endif 18 #include <stdint.h> 28 19 29 20 // ---------------------------------- // … … 31 22 // ---------------------------------- // 32 23 24 33 25 #include "mypredef.h" 34 26 35 typedef unsigned char BOOLEAN;36 typedef unsigned char boolean;37 typedef int BOOL;38 #ifdef VERBOSE_PRAGMA39 //#pragma message("boolean")40 #endif41 27 42 #ifndef TRUE 43 #define TRUE 1 44 #else 45 #pragma message(" ATTENTION : TRUE already defined") 46 #endif 28 // Short names 47 29 48 #ifndef FALSE 49 #define FALSE 0 50 #else 51 #pragma message(" ATTENTION : FALSE already defined") 52 #endif 30 #define sn_int8_t(p,s) p##i8##s 31 #define sn_int16_t(p,s) p##i16##s 32 #define sn_int32_t(p,s) p##i32##s 33 #define sn_int64_t(p,s) p##i64##s 34 #define sn_uint8_t(p,s) p##ui8##s 35 #define sn_uint16_t(p,s) p##ui16##s 36 #define sn_uint32_t(p,s) p##ui32##s 37 #define sn_uint64_t(p,s) p##ui64##s 38 #define sn_float(p,s) p##f32##s 39 #define sn_double(p,s) p##f64##s 40 #define sn_void_p(p,s) p##v##s 41 #define sn_rgb8(p,s) p##rgb8##s 42 #define sn_rgbx8(p,s) p##rgbx8##s 43 #define sn_rgb32(p,s) p##rgb32##s 44 #define sn_rgbx32(p,s) p##rgbx32##s 45 #define sn_complex32(p,s) p##c32##s 46 #define sn_complex64(p,s) p##c64##s 47 #define sn_si16Point(p,s) p##si16P##s 48 #define sn_ui16Point(p,s) p##ui16P##s 49 #define sn_si32Point(p,s) p##si32P##s 50 #define sn_ui32Point(p,s) p##ui32P##s 51 #define sn_f32Point(p,s) p##f32P##s 52 #define sn_si16Triplet(p,s) p##si16T##s 53 #define sn_ui16Triplet(p,s) p##ui16T##s 54 #define sn_si32Triplet(p,s) p##si32T##s 55 #define sn_ui32Triplet(p,s) p##ui32T##s 56 #define sn_f32Triplet(p,s) p##f32T##s 57 58 #define short_name(t,p,s) sn_##t(p,s) 59 60 #define NR_END 0 61 #define FREE_ARG char* 62 63 64 53 65 54 66 /* ------------------------------- */ 55 67 /* --- 8, 16, 32, 64 bit types --- */ 56 68 /* ------------------------------- */ 57 // old types to be removed58 //typedef sint16 usint16 ;59 //typedef int uint;60 69 61 // half-typed types 70 typedef void * void_p; 71 typedef char byte; 62 72 63 typedef char byte; 64 //typedef char usint16 ; 65 //typedef char uint; 66 67 typedef char int8; 68 typedef short int16; 69 typedef int int32; 70 typedef long long int64; 73 typedef int8_t int8; 74 typedef int16_t int16; 75 typedef int32_t int32; 76 typedef int64_t int64; 71 77 72 #ifdef LIBCOMP73 #if defined(myCompiler_ICC) || defined (myCompiler_MSC)74 typedef __int64 int64;75 #else76 typedef long long int64;77 #endif78 #endif79 78 80 79 // full-typed types 81 typedef signed charsint8;82 typedef u nsigned charuint8;80 typedef int8_t sint8; 81 typedef uint8_t uint8; 83 82 84 typedef signed short sint16;85 typedef u nsigned shortuint16;83 typedef int16_t sint16; 84 typedef uint16_t uint16; 86 85 87 typedef signed intsint32;88 typedef u nsigned int uint32;86 typedef int32_t sint32; 87 typedef uint32_t uint32; 89 88 90 #if defined(myCompiler_ICC) || defined (myCompiler_MSC) 91 typedef __int64 int64; 92 typedef signed __int64 sint64; 93 typedef unsigned __int64 uint64; 94 #else 95 typedef signed long long sint64; 96 typedef unsigned long long uint64; 97 #endif 89 typedef int64_t sint64; 90 typedef uint64_t uint64; 98 91 99 typedef float float32; 100 typedef double float64; 92 typedef float float32; 93 typedef double float64; 94 101 95 102 96 /* -------------------- */ 103 97 /* --- complex type --- */ 104 98 /* -------------------- */ 99 105 100 typedef struct { float32 x; float32 y;} complex32; 106 101 typedef struct { float64 x; float64 y;} complex64; … … 199 194 } bitfield8; 200 195 201 #ifdef __cplusplus202 }203 #endif204 196 205 197 #endif // _NR_TYPE_H_ 198 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c
r772 r821 29 29 #include <stdlib.h> 30 30 #include <malloc.h> 31 #include < math.h> // fabs31 #include <stdint.h> 32 32 33 #include "nrc_os_config.h" 33 34 #include "mypredef.h" 34 35 #include "nrtype.h" … … 38 39 39 40 #include "nralloc1.h" 40 #include "nrset1.h" // set 141 41 42 42 43 long nr_end = NR_END;44 43 45 // ------------------------------------------------------------------ 46 // -- deprecated type (original NRC type, not enough typed vector) -- 47 // ------------------------------------------------------------------ 48 49 /* ---------------------------------------- */ 50 NRC_EXPORT(sint8*) si8vector(long nl, long nh) 51 /* ---------------------------------------- */ 52 { 53 sint8 *v; 54 55 v=(sint8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint8))); 56 if (!v) nrerror("allocation failure in si8vector()"); 57 return v-nl+NR_END; 58 } 59 /* ---------------------------------------- */ 60 NRC_EXPORT(uint8*) ui8vector(long nl, long nh) 61 /* ---------------------------------------- */ 62 { 63 uint8 *v; 64 65 v=(uint8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint8))); 66 if (!v) nrerror("allocation failure in ui8vector()"); 67 return v-nl+NR_END; 68 } 69 /* -------------------------------------------- */ 70 NRC_EXPORT(sint16*) si16vector(long nl, long nh) 71 /* -------------------------------------------- */ 72 { 73 sint16 *v; 74 75 v=(sint16 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint16))); 76 if (!v) nrerror("allocation failure in si16vector()"); 77 return v-nl+NR_END; 78 } 79 /* -------------------------------------------- */ 80 NRC_EXPORT(uint16*) ui16vector(long nl, long nh) 81 /* -------------------------------------------- */ 82 { 83 uint16 *v; 84 85 v=(uint16 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint16))); 86 if (!v) nrerror("allocation failure in ui16vector()"); 87 return v-nl+NR_END; 88 } 89 /* -------------------------------------------- */ 90 IMAGE_EXPORT(sint32*) si32vector(long nl, long nh) 91 /* -------------------------------------------- */ 92 { 93 sint32 *v; 94 95 v=(sint32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint32))); 96 if (!v) nrerror("allocation failure in si32vector()"); 97 if(!v) return NULL; 98 return v-nl+NR_END; 99 } 100 /* -------------------------------------------- */ 101 IMAGE_EXPORT(uint32*) ui32vector(long nl, long nh) 102 /* -------------------------------------------- */ 103 { 104 uint32 *v; 105 106 v=(uint32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint32))); 107 if (!v) nrerror("allocation failure in ui32vector()"); 108 if(!v) return NULL; 109 return v-nl+NR_END; 110 } 111 /* -------------------------------------------- */ 112 IMAGE_EXPORT(sint64*) si64vector(long nl, long nh) 113 /* -------------------------------------------- */ 114 { 115 sint64 *v; 116 117 v=(sint64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint64))); 118 if (!v) nrerror("allocation failure in si64vector()"); 119 return v-nl+NR_END; 120 } 121 /* -------------------------------------------- */ 122 IMAGE_EXPORT(uint64*) ui64vector(long nl, long nh) 123 /* -------------------------------------------- */ 124 { 125 uint64 *v; 126 127 v=(uint64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint64))); 128 if (!v) nrerror("allocation failure in ui64vector()"); 129 return v-nl+NR_END; 130 } 131 /* ------------------------------------------ */ 132 NRC_EXPORT(float32*) f32vector(long nl, long nh) 133 /* ------------------------------------------ */ 134 { 135 float32 *v; 136 137 v=(float32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float32))); 138 if (!v) nrerror("allocation failure in f32vector()"); 139 if(!v) return NULL; 140 return v-nl+NR_END; 141 } 142 /* ------------------------------------------ */ 143 NRC_EXPORT(float64*) f64vector(long nl, long nh) 144 /* ------------------------------------------ */ 145 { 146 float64 *v; 147 148 v=(float64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float64))); 149 if (!v) nrerror("allocation failure in f64vector()"); 150 if(!v) return NULL; 151 return v-nl+NR_END; 152 } 153 /* ------------------------------------------ */ 154 IMAGE_EXPORT(rgb8*) rgb8vector(long nl, long nh) 155 /* ------------------------------------------ */ 156 { 157 rgb8 *v; 158 159 v=(rgb8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgb8))); 160 if (!v) nrerror("allocation failure in rgb8vector()"); 161 return v-nl+NR_END; 162 } 163 /* -------------------------------------------- */ 164 IMAGE_EXPORT(rgbx8*) rgbx8vector(long nl, long nh) 165 /* -------------------------------------------- */ 166 { 167 rgbx8 *v; 168 169 v=(rgbx8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgbx8))); 170 if (!v) nrerror("allocation failure in rgbx8vector()"); 171 return v-nl+NR_END; 172 } 173 /* -------------------------------------------- */ 174 IMAGE_EXPORT(rgb32*) rgb32vector(long nl, long nh) 175 /* -------------------------------------------- */ 176 { 177 rgb32 *v; 178 179 v=(rgb32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgb32))); 180 if (!v) nrerror("allocation failure in rgb32vector()"); 181 return v-nl+NR_END; 44 #undef type_vector 45 #define type_vector(t) \ 46 t * short_name(t,,vector)(int32_t nl, int32_t nh) \ 47 { \ 48 t * v; \ 49 v = malloc((nh - nl + 1 + NR_END) * sizeof(t)); \ 50 if (v == NULL) { \ 51 nrerror("*** Error: allocation failure in %s\n", __func__); \ 52 } \ 53 return v - nl + NR_END; \ 182 54 } 183 55 184 /* ---------------------------------------- */ 185 IMAGE_EXPORT(void**) vvector(long nl, long nh) 186 /* ---------------------------------------- */ 187 { 188 void **v; 189 190 v=(void**)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(void*))); 191 if (!v) nrerror("allocation failure in vvector()"); 192 return v-nl+NR_END; 56 type_vector(int8_t); 57 type_vector(uint8_t); 58 type_vector(int16_t); 59 type_vector(uint16_t); 60 type_vector(int32_t); 61 type_vector(uint32_t); 62 type_vector(int64_t); 63 type_vector(uint64_t); 64 type_vector(float); 65 type_vector(double); 66 type_vector(void_p); 67 type_vector(rgb8); 68 type_vector(rgbx8); 69 type_vector(rgb32); 70 71 72 73 #undef type_vector0 74 #define type_vector0(t) \ 75 t * short_name(t,,vector0)(int32_t nl, int32_t nh) \ 76 { \ 77 t * v; \ 78 v = calloc((nh - nl + 1 + NR_END), sizeof(t)); \ 79 if (v == NULL) { \ 80 nrerror("*** Error: allocation failure in %s\n", __func__); \ 81 } \ 82 return v - nl + NR_END; \ 193 83 } 194 /*195 * ---------------196 * --- vector0 ---197 * ---------------198 */199 84 200 // do: allocate a vector and set it to 0 85 type_vector0(int8_t); 86 type_vector0(uint8_t); 87 type_vector0(int16_t); 88 type_vector0(uint16_t); 89 type_vector0(int32_t); 90 type_vector0(uint32_t); 91 type_vector0(int64_t); 92 type_vector0(uint64_t); 93 type_vector0(float); 94 type_vector0(double); 95 type_vector0(void_p); 96 type_vector0(rgb8); 97 type_vector0(rgbx8); 98 type_vector0(rgb32); 201 99 202 // ---------------------- 203 // --- not deprecated --- 204 // ---------------------- 205 /* ------------------------------------------- */ 206 IMAGE_EXPORT(sint8*) si8vector0(long nl, long nh) 207 /* ------------------------------------------- */ 208 { 209 sint8 *v;210 211 v=(sint8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(sint8));212 if (!v) nrerror("allocation failure in si8vector0()");213 return v -nl+NR_END;100 101 #undef realloc_type_vector 102 #define realloc_type_vector(t) \ 103 t * short_name(t,realloc_,vector)(t * v, int32_t nl, int32_t nh) \ 104 { \ 105 v += nl; \ 106 v -= NR_END; \ 107 v = realloc(v, (nh - nl + 1 + NR_END) * sizeof(t)); \ 108 if (v == NULL) { \ 109 nrerror("*** Error: allocation failure in %s\n", __func__); \ 110 } \ 111 return v - nl + NR_END; \ 214 112 } 215 /* ------------------------------------------- */ 216 IMAGE_EXPORT(uint8*) ui8vector0(long nl, long nh) 217 /* ------------------------------------------- */ 218 { 219 uint8 *v; 220 221 v=(uint8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(uint8)); 222 if (!v) nrerror("allocation failure in ui8vector0()"); 223 return v-nl+NR_END; 113 114 115 realloc_type_vector(int8_t); 116 realloc_type_vector(uint8_t); 117 realloc_type_vector(int16_t); 118 realloc_type_vector(uint16_t); 119 realloc_type_vector(int32_t); 120 realloc_type_vector(uint32_t); 121 realloc_type_vector(int64_t); 122 realloc_type_vector(uint64_t); 123 realloc_type_vector(float); 124 realloc_type_vector(double); 125 realloc_type_vector(void_p); 126 realloc_type_vector(rgb8); 127 realloc_type_vector(rgbx8); 128 realloc_type_vector(rgb32); 129 130 131 #undef free_type_vector 132 #define free_type_vector(t) \ 133 void short_name(t,free_,vector)(t * v, long nl, long nh) \ 134 { \ 135 free((FREE_ARG) (v + nl - NR_END)); \ 224 136 } 225 /* -------------------------------------------- */ 226 IMAGE_EXPORT(int16*) si16vector0(long nl, long nh) 227 /* -------------------------------------------- */ 228 { 229 sint16 *v; 230 231 v=(sint16 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(sint16)); 232 if (!v) nrerror("allocation failure in si16vector0()"); 233 return v-nl+NR_END; 137 138 free_type_vector(int8_t); 139 free_type_vector(uint8_t); 140 free_type_vector(int16_t); 141 free_type_vector(uint16_t); 142 free_type_vector(int32_t); 143 free_type_vector(uint32_t); 144 free_type_vector(int64_t); 145 free_type_vector(uint64_t); 146 free_type_vector(float); 147 free_type_vector(double); 148 free_type_vector(void_p); 149 free_type_vector(rgb8); 150 free_type_vector(rgbx8); 151 free_type_vector(rgb32); 152 153 154 155 156 #if TARGET_OS == GIETVM 157 #undef remote_type_vector 158 #define remote_type_vector(t) \ 159 t * short_name(t,remote_,vector)(int32_t nl, int32_t nh, int32_t x, int32_t y) \ 160 { \ 161 t * v; \ 162 v = remote_malloc((nh - nl + 1 + NR_END) * sizeof(t), x, y); \ 163 if (v == NULL) { \ 164 nrerror("*** Error: allocation failure in %s\n", __func__); \ 165 } \ 166 return v - nl + NR_END; \ 234 167 } 235 /* --------------------------------------------- */236 IMAGE_EXPORT(uint16*) ui16vector0(long nl, long nh)237 /* --------------------------------------------- */238 {239 uint16 *v;240 241 v=(uint16 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(uint16));242 if (!v) nrerror("allocation failure in ui16vector0()");243 return v-nl+NR_END;244 }245 /* --------------------------------------------- */246 IMAGE_EXPORT(sint32*) si32vector0(long nl, long nh)247 /* --------------------------------------------- */248 /* allocate a sint32 vector with subscript range v[nl..nh] */249 {250 sint32 *v;251 252 v=(sint32 *) calloc((size_t) (nh-nl+1+NR_END),sizeof(sint32));253 if (!v) nrerror("allocation failure in si32vector0()");254 return v-nl+NR_END;255 }256 /* --------------------------------------------- */257 IMAGE_EXPORT(uint32*) ui32vector0(long nl, long nh)258 /* --------------------------------------------- */259 /* allocate a uint32 vector with subscript range v[nl..nh] */260 {261 uint32 *v;262 263 v=(uint32 *) calloc((size_t) (nh-nl+1+NR_END),sizeof(uint32));264 if (!v) nrerror("allocation failure in ui32vector0()");265 return v-nl+NR_END;266 }267 /* --------------------------------------------- */268 IMAGE_EXPORT(float32*) f32vector0(long nl, long nh)269 /* --------------------------------------------- */270 /* allocate a float32 vector with subscript range v[nl..nh] */271 {272 float32 *v;273 274 v=(float32 *) calloc ( (size_t) (nh-nl+1+NR_END), sizeof(float32) );275 if (!v) nrerror("allocation failure in f32vector0()");276 if(!v) return NULL;277 return v-nl+NR_END;278 }279 /* --------------------------------------------- */280 IMAGE_EXPORT(float64*) f64vector0(long nl, long nh)281 /* --------------------------------------------- */282 /* allocate a float vector with subscript range v[nl..nh] */283 {284 float64 *v;285 286 v=(float64 *) calloc ( (size_t) (nh-nl+1+NR_END), sizeof(float64) );287 if (!v) nrerror("allocation failure in f64vector0()");288 if(!v) return NULL;289 return v-nl+NR_END;290 }291 /* ------------------------------------------- */292 IMAGE_EXPORT(rgb8*) rgb8vector0(long nl, long nh)293 /* ------------------------------------------- */294 {295 rgb8 *v;296 297 v=(rgb8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgb8));298 if (!v) nrerror("allocation failure in rgb8vector0()");299 return v-nl+NR_END;300 }301 /* --------------------------------------------- */302 IMAGE_EXPORT(rgbx8*) rgbx8vector0(long nl, long nh)303 /* --------------------------------------------- */304 {305 rgbx8 *v;306 307 v=(rgbx8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgbx8));308 if (!v) nrerror("allocation failure in rgbx8vector0()");309 return v-nl+NR_END;310 }311 /* --------------------------------------------- */312 IMAGE_EXPORT(rgb32*) rgb32vector0(long nl, long nh)313 /* --------------------------------------------- */314 {315 rgb32 *v;316 317 v=(rgb32 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgb32));318 if (!v) nrerror("allocation failure in rgb32vector0()");319 return v-nl+NR_END;320 }321 /*322 * ----------------------323 * --- realloc_vector ---324 * ----------------------325 */326 168 327 /* ------------------------------------------------------------ */ 328 IMAGE_EXPORT(sint8*) realloc_si8vector(sint8 *v, long nl, long nh) 329 /* ------------------------------------------------------------ */ 330 { 331 v += nl; 332 v -= NR_END; 333 v=(sint8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint8))); 334 if (!v) nrerror("allocation failure in realloc_si8vector()"); 335 336 return v-nl+NR_END; 337 } 338 /* ------------------------------------------------------------ */ 339 IMAGE_EXPORT(uint8*) realloc_ui8vector(uint8 *v, long nl, long nh) 340 /* ------------------------------------------------------------ */ 341 { 342 v += nl; 343 v -= NR_END; 344 v=(uint8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint8))); 345 if (!v) nrerror("allocation failure in realloc_ui8vector()"); 346 347 return v-nl+NR_END; 348 } 349 /* --------------------------------------------------------------- */ 350 IMAGE_EXPORT(sint16*) realloc_si16vector(sint16 *v, long nl, long nh) 351 /* --------------------------------------------------------------- */ 352 { 353 v += nl; 354 v -= NR_END; 355 v=(sint16 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint16))); 356 if (!v) nrerror("allocation failure in realloc_si16vector()"); 357 358 return v-nl+NR_END; 359 } 360 /* --------------------------------------------------------------- */ 361 IMAGE_EXPORT(uint16*) realloc_ui16vector(uint16 *v, long nl, long nh) 362 /* --------------------------------------------------------------- */ 363 { 364 v += nl; 365 v -= NR_END; 366 v=(uint16 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint16))); 367 if (!v) nrerror("allocation failure in realloc_ui16vector()"); 368 369 return v-nl+NR_END; 370 } 371 /* --------------------------------------------------------------- */ 372 IMAGE_EXPORT(sint32*) realloc_si32vector(sint32 *v, long nl, long nh) 373 /* --------------------------------------------------------------- */ 374 { 375 v += nl; 376 v -= NR_END; 377 v=(sint32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint32))); 378 if (!v) nrerror("allocation failure in realloc_si32vector()"); 379 380 return v-nl+NR_END; 381 } 382 /* --------------------------------------------------------------- */ 383 IMAGE_EXPORT(uint32*) realloc_ui32vector(uint32 *v, long nl, long nh) 384 /* --------------------------------------------------------------- */ 385 { 386 v += nl; 387 v -= NR_END; 388 v=(uint32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint32))); 389 if (!v) nrerror("allocation failure in realloc_ui32vector()"); 390 391 return v-nl+NR_END; 392 } 393 /* --------------------------------------------------------------- */ 394 IMAGE_EXPORT(sint64*) realloc_si64vector(sint64 *v, long nl, long nh) 395 /* --------------------------------------------------------------- */ 396 { 397 v += nl; 398 v -= NR_END; 399 v=(sint64 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint64))); 400 if (!v) nrerror("allocation failure in realloc_si64vector()"); 401 402 return v-nl+NR_END; 403 } 404 /* --------------------------------------------------------------- */ 405 IMAGE_EXPORT(uint64*) realloc_ui64vector(uint64 *v, long nl, long nh) 406 /* --------------------------------------------------------------- */ 407 { 408 v += nl; 409 v -= NR_END; 410 v=(uint64 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint64))); 411 if (!v) nrerror("allocation failure in realloc_ui64vector()"); 412 413 return v-nl+NR_END; 414 } 415 /* ---------------------------------------------------------- */ 416 IMAGE_EXPORT(rgb8*) realloc_rgb8vector(rgb8 *v, long nl, long nh) 417 /* ---------------------------------------------------------- */ 418 { 419 v += nl; 420 v -= NR_END; 421 v=(rgb8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgb8))); 422 if (!v) nrerror("allocation failure in realloc_rgb8vector()"); 423 424 return v-nl+NR_END; 425 } 426 /* -------------------------------------------------------------- */ 427 IMAGE_EXPORT(rgbx8*) realloc_rgbx8vector(rgbx8 *v, long nl, long nh) 428 /* -------------------------------------------------------------- */ 429 { 430 v += nl; 431 v -= NR_END; 432 v=(rgbx8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgbx8))); 433 if (!v) nrerror("allocation failure in realloc_rgbx8vector()"); 434 435 return v-nl+NR_END; 436 } 437 /* -------------------------------------------------------------- */ 438 IMAGE_EXPORT(rgb32*) realloc_rgb32vector(rgb32 *v, long nl, long nh) 439 /* -------------------------------------------------------------- */ 440 { 441 v += nl; 442 v -= NR_END; 443 v=(rgb32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgb32))); 444 if (!v) nrerror("allocation failure in realloc_rgb32vector()"); 445 446 return v-nl+NR_END; 447 } 448 /* ---------------------------------------------------------- */ 449 IMAGE_EXPORT(void**) realloc_vvector(void **v, long nl, long nh) 450 /* ---------------------------------------------------------- */ 451 /* 452 * add n item to an void* vector with subscript range 453 * fromv[nl..nh] to [nl..nh+n] */ 454 { 455 v += nl; 456 v -= NR_END; 457 v=(void**)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(void*))); 458 if (!v) nrerror("allocation failure in realloc vvector()"); 459 460 return v-nl+NR_END; 461 } 462 /* 463 * ------------------- 464 * --- free_vector --- 465 * ------------------- 466 */ 169 remote_type_vector(int8_t); 170 remote_type_vector(uint8_t); 171 remote_type_vector(int16_t); 172 remote_type_vector(uint16_t); 173 remote_type_vector(int32_t); 174 remote_type_vector(uint32_t); 175 remote_type_vector(int64_t); 176 remote_type_vector(uint64_t); 177 remote_type_vector(float); 178 remote_type_vector(double); 179 remote_type_vector(void_p); 180 remote_type_vector(rgb8); 181 remote_type_vector(rgbx8); 182 remote_type_vector(rgb32); 467 183 468 /* free a byte vector allocated with bvector() */ 184 #endif 469 185 470 /* ------------------------------------------------------- */ 471 IMAGE_EXPORT(void) free_si8vector(sint8 *v, long nl, long nh) 472 /* ------------------------------------------------------- */ 473 { 474 free((FREE_ARG) (v+nl-NR_END)); 475 } 476 /* ------------------------------------------------------- */ 477 IMAGE_EXPORT(void) free_ui8vector(uint8 *v, long nl, long nh) 478 /* ------------------------------------------------------- */ 479 { 480 free((FREE_ARG) (v+nl-NR_END)); 481 } 482 /* --------------------------------------------------------- */ 483 IMAGE_EXPORT(void) free_si16vector(sint16 *v, long nl, long nh) 484 /* --------------------------------------------------------- */ 485 { 486 free((FREE_ARG) (v+nl-NR_END)); 487 } 488 /* ------------------------------------------------------- */ 489 IMAGE_EXPORT(void) free_ui16vector(uint16 *v, long nl, long nh) 490 /* ------------------------------------------------------- */ 491 { 492 free((FREE_ARG) (v+nl-NR_END)); 493 } 494 /* --------------------------------------------------------- */ 495 IMAGE_EXPORT(void) free_si32vector(sint32 *v, long nl, long nh) 496 /* --------------------------------------------------------- */ 497 { 498 free((FREE_ARG) (v+nl-NR_END)); 499 } 500 /* --------------------------------------------------------- */ 501 IMAGE_EXPORT(void) free_ui32vector(uint32 *v, long nl, long nh) 502 /* --------------------------------------------------------- */ 503 { 504 free((FREE_ARG) (v+nl-NR_END)); 505 } 506 /* --------------------------------------------------------- */ 507 IMAGE_EXPORT(void) free_si64vector(sint64 *v, long nl, long nh) 508 /* --------------------------------------------------------- */ 509 { 510 free((FREE_ARG) (v+nl-NR_END)); 511 } 512 /* --------------------------------------------------------- */ 513 IMAGE_EXPORT(void) free_ui64vector(uint64 *v, long nl, long nh) 514 /* --------------------------------------------------------- */ 515 { 516 free((FREE_ARG) (v+nl-NR_END)); 517 } 518 /* ---------------------------------------------------- */ 519 IMAGE_EXPORT(void) free_f32vector(float32 *v, long nl, long nh) 520 /* ---------------------------------------------------- */ 521 { 522 free((FREE_ARG) (v+nl-NR_END)); 523 } 524 /* ---------------------------------------------------- */ 525 IMAGE_EXPORT(void) free_f64vector(float64 *v, long nl, long nh) 526 /* ---------------------------------------------------- */ 527 { 528 free((FREE_ARG) (v+nl-NR_END)); 529 } 530 /* -------------------------------------------------------- */ 531 IMAGE_EXPORT(void) free_rgb8vector(rgb8 *v, long nl, long nh) 532 /* -------------------------------------------------------- */ 533 { 534 free((FREE_ARG) (v+nl-NR_END)); 535 } 536 /* --------------------------------------------------------- */ 537 IMAGE_EXPORT(void) free_rgbx8vector(rgbx8 *v, long nl, long nh) 538 /* --------------------------------------------------------- */ 539 { 540 free((FREE_ARG) (v+nl-NR_END)); 541 } 542 /* ------------------------------------------------------- */ 543 IMAGE_EXPORT(void) free_rgb32vector(rgb32 *v, long nl, long nh) 544 /* ------------------------------------------------------- */ 545 { 546 free((FREE_ARG) (v+nl-NR_END)); 547 } 548 /* ----------------------------------------------------- */ 549 IMAGE_EXPORT(void) free_vvector(void **v, long nl, long nh) 550 /* ----------------------------------------------------- */ 551 { 552 free((FREE_ARG) (v+nl-NR_END)); 553 } 186 // Local Variables: 187 // tab-width: 4 188 // c-basic-offset: 4 189 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 190 // indent-tabs-mode: nil 191 // End: 192 193 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 194 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2.c
r772 r821 30 30 #include <malloc.h> 31 31 #include <math.h> // fabs 32 // #include <memory.h> // memcpy 33 32 33 #include "nrc_os_config.h" 34 34 #include "mypredef.h" 35 35 #include "nrtype.h" 36 #include "nrtypex.h" 36 37 #include "nrdef.h" 37 38 #include "nrmacro.h" 38 39 #include "nrkernel.h" 39 40 40 #include "nralloc1.h"41 41 #include "nralloc2.h" 42 //#include "nrarith.h"43 42 44 43 /* … … 47 46 * -------------- 48 47 */ 49 /* ------------------------------------------------ */ 50 float** matrix(long nrl, long nrh, long ncl, long nch) 51 /* ------------------------------------------------ */ 52 { 53 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 54 float **m; 55 56 /* allocate pointers to rows */ 57 m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*))); 58 if (!m) nrerror("allocation failure 1 in matrix()"); 59 m += NR_END; 60 m -= nrl; 61 62 63 /* allocate rows and set pointers to them */ 64 m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float))); 65 if (!m[nrl]) nrerror("allocation failure 2 in matrix()"); 66 m[nrl] += NR_END; 67 m[nrl] -= ncl; 68 69 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 70 71 /* return pointer to array of pointers to rows */ 72 return m; 73 } 74 /* -------------------------------------------------------------- */ 75 IMAGE_EXPORT(byte**) bmatrix(long nrl, long nrh, long ncl, long nch) 76 /* -------------------------------------------------------------- */ 77 { 78 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 79 byte **m; 80 81 /* allocate pointers to rows */ 82 m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*))); 83 if (!m) nrerror("allocation failure 1 in bmatrix()"); 84 m += NR_END; 85 m -= nrl; 86 87 88 /* allocate rows and set pointers to them */ 89 m[nrl]=(byte *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(byte))); 90 if (!m[nrl]) nrerror("allocation failure 2 in bmatrix()"); 91 m[nrl] += NR_END; 92 m[nrl] -= ncl; 93 94 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 95 96 /* return pointer to array of pointers to rows */ 97 return m; 98 }/* ---------------------------------------------------------------- */ 99 IMAGE_EXPORT(sint8**) si8matrix(long nrl, long nrh, long ncl, long nch) 100 /* ----------------------------------------------------------------- */ 101 { 102 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 103 sint8 **m; 104 105 /* allocate pointers to rows */ 106 m=(sint8 **) malloc((size_t)((nrow+NR_END)*sizeof(sint8*))); 107 if (!m) nrerror("allocation failure 1 in i8matrix()"); 108 m += NR_END; 109 m -= nrl; 110 111 /* allocate rows and set pointers to them */ 112 m[nrl]=(sint8 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint8))); 113 if (!m[nrl]) nrerror("allocation failure 2 in i8matrix()"); 114 m[nrl] += NR_END; 115 m[nrl] -= ncl; 116 117 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 118 119 /* return pointer to array of pointers to rows */ 120 return m; 121 } 122 /* ----------------------------------------------------------------- */ 123 IMAGE_EXPORT(uint8**) ui8matrix(long nrl, long nrh, long ncl, long nch) 124 /* ----------------------------------------------------------------- */ 125 { 126 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 127 uint8 **m; 128 129 /* allocate pointers to rows */ 130 m=(uint8 **) malloc((size_t)((nrow+NR_END)*sizeof(uint8*))); 131 if (!m) nrerror("allocation failure 1 in ui8matrix()"); 132 m += NR_END; 133 m -= nrl; 134 135 /* allocate rows and set pointers to them */ 136 m[nrl]=(uint8 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint8))); 137 if (!m[nrl]) nrerror("allocation failure 2 in ui8matrix()"); 138 m[nrl] += NR_END; 139 m[nrl] -= ncl; 140 141 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 142 143 /* return pointer to array of pointers to rows */ 144 return m; 145 } 146 /* ------------------------------------------------------------------- */ 147 IMAGE_EXPORT(sint16**) si16matrix(long nrl, long nrh, long ncl, long nch) 148 /* ------------------------------------------------------------------- */ 149 { 150 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 151 sint16 **m; 152 153 /* allocate pointers to rows */ 154 m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*))); 155 if (!m) nrerror("allocation failure 1 in si16matrix()"); 156 m += NR_END; 157 m -= nrl; 158 159 /* allocate rows and set pointers to them */ 160 m[nrl]=(sint16 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint16))); 161 if (!m[nrl]) nrerror("allocation failure 2 in si16matrix()"); 162 m[nrl] += NR_END; 163 m[nrl] -= ncl; 164 165 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 166 167 /* return pointer to array of pointers to rows */ 168 return m; 169 } 170 /* ------------------------------------------------------------------- */ 171 IMAGE_EXPORT(uint16**) ui16matrix(long nrl, long nrh, long ncl, long nch) 172 /* ------------------------------------------------------------------- */ 173 { 174 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 175 uint16 **m; 176 177 /* allocate pointers to rows */ 178 m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*))); 179 if (!m) nrerror("allocation failure 1 in ui16matrix()"); 180 m += NR_END; 181 m -= nrl; 182 183 /* allocate rows and set pointers to them */ 184 m[nrl]=(uint16 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint16))); 185 if (!m[nrl]) nrerror("allocation failure 2 in ui16matrix()"); 186 m[nrl] += NR_END; 187 m[nrl] -= ncl; 188 189 for(i=nrl+1;i<=nrh;i++) 190 m[i]=m[i-1]+ncol; 191 192 /* return pointer to array of pointers to rows */ 193 return m; 194 } 195 /* ------------------------------------------------------------------- */ 196 IMAGE_EXPORT(sint32**) si32matrix(long nrl, long nrh, long ncl, long nch) 197 /* ------------------------------------------------------------------- */ 198 /* allocate a int32 matrix with subscript range m[nrl..nrh][ncl..nch] */ 199 { 200 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 201 sint32 **m; 202 203 /* allocate pointers to rows */ 204 m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*))); 205 if (!m) nrerror("allocation failure 1 in si32matrix()"); 206 m += NR_END; 207 m -= nrl; 208 209 /* allocate rows and set pointers to them */ 210 m[nrl]=(sint32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint32))); 211 if (!m[nrl]) nrerror("allocation failure 2 in si32matrix()"); 212 m[nrl] += NR_END; 213 m[nrl] -= ncl; 214 215 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 216 217 /* return pointer to array of pointers to rows */ 218 return m; 219 } 220 /* ------------------------------------------------------------------- */ 221 IMAGE_EXPORT(uint32**) ui32matrix(long nrl, long nrh, long ncl, long nch) 222 /* ------------------------------------------------------------------- */ 223 /* allocate a uint32 matrix with subscript range m[nrl..nrh][ncl..nch] */ 224 { 225 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 226 uint32 **m; 227 228 /* allocate pointers to rows */ 229 m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*))); 230 if (!m) nrerror("allocation failure 1 in ui32matrix()"); 231 m += NR_END; 232 m -= nrl; 233 234 /* allocate rows and set pointers to them */ 235 m[nrl]=(uint32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint32))); 236 if (!m[nrl]) nrerror("allocation failure 2 in ui32matrix()"); 237 m[nrl] += NR_END; 238 m[nrl] -= ncl; 239 240 for(i=nrl+1;i<=nrh;i++) 241 m[i]=m[i-1]+ncol; 242 243 /* return pointer to array of pointers to rows */ 244 return m; 245 } 246 /* ------------------------------------------------------------------- */ 247 IMAGE_EXPORT(sint64**) si64matrix(long nrl, long nrh, long ncl, long nch) 248 /* ------------------------------------------------------------------- */ 249 /* allocate a int64 matrix with subscript range m[nrl..nrh][ncl..nch] */ 250 { 251 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 252 sint64 **m; 253 254 /* allocate pointers to rows */ 255 m=(sint64 **) malloc((size_t)((nrow+NR_END)*sizeof(sint64*))); 256 if (!m) nrerror("allocation failure 1 in si64matrix()"); 257 m += NR_END; 258 m -= nrl; 259 260 /* allocate rows and set pointers to them */ 261 m[nrl]=(sint64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint64))); 262 if (!m[nrl]) nrerror("allocation failure 2 in si64matrix()"); 263 m[nrl] += NR_END; 264 m[nrl] -= ncl; 265 266 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 267 268 /* return pointer to array of pointers to rows */ 269 return m; 270 } 271 /* ------------------------------------------------------------------- */ 272 IMAGE_EXPORT(uint64**) ui64matrix(long nrl, long nrh, long ncl, long nch) 273 /* ------------------------------------------------------------------- */ 274 /* allocate a int64 matrix with subscript range m[nrl..nrh][ncl..nch] */ 275 { 276 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 277 uint64 **m; 278 279 /* allocate pointers to rows */ 280 m=(uint64 **) malloc((size_t)((nrow+NR_END)*sizeof(uint64*))); 281 if (!m) nrerror("allocation failure 1 in ui64matrix()"); 282 m += NR_END; 283 m -= nrl; 284 285 /* allocate rows and set pointers to them */ 286 m[nrl]=(uint64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint64))); 287 if (!m[nrl]) nrerror("allocation failure 2 in ui64matrix()"); 288 m[nrl] += NR_END; 289 m[nrl] -= ncl; 290 291 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 292 293 /* return pointer to array of pointers to rows */ 294 return m; 295 } 296 /* ------------------------------------------------------------------- */ 297 IMAGE_EXPORT(float32**) f32matrix(long nrl, long nrh, long ncl, long nch) 298 /* ------------------------------------------------------------------- */ 299 /* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */ 300 { 301 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 302 float32 **m; 303 304 /* allocate pointers to rows */ 305 m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*))); 306 if (!m) nrerror("allocation failure 1 in f32matrix()"); 307 m += NR_END; 308 m -= nrl; 309 310 /* allocate rows and set pointers to them */ 311 m[nrl]=(float32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float32))); 312 if (!m[nrl]) nrerror("allocation failure 2 in f32matrix()"); 313 m[nrl] += NR_END; 314 m[nrl] -= ncl; 315 316 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 317 318 /* return pointer to array of pointers to rows */ 319 return m; 320 }/* ------------------------------------------------------------------- */ 321 IMAGE_EXPORT(float64**) f64matrix(long nrl, long nrh, long ncl, long nch) 322 /* ------------------------------------------------------------------- */ 323 324 /* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */ 325 { 326 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 327 float64 **m; 328 329 /* allocate pointers to rows */ 330 m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*))); 331 if (!m) nrerror("allocation failure 1 in f64matrix()"); 332 m += NR_END; 333 m -= nrl; 334 335 /* allocate rows and set pointers to them */ 336 m[nrl]=(float64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float64))); 337 if (!m[nrl]) nrerror("allocation failure 2 in f64matrix()"); 338 m[nrl] += NR_END; 339 m[nrl] -= ncl; 340 341 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 342 /* return pointer to array of pointers to rows */ 343 return m; 344 } 345 /* --------------------------------------------------------------------- */ 346 IMAGE_EXPORT(complex32**) c32matrix(long nrl, long nrh, long ncl, long nch) 347 /* --------------------------------------------------------------------- */ 348 /* allocate a complex32 matrix with subscript range m[nrl..nrh][ncl..nch] */ 349 { 350 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 351 complex32 **m; 352 353 /* allocate pointers to rows */ 354 m=(complex32 **) malloc((size_t)((nrow+NR_END)*sizeof(complex32*))); 355 if (!m) nrerror("allocation failure 1 in c32matrix()"); 356 m += NR_END; 357 m -= nrl; 358 359 /* allocate rows and set pointers to them */ 360 m[nrl]=(complex32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(complex32))); 361 if (!m[nrl]) nrerror("allocation failure 2 in c32matrix()"); 362 m[nrl] += NR_END; 363 m[nrl] -= ncl; 364 365 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 366 367 /* return pointer to array of pointers to rows */ 368 return m; 369 } 370 /* --------------------------------------------------------------------- */ 371 IMAGE_EXPORT(complex64**) c64matrix(long nrl, long nrh, long ncl, long nch) 372 /* --------------------------------------------------------------------- */ 373 /* allocate a complex32 matrix with subscript range m[nrl..nrh][ncl..nch] */ 374 { 375 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 376 complex64 **m; 377 378 /* allocate pointers to rows */ 379 m=(complex64 **) malloc((size_t)((nrow+NR_END)*sizeof(complex64*))); 380 if (!m) nrerror("allocation failure 1 in c64matrix()"); 381 m += NR_END; 382 m -= nrl; 383 384 /* allocate rows and set pointers to them */ 385 m[nrl]=(complex64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(complex64))); 386 if (!m[nrl]) nrerror("allocation failure 2 in c64matrix()"); 387 m[nrl] += NR_END; 388 m[nrl] -= ncl; 389 390 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 391 392 /* return pointer to array of pointers to rows */ 393 return m; 394 } 395 /* ----------------------------------------------------------------- */ 396 IMAGE_EXPORT(rgb8**) rgb8matrix(long nrl, long nrh, long ncl, long nch) 397 /* ----------------------------------------------------------------- */ 398 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 399 { 400 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 401 rgb8 **m; 402 403 /* allocate pointers to rows */ 404 m=(rgb8**) malloc((size_t)((nrow+NR_END)*sizeof(rgb8*))); 405 if (!m) nrerror("allocation failure 1 in rgb8matrix()"); 406 m += NR_END; 407 m -= nrl; 408 409 /* allocate rows and set pointers to them */ 410 m[nrl]=(rgb8*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgb8))); 411 if (!m[nrl]) nrerror("allocation failure 2 in rgb8matrix()"); 412 m[nrl] += NR_END; 413 m[nrl] -= ncl; 414 415 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 416 417 /* return pointer to array of pointers to rows */ 418 return m; 419 } 420 /* ------------------------------------------------------------------- */ 421 IMAGE_EXPORT(rgbx8**) rgbx8matrix(long nrl, long nrh, long ncl, long nch) 422 /* ------------------------------------------------------------------- */ 423 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 424 { 425 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 426 rgbx8 **m; 427 428 /* allocate pointers to rows */ 429 m=(rgbx8**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx8*))); 430 if (!m) nrerror("allocation failure 1 in rgbx8matrix()"); 431 m += NR_END; 432 m -= nrl; 433 434 /* allocate rows and set pointers to them */ 435 m[nrl]=(rgbx8*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgbx8))); 436 if (!m[nrl]) nrerror("allocation failure 2 in rgbx8matrix()"); 437 m[nrl] += NR_END; 438 m[nrl] -= ncl; 439 440 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 441 442 /* return pointer to array of pointers to rows */ 443 return m; 444 } 445 /* ------------------------------------------------------------------- */ 446 IMAGE_EXPORT(rgb32**) rgb32matrix(long nrl, long nrh, long ncl, long nch) 447 /* ------------------------------------------------------------------- */ 448 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 449 { 450 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 451 rgb32 **m; 452 453 /* allocate pointers to rows */ 454 m=(rgb32**) malloc((size_t)((nrow+NR_END)*sizeof(rgb32*))); 455 if (!m) nrerror("allocation failure 1 in rgb32matrix()"); 456 m += NR_END; 457 m -= nrl; 458 459 /* allocate rows and set pointers to them */ 460 m[nrl]=(rgb32*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgb32))); 461 if (!m[nrl]) nrerror("allocation failure 2 in rgb32matrix()"); 462 m[nrl] += NR_END; 463 m[nrl] -= ncl; 464 465 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 466 467 /* return pointer to array of pointers to rows */ 468 return m; 469 } 470 /* --------------------------------------------------------------------- */ 471 IMAGE_EXPORT(rgbx32**) rgbx32matrix(long nrl, long nrh, long ncl, long nch) 472 /* --------------------------------------------------------------------- */ 473 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 474 { 475 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 476 rgbx32 **m; 477 478 /* allocate pointers to rows */ 479 m=(rgbx32**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx32*))); 480 if (!m) nrerror("allocation failure 1 in rgbx32matrix()"); 481 m += NR_END; 482 m -= nrl; 483 484 /* allocate rows and set pointers to them */ 485 m[nrl]=(rgbx32*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgbx32))); 486 if (!m[nrl]) nrerror("allocation failure 2 in rgbx32matrix()"); 487 m[nrl] += NR_END; 488 m[nrl] -= ncl; 489 490 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 491 492 /* return pointer to array of pointers to rows */ 493 return m; 494 } 495 496 /* 497 * --------------- 498 * --- matrix0 --- 499 * --------------- 500 */ 501 502 /* --------------------------------------------------------------- */ 503 IMAGE_EXPORT(byte**) bmatrix0(long nrl, long nrh, long ncl, long nch) 504 /* --------------------------------------------------------------- */ 505 /* allocate a byte matrix with subscript range m[nrl..nrh][ncl..nch] */ 506 { 507 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 508 byte **m; 509 510 /* allocate pointers to rows */ 511 m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*))); 512 if (!m) nrerror("allocation failure 1 in bmatrix0()"); 513 m += NR_END; 514 m -= nrl; 515 516 /* allocate rows and set pointers to them */ 517 m[nrl]=(byte *) calloc((size_t)(nrow*ncol+NR_END),sizeof(byte)); 518 if (!m[nrl]) nrerror("allocation failure 2 in bmatrix0()"); 519 m[nrl] += NR_END; 520 m[nrl] -= ncl; 521 522 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 523 524 /* return pointer to array of pointers to rows */ 525 return m; 526 } 527 /* ------------------------------------------------------------------ */ 528 IMAGE_EXPORT(sint8**) si8matrix0(long nrl, long nrh, long ncl, long nch) 529 /* ------------------------------------------------------------------ */ 530 { 531 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 532 sint8 **m; 533 534 /* allocate pointers to rows */ 535 m=(sint8 **) malloc((size_t)((nrow+NR_END)*sizeof(sint8*))); 536 if (!m) nrerror("allocation failure 1 in i8matrix0()"); 537 m += NR_END; 538 m -= nrl; 539 540 /* allocate rows and set pointers to them */ 541 m[nrl]=(sint8 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint8)); 542 if (!m[nrl]) nrerror("allocation failure 2 in imatrix0()"); 543 m[nrl] += NR_END; 544 m[nrl] -= ncl; 545 546 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 547 548 /* return pointer to array of pointers to rows */ 549 return m; 550 } 551 /* ------------------------------------------------------------------ */ 552 IMAGE_EXPORT(uint8**) ui8matrix0(long nrl, long nrh, long ncl, long nch) 553 /* ------------------------------------------------------------------ */ 554 { 555 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 556 uint8 **m; 557 558 /* allocate pointers to rows */ 559 m=(uint8 **) malloc((size_t)((nrow+NR_END)*sizeof(uint8*))); 560 if (!m) nrerror("allocation failure 1 in ui8matrix0()"); 561 m += NR_END; 562 m -= nrl; 563 564 /* allocate rows and set pointers to them */ 565 m[nrl]=(uint8 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(uint8)); 566 if (!m[nrl]) nrerror("allocation failure 2 in ui8matrix0()"); 567 m[nrl] += NR_END; 568 m[nrl] -= ncl; 569 570 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 571 572 /* return pointer to array of pointers to rows */ 573 return m; 574 } 575 /* -------------------------------------------------------------------- */ 576 IMAGE_EXPORT(sint16**) si16matrix0(long nrl, long nrh, long ncl, long nch) 577 /* -------------------------------------------------------------------- */ 578 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 579 { 580 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 581 sint16 **m; 582 583 /* allocate pointers to rows */ 584 m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*))); 585 if (!m) nrerror("allocation failure 1 in si16matrix0()"); 586 m += NR_END; 587 m -= nrl; 588 589 /* allocate rows and set pointers to them */ 590 m[nrl]=(sint16 *) calloc(nrow*ncol, sizeof(int16)); 591 if (!m[nrl]) nrerror("allocation failure 2 in si16matrix0()"); 592 m[nrl] += NR_END; 593 m[nrl] -= ncl; 594 595 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 596 597 /* return pointer to array of pointers to rows */ 598 return m; 599 } 600 /* -------------------------------------------------------------------- */ 601 IMAGE_EXPORT(uint16**) ui16matrix0(long nrl, long nrh, long ncl, long nch) 602 /* -------------------------------------------------------------------- */ 603 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 604 { 605 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 606 uint16 **m; 607 608 /* allocate pointers to rows */ 609 m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*))); 610 if (!m) nrerror("allocation failure 1 in ui16matrix0()"); 611 m += NR_END; 612 m -= nrl; 613 614 /* allocate rows and set pointers to them */ 615 m[nrl]=(uint16 *) calloc(nrow*ncol, sizeof(uint16)); 616 if (!m[nrl]) nrerror("allocation failure 2 in ui16matrix0()"); 617 m[nrl] += NR_END; 618 m[nrl] -= ncl; 619 620 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 621 622 /* return pointer to array of pointers to rows */ 623 return m; 624 } 625 /* -------------------------------------------------------------------- */ 626 IMAGE_EXPORT(sint32**) si32matrix0(long nrl, long nrh, long ncl, long nch) 627 /* -------------------------------------------------------------------- */ 628 /* allocate a int32 matrix with subscript range m[nrl..nrh][ncl..nch] */ 629 { 630 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 631 sint32 **m; 632 633 /* allocate pointers to rows */ 634 m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*))); 635 if (!m) nrerror("allocation failure 1 in si32matrix0()"); 636 m += NR_END; 637 m -= nrl; 638 639 /* allocate rows and set pointers to them */ 640 m[nrl]=(sint32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint32)); 641 if (!m[nrl]) nrerror("allocation failure 2 in si32matrix0()"); 642 m[nrl] += NR_END; 643 m[nrl] -= ncl; 644 645 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 646 647 /* return pointer to array of pointers to rows */ 648 return m; 649 } 650 /* -------------------------------------------------------------------- */ 651 IMAGE_EXPORT(uint32**) ui32matrix0(long nrl, long nrh, long ncl, long nch) 652 /* -------------------------------------------------------------------- */ 653 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 654 { 655 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 656 uint32 **m; 657 /* allocate pointers to rows */ 658 m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*))); 659 if (!m) nrerror("allocation failure 1 in ui32matrix0()"); 660 m += NR_END; 661 m -= nrl; 662 663 /* allocate rows and set pointers to them */ 664 m[nrl]=(uint32 *) calloc((size_t)(nrow*ncol+NR_END), sizeof(uint32)); 665 if (!m[nrl]) nrerror("allocation failure 2 in ui32matrix0()"); 666 m[nrl] += NR_END; 667 m[nrl] -= ncl; 668 669 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 670 /* return pointer to array of pointers to rows */ 671 return m; 672 } 673 /* -------------------------------------------------------------------- */ 674 IMAGE_EXPORT(sint64**) si64matrix0(long nrl, long nrh, long ncl, long nch) 675 /* -------------------------------------------------------------------- */ 676 { 677 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 678 sint64 **m; 679 680 /* allocate pointers to rows */ 681 m=(sint64 **) malloc((size_t)((nrow+NR_END)*sizeof(sint64*))); 682 if (!m) nrerror("allocation failure 1 in si64matrix0()"); 683 m += NR_END; 684 m -= nrl; 685 686 /* allocate rows and set pointers to them */ 687 m[nrl]=(sint64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint64)); 688 if (!m[nrl]) nrerror("allocation failure 2 in si64matrix0()"); 689 m[nrl] += NR_END; 690 m[nrl] -= ncl; 691 692 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 693 694 /* return pointer to array of pointers to rows */ 695 return m; 696 } 697 /* -------------------------------------------------------------------- */ 698 IMAGE_EXPORT(uint64**) ui64matrix0(long nrl, long nrh, long ncl, long nch) 699 /* -------------------------------------------------------------------- */ 700 { 701 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 702 uint64 **m; 703 704 /* allocate pointers to rows */ 705 m=(uint64 **) malloc((size_t)((nrow+NR_END)*sizeof(uint64*))); 706 if (!m) nrerror("allocation failure 1 in i64matrix0()"); 707 m += NR_END; 708 m -= nrl; 709 710 /* allocate rows and set pointers to them */ 711 m[nrl]=(uint64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(uint64)); 712 if (!m[nrl]) nrerror("allocation failure 2 in i64matrix0()"); 713 m[nrl] += NR_END; 714 m[nrl] -= ncl; 715 716 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 717 718 /* return pointer to array of pointers to rows */ 719 return m; 720 } 721 /* -------------------------------------------------------------------- */ 722 IMAGE_EXPORT(float32**) f32matrix0(long nrl, long nrh, long ncl, long nch) 723 /* -------------------------------------------------------------------- */ 724 { 725 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 726 float32 **m; 727 728 /* allocate pointers to rows */ 729 m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*))); 730 if (!m) nrerror("allocation failure 1 in f32matrix0()"); 731 m += NR_END; 732 m -= nrl; 733 734 /* allocate rows and set pointers to them */ 735 m[nrl]=(float32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(float32)); 736 if (!m[nrl]) nrerror("allocation failure 2 in f32matrix0()"); 737 m[nrl] += NR_END; 738 m[nrl] -= ncl; 739 740 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 741 742 /* return pointer to array of pointers to rows */ 743 return m; 744 } 745 /* -------------------------------------------------------------------- */ 746 IMAGE_EXPORT(float64**) f64matrix0(long nrl, long nrh, long ncl, long nch) 747 /* -------------------------------------------------------------------- */ 748 { 749 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 750 float64 **m; 751 752 /* allocate pointers to rows */ 753 m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*))); 754 if (!m) nrerror("allocation failure 1 in f64matrix0()"); 755 m += NR_END; 756 m -= nrl; 757 758 /* allocate rows and set pointers to them */ 759 m[nrl]=(float64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(float64)); 760 if (!m[nrl]) nrerror("allocation failure 2 in f64matrix0()"); 761 m[nrl] += NR_END; 762 m[nrl] -= ncl; 763 764 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 765 /* return pointer to array of pointers to rows */ 766 return m; 767 } 768 /* ---------------------------------------------------------------------- */ 769 IMAGE_EXPORT(complex32**) c32matrix0(long nrl, long nrh, long ncl, long nch) 770 /* ---------------------------------------------------------------------- */ 771 { 772 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 773 complex32 **m; 774 775 /* allocate pointers to rows */ 776 m=(complex32 **) malloc((size_t)((nrow+NR_END)*sizeof(complex32*))); 777 if (!m) nrerror("allocation failure 1 in c32matrix0()"); 778 m += NR_END; 779 m -= nrl; 780 781 /* allocate rows and set pointers to them */ 782 m[nrl]=(complex32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(complex32)); 783 if (!m[nrl]) nrerror("allocation failure 2 in c32matrix0()"); 784 m[nrl] += NR_END; 785 m[nrl] -= ncl; 786 787 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 788 789 /* return pointer to array of pointers to rows */ 790 return m; 791 } 792 /* ---------------------------------------------------------------------- */ 793 IMAGE_EXPORT(complex64**) c64matrix0(long nrl, long nrh, long ncl, long nch) 794 /* ---------------------------------------------------------------------- */ 795 { 796 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 797 complex64 **m; 798 799 /* allocate pointers to rows */ 800 m=(complex64 **) malloc((size_t)((nrow+NR_END)*sizeof(complex64*))); 801 if (!m) nrerror("allocation failure 1 in c64matrix0()"); 802 m += NR_END; 803 m -= nrl; 804 805 /* allocate rows and set pointers to them */ 806 m[nrl]=(complex64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(complex64)); 807 if (!m[nrl]) nrerror("allocation failure 2 in c64matrix0()"); 808 m[nrl] += NR_END; 809 m[nrl] -= ncl; 810 811 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 812 813 /* return pointer to array of pointers to rows */ 814 return m; 815 } 816 /* ------------------------------------------------------------------ */ 817 IMAGE_EXPORT(rgb8**) rgb8matrix0(long nrl, long nrh, long ncl, long nch) 818 /* ------------------------------------------------------------------ */ 819 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 820 { 821 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 822 rgb8 **m; 823 824 /* allocate pointers to rows */ 825 m=(rgb8**) malloc((size_t)((nrow+NR_END)*sizeof(rgb8*))); 826 if (!m) nrerror("allocation failure 1 in rgb8matrix0()"); 827 m += NR_END; 828 m -= nrl; 829 830 /* allocate rows and set pointers to them */ 831 m[nrl]=(rgb8*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgb8)); 832 if (!m[nrl]) nrerror("allocation failure 2 in rgb8matrix0()"); 833 m[nrl] += NR_END; 834 m[nrl] -= ncl; 835 836 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 837 838 /* return pointer to array of pointers to rows */ 839 return m; 840 } 841 /* -------------------------------------------------------------------- */ 842 IMAGE_EXPORT(rgbx8**) rgbx8matrix0(long nrl, long nrh, long ncl, long nch) 843 /* -------------------------------------------------------------------- */ 844 /* allocate a sint16 matrix with subscript range m[nrl..nrh][ncl..nch] */ 845 { 846 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 847 rgbx8 **m; 848 849 /* allocate pointers to rows */ 850 m=(rgbx8**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx8*))); 851 if (!m) nrerror("allocation failure 1 in rgbx8matrix()"); 852 m += NR_END; 853 m -= nrl; 854 855 /* allocate rows and set pointers to them */ 856 m[nrl]=(rgbx8*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgbx8)); 857 if (!m[nrl]) nrerror("allocation failure 2 in rgbx8matrix()"); 858 m[nrl] += NR_END; 859 m[nrl] -= ncl; 860 861 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 862 863 /* return pointer to array of pointers to rows */ 864 return m; 865 } 866 /* -------------------------------------------------------------------- */ 867 IMAGE_EXPORT(rgb32**) rgb32matrix0(long nrl, long nrh, long ncl, long nch) 868 /* -------------------------------------------------------------------- */ 869 /* allocate a rgb32 matrix with subscript range m[nrl..nrh][ncl..nch] */ 870 { 871 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 872 rgb32 **m; 873 874 /* allocate pointers to rows */ 875 m=(rgb32**) malloc((size_t)((nrow+NR_END)*sizeof(rgb32*))); 876 if (!m) nrerror("allocation failure 1 in rgb32matrix0()"); 877 m += NR_END; 878 m -= nrl; 879 880 /* allocate rows and set pointers to them */ 881 m[nrl]=(rgb32*) calloc((nrow*ncol+NR_END), sizeof(rgb32)); 882 if (!m[nrl]) nrerror("allocation failure 2 in rgb32matrix0()"); 883 m[nrl] += NR_END; 884 m[nrl] -= ncl; 885 886 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 887 888 /* return pointer to array of pointers to rows */ 889 return m; 890 } 891 /* ---------------------------------------------------------------------- */ 892 IMAGE_EXPORT(rgbx32**) rgbx32matrix0(long nrl, long nrh, long ncl, long nch) 893 /* ---------------------------------------------------------------------- */ 894 /* allocate a rgb32 matrix with subscript range m[nrl..nrh][ncl..nch] */ 895 { 896 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1; 897 rgbx32 **m; 898 899 /* allocate pointers to rows */ 900 m=(rgbx32**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx32*))); 901 if (!m) nrerror("allocation failure 1 in rgbx32matrix()"); 902 m += NR_END; 903 m -= nrl; 904 905 /* allocate rows and set pointers to them */ 906 m[nrl]=(rgbx32*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgbx32)); 907 if (!m[nrl]) nrerror("allocation failure 2 in rgbx32matrix()"); 908 m[nrl] += NR_END; 909 m[nrl] -= ncl; 910 911 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol; 912 913 /* return pointer to array of pointers to rows */ 914 return m; 915 } 916 /* 917 * ------------------- 918 * --- free_matrix --- 919 * ------------------- 920 */ 921 922 /* ------------------------------------------------------------- */ 923 void free_matrix(float **m, long nrl, long nrh, long ncl, long nch) 924 /* ------------------------------------------------------------- */ 925 /* free a float matrix allocated by matrix() */ 926 { 927 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 928 free((FREE_ARG) (m+nrl-NR_END)); 929 } 930 /* --------------------------------------------------------------------------- */ 931 IMAGE_EXPORT(void) free_bmatrix(byte **m, long nrl, long nrh, long ncl, long nch) 932 /* --------------------------------------------------------------------------- */ 933 { 934 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 935 free((FREE_ARG) (m+nrl-NR_END)); 936 } 937 /* ------------------------------------------------------------------------------ */ 938 IMAGE_EXPORT(void) free_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch) 939 /* ------------------------------------------------------------------------------ */ 940 { 941 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 942 free((FREE_ARG) (m+nrl-NR_END)); 943 } 944 /* ------------------------------------------------------------------------------ */ 945 IMAGE_EXPORT(void) free_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch) 946 /* ------------------------------------------------------------------------------ */ 947 { 948 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 949 free((FREE_ARG) (m+nrl-NR_END)); 950 }/* -------------------------------------------------------------------------------- */ 951 IMAGE_EXPORT(void) free_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch) 952 /* -------------------------------------------------------------------------------- */ 953 { 954 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 955 free((FREE_ARG) (m+nrl-NR_END)); 956 } 957 /* -------------------------------------------------------------------------------- */ 958 IMAGE_EXPORT(void) free_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch) 959 /* -------------------------------------------------------------------------------- */ 960 { 961 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 962 free((FREE_ARG) (m+nrl-NR_END)); 963 } 964 /* -------------------------------------------------------------------------------- */ 965 IMAGE_EXPORT(void) free_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch) 966 /* -------------------------------------------------------------------------------- */ 967 { 968 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 969 free((FREE_ARG) (m+nrl-NR_END)); 970 } 971 /* -------------------------------------------------------------------------------- */ 972 IMAGE_EXPORT(void) free_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch) 973 /* -------------------------------------------------------------------------------- */ 974 { 975 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 976 free((FREE_ARG) (m+nrl-NR_END)); 977 } 978 /* -------------------------------------------------------------------------------- */ 979 IMAGE_EXPORT(void) free_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch) 980 /* -------------------------------------------------------------------------------- */ 981 { 982 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 983 free((FREE_ARG) (m+nrl-NR_END)); 984 } 985 /* -------------------------------------------------------------------------------- */ 986 IMAGE_EXPORT(void) free_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch) 987 /* -------------------------------------------------------------------------------- */ 988 { 989 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 990 free((FREE_ARG) (m+nrl-NR_END)); 991 } 992 /* -------------------------------------------------------------------------------- */ 993 IMAGE_EXPORT(void) free_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch) 994 /* -------------------------------------------------------------------------------- */ 995 { 996 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 997 free((FREE_ARG) (m+nrl-NR_END)); 998 } 999 /* -------------------------------------------------------------------------------- */ 1000 IMAGE_EXPORT(void) free_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch) 1001 /* -------------------------------------------------------------------------------- */ 1002 { 1003 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 1004 free((FREE_ARG) (m+nrl-NR_END)); 1005 } 1006 /* ---------------------------------------------------------------------------------- */ 1007 IMAGE_EXPORT(void) free_c32matrix(complex32 **m, long nrl, long nrh, long ncl, long nch) 1008 /* ---------------------------------------------------------------------------------- */ 1009 { 1010 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 1011 free((FREE_ARG) (m+nrl-NR_END)); 1012 } 1013 /* ---------------------------------------------------------------------------------- */ 1014 IMAGE_EXPORT(void) free_c64matrix(complex64 **m, long nrl, long nrh, long ncl, long nch) 1015 /* ---------------------------------------------------------------------------------- */ 1016 { 1017 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 1018 free((FREE_ARG) (m+nrl-NR_END)); 1019 } 1020 /* ------------------------------------------------------------------------------ */ 1021 IMAGE_EXPORT(void) free_rgb8matrix(rgb8 **m, long nrl, long nrh, long ncl, long nch) 1022 /* ------------------------------------------------------------------------------ */ 1023 { 1024 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 1025 free((FREE_ARG) (m+nrl-NR_END)); 1026 } 1027 /* -------------------------------------------------------------------------------- */ 1028 IMAGE_EXPORT(void) free_rgbx8matrix(rgbx8 **m, long nrl, long nrh, long ncl, long nch) 1029 /* -------------------------------------------------------------------------------- */ 1030 { 1031 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 1032 free((FREE_ARG) (m+nrl-NR_END)); 1033 } 1034 /* ------------------------------------------------------------------------------ */ 1035 IMAGE_EXPORT(void) free_rgb32matrix(rgb32 **m, long nrl, long nrh, long ncl, long nch) 1036 /* ------------------------------------------------------------------------------ */ 1037 { 1038 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 1039 free((FREE_ARG) (m+nrl-NR_END)); 1040 } 1041 /* ---------------------------------------------------------------------------------- */ 1042 IMAGE_EXPORT(void) free_rgbx32matrix(rgbx32 **m, long nrl, long nrh, long ncl, long nch) 1043 /* ---------------------------------------------------------------------------------- */ 1044 { 1045 free((FREE_ARG) (m[nrl]+ncl-NR_END)); 1046 free((FREE_ARG) (m+nrl-NR_END)); 1047 } 48 49 50 #undef type_matrix 51 #define type_matrix(t) \ 52 t ** short_name(t,,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ 53 { \ 54 int32_t nrow = nrh - nrl + 1; \ 55 int32_t ncol = nch - ncl + 1; \ 56 t ** m; \ 57 /* allocate pointers to row */ \ 58 m = malloc((nrow + NR_END) * sizeof(t *)); \ 59 if (m == NULL) { \ 60 nrerror("*** Error: allocation failure in %s\n", __func__); \ 61 } \ 62 m += NR_END; \ 63 m -= nrl; \ 64 /* allocate rows and set pointers to them */ \ 65 m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t)); \ 66 if (m[nrl] == NULL) { \ 67 nrerror("*** Error: allocation failure in %s\n", __func__); \ 68 } \ 69 m[nrl] += NR_END; \ 70 m[nrl] -= ncl; \ 71 for (int32_t i = nrl + 1; i <= nrh; i++) { \ 72 m[i] = m[i - 1] + ncol; \ 73 } \ 74 /* return pointer to array of pointers to rows */ \ 75 return m; \ 76 } 77 78 79 type_matrix(int8_t); 80 type_matrix(uint8_t); 81 type_matrix(int16_t); 82 type_matrix(uint16_t); 83 type_matrix(int32_t); 84 type_matrix(uint32_t); 85 type_matrix(int64_t); 86 type_matrix(uint64_t); 87 type_matrix(float); 88 type_matrix(double); 89 type_matrix(void_p); 90 type_matrix(rgb8); 91 type_matrix(rgbx8); 92 type_matrix(rgb32); 93 type_matrix(rgbx32); 94 type_matrix(complex32); 95 type_matrix(complex64); 96 type_matrix(si16Point); 97 type_matrix(ui16Point); 98 type_matrix(si32Point); 99 type_matrix(ui32Point); 100 type_matrix(f32Point); 101 type_matrix(si16Triplet); 102 type_matrix(ui16Triplet); 103 type_matrix(si32Triplet); 104 type_matrix(ui32Triplet); 105 type_matrix(f32Triplet); 106 107 108 109 110 #undef type_matrix0 111 #define type_matrix0(t) \ 112 t ** short_name(t,,matrix0)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ 113 { \ 114 int32_t nrow = nrh - nrl + 1; \ 115 int32_t ncol = nch - ncl + 1; \ 116 t ** m; \ 117 /* allocate pointers to row */ \ 118 m = malloc((nrow + NR_END) * sizeof(t *)); \ 119 if (m == NULL) { \ 120 nrerror("*** Error: allocation failure in %s\n", __func__); \ 121 } \ 122 m += NR_END; \ 123 m -= nrl; \ 124 /* allocate rows and set pointers to them */ \ 125 m[nrl] = calloc((nrow * ncol + NR_END), sizeof(t)); \ 126 if (m[nrl] == NULL) { \ 127 nrerror("*** Error: allocation failure in %s\n", __func__); \ 128 } \ 129 m[nrl] += NR_END; \ 130 m[nrl] -= ncl; \ 131 for (int32_t i = nrl + 1; i <= nrh; i++) { \ 132 m[i] = m[i - 1] + ncol; \ 133 } \ 134 /* return pointer to array of pointers to rows */ \ 135 return m; \ 136 } 137 138 139 type_matrix0(int8_t); 140 type_matrix0(uint8_t); 141 type_matrix0(int16_t); 142 type_matrix0(uint16_t); 143 type_matrix0(int32_t); 144 type_matrix0(uint32_t); 145 type_matrix0(int64_t); 146 type_matrix0(uint64_t); 147 type_matrix0(float); 148 type_matrix0(double); 149 type_matrix0(void_p); 150 type_matrix0(rgb8); 151 type_matrix0(rgbx8); 152 type_matrix0(rgb32); 153 type_matrix0(rgbx32); 154 type_matrix0(complex32); 155 type_matrix0(complex64); 156 157 158 #if TARGET_OS == GIETVM 159 160 #undef remote_type_matrix 161 #define remote_type_matrix(t) \ 162 t ** short_name(t,remote_,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ 163 { \ 164 int32_t nrow = nrh - nrl + 1; \ 165 int32_t ncol = nch - ncl + 1; \ 166 t ** m; \ 167 /* allocate pointers to row */ \ 168 m = malloc((nrow + NR_END) * sizeof(t *)); \ 169 if (m == NULL) { \ 170 nrerror("*** Error: allocation failure in %s\n", __func__); \ 171 } \ 172 m += NR_END; \ 173 m -= nrl; \ 174 /* allocate rows and set pointers to them */ \ 175 m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t)); \ 176 if (m[nrl] == NULL) { \ 177 nrerror("*** Error: allocation failure in %s\n", __func__); \ 178 } \ 179 m[nrl] += NR_END; \ 180 m[nrl] -= ncl; \ 181 for (int32_t i = nrl + 1; i <= nrh; i++) { \ 182 m[i] = m[i - 1] + ncol; \ 183 } \ 184 /* return pointer to array of pointers to rows */ \ 185 return m; \ 186 } 187 188 189 remote_type_matrix(int8_t); 190 remote_type_matrix(uint8_t); 191 remote_type_matrix(int16_t); 192 remote_type_matrix(uint16_t); 193 remote_type_matrix(int32_t); 194 remote_type_matrix(uint32_t); 195 remote_type_matrix(int64_t); 196 remote_type_matrix(uint64_t); 197 remote_type_matrix(float); 198 remote_type_matrix(double); 199 remote_type_matrix(void_p); 200 remote_type_matrix(rgb8); 201 remote_type_matrix(rgbx8); 202 remote_type_matrix(rgb32); 203 remote_type_matrix(rgbx32); 204 remote_type_matrix(complex32); 205 remote_type_matrix(complex64); 206 207 #endif 208 209 210 #undef free_type_matrix 211 #define free_type_matrix(t) \ 212 void short_name(t,free_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ 213 { \ 214 free((FREE_ARG) (m[nrl] + ncl - NR_END)); \ 215 free((FREE_ARG) (m + nrl - NR_END)); \ 216 } 217 218 free_type_matrix(int8_t); 219 free_type_matrix(uint8_t); 220 free_type_matrix(int16_t); 221 free_type_matrix(uint16_t); 222 free_type_matrix(int32_t); 223 free_type_matrix(uint32_t); 224 free_type_matrix(int64_t); 225 free_type_matrix(uint64_t); 226 free_type_matrix(float); 227 free_type_matrix(double); 228 free_type_matrix(void_p); 229 free_type_matrix(rgb8); 230 free_type_matrix(rgbx8); 231 free_type_matrix(rgb32); 232 free_type_matrix(rgbx32); 233 free_type_matrix(complex32); 234 free_type_matrix(complex64); 235 free_type_matrix(si16Point); 236 free_type_matrix(ui16Point); 237 free_type_matrix(si32Point); 238 free_type_matrix(ui32Point); 239 free_type_matrix(f32Point); 240 free_type_matrix(si16Triplet); 241 free_type_matrix(ui16Triplet); 242 free_type_matrix(si32Triplet); 243 free_type_matrix(ui32Triplet); 244 free_type_matrix(f32Triplet); 245 246 247 248 // Local Variables: 249 // tab-width: 4 250 // c-basic-offset: 4 251 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 252 // indent-tabs-mode: nil 253 // End: 254 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 255 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2x.c
r772 r821 17 17 #include <malloc.h> 18 18 #include <math.h> // fabs 19 // #include <memory.h> // memcpy20 19 20 #include "nrc_os_config.h" 21 21 #include "mypredef.h" 22 22 #include "nrtype.h" … … 25 25 #include "nrkernel.h" 26 26 27 #include "nralloc1.h"28 #include "nralloc2.h"29 27 #include "nralloc2x.h" 30 //#include "nrarith.h"31 28 32 /* ----------------------------------------------------------------------- */33 IMAGE_EXPORT(si16Point**) si16Pmatrix(long nrl, long nrh, long ncl, long nch)34 /* ----------------------------------------------------------------------- */35 {36 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;37 si16Point **m;38 39 /* allocate pointers to rows */40 m=(si16Point **) malloc((size_t)((nrow+NR_END)*sizeof(si16Point*)));41 if (!m) nrerror("allocation failure 1 in si16Pmatrix()");42 m += NR_END;43 m -= nrl;44 45 /* allocate rows and set pointers to them */46 m[nrl]=(si16Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si16Point)));47 if (!m[nrl]) nrerror("allocation failure 2 in si16Pmatrix()");48 m[nrl] += NR_END;49 m[nrl] -= ncl;50 51 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;52 53 /* return pointer to array of pointers to rows */54 return m;55 }56 /* ----------------------------------------------------------------------- */57 IMAGE_EXPORT(ui16Point**) ui16Pmatrix(long nrl, long nrh, long ncl, long nch)58 /* ----------------------------------------------------------------------- */59 {60 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;61 ui16Point **m;62 63 /* allocate pointers to rows */64 m=(ui16Point **) malloc((size_t)((nrow+NR_END)*sizeof(ui16Point*)));65 if (!m) nrerror("allocation failure 1 in ui16Pmatrix()");66 m += NR_END;67 m -= nrl;68 69 /* allocate rows and set pointers to them */70 m[nrl]=(ui16Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui16Point)));71 if (!m[nrl]) nrerror("allocation failure 2 in ui16Pmatrix()");72 m[nrl] += NR_END;73 m[nrl] -= ncl;74 75 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;76 77 /* return pointer to array of pointers to rows */78 return m;79 }80 /* ----------------------------------------------------------------------- */81 IMAGE_EXPORT(si32Point**) si32Pmatrix(long nrl, long nrh, long ncl, long nch)82 /* ----------------------------------------------------------------------- */83 {84 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;85 si32Point **m;86 87 /* allocate pointers to rows */88 m=(si32Point **) malloc((size_t)((nrow+NR_END)*sizeof(si32Point*)));89 if (!m) nrerror("allocation failure 1 in si32Pmatrix()");90 m += NR_END;91 m -= nrl;92 93 /* allocate rows and set pointers to them */94 m[nrl]=(si32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si32Point)));95 if (!m[nrl]) nrerror("allocation failure 2 in si32Pmatrix()");96 m[nrl] += NR_END;97 m[nrl] -= ncl;98 99 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;100 101 /* return pointer to array of pointers to rows */102 return m;103 }104 /* ----------------------------------------------------------------------- */105 IMAGE_EXPORT(ui32Point**) ui32Pmatrix(long nrl, long nrh, long ncl, long nch)106 /* ----------------------------------------------------------------------- */107 {108 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;109 ui32Point **m;110 111 /* allocate pointers to rows */112 m=(ui32Point **) malloc((size_t)((nrow+NR_END)*sizeof(ui32Point*)));113 if (!m) nrerror("allocation failure 1 in ui32Pmatrix()");114 m += NR_END;115 m -= nrl;116 117 /* allocate rows and set pointers to them */118 m[nrl]=(ui32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui32Point)));119 if (!m[nrl]) nrerror("allocation failure 2 in ui32Pmatrix()");120 m[nrl] += NR_END;121 m[nrl] -= ncl;122 123 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;124 125 /* return pointer to array of pointers to rows */126 return m;127 }128 /* ---------------------------------------------------------------------- */129 IMAGE_EXPORT(f32Point**) f32Pmatrix(long nrl, long nrh, long ncl, long nch)130 /* --------------------------------------------------------------------- */131 {132 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;133 f32Point **m;134 135 /* allocate pointers to rows */136 m=(f32Point **) malloc((size_t)((nrow+NR_END)*sizeof(f32Point*)));137 if (!m) nrerror("allocation failure 1 in f32Pmatrix()");138 m += NR_END;139 m -= nrl;140 141 /* allocate rows and set pointers to them */142 m[nrl]=(f32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(f32Point)));143 if (!m[nrl]) nrerror("allocation failure 2 in f32Pmatrix()");144 m[nrl] += NR_END;145 m[nrl] -= ncl;146 147 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;148 149 /* return pointer to array of pointers to rows */150 return m;151 }152 /* ------------------------------------------------------------------------- */153 IMAGE_EXPORT(si16Triplet**) si16Tmatrix(long nrl, long nrh, long ncl, long nch)154 /* ------------------------------------------------------------------------- */155 {156 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;157 si16Triplet **m;158 159 /* allocate pointers to rows */160 m=(si16Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(si16Triplet*)));161 if (!m) nrerror("allocation failure 1 in si16Tmatrix()");162 m += NR_END;163 m -= nrl;164 165 /* allocate rows and set pointers to them */166 m[nrl]=(si16Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si16Triplet)));167 if (!m[nrl]) nrerror("allocation failure 2 in si16Tmatrix()");168 m[nrl] += NR_END;169 m[nrl] -= ncl;170 171 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;172 173 /* return pointer to array of pointers to rows */174 return m;175 }176 /* ----------------------------------------------------------------------- */177 IMAGE_EXPORT(ui16Triplet**) ui16Tmatrix(long nrl, long nrh, long ncl, long nch)178 /* ----------------------------------------------------------------------- */179 {180 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;181 ui16Triplet **m;182 183 /* allocate pointers to rows */184 m=(ui16Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(ui16Triplet*)));185 if (!m) nrerror("allocation failure 1 in ui16Tmatrix()");186 m += NR_END;187 m -= nrl;188 189 /* allocate rows and set pointers to them */190 m[nrl]=(ui16Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui16Triplet)));191 if (!m[nrl]) nrerror("allocation failure 2 in ui16Tmatrix()");192 m[nrl] += NR_END;193 m[nrl] -= ncl;194 195 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;196 197 /* return pointer to array of pointers to rows */198 return m;199 }200 /* ----------------------------------------------------------------------- */201 IMAGE_EXPORT(si32Triplet**) si32Tmatrix(long nrl, long nrh, long ncl, long nch)202 /* ----------------------------------------------------------------------- */203 {204 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;205 si32Triplet **m;206 207 /* allocate pointers to rows */208 m=(si32Triplet**) malloc((size_t)((nrow+NR_END)*sizeof(si32Triplet*)));209 if (!m) nrerror("allocation failure 1 in si32Tmatrix()");210 m += NR_END;211 m -= nrl;212 213 /* allocate rows and set pointers to them */214 m[nrl]=(si32Triplet*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si32Triplet)));215 if (!m[nrl]) nrerror("allocation failure 2 in si32Tmatrix()");216 m[nrl] += NR_END;217 m[nrl] -= ncl;218 219 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;220 221 /* return pointer to array of pointers to rows */222 return m;223 }224 /* ----------------------------------------------------------------------- */225 IMAGE_EXPORT(ui32Triplet**) ui32Tmatrix(long nrl, long nrh, long ncl, long nch)226 /* ----------------------------------------------------------------------- */227 {228 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;229 ui32Triplet **m;230 231 /* allocate pointers to rows */232 m=(ui32Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(ui32Triplet*)));233 if (!m) nrerror("allocation failure 1 in ui32Tmatrix()");234 m += NR_END;235 m -= nrl;236 237 /* allocate rows and set pointers to them */238 m[nrl]=(ui32Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui32Triplet)));239 if (!m[nrl]) nrerror("allocation failure 2 in ui32Tmatrix()");240 m[nrl] += NR_END;241 m[nrl] -= ncl;242 243 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;244 245 /* return pointer to array of pointers to rows */246 return m;247 }248 /* ---------------------------------------------------------------------- */249 IMAGE_EXPORT(f32Triplet**) f32Tmatrix(long nrl, long nrh, long ncl, long nch)250 /* --------------------------------------------------------------------- */251 {252 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;253 f32Triplet **m;254 255 /* allocate pointers to rows */256 m=(f32Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(f32Triplet*)));257 if (!m) nrerror("allocation failure 1 in f32Tmatrix()");258 m += NR_END;259 m -= nrl;260 261 /* allocate rows and set pointers to them */262 m[nrl]=(f32Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(f32Triplet)));263 if (!m[nrl]) nrerror("allocation failure 2 in f32Tmatrix()");264 m[nrl] += NR_END;265 m[nrl] -= ncl;266 267 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;268 269 /* return pointer to array of pointers to rows */270 return m;271 }272 /* ---------------------------------------------------------------------------------- */273 IMAGE_EXPORT(void) free_si16Pmatrix(si16Point **m, long nrl, long nrh, long ncl, long nch)274 /* ---------------------------------------------------------------------------------- */275 /* free an si16Point matrix allocated by si16Pmatrix() */276 {277 free((FREE_ARG) (m[nrl]+ncl-NR_END));278 free((FREE_ARG) (m+nrl-NR_END));279 }280 /* ---------------------------------------------------------------------------------- */281 IMAGE_EXPORT(void) free_ui16Pmatrix(ui16Point **m, long nrl, long nrh, long ncl, long nch)282 /* ---------------------------------------------------------------------------------- */283 /* free an ui16Point matrix allocated by ui16Pmatrix() */284 {285 free((FREE_ARG) (m[nrl]+ncl-NR_END));286 free((FREE_ARG) (m+nrl-NR_END));287 }288 /* ------------------------------------------------------------------------------------ */289 IMAGE_EXPORT(void) free_si32Pmatrix(si32Point **m, long nrl, long nrh, long ncl, long nch)290 /* ------------------------------------------------------------------------------------ */291 {292 free((FREE_ARG) (m[nrl]+ncl-NR_END));293 free((FREE_ARG) (m+nrl-NR_END));294 }295 /* ------------------------------------------------------------------------------------ */296 IMAGE_EXPORT(void) free_ui32Pmatrix(ui32Point **m, long nrl, long nrh, long ncl, long nch)297 /* ------------------------------------------------------------------------------------ */298 {299 free((FREE_ARG) (m[nrl]+ncl-NR_END));300 free((FREE_ARG) (m+nrl-NR_END));301 }302 /* ---------------------------------------------------------------------------------- */303 IMAGE_EXPORT(void) free_f32Pmatrix(f32Point **m, long nrl, long nrh, long ncl, long nch)304 /* ---------------------------------------------------------------------------------- */305 /* free an f32Point matrix allocated by f32Pmatrix() */306 {307 free((FREE_ARG) (m[nrl]+ncl-NR_END));308 free((FREE_ARG) (m+nrl-NR_END));309 }310 /* -------------------------------------------------------------------------------------- */311 IMAGE_EXPORT(void) free_si16Tmatrix(si16Triplet **m, long nrl, long nrh, long ncl, long nch)312 /* -------------------------------------------------------------------------------------- */313 /* free an si16Point matrix allocated by si16Pmatrix() */314 {315 free((FREE_ARG) (m[nrl]+ncl-NR_END));316 free((FREE_ARG) (m+nrl-NR_END));317 }318 /* ---------------------------------------------------------------------------------- */319 IMAGE_EXPORT(void) free_ui16Tmatrix(ui16Triplet **m, long nrl, long nrh, long ncl, long nch)320 /* ---------------------------------------------------------------------------------- */321 /* free an ui16Point matrix allocated by ui16Pmatrix() */322 {323 free((FREE_ARG) (m[nrl]+ncl-NR_END));324 free((FREE_ARG) (m+nrl-NR_END));325 }326 /* ------------------------------------------------------------------------------------ */327 IMAGE_EXPORT(void) free_si32Tmatrix(si32Triplet **m, long nrl, long nrh, long ncl, long nch)328 /* ------------------------------------------------------------------------------------ */329 {330 free((FREE_ARG) (m[nrl]+ncl-NR_END));331 free((FREE_ARG) (m+nrl-NR_END));332 }333 /* -------------------------------------------------------------------------------------- */334 IMAGE_EXPORT(void) free_ui32Tmatrix(ui32Triplet **m, long nrl, long nrh, long ncl, long nch)335 /* -------------------------------------------------------------------------------------- */336 {337 free((FREE_ARG) (m[nrl]+ncl-NR_END));338 free((FREE_ARG) (m+nrl-NR_END));339 }340 /* ------------------------------------------------------------------------------------ */341 IMAGE_EXPORT(void) free_f32Tmatrix(f32Triplet **m, long nrl, long nrh, long ncl, long nch)342 /* ------------------------------------------------------------------------------------ */343 /* free an f32Point matrix allocated by f32Pmatrix() */344 {345 free((FREE_ARG) (m[nrl]+ncl-NR_END));346 free((FREE_ARG) (m+nrl-NR_END));347 }348 29 349 30 /* ----------------- */ 350 31 /* --- trimatrix --- */ 351 32 /* ----------------- */ 352 /* ---------------------------------------------------------------------------- */ 353 IMAGE_EXPORT(byte**) btrimatrix(long nrl, long nrh, long ncl, long nch, long step) 354 /* ---------------------------------------------------------------------------- */ 355 /* allocate an byte triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */ 356 { 357 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2; 358 // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!! 359 byte **m; 360 361 /* allocate pointers to rows */ 362 m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*))); 363 if (!m) nrerror("allocation failure 1 in btrimatrix()"); 364 m += NR_END; 365 m -= nrl; 366 367 368 /* allocate rows and set pointers to them */ 369 m[nrl]=(byte *) malloc((size_t)((n+NR_END)*sizeof(byte))); 370 if (!m[nrl]) nrerror("allocation failure 2 in btrimatrix()"); 371 m[nrl] += NR_END; 372 m[nrl] -= ncl; 373 374 for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; } 375 376 /* return pointer to array of pointers to rows */ 377 return m; 33 34 35 #undef type_trimatrix 36 #define type_trimatrix(t) \ 37 t ** short_name(t,,trimatrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t step) \ 38 /* allocate an byte triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */ \ 39 { \ 40 int32_t nrow = nrh - nrl + 1; \ 41 int32_t ncol = nch - ncl + 1; \ 42 int n = nrow * ncol + (nrow * (nrow - 1) * step) / 2; \ 43 /* Attention, factorisation of n IS NOT PERMITTED : (nrow - 1) step / 2 is not even!!! */ \ 44 t ** m; \ 45 /* allocate pointers to rows */ \ 46 m = malloc((nrow + NR_END) * sizeof(t *)); \ 47 if (m == NULL) { \ 48 nrerror("*** Error: allocation failure in %s\n", __func__); \ 49 } \ 50 m += NR_END; \ 51 m -= nrl; \ 52 /* allocate rows and set pointers to them */ \ 53 m[nrl] = malloc(((n + NR_END) * sizeof(t))); \ 54 if (m[nrl] == NULL) { \ 55 nrerror("*** Error: allocation failure in %s\n", __func__); \ 56 } \ 57 m[nrl] += NR_END; \ 58 m[nrl] -= ncl; \ 59 for (int32_t i = nrl + 1; i <= nrh;i++) { \ 60 m[i] = m[i - 1] + ncol; \ 61 ncol += step; \ 62 } \ 63 /* return pointer to array of pointers to rows */ \ 64 return m; \ 378 65 } 379 /* --------------------------------------------------------------------------------- */ 380 IMAGE_EXPORT(sint16**) si16trimatrix(long nrl, long nrh, long ncl, long nch, long step) 381 /* --------------------------------------------------------------------------------- */ 382 /* allocate an i16 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */ 383 { 384 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2; 385 // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!! 386 sint16 **m; 387 388 /* allocate pointers to rows */ 389 m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*))); 390 if (!m) nrerror("allocation failure 1 in i16trimatrix()"); 391 m += NR_END; 392 m -= nrl; 393 394 395 /* allocate rows and set pointers to them */ 396 m[nrl]=(int16*) malloc((size_t)((n+NR_END)*sizeof(int16))); 397 if (!m[nrl]) nrerror("allocation failure 2 in i16trimatrix()"); 398 m[nrl] += NR_END; 399 m[nrl] -= ncl; 400 401 for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; } 402 403 /* return pointer to array of pointers to rows */ 404 return m; 405 } 406 /* --------------------------------------------------------------------------------- */ 407 IMAGE_EXPORT(uint16**) ui16trimatrix(long nrl, long nrh, long ncl, long nch, long step) 408 /* --------------------------------------------------------------------------------- */ 409 /* allocate an i16 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */ 410 { 411 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2; 412 // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!! 413 uint16 **m; 414 415 /* allocate pointers to rows */ 416 m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*))); 417 if (!m) nrerror("allocation failure 1 in ui16trimatrix()"); 418 m += NR_END; 419 m -= nrl; 420 421 422 /* allocate rows and set pointers to them */ 423 m[nrl]=(uint16*) malloc((size_t)((n+NR_END)*sizeof(uint16))); 424 if (!m[nrl]) nrerror("allocation failure 2 in i16trimatrix()"); 425 m[nrl] += NR_END; 426 m[nrl] -= ncl; 427 428 for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; } 429 430 /* return pointer to array of pointers to rows */ 431 return m; 432 } 433 /* --------------------------------------------------------------------------------- */ 434 IMAGE_EXPORT(sint32**) si32trimatrix(long nrl, long nrh, long ncl, long nch, long step) 435 /* --------------------------------------------------------------------------------- */ 436 /* allocate an i32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */ 437 { 438 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2; 439 // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!! 440 sint32 **m; 441 442 /* allocate pointers to rows */ 443 m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*))); 444 if (!m) nrerror("allocation failure 1 in si32trimatrix()"); 445 m += NR_END; 446 m -= nrl; 447 448 449 /* allocate rows and set pointers to them */ 450 m[nrl]=(sint32*) malloc((size_t)((n+NR_END)*sizeof(sint32))); 451 if (!m[nrl]) nrerror("allocation failure 2 in si32trimatrix()"); 452 m[nrl] += NR_END; 453 m[nrl] -= ncl; 454 455 for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; } 456 457 /* return pointer to array of pointers to rows */ 458 return m; 459 } 460 /* -------------------------------------------------------------------------------- */ 461 IMAGE_EXPORT(uint32**) i32trimatrix(long nrl, long nrh, long ncl, long nch, long step) 462 /* -------------------------------------------------------------------------------- */ 463 /* allocate an i32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */ 464 { 465 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2; 466 // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!! 467 uint32 **m; 468 469 /* allocate pointers to rows */ 470 m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*))); 471 if (!m) nrerror("allocation failure 1 in ui32trimatrix()"); 472 m += NR_END; 473 m -= nrl; 474 475 476 /* allocate rows and set pointers to them */ 477 m[nrl]=(uint32*) malloc((size_t)((n+NR_END)*sizeof(uint32))); 478 if (!m[nrl]) nrerror("allocation failure 2 in i32trimatrix()"); 479 m[nrl] += NR_END; 480 m[nrl] -= ncl; 481 482 for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; } 483 484 /* return pointer to array of pointers to rows */ 485 return m; 486 } 487 /* --------------------------------------------------------------------------------- */ 488 IMAGE_EXPORT(float32**) f32trimatrix(long nrl, long nrh, long ncl, long nch, long step) 489 /* --------------------------------------------------------------------------------- */ 490 /* allocate an f32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */ 491 { 492 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2; 493 // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!! 494 float32 **m; 495 496 /* allocate pointers to rows */ 497 m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*))); 498 if (!m) nrerror("allocation failure 1 in f32trimatrix()"); 499 m += NR_END; 500 m -= nrl; 501 502 503 /* allocate rows and set pointers to them */ 504 m[nrl]=(float32*) malloc((size_t)((n+NR_END)*sizeof(float32))); 505 if (!m[nrl]) nrerror("allocation failure 2 in f32trimatrix()"); 506 m[nrl] += NR_END; 507 m[nrl] -= ncl; 508 509 for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; } 510 511 /* return pointer to array of pointers to rows */ 512 return m; 513 } 514 /* --------------------------------------------------------------------------------- */ 515 IMAGE_EXPORT(float64**) f64trimatrix(long nrl, long nrh, long ncl, long nch, long step) 516 /* --------------------------------------------------------------------------------- */ 517 /* allocate an f64 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */ 518 { 519 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2; 520 // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!! 521 float64 **m; 522 523 /* allocate pointers to rows */ 524 m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*))); 525 if (!m) nrerror("allocation failure 1 in f64trimatrix()"); 526 m += NR_END; 527 m -= nrl; 528 529 530 /* allocate rows and set pointers to them */ 531 m[nrl]=(float64*) malloc((size_t)((n+NR_END)*sizeof(float64))); 532 if (!m[nrl]) nrerror("allocation failure 2 in f64trimatrix()"); 533 m[nrl] += NR_END; 534 m[nrl] -= ncl; 535 536 for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; } 537 538 /* return pointer to array of pointers to rows */ 539 return m; 540 } 66 67 68 type_trimatrix(int8_t); 69 type_trimatrix(uint8_t); 70 type_trimatrix(int16_t); 71 type_trimatrix(uint16_t); 72 type_trimatrix(int32_t); 73 type_trimatrix(uint32_t); 74 type_trimatrix(float); 75 type_trimatrix(double); 76 77 // Local Variables: 78 // tab-width: 4 79 // c-basic-offset: 4 80 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 81 // indent-tabs-mode: nil 82 // End: 83 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 84 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc3.c
r772 r821 31 31 #include <string.h> // memcpy 32 32 #include <math.h> // fabs 33 // #include <memory.h> // memcpy34 33 34 35 #include "nrc_os_config.h" 35 36 #include "mypredef.h" 36 37 #include "nrtype.h" … … 39 40 #include "nrkernel.h" 40 41 41 #include "nralloc1.h"42 42 #include "nralloc3.h" 43 43 44 45 #undef type_cube 46 #define type_cube(t) \ 47 t *** short_name(t,,cube)(int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ 48 { \ 49 int32_t ndep = ndh - ndl + 1; \ 50 int32_t nrow = nrh - nrl + 1; \ 51 int32_t nrol = nch - ncl + 1; \ 52 t *** c; \ 53 /* allocate pointers to pointers to rows */ \ 54 c = malloc((ndep + NR_END) * sizeof(t **)); \ 55 if (c == NULL) { \ 56 nrerror("*** Error: allocation failure in %s\n", __func__); \ 57 } \ 58 c += NR_END; \ 59 c -= ndl; \ 60 /* allocate pointers to rows anc set pointers to them */ \ 61 c[ndl] = malloc((ndep * nrow + NR_END) * sizeof(t *)); \ 62 if (c[ndl] == NULL) { \ 63 nrerror("*** Error: allocation failure in %s\n", __func__); \ 64 } \ 65 c[ndl] += NR_END; \ 66 c[ndl] -= nrl; \ 67 /* allocate rows anc set pointers to them */ \ 68 c[ndl][nrl] = malloc((ndep * nrow * nrol + NR_END) * sizeof(t)); \ 69 if (c[ndl][nrl]) { \ 70 nrerror("*** Error: allocation failure in %s\n", __func__); \ 71 } \ 72 c[ndl][nrl] += NR_END; \ 73 c[ndl][nrl] -= ncl; \ 74 \ 75 for(int32_t j = nrl + 1; j <= nrh; j++) { \ 76 c[ndl][j] = c[ndl][j - 1] + nrol; \ 77 } \ 78 for(int32_t i = ndl + 1; i <= ndh; i++) { \ 79 c[i] = c[i - 1] + nrow; \ 80 c[i][nrl] = c[i - 1][nrl] + nrow * nrol; \ 81 for (int32_t j = nrl + 1; j <= nrh; j++) { \ 82 c[i][j] = c[i][j - 1] + nrol; \ 83 } \ 84 } \ 85 /* return pointer to array of pointers to rows */ \ 86 return t; \ 87 } 88 89 90 type_cube(int8_t); 91 type_cube(uint8_t); 92 type_cube(int16_t); 93 type_cube(uint16_t); 94 type_cube(int32_t); 95 type_cube(uint32_t); 96 type_cube(int64_t); 97 type_cube(uint64_t); 98 type_cube(float); 99 type_cube(double); 100 type_cube(rgb8); 101 type_cube(rgbx8); 102 103 #undef free_type_cube 104 #define free_type_cube(t) \ 105 void short_name(t,free_,cube)(t *** c, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh) \ 106 { \ 107 free((FREE_ARG) (c[nrl][ncl] + ndl - NR_END)); \ 108 free((FREE_ARG) (c[nrl] + ncl - NR_END)); \ 109 free((FREE_ARG) (c + nrl - NR_END)); \ 110 } 111 112 free_type_cube(int8_t); 113 free_type_cube(uint8_t); 114 free_type_cube(int16_t); 115 free_type_cube(uint16_t); 116 free_type_cube(int32_t); 117 free_type_cube(uint32_t); 118 free_type_cube(int64_t); 119 free_type_cube(uint64_t); 120 free_type_cube(float); 121 free_type_cube(double); 122 free_type_cube(rgb8); 123 free_type_cube(rgbx8); 124 125 126 #if 0 44 127 /* ----------------------------------------------------------------------- */ 45 128 double*** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh) … … 78 161 return t; 79 162 } 163 164 80 165 /* ------------------------------------------------------------------------------ */ 81 166 void free_d3tensor(double ***t,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) … … 87 172 free((FREE_ARG) (t+nrl-NR_END)); 88 173 } 174 #endif 89 175 90 /* ------------------------------------------------------------------------------------ */ 91 IMAGE_EXPORT(sint8***) si8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 92 /* ------------------------------------------------------------------------------------ */ 93 { 94 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 95 sint8 ***t; 96 97 /* allocate pointers to pointers to rows */ 98 t=(sint8***) malloc((size_t)((ndep+NR_END)*sizeof(sint8**))); 99 if (!t) nrerror("allocation failure 1 in si8cube()"); 100 t += NR_END; 101 t -= ndl; 102 103 /* allocate pointers to rows anc set pointers to them */ 104 t[ndl]=(sint8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint8*))); 105 if (!t[ndl]) nrerror("allocation failure 2 in si8cube()"); 106 t[ndl] += NR_END; 107 t[ndl] -= nrl; 108 109 /* allocate rows anc set pointers to them */ 110 t[ndl][nrl]=(sint8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint8))); 111 if (!t[ndl][nrl]) nrerror("allocation failure 3 in si8cube()"); 112 t[ndl][nrl] += NR_END; 113 t[ndl][nrl] -= ncl; 114 115 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 116 for(i=ndl+1;i<=ndh;i++) { 117 t[i]=t[i-1]+nrow; 118 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 119 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 120 } 121 /* return pointer to array of pointers to rows */ 122 return t; 123 } 124 /* ------------------------------------------------------------------------------------ */ 125 IMAGE_EXPORT(uint8***) ui8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 126 /* ------------------------------------------------------------------------------------ */ 127 { 128 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 129 uint8 ***t; 130 131 /* allocate pointers to pointers to rows */ 132 t=(uint8***) malloc((size_t)((ndep+NR_END)*sizeof(uint8**))); 133 if (!t) nrerror("allocation failure 1 in ui8cube()"); 134 t += NR_END; 135 t -= ndl; 136 137 /* allocate pointers to rows anc set pointers to them */ 138 t[ndl]=(uint8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint8*))); 139 if (!t[ndl]) nrerror("allocation failure 2 in ui8cube()"); 140 t[ndl] += NR_END; 141 t[ndl] -= nrl; 142 143 /* allocate rows anc set pointers to them */ 144 t[ndl][nrl]=(uint8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint8))); 145 if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui8cube()"); 146 t[ndl][nrl] += NR_END; 147 t[ndl][nrl] -= ncl; 148 149 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 150 for(i=ndl+1;i<=ndh;i++) { 151 t[i]=t[i-1]+nrow; 152 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 153 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 154 } 155 /* return pointer to array of pointers to rows */ 156 return t; 157 } 158 /* -------------------------------------------------------------------------------------- */ 159 IMAGE_EXPORT(sint16***) si16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 160 /* -------------------------------------------------------------------------------------- */ 161 { 162 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 163 sint16 ***t; 164 165 /* allocate pointers to pointers to rows */ 166 t=(sint16 ***) malloc((size_t)((ndep+NR_END)*sizeof(sint16**))); 167 if (!t) nrerror("allocation failure 1 in si16cube()"); 168 t += NR_END; 169 t -= ndl; 170 171 /* allocate pointers to rows anc set pointers to them */ 172 t[ndl]=(sint16 **) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint16*))); 173 if (!t[ndl]) nrerror("allocation failure 2 in si16cube()"); 174 t[ndl] += NR_END; 175 t[ndl] -= nrl; 176 177 /* allocate rows anc set pointers to them */ 178 t[ndl][nrl]=(sint16 *) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint16))); 179 if (!t[ndl][nrl]) nrerror("allocation failure 3 in si16cube()"); 180 t[ndl][nrl] += NR_END; 181 t[ndl][nrl] -= ncl; 182 183 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 184 for(i=ndl+1;i<=ndh;i++) { 185 t[i]=t[i-1]+nrow; 186 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 187 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 188 } 189 /* return pointer to array of pointers to rows */ 190 return t; 191 } 192 /* -------------------------------------------------------------------------------------- */ 193 IMAGE_EXPORT(uint16***) ui16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 194 /* -------------------------------------------------------------------------------------- */ 195 { 196 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 197 uint16 ***t; 198 199 /* allocate pointers to pointers to rows */ 200 t=(uint16***) malloc((size_t)((ndep+NR_END)*sizeof(uint16**))); 201 if (!t) nrerror("allocation failure 1 in ui16cube()"); 202 t += NR_END; 203 t -= ndl; 204 205 /* allocate pointers to rows anc set pointers to them */ 206 t[ndl]=(uint16**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint16*))); 207 if (!t[ndl]) nrerror("allocation failure 2 in ui16cube()"); 208 t[ndl] += NR_END; 209 t[ndl] -= nrl; 210 211 /* allocate rows anc set pointers to them */ 212 t[ndl][nrl]=(uint16*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint16))); 213 if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui16cube()"); 214 t[ndl][nrl] += NR_END; 215 t[ndl][nrl] -= ncl; 216 217 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 218 for(i=ndl+1;i<=ndh;i++) { 219 t[i]=t[i-1]+nrow; 220 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 221 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 222 } 223 /* return pointer to array of pointers to rows */ 224 return t; 225 } 226 /* ------------------------------------------------------------------------------------ */ 227 IMAGE_EXPORT(sint32***) si32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 228 /* ------------------------------------------------------------------------------------ */ 229 { 230 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 231 sint32 ***t; 232 233 /* allocate pointers to pointers to rows */ 234 t=(sint32***) malloc((size_t)((ndep+NR_END)*sizeof(sint32**))); 235 if (!t) nrerror("allocation failure 1 in si32cube()"); 236 t += NR_END; 237 t -= ndl; 238 239 /* allocate pointers to rows anc set pointers to them */ 240 t[ndl]=(sint32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint32*))); 241 if (!t[ndl]) nrerror("allocation failure 2 in si32cube()"); 242 t[ndl] += NR_END; 243 t[ndl] -= nrl; 244 245 /* allocate rows anc set pointers to them */ 246 t[ndl][nrl]=(sint32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint32))); 247 if (!t[ndl][nrl]) nrerror("allocation failure 3 in si32cube()"); 248 t[ndl][nrl] += NR_END; 249 t[ndl][nrl] -= ncl; 250 251 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 252 for(i=ndl+1;i<=ndh;i++) { 253 t[i]=t[i-1]+nrow; 254 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 255 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 256 } 257 /* return pointer to array of pointers to rows */ 258 return t; 259 } 260 /* -------------------------------------------------------------------------------------- */ 261 IMAGE_EXPORT(uint32***) ui32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 262 /* -------------------------------------------------------------------------------------- */ 263 { 264 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 265 uint32 ***t; 266 267 /* allocate pointers to pointers to rows */ 268 t=(uint32***) malloc((size_t)((ndep+NR_END)*sizeof(uint32**))); 269 if (!t) nrerror("allocation failure 1 in ui32cube()"); 270 t += NR_END; 271 t -= ndl; 272 273 /* allocate pointers to rows anc set pointers to them */ 274 t[ndl]=(uint32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint32*))); 275 if (!t[ndl]) nrerror("allocation failure 2 in ui32cube()"); 276 t[ndl] += NR_END; 277 t[ndl] -= nrl; 278 279 /* allocate rows anc set pointers to them */ 280 t[ndl][nrl]=(uint32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint32))); 281 if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui32cube()"); 282 t[ndl][nrl] += NR_END; 283 t[ndl][nrl] -= ncl; 284 285 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 286 for(i=ndl+1;i<=ndh;i++) { 287 t[i]=t[i-1]+nrow; 288 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 289 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 290 } 291 /* return pointer to array of pointers to rows */ 292 return t; 293 } 294 /* -------------------------------------------------------------------------------------- */ 295 IMAGE_EXPORT(float32***) f32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 296 /* -------------------------------------------------------------------------------------- */ 297 { 298 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 299 float32 ***t; 300 301 /* allocate pointers to pointers to rows */ 302 t=(float32***) malloc((size_t)((ndep+NR_END)*sizeof(float32**))); 303 if (!t) nrerror("allocation failure 1 in f32cube()"); 304 t += NR_END; 305 t -= ndl; 306 307 /* allocate pointers to rows anc set pointers to them */ 308 t[ndl]=(float32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(float32*))); 309 if (!t[ndl]) nrerror("allocation failure 2 in f32cube()"); 310 t[ndl] += NR_END; 311 t[ndl] -= nrl; 312 313 /* allocate rows anc set pointers to them */ 314 t[ndl][nrl]=(float32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(float32))); 315 if (!t[ndl][nrl]) nrerror("allocation failure 3 in f32cube()"); 316 t[ndl][nrl] += NR_END; 317 t[ndl][nrl] -= ncl; 318 319 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 320 for(i=ndl+1;i<=ndh;i++) { 321 t[i]=t[i-1]+nrow; 322 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 323 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 324 } 325 /* return pointer to array of pointers to rows */ 326 return t; 327 } 328 /* -------------------------------------------------------------------------------------- */ 329 IMAGE_EXPORT(float64***) f64cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 330 /* -------------------------------------------------------------------------------------- */ 331 { 332 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 333 float64 ***t; 334 335 /* allocate pointers to pointers to rows */ 336 t=(float64***) malloc((size_t)((ndep+NR_END)*sizeof(float64**))); 337 if (!t) nrerror("allocation failure 1 in f32cube()"); 338 t += NR_END; 339 t -= ndl; 340 341 /* allocate pointers to rows anc set pointers to them */ 342 t[ndl]=(float64**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(float64*))); 343 if (!t[ndl]) nrerror("allocation failure 2 in f64cube()"); 344 t[ndl] += NR_END; 345 t[ndl] -= nrl; 346 347 /* allocate rows anc set pointers to them */ 348 t[ndl][nrl]=(float64*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(float64))); 349 if (!t[ndl][nrl]) nrerror("allocation failure 3 in f64cube()"); 350 t[ndl][nrl] += NR_END; 351 t[ndl][nrl] -= ncl; 352 353 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 354 for(i=ndl+1;i<=ndh;i++) { 355 t[i]=t[i-1]+nrow; 356 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 357 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 358 } 359 /* return pointer to array of pointers to rows */ 360 return t; 361 } 362 /* ------------------------------------------------------------------------------------ */ 363 IMAGE_EXPORT(rgb8***) rgb8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 364 /* ------------------------------------------------------------------------------------ */ 365 /* allocate a rgb8 cube with range t[ndl..ndh][nrl..nrh][ncl..nch] */ 366 { 367 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 368 rgb8 ***t; 369 370 /* allocate pointers to pointers to rows */ 371 t=(rgb8***) malloc((size_t)((ndep+NR_END)*sizeof(rgb8**))); 372 if (!t) nrerror("allocation failure 1 in rgb8cube()"); 373 t += NR_END; 374 t -= ndl; 375 376 /* allocate pointers to rows anc set pointers to them */ 377 t[ndl]=(rgb8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(rgb8*))); 378 if (!t[ndl]) nrerror("allocation failure 2 in rgb8cube()"); 379 t[ndl] += NR_END; 380 t[ndl] -= nrl; 381 382 /* allocate rows anc set pointers to them */ 383 t[ndl][nrl]=(rgb8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(rgb8))); 384 if (!t[ndl][nrl]) nrerror("allocation failure 3 in rgb8cube()"); 385 t[ndl][nrl] += NR_END; 386 t[ndl][nrl] -= ncl; 387 388 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 389 for(i=ndl+1;i<=ndh;i++) { 390 t[i]=t[i-1]+nrow; 391 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 392 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 393 } 394 /* return pointer to array of pointers to rows */ 395 return t; 396 } 397 /* -------------------------------------------------------------------------------------- */ 398 IMAGE_EXPORT(rgbx8***) rgbx8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch) 399 /* -------------------------------------------------------------------------------------- */ 400 /* allocate a rgb8 cube with range t[ndl..ndh][nrl..nrh][ncl..nch] */ 401 { 402 long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1; 403 rgbx8 ***t; 404 405 /* allocate pointers to pointers to rows */ 406 t=(rgbx8***) malloc((size_t)((ndep+NR_END)*sizeof(rgbx8**))); 407 if (!t) nrerror("allocation failure 1 in rgbx8cube()"); 408 t += NR_END; 409 t -= ndl; 410 411 /* allocate pointers to rows anc set pointers to them */ 412 t[ndl]=(rgbx8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(rgbx8*))); 413 if (!t[ndl]) nrerror("allocation failure 2 in rgbx8cube()"); 414 t[ndl] += NR_END; 415 t[ndl] -= nrl; 416 417 /* allocate rows anc set pointers to them */ 418 t[ndl][nrl]=(rgbx8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(rgbx8))); 419 if (!t[ndl][nrl]) nrerror("allocation failure 3 in rgbx8cube()"); 420 t[ndl][nrl] += NR_END; 421 t[ndl][nrl] -= ncl; 422 423 for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol; 424 for(i=ndl+1;i<=ndh;i++) { 425 t[i]=t[i-1]+nrow; 426 t[i][nrl]=t[i-1][nrl]+nrow*nrol; 427 for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol; 428 } 429 /* return pointer to array of pointers to rows */ 430 return t; 431 } 432 /* ------------------------------------------------------------------------------------------- */ 433 IMAGE_EXPORT(void) free_si8cube(sint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 434 /* ------------------------------------------------------------------------------------------- */ 435 { 436 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 437 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 438 free((FREE_ARG) (c+nrl-NR_END)); 439 } 440 /* ------------------------------------------------------------------------------------------- */ 441 IMAGE_EXPORT(void) free_ui8cube(uint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 442 /* ------------------------------------------------------------------------------------------- */ 443 { 444 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 445 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 446 free((FREE_ARG) (c+nrl-NR_END)); 447 } 448 /* --------------------------------------------------------------------------------------------- */ 449 IMAGE_EXPORT(void) free_si16cube(sint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 450 /* --------------------------------------------------------------------------------------------- */ 451 { 452 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 453 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 454 free((FREE_ARG) (c+nrl-NR_END)); 455 } 456 /* --------------------------------------------------------------------------------------------- */ 457 IMAGE_EXPORT(void) free_ui16cube(uint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 458 /* --------------------------------------------------------------------------------------------- */ 459 { 460 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 461 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 462 free((FREE_ARG) (c+nrl-NR_END)); 463 } 464 /* --------------------------------------------------------------------------------------------- */ 465 IMAGE_EXPORT(void) free_si32cube(sint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 466 /* --------------------------------------------------------------------------------------------- */ 467 { 468 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 469 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 470 free((FREE_ARG) (c+nrl-NR_END)); 471 } 472 /* --------------------------------------------------------------------------------------------- */ 473 IMAGE_EXPORT(void) free_ui32cube(uint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 474 /* --------------------------------------------------------------------------------------------- */ 475 { 476 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 477 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 478 free((FREE_ARG) (c+nrl-NR_END)); 479 } 480 /* --------------------------------------------------------------------------------------------- */ 481 IMAGE_EXPORT(void) free_f32cube(float32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 482 /* --------------------------------------------------------------------------------------------- */ 483 { 484 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 485 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 486 free((FREE_ARG) (c+nrl-NR_END)); 487 } 488 /* --------------------------------------------------------------------------------------------- */ 489 IMAGE_EXPORT(void) free_f64cube(float64 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 490 /* --------------------------------------------------------------------------------------------- */ 491 { 492 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 493 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 494 free((FREE_ARG) (c+nrl-NR_END)); 495 } 496 /* ------------------------------------------------------------------------------------------- */ 497 IMAGE_EXPORT(void) free_rgb8cube(rgb8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 498 /* ------------------------------------------------------------------------------------------- */ 499 { 500 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 501 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 502 free((FREE_ARG) (c+nrl-NR_END)); 503 } 504 /* --------------------------------------------------------------------------------------------- */ 505 IMAGE_EXPORT(void) free_rgbx8cube(rgbx8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh) 506 /* --------------------------------------------------------------------------------------------- */ 507 { 508 free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END)); 509 free((FREE_ARG) (c[nrl]+ncl-NR_END)); 510 free((FREE_ARG) (c+nrl-NR_END)); 511 } 176 // Local Variables: 177 // tab-width: 4 178 // c-basic-offset: 4 179 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 180 // indent-tabs-mode: nil 181 // End: 182 183 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 184 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith0.c
r772 r821 22 22 #include <math.h> 23 23 24 #include "nrc_os_config.h" 24 25 #include "mypredef.h" 25 26 #include "nrtype.h" … … 30 31 #include "nrarith0.h" 31 32 32 ROUTINE(void) i8swap(int8 *a, int8 *b) { int8 *t; t=a; a=b; b=t;} 33 ROUTINE(void) i16swap(int16 *a, int16 *b) { int16 *t; t=a; a=b; b=t;} 34 ROUTINE(void) i32swap(int32 *a, int32 *b) { int32 *t; t=a; a=b; b=t;} 35 ROUTINE(void) i64swap(int64 *a, int64 *b) { int64 *t; t=a; a=b; b=t;} 36 ROUTINE(void) f32swap(float32 *a, float32 *b) { float32 *t; t=a; a=b; b=t;} 37 ROUTINE(void) f64swap(float64 *a, float64 *b) { float64 *t; t=a; a=b; b=t;} 38 ROUTINE(void) rgb8swap(rgb8 *a, rgb8 *b) { rgb8 *t; t=a; a=b; b=t;} 39 ROUTINE(void) rgbx8swap(rgbx8 *a, rgbx8 *b) { rgbx8 *t; t=a; a=b; b=t;} 33 #undef type_swap 34 #define type_swap(t) \ 35 void short_name(t,,swap)(t * a, t * b) \ 36 { \ 37 t c; \ 38 c = *a; \ 39 *a = *b; \ 40 *b = c; \ 41 } 42 43 type_swap(int8_t); 44 type_swap(int16_t); 45 type_swap(int32_t); 46 type_swap(int64_t); 47 type_swap(float); 48 type_swap(double); 49 type_swap(rgb8); 50 type_swap(rgbx8); 40 51 41 52 /* --------- */ … … 43 54 /* --------- */ 44 55 45 ROUTINE(float32) f32min (float32 x1, float32 x2) {if (x1<x2) return x1; else return x2;} 46 ROUTINE(float32) f32min2 (float32 x1, float32 x2) {if (x1<x2) return x1; else return x2;} 47 ROUTINE(float32) f32min3 (float32 x1, float32 x2, float32 x3) {return f32min2(f32min2(x1, x2), x3);} 48 ROUTINE(float32) f32min4 (float32 x1, float32 x2, float32 x3, float32 x4) {return f32min2(f32min2(x1, x2), f32min2(x3, x4));} 49 ROUTINE(float32) f32min5 (float32 x1, float32 x2, float32 x3, float32 x4, float32 x5) {return f32min3(f32min2(x1, x2), f32min2(x3, x4), x5);} 50 51 ROUTINE(float64) f64min (float64 x1, float64 x2) {if (x1<x2) return x1; else return x2;} 52 ROUTINE(float64) f64min2 (float64 x1, float64 x2) {if (x1<x2) return x1; else return x2;} 53 ROUTINE(float64) f64min3 (float64 x1, float64 x2, float64 x3) {return f64min2(f64min2(x1, x2), x3);} 54 ROUTINE(float64) f64min4 (float64 x1, float64 x2, float64 x3, float64 x4) {return f64min2(f64min2(x1, x2), f64min2(x3, x4));} 55 ROUTINE(float64) f64min5 (float64 x1, float64 x2, float64 x3, float64 x4, float64 x5) {return f64min3(f64min2(x1, x2), f64min2(x3, x4), x5);} 56 57 ROUTINE(uint8) ui8min (uint8 x1, uint8 x2) {if (x1<x2) return x1; else return x2;} 58 ROUTINE(uint8) ui8min2(uint8 x1, uint8 x2) {if (x1<x2) return x1; else return x2;} 59 ROUTINE(uint8) ui8min3(uint8 x1, uint8 x2, uint8 x3) {return ui8min2(ui8min2(x1, x2), x3);} 60 ROUTINE(uint8) ui8min4(uint8 x1, uint8 x2, uint8 x3, uint8 x4) {return ui8min2(ui8min2(x1, x2), ui8min2(x3, x4));} 61 ROUTINE(uint8) ui8min5(uint8 x1, uint8 x2, uint8 x3, uint8 x4, uint8 x5) {return ui8min3(ui8min2(x1, x2), ui8min2(x3, x4), x5);} 62 63 ROUTINE(uint16) ui16min (uint16 x1, uint16 x2) {if (x1<x2) return x1; else return x2;} 64 ROUTINE(uint16) ui16min2(uint16 x1, uint16 x2) {if (x1<x2) return x1; else return x2;} 65 ROUTINE(uint16) ui16min3(uint16 x1, uint16 x2, uint16 x3) {return ui16min2(ui16min2(x1, x2), x3);} 66 ROUTINE(uint16) ui16min4(uint16 x1, uint16 x2, uint16 x3, uint16 x4) {return ui16min2(ui16min2(x1, x2), ui16min2(x3, x4));} 67 ROUTINE(uint16) ui16min5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5) {return ui16min3(ui16min2(x1, x2), ui16min2(x3, x4), x5);} 68 69 ROUTINE(int32) ui32min (uint32 x1, uint32 x2) {if (x1<x2) return x1; else return x2;} 70 ROUTINE(int32) ui32min2(uint32 x1, uint32 x2) {if (x1<x2) return x1; else return x2;} 71 ROUTINE(int32) ui32min3(uint32 x1, uint32 x2, uint32 x3) {return ui32min2(ui32min2(x1, x2), x3);} 72 ROUTINE(int32) ui32min4(uint32 x1, uint32 x2, uint32 x3, uint32 x4) {return ui32min2(ui32min2(x1, x2), ui32min2(x3, x4));} 73 ROUTINE(int32) ui32min5(uint32 x1, uint32 x2, uint32 x3, uint32 x4, uint32 x5) {return ui32min3(ui32min2(x1, x2), ui32min2(x3, x4), x5);} 74 75 ROUTINE(rgb8) rgb8min (rgb8 x1, rgb8 x2) {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;} 76 ROUTINE(rgb8) rgb8min2(rgb8 x1, rgb8 x2) {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;} 77 ROUTINE(rgb8) rgb8min3(rgb8 x1, rgb8 x2, rgb8 x3) {return rgb8min2(rgb8min2(x1, x2), x3);} 78 ROUTINE(rgb8) rgb8min4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4) {return rgb8min2(rgb8min2(x1, x2), rgb8min2(x3,x4));} 79 ROUTINE(rgb8) rgb8min5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5) {return rgb8min3(rgb8min2(x1, x2), rgb8min2(x3,x4), x5);} 56 #undef type_min 57 #define type_min(t) \ 58 t short_name(t,,min)(t x1, t x2) \ 59 { \ 60 return (x1 < x2) ? x1 : x2; \ 61 } \ 62 t short_name(t,,min2)(t x1, t x2) \ 63 { \ 64 return (x1 < x2) ? x1 : x2; \ 65 } \ 66 t short_name(t,,min3)(t x1, t x2, t x3) \ 67 { \ 68 return short_name(t,,min2)(short_name(t,,min2)(x1, x2), x3); \ 69 } \ 70 t short_name(t,,min4)(t x1, t x2, t x3, t x4) \ 71 { \ 72 return short_name(t,,min2)(short_name(t,,min2)(x1, x2), short_name(t,,min2)(x3, x4)); \ 73 } \ 74 t short_name(t,,min5)(t x1, t x2, t x3, t x4, t x5) \ 75 { \ 76 return short_name(t,,min3)(short_name(t,,min2)(x1, x2), short_name(t,,min2)(x3, x4), x5); \ 77 } 78 79 type_min(float); 80 type_min(double); 81 type_min(int8_t); 82 type_min(uint8_t); 83 type_min(int16_t); 84 type_min(uint16_t); 85 type_min(int32_t); 86 type_min(uint32_t); 87 88 rgb8 rgb8min (rgb8 x1, rgb8 x2) {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;} 89 rgb8 rgb8min2(rgb8 x1, rgb8 x2) {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;} 90 rgb8 rgb8min3(rgb8 x1, rgb8 x2, rgb8 x3) {return rgb8min2(rgb8min2(x1, x2), x3);} 91 rgb8 rgb8min4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4) {return rgb8min2(rgb8min2(x1, x2), rgb8min2(x3,x4));} 92 rgb8 rgb8min5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5) {return rgb8min3(rgb8min2(x1, x2), rgb8min2(x3,x4), x5);} 80 93 81 94 /* --------- */ … … 83 96 /* --------- */ 84 97 85 ROUTINE(float32) f32max (float32 x1, float32 x2) {if (x1>x2) return x1; else return x2;} 86 ROUTINE(float32) f32max2(float32 x1, float32 x2) {if (x1>x2) return x1; else return x2;} 87 ROUTINE(float32) f32max3(float32 x1, float32 x2, float32 x3) {return f32max2(f32max2(x1, x2), x3);} 88 ROUTINE(float32) f32max4(float32 x1, float32 x2, float32 x3, float32 x4) {return f32max2(f32max2(x1, x2), f32max2(x3, x4));} 89 ROUTINE(float32) f32max5(float32 x1, float32 x2, float32 x3, float32 x4, float32 x5) {return f32max3(f32max2(x1, x2), f32max2(x3, x4), x5);} 90 91 ROUTINE(float64) f64max (float64 x1, float64 x2) {if (x1>x2) return x1; else return x2;} 92 ROUTINE(float64) f64max2 (float64 x1, float64 x2) {if (x1>x2) return x1; else return x2;} 93 ROUTINE(float64) f64max3 (float64 x1, float64 x2, float64 x3) {return f64max2(f64max2(x1, x2), x3);} 94 ROUTINE(float64) f64max4 (float64 x1, float64 x2, float64 x3, float64 x4) {return f64max2(f64max2(x1, x2), f64max2(x3, x4));} 95 ROUTINE(float64) f64max5 (float64 x1, float64 x2, float64 x3, float64 x4, float64 x5) {return f64max3(f64max2(x1, x2), f64max2(x3, x4), x5);} 96 97 ROUTINE(uint8) ui8max (uint8 x1, uint8 x2) {if (x1>x2) return x1; else return x2;} 98 ROUTINE(uint8) ui8max2(uint8 x1, uint8 x2) {if (x1>x2) return x1; else return x2;} 99 ROUTINE(uint8) ui8max3(uint8 x1, uint8 x2, uint8 x3) {return ui8max2(ui8max2(x1, x2), x3);} 100 ROUTINE(uint8) ui8max4(uint8 x1, uint8 x2, uint8 x3, uint8 x4) {return ui8max2(ui8max2(x1, x2), ui8max2(x3, x4));} 101 ROUTINE(uint8) ui8max5(uint8 x1, uint8 x2, uint8 x3, uint8 x4, uint8 x5) {return ui8max3(ui8max2(x1, x2), ui8max2(x3, x4), x5);} 102 103 ROUTINE(uint16) ui16max (uint16 x1, uint16 x2) {if (x1>x2) return x1; else return x2;} 104 ROUTINE(uint16) ui16max2(uint16 x1, uint16 x2) {if (x1>x2) return x1; else return x2;} 105 ROUTINE(uint16) ui16max3(uint16 x1, uint16 x2, uint16 x3) {return ui16max2(ui16max2(x1, x2), x3);} 106 ROUTINE(uint16) ui16max4(uint16 x1, uint16 x2, uint16 x3, uint16 x4) {return ui16max2(ui16max2(x1, x2), ui16max2(x3, x4));} 107 ROUTINE(uint16) ui16max5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5) {return ui16max3(ui16max2(x1, x2), ui16max2(x3, x4), x5);} 108 109 ROUTINE(int32) ui32max (uint32 x1, uint32 x2) {if (x1>x2) return x1; else return x2;} 110 ROUTINE(int32) ui32max2(uint32 x1, uint32 x2) {if (x1>x2) return x1; else return x2;} 111 ROUTINE(int32) ui32max3(uint32 x1, uint32 x2, uint32 x3) {return ui32max2(ui32max2(x1, x2), x3);} 112 ROUTINE(int32) ui32max4(uint32 x1, uint32 x2, uint32 x3, uint32 x4) {return ui32max2(ui32max2(x1, x2), ui32max2(x3, x4));} 113 ROUTINE(int32) ui32max5(uint32 x1, uint32 x2, uint32 x3, uint32 x4, int32 x5) {return ui32max3(ui32max2(x1, x2), ui32max2(x3, x4), x5);} 98 #undef type_max 99 #define type_max(t) \ 100 t short_name(t,,max)(t x1, t x2) \ 101 { \ 102 return (x1 > x2) ? x1 : x2; \ 103 } \ 104 t short_name(t,,max2)(t x1, t x2) \ 105 { \ 106 return (x1 > x2) ? x1 : x2; \ 107 } \ 108 t short_name(t,,max3)(t x1, t x2, t x3) \ 109 { \ 110 return short_name(t,,max2)(short_name(t,,max2)(x1, x2), x3); \ 111 } \ 112 t short_name(t,,max4)(t x1, t x2, t x3, t x4) \ 113 { \ 114 return short_name(t,,max2)(short_name(t,,max2)(x1, x2), short_name(t,,max2)(x3, x4)); \ 115 } \ 116 t short_name(t,,max5)(t x1, t x2, t x3, t x4, t x5) \ 117 { \ 118 return short_name(t,,max3)(short_name(t,,max2)(x1, x2), short_name(t,,max2)(x3, x4), x5); \ 119 } 120 121 type_max(float); 122 type_max(double); 123 type_max(int8_t); 124 type_max(uint8_t); 125 type_max(int16_t); 126 type_max(uint16_t); 127 type_max(int32_t); 128 type_max(uint32_t); 114 129 115 130 ROUTINE(rgb8) rgb8max (rgb8 x1, rgb8 x2) {rgb8 y; y.r = ui8max2(x1.r,x2.r);y.g=ui8max2(x1.g,x2.g);y.b=ui8max2(x1.b,x2.b);return y;} … … 124 139 125 140 /* ------------------------------- */ 126 ROUTINE(int32) i32bit(int32 x, int n)141 int32_t i32bit(int32_t x, int32_t n) 127 142 /* ------------------------------- */ 128 143 { 129 return ((x>>n)&1); 130 } 144 return ((x >> n) & 1); 145 } 146 131 147 /* --------------------------- */ 132 ROUTINE(int32) sym_int32(int32x)148 int32_t sym_int32(int32_t x) 133 149 /* --------------------------- */ 134 150 { 135 int i; 136 int32 y = 0; 137 for(i=0; i<31; i++) { 138 y = y | (x & 1); 139 x = x >> 1; 140 } 141 y = y | x; 142 return y; 151 int32_t y = 0; 152 for (int32_t i = 0; i < 31; i++) { 153 y = y | (x & 1); 154 x = x >> 1; 155 } 156 y = y | x; 157 return y; 143 158 } 144 159 145 160 146 161 /* ----------------------- */ 147 ROUTINE(int) ilog2(int x)162 int32_t ilog2(int32_t x) 148 163 /* ----------------------- */ 149 164 { 150 int s = 0; 151 while(x) { 152 x >>= 1; 153 s++; 154 } 155 return s - 1; 156 } 165 int32_t s = 0; 166 while (x) { 167 x >>= 1; 168 s++; 169 } 170 return s - 1; 171 } 172 157 173 /* ----------------------------- */ 158 ROUTINE(int) next_power2(int x)174 int32_t next_power2(int32_t x) 159 175 /* ----------------------------- */ 160 176 { 161 int s = ilog2(x); 162 int n = 1 << s; 163 164 if(x != n) 165 return n << 1; 166 else 167 return n; 168 } 169 /* ---------------------------- */ 170 ROUTINE(int) gcd(int u, int v) 171 /* ---------------------------- */ 172 { 173 int r; 174 while(v) { 175 r = u % v; 176 u = v; 177 v = r; 178 } 179 return u; 180 } 181 /* ---------------------------- */ 182 ROUTINE(int) lcm(int u, int v) 183 /* ---------------------------- */ 184 { 185 return (u*v)/gcd(u,v); 186 } 177 int32_t s = ilog2(x); 178 int32_t n = 1 << s; 179 180 if (x != n) { 181 return n << 1; 182 } 183 else { 184 return n; 185 } 186 } 187 188 /* ---------------------------- */ 189 int32_t myGCD(int32_t u, int32_t v) 190 /* ---------------------------- */ 191 { 192 int32_t r; 193 while (v != 0) { 194 r = u % v; 195 u = v; 196 v = r; 197 } 198 return u; 199 } 200 201 /* ---------------------------- */ 202 int32_t myLCM(int32_t u, int32_t v) 203 /* ---------------------------- */ 204 { 205 return (u * v) / myGCD(u, v); 206 } 207 208 209 // Local Variables: 210 // tab-width: 4 211 // c-basic-offset: 4 212 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 213 // indent-tabs-mode: nil 214 // End: 215 216 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 217 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith1.c
r772 r821 20 20 #include <malloc.h> 21 21 #include <math.h> // fabs 22 // #include <memory.h> // memcpy 23 22 23 #include "nrc_os_config.h" 24 24 #include "mypredef.h" 25 25 #include "nrtype.h" … … 28 28 #include "nrkernel.h" 29 29 30 //#include "nralloc.h"31 30 #include "nrarith1.h" 32 31 … … 37 36 */ 38 37 39 /* -------------------------------------------------------- */ 40 IMAGE_EXPORT(sint32) sum_si8vector(sint8 *v, long nl, long nh) 41 /* -------------------------------------------------------- */ 42 { 43 int i; 44 sint32 s = 0; 45 for(i=nl; i<=nh; i++) { 46 s += v[i]; 47 } 48 return s; 49 } 50 /* -------------------------------------------------------- */ 51 IMAGE_EXPORT(uint32) sum_u8ivector(uint8 *v, long nl, long nh) 52 /* -------------------------------------------------------- */ 53 { 54 int i; 55 uint32 s = 0; 56 for(i=nl; i<=nh; i++) { 57 s += v[i]; 58 } 59 return s; 60 } 61 /* ---------------------------------------------------------- */ 62 IMAGE_EXPORT(sint32) sum_si16vector(sint16 *v, long nl, long nh) 63 /* ---------------------------------------------------------- */ 64 { 65 int i; 66 sint32 s = 0; 67 for(i=nl; i<=nh; i++) { 68 s += v[i]; 69 } 70 return s; 71 } 72 /* ---------------------------------------------------------- */ 73 IMAGE_EXPORT(uint32) sum_u16ivector(uint16 *v, long nl, long nh) 74 /* ---------------------------------------------------------- */ 75 { 76 int i; 77 uint32 s = 0; 78 for(i=nl; i<=nh; i++) { 79 s += v[i]; 80 } 81 return s; 82 } 83 /* ---------------------------------------------------------- */ 84 IMAGE_EXPORT(sint32) sum_si32vector(sint32 *v, long nl, long nh) 85 /* ---------------------------------------------------------- */ 86 { 87 int i; 88 sint32 s = 0; 89 for(i=nl; i<=nh; i++) { 90 s += v[i]; 91 } 92 return s; 93 } 94 /* ---------------------------------------------------------- */ 95 IMAGE_EXPORT(uint32) sum_u32ivector(uint32 *v, long nl, long nh) 96 /* ---------------------------------------------------------- */ 97 { 98 int i; 99 uint32 s = 0; 100 for(i=nl; i<=nh; i++) { 101 s += v[i]; 102 } 103 return s; 104 } 105 /* ----------------------------------------------------------- */ 106 IMAGE_EXPORT(float32) sum_f32vector(float32 *v, long nl, long nh) 107 /* ----------------------------------------------------------- */ 108 { 109 int i; 110 float32 s = 0.0f; 111 for(i=nl; i<=nh; i++) { 112 s += v[i]; 113 } 114 return s; 115 } 116 /* ----------------------------------------------------------- */ 117 IMAGE_EXPORT(float64) sum_f64vector(float64 *v, long nl, long nh) 118 /* ----------------------------------------------------------- */ 119 { 120 int i; 121 float64 s = 0.0; 122 for(i=nl; i<=nh; i++) { 123 s += v[i]; 124 } 125 return s; 126 } 38 #undef sum_type_vector 39 #define sum_type_vector(t,r) \ 40 r short_name(t,sum_,vector)(t * v, int32_t nl, int32_t nh) \ 41 { \ 42 r s = 0; \ 43 for (int32_t i = nl; i <= nh; i++) { \ 44 s += v[i]; \ 45 } \ 46 return s; \ 47 } 48 49 sum_type_vector(int8_t, int32_t); 50 sum_type_vector(uint8_t, uint32_t); 51 sum_type_vector(int16_t, int32_t); 52 sum_type_vector(uint16_t, uint32_t); 53 sum_type_vector(int32_t, int32_t); 54 sum_type_vector(uint32_t, uint32_t); 55 sum_type_vector(float, float); 56 sum_type_vector(double, double); 127 57 128 58 /* … … 132 62 */ 133 63 134 /* ------------------------------------------------------- */ 135 IMAGE_EXPORT(sint8) min_si8vector(sint8 *v, long nl, long nh) 136 /* ------------------------------------------------------- */ 137 { 138 int i; 139 uint8 m; 140 141 m = v[nl]; 142 for(i=nl+1; i<=nh; i++) { 143 if(v[i]<m) m = v[i]; 144 } 145 return m; 146 } 147 /* ------------------------------------------------------- */ 148 IMAGE_EXPORT(uint8) min_ui8vector(uint8 *v, long nl, long nh) 149 /* ------------------------------------------------------- */ 150 { 151 int i; 152 uint8 m; 153 154 m = v[nl]; 155 for(i=nl+1; i<=nh; i++) { 156 if(v[i]<m) m = v[i]; 157 } 158 return m; 159 } 160 /* ---------------------------------------------------------- */ 161 IMAGE_EXPORT(sint16) min_si16vector(sint16 *v, long nl, long nh) 162 /* ---------------------------------------------------------- */ 163 { 164 int i; 165 int16 m; 166 167 m = v[nl]; 168 for(i=nl+1; i<=nh; i++) { 169 if(v[i]<m) m = v[i]; 170 } 171 return m; 172 } 173 /* ---------------------------------------------------------- */ 174 IMAGE_EXPORT(uint16) min_ui16vector(uint16 *v, long nl, long nh) 175 /* ---------------------------------------------------------- */ 176 { 177 int i; 178 uint16 m; 179 180 m = v[nl]; 181 for(i=nl+1; i<=nh; i++) { 182 if(v[i]<m) m = v[i]; 183 } 184 return m; 185 } 186 /* ---------------------------------------------------------- */ 187 IMAGE_EXPORT(sint32) min_si32vector(sint32 *v, long nl, long nh) 188 /* ---------------------------------------------------------- */ 189 { 190 int i; 191 int16 m; 192 193 m = v[nl]; 194 for(i=nl+1; i<=nh; i++) { 195 if(v[i]<m) m = v[i]; 196 } 197 return m; 198 } 199 /* ---------------------------------------------------------- */ 200 IMAGE_EXPORT(uint32) min_ui32vector(uint32 *v, long nl, long nh) 201 /* ---------------------------------------------------------- */ 202 { 203 int i; 204 uint32 m; 205 206 m = v[nl]; 207 for(i=nl+1; i<=nh; i++) { 208 if(v[i]<m) m = v[i]; 209 } 210 return m; 211 } 212 /* ----------------------------------------------------------- */ 213 IMAGE_EXPORT(float32) min_f32vector(float32 *v, long nl, long nh) 214 /* ----------------------------------------------------------- */ 215 { 216 int i; 217 float32 m; 218 219 m = v[nl]; 220 for(i=nl+1; i<=nh; i++) { 221 if(v[i]<m) m = v[i]; 222 } 223 return m; 224 } 225 /* ----------------------------------------------------------- */ 226 IMAGE_EXPORT(float64) min_f64vector(float64 *v, long nl, long nh) 227 /* ----------------------------------------------------------- */ 228 { 229 int i; 230 float64 m; 231 232 m = v[nl]; 233 for(i=nl+1; i<=nh; i++) { 234 if(v[i]<m) m = v[i]; 235 } 236 return m; 237 } 64 #undef min_type_vector 65 #define min_type_vector(t) \ 66 t short_name(t,min_,vector)(t * v, int32_t nl, int32_t nh) \ 67 { \ 68 t m = v[nl]; \ 69 for (int32_t i = nl + 1; i <= nh; i++) { \ 70 if (v[i] < m) { \ 71 m = v[i]; \ 72 } \ 73 } \ 74 return m; \ 75 } 76 77 78 min_type_vector(int8_t); 79 min_type_vector(uint8_t); 80 min_type_vector(int16_t); 81 min_type_vector(uint16_t); 82 min_type_vector(int32_t); 83 min_type_vector(uint32_t); 84 min_type_vector(float); 85 min_type_vector(double); 86 238 87 239 88 /* … … 243 92 */ 244 93 245 /* ------------------------------------------------------- */ 246 IMAGE_EXPORT(sint8) max_si8vector(sint8 *v, long nl, long nh) 247 /* ------------------------------------------------------- */ 248 { 249 int i; 250 sint8 m; 251 252 m = v[nl]; 253 for(i=nl+1; i<=nh; i++) { 254 if(v[i]>m) m = v[i]; 255 } 256 return m; 257 } 258 /* ------------------------------------------------------- */ 259 IMAGE_EXPORT(uint8) max_ui8vector(uint8 *v, long nl, long nh) 260 /* ------------------------------------------------------- */ 261 { 262 int i; 263 uint8 m; 264 265 m = v[nl]; 266 for(i=nl+1; i<=nh; i++) { 267 if(v[i]>m) m = v[i]; 268 } 269 return m; 270 } 271 /* ---------------------------------------------------------- */ 272 IMAGE_EXPORT(sint16) max_si16vector(sint16 *v, long nl, long nh) 273 /* ---------------------------------------------------------- */ 274 { 275 int i; 276 sint16 m; 277 278 m = v[nl]; 279 for(i=nl+1; i<=nh; i++) { 280 if(v[i]>m) m = v[i]; 281 } 282 return m; 283 } 284 /* ---------------------------------------------------------- */ 285 IMAGE_EXPORT(uint16) max_ui16vector(uint16 *v, long nl, long nh) 286 /* ---------------------------------------------------------- */ 287 { 288 int i; 289 uint16 m; 290 291 m = v[nl]; 292 for(i=nl+1; i<=nh; i++) { 293 if(v[i]>m) m = v[i]; 294 } 295 return m; 296 } 297 /* ---------------------------------------------------------- */ 298 IMAGE_EXPORT(sint32) max_si32vector(sint32 *v, long nl, long nh) 299 /* ---------------------------------------------------------- */ 300 { 301 int i; 302 sint32 m; 303 304 m = v[nl]; 305 for(i=nl+1; i<=nh; i++) { 306 if(v[i]>m) m = v[i]; 307 } 308 return m; 309 } 310 /* ---------------------------------------------------------- */ 311 IMAGE_EXPORT(uint32) max_ui32vector(uint32 *v, long nl, long nh) 312 /* ---------------------------------------------------------- */ 313 { 314 int i; 315 uint32 m; 316 317 m = v[nl]; 318 for(i=nl+1; i<=nh; i++) { 319 if(v[i]>m) m = v[i]; 320 } 321 return m; 322 } 323 /* ----------------------------------------------------------- */ 324 IMAGE_EXPORT(float32) max_f32vector(float32 *v, long nl, long nh) 325 /* ----------------------------------------------------------- */ 326 { 327 int i; 328 float32 m; 329 330 m = v[nl]; 331 for(i=nl+1; i<=nh; i++) { 332 if(v[i]>m) m = v[i]; 333 } 334 return m; 335 } 336 /* ----------------------------------------------------------- */ 337 IMAGE_EXPORT(float64) max_f64vector(float64 *v, long nl, long nh) 338 /* ----------------------------------------------------------- */ 339 { 340 int i; 341 float64 m; 342 343 m = v[nl]; 344 for(i=nl+1; i<=nh; i++) { 345 if(v[i]>m) m = v[i]; 346 } 347 return m; 348 } 94 #undef max_type_vector 95 #define max_type_vector(t) \ 96 t short_name(t,max_,vector)(t * v, int32_t nl, int32_t nh) \ 97 { \ 98 t m = v[nl]; \ 99 for (int32_t i = nl + 1; i <= nh; i++) { \ 100 if (v[i] > m) { \ 101 m = v[i]; \ 102 } \ 103 } \ 104 return m; \ 105 } 106 107 108 max_type_vector(int8_t); 109 max_type_vector(uint8_t); 110 max_type_vector(int16_t); 111 max_type_vector(uint16_t); 112 max_type_vector(int32_t); 113 max_type_vector(uint32_t); 114 max_type_vector(float); 115 max_type_vector(double); 116 117 349 118 /* 350 119 * ---------------------- … … 353 122 */ 354 123 355 /* --------------------------------------------------------------------- */ 356 IMAGE_EXPORT(sint8) min_si8vector_pos(sint8 *v, long nl, long nh, int *pos) 357 /* --------------------------------------------------------------------- */ 358 { 359 int i; 360 sint8 m = v[nl]; 361 int p = nl; 362 363 for(i=nl+1; i<=nh; i++) { 364 if(v[i]>m) { m = v[i]; p = i;} 365 } 366 *pos = p; 367 return m; 368 } 369 /* --------------------------------------------------------------------- */ 370 IMAGE_EXPORT(uint8) min_ui8vector_pos(uint8 *v, long nl, long nh, int *pos) 371 /* --------------------------------------------------------------------- */ 372 { 373 int i; 374 uint8 m = v[nl]; 375 int p = nl; 376 377 for(i=nl+1; i<=nh; i++) { 378 if(v[i]>m) { m = v[i]; p = i;} 379 } 380 *pos = p; 381 return m; 382 } 383 /* ------------------------------------------------------------------------ */ 384 IMAGE_EXPORT(sint16) min_si16vector_pos(sint16 *v, long nl, long nh, int *pos) 385 /* ------------------------------------------------------------------------ */ 386 { 387 int i; 388 sint16 m = v[nl]; 389 int p = nl; 390 391 for(i=nl+1; i<=nh; i++) { 392 if(v[i]>m) { m = v[i]; p = i;} 393 } 394 *pos = p; 395 return m; 396 } 397 /* ------------------------------------------------------------------------ */ 398 IMAGE_EXPORT(uint16) min_ui16vector_pos(uint16 *v, long nl, long nh, int *pos) 399 /* ------------------------------------------------------------------------ */ 400 { 401 int i; 402 uint16 m = v[nl]; 403 int p = nl; 404 405 for(i=nl+1; i<=nh; i++) { 406 if(v[i]>m) { m = v[i]; p = i;} 407 } 408 *pos = p; 409 return m; 410 } 411 /* ------------------------------------------------------------------------ */ 412 IMAGE_EXPORT(sint32) min_si32vector_pos(sint32 *v, long nl, long nh, int *pos) 413 /* ------------------------------------------------------------------------ */ 414 { 415 int i; 416 sint32 m = v[nl]; 417 int p = nl; 418 419 for(i=nl+1; i<=nh; i++) { 420 if(v[i]>m) { m = v[i]; p = i;} 421 } 422 *pos = p; 423 return m; 424 } 425 /* ------------------------------------------------------------------------ */ 426 IMAGE_EXPORT(uint32) min_ui32vector_pos(uint32 *v, long nl, long nh, int *pos) 427 /* ------------------------------------------------------------------------ */ 428 { 429 int i; 430 uint32 m = v[nl]; 431 int p = nl; 432 433 for(i=nl+1; i<=nh; i++) { 434 if(v[i]>m) { m = v[i]; p = i;} 435 } 436 *pos = p; 437 return m; 438 } 439 /* ------------------------------------------------------------------------- */ 440 IMAGE_EXPORT(float32) min_f32vector_pos(float32 *v, long nl, long nh, int *pos) 441 /* ------------------------------------------------------------------------- */ 442 { 443 int i; 444 float32 m = v[nl]; 445 int p = nl; 446 447 for(i=nl+1; i<=nh; i++) { 448 if(v[i]>m) { m = v[i]; p = i;} 449 } 450 *pos = p; 451 return m; 452 } 453 /* ------------------------------------------------------------------------- */ 454 IMAGE_EXPORT(float64) min_f64vector_pos(float64 *v, long nl, long nh, int *pos) 455 /* ------------------------------------------------------------------------- */ 456 { 457 int i; 458 float64 m = v[nl]; 459 int p = nl; 460 461 for(i=nl+1; i<=nh; i++) { 462 if(v[i]>m) { m = v[i]; p = i;} 463 } 464 *pos = p; 465 return m; 466 } 124 125 #undef min_type_vector_pos 126 #define min_type_vector_pos(t) \ 127 t short_name(t,min_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) \ 128 { \ 129 t m = v[nl]; \ 130 int32_t p = nl; \ 131 for (int32_t i = nl + 1; i <= nh; i++) { \ 132 if (v[i] < m) { \ 133 m = v[i]; \ 134 p = i; \ 135 } \ 136 } \ 137 *pos = p; \ 138 return m; \ 139 } 140 141 142 min_type_vector_pos(int8_t); 143 min_type_vector_pos(uint8_t); 144 min_type_vector_pos(int16_t); 145 min_type_vector_pos(uint16_t); 146 min_type_vector_pos(int32_t); 147 min_type_vector_pos(uint32_t); 148 min_type_vector_pos(float); 149 min_type_vector_pos(double); 150 467 151 468 152 /* … … 472 156 */ 473 157 474 /* --------------------------------------------------------------------- */ 475 IMAGE_EXPORT(sint8) max_si8vector_pos(sint8 *v, long nl, long nh, int *pos) 476 /* --------------------------------------------------------------------- */ 477 { 478 int i; 479 sint8 m = v[nl]; 480 int p = nl; 481 482 for(i=nl+1; i<=nh; i++) { 483 if(v[i]>m) { m = v[i]; p = i;} 484 } 485 *pos = p; 486 487 return m; 488 } 489 /* --------------------------------------------------------------------- */ 490 IMAGE_EXPORT(uint8) max_ui8vector_pos(uint8 *v, long nl, long nh, int *pos) 491 /* --------------------------------------------------------------------- */ 492 { 493 int i; 494 uint8 m = v[nl]; 495 int p = nl; 496 497 for(i=nl+1; i<=nh; i++) { 498 if(v[i]>m) { m = v[i]; p = i;} 499 } 500 *pos = p; 501 502 return m; 503 } 158 159 #undef max_type_vector_pos 160 #define max_type_vector_pos(t) \ 161 t short_name(t,max_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) \ 162 { \ 163 t m = v[nl]; \ 164 int32_t p = nl; \ 165 for (int32_t i = nl + 1; i <= nh; i++) { \ 166 if (v[i] > m) { \ 167 m = v[i]; \ 168 p = i; \ 169 } \ 170 } \ 171 *pos = p; \ 172 return m; \ 173 } 174 175 176 max_type_vector_pos(int8_t); 177 max_type_vector_pos(uint8_t); 178 max_type_vector_pos(int16_t); 179 max_type_vector_pos(uint16_t); 180 max_type_vector_pos(int32_t); 181 max_type_vector_pos(uint32_t); 182 max_type_vector_pos(float); 183 max_type_vector_pos(double); 184 185 186 #undef add_type_vector 187 #define add_type_vector(t) \ 188 void short_name(t,add_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) \ 189 { \ 190 for (int32_t i = nl; i <= nh; i++) { \ 191 D[i] = S1[i] + S2[i]; \ 192 } \ 193 } 194 195 add_type_vector(int8_t); 196 add_type_vector(uint8_t); 197 add_type_vector(int16_t); 198 add_type_vector(uint16_t); 199 add_type_vector(int32_t); 200 add_type_vector(uint32_t); 201 add_type_vector(float); 202 add_type_vector(double); 203 204 205 #undef sub_type_vector 206 #define sub_type_vector(t) \ 207 void short_name(t,sub_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) \ 208 { \ 209 for (int32_t i = nl; i <= nh; i++) { \ 210 D[i] = S1[i] - S2[i]; \ 211 } \ 212 } 213 214 sub_type_vector(int8_t); 215 sub_type_vector(uint8_t); 216 sub_type_vector(int16_t); 217 sub_type_vector(uint16_t); 218 sub_type_vector(int32_t); 219 sub_type_vector(uint32_t); 220 sub_type_vector(float); 221 sub_type_vector(double); 222 223 224 #undef mulc_type_vector 225 #define mulc_type_vector(t) \ 226 void short_name(t,mulc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D) \ 227 { \ 228 for (int32_t i = nl; i <= nh; i++) { \ 229 D[i] = S[i] * c; \ 230 } \ 231 } 232 233 mulc_type_vector(int8_t); 234 mulc_type_vector(uint8_t); 235 mulc_type_vector(int16_t); 236 mulc_type_vector(uint16_t); 237 mulc_type_vector(int32_t); 238 mulc_type_vector(uint32_t); 239 mulc_type_vector(float); 240 mulc_type_vector(double); 241 242 243 #undef divc_type_vector 244 #define divc_type_vector(t) \ 245 void short_name(t,divc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D) \ 246 { \ 247 for (int32_t i = nl; i <= nh; i++) { \ 248 D[i] = S[i] / c; \ 249 } \ 250 } 251 252 divc_type_vector(int8_t); 253 divc_type_vector(uint8_t); 254 divc_type_vector(int16_t); 255 divc_type_vector(uint16_t); 256 divc_type_vector(int32_t); 257 divc_type_vector(uint32_t); 258 divc_type_vector(float); 259 divc_type_vector(double); 260 261 262 #undef cumulleft_type_vector 263 #define cumulleft_type_vector(t) \ 264 void short_name(t,cumulleft_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) \ 265 { \ 266 for (int32_t i = nh - 1; i >= nl; i--) { \ 267 D[i] += S[i + 1]; \ 268 } \ 269 } 270 271 cumulleft_type_vector(int8_t); 272 cumulleft_type_vector(uint8_t); 273 cumulleft_type_vector(int16_t); 274 cumulleft_type_vector(uint16_t); 275 cumulleft_type_vector(int32_t); 276 cumulleft_type_vector(uint32_t); 277 cumulleft_type_vector(float); 278 cumulleft_type_vector(double); 279 280 281 #undef cumulright_type_vector 282 #define cumulright_type_vector(t) \ 283 void short_name(t,cumulright_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) \ 284 { \ 285 for (int32_t i = nl + 1; i <= nh; i++) { \ 286 D[i] += S[i - 1]; \ 287 } \ 288 } 289 290 cumulright_type_vector(int8_t); 291 cumulright_type_vector(uint8_t); 292 cumulright_type_vector(int16_t); 293 cumulright_type_vector(uint16_t); 294 cumulright_type_vector(int32_t); 295 cumulright_type_vector(uint32_t); 296 cumulright_type_vector(float); 297 cumulright_type_vector(double); 298 299 300 #undef mulfrac_type_vector 301 #define mulfrac_type_vector(t) \ 302 void short_name(t,mulfrac_,vector)(t * S, int32_t nl, int32_t nh, int32_t a, int32_t b, t * D) \ 303 { \ 304 for (int32_t i = nl; i <= nh; i++) { \ 305 D[i] = (a * S[i]) / b; \ 306 } \ 307 } 308 309 310 mulfrac_type_vector(int8_t); 311 mulfrac_type_vector(uint8_t); 312 mulfrac_type_vector(int16_t); 313 mulfrac_type_vector(uint16_t); 314 mulfrac_type_vector(int32_t); 315 mulfrac_type_vector(uint32_t); 316 mulfrac_type_vector(float); 317 mulfrac_type_vector(double); 318 319 320 /* --------------------------------------------------------------------- */ 321 void beta_sum_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D) 322 /* --------------------------------------------------------------------- */ 323 { 324 int32_t r, g, b; 325 int32_t s; 326 for (int32_t i = nl; i <= nh; i++) { 327 r = S[i].r; 328 g = S[i].g; 329 b = S[i].b; 330 s = r + g + b; 331 D[i].r = s; 332 D[i].g = s; 333 D[i].b = s; 334 } 335 } 336 337 /* ----------------------------------------------------------------------- */ 338 void beta_average_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D) 339 /* ----------------------------------------------------------------------- */ 340 { 341 int32_t r, g, b; 342 int32_t s; 343 for (int32_t i = nl; i <= nh; i++) { 344 r = S[i].r; 345 g = S[i].g; 346 b = S[i].b; 347 s = (r + g + b) / 3; 348 D[i].r = s; 349 D[i].g = s; 350 D[i].b = s; 351 } 352 } 353 504 354 /* ------------------------------------------------------------------------ */ 505 IMAGE_EXPORT(sint16) max_si16vector_pos(sint16 *v, long nl, long nh, int *pos)355 void mulc_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t c, rgb32 * D) 506 356 /* ------------------------------------------------------------------------ */ 507 357 { 508 int i; 509 int16 m = v[nl]; 510 int p = nl; 511 512 for(i=nl+1; i<=nh; i++) { 513 if(v[i]>m) { m = v[i]; p = i;} 514 } 515 *pos = p; 516 return m; 517 } 518 /* ----------------------------------------------------------------------- */ 519 IMAGE_EXPORT(uint16) max_ui16vector_pos(uint16 *v, long nl, long nh, int *pos) 520 /* ----------------------------------------------------------------------- */ 521 { 522 int i; 523 uint16 m = v[nl]; 524 int p = nl; 525 526 for(i=nl+1; i<=nh; i++) { 527 if(v[i]>m) { m = v[i]; p = i;} 528 } 529 *pos = p; 530 531 return m; 532 } 533 /* --------------------------------------------------------------------- */ 534 IMAGE_EXPORT(sint32) max_si32vector_pos(sint32 *v, long nl, long nh, int *pos) 535 /* --------------------------------------------------------------------- */ 536 { 537 int i; 538 sint32 m = v[nl]; 539 int p = nl; 540 541 for(i=nl+1; i<=nh; i++) { 542 if(v[i]>m) { m = v[i]; p = i;} 543 } 544 *pos = p; 545 546 return m; 547 } 548 /* ------------------------------------------------------------------------ */ 549 IMAGE_EXPORT(uint32) max_ui32vector_pos(uint32 *v, long nl, long nh, int *pos) 550 /* ------------------------------------------------------------------------ */ 551 { 552 int i; 553 uint32 m = v[nl]; 554 int p = nl; 555 556 for(i=nl+1; i<=nh; i++) { 557 if(v[i]>m) { m = v[i]; p = i;} 558 } 559 *pos = p; 560 561 return m; 562 } 563 /* ----------------------------------------------------------------------- */ 564 IMAGE_EXPORT(float32) max_f32vector_pos(float32 *v, long nl, long nh, int *pos) 565 /* ----------------------------------------------------------------------- */ 566 { 567 int i; 568 float32 m = v[nl]; 569 int p = nl; 570 571 for(i=nl+1; i<=nh; i++) { 572 if(v[i]>m) { m = v[i]; p = i;} 573 } 574 *pos = p; 575 576 return m; 577 } 578 /* ------------------------------------------------------------------------- */ 579 IMAGE_EXPORT(float64) max_f64vector_pos(float64 *v, long nl, long nh, int *pos) 580 /* ------------------------------------------------------------------------- */ 581 { 582 int i; 583 float64 m = v[nl]; 584 int p = nl; 585 586 for(i=nl+1; i<=nh; i++) { 587 if(v[i]>m) { m = v[i]; p = i;} 588 } 589 *pos = p; 590 591 return m; 592 } 593 /* --------------------------------------------------------------------- */ 594 IMAGE_EXPORT(void) beta_sum_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D) 595 /* --------------------------------------------------------------------- */ 596 { 597 long i; 598 int32 r, g, b, s; 599 for(i=nl; i<=nh; i++){ 600 r = S[i].r; 601 g = S[i].g; 602 b = S[i].b; 603 s = r + g + b; 604 D[i].r = s; 605 D[i].g = s; 606 D[i].b = s; 607 } 608 } 609 /* ----------------------------------------------------------------------- */ 610 IMAGE_EXPORT(void) beta_average_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D) 611 /* ----------------------------------------------------------------------- */ 612 { 613 long i; 614 int32 r, g, b, s; 615 for(i=nl; i<=nh; i++){ 616 r = S[i].r; 617 g = S[i].g; 618 b = S[i].b; 619 s = (r + g + b) / 3; 620 D[i].r = s; 621 D[i].g = s; 622 D[i].b = s; 623 } 624 } 625 /* ------------------------------------------------------------------------ */ 626 IMAGE_EXPORT(void) add_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D) 627 /* ------------------------------------------------------------------------ */ 628 { 629 long i; 630 for(i=nl; i<=nh; i++) D[i] = S1[i] + S2[i]; 631 } 632 /* ------------------------------------------------------------------------ */ 633 IMAGE_EXPORT(void) sub_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D) 634 /* ------------------------------------------------------------------------ */ 635 { 636 long i; 637 for(i=nl; i<=nh; i++) D[i] = S1[i] - S2[i]; 638 } 639 /* ---------------------------------------------------------------------- */ 640 IMAGE_EXPORT(void) mulc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D) 641 /* ---------------------------------------------------------------------- */ 642 { 643 long i; 644 for(i=nl; i<=nh; i++) D[i] = c * S[i]; 645 } 646 /* ------------------------------------------------------------------------ */ 647 IMAGE_EXPORT(void) mulc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D) 648 /* ------------------------------------------------------------------------ */ 649 { 650 long i; 651 652 for(i=nl; i<=nh; i++) { 653 D[i].r = c * S[i].r; 654 D[i].g = c * S[i].g; 655 D[i].b = c * S[i].b; 656 } 657 } 658 /* ------------------------------------------------------------------------ */ 659 IMAGE_EXPORT(void) divc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D) 660 /* ------------------------------------------------------------------------ */ 661 { 662 long i; 663 for(i=nl; i<=nh; i++) D[i] = S[i] / c; 664 } 665 /* -------------------------------------------------------------------------- */ 666 IMAGE_EXPORT(void) divc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D) 667 /* -------------------------------------------------------------------------- */ 668 { 669 long i; 670 671 for(i=nl; i<=nh; i++) { 672 D[i].r = S[i].r / c; 673 D[i].g = S[i].g / c; 674 D[i].b = S[i].b / c; 675 } 676 } 677 /* -------------------------------------------------------------------- */ 678 IMAGE_EXPORT(void) cumulleft_i32vector(int32 *S, long nl,long nh, int32 *D) 679 /* -------------------------------------------------------------------- */ 680 { 681 // for histogram 682 long i; 683 684 for(i=nh-1; i>=nl; i--) { 685 D[i] += S[i+1]; 686 } 687 } 688 /* --------------------------------------------------------------------- */ 689 IMAGE_EXPORT(void) cumulleft_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D) 690 /* --------------------------------------------------------------------- */ 691 { 692 // for histogram 693 long i; 694 695 for(i=nh-1; i>=nl; i--) { 696 D[i].r += S[i+1].r; 697 D[i].g += S[i+1].g; 698 D[i].b += S[i+1].b; 699 } 700 } 701 /* -------------------------------------------------------------------- */ 702 IMAGE_EXPORT(void) cumulright_i32vector(int32 *S, long nl,long nh, int32 *D) 703 /* -------------------------------------------------------------------- */ 704 { 705 // for histogram 706 long i; 707 708 for(i=nl+1; i<=nh; i++) { 709 D[i] += S[i-1]; 710 } 711 } 712 /* ---------------------------------------------------------------------- */ 713 IMAGE_EXPORT(void) cumulright_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D) 714 /* ---------------------------------------------------------------------- */ 715 { 716 // for histogram 717 long i; 718 719 for(i=nl+1; i<=nh; i++) { 720 D[i].r += S[i-1].r; 721 D[i].g += S[i-1].g; 722 D[i].b += S[i-1].b; 723 } 724 } 725 /* ----------------------------------------------------------------------------------- */ 726 IMAGE_EXPORT(void) mulfrac_i32vector(int32 *S, long nl,long nh, int32 a, int32 b, int32 *D) 727 /* ----------------------------------------------------------------------------------- */ 728 { 729 long i; 730 731 for(i=nl; i<=nh; i++) { 732 //D[i] = (a * S[i] + b) / b; 733 D[i] = (a * S[i]) / b; 734 } 735 } 358 for (int32_t i = nl; i <= nh; i++) { 359 D[i].r = c * S[i].r; 360 D[i].g = c * S[i].g; 361 D[i].b = c * S[i].b; 362 } 363 } 364 365 /* --------------------------------------------------------------------- */ 366 void divc_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t c, rgb32 * D) 367 /* --------------------------------------------------------------------- */ 368 { 369 for (int32_t i = nl; i <= nh; i++) { 370 D[i].r = S[i].r / c; 371 D[i].g = S[i].g / c; 372 D[i].b = S[i].b / c; 373 } 374 } 375 376 /* --------------------------------------------------------------------- */ 377 void cumulleft_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D) 378 /* --------------------------------------------------------------------- */ 379 { 380 // for histogram 381 for (int32_t i = nh - 1; i >= nl; i--) { 382 D[i].r += S[i + 1].r; 383 D[i].g += S[i + 1].g; 384 D[i].b += S[i + 1].b; 385 } 386 } 387 388 389 /* --------------------------------------------------------------------- */ 390 void cumulright_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D) 391 /* --------------------------------------------------------------------- */ 392 { 393 // for histogram 394 for (int32_t i = nl + 1; i <= nh; i++) { 395 D[i].r += S[i - 1].r; 396 D[i].g += S[i - 1].g; 397 D[i].b += S[i - 1].b; 398 } 399 } 400 401 736 402 /* ------------------------------------------------------------------------------------- */ 737 IMAGE_EXPORT(void) mulfrac_rgb32vector(rgb32 *S, long nl,long nh, int32 a, int32 b, rgb32 *D)403 void mulfrac_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t a, int32_t b, rgb32 * D) 738 404 /* ------------------------------------------------------------------------------------- */ 739 405 { 740 long i; 741 742 for(i=nl; i<=nh; i++) { 743 //D[i].r = (a * S[i].r + b) / b; 744 //D[i].g = (a * S[i].g + b) / b; 745 //D[i].b = (a * S[i].b + b) / b; 746 D[i].r = (a * S[i].r) / b; 747 D[i].g = (a * S[i].g) / b; 748 D[i].b = (a * S[i].b) / b; 749 } 750 } 406 for (int32_t i = nl; i <= nh; i++) { 407 D[i].r = (a * S[i].r) / b; 408 D[i].g = (a * S[i].g) / b; 409 D[i].b = (a * S[i].b) / b; 410 } 411 } 412 413 // Local Variables: 414 // tab-width: 4 415 // c-basic-offset: 4 416 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 417 // indent-tabs-mode: nil 418 // End: 419 420 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 421 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2.c
r772 r821 17 17 #include <malloc.h> 18 18 #include <math.h> // fabs 19 // #include <memory.h> // memcpy 20 19 20 #include "nrc_os_config.h" 21 21 #include "mypredef.h" 22 22 #include "nrtype.h" … … 25 25 #include "nrkernel.h" 26 26 27 #include "nrarith1.h"28 27 #include "nrarith2.h" 29 28 … … 32 31 /* ------------------ */ 33 32 34 /* ----------------------------------------------------------------------------- */ 35 IMAGE_EXPORT(sint8) min_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch) 36 /* ----------------------------------------------------------------------------- */ 37 { 38 int i, j; 39 sint8 minimum = m[nrl][ncl]; 40 41 for(i=nrl; i<=nrh; i++) { 42 for(j=ncl; j<=nch; j++) { 43 if(m[i][j]<minimum) minimum = m[i][j]; 44 } 45 } 46 return minimum; 47 } 48 /* ------------------------------------------------------------------------------ */ 49 IMAGE_EXPORT(uint8) min_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch) 50 /* ------------------------------------------------------------------------------ */ 51 { 52 int i, j; 53 uint8 minimum = m[nrl][ncl]; 54 55 for(i=nrl; i<=nrh; i++) { 56 for(j=ncl; j<=nch; j++) { 57 if(m[i][j]<minimum) minimum = m[i][j]; 58 } 59 } 60 return minimum; 61 } 62 /* --------------------------------------------------------------------------------- */ 63 IMAGE_EXPORT(sint16) min_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch) 64 /* --------------------------------------------------------------------------------- */ 65 { 66 int i, j; 67 sint16 minimum = m[nrl][ncl]; 68 69 for(i=nrl; i<=nrh; i++) { 70 for(j=ncl; j<=nch; j++) { 71 if(m[i][j]<minimum) minimum = m[i][j]; 72 } 73 } 74 return minimum; 75 } 76 /* --------------------------------------------------------------------------------- */ 77 IMAGE_EXPORT(uint16) min_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch) 78 /* --------------------------------------------------------------------------------- */ 79 { 80 int i, j; 81 uint16 minimum = m[nrl][ncl]; 82 83 for(i=nrl; i<=nrh; i++) { 84 for(j=ncl; j<=nch; j++) { 85 if(m[i][j]<minimum) minimum = m[i][j]; 86 } 87 } 88 return minimum; 89 } 90 /* --------------------------------------------------------------------------------- */ 91 IMAGE_EXPORT(sint32) min_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch) 92 /* --------------------------------------------------------------------------------- */ 93 { 94 int i, j; 95 sint32 minimum = m[nrl][ncl]; 96 97 for(i=nrl; i<=nrh; i++) { 98 for(j=ncl; j<=nch; j++) { 99 if(m[i][j]<minimum) minimum = m[i][j]; 100 } 101 } 102 return minimum; 103 } 104 /* --------------------------------------------------------------------------------- */ 105 IMAGE_EXPORT(uint32) min_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch) 106 /* --------------------------------------------------------------------------------- */ 107 { 108 int i, j; 109 uint32 minimum = m[nrl][ncl]; 110 111 for(i=nrl; i<=nrh; i++) { 112 for(j=ncl; j<=nch; j++) { 113 if(m[i][j]<minimum) minimum = m[i][j]; 114 } 115 } 116 return minimum; 117 } 118 /* --------------------------------------------------------------------------------- */ 119 IMAGE_EXPORT(sint64) min_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch) 120 /* --------------------------------------------------------------------------------- */ 121 { 122 int i, j; 123 sint64 minimum = m[nrl][ncl]; 124 125 for(i=nrl; i<=nrh; i++) { 126 for(j=ncl; j<=nch; j++) { 127 if(m[i][j]<minimum) minimum = m[i][j]; 128 } 129 } 130 return minimum; 131 } 132 /* --------------------------------------------------------------------------------- */ 133 IMAGE_EXPORT(uint64) min_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch) 134 /* --------------------------------------------------------------------------------- */ 135 { 136 int i, j; 137 uint64 minimum = m[nrl][ncl]; 138 139 for(i=nrl; i<=nrh; i++) { 140 for(j=ncl; j<=nch; j++) { 141 if(m[i][j]<minimum) minimum = m[i][j]; 142 } 143 } 144 return minimum; 145 } 146 /* ---------------------------------------------------------------------------------- */ 147 IMAGE_EXPORT(float32) min_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch) 148 /* ---------------------------------------------------------------------------------- */ 149 { 150 int i, j; 151 float32 minimum = m[nrl][ncl]; 152 153 for(i=nrl; i<=nrh; i++) { 154 for(j=ncl; j<=nch; j++) { 155 if(m[i][j]<minimum) minimum = m[i][j]; 156 } 157 } 158 return minimum; 159 } 160 /* ---------------------------------------------------------------------------------- */ 161 IMAGE_EXPORT(float64) min_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch) 162 /* ---------------------------------------------------------------------------------- */ 163 { 164 int i, j; 165 float64 minimum = m[nrl][ncl]; 166 167 for(i=nrl; i<=nrh; i++) { 168 for(j=ncl; j<=nch; j++) { 169 if(m[i][j]<minimum) minimum = m[i][j]; 170 } 171 } 172 return minimum; 173 } 33 #undef min_type_matrix 34 #define min_type_matrix(t) \ 35 t short_name(t,min_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ 36 { \ 37 t minimum = m[nrl][nrh]; \ 38 for (int32_t i = nrl; i <= nrh; i++) { \ 39 for (int32_t j = ncl; j <= nch; j++) { \ 40 if (m[i][j] < minimum) { \ 41 minimum = m[i][j]; \ 42 } \ 43 } \ 44 } \ 45 return minimum; \ 46 } 47 48 min_type_matrix(int8_t); 49 min_type_matrix(uint8_t); 50 min_type_matrix(int16_t); 51 min_type_matrix(uint16_t); 52 min_type_matrix(int32_t); 53 min_type_matrix(uint32_t); 54 min_type_matrix(int64_t); 55 min_type_matrix(uint64_t); 56 min_type_matrix(float); 57 min_type_matrix(double); 58 174 59 175 60 /* ------------------ */ … … 177 62 /* ------------------ */ 178 63 179 /* ----------------------------------------------------------------------------- */ 180 IMAGE_EXPORT(sint8) max_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch) 181 /* ----------------------------------------------------------------------------- */ 182 { 183 int i, j; 184 sint8 minimum = m[nrl][ncl]; 185 186 for(i=nrl; i<=nrh; i++) { 187 for(j=ncl; j<=nch; j++) { 188 if(m[i][j]>minimum) minimum = m[i][j]; 189 } 190 } 191 return minimum; 192 } 193 /* ------------------------------------------------------------------------------ */ 194 IMAGE_EXPORT(uint8) max_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch) 195 /* ------------------------------------------------------------------------------ */ 196 { 197 int i, j; 198 uint8 minimum = m[nrl][ncl]; 199 200 for(i=nrl; i<=nrh; i++) { 201 for(j=ncl; j<=nch; j++) { 202 if(m[i][j]>minimum) minimum = m[i][j]; 203 } 204 } 205 return minimum; 206 } 207 /* --------------------------------------------------------------------------------- */ 208 IMAGE_EXPORT(sint16) max_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch) 209 /* --------------------------------------------------------------------------------- */ 210 { 211 int i, j; 212 sint16 minimum = m[nrl][ncl]; 213 214 for(i=nrl; i<=nrh; i++) { 215 for(j=ncl; j<=nch; j++) { 216 if(m[i][j]>minimum) minimum = m[i][j]; 217 } 218 } 219 return minimum; 220 } 221 /* --------------------------------------------------------------------------------- */ 222 IMAGE_EXPORT(uint16) max_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch) 223 /* --------------------------------------------------------------------------------- */ 224 { 225 int i, j; 226 uint16 minimum = m[nrl][ncl]; 227 228 for(i=nrl; i<=nrh; i++) { 229 for(j=ncl; j<=nch; j++) { 230 if(m[i][j]>minimum) minimum = m[i][j]; 231 } 232 } 233 return minimum; 234 } 235 /* --------------------------------------------------------------------------------- */ 236 IMAGE_EXPORT(sint32) max_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch) 237 /* --------------------------------------------------------------------------------- */ 238 { 239 int i, j; 240 sint32 minimum = m[nrl][ncl]; 241 242 for(i=nrl; i<=nrh; i++) { 243 for(j=ncl; j<=nch; j++) { 244 if(m[i][j]>minimum) minimum = m[i][j]; 245 } 246 } 247 return minimum; 248 } 249 /* --------------------------------------------------------------------------------- */ 250 IMAGE_EXPORT(uint32) max_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch) 251 /* --------------------------------------------------------------------------------- */ 252 { 253 int i, j; 254 uint32 minimum = m[nrl][ncl]; 255 256 for(i=nrl; i<=nrh; i++) { 257 for(j=ncl; j<=nch; j++) { 258 if(m[i][j]>minimum) minimum = m[i][j]; 259 } 260 } 261 return minimum; 262 } 263 /* --------------------------------------------------------------------------------- */ 264 IMAGE_EXPORT(sint64) max_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch) 265 /* --------------------------------------------------------------------------------- */ 266 { 267 int i, j; 268 sint64 minimum = m[nrl][ncl]; 269 270 for(i=nrl; i<=nrh; i++) { 271 for(j=ncl; j<=nch; j++) { 272 if(m[i][j]>minimum) minimum = m[i][j]; 273 } 274 } 275 return minimum; 276 } 277 /* --------------------------------------------------------------------------------- */ 278 IMAGE_EXPORT(uint64) max_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch) 279 /* --------------------------------------------------------------------------------- */ 280 { 281 int i, j; 282 uint64 minimum = m[nrl][ncl]; 283 284 for(i=nrl; i<=nrh; i++) { 285 for(j=ncl; j<=nch; j++) { 286 if(m[i][j]>minimum) minimum = m[i][j]; 287 } 288 } 289 return minimum; 290 } 291 /* ---------------------------------------------------------------------------------- */ 292 IMAGE_EXPORT(float32) max_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch) 293 /* ---------------------------------------------------------------------------------- */ 294 { 295 int i, j; 296 float32 minimum = m[nrl][ncl]; 297 298 for(i=nrl; i<=nrh; i++) { 299 for(j=ncl; j<=nch; j++) { 300 if(m[i][j]>minimum) minimum = m[i][j]; 301 } 302 } 303 return minimum; 304 } 305 /* ---------------------------------------------------------------------------------- */ 306 IMAGE_EXPORT(float64) max_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch) 307 /* ---------------------------------------------------------------------------------- */ 308 { 309 int i, j; 310 float64 minimum = m[nrl][ncl]; 311 312 for(i=nrl; i<=nrh; i++) { 313 for(j=ncl; j<=nch; j++) { 314 if(m[i][j]>minimum) minimum = m[i][j]; 315 } 316 } 317 return minimum; 318 } 319 320 /* -------------------------------------------------------------------------------------------------- */ 321 IMAGE_EXPORT(void) add_si8matrix(sint8 **X, long nrl,long nrh, long ncl, long nch, sint8 **Y, sint8 **Z) 322 /* -------------------------------------------------------------------------------------------------- */ 323 { 324 long i, j; 325 326 for(i=nrl; i<=nrh; i++) { 327 for(j=ncl; j<=nch; j++) { 328 Z[i][j] = X[i][j] + Y[i][j]; 329 } 330 } 331 } 64 #undef max_type_matrix 65 #define max_type_matrix(t) \ 66 t short_name(t,max_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \ 67 { \ 68 t maximum = m[nrl][nrh]; \ 69 for (int32_t i = nrl; i <= nrh; i++) { \ 70 for (int32_t j = ncl; j <= nch; j++) { \ 71 if (m[i][j] > maximum) { \ 72 maximum = m[i][j]; \ 73 } \ 74 } \ 75 } \ 76 return maximum; \ 77 } 78 79 max_type_matrix(int8_t); 80 max_type_matrix(uint8_t); 81 max_type_matrix(int16_t); 82 max_type_matrix(uint16_t); 83 max_type_matrix(int32_t); 84 max_type_matrix(uint32_t); 85 max_type_matrix(int64_t); 86 max_type_matrix(uint64_t); 87 max_type_matrix(float); 88 max_type_matrix(double); 89 90 332 91 333 92 /* ------------------ */ … … 335 94 /* ------------------ */ 336 95 337 /* -------------------------------------------------------------------------------------------------- */ 338 IMAGE_EXPORT(void) add_ui8matrix(uint8 **X, long nrl,long nrh, long ncl, long nch, uint8 **Y, uint8 **Z) 339 /* -------------------------------------------------------------------------------------------------- */ 340 { 341 long i, j; 342 343 for(i=nrl; i<=nrh; i++) { 344 for(j=ncl; j<=nch; j++) { 345 Z[i][j] = X[i][j] + Y[i][j]; 346 } 347 } 348 } 349 /* ------------------------------------------------------------------------------------------------------ */ 350 IMAGE_EXPORT(void) add_si16matrix(sint16 **X, long nrl,long nrh, long ncl, long nch, sint16 **Y, sint16 **Z) 351 /* ------------------------------------------------------------------------------------------------------ */ 352 { 353 long i, j; 354 355 for(i=nrl; i<=nrh; i++) { 356 for(j=ncl; j<=nch; j++) { 357 Z[i][j] = X[i][j] + Y[i][j]; 358 } 359 } 360 } 361 /* ------------------------------------------------------------------------------------------------------ */ 362 IMAGE_EXPORT(void) add_ui16matrix(uint16 **X, long nrl,long nrh, long ncl, long nch, uint16 **Y, uint16 **Z) 363 /* ------------------------------------------------------------------------------------------------------ */ 364 { 365 long i, j; 366 367 for(i=nrl; i<=nrh; i++) { 368 for(j=ncl; j<=nch; j++) { 369 Z[i][j] = X[i][j] + Y[i][j]; 370 } 371 } 372 } 373 /* ------------------------------------------------------------------------------------------------------ */ 374 IMAGE_EXPORT(void) add_si32matrix(sint32 **X, long nrl,long nrh, long ncl, long nch, sint32 **Y, sint32 **Z) 375 /* ------------------------------------------------------------------------------------------------------ */ 376 { 377 long i, j; 378 379 for(i=nrl; i<=nrh; i++) { 380 for(j=ncl; j<=nch; j++) { 381 Z[i][j] = X[i][j] + Y[i][j]; 382 } 383 } 384 } 385 /* ------------------------------------------------------------------------------------------------------ */ 386 IMAGE_EXPORT(void) add_ui32matrix(uint32 **X, long nrl,long nrh, long ncl, long nch, uint32 **Y, uint32 **Z) 387 /* ------------------------------------------------------------------------------------------------------ */ 388 { 389 long i, j; 390 391 for(i=nrl; i<=nrh; i++) { 392 for(j=ncl; j<=nch; j++) { 393 Z[i][j] = X[i][j] + Y[i][j]; 394 } 395 } 396 } 397 /* ------------------------------------------------------------------------------------------------------ */ 398 IMAGE_EXPORT(void) add_si64matrix(sint64 **X, long nrl,long nrh, long ncl, long nch, sint64 **Y, sint64 **Z) 399 /* ------------------------------------------------------------------------------------------------------ */ 400 { 401 long i, j; 402 403 for(i=nrl; i<=nrh; i++) { 404 for(j=ncl; j<=nch; j++) { 405 Z[i][j] = X[i][j] + Y[i][j]; 406 } 407 } 408 } 409 /* ------------------------------------------------------------------------------------------------------ */ 410 IMAGE_EXPORT(void) add_ui64matrix(uint64 **X, long nrl,long nrh, long ncl, long nch, uint64 **Y, uint64 **Z) 411 /* ------------------------------------------------------------------------------------------------------ */ 412 { 413 long i, j; 414 415 for(i=nrl; i<=nrh; i++) { 416 for(j=ncl; j<=nch; j++) { 417 Z[i][j] = X[i][j] + Y[i][j]; 418 } 419 } 420 } 421 /* -------------------------------------------------------------------------------------------------------- */ 422 IMAGE_EXPORT(void) add_f32matrix(float32 **X, long nrl,long nrh, long ncl, long nch, float32 **Y, float32 **Z) 423 /* -------------------------------------------------------------------------------------------------------- */ 424 { 425 long i, j; 426 427 for(i=nrl; i<=nrh; i++) { 428 for(j=ncl; j<=nch; j++) { 429 Z[i][j] = X[i][j] + Y[i][j]; 430 } 431 } 432 } 433 /* -------------------------------------------------------------------------------------------------------- */ 434 IMAGE_EXPORT(void) add_f64matrix(float64 **X, long nrl,long nrh, long ncl, long nch, float64 **Y, float64 **Z) 435 /* -------------------------------------------------------------------------------------------------------- */ 436 { 437 long i, j; 438 439 for(i=nrl; i<=nrh; i++) { 440 for(j=ncl; j<=nch; j++) { 441 Z[i][j] = X[i][j] + Y[i][j]; 442 } 443 } 444 } 96 97 #undef add_type_matrix 98 #define add_type_matrix(t) \ 99 void short_name(t,add_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \ 100 { \ 101 for (int32_t i = nrl; i <= nrh; i++) { \ 102 for (int32_t j = ncl; j <= nch; j++) { \ 103 Z[i][j] = X[i][j] + Y[i][j]; \ 104 } \ 105 } \ 106 } 107 108 add_type_matrix(int8_t); 109 add_type_matrix(uint8_t); 110 add_type_matrix(int16_t); 111 add_type_matrix(uint16_t); 112 add_type_matrix(int32_t); 113 add_type_matrix(uint32_t); 114 add_type_matrix(int64_t); 115 add_type_matrix(uint64_t); 116 add_type_matrix(float); 117 add_type_matrix(double); 118 119 445 120 /* ----------------------------------------------------------------------------------------------- */ 446 IMAGE_EXPORT(void) add_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)121 void add_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z) 447 122 /* ----------------------------------------------------------------------------------------------- */ 448 123 { 449 long i, j; 450 rgb8 x, y, z; 451 452 for(i=nrl; i<=nrh; i++) { 453 for(j=ncl; j<=nch; j++) { 454 x = X[i][j]; 455 y = Y[i][j]; 456 //z = x + y; 457 RGB8_ADD(x,y,z); 458 Z[i][j] = z; 459 } 460 } 461 } 124 for (int32_t i = nrl; i <= nrh; i++) { 125 for (int32_t j = ncl; j <= nch; j++) { 126 //z = x + y; 127 RGB8_ADD(X[i][j], Y[i][j], Z[i][j]); 128 } 129 } 130 } 131 462 132 /* --------------------------------------------------------------------------------------------------- */ 463 IMAGE_EXPORT(void) add_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)133 void add_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z) 464 134 /* --------------------------------------------------------------------------------------------------- */ 465 135 { 466 long i, j; 467 rgbx8 x, y, z; 468 469 for(i=nrl; i<=nrh; i++) { 470 for(j=ncl; j<=nch; j++) { 471 x = X[i][j]; 472 y = Y[i][j]; 473 //z = x + y; 474 RGBX8_ADD(x,y,z); 475 Z[i][j] = z; 476 } 477 } 136 for (int32_t i = nrl; i <= nrh; i++) { 137 for (int32_t j = ncl; j <= nch; j++) { 138 //z = x + y; 139 RGBX8_ADD(X[i][j], Y[i][j], Z[i][j]); 140 } 141 } 478 142 } 479 143 … … 482 146 /* -------------------- */ 483 147 484 /* ------------------------------------------------------------------------------------------------ */ 485 IMAGE_EXPORT(void) addc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z) 486 /* ------------------------------------------------------------------------------------------------ */ 487 { 488 long i,j; 489 490 for(i=nrl; i<=nrh; i++) { 491 for(j=ncl; j<=nch; j++) { 492 Z[i][j] = X[i][j] + y; 493 } 494 } 495 } 496 /* ------------------------------------------------------------------------------------------------ */ 497 IMAGE_EXPORT(void) addc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z) 498 /* ------------------------------------------------------------------------------------------------ */ 499 { 500 long i,j; 501 502 for(i=nrl; i<=nrh; i++) { 503 for(j=ncl; j<=nch; j++) { 504 Z[i][j] = X[i][j] + y; 505 } 506 } 507 } 508 /* ---------------------------------------------------------------------------------------------------- */ 509 IMAGE_EXPORT(void) addc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z) 510 /* ---------------------------------------------------------------------------------------------------- */ 511 { 512 long i,j; 513 514 for(i=nrl; i<=nrh; i++) { 515 for(j=ncl; j<=nch; j++) { 516 Z[i][j] = X[i][j] + y; 517 } 518 } 519 } 520 /* ---------------------------------------------------------------------------------------------------- */ 521 IMAGE_EXPORT(void) addc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z) 522 /* ---------------------------------------------------------------------------------------------------- */ 523 { 524 long i,j; 525 526 for(i=nrl; i<=nrh; i++) { 527 for(j=ncl; j<=nch; j++) { 528 Z[i][j] = X[i][j] + y; 529 } 530 } 531 } 532 /* ---------------------------------------------------------------------------------------------------- */ 533 IMAGE_EXPORT(void) addc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z) 534 /* ---------------------------------------------------------------------------------------------------- */ 535 { 536 long i,j; 537 538 for(i=nrl; i<=nrh; i++) { 539 for(j=ncl; j<=nch; j++) { 540 Z[i][j] = X[i][j] + y; 541 } 542 } 543 } 544 /* ---------------------------------------------------------------------------------------------------- */ 545 IMAGE_EXPORT(void) addc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z) 546 /* ---------------------------------------------------------------------------------------------------- */ 547 { 548 long i,j; 549 550 for(i=nrl; i<=nrh; i++) { 551 for(j=ncl; j<=nch; j++) { 552 Z[i][j] = X[i][j] + y; 553 } 554 } 555 } 556 /* ---------------------------------------------------------------------------------------------------- */ 557 IMAGE_EXPORT(void) addc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z) 558 /* ---------------------------------------------------------------------------------------------------- */ 559 { 560 long i,j; 561 562 for(i=nrl; i<=nrh; i++) { 563 for(j=ncl; j<=nch; j++) { 564 Z[i][j] = X[i][j] + y; 565 } 566 } 567 } 568 /* ---------------------------------------------------------------------------------------------------- */ 569 IMAGE_EXPORT(void) addc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z) 570 /* ---------------------------------------------------------------------------------------------------- */ 571 { 572 long i,j; 573 574 for(i=nrl; i<=nrh; i++) { 575 for(j=ncl; j<=nch; j++) { 576 Z[i][j] = X[i][j] + y; 577 } 578 } 579 } 580 /* ------------------------------------------------------------------------------------------------------ */ 581 IMAGE_EXPORT(void) addc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z) 582 /* ------------------------------------------------------------------------------------------------------ */ 583 { 584 long i,j; 585 586 for(i=nrl; i<=nrh; i++) { 587 for(j=ncl; j<=nch; j++) { 588 Z[i][j] = X[i][j] + y; 589 } 590 } 591 } 592 /* ------------------------------------------------------------------------------------------------------ */ 593 IMAGE_EXPORT(void) addc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z) 594 /* ------------------------------------------------------------------------------------------------------ */ 595 { 596 long i,j; 597 598 for(i=nrl; i<=nrh; i++) { 599 for(j=ncl; j<=nch; j++) { 600 Z[i][j] = X[i][j] + y; 601 } 602 } 603 } 604 /* ---------------------------------------------------------------------------------------------- */ 605 IMAGE_EXPORT(void) addc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z) 606 /* ---------------------------------------------------------------------------------------------- */ 607 { 608 long i,j; 609 rgb8 x, z; 610 611 for(i=nrl; i<=nrh; i++) { 612 for(j=ncl; j<=nch; j++) { 613 x = X[i][j]; 614 RGB8_ADD(x,y,z); 615 Z[i][j] = z; 616 } 617 } 618 } 619 /* -------------------------------------------------------------------------------------------------- */ 620 IMAGE_EXPORT(void) addc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z) 621 /* -------------------------------------------------------------------------------------------------- */ 622 { 623 long i,j; 624 rgbx8 x, z; 625 626 for(i=nrl; i<=nrh; i++) { 627 for(j=ncl; j<=nch; j++) { 628 x = X[i][j]; 629 RGBX8_ADD(x,y,z); 630 Z[i][j] = z; 631 } 632 } 633 } 634 /* ------------------ */ 635 /* --- Add Matrix --- */ 636 /* ------------------ */ 637 638 /* -------------------------------------------------------------------------------------------------- */ 639 IMAGE_EXPORT(void) sub_ui8matrix(uint8 **X, long nrl,long nrh, long ncl, long nch, uint8 **Y, uint8 **Z) 640 /* -------------------------------------------------------------------------------------------------- */ 641 { 642 long i, j; 643 644 for(i=nrl; i<=nrh; i++) { 645 for(j=ncl; j<=nch; j++) { 646 Z[i][j] = X[i][j] - Y[i][j]; 647 } 648 } 649 } 650 /* ------------------------------------------------------------------------------------------------------ */ 651 IMAGE_EXPORT(void) sub_si16matrix(sint16 **X, long nrl,long nrh, long ncl, long nch, sint16 **Y, sint16 **Z) 652 /* ------------------------------------------------------------------------------------------------------ */ 653 { 654 long i, j; 655 656 for(i=nrl; i<=nrh; i++) { 657 for(j=ncl; j<=nch; j++) { 658 Z[i][j] = X[i][j] - Y[i][j]; 659 } 660 } 661 } 662 /* ------------------------------------------------------------------------------------------------------ */ 663 IMAGE_EXPORT(void) sub_ui16matrix(uint16 **X, long nrl,long nrh, long ncl, long nch, uint16 **Y, uint16 **Z) 664 /* ------------------------------------------------------------------------------------------------------ */ 665 { 666 long i, j; 667 668 for(i=nrl; i<=nrh; i++) { 669 for(j=ncl; j<=nch; j++) { 670 Z[i][j] = X[i][j] - Y[i][j]; 671 } 672 } 673 } 674 /* ------------------------------------------------------------------------------------------------------ */ 675 IMAGE_EXPORT(void) sub_si32matrix(sint32 **X, long nrl,long nrh, long ncl, long nch, sint32 **Y, sint32 **Z) 676 /* ------------------------------------------------------------------------------------------------------ */ 677 { 678 long i, j; 679 680 for(i=nrl; i<=nrh; i++) { 681 for(j=ncl; j<=nch; j++) { 682 Z[i][j] = X[i][j] - Y[i][j]; 683 } 684 } 685 } 686 /* ------------------------------------------------------------------------------------------------------ */ 687 IMAGE_EXPORT(void) sub_ui32matrix(uint32 **X, long nrl,long nrh, long ncl, long nch, uint32 **Y, uint32 **Z) 688 /* ------------------------------------------------------------------------------------------------------ */ 689 { 690 long i, j; 691 692 for(i=nrl; i<=nrh; i++) { 693 for(j=ncl; j<=nch; j++) { 694 Z[i][j] = X[i][j] - Y[i][j]; 695 } 696 } 697 } 698 /* ------------------------------------------------------------------------------------------------------ */ 699 IMAGE_EXPORT(void) sub_si64matrix(sint64 **X, long nrl,long nrh, long ncl, long nch, sint64 **Y, sint64 **Z) 700 /* ------------------------------------------------------------------------------------------------------ */ 701 { 702 long i, j; 703 704 for(i=nrl; i<=nrh; i++) { 705 for(j=ncl; j<=nch; j++) { 706 Z[i][j] = X[i][j] - Y[i][j]; 707 } 708 } 709 } 710 /* ------------------------------------------------------------------------------------------------------ */ 711 IMAGE_EXPORT(void) sub_ui64matrix(uint64 **X, long nrl,long nrh, long ncl, long nch, uint64 **Y, uint64 **Z) 712 /* ------------------------------------------------------------------------------------------------------ */ 713 { 714 long i, j; 715 716 for(i=nrl; i<=nrh; i++) { 717 for(j=ncl; j<=nch; j++) { 718 Z[i][j] = X[i][j] - Y[i][j]; 719 } 720 } 721 } 722 /* -------------------------------------------------------------------------------------------------------- */ 723 IMAGE_EXPORT(void) sub_f32matrix(float32 **X, long nrl,long nrh, long ncl, long nch, float32 **Y, float32 **Z) 724 /* -------------------------------------------------------------------------------------------------------- */ 725 { 726 long i, j; 727 728 for(i=nrl; i<=nrh; i++) { 729 for(j=ncl; j<=nch; j++) { 730 Z[i][j] = X[i][j] - Y[i][j]; 731 } 732 } 733 } 734 /* -------------------------------------------------------------------------------------------------------- */ 735 IMAGE_EXPORT(void) sub_f64matrix(float64 **X, long nrl,long nrh, long ncl, long nch, float64 **Y, float64 **Z) 736 /* -------------------------------------------------------------------------------------------------------- */ 737 { 738 long i, j; 739 740 for(i=nrl; i<=nrh; i++) { 741 for(j=ncl; j<=nch; j++) { 742 Z[i][j] = X[i][j] - Y[i][j]; 743 } 744 } 745 } 148 #undef addc_type_matrix 149 #define addc_type_matrix(t) \ 150 void short_name(t,addc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \ 151 { \ 152 for (int32_t i = nrl; i <= nrh; i++) { \ 153 for (int32_t j = ncl; j <= nch; j++) { \ 154 Z[i][j] = X[i][j] + y; \ 155 } \ 156 } \ 157 } 158 159 addc_type_matrix(int8_t); 160 addc_type_matrix(uint8_t); 161 addc_type_matrix(int16_t); 162 addc_type_matrix(uint16_t); 163 addc_type_matrix(int32_t); 164 addc_type_matrix(uint32_t); 165 addc_type_matrix(int64_t); 166 addc_type_matrix(uint64_t); 167 addc_type_matrix(float); 168 addc_type_matrix(double); 169 170 171 172 /* ---------------------------------------------------------------------------------------------- */ 173 void addc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z) 174 /* ---------------------------------------------------------------------------------------------- */ 175 { 176 for (int32_t i = nrl; i <= nrh; i++) { 177 for (int32_t j = ncl; j <= nch; j++) { 178 RGB8_ADD(X[i][j], y, Z[i][j]); 179 } 180 } 181 } 182 183 /* -------------------------------------------------------------------------------------------------- */ 184 void addc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z) 185 /* -------------------------------------------------------------------------------------------------- */ 186 { 187 for (int32_t i = nrl; i <= nrh; i++) { 188 for (int32_t j = ncl; j <= nch; j++) { 189 RGBX8_ADD(X[i][j], y, Z[i][j]); 190 } 191 } 192 } 193 194 195 /* ------------------ */ 196 /* --- Sub Matrix --- */ 197 /* ------------------ */ 198 199 #undef sub_type_matrix 200 #define sub_type_matrix(t) \ 201 void short_name(t,sub_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \ 202 { \ 203 for (int32_t i = nrl; i <= nrh; i++) { \ 204 for (int32_t j = ncl; j <= nch; j++) { \ 205 Z[i][j] = X[i][j] - Y[i][j]; \ 206 } \ 207 } \ 208 } 209 210 sub_type_matrix(int8_t); 211 sub_type_matrix(uint8_t); 212 sub_type_matrix(int16_t); 213 sub_type_matrix(uint16_t); 214 sub_type_matrix(int32_t); 215 sub_type_matrix(uint32_t); 216 sub_type_matrix(int64_t); 217 sub_type_matrix(uint64_t); 218 sub_type_matrix(float); 219 sub_type_matrix(double); 220 221 746 222 /* ----------------------------------------------------------------------------------------------- */ 747 IMAGE_EXPORT(void) sub_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)223 void sub_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z) 748 224 /* ----------------------------------------------------------------------------------------------- */ 749 225 { 750 long i, j; 751 rgb8 x, y, z; 752 753 for(i=nrl; i<=nrh; i++) { 754 for(j=ncl; j<=nch; j++) { 755 x = X[i][j]; 756 y = Y[i][j]; 757 RGB8_SUB(x,y,z); 758 Z[i][j] = z; 759 } 760 } 761 } 226 for (int32_t i = nrl; i <= nrh; i++) { 227 for (int32_t j = ncl; j <= nch; j++) { 228 //z = x + y; 229 RGB8_SUB(X[i][j], Y[i][j], Z[i][j]); 230 } 231 } 232 } 233 762 234 /* --------------------------------------------------------------------------------------------------- */ 763 IMAGE_EXPORT(void) sub_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)235 void sub_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z) 764 236 /* --------------------------------------------------------------------------------------------------- */ 765 237 { 766 long i, j; 767 rgbx8 x, y, z; 768 769 for(i=nrl; i<=nrh; i++) { 770 for(j=ncl; j<=nch; j++) { 771 x = X[i][j]; 772 y = Y[i][j]; 773 RGBX8_SUB(x,y,z); 774 Z[i][j] = z; 775 } 776 } 777 } 238 for (int32_t i = nrl; i <= nrh; i++) { 239 for (int32_t j = ncl; j <= nch; j++) { 240 //z = x + y; 241 RGBX8_SUB(X[i][j], Y[i][j], Z[i][j]); 242 } 243 } 244 } 245 778 246 779 247 /* -------------------- */ … … 781 249 /* -------------------- */ 782 250 783 /* ------------------------------------------------------------------------------------------------ */ 784 IMAGE_EXPORT(void) subc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z) 785 /* ------------------------------------------------------------------------------------------------ */ 786 { 787 long i,j; 788 789 for(i=nrl; i<=nrh; i++) { 790 for(j=ncl; j<=nch; j++) { 791 Z[i][j] = X[i][j] - y; 792 } 793 } 794 } 795 /* ------------------------------------------------------------------------------------------------ */ 796 IMAGE_EXPORT(void) subc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z) 797 /* ------------------------------------------------------------------------------------------------ */ 798 { 799 long i,j; 800 801 for(i=nrl; i<=nrh; i++) { 802 for(j=ncl; j<=nch; j++) { 803 Z[i][j] = X[i][j] - y; 804 } 805 } 806 } 807 /* ---------------------------------------------------------------------------------------------------- */ 808 IMAGE_EXPORT(void) subc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z) 809 /* ---------------------------------------------------------------------------------------------------- */ 810 { 811 long i,j; 812 813 for(i=nrl; i<=nrh; i++) { 814 for(j=ncl; j<=nch; j++) { 815 Z[i][j] = X[i][j] - y; 816 } 817 } 818 } 819 /* ---------------------------------------------------------------------------------------------------- */ 820 IMAGE_EXPORT(void) subc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z) 821 /* ---------------------------------------------------------------------------------------------------- */ 822 { 823 long i,j; 824 825 for(i=nrl; i<=nrh; i++) { 826 for(j=ncl; j<=nch; j++) { 827 Z[i][j] = X[i][j] - y; 828 } 829 } 830 } 831 /* ---------------------------------------------------------------------------------------------------- */ 832 IMAGE_EXPORT(void) subc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z) 833 /* ---------------------------------------------------------------------------------------------------- */ 834 { 835 long i,j; 836 837 for(i=nrl; i<=nrh; i++) { 838 for(j=ncl; j<=nch; j++) { 839 Z[i][j] = X[i][j] - y; 840 } 841 } 842 } 843 /* ---------------------------------------------------------------------------------------------------- */ 844 IMAGE_EXPORT(void) subc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z) 845 /* ---------------------------------------------------------------------------------------------------- */ 846 { 847 long i,j; 848 849 for(i=nrl; i<=nrh; i++) { 850 for(j=ncl; j<=nch; j++) { 851 Z[i][j] = X[i][j] - y; 852 } 853 } 854 } 855 /* ---------------------------------------------------------------------------------------------------- */ 856 IMAGE_EXPORT(void) subc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z) 857 /* ---------------------------------------------------------------------------------------------------- */ 858 { 859 long i,j; 860 861 for(i=nrl; i<=nrh; i++) { 862 for(j=ncl; j<=nch; j++) { 863 Z[i][j] = X[i][j] - y; 864 } 865 } 866 } 867 /* ---------------------------------------------------------------------------------------------------- */ 868 IMAGE_EXPORT(void) subc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z) 869 /* ---------------------------------------------------------------------------------------------------- */ 870 { 871 long i,j; 872 873 for(i=nrl; i<=nrh; i++) { 874 for(j=ncl; j<=nch; j++) { 875 Z[i][j] = X[i][j] - y; 876 } 877 } 878 } 879 /* ------------------------------------------------------------------------------------------------------ */ 880 IMAGE_EXPORT(void) subc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z) 881 /* ------------------------------------------------------------------------------------------------------ */ 882 { 883 long i,j; 884 885 for(i=nrl; i<=nrh; i++) { 886 for(j=ncl; j<=nch; j++) { 887 Z[i][j] = X[i][j] - y; 888 } 889 } 890 } 891 /* ------------------------------------------------------------------------------------------------------ */ 892 IMAGE_EXPORT(void) subc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z) 893 /* ------------------------------------------------------------------------------------------------------ */ 894 { 895 long i,j; 896 897 for(i=nrl; i<=nrh; i++) { 898 for(j=ncl; j<=nch; j++) { 899 Z[i][j] = X[i][j] - y; 900 } 901 } 902 } 903 /* ---------------------------------------------------------------------------------------------- */ 904 IMAGE_EXPORT(void) subc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z) 905 /* ---------------------------------------------------------------------------------------------- */ 906 { 907 long i,j; 908 rgb8 x, z; 909 910 for(i=nrl; i<=nrh; i++) { 911 for(j=ncl; j<=nch; j++) { 912 x = X[i][j]; 913 RGB8_SUB(x,y,z); 914 Z[i][j] = z; 915 } 916 } 917 } 918 /* -------------------------------------------------------------------------------------------------- */ 919 IMAGE_EXPORT(void) subc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z) 920 /* -------------------------------------------------------------------------------------------------- */ 921 { 922 long i,j; 923 rgbx8 x, z; 924 925 for(i=nrl; i<=nrh; i++) { 926 for(j=ncl; j<=nch; j++) { 927 x = X[i][j]; 928 RGBX8_SUB(x,y,z); 929 Z[i][j] = z; 930 } 931 } 932 } 251 #undef subc_type_matrix 252 #define subc_type_matrix(t) \ 253 void short_name(t,subc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \ 254 { \ 255 for (int32_t i = nrl; i <= nrh; i++) { \ 256 for (int32_t j = ncl; j <= nch; j++) { \ 257 Z[i][j] = X[i][j] - y; \ 258 } \ 259 } \ 260 } 261 262 subc_type_matrix(int8_t); 263 subc_type_matrix(uint8_t); 264 subc_type_matrix(int16_t); 265 subc_type_matrix(uint16_t); 266 subc_type_matrix(int32_t); 267 subc_type_matrix(uint32_t); 268 subc_type_matrix(int64_t); 269 subc_type_matrix(uint64_t); 270 subc_type_matrix(float); 271 subc_type_matrix(double); 272 273 274 275 /* ---------------------------------------------------------------------------------------------- */ 276 void subc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z) 277 /* ---------------------------------------------------------------------------------------------- */ 278 { 279 for (int32_t i = nrl; i <= nrh; i++) { 280 for (int32_t j = ncl; j <= nch; j++) { 281 RGB8_SUB(X[i][j], y, Z[i][j]); 282 } 283 } 284 } 285 286 /* -------------------------------------------------------------------------------------------------- */ 287 void subc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z) 288 /* -------------------------------------------------------------------------------------------------- */ 289 { 290 for (int32_t i = nrl; i <= nrh; i++) { 291 for (int32_t j = ncl; j <= nch; j++) { 292 RGBX8_SUB(X[i][j], y, Z[i][j]); 293 } 294 } 295 } 296 297 933 298 /* -------------------- */ 934 299 /* --- Mul constant --- */ 935 300 /* -------------------- */ 936 301 937 /* ------------------------------------------------------------------------------------------------ */ 938 IMAGE_EXPORT(void) mulc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z) 939 /* ------------------------------------------------------------------------------------------------ */ 940 { 941 long i,j; 942 943 for(i=nrl; i<=nrh; i++) { 944 for(j=ncl; j<=nch; j++) { 945 Z[i][j] = X[i][j] * y; 946 } 947 } 948 } 949 /* ------------------------------------------------------------------------------------------------ */ 950 IMAGE_EXPORT(void) mulc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z) 951 /* ------------------------------------------------------------------------------------------------ */ 952 { 953 long i,j; 954 955 for(i=nrl; i<=nrh; i++) { 956 for(j=ncl; j<=nch; j++) { 957 Z[i][j] = X[i][j] * y; 958 } 959 } 960 } 961 /* ---------------------------------------------------------------------------------------------------- */ 962 IMAGE_EXPORT(void) mulc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z) 963 /* ---------------------------------------------------------------------------------------------------- */ 964 { 965 long i,j; 966 967 for(i=nrl; i<=nrh; i++) { 968 for(j=ncl; j<=nch; j++) { 969 Z[i][j] = X[i][j] * y; 970 } 971 } 972 } 973 /* ---------------------------------------------------------------------------------------------------- */ 974 IMAGE_EXPORT(void) mulc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z) 975 /* ---------------------------------------------------------------------------------------------------- */ 976 { 977 long i,j; 978 979 for(i=nrl; i<=nrh; i++) { 980 for(j=ncl; j<=nch; j++) { 981 Z[i][j] = X[i][j] * y; 982 } 983 } 984 } 985 /* ---------------------------------------------------------------------------------------------------- */ 986 IMAGE_EXPORT(void) mulc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z) 987 /* ---------------------------------------------------------------------------------------------------- */ 988 { 989 long i,j; 990 991 for(i=nrl; i<=nrh; i++) { 992 for(j=ncl; j<=nch; j++) { 993 Z[i][j] = X[i][j] * y; 994 } 995 } 996 } 997 /* ---------------------------------------------------------------------------------------------------- */ 998 IMAGE_EXPORT(void) mulc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z) 999 /* ---------------------------------------------------------------------------------------------------- */ 1000 { 1001 long i,j; 1002 1003 for(i=nrl; i<=nrh; i++) { 1004 for(j=ncl; j<=nch; j++) { 1005 Z[i][j] = X[i][j] * y; 1006 } 1007 } 1008 } 1009 /* ---------------------------------------------------------------------------------------------------- */ 1010 IMAGE_EXPORT(void) mulc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z) 1011 /* ---------------------------------------------------------------------------------------------------- */ 1012 { 1013 long i,j; 1014 1015 for(i=nrl; i<=nrh; i++) { 1016 for(j=ncl; j<=nch; j++) { 1017 Z[i][j] = X[i][j] * y; 1018 } 1019 } 1020 } 1021 /* ---------------------------------------------------------------------------------------------------- */ 1022 IMAGE_EXPORT(void) mulc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z) 1023 /* ---------------------------------------------------------------------------------------------------- */ 1024 { 1025 long i,j; 1026 1027 for(i=nrl; i<=nrh; i++) { 1028 for(j=ncl; j<=nch; j++) { 1029 Z[i][j] = X[i][j] * y; 1030 } 1031 } 1032 } 1033 /* ------------------------------------------------------------------------------------------------------ */ 1034 IMAGE_EXPORT(void) mulc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z) 1035 /* ------------------------------------------------------------------------------------------------------ */ 1036 { 1037 long i,j; 1038 1039 for(i=nrl; i<=nrh; i++) { 1040 for(j=ncl; j<=nch; j++) { 1041 Z[i][j] = X[i][j] * y; 1042 } 1043 } 1044 } 1045 /* ------------------------------------------------------------------------------------------------------ */ 1046 IMAGE_EXPORT(void) mulc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z) 1047 /* ------------------------------------------------------------------------------------------------------ */ 1048 { 1049 long i,j; 1050 1051 for(i=nrl; i<=nrh; i++) { 1052 for(j=ncl; j<=nch; j++) { 1053 Z[i][j] = X[i][j] * y; 1054 } 1055 } 1056 } 1057 /* ---------------------------------------------------------------------------------------------- */ 1058 IMAGE_EXPORT(void) mulc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z) 1059 /* ---------------------------------------------------------------------------------------------- */ 1060 { 1061 long i,j; 1062 rgb8 x, z; 1063 1064 for(i=nrl; i<=nrh; i++) { 1065 for(j=ncl; j<=nch; j++) { 1066 x = X[i][j]; 1067 RGB8_MUL(x,y,z); 1068 Z[i][j] = z; 1069 } 1070 } 1071 } 1072 /* -------------------------------------------------------------------------------------------------- */ 1073 IMAGE_EXPORT(void) mulc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z) 1074 /* -------------------------------------------------------------------------------------------------- */ 1075 { 1076 long i,j; 1077 rgbx8 x, z; 1078 1079 for(i=nrl; i<=nrh; i++) { 1080 for(j=ncl; j<=nch; j++) { 1081 x = X[i][j]; 1082 RGBX8_MUL(x,y,z); 1083 Z[i][j] = z; 1084 } 1085 } 1086 } 302 #undef mulc_type_matrix 303 #define mulc_type_matrix(t) \ 304 void short_name(t,mulc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \ 305 { \ 306 for (int32_t i = nrl; i <= nrh; i++) { \ 307 for (int32_t j = ncl; j <= nch; j++) { \ 308 Z[i][j] = X[i][j] * y; \ 309 } \ 310 } \ 311 } 312 313 mulc_type_matrix(int8_t); 314 mulc_type_matrix(uint8_t); 315 mulc_type_matrix(int16_t); 316 mulc_type_matrix(uint16_t); 317 mulc_type_matrix(int32_t); 318 mulc_type_matrix(uint32_t); 319 mulc_type_matrix(int64_t); 320 mulc_type_matrix(uint64_t); 321 mulc_type_matrix(float); 322 mulc_type_matrix(double); 323 324 325 326 /* ---------------------------------------------------------------------------------------------- */ 327 void mulc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z) 328 /* ---------------------------------------------------------------------------------------------- */ 329 { 330 for (int32_t i = nrl; i <= nrh; i++) { 331 for (int32_t j = ncl; j <= nch; j++) { 332 RGB8_MUL(X[i][j], y, Z[i][j]); 333 } 334 } 335 } 336 337 /* -------------------------------------------------------------------------------------------------- */ 338 void mulc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z) 339 /* -------------------------------------------------------------------------------------------------- */ 340 { 341 for (int32_t i = nrl; i <= nrh; i++) { 342 for (int32_t j = ncl; j <= nch; j++) { 343 RGBX8_MUL(X[i][j], y, Z[i][j]); 344 } 345 } 346 } 347 348 1087 349 /* --------------- */ 1088 350 /* --- MulFrac --- */ 1089 351 /* --------------- */ 1090 352 1091 // Y=(a*X)/b 1092 1093 /* -------------------------------------------------------------------------------------------------------------- */ 1094 IMAGE_EXPORT(void) mulfrac_si8matrix(sint8 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint8 **Y) 1095 /* -------------------------------------------------------------------------------------------------------------- */ 1096 { 1097 int i, j; 1098 int32 x, y; 1099 1100 for(i=nrl; i<=nrh; i++) { 1101 for(j=ncl; j<=nch; j++) { 1102 x = X[i][j]; 1103 y = (a * x) / b; 1104 Y[i][j] = (sint8) y; 1105 } 1106 } 1107 } 1108 /* -------------------------------------------------------------------------------------------------------------- */ 1109 IMAGE_EXPORT(void) mulfrac_ui8matrix(uint8 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint8 **Y) 1110 /* -------------------------------------------------------------------------------------------------------------- */ 1111 { 1112 int i, j; 1113 int32 x, y; 1114 1115 for(i=nrl; i<=nrh; i++) { 1116 for(j=ncl; j<=nch; j++) { 1117 x = X[i][j]; 1118 y = (a * x) / b; 1119 Y[i][j] = (uint8) y; 1120 } 1121 } 1122 } 353 // Y = (a * X) / b 354 355 #undef mulfrac_type_matrix 356 #define mulfrac_type_matrix(t) \ 357 void short_name(t,mulfrac_,matrix)(t ** X, int32_t nrl, int32_t nrh, \ 358 int32_t ncl, int32_t nch, int32_t a, int32_t b, t ** Y) \ 359 { \ 360 for (int32_t i = nrl; i <= nrh; i++) { \ 361 for (int32_t j = ncl; j <= nch; j++) { \ 362 Y[i][j] = (t) ((a * X[i][j]) / b); \ 363 } \ 364 } \ 365 } 366 367 mulfrac_type_matrix(int8_t); 368 mulfrac_type_matrix(uint8_t); 369 mulfrac_type_matrix(int16_t); 370 mulfrac_type_matrix(uint16_t); 371 mulfrac_type_matrix(int32_t); 372 mulfrac_type_matrix(uint32_t); 373 mulfrac_type_matrix(int64_t); 374 mulfrac_type_matrix(uint64_t); 375 mulfrac_type_matrix(float); 376 mulfrac_type_matrix(double); 377 378 379 /* ------------------------------------------------------------------------------------------------------------ */ 380 void mulfrac_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 a, rgb32 b, rgb8 ** Y) 381 /* ------------------------------------------------------------------------------------------------------------ */ 382 { 383 rgb32 y32; 384 rgb8 x8, y8; 385 for (int32_t i = nrl; i <= nrh; i++) { 386 for (int32_t j = ncl; j <= nch; j++) { 387 x8 = X[i][j]; 388 RGB8_MULFRAC(x8, a, b, y32); 389 RGB32CAST8(y32, y8); 390 Y[i][j] = y8; 391 } 392 } 393 } 394 1123 395 /* ----------------------------------------------------------------------------------------------------------------- */ 1124 IMAGE_EXPORT(void) mulfrac_si16matrix(sint16 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint16 **Y)396 void mulfrac_rgb8xmatrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 b, rgbx8 ** Y) 1125 397 /* ----------------------------------------------------------------------------------------------------------------- */ 1126 398 { 1127 int i, j; 1128 int32 x, y; 1129 1130 for(i=nrl; i<=nrh; i++) { 1131 for(j=ncl; j<=nch; j++) { 1132 x = X[i][j]; 1133 y = (a * x) / b; 1134 Y[i][j] = (sint16) y; 1135 } 1136 } 1137 } 1138 /* ----------------------------------------------------------------------------------------------------------------- */ 1139 IMAGE_EXPORT(void) mulfrac_ui16matrix(uint16 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint16 **Y) 1140 /* ----------------------------------------------------------------------------------------------------------------- */ 1141 { 1142 int i, j; 1143 int32 x, y; 1144 1145 for(i=nrl; i<=nrh; i++) { 1146 for(j=ncl; j<=nch; j++) { 1147 x = X[i][j]; 1148 y = (a * x) / b; 1149 Y[i][j] = (uint16) y; 1150 } 1151 } 1152 } 1153 /* ------------------------------------------------------------------------------------------------------------------ */ 1154 IMAGE_EXPORT(void) mulfrac_si32matrix(sint32 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint32 **Y) 1155 /* ------------------------------------------------------------------------------------------------------------------ */ 1156 { 1157 int i, j; 1158 int32 x, y; 1159 1160 for(i=nrl; i<=nrh; i++) { 1161 for(j=ncl; j<=nch; j++) { 1162 x = X[i][j]; 1163 y = (a * x) / b; 1164 Y[i][j] = (sint16) y; 1165 } 1166 } 1167 } 1168 /* ------------------------------------------------------------------------------------------------------------------ */ 1169 IMAGE_EXPORT(void) mulfrac_ui32matrix(uint32 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint32 **Y) 1170 /* ------------------------------------------------------------------------------------------------------------------ */ 1171 { 1172 int i, j; 1173 int32 x, y; 1174 1175 for(i=nrl; i<=nrh; i++) { 1176 for(j=ncl; j<=nch; j++) { 1177 x = X[i][j]; 1178 y = (a * x) / b; 1179 Y[i][j] = (uint16) y; 1180 } 1181 } 1182 } 1183 /* ----------------------------------------------------------------------------------------------------------------- */ 1184 IMAGE_EXPORT(void) mulfrac_si64matrix(sint64 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint64 **Y) 1185 /* ----------------------------------------------------------------------------------------------------------------- */ 1186 { 1187 int i, j; 1188 sint64 x, y; 1189 1190 for(i=nrl; i<=nrh; i++) { 1191 for(j=ncl; j<=nch; j++) { 1192 x = X[i][j]; 1193 y = (a * x) / b; 1194 Y[i][j] = (sint64) y; 1195 } 1196 } 1197 } 1198 /* ----------------------------------------------------------------------------------------------------------------- */ 1199 IMAGE_EXPORT(void) mulfrac_ui64matrix(uint64 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint64 **Y) 1200 /* ----------------------------------------------------------------------------------------------------------------- */ 1201 { 1202 int i, j; 1203 uint64 x, y; 1204 1205 for(i=nrl; i<=nrh; i++) { 1206 for(j=ncl; j<=nch; j++) { 1207 x = X[i][j]; 1208 y = (a * x) / b; 1209 Y[i][j] = (uint64) y; 1210 } 1211 } 1212 } 1213 /* ------------------------------------------------------------------------------------------------------------ */ 1214 IMAGE_EXPORT(void) mulfrac_rgb8matrix(rgb8 **X, long nrl,long nrh, long ncl, long nch, rgb32 a, rgb32 b, rgb8 **Y) 1215 /* ------------------------------------------------------------------------------------------------------------ */ 1216 { 1217 int i, j; 1218 rgb32 y32; 1219 rgb8 x8, y8; 1220 1221 1222 for(i=nrl; i<=nrh; i++) { 1223 for(j=ncl; j<=nch; j++) { 1224 x8 = X[i][j]; 1225 RGB8_MULFRAC(x8,a,b,y32); 1226 RGB32CAST8(y32,y8); 1227 Y[i][j] = y8; 1228 } 1229 } 1230 } 1231 /* ----------------------------------------------------------------------------------------------------------------- */ 1232 IMAGE_EXPORT(void) mulfrac_rgb8xmatrix(rgbx8 **X, long nrl,long nrh, long ncl, long nch, rgbx32 a, rgbx32 b, rgbx8 **Y) 1233 /* ----------------------------------------------------------------------------------------------------------------- */ 1234 { 1235 int i, j; 1236 rgbx32 y32; 1237 rgbx8 x8, y8; 1238 1239 for(i=nrl; i<=nrh; i++) { 1240 for(j=ncl; j<=nch; j++) { 1241 x8 = X[i][j]; 1242 RGBX8_MULFRAC(x8,a,b,y32); 1243 RGBX32CAST8(y32,y8); 1244 Y[i][j] = y8; 1245 } 1246 } 1247 } 399 rgbx32 y32; 400 rgbx8 x8, y8; 401 for (int32_t i = nrl; i <= nrh; i++) { 402 for (int32_t j = ncl; j <= nch; j++) { 403 x8 = X[i][j]; 404 RGBX8_MULFRAC(x8, a, b, y32); 405 RGBX32CAST8(y32, y8); 406 Y[i][j] = y8; 407 } 408 } 409 } 410 1248 411 1249 412 /* ---------------- */ … … 1251 414 /* ---------------- */ 1252 415 1253 // m3 = (a*m1)>>s 1254 1255 /* -------------------------------------------------------------------------------------------------------------- */ 1256 IMAGE_EXPORT(void) mulshift_si8matrix(sint8 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint8 **Y) 1257 /* -------------------------------------------------------------------------------------------------------------- */ 1258 { 1259 int i, j; 1260 int32 x, y; 1261 1262 for(i=nrl; i<=nrh; i++) { 1263 for(j=ncl; j<=nch; j++) { 1264 x = X[i][j]; 1265 y = (a * x) >> s; 1266 Y[i][j] = (sint8) y; 1267 } 1268 } 1269 } 1270 /* --------------------------------------------------------------------------------------------------------------- */ 1271 IMAGE_EXPORT(void) mulshift_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, uint8 **Y) 1272 /* --------------------------------------------------------------------------------------------------------------- */ 1273 { 1274 int i, j; 1275 int32 x, y; 1276 1277 for(i=nrl; i<=nrh; i++) { 1278 for(j=ncl; j<=nch; j++) { 1279 x = X[i][j]; 1280 y = (a * x) >> s; 1281 Y[i][j] = (uint8) y; 1282 } 1283 } 1284 } 416 // m3 = (a * m1) >> s 417 418 #undef mulshift_type_matrix 419 #define mulshift_type_matrix(t) \ 420 void short_name(t,mulshift_,matrix)(t ** X, int32_t nrl, int32_t nrh, \ 421 int32_t ncl, int32_t nch, int32_t a, int32_t s, t ** Y) \ 422 { \ 423 for (int32_t i = nrl; i <= nrh; i++) { \ 424 for (int32_t j = ncl; j <= nch; j++) { \ 425 Y[i][j] = (t) ((a * X[i][j]) >> s); \ 426 } \ 427 } \ 428 } 429 430 mulshift_type_matrix(int8_t); 431 mulshift_type_matrix(uint8_t); 432 mulshift_type_matrix(int16_t); 433 mulshift_type_matrix(uint16_t); 434 mulshift_type_matrix(int32_t); 435 mulshift_type_matrix(uint32_t); 436 mulshift_type_matrix(int64_t); 437 mulshift_type_matrix(uint64_t); 438 439 440 /* ---------------------------------------------------------------------------------------------------------------- */ 441 void mulshift_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 a, rgb32 s, rgb8 ** Y) 442 /* ---------------------------------------------------------------------------------------------------------------- */ 443 { 444 rgb32 y32; 445 rgb8 x8, y8; 446 for (int32_t i = nrl; i <= nrh; i++) { 447 for (int32_t j = ncl; j <= nch; j++) { 448 x8 = X[i][j]; 449 RGB8_MULSHIFT(x8, a, s, y32); 450 RGB32CAST8(y32, y8); 451 Y[i][j] = y8; 452 } 453 } 454 } 455 1285 456 /* ----------------------------------------------------------------------------------------------------------------- */ 1286 IMAGE_EXPORT(void) mulshift_si16matrix(sint16 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint16 **Y)457 void mulshift_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 s, rgbx8 ** Y) 1287 458 /* ----------------------------------------------------------------------------------------------------------------- */ 1288 459 { 1289 int i, j; 1290 int32 x, y; 1291 1292 for(i=nrl; i<=nrh; i++) { 1293 for(j=ncl; j<=nch; j++) { 1294 x = X[i][j]; 1295 y = (a * x) >> s; 1296 Y[i][j] = (sint16) y; 1297 } 1298 } 1299 } 1300 /* ------------------------------------------------------------------------------------------------------------------ */ 1301 IMAGE_EXPORT(void) mulshift_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, uint16 **Y) 1302 /* ------------------------------------------------------------------------------------------------------------------ */ 1303 { 1304 int i, j; 1305 int32 x, y; 1306 1307 for(i=nrl; i<=nrh; i++) { 1308 for(j=ncl; j<=nch; j++) { 1309 x = X[i][j]; 1310 y = (a * x) >> s; 1311 Y[i][j] = (uint16) y; 1312 } 1313 } 1314 } 1315 /* ----------------------------------------------------------------------------------------------------------------- */ 1316 IMAGE_EXPORT(void) mulshift_si32matrix(sint32 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint32 **Y) 1317 /* ----------------------------------------------------------------------------------------------------------------- */ 1318 { 1319 int i, j; 1320 int32 x, y; 1321 1322 for(i=nrl; i<=nrh; i++) { 1323 for(j=ncl; j<=nch; j++) { 1324 x = X[i][j]; 1325 y = (a * x) >> s; 1326 Y[i][j] = (sint32) y; 1327 } 1328 } 1329 } 1330 /* ------------------------------------------------------------------------------------------------------------------ */ 1331 IMAGE_EXPORT(void) mulshift_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, int32 a, int32 s, uint32 **Y) 1332 /* ------------------------------------------------------------------------------------------------------------------ */ 1333 { 1334 int i, j; 1335 int32 x, y; 1336 1337 for(i=nrl; i<=nrh; i++) { 1338 for(j=ncl; j<=nch; j++) { 1339 x = X[i][j]; 1340 y = (a * x) >> s; 1341 Y[i][j] = (uint32) y; 1342 } 1343 } 1344 } 1345 /* ---------------------------------------------------------------------------------------------------------------- */ 1346 IMAGE_EXPORT(void) mulshift_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb32 a, rgb32 s, rgb8 **Y) 1347 /* ---------------------------------------------------------------------------------------------------------------- */ 1348 { 1349 int i, j; 1350 rgb32 y32; 1351 rgb8 x8, y8; 1352 1353 for(i=nrl; i<=nrh; i++) { 1354 for(j=ncl; j<=nch; j++) { 1355 x8 = X[i][j]; 1356 RGB8_MULSHIFT(x8,a,s,y32); 1357 RGB32CAST8(y32,y8); 1358 Y[i][j] = y8; 1359 } 1360 } 1361 } 1362 /* ----------------------------------------------------------------------------------------------------------------- */ 1363 IMAGE_EXPORT(void) mulshift_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx32 a, rgbx32 s, rgbx8 **Y) 1364 /* ----------------------------------------------------------------------------------------------------------------- */ 1365 { 1366 int i, j; 1367 rgbx32 y32; 1368 rgbx8 x8, y8; 1369 1370 for(i=nrl; i<=nrh; i++) { 1371 for(j=ncl; j<=nch; j++) { 1372 x8 = X[i][j]; 1373 RGBX8_MULSHIFT(x8,a,s,y32); 1374 RGBX32CAST8(y32,y8); 1375 Y[i][j] = y8; 1376 } 1377 } 1378 } 460 rgbx32 y32; 461 rgbx8 x8, y8; 462 for (int32_t i = nrl; i <= nrh; i++) { 463 for (int32_t j = ncl; j <= nch; j++) { 464 x8 = X[i][j]; 465 RGBX8_MULSHIFT(x8, a, s, y32); 466 RGBX32CAST8(y32, y8); 467 Y[i][j] = y8; 468 } 469 } 470 } 471 472 // Local Variables: 473 // tab-width: 4 474 // c-basic-offset: 4 475 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 476 // indent-tabs-mode: nil 477 // End: 478 479 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 480 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2x.c
r772 r821 17 17 #include <malloc.h> 18 18 #include <math.h> // fabs 19 // #include <memory.h> // memcpy20 19 20 #include "nrc_os_config.h" 21 21 #include "mypredef.h" 22 22 #include "nrtype.h" … … 25 25 #include "nrkernel.h" 26 26 27 /* ------------------------------------------------------------------------------------- */ 28 IMAGE_EXPORT(void) addcnz_bmatrix(byte **src,long nrl,long nrh,long ncl, long nch, byte cte, byte **dst) 29 /* ------------------------------------------------------------------------------------- */ 30 { 31 long i,j; 32 byte *Xi, *Yi; 33 34 for(i=nrl; i<=nrh; i++) { 35 Xi = src[i]; 36 Yi = dst[i]; 37 for(j=ncl; j<=nch; j++) { 38 if(Xi[j]) 39 Yi[j] = Xi[j] + cte; 40 else 41 Yi[j] = Xi[j]; 42 } 43 } 27 28 #undef addcnz_type_matrix 29 #define addcnz_type_matrix(t) \ 30 void short_name(t,addcnz_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) \ 31 { \ 32 t * Xi; \ 33 t * Yi; \ 34 for (int32_t i = nrl; i <= nrh; i++) { \ 35 Xi = src[i]; \ 36 Yi = dst[i]; \ 37 for (int32_t j = ncl; j <= nch; j++) { \ 38 if (Xi[j] != 0) { \ 39 Yi[j] = Xi[j] + cte; \ 40 } \ 41 else { \ 42 Yi[j] = Xi[j]; \ 43 } \ 44 } \ 45 } \ 44 46 } 45 /* ----------------------------------------------------------------------------------- */ 46 IMAGE_EXPORT(void) addandc_bmatrix(byte **src,long nrl,long nrh,long ncl, long nch, byte cte, byte **dst) 47 /* ----------------------------------------------------------------------------------- */ 48 { 49 long i,j; 50 byte *Xi, *Yi; 51 52 for(i=nrl; i<=nrh; i++) { 53 Xi = src[i]; 54 Yi = dst[i]; 55 for(j=ncl; j<=nch; j++) { 56 if(Xi[j]) 57 Yi[j] = Xi[j] + cte; 58 else 59 Yi[j] = Xi[i]; 60 } 61 } 47 48 addcnz_type_matrix(int8_t); 49 addcnz_type_matrix(uint8_t); 50 addcnz_type_matrix(int16_t); 51 addcnz_type_matrix(uint16_t); 52 addcnz_type_matrix(int32_t); 53 addcnz_type_matrix(uint32_t); 54 addcnz_type_matrix(int64_t); 55 addcnz_type_matrix(uint64_t); 56 addcnz_type_matrix(float); 57 addcnz_type_matrix(double); 58 59 60 #undef addandc_type_matrix 61 #define addandc_type_matrix(t) \ 62 void short_name(t,addandc_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) \ 63 { \ 64 t * Xi; \ 65 t * Yi; \ 66 for (int32_t i = nrl; i <= nrh; i++) { \ 67 Xi = src[i]; \ 68 Yi = dst[i]; \ 69 for (int32_t j = ncl; j <= nch; j++) { \ 70 if (Xi[j] != 0) { \ 71 Yi[j] = Xi[j] + cte; \ 72 } \ 73 } \ 74 } \ 62 75 } 63 /* ---------------------------------------------------------------------------------------- */ 64 IMAGE_EXPORT(void) addandc_si16matrix(sint16 **src,long nrl,long nrh,long ncl, long nch, short cte, sint16 **dst) 65 /* ---------------------------------------------------------------------------------------- */ 66 { 67 long i,j; 68 sint16 *Xi, *Yi; 69 70 for(i=nrl; i<=nrh; i++) { 71 Xi = src[i]; 72 Yi = dst[i]; 73 for(j=ncl; j<=nch; j++) { 74 if(Xi[j]) Yi[j] = Xi[j] + cte; 75 } 76 } 76 77 addandc_type_matrix(int8_t); 78 addandc_type_matrix(uint8_t); 79 addandc_type_matrix(int16_t); 80 addandc_type_matrix(uint16_t); 81 addandc_type_matrix(int32_t); 82 addandc_type_matrix(uint32_t); 83 addandc_type_matrix(int64_t); 84 addandc_type_matrix(uint64_t); 85 addandc_type_matrix(float); 86 addandc_type_matrix(double); 87 88 89 #undef sum_type_matrix 90 #define sum_type_matrix(t,rt) \ 91 rt short_name(t,sum_,matrix)(t ** m, int32_t nrl, int32_t nrh,int32_t ncl, int32_t nch) \ 92 { \ 93 rt s = 0; \ 94 t * Xi; \ 95 for (int32_t i = nrl; i <= nrh; i++) { \ 96 Xi = m[i]; \ 97 for (int32_t j = ncl; j <= nch; j++) { \ 98 s += Xi[j]; \ 99 } \ 100 } \ 101 return s; \ 77 102 } 78 /* ------------------------------------------------------------------------------------------- */ 79 IMAGE_EXPORT(void) addandc_ui16matrix(uint16 **src,long nrl,long nrh,long ncl, long nch, short cte, uint16 **dst) 80 /* ------------------------------------------------------------------------------------------ */ 81 { 82 long i,j; 83 uint16 *Xi, *Yi; 84 85 for(i=nrl; i<=nrh; i++) { 86 Xi = src[i]; 87 Yi = dst[i]; 88 for(j=ncl; j<=nch; j++) { 89 if(Xi[j]) Yi[j] = Xi[j] + cte; 90 } 91 } 92 } 93 /* ----------------------------------------------------------- */ 94 IMAGE_EXPORT(int) count_bmatrix(byte **m, long nrl,long nrh,long ncl, long nch) 95 /* ----------------------------------------------------------- */ 96 { 97 long i, j; 98 int s = 0; 99 byte *Xi; 100 101 for(i=nrl; i<=nrh; i++) { 102 Xi = m[i]; 103 for(j=ncl; j<=nch; j++) { 104 s += Xi[j]; 105 } 106 } 107 return s; 108 } 103 104 105 sum_type_matrix(int8_t, int32_t); 106 sum_type_matrix(uint8_t, uint32_t); 107 sum_type_matrix(int16_t, int32_t); 108 sum_type_matrix(uint16_t, uint32_t); 109 sum_type_matrix(int32_t, int64_t); 110 sum_type_matrix(uint32_t, uint64_t); 111 sum_type_matrix(int64_t, int64_t); 112 sum_type_matrix(uint64_t, uint64_t); 113 sum_type_matrix(float, float); 114 sum_type_matrix(double, double); 115 116 117 // Local Variables: 118 // tab-width: 4 119 // c-basic-offset: 4 120 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 121 // indent-tabs-mode: nil 122 // End: 123 124 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 125 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2.c
r805 r821 1001 1001 char buffer[80]; 1002 1002 int i; 1003 (void) gris; 1003 1004 1004 1005 // open file 1005 1006 fd = open(filename, O_RDONLY); 1006 1007 if (fd < 0) { 1007 printf("*** Error: Can't open file %s in %s.\n", filename, __func__); 1008 printf("\n*** Error: Can't open file %s in %s.\n", filename, __func__); 1009 exit(1); 1008 1010 } 1009 1011 … … 1046 1048 int i; 1047 1049 1050 //fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT); 1048 1051 fd = open(filename, O_TRUNC | O_CREAT); 1049 1052 if (fd < 0) { 1050 printf("*** Error: Impossible to open file %s in %s\n", filename, __func__); 1053 printf("\n*** Error: Impossible to open file %s in %s\n", filename, __func__); 1054 return; 1051 1055 } 1052 1056 -
soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c
r772 r821 304 304 rgb8 *Si; 305 305 int r, b, g; 306 (void) Si; 306 307 307 308 //FUNCTION_NAME("Histogram_rgbmatrix"); -
soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1x.c
r772 r821 11 11 #include <stdio.h> 12 12 #include <stddef.h> 13 #include <string.h> 13 14 14 15 #include "mypredef.h" -
soft/giet_vm/applications/rosenfeld/nrc2/src/nrwrap2.c
r772 r821 21 21 #include <math.h> // fabs 22 22 23 #include "nrc_os_config.h" 23 24 #include "mypredef.h" 24 25 #include "nrtype.h" -
soft/giet_vm/applications/rosenfeld/rosenfeld.py
r805 r821 40 40 data_size = 0x00010000 # 64 Kbytes (non replicated) 41 41 42 # QM warning: if less than 8M per cluster (i.e. 2M per thread), small pages are required 42 43 stack_base = 0x40000000 43 stack_size = 0x00800000 # 8 Mbytes (per cluster) 44 stack_size = 0x00080000 # 512K (per cluster) => 128K per thread 45 #stack_size = 0x00400000 # 4M (per cluster) => 1M per thread 44 46 45 47 heap_base = 0x60000000 46 heap_size = 0x01000000 # 16 Mbytes (per cluster) 48 #heap_size = 0x00800000 # 8 Mbytes (per cluster) 49 heap_size = 0x10000000 # 256 Mbytes (total) 47 50 48 51 # create vspace … … 80 83 base, size, 'C_WU', vtype = 'BUFFER', 81 84 x = x , y = y , pseg = 'RAM', 82 local = True, big = True )85 local = True, big = False ) 83 86 84 87 # heap vsegs: distributed non local (all heap vsegs can be accessed by all tasks) … … 87 90 cluster_id = (x * y_size) + y 88 91 if (mapping.clusters[cluster_id].procs): 89 size = heap_size 90 base = heap_base + (cluster_id * size) 91 92 nclusters = x_size * y_size 93 if x == 0 and y == 0: 94 size = heap_size / 2 95 base = heap_base 96 else: 97 size = heap_size / (2 * nclusters) 98 base = heap_base + heap_size / 2 + ((y * x_size) + x - 1) * size 92 99 mapping.addVseg(vspace, 'rosen_heap_%d_%d' % (x, y), base, size, 93 94 100 'C_WU', vtype = 'HEAP', x = x, y = y, pseg = 'RAM', 101 local = False, big = True ) 95 102 96 103 # distributed tasks / one task per processor -
soft/giet_vm/applications/rosenfeld/src-par/mca.c
r805 r821 15 15 #include <malloc.h> 16 16 17 #ifdef CLI18 17 #include "nrc_os_config.h" 18 #include "config.h" 19 19 #include "nrc.h" 20 #endif 21 20 21 #if TARGET_OS == GIETVM 22 #include <giet_config.h> 23 #endif 22 24 23 25 #include "util.h" 24 26 #include "ecc_common.h" 27 #include "ecc_features.h" 25 28 #include "mca_matrix_dist.h" 26 29 … … 34 37 35 38 36 // ---------------------- 39 // ----------------------- 37 40 void MCA_Error(char * msg) 38 // ---------------------- 41 // ----------------------- 39 42 { 40 43 printf("MCA ERROR: %s\n", msg); 41 44 printf("now exiting to system...\n"); 42 exit(1); 43 } 44 45 46 // --------------------- 47 void MCA_Zero(MCA * mca) 48 // --------------------- 49 { 45 exit(1); 50 46 } 51 47 … … 58 54 mca = (MCA *) malloc(sizeof(MCA)); 59 55 60 if (mca) { 61 MCA_Zero(mca); 62 } 63 else { 56 if (mca == NULL) { 64 57 MCA_Error("allocation failed in MCA_pConstructor_Empty"); 65 58 } … … 91 84 92 85 mca->j0 = 0; 93 mca->j1 = width -1;86 mca->j1 = width - 1; 94 87 } 95 88 … … 102 95 103 96 mca->i0 = 0; 104 mca->i1 = height -1;97 mca->i1 = height - 1; 105 98 } 106 99 … … 161 154 int j0_par, j1_par; 162 155 int height_par, height_mod; 163 156 164 157 int pw2; 165 158 int32 ne_par; // quantite par bande 166 159 uint32 nemax_par; // la puissance de 2 >= 167 160 uint32 e0_par, e1_par; // indice par bande [start..end] 161 int nb_level; 168 162 169 163 MCA ** mcas; 170 164 MCA * mca_par; 171 165 172 MCA_VERBOSE1(printf("====================\n")); 173 MCA_VERBOSE1(printf("== MCA_Initialize ==\n")); 174 MCA_VERBOSE1(printf("====================\n")); 175 176 MCA_VERBOSE1(printf("height = %d\n", height)); 177 MCA_VERBOSE1(printf("width = %d\n", width)); 166 printf("*** %s ***\n", __func__); 167 MCA_VERBOSE1(printf(" height = %d\n", height)); 168 MCA_VERBOSE1(printf(" width = %d\n", width)); 178 169 179 170 // array of pointers to mca workers … … 187 178 height_par = height / np; 188 179 height_mod = height % np; 189 //if(height % np) height_par++; 190 MCA_VERBOSE1(printf("height_par = %d x %d + %d\n", height_par, np, height_mod)); 191 192 MCA_VERBOSE1(printf("========================\n")); 180 181 MCA_VERBOSE1(printf(" height_par = %d x %d + %d\n", height_par, np, height_mod)); 182 MCA_VERBOSE1(printf(" ========================\n")); 193 183 194 184 i1_par_previous = 0; 195 196 for (int p = 0; p < np; p++) { 185 186 // puissance de 2 de chaque bande 187 ne_par = height_par * width + 1; 188 MCA_VERBOSE1(printf(" ne_par = %d\n", ne_par)); 189 pw2 = i32log2(ne_par); 190 if (ne_par > (1 << pw2)) { 191 pw2++; 192 } 193 nemax_par = 1 << pw2; 194 195 MCA_VERBOSE1(printf(" nemax_par = %d\n", nemax_par)); 196 197 nb_level = i32log2(np); 198 if ((1 << nb_level) < np) { 199 nb_level++; 200 } 201 202 #if PYR_BARRIERS 203 // ------------------------------------------ 204 // -- Allocation des barriÚres pyramidales -- 205 // ------------------------------------------ 206 207 pthread_barrier_t * barriers = NULL; 208 if (nb_level > 0) { 209 barriers = malloc(sizeof(pthread_barrier_t) * nb_level); 210 211 // Initially all threads are active except thread 0 212 int nb_active = np - 1; 213 pthread_barrier_init(&barriers[0], NULL, nb_active); 214 for (int i = 1; i < nb_level; i++) { 215 // thread 0 never does any merge 216 for (int p = 1; p < np; p++) { 217 if ((p + (1 << (i - 1))) % (1 << i) == 0) { 218 // thread inactive at level i 219 nb_active -= 1; 220 } 221 } 222 pthread_barrier_init(&barriers[i], NULL, nb_active); 223 } 224 } 225 #endif 226 227 for (int p = 0; p < np; p++) { 228 197 229 // ----------------- // 198 230 // -- constructor -- // 199 231 // ----------------- // 200 MCA_VERBOSE 1(printf("-- p = %d ----------------\n", p));232 MCA_VERBOSE2(printf("-- p = %d ----------------\n", p)); 201 233 202 234 // alloc of mca workers into array of pointers … … 208 240 mca_par->p = p; 209 241 mca_par->mca = mca; // pointer to master 242 #if TARGET_OS == GIETVM 243 int x, y; // cluster coordinates 244 // We have p == 4 => x = 0; y = 1 245 x = (p / NB_PROCS_MAX) / Y_SIZE; 246 y = (p / NB_PROCS_MAX) % Y_SIZE; 247 MCA_VERBOSE2(printf("p = %d (x = %d, y = %d)\n", p, x, y)); 248 #endif 210 249 211 250 // ------------------------------------- // … … 214 253 215 254 // hauteur de chaque bande 216 217 //printf("i1_par_previous = %d\n", i1_par_previous);218 219 255 if (p == 0) { 220 256 i0_par = 0; … … 232 268 i1_par_previous = i1_par; 233 269 234 MCA_VERBOSE1(printf("i0_par = %d\n", i0_par)); 235 MCA_VERBOSE1(printf("i1_par = %d\n", i1_par)); 236 237 // puissance de 2 de chaque bande 238 ne_par = height_par * width + 1; 239 //if (p == 0) { 240 // ne_par++; 241 //} 242 MCA_VERBOSE1(printf("ne_par = %d\n", ne_par)); 243 pw2 = i32log2(ne_par); 244 if (ne_par > (1 << pw2)) { 245 pw2++; 246 } 247 nemax_par = 1 << pw2; 248 MCA_VERBOSE1(printf("nemax_par = %d\n", nemax_par)); 270 MCA_VERBOSE2(printf("i0_par = %d\n", i0_par)); 271 MCA_VERBOSE2(printf("i1_par = %d\n", i1_par)); 249 272 250 273 // etiquettes … … 260 283 MCA_VERBOSE2(printf("e0_par = %d\n", e0_par)); 261 284 MCA_VERBOSE2(printf("e1_par = %d\n", e1_par)); 262 285 263 286 mca_par->width = width; 264 287 mca_par->height = height_par; 265 266 288 mca_par->i0 = i0_par; 267 289 mca_par->i1 = i1_par; 268 290 mca_par->j0 = 0; 269 291 mca_par->j1 = width - 1; 270 271 292 mca_par->e0 = e0_par; 272 293 mca_par->e1 = e1_par; 273 274 294 mca_par->alpha = pw2; 295 mca_par->np = np; 296 // Pour les barriÚres pyramidales 297 mca_par->nb_level = nb_level; 298 #if PYR_BARRIERS 299 mca_par->barriers = barriers; 300 #else 301 mca_par->barriers = NULL; 302 #endif 303 mca_par->F = NULL; // default init 304 mca_par->stats = NULL; // default init 275 305 276 306 // ---------------- // 277 307 // -- allocation -- // 278 308 // ---------------- // 279 309 #if TARGET_OS == GIETVM 310 mca_par->X = remote_ui8matrix(i0_par, i1_par, 0, width - 1, x, y); 311 mca_par->E = remote_dist_ui32matrix(i0_par, i1_par, 0, width - 1, x, y); // distributed matrix with border 312 313 if (p == 0) { 314 mca_par->T = remote_ui32vector(e0_par - 1, e1_par, x, y); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 315 #if FEATURES 316 mca_par->stats = remote_RegionStatsVector(e0_par - 1, e1_par, x, y); 317 #endif 318 } 319 else { 320 mca_par->T = remote_ui32vector(e0_par, e1_par, x, y); 321 #if FEATURES 322 mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y); 323 #endif 324 } 325 326 mca_par->D = (uint32 **) remote_vvector(0, np - 1, x, y); 327 #if FEATURES 328 mca_par->F = (RegionStats **) remote_vvector(0, np - 1, x, y); 329 #endif 330 #else // !GIETVM 280 331 mca_par->X = ui8matrix (i0_par, i1_par, 0, width - 1); 281 332 mca_par->E = dist_ui32matrix(i0_par, i1_par, 0, width - 1); // distributed matrix with border … … 283 334 if (p == 0) { 284 335 mca_par->T = ui32vector(e0_par - 1, e1_par); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 336 #if FEATURES 337 mca_par->stats = RegionStatsVector(e0_par - 1, e1_par); 338 339 #endif 285 340 } 286 341 else { 287 342 mca_par->T = ui32vector(e0_par, e1_par); 343 #if FEATURES 344 mca_par->stats = RegionStatsVector(e0_par, e1_par); 345 #endif 288 346 } 289 347 290 348 mca_par->D = (uint32 **) vvector(0, np - 1); 291 349 #if FEATURES 350 mca_par->F = (RegionStats **) vvector(0, np - 1); 351 #endif 352 #endif 292 353 MCA_VERBOSE2(printf("X = %p\n", mca_par->X)); 293 354 MCA_VERBOSE2(printf("E = %p\n", mca_par->E)); 294 355 MCA_VERBOSE2(printf("T = %p\n", mca_par->T)); 295 356 MCA_VERBOSE2(printf("D = %p\n", mca_par->D)); 296 297 357 } // p 298 358 299 // pour debug 300 MCA_VERBOSE2(printf("init des tables d'EQ a l'identite\n")); 301 for (int p = 0; p < np; p++) { 302 359 360 for (int p = 0; p < np; p++) { 303 361 MCA * mca_par = mcas[p]; 304 362 … … 319 377 MCA_VERBOSE2(printf("display des tables d'EQ\n")); 320 378 for (int p = 0; p < np; p++) { 321 322 379 MCA * mca_par = mcas[p]; 323 380 … … 326 383 uint32 e1 = mca_par->e1; 327 384 328 MCA_VERBOSE 1(printf("p = %d T[%d..%d]\n", p, e0, e1));385 MCA_VERBOSE2(printf("p = %d T[%d..%d]\n", p, e0, e1)); 329 386 if (p == 0) { 330 MCA_VERBOSE 1(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));331 } 332 else { 333 MCA_VERBOSE 1(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));387 MCA_VERBOSE2(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T")); 388 } 389 else { 390 MCA_VERBOSE2(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T")); 334 391 } 335 392 MCA_VERBOSE2(printf("\n")); … … 343 400 // table d'indirection distribuee D 344 401 MCA_VERBOSE2(printf("nemax_par = %d\n", nemax_par)); 345 346 for (int p = 0; p < np; p++) { 347 402 for (int p = 0; p < np; p++) { 348 403 MCA * mca_p = mcas[p]; 349 404 uint32 ** D = mca_p->D; 405 RegionStats ** F = mca_p->F; 350 406 351 407 for (int k = 0; k < np; k++) { 352 //mcas[p]->D[k] = (void*) (&(mcas[k]->T[mcas[k]->e0])) - mcas[k]->e0; //k * nemax_par;353 354 408 MCA * mca_k = mcas[k]; 355 409 uint32 * T = mca_k->T; 356 357 410 D[k] = T + k * nemax_par; // il faut soustraire le "MSB" 411 #if FEATURES 412 RegionStats * stat = mca_k->stats; 413 F[k] = stat + k * nemax_par; // il faut soustraire le "MSB" 414 #endif 358 415 } // k 359 416 } // p … … 376 433 MCA_VERBOSE2(display_ui32vector(D[k], 0, 9, "%5d", "D\n")); 377 434 } 378 printf("\n");435 MCA_VERBOSE2(printf("\n")); 379 436 } 380 437 … … 413 470 // ----------------------------------- 414 471 { 415 int p,np = mca->np;472 int np = mca->np; 416 473 417 474 MCA ** mcas = mca->mcas; 418 475 MCA * mca_par; 419 420 printf("============================\n"); 421 printf("== MCA_Display_Parameters ==\n"); 422 printf("============================\n"); 423 424 printf("height = %d\n", mca->height); 425 printf("width = %d\n", mca->width); 426 printf("np = %d\n", mca->np); 427 428 for (p = 0; p < np; p++) { 476 (void) mca_par; 477 478 printf("*** MCA_Display_Parameters ***\n"); 479 480 MCA_VERBOSE1(printf(" height = %d\n", mca->height)); 481 MCA_VERBOSE1(printf(" width = %d\n", mca->width)); 482 MCA_VERBOSE1(printf(" np = %d\n", mca->np)); 483 484 for (int p = 0; p < np; p++) { 429 485 mca_par = mcas[p]; 430 486 431 printf("Display MCA[%d]\n", p);432 printf("p = %d\n", mca_par->p);433 printf("i0 = %8d i1 = %8d\n", mca_par->i0, mca_par->i1);434 printf("j0 = %8d j1 = %8d\n", mca_par->j0, mca_par->j1);435 printf("e0 = %8d e1 = %8d\n", mca_par->e0, mca_par->e1);487 MCA_VERBOSE2(printf("Display MCA[%d]\n", p)); 488 MCA_VERBOSE2(printf("p = %d\n", mca_par->p)); 489 MCA_VERBOSE2(printf("i0 = %8d i1 = %8d\n", mca_par->i0, mca_par->i1)); 490 MCA_VERBOSE2(printf("j0 = %8d j1 = %8d\n", mca_par->j0, mca_par->j1)); 491 MCA_VERBOSE2(printf("e0 = %8d e1 = %8d\n", mca_par->e0, mca_par->e1)); 436 492 } 437 493 } … … 442 498 // ------------------------- 443 499 { 444 int p,np = mca->np;500 int np = mca->np; 445 501 446 502 MCA ** mcas = mca->mcas; … … 451 507 uint32 e0, e1; 452 508 453 printf("==================\n"); 454 printf("== MCA_Finalize ==\n"); 455 printf("==================\n"); 456 457 for (p = 0; p < np; p++) { 458 509 printf("*** MCA_Finalize ***\n"); 510 511 #if PYR_BARRIERS 512 free(mcas[0]->barriers); 513 #endif 514 515 for (int p = 0; p < np; p++) { 459 516 mca_par = mcas[p]; 460 517 … … 475 532 if (p == 0) { 476 533 free_ui32vector(mca_par->T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 534 #if FEATURES 535 free_RegionStatsVector(mca_par->stats, e0 - 1, e1); 536 #endif 477 537 } 478 538 else { 479 539 free_ui32vector(mca_par->T, e0, e1); 540 #if FEATURES 541 free_RegionStatsVector(mca_par->stats, e0, e1); 542 #endif 480 543 } 481 544 482 545 free_vvector((void **) mca_par->D, 0, np - 1); 483 484 } 485 printf("[MCA_Finalize]: fin boucle\n"); 546 #if FEATURES 547 free_vvector((void **) mca_par->F, 0, np - 1); 548 #endif 549 free(mca_par); 550 } 486 551 free(mcas); 487 printf("[MCA_Finalize]: mcas freed\n"); 488 free(mca); // plante si free XET, ne plante pas si pas de free ... 489 printf("[MCA_Finalize]: mca freed\n"); 490 } 491 492 493 // @QM check my modifs... 552 free(mca); 553 } 554 555 494 556 // ------------------------------- 495 557 void MCA_Scatter_ImageX(MCA * mca) … … 498 560 // diffusion de l'image binaire source 499 561 500 int 562 int np = mca->np; 501 563 uint8 ** X = mca->mca->X; 502 564 503 565 if (mca->p == 0) { 504 MCA_VERBOSE1(printf("------------------------\n")); 505 MCA_VERBOSE1(printf("-- MCA_Scatter_ImageX --\n")); 506 MCA_VERBOSE1(printf("------------------------\n")); 566 printf("*** MCA_Scatter_ImageX ***\n"); 507 567 } 508 568 … … 524 584 525 585 526 // @QM check my modifs...527 586 // ------------------------------ 528 587 void MCA_Gather_ImageL(MCA * mca) … … 532 591 int np = mca->np; 533 592 uint32 ** E = mca->mca->E; 593 594 if (mca->p == 0) { 595 printf("*** MCA_Gather_ImageL ***\n"); 596 } 534 597 535 598 int i0 = mca->i0; -
soft/giet_vm/applications/rosenfeld/src-par/mca_main.c
r805 r821 1 1 /* ------------------ */ 2 /* --- mca .c --- */2 /* --- mca_main.c --- */ 3 3 /* ------------------ */ 4 4 … … 12 12 #include <string.h> 13 13 #include <math.h> 14 15 #include <user_lock.h> 16 17 #ifdef CLI 14 #include <malloc.h> 15 18 16 #include "nrc_os_config.h" 17 #include "config.h" 19 18 #include "nrc.h" 20 #endif 21 19 20 #if TARGET_OS == GIETVM 21 #include <user_lock.h> 22 #include <malloc.h> 23 #include <giet_config.h> 24 #include <user_barrier.h> 25 #else 26 #include <unistd.h> 27 #endif 22 28 23 29 #include "util.h" 24 30 #include "ecc_common.h" 25 31 #include "ecc_features.h" 26 27 32 #include "palette.h" 28 33 #include "bmpNR.h" 29 34 #include "mca_matrix_dist.h" 35 #include "mca_rosenfeld.h" 36 #include "clock.h" 30 37 #include "str_ext.h" 38 31 39 32 40 /* -- local -- */ 33 41 #include "mca.h" 34 #include "mca_test.h" 35 36 42 43 #define MAX_THREADS 256 44 #define DEFAULT_NTHREADS 1 45 #define DEFAULT_IN_FILENAME "/misc/cadastre.pgm" 46 #define DEFAULT_OUT_FILENAME "out.bmp" 47 48 pthread_t thread_table[MAX_THREADS]; 49 pthread_barrier_t main_barrier; 50 int display_features = 0; 51 int generate_output_image = 0; 52 53 CLOCK_DEC; 54 55 static void usage(char * name) { 56 printf("Usage: %s <options>\n", name); 57 printf("options:\n"); 58 printf(" -i <input_file> : Input file (default = %s)\n", DEFAULT_IN_FILENAME); 59 printf(" -o <output_file> : Output file (default = %s)\n", DEFAULT_OUT_FILENAME); 60 printf(" -nN : N = number of threads (default = %d).\n", DEFAULT_NTHREADS); 61 printf(" -d : Display features (default = false, requires features computation).\n"); 62 printf(" -g : Generate output image (default = false).\n"); 63 printf(" -h : Print out command line options.\n\n"); 64 } 65 66 67 68 // -------------------------------------------------------------------------- 69 void init_forme_boulon1(uint8 *** X0, int * i0, int * i1, int * j0, int * j1) 70 // -------------------------------------------------------------------------- 71 { 72 uint8 ** X; 73 int i = 0; 74 int h = 28; 75 int w = 30; 76 77 X = ui8matrix(0, h - 1, 0, w - 1); 78 zero_ui8matrix(X, 0, h - 1, 0, w - 1); 79 80 *X0 = X; 81 *i0 = 0; 82 *i1 = h - 1; 83 *j0 = 0; 84 *j1 = w - 1; 85 86 // 0000000001111111111122222222223 87 // 0123456789012345678901234567890 88 set_ui8vector_str(X[i++], 0, w - 1, " 111 "); // 00 89 set_ui8vector_str(X[i++], 0, w - 1, " 11111 "); // 01 90 set_ui8vector_str(X[i++], 0, w - 1, " 1111111 "); // 02 91 set_ui8vector_str(X[i++], 0, w - 1, " 11111111 "); // 03 92 set_ui8vector_str(X[i++], 0, w - 1, " 1111111111"); // 04 93 set_ui8vector_str(X[i++], 0, w - 1, " 11111111111"); // 05 94 set_ui8vector_str(X[i++], 0, w - 1, " 1111111111111"); // 06 95 set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111 "); // 07 96 set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111 "); // 08 97 set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111 "); // 09 98 set_ui8vector_str(X[i++], 0, w - 1, " 11 11111111111111 "); // 10 99 set_ui8vector_str(X[i++], 0, w - 1, " 111 11111111111111 "); // 11 100 set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111111111 "); // 12 101 set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111111111 "); // 13 102 set_ui8vector_str(X[i++], 0, w - 1, "1111111111111111111 "); // 14 103 set_ui8vector_str(X[i++], 0, w - 1, " 11111111111111111 "); // 15 104 set_ui8vector_str(X[i++], 0, w - 1, " 1111111111111111 "); // 16 105 set_ui8vector_str(X[i++], 0, w - 1, " 111111111111111 "); // 17 106 set_ui8vector_str(X[i++], 0, w - 1, " 111111111111 "); // 18 107 set_ui8vector_str(X[i++], 0, w - 1, " 1111111111 "); // 29 108 set_ui8vector_str(X[i++], 0, w - 1, " 1111111111 "); // 20 109 set_ui8vector_str(X[i++], 0, w - 1, " 111111111 "); // 21 110 set_ui8vector_str(X[i++], 0, w - 1, " 111111111 "); // 22 111 set_ui8vector_str(X[i++], 0, w - 1, " 11111111 "); // 23 112 set_ui8vector_str(X[i++], 0, w - 1, " 1111111 "); // 24 113 set_ui8vector_str(X[i++], 0, w - 1, " 11111 "); // 25 114 set_ui8vector_str(X[i++], 0, w - 1, " 111 "); // 26 115 set_ui8vector_str(X[i++], 0, w - 1, " "); // 27 116 117 //printf("[init_forme_boulon1]: h = %d i = %d\n", h, i); 118 if (i != h) { 119 MCA_Error("init_forme_boulon1 i != h"); 120 } 121 122 123 //display_ui8matrix_positive(X, 0, h-1, 0, w-1, 4, "forme_boulon1"); printf(""); 124 //write_ui8matrix_positive( X, 0, h-1, 0, w-1, 4, "forme_boulon1.txt"); 125 } 126 127 128 // QM : The cost of this function is horrible 129 // but it is only for testing purpose 130 // Renumbers object in a contiguous way, for an image which has already 131 // been processed with several threads 132 // -------------------------------------------------------------------- 133 static void renumber_image(uint32 ** E, int i0, int i1, int j0, int j1) 134 // -------------------------------------------------------------------- 135 { 136 int size = 10; 137 int idx = 1; // next label to give, first invalid index in the equiv table 138 uint32 * equiv = malloc(sizeof(uint32) * size); 139 equiv[0] = 0; // unused 140 int found; 141 142 for (int i = i0; i <= i1; i++) { 143 for (int j = j0; j <= j1; j++) { 144 if (E[i][j] != 0) { 145 found = 0; 146 for (int k = 1; k < idx; k++) { 147 if (equiv[k] == E[i][j]) { 148 E[i][j] = k; 149 found = 1; 150 break; 151 } 152 } 153 if (found == 0) { 154 equiv[idx] = E[i][j]; 155 E[i][j] = idx; 156 idx += 1; 157 if (idx == size) { 158 size = size * 2; 159 equiv = realloc(equiv, sizeof(uint32) * size); 160 } 161 } 162 } 163 } 164 } 165 free(equiv); 166 } 167 168 169 // ---------------------------- 170 void mca_test1(int num_threads) 171 // ---------------------------- 172 { 173 int i0, i1, j0, j1; 174 int height, width; 175 176 uint8 ** X0; 177 uint32 ** E; 178 MCA * mca; 179 180 pthread_barrier_init(&main_barrier, NULL, num_threads); 181 182 // -- Allocation -- 183 init_forme_boulon1(&X0, &i0, &i1, &j0, &j1); 184 185 height = i1 - i0 + 1; 186 width = j1 - j0 + 1; 187 188 E = ui32matrix(i0, i1, j0, j1); 189 190 zero_ui32matrix(E, i0, i1, j0, j1); 191 192 mca = MCA_pConstructor_Empty(); 193 194 // -- set param 195 MCA_Set_Size(mca, width, height); 196 MCA_Set_ImageX(mca, X0); 197 MCA_Set_ImageL(mca, E); 198 MCA_Set_NP(mca, num_threads); 199 200 // -- MCA init 201 MCA_Initialize(mca); 202 MCA_Display_Parameters(mca); 203 204 display_ui8matrix_positive(mca->X, i0, i1, j0, j1, 5, "X0"); 205 #if FEATURES 206 for (int i = 1; i < num_threads; i++) { 207 pthread_create(&thread_table[i], NULL, MCA_Label_Features_Rosenfeld, (void *) mca->mcas[i]); 208 } 209 MCA_Label_Features_Rosenfeld(mca->mcas[0]); 210 #else 211 for (int i = 1; i < num_threads; i++) { 212 pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]); 213 } 214 MCA_Label_Rosenfeld(mca->mcas[0]); 215 #endif 216 for (int i = 1; i < num_threads; i++) { 217 pthread_join(thread_table[i], NULL); 218 } 219 display_ui32matrix_positive(mca->E, i0, i1, j0, j1, 5, "Efinal"); 220 221 222 // -- free -- 223 printf("Finalize\n"); 224 MCA_Finalize(mca); 225 226 printf("Free_matrix\n"); 227 free_ui8matrix (X0, i0, i1, j0, j1); 228 free_ui32matrix(E, i0, i1, j0, j1); 229 } 230 231 232 233 // ----------------------------------------------------------- 234 void mca_test2(int num_threads, char * infile, char * outfile) 235 // ----------------------------------------------------------- 236 { 237 int i0, i1, j0, j1; 238 int height, width; 239 240 uint8 ** X; 241 uint8 ** E8; 242 uint32 ** E; 243 MCA * mca; 244 245 RGBQuad palette[256]; 246 247 pthread_barrier_init(&main_barrier, NULL, num_threads); 248 249 Palette_18ColorsBW(palette); 250 251 printf("Loading file %s... ", infile); 252 X = LoadPGM_ui8matrix(infile, &i0, &i1, &j0, &j1); 253 printf("done.\n"); 254 255 printf("Allocating memory... "); 256 height = i1 - i0 + 1; 257 width = j1 - j0 + 1; 258 259 E8 = ui8matrix (i0, i1, j0, j1); 260 E = ui32matrix(i0, i1, j0, j1); 261 262 zero_ui8matrix(E8, i0, i1, j0, j1); 263 zero_ui32matrix(E, i0, i1, j0, j1); 264 265 // pre-traitements 266 binarisation_ui8matrix(X, i0, i1, j0, j1, 20, 1, X); // pour le traitement 267 printf("done.\n"); 268 269 printf("Allocating and initializing MCA... \n"); 270 mca = MCA_pConstructor_Empty(); 271 272 // -- set param 273 MCA_Set_Size(mca, width, height); 274 MCA_Set_ImageX(mca, X); 275 MCA_Set_ImageL(mca, E); 276 MCA_Set_NP(mca, num_threads); 277 278 // -- MCA init 279 MCA_Initialize(mca); 280 MCA_Display_Parameters(mca); 281 printf("End of MCA allocation and initialization.\n"); 282 283 CLOCK_APP_CREATE; 284 #if FEATURES 285 for (int i = 1; i < num_threads; i++) { 286 pthread_create(&thread_table[i], NULL, MCA_Label_Features_Rosenfeld, (void *) mca->mcas[i]); 287 } 288 MCA_Label_Features_Rosenfeld(mca->mcas[0]); 289 #else 290 for (int i = 1; i < num_threads; i++) { 291 pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]); 292 } 293 MCA_Label_Rosenfeld(mca->mcas[0]); 294 #endif 295 for (int i = 1; i < num_threads; i++) { 296 pthread_join(thread_table[i], NULL); 297 } 298 CLOCK_APP_JOIN; 299 300 if (generate_output_image) { 301 #if TARGET_OS != GIETVM 302 renumber_image(mca->E, i0, i1, j0, j1); 303 #else 304 printf("Warning: the output image has not been renumbered, it cannot be used as a comparison with the reference\n"); 305 #endif 306 mod_ui32matrix_ui8matrix(mca->E, i0, i1, j0, j1, E8); 307 printf("Saving file %s for verification... ", outfile); 308 SaveBMP2_ui8matrix(E8, width, height, palette, outfile); 309 printf("done.\n"); 310 } 311 312 MCA_Finalize(mca); 313 printf("Deallocating memory..."); 314 free_ui8matrix (X, i0, i1, j0, j1); 315 free_ui8matrix (E8, i0, i1, j0, j1); 316 free_ui32matrix(E, i0, i1, j0, j1); 317 printf("done.\n"); 318 } 319 320 321 // -------------------------------------------------------------- 322 int main_test_mca(int num_threads, char * infile, char * outfile) 323 // -------------------------------------------------------------- 324 { 325 CLOCK_INIT(num_threads, 4); // 4 = Number of steps in body 326 CLOCK_APP_START; 327 328 mca_test2(num_threads, infile, outfile); 329 330 CLOCK_APP_END; 331 CLOCK_FINALIZE; 332 PRINT_CLOCK; 333 CLOCK_FREE; 334 335 return 0; 336 } 337 338 339 #if TARGET_OS == GIETVM 340 // ------------------------------------ 341 __attribute__((constructor)) int main() 342 // ------------------------------------ 343 #else 37 344 // ----------------------------- 38 __attribute__((constructor)) void main()345 int main(int argc, char ** argv) 39 346 // ----------------------------- 40 { 347 #endif 348 { 349 char * infile = DEFAULT_IN_FILENAME; 350 char * outfile = DEFAULT_OUT_FILENAME; 351 352 int ch; 353 int num_threads = DEFAULT_NTHREADS; 354 355 printf("*** Starting application Rosenfeld ***\n"); 356 357 #if TARGET_OS != GIETVM // @QM I think the giet has some random (uninitialized) values for argc and argv 358 while ((ch = getopt(argc, argv, "i:o:n:hdg")) != EOF) { 359 switch (ch) { 360 case 'i': 361 infile = optarg; 362 break; 363 case 'o': 364 outfile = optarg; 365 break; 366 case 'n': 367 num_threads = atoi(optarg); 368 break; 369 case 'h': 370 usage(argv[0]); 371 return 0; 372 break; 373 case 'd': 374 #if !FEATURES 375 fprintf(stderr, "*** Error: Features display requires features computation\n"); 376 return 1; 377 #endif 378 display_features = 1; 379 break; 380 case 'g': 381 generate_output_image = 1; 382 break; 383 default: 384 usage(argv[0]); 385 return 1; 386 break; 387 } 388 } 389 390 // Check arguments 391 if (num_threads < 1) { 392 fprintf(stderr, "*** Error: The number of threads must at least be 1\n"); 393 usage(argv[0]); 394 return -1; 395 } 396 #endif 397 398 #if TARGET_OS == GIETVM 399 { 400 unsigned int xsize, ysize, nprocs; 401 giet_procs_number(&xsize, &ysize, &nprocs); 402 num_threads = xsize * ysize * nprocs; 403 } 404 #endif 405 406 if (num_threads > MAX_THREADS) { 407 printf("*** Error: The maximum number of threads is %d, i.e. less than the current number of threads.\n", MAX_THREADS); 408 printf("Please recompile with a bigger MAX_THREADS value.\n"); 409 exit(1); 410 } 411 412 printf("Parameters:\n"); 413 printf("- Number of threads: %d\n", num_threads); 414 printf("- Input file: %s\n", infile); 415 printf("- Output file: %s\n", outfile); 416 #if FAST 417 printf("- Using decision trees (fast): yes\n"); 418 #elif SLOW 419 printf("- Using decision trees (fast): no\n"); 420 #endif 421 #if FEATURES 422 printf("- Computing features: yes\n"); 423 #else 424 printf("- Computing features: no\n"); 425 #endif 426 427 41 428 #if TARGET_OS == GIETVM 42 429 giet_tty_alloc(1); 43 heap_init(0, 0); 44 #endif 45 lock_init(&print_lock); 46 main_test_mca(); 47 48 exit(0); 49 } 50 430 printf("Initializing heaps... "); 431 for (int i = 0; i < X_SIZE; i++) { 432 for (int j = 0; j < X_SIZE; j++) { 433 heap_init(i, j); 434 } 435 } 436 printf("done.\n"); 437 #endif 438 439 pthread_mutex_init(&print_lock, PTHREAD_PROCESS_PRIVATE); 440 main_test_mca(num_threads, infile, outfile); 441 442 return 0; 443 } 444 -
soft/giet_vm/applications/rosenfeld/src-par/mca_matrix_dist.c
r805 r821 14 14 #include <malloc.h> 15 15 16 #ifdef CLI17 16 #include "nrc_os_config.h" 18 17 #include "nrc.h" 19 #endif20 18 21 19 … … 61 59 } 62 60 61 #if TARGET_OS == GIETVM 62 // --------------------------------------------------------------------------- 63 uint32 ** remote_dist_ui32matrix(int i0, int i1, int j0, int j1, int x, int y) 64 // --------------------------------------------------------------------------- 65 { 66 int i; 67 int nrow = i1 - i0 + 1; 68 int ncol = j1 - j0 + 1; 69 uint32 ** m; 70 71 // allocate pointers to rows 72 m = (uint32 **) remote_malloc((nrow + 2) * sizeof(uint32 *), x, y); 73 if (!m) { 74 nrerror("allocation failure 1 in dist_ui32matrix()"); 75 } 76 m -= i0; 77 m += 1; 78 79 // allocate rows and set pointers to them 80 m[i0] = (uint32 *) remote_malloc((nrow * ncol + 1) * sizeof(uint32), x, y); 81 if (!m[i0]) { 82 nrerror("allocation failure 2 in dist_ui32matrix()"); 83 } 84 m[i0] -= j0; 85 86 for (i = i0 + 1; i <= i1; i++) { 87 m[i] = m[i - 1] + ncol; 88 } 89 90 // make borders to point to first and last lines 91 m[i0 - 1] = m[i0]; 92 m[i1 + 1] = m[i1]; 93 94 return m; 95 } 96 #endif 97 98 63 99 64 100 // ------------------------------------------------------------------- … … 66 102 // ------------------------------------------------------------------- 67 103 { 68 free( (FREE_ARG) (m[i0] + j0));69 free( (FREE_ARG) (m + i0 - 1));104 free(m[i0] + j0); 105 free(m + i0 - 1); 70 106 } 71 107 -
soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c
r805 r821 12 12 #include <string.h> 13 13 #include <math.h> 14 #include <user_barrier.h> 15 #include <user_lock.h> 16 17 #ifdef CLI 14 #include <assert.h> 15 #if PARMERGE 16 #include <pthread.h> 17 #endif 18 18 19 #include "nrc_os_config.h" 20 #include "config.h" 19 21 #include "nrc.h" 22 23 #if TARGET_OS == GIETVM 24 #include <user_barrier.h> 25 #include <user_lock.h> 26 #include <giet_config.h> 27 #else 28 #include <stdbool.h> 20 29 #endif 30 21 31 22 32 #include "util.h" 23 33 #include "ecc_common.h" 24 25 34 #include "palette.h" 26 35 #include "bmpNR.h" 27 36 #include "clock.h" 28 37 #include "str_ext.h" 38 #include "ecc_features.h" 29 39 30 40 // ----------- … … 34 44 #include "mca.h" 35 45 36 extern giet_barrier_t main_barrier; 37 38 // ---------------------------------- 39 uint32 FindRoot(uint32 * T, uint32 e) 40 // ---------------------------------- 46 extern pthread_barrier_t main_barrier; 47 extern int display_features; 48 49 CLOCK_DEC; 50 51 52 // ----------------------------------------- 53 static uint32 FindRoot(uint32 * T, uint32 e) 54 // ----------------------------------------- 41 55 { 42 56 uint32 r; 43 57 58 assert(e != 0); 44 59 r = e; 45 60 while (T[r] < r) { 46 61 r = T[r]; 47 62 } 63 if (r == 0) { 64 printf("e = %d\n",e); 65 assert(0); 66 } 48 67 return r; 49 68 } 50 69 51 70 52 // --------------------------------------------------- 53 uint32 FindRoot_Dist(uint32 ** D, uint32 r, int shift)54 // --------------------------------------------------- 71 // ---------------------------------------------------------- 72 static uint32 FindRoot_Dist(uint32 ** D, uint32 r, int shift) 73 // ---------------------------------------------------------- 55 74 { 56 75 uint32 e; 57 76 uint32 e1; 58 77 uint32 e0; 78 79 assert(r != 0); 59 80 60 81 int mask = (1 << shift) - 1; 61 82 62 MCA_VERBOSE2(printf(" FindRoot_Dist(%d) (alpha = %d) \n", r, shift));83 MCA_VERBOSE2(printf("%s(%d, %d) \n", __func__, r, shift)); 63 84 do { 64 85 e = r; … … 66 87 e0 = r & mask; 67 88 r = D[e1][e0]; 68 MCA_VERBOSE2(printf(" FindRoot: D(%d) = D[%d,%d] = %d (alpha = %d)\n", e, e1, e0, r, shift));89 MCA_VERBOSE2(printf("%s: D(%d) = D[%d,%d] = %d (alpha = %d)\n", __func__, e, e1, e0, r, shift)); 69 90 } while (r < e); 70 MCA_VERBOSE2(printf("FindRoot_Dist = %d \n\n", r)); 91 MCA_VERBOSE2(printf("%s = %d \n\n", __func__, r)); 92 assert(r != 0); 71 93 return r; 72 94 } 73 95 74 96 75 // ----------------------------------------- 76 void SetRoot(uint32 * T, uint32 e, uint32 r) 77 // ----------------------------------------- 78 { 79 while (T[e] < e) { 80 e = T[e]; 81 } 82 T[e] = r; 83 } 84 85 86 // ---------------------------------------------------------- 87 void SetRoot_Dist(uint32 ** D, uint32 e, uint32 r, int shift) 88 // ---------------------------------------------------------- 97 #if !FEATURES 98 // -------------------------------------------------------------------------------- 99 static void SetRoot_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift) 100 // -------------------------------------------------------------------------------- 89 101 { 90 102 int mask = (1 << shift) - 1; 91 92 uint32 e1 = e >> shift; 93 uint32 e0 = e & mask; 94 95 D[e1][e0] = r; 96 } 97 98 99 // -------------------------------------------- 100 uint32 Union0(uint32 * T, uint32 ei, uint32 ej) 101 // -------------------------------------------- 102 { 103 // version de la publication 104 // @QM : faut-il tester le cas == 0 ici aussi ? 105 uint32 ri, rj; 106 ri = (ei == 0) ? 0 : FindRoot(T, ei); 107 if (ei != ej) { 108 rj = (ej == 0) ? 0 : FindRoot(T, ej); 109 if (ri > rj) { 110 ri = rj; 111 } 112 SetRoot(T, ej, ri); 113 } 114 SetRoot(T, ei, ri); 115 return ri; 116 } 117 118 119 // ------------------------------------------------- 120 uint32 QuickUnion2(uint32 * T, uint32 e1, uint32 e2) 121 // ------------------------------------------------- 103 assert(root != 0 && eps != 0); 104 105 uint32 r1 = root >> shift; 106 uint32 r0 = root & mask; 107 108 D[r1][r0] = eps; 109 } 110 #endif // !FEATURES 111 112 113 #if FEATURES && !PARMERGE 114 // ---------------------------------------------------------------------------------------------------- 115 void SetRoot_Features_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F) 116 // ---------------------------------------------------------------------------------------------------- 117 { 118 assert(root != 0 && eps != 0); 119 120 MCA_VERBOSE2(printf("F(%d) += F(%d)\n", eps, root)); 121 122 int mask = (1 << shift) - 1; 123 124 // SetRoot_Rosenfeld_Dist 125 uint32 r1 = root >> shift; 126 uint32 r0 = root & mask; 127 128 D[r1][r0] = eps; 129 130 uint32 e1 = eps >> shift; 131 uint32 e0 = eps & mask; 132 133 // version Dist de "RegionStats_Accumulate_Stats1_From_Index" 134 135 // F(eps) = F(eps) U F(root) 136 137 F[e1][e0].xmin = ui16min2(F[e1][e0].xmin, F[r1][r0].xmin); 138 F[e1][e0].xmax = ui16max2(F[e1][e0].xmax, F[r1][r0].xmax); 139 F[e1][e0].ymin = ui16min2(F[e1][e0].ymin, F[r1][r0].ymin); 140 F[e1][e0].ymax = ui16max2(F[e1][e0].ymax, F[r1][r0].ymax); 141 142 F[e1][e0].S += F[r1][r0].S; 143 F[e1][e0].Sx += F[r1][r0].Sx; 144 F[e1][e0].Sy += F[r1][r0].Sy; 145 } 146 #endif // FEATURES && !PARMERGE 147 148 149 #if FEATURES && PARMERGE 150 // ------------------------------------------------------------------------------------------------------------- 151 bool SetRoot_Parallel_Features_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F) 152 // ------------------------------------------------------------------------------------------------------------- 153 { 154 assert(root != 0 && eps != 0); 155 156 MCA_VERBOSE2(printf("F(%d) += F(%d)\n", eps, root)); 157 158 int mask = (1 << shift) - 1; 159 160 // SetRoot_Rosenfeld_Dist 161 uint32 r1 = root >> shift; 162 uint32 r0 = root & mask; 163 164 uint32 e1 = eps >> shift; 165 uint32 e0 = eps & mask; 166 167 // Locking towards the root (first root, then eps) 168 pthread_spin_lock(&F[r1][r0].lock); 169 pthread_spin_lock(&F[e1][e0].lock); 170 // FIXME: merge these conditions later, when they both appear 171 if (D[e1][e0] != eps) { 172 // Someone change the root of epsilon, need to find the new root 173 printf("race cond 1\n"); 174 pthread_spin_unlock(&F[e1][e0].lock); 175 pthread_spin_unlock(&F[r1][r0].lock); 176 return false; 177 } 178 if (D[r1][r0] != root) { 179 // Someone change the root of epsilon, need to find the new root 180 printf("race cond 2\n"); 181 pthread_spin_unlock(&F[e1][e0].lock); 182 pthread_spin_unlock(&F[r1][r0].lock); 183 return false; 184 } 185 186 D[r1][r0] = eps; 187 188 // F(eps) = F(eps) U F(root) 189 F[e1][e0].xmin = ui16min2(F[e1][e0].xmin, F[r1][r0].xmin); 190 F[e1][e0].xmax = ui16max2(F[e1][e0].xmax, F[r1][r0].xmax); 191 F[e1][e0].ymin = ui16min2(F[e1][e0].ymin, F[r1][r0].ymin); 192 F[e1][e0].ymax = ui16max2(F[e1][e0].ymax, F[r1][r0].ymax); 193 194 F[e1][e0].S += F[r1][r0].S; 195 F[e1][e0].Sx += F[r1][r0].Sx; 196 F[e1][e0].Sy += F[r1][r0].Sy; 197 198 pthread_spin_unlock(&F[e1][e0].lock); 199 pthread_spin_unlock(&F[r1][r0].lock); 200 return true; 201 } 202 #endif // FEATURES && PARMERGE 203 204 205 206 #if FAST 207 // -------------------------------------------------------- 208 static uint32 QuickUnion2(uint32 * T, uint32 e1, uint32 e2) 209 // -------------------------------------------------------- 122 210 { 123 211 // version QU de Union2 124 uint32 r1, r2, r; 125 126 r1 = (e1 == 0) ? 0 : FindRoot(T, e1); 127 r2 = (e2 == 0) ? 0 : FindRoot(T, e2); 128 129 r = ui32Min2(r1, r2); 130 131 if (r1 != r) { 132 T[r1] = r; // SetRoot 133 } 134 if (r2 != r) { 135 T[r2] = r; // SetRoot 136 } 137 138 return r; 139 } 140 141 142 // -------------------------------------------- 143 uint32 use1_QU_Rosenfeld(uint32 e1, uint32 * T) 144 // -------------------------------------------- 145 { 146 return T[e1]; 147 } 148 149 150 // ------------------------------------------------------- 151 uint32 use2_QU_Rosenfeld(uint32 e1, uint32 e2, uint32 * T) 152 // ------------------------------------------------------- 212 uint32 r1 = FindRoot(T, e1); 213 uint32 r2 = FindRoot(T, e2); 214 215 assert(e1 != 0 && e2 != 0 && r1 != 0 && r2 != 0); 216 uint32 eps = ui32Min2(r1, r2); 217 218 if (r1 > eps) { 219 T[r1] = eps; // SetRoot sans besoin de remonter 220 } 221 if (r2 > eps) { 222 T[r2] = eps; // SetRoot sans besoin de remonter 223 } 224 assert(e1 != 0 && e2 != 0 && r1 != 0 && r2 != 0); 225 226 return eps; 227 } 228 #endif // FAST 229 230 231 #if FAST 232 // --------------------------------------------------- 233 static uint32 use1_QU_Rosenfeld(uint32 e1, uint32 * T) 234 // --------------------------------------------------- 235 { 236 return FindRoot(T, e1); 237 } 238 #endif // FAST 239 240 241 #if FAST 242 // -------------------------------------------------------------- 243 static uint32 use2_QU_Rosenfeld(uint32 e1, uint32 e2, uint32 * T) 244 // -------------------------------------------------------------- 153 245 { 154 246 return QuickUnion2(T, e1, e2); 155 247 } 156 157 158 // ---------------------------------------------------------------- 159 uint32 updateTable_Rosenfeld(uint32 * T, uint32 e, uint32 epsilon) 160 // ---------------------------------------------------------------- 161 { 162 // notations e == v, epsilon == u avec v > u (v forcement different de u) 163 return Union0(T, e, epsilon); // original 164 } 165 166 167 // ---------------------------------------------------------------- 168 void vuse2_Rosenfeld(uint32 e1, uint32 e2, uint32 * T, uint32 ** D) 169 // ---------------------------------------------------------------- 170 { 171 uint32 e; 172 uint32 a1; 173 uint32 a2; 174 175 a1 = (e1 == 0) ? 0 : FindRoot(T, e1); 176 a2 = (e2 == 0) ? 0 : FindRoot(T, e2); 177 178 if (a1 == a2) { 248 #endif // FAST 249 250 251 #if FAST && !FEATURES 252 // --------------------------------------------------------------------------------------- 253 static void vuse2_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha) 254 // --------------------------------------------------------------------------------------- 255 { 256 uint32 rd = FindRoot_Dist(D, ed, alpha); 257 258 uint32 rl = T[el]; // car le premier acces est local 259 rl = FindRoot_Dist(D, rl, alpha); 260 261 assert(ed != 0 && el != 0 && rd != 0 && rl != 0); 262 if (rd == rl) { 179 263 return; // evite la backdoor 180 264 } 181 265 182 // forcement positifs car appel depuis optimizedBorder qui a fait un test183 if (a1 < a2) {184 e = a1;185 updateTable_Rosenfeld(T, a2, e);266 // forcement positifs car appel depuis optimizedBorder 267 // qui a fait un test 268 if (rd < rl) { 269 SetRoot_Rosenfeld_Dist(D, rl, rd, alpha); 186 270 } 187 271 else { 188 e = a2; 189 updateTable_Rosenfeld(T, a1, e); 190 } 191 } 192 193 194 // --------------------------------------------------------------------------- 195 void vuse3_Rosenfeld(uint32 e1, uint32 e2, uint32 e3, uint32 * T, uint32 ** D) 196 // --------------------------------------------------------------------------- 197 { 198 uint32 e; 199 uint32 a1; 200 uint32 a2; 201 uint32 a3; 202 203 a1 = (e1 == 0) ? 0 : FindRoot(T, e1); 204 a2 = (e2 == 0) ? 0 : FindRoot(T, e2); 205 a3 = (e3 == 0) ? 0 : FindRoot(T, e3); 206 207 if (a1 == a2 && a2 == a3) { 272 SetRoot_Rosenfeld_Dist(D, rd, rl, alpha); 273 } 274 } 275 #endif // FAST && !FEATURES 276 277 278 #if FAST && !FEATURES 279 // ----------------------------------------------------------------------------------------------------- 280 static void vuse3_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha) 281 // ----------------------------------------------------------------------------------------------------- 282 { 283 uint32 r1 = FindRoot_Dist(D, ed1, alpha); 284 uint32 r2 = FindRoot_Dist(D, ed2, alpha); 285 286 // QM 287 //uint32 r3 = FindRoot(T, el3); // local - distant 288 uint32 r3 = T[el3]; // local - distant 289 r3 = FindRoot_Dist(D, r3, alpha); 290 291 assert(ed1 != 0 && ed2 != 0 && el3 != 0 && r1 != 0 && r2 != 0 && r3 != 0); 292 293 if (r1 == r2 && r2 == r3) { 208 294 return; 209 295 } 210 296 211 e = ui32Min3(a1, a2, a3); // forcement positifs car appel depuis optimizedBorder qui a fait un test 212 213 if (a1 > e) { 214 updateTable_Rosenfeld(T, a1, e); 215 } 216 a2 = T[a2]; 217 if (a2 > e) { 218 updateTable_Rosenfeld(T, a2, e); 219 } 220 a3 = T[a3]; 221 if (a3 > e) { 222 updateTable_Rosenfeld(T, a3, e); 223 } 224 } 225 226 227 // ---------------------------------------------- 228 uint32 solveTable_Rosenfeld(uint32 * T, uint32 ne) 229 // ---------------------------------------------- 230 { 231 // equivalent a Flatten 232 // fermeture transitive sans pack 233 // (presence de trous dans les numeros d'etiquettes) 234 235 uint32 e; 236 237 for (e = 1; e <= ne; e++) { 238 T[e] = T[T[e]]; 239 } 240 return ne; 241 } 242 243 244 // ---------------------------------------------------------------------------------- 245 uint32 optimizedAccess_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne) 246 // ---------------------------------------------------------------------------------- 247 { 248 // Decision Tree 8-connexe avec Quick-Union 249 uint32 a, b, c, d, e; 250 251 b = E[i - 1][j]; 252 if (b) { 253 e = use1_QU_Rosenfeld(b, T); 297 uint32 eps = ui32Min3(r1, r2, r3); // forcement positifs car appel depuis optimizedBorder qui a fait un test 298 299 if (r1 > eps) { 300 SetRoot_Rosenfeld_Dist(D, r1, eps, alpha); 301 } 302 //r2 = T[r2]; // @QM est-ce indispensable s'il n'y a pas de features ? (cf. slow no features) 303 // comment est-on sur que r2 (ou r3) est local ??? 304 if (r2 > eps) { 305 SetRoot_Rosenfeld_Dist(D, r2, eps, alpha); 306 } 307 //r3 = T[r3]; 308 if (r3 > eps) { 309 SetRoot_Rosenfeld_Dist(D, r3, eps, alpha); 310 } 311 } 312 #endif // FAST && !FEATURES 313 314 315 #if FAST && FEATURES && !PARMERGE 316 // ----------------------------------------------------------------------------------------------------------- 317 void vuse2_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 318 // ----------------------------------------------------------------------------------------------------------- 319 { 320 assert(ed != 0 && el != 0); 321 322 uint32 rd = FindRoot_Dist(D, ed, alpha); 323 324 uint32 rl = T[el]; // car le premier acces est local 325 assert(rl != 0); 326 rl = FindRoot_Dist(D, rl, alpha); 327 328 assert(rd != 0 && rl != 0); 329 330 if (rd == rl) { 331 return; // evite la backdoor 332 } 333 334 // forcement positifs car appel depuis optimizedBorder 335 // qui a fait un test 336 if (rd < rl) { 337 SetRoot_Features_Rosenfeld_Dist(D, rl, rd, alpha, F); 254 338 } 255 339 else { 256 c = E[i - 1][j + 1]; 257 if (c) { 258 a = E[i - 1][j - 1]; 340 SetRoot_Features_Rosenfeld_Dist(D, rd, rl, alpha, F); 341 } 342 } 343 #endif // FAST && FEATURES && !PARMERGE 344 345 346 #if FAST && FEATURES && !PARMERGE 347 // ------------------------------------------------------------------------------------------------------------------------- 348 void vuse3_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 349 // ------------------------------------------------------------------------------------------------------------------------- 350 { 351 assert(ed1 != 0 && ed2 != 0 && el3 != 0); 352 353 uint32 r1 = FindRoot_Dist(D, ed1, alpha); 354 uint32 r2 = FindRoot_Dist(D, ed2, alpha); 355 356 //uint32 r3 = FindRoot(T, el3); // local - distant 357 uint32 r3 = T[el3]; // local - distant 358 assert(r3 != 0); 359 r3 = FindRoot_Dist(D, r3, alpha); 360 361 assert(r1 != 0 && r2 != 0 && r3 != 0); 362 363 if (r1 == r2 && r2 == r3) { 364 return; 365 } 366 367 uint32 eps = ui32Min3(r1, r2, r3); // forcement positifs car appel depuis optimizedBorder qui a fait un test 368 369 if (r1 > eps) { 370 SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F); 371 } 372 //r2 = T[r2]; 373 if (r2 > eps && r2 != r1) { 374 SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F); 375 } 376 //r3 = T[r3]; 377 if (r3 > eps && r3 != r2 && r3 != r1) { 378 SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F); 379 } 380 } 381 #endif // FAST && FEATURES && !PARMERGE 382 383 384 #if FAST && FEATURES && PARMERGE 385 // -------------------------------------------------------------------------------------------------------------------- 386 void vuse2_Parallel_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 387 // -------------------------------------------------------------------------------------------------------------------- 388 { 389 bool ok; 390 assert(ed != 0 && el != 0); 391 uint32 rl = T[el]; // car le premier acces est local 392 assert(rl != 0); 393 394 uint32 rd; 395 396 do { 397 rd = FindRoot_Dist(D, ed, alpha); // no lock 398 rl = FindRoot_Dist(D, rl, alpha); 399 400 assert(rd != 0 && rl != 0); 401 402 if (rd == rl) { 403 return; // evite la backdoor 404 } 405 406 // forcement positifs car appel depuis optimizedBorder 407 // qui a fait un test 408 if (rd < rl) { 409 ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rl, rd, alpha, F); 410 } 411 else { 412 ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rd, rl, alpha, F); 413 } 414 } while (!ok); 415 } 416 #endif // FAST && FEATURES && PARMERGE 417 418 419 #if FAST && FEATURES && PARMERGE 420 // ---------------------------------------------------------------------------------------------------------------------------------- 421 void vuse3_Parallel_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 422 // ---------------------------------------------------------------------------------------------------------------------------------- 423 { 424 bool ok1, ok2, ok3; 425 assert(ed1 != 0 && ed2 != 0 && el3 != 0); 426 427 uint32 r1; 428 uint32 r2; 429 uint32 r3 = T[el3]; // local - distant 430 assert(r3 != 0); 431 432 do { 433 r1 = FindRoot_Dist(D, ed1, alpha); 434 r2 = FindRoot_Dist(D, ed2, alpha); 435 r3 = FindRoot_Dist(D, r3, alpha); 436 437 assert(r1 != 0 && r2 != 0 && r3 != 0); 438 439 if (r1 == r2 && r2 == r3) { 440 return; 441 } 442 443 uint32 eps = ui32Min3(r1, r2, r3); // forcement positifs car appel depuis optimizedBorder qui a fait un test 444 445 ok1 = true; 446 ok2 = true; 447 ok3 = true; 448 if (r1 > eps) { 449 ok1 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r1, eps, alpha, F); 450 } 451 if (r2 > eps && r2 != r1) { 452 ok2 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r2, eps, alpha, F); 453 } 454 if (r3 > eps && r3 != r2 && r3 != r1) { 455 ok3 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r3, eps, alpha, F); 456 } 457 } while (!(ok1 && ok2 && ok3)); 458 } 459 #endif // FAST && FEATURES && PARMERGE 460 461 462 463 464 #if FAST && !FEATURES 465 // ------------------------------------------------------------------------------------------------------ 466 static void optimizedBorder_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha) 467 // ------------------------------------------------------------------------------------------------------ 468 { 469 uint32 a, b, c, x; 470 471 x = E[i][j]; 472 if (x) { 473 b = E[i - 1][j]; 474 if (b) { 475 vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local 476 } 477 else { 478 c = E[i - 1][j + 1]; 479 if (c) { 480 a = E[i - 1][j - 1]; 481 if (a) { 482 vuse3_Rosenfeld_Dist(a, c, x, T, D, alpha); // dist, local 483 } 484 else { 485 vuse2_Rosenfeld_Dist(c, x, T, D, alpha); // dist, local 486 } 487 } 488 else { 489 a = E[i - 1][j - 1]; 490 if (a) { 491 vuse2_Rosenfeld_Dist(a, x, T, D, alpha); // dist, local 492 } 493 } 494 } 495 } 496 } 497 #endif // FAST && !FEATURES 498 499 500 #if FAST && !FEATURES 501 // --------------------------------------------------------------------------------------------------- 502 static void optimizedBorderLeft_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha) 503 // --------------------------------------------------------------------------------------------------- 504 { 505 uint32 x = E[i][j]; 506 if (x) { 507 uint32 b = E[i - 1][j]; 508 if (b) { 509 vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local 510 } 511 else { 512 uint32 c = E[i - 1][j + 1]; 513 if (c) { 514 vuse2_Rosenfeld_Dist(c, x, T, D, alpha); // dist, local 515 } 516 } 517 } 518 } 519 #endif // FAST && !FEATURES 520 521 522 #if FAST && !FEATURES 523 // ----------------------------------------------------------------------------------------------------------- 524 static void optimizedBorderRight_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha) 525 // ----------------------------------------------------------------------------------------------------------- 526 { 527 // copie de optimizedBorder_Rosenfeld 528 // test d'existance de ex en local local 529 530 uint32 b = E[i - 1][j]; 531 uint32 x = E[i][j]; 532 533 if (x) { 534 if (b) { 535 vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local 536 } 537 else { 538 uint32 a = E[i - 1][j - 1]; 259 539 if (a) { 260 e = use2_QU_Rosenfeld(a, c, T); 261 } 262 else { 263 d = E[i][j - 1]; 264 if (d) { 265 e = use2_QU_Rosenfeld(c, d, T); 266 } 267 else { 268 e = use1_QU_Rosenfeld(c, T); 269 } 270 } 271 } 272 else { 273 a = E[i - 1][j - 1]; 274 if (a) { 275 e = use1_QU_Rosenfeld(a, T); 276 } 277 else { 278 d = E[i][j - 1]; 279 if (d) { 280 e = use1_QU_Rosenfeld(d, T); 281 } 282 else { 283 e = ++ne; 284 } 285 } 286 } 287 } 288 E[i][j] = e; 289 return ne; 290 } 291 292 293 // ------------------------------------------------------------------------------------------ 294 void optimizedBorder_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha) 295 // ------------------------------------------------------------------------------------------ 296 { 297 // copie de optimizedBorder_Rosenfeld 298 uint32 a, b, c, x; 299 300 b = E[i - 1][j]; 301 x = E[i][j]; 302 303 if (b) { 304 //printf("%d = %d\n", b, x); 305 vuse2_Rosenfeld(b, x, T, D); 306 } 307 else { 308 c = E[i - 1][j + 1]; 309 if (c) { 310 a = E[i - 1][j - 1]; 311 if (a) { 312 //printf("%d = %d = %d\n", a, c, x); 313 vuse3_Rosenfeld(a, c, x, T, D); 314 } 315 else { 316 //printf("%d = %d\n", c, x); 317 vuse2_Rosenfeld(c, x, T, D); 318 } 319 } 320 else { 321 a = E[i - 1][j - 1]; 322 if (a) { 323 //printf("%d = %d\n", a, x); 324 vuse2_Rosenfeld(a, x, T, D); 325 } 326 } 327 } 328 } 329 330 331 // ----------------------------------------------------------------------------------------------------------------- 332 void borderMerging_Fast_Rosenfeld_Dist(uint8 **X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha) 333 // ----------------------------------------------------------------------------------------------------------------- 334 { 335 for (int j = 0; j < width; j++) { 336 if (X[i][j]) { 337 optimizedBorder_Rosenfeld(E, i, j, T, D, alpha); 338 } 339 } 340 return; 341 } 342 343 344 // ------------------------------------------------------------------------------------------------------------------ 345 void borderMerging_Slow_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha) 346 // ------------------------------------------------------------------------------------------------------------------ 347 { 348 // copie de borderMerging_Rosenfeld_UF_Fast2_8C 349 540 vuse2_Rosenfeld_Dist(a, x, T, D, alpha); // dist, local 541 } 542 } 543 } 544 } 545 #endif // FAST && !FEATURES 546 547 548 #if FAST && !FEATURES 549 // ------------------------------------------------------------------------------------------------------------------------ 550 static void borderMerging_Fast_Rosenfeld_Dist(uint8 **X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha) 551 // ------------------------------------------------------------------------------------------------------------------------ 552 { 553 // Prologue 554 optimizedBorderLeft_Rosenfeld_Dist(E, i, 0, T, D, alpha); 555 // Boucle principale 556 for (int j = 1; j < width - 1; j++) { 557 optimizedBorder_Rosenfeld_Dist(E, i, j, T, D, alpha); 558 } 559 // Epilogue 560 optimizedBorderRight_Rosenfeld_Dist(E, i, width - 1, T, D, alpha); 561 } 562 #endif // FAST && !FEATURES 563 564 565 #if SLOW && !FEATURES 566 // ------------------------------------------------------------------------------------------------------------------------- 567 static void borderMerging_Slow_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha) 568 // ------------------------------------------------------------------------------------------------------------------------- 569 { 350 570 int j; 351 571 352 uint32 e; 353 572 uint32 eps; 354 573 uint32 e1, e2, e3, ex; 355 574 uint32 r1, r2, r3, rx; … … 358 577 // -- prologue -- 359 578 // -------------- 360 MCA_VERBOSE2(printf("[ borderMerging_Slow_Rosenfeld_Dist] i = %d\n", i));579 MCA_VERBOSE2(printf("[%s] i = %d\n", __func__, i)); 361 580 362 581 j = 0; … … 365 584 if (ex) { 366 585 367 MCA_VERBOSE2(printf("[ borderMerging_Slow_Rosenfeld_Dist] j = %d\n", j));586 MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j)); 368 587 369 588 e2 = E[i - 1][j]; 370 589 e3 = E[i - 1][j + 1]; 371 372 r2 = FindRoot_Dist(D, e2, alpha); 373 r3 = FindRoot_Dist(D, e3, alpha); 374 rx = FindRoot(T, ex); // we already tested that ex != 0 375 590 591 // test pour eviter acces distant 592 r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0; 593 r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0; 594 595 rx = T[ex]; 596 rx = FindRoot_Dist(D, rx, alpha); 597 376 598 MCA_VERBOSE2(printf("\n")); 377 599 MCA_VERBOSE2(printf("e2 = %4d -> %4d\n", e2, r2)); … … 379 601 MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx)); 380 602 381 e = ui32MinNonNul3(r2, r3, rx);603 eps = ui32MinNonNul3(r2, r3, rx); 382 604 383 605 // Quick-Union 384 if (r2 > e ) {385 SetRoot_ Dist(D, r2, e, alpha);386 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, e ));387 } 388 if (r3 > e ) {389 SetRoot_ Dist(D, r3, e, alpha);390 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, e ));391 } 392 if (rx > e ) {393 SetRoot (T, rx, e);394 MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, e ));606 if (r2 > eps) { 607 SetRoot_Rosenfeld_Dist(D, r2, eps, alpha); 608 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps)); 609 } 610 if (r3 > eps) { 611 SetRoot_Rosenfeld_Dist(D, r3, eps, alpha); 612 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, eps)); 613 } 614 if (rx > eps) { 615 SetRoot_Rosenfeld_Dist(D, rx, eps, alpha); 616 MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps)); 395 617 } 396 618 MCA_VERBOSE2(printf("\n")); 397 // attention SetRoot fait un while inutile398 619 } 399 620 … … 408 629 // que le cas general (pour faire un code simple) 409 630 if (ex) { 410 MCA_VERBOSE2(printf("[ borderMerging_Slow_Rosenfeld_Dist] j = %d\n", j));631 MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j)); 411 632 412 633 e1 = E[i - 1][j - 1]; … … 414 635 e3 = E[i - 1][j + 1]; 415 636 416 r1 = FindRoot_Dist(D, e1, alpha); 417 r2 = FindRoot_Dist(D, e2, alpha); 418 r3 = FindRoot_Dist(D, e3, alpha); 419 rx = FindRoot(T, ex); // we already tested that ex != 0 420 637 // test pour eviter acces distant 638 r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0; 639 r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0; 640 r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0; 641 642 rx = T[ex]; 643 rx = FindRoot_Dist(D, rx, alpha); 644 421 645 MCA_VERBOSE2(printf("\n")); 422 646 MCA_VERBOSE2(printf("e1 = %4d -> %4d\n", e1, r1)); … … 425 649 MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx)); 426 650 427 e = ui32MinNonNul4(r1, r2, r3, rx);651 eps = ui32MinNonNul4(r1, r2, r3, rx); 428 652 429 653 // Quick-Union 430 if (r1 > e) { 431 SetRoot_Dist(D, r1, e, alpha); 432 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, e)); 433 } 434 if (r2 > e) { 435 SetRoot_Dist(D, r2, e, alpha); 436 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, e)); 437 } 438 if (r3 > e) { 439 SetRoot_Dist(D, r3, e, alpha); 440 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, e)); 441 } 442 if (rx > e) { 443 // @QM pourquoi pas T[e] = rx; ? 444 //SetRoot(T, rx, e); 445 T[e] = rx; 446 MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, e)); 654 if (r1 > eps) { 655 SetRoot_Rosenfeld_Dist(D, r1, eps, alpha); 656 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, eps)); 657 } 658 if (r2 > eps) { 659 SetRoot_Rosenfeld_Dist(D, r2, eps, alpha); 660 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps)); 661 } 662 if (r3 > eps) { 663 SetRoot_Rosenfeld_Dist(D, r3, eps, alpha); 664 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, eps)); 665 } 666 if (rx > eps) { 667 SetRoot_Rosenfeld_Dist(D, rx, eps, alpha); 668 MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps)); 447 669 } 448 670 MCA_VERBOSE2(printf("\n")); … … 460 682 if (ex) { 461 683 462 MCA_VERBOSE2(printf("[ borderMerging_Slow_Rosenfeld_Dist] j = %d\n", j));684 MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j)); 463 685 464 686 e1 = E[i - 1][j - 1]; 465 687 e2 = E[i - 1][j]; 466 467 r1 = FindRoot_Dist(D, e1, alpha); 468 r2 = FindRoot_Dist(D, e2, alpha); 469 rx = FindRoot(T, ex); // we already tested that ex != 0 470 688 689 // test pour eviter acces distant 690 r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0; 691 r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0; 692 693 rx = T[ex]; 694 rx = FindRoot_Dist(D, rx, alpha); 695 471 696 MCA_VERBOSE2(printf("\n")); 472 697 MCA_VERBOSE2(printf("e1 = %4d -> %4d\n", e1, r1)); … … 474 699 MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx)); 475 700 476 e = ui32MinNonNul3(r1, r2, rx);701 eps = ui32MinNonNul3(r1, r2, rx); 477 702 478 703 // Quick-Union 479 if (r1 > e ) {480 SetRoot_ Dist(D, r1, e, alpha);481 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, e ));482 } 483 if (r2 > e ) {484 SetRoot_ Dist(D, r2, e, alpha);485 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, e ));486 } 487 if (rx > e ) {488 SetRoot (T, rx, e);489 MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, e ));704 if (r1 > eps) { 705 SetRoot_Rosenfeld_Dist(D, r1, eps, alpha); 706 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, eps)); 707 } 708 if (r2 > eps) { 709 SetRoot_Rosenfeld_Dist(D, r2, eps, alpha); 710 MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps)); 711 } 712 if (rx > eps) { 713 SetRoot_Rosenfeld_Dist(D, rx, eps, alpha); 714 MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps)); 490 715 } 491 716 MCA_VERBOSE2(printf("\n")); … … 493 718 return; 494 719 } 495 496 497 // ------------------------------------------------------------------------------------------------------------- 498 void borderMerging_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha) 499 // ------------------------------------------------------------------------------------------------------------- 500 { 720 #endif // SLOW && !FEATURES 721 722 723 #if SLOW && FEATURES 724 // ---------------------------------------------------------------------------------------------------------------------------------------------------- 725 static void borderMerging_Slow_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 726 // ---------------------------------------------------------------------------------------------------------------------------------------------------- 727 { 728 int j = 0; 729 730 uint32 eps; 731 732 uint32 e1, e2, e3, ex; 733 uint32 r1, r2, r3, rx; 734 735 // -------------- 736 // -- prologue -- 737 // -------------- 738 MCA_VERBOSE2(printf("[%s] i = %d\n", __func__, i)); 739 740 ex = E[i][j]; 741 742 if (ex) { 743 744 MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j)); 745 746 e2 = E[i - 1][j]; 747 e3 = E[i - 1][j + 1]; 748 749 if (e2 || e3) { 750 751 // test pour eviter acces distant 752 r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0; 753 r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0; 754 755 rx = T[ex]; 756 rx = FindRoot_Dist(D, rx, alpha); 757 758 eps = ui32MinNonNul3(r2, r3, rx); 759 760 MCA_VERBOSE2(printf("\n")); 761 MCA_VERBOSE2(printf("e2 = %5d -> r2 = %5d\n", e2, r2)); 762 MCA_VERBOSE2(printf("e3 = %5d -> r3 = %5d\n", e3, r3)); 763 MCA_VERBOSE2(printf("ex = %5d -> rx = %5d\n", ex, rx)); 764 MCA_VERBOSE2(printf("eps = %5d\n", eps)); 765 766 // Quick-Union 767 // @QM 768 if (r2 > eps) { 769 SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F); 770 MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps)); 771 } 772 if (r3 > 0) { 773 r3 = FindRoot_Dist(D, r3, alpha); 774 } 775 // Pour le cas où r2 == r3, il ne faut pas ajouter deux fois les features 776 //if (r3 > eps && r3 != r2) { 777 if (r3 > eps) { 778 SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F); 779 MCA_VERBOSE2(printf("D[%5d] <- %d\n", r3, eps)); 780 } 781 rx = FindRoot_Dist(D, rx, alpha); 782 //if (rx > eps && rx != r3 && rx != r2) { 783 if (rx > eps) { 784 SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F); 785 MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps)); 786 } 787 MCA_VERBOSE2(printf("---------------------------\n")); 788 } 789 } 790 791 // ----------------------- 792 // -- boucle principale -- 793 // ----------------------- 794 795 for (j = 0 + 1; j < width - 1; j++) { 796 797 ex = E[i][j]; 798 799 if (ex) { 800 801 MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j)); 802 803 e1 = E[i - 1][j - 1]; 804 e2 = E[i - 1][j]; 805 e3 = E[i - 1][j + 1]; 806 807 if (e1 || e2 || e3) { 808 // test pour eviter un acces distant 809 r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0; 810 r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0; 811 r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0; 812 813 rx = T[ex]; 814 rx = FindRoot_Dist(D, rx, alpha); 815 816 eps = ui32MinNonNul4(r1, r2, r3, rx); 817 818 MCA_VERBOSE2(printf("\n")); 819 MCA_VERBOSE2(printf("e1 = %5d -> r1 = %5d\n", e1, r1)); 820 MCA_VERBOSE2(printf("e2 = %5d -> r2 = %5d\n", e2, r2)); 821 MCA_VERBOSE2(printf("e3 = %5d -> r3 = %5d\n", e3, r3)); 822 MCA_VERBOSE2(printf("ex = %5d -> rx = %5d\n", ex, rx)); 823 MCA_VERBOSE2(printf("eps = %5d\n", eps)); 824 825 // Quick-Union 826 // @QM 827 if (r1 > eps) { 828 SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F); 829 MCA_VERBOSE2(printf("D[%5d] <- %d\n", r1, eps)); 830 } 831 if (r2 > 0) { 832 r2 = FindRoot_Dist(D, r2, alpha); 833 } 834 //if (r2 > eps && r2 != r1) { 835 if (r2 > eps) { 836 SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F); 837 MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps)); 838 } 839 if (r3 > 0) { 840 r3 = FindRoot_Dist(D, r3, alpha); 841 } 842 //if (r3 > eps && r3 != r2 && r3 != r1) { 843 if (r3 > eps) { 844 SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F); 845 MCA_VERBOSE2(printf("D[%5d] <- %d\n", r3, eps)); 846 } 847 rx = FindRoot_Dist(D, rx, alpha); 848 //if (rx > eps && rx != r3 && rx != r2 && rx != r1) { 849 if (rx > eps) { 850 SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F); 851 MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps)); 852 } 853 MCA_VERBOSE2(puts("---------------------------\n")); 854 855 // attention SetRoot fait un while inutile 856 } 857 } 858 } 859 860 // -------------- 861 // -- epilogue -- 862 // -------------- 863 864 j = width - 1; 865 ex = E[i][j]; 866 867 if (ex) { 868 869 MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j)); 870 871 e1 = E[i - 1][j - 1]; 872 e2 = E[i - 1][j]; 873 874 if (e1 || e2) { 875 876 // test pour eviter acces distant 877 r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0; 878 r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0; 879 880 rx = T[ex]; 881 rx = FindRoot_Dist(D, rx, alpha); 882 883 eps = ui32MinNonNul3(r1, r2, rx); 884 885 MCA_VERBOSE2(printf("\n")); 886 MCA_VERBOSE2(printf("e1 = %5d -> r1 = %5d\n", e1, r1)); 887 MCA_VERBOSE2(printf("e2 = %5d -> r2 = %5d\n", e2, r2)); 888 MCA_VERBOSE2(printf("ex = %5d -> rx = %5d\n", ex, rx)); 889 MCA_VERBOSE2(printf("eps = %5d\n", eps)); 890 891 // Quick-Union 892 if (r1 > eps) { 893 SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F); 894 MCA_VERBOSE2(printf("D[%5d] <- %d\n", r1, eps)); 895 } 896 if (r2 > 0) { 897 r2 = FindRoot_Dist(D, r2, alpha); 898 } 899 //if (r2 > eps && r2 != r1) { 900 if (r2 > eps) { 901 SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F); 902 MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps)); 903 } 904 rx = FindRoot_Dist(D, rx, alpha); 905 //if (rx > eps && rx != r2 && rx != r1) { 906 if (rx > eps) { 907 SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F); 908 MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps)); 909 } 910 MCA_VERBOSE2(printf("---------------------------\n")); 911 } 912 } 913 return; 914 } 915 #endif // SLOW && FEATURES 916 917 918 #if FAST && FEATURES && !PARMERGE 919 // -------------------------------------------------------------------------------------------------------------------------- 920 void optimizedBorder_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 921 // -------------------------------------------------------------------------------------------------------------------------- 922 { 923 // copie de optimizedBorder_Rosenfeld 924 uint32 a, b, c, x; 925 926 x = E[i][j]; 927 928 if (x) { 929 b = E[i - 1][j]; 930 if (b) { 931 vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local 932 } 933 else { 934 c = E[i - 1][j + 1]; 935 if (c) { 936 a = E[i - 1][j - 1]; 937 if (a) { 938 vuse3_Features_Rosenfeld_Dist(a, c, x, T, D, alpha, F); // dist, local 939 } 940 else { 941 vuse2_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local 942 } 943 } 944 else { 945 a = E[i - 1][j - 1]; 946 if (a) { 947 vuse2_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local 948 } 949 } 950 } 951 } 952 } 953 #endif // FAST && FEATURES && !PARMERGE 954 955 956 #if FAST && FEATURES && !PARMERGE 957 // ------------------------------------------------------------------------------------------------------------------------------ 958 void optimizedBorderLeft_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 959 // ------------------------------------------------------------------------------------------------------------------------------ 960 { 961 uint32 x = E[i][j]; 962 963 if (x) { 964 uint32 b = E[i - 1][j]; 965 if (b) { 966 vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local 967 } 968 else { 969 uint32 c = E[i - 1][j + 1]; 970 if (c) { 971 vuse2_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local 972 } 973 } 974 } 975 } 976 #endif // FAST && FEATURES && !PARMERGE 977 978 979 #if FAST && FEATURES && !PARMERGE 980 // ------------------------------------------------------------------------------------------------------------------------------- 981 void optimizedBorderRight_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 982 // ------------------------------------------------------------------------------------------------------------------------------- 983 { 984 // copie de optimizedBorder_Rosenfeld 985 // test d'existance de ex en local local 986 987 uint32 x = E[i][j]; 988 989 if (x) { 990 uint32 b = E[i - 1][j]; 991 if (b) { 992 vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local 993 } 994 else { 995 uint32 a = E[i - 1][j - 1]; 996 if (a) { 997 vuse2_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local 998 } 999 } 1000 } 1001 } 1002 #endif // FAST && FEATURES && !PARMERGE 1003 1004 1005 #if FAST && FEATURES && PARMERGE 1006 // ----------------------------------------------------------------------------------------------------------------------------------- 1007 void optimizedBorder_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 1008 // ----------------------------------------------------------------------------------------------------------------------------------- 1009 { 1010 // copie de optimizedBorder_Rosenfeld 1011 uint32 a, b, c, x; 1012 1013 x = E[i][j]; 1014 1015 if (x) { 1016 b = E[i - 1][j]; 1017 if (b) { 1018 vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local 1019 } 1020 else { 1021 c = E[i - 1][j + 1]; 1022 if (c) { 1023 a = E[i - 1][j - 1]; 1024 if (a) { 1025 vuse3_Parallel_Features_Rosenfeld_Dist(a, c, x, T, D, alpha, F); // dist, local 1026 } 1027 else { 1028 vuse2_Parallel_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local 1029 } 1030 } 1031 else { 1032 a = E[i - 1][j - 1]; 1033 if (a) { 1034 vuse2_Parallel_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local 1035 } 1036 } 1037 } 1038 } 1039 } 1040 #endif // FAST && FEATURES && PARMERGE 1041 1042 1043 #if FAST && FEATURES && PARMERGE 1044 // --------------------------------------------------------------------------------------------------------------------------------------- 1045 void optimizedBorderLeft_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 1046 // --------------------------------------------------------------------------------------------------------------------------------------- 1047 { 1048 uint32 x = E[i][j]; 1049 1050 if (x) { 1051 uint32 b = E[i - 1][j]; 1052 if (b) { 1053 vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local 1054 } 1055 else { 1056 uint32 c = E[i - 1][j + 1]; 1057 if (c) { 1058 vuse2_Parallel_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local 1059 } 1060 } 1061 } 1062 } 1063 #endif // FAST && FEATURES && PARMERGE 1064 1065 1066 #if FAST && FEATURES && PARMERGE 1067 // ---------------------------------------------------------------------------------------------------------------------------------------- 1068 void optimizedBorderRight_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 1069 // ---------------------------------------------------------------------------------------------------------------------------------------- 1070 { 1071 // copie de optimizedBorder_Rosenfeld 1072 // test d'existance de ex en local local 1073 1074 uint32 x = E[i][j]; 1075 1076 if (x) { 1077 uint32 b = E[i - 1][j]; 1078 if (b) { 1079 vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local 1080 } 1081 else { 1082 uint32 a = E[i - 1][j - 1]; 1083 if (a) { 1084 vuse2_Parallel_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local 1085 } 1086 } 1087 } 1088 } 1089 #endif // FAST && FEATURES && PARMERGE 1090 1091 1092 #if FAST && FEATURES 1093 // --------------------------------------------------------------------------------------------------------------------------------------------- 1094 void borderMerging_Fast_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 1095 // --------------------------------------------------------------------------------------------------------------------------------------------- 1096 { 1097 MCA_VERBOSE2(printf("[%s]", __func__)); 1098 1099 #if PARMERGE 1100 optimizedBorderLeft_Parallel_Features_Rosenfeld_Dist(E, i, 0, T, D, alpha, F); 1101 #else 1102 optimizedBorderLeft_Features_Rosenfeld_Dist(E, i, 0, T, D, alpha, F); 1103 #endif 1104 1105 for (int j = 1; j < width - 1; j++) { 1106 #if PARMERGE 1107 optimizedBorder_Parallel_Features_Rosenfeld_Dist(E, i, j, T, D, alpha, F); 1108 #else 1109 optimizedBorder_Features_Rosenfeld_Dist(E, i, j, T, D, alpha, F); 1110 #endif 1111 } 1112 1113 #if PARMERGE 1114 optimizedBorderRight_Parallel_Features_Rosenfeld_Dist(E, i, width - 1, T, D, alpha, F); 1115 #else 1116 optimizedBorderRight_Features_Rosenfeld_Dist(E, i, width - 1, T, D, alpha, F); 1117 #endif 1118 } 1119 #endif // FAST && FEATURES 1120 1121 1122 #if !FEATURES 1123 // -------------------------------------------------------------------------------------------------------------------- 1124 static void borderMerging_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha) 1125 // -------------------------------------------------------------------------------------------------------------------- 1126 { 1127 #if SLOW 501 1128 borderMerging_Slow_Rosenfeld_Dist(X, i, width, E, T, D, alpha); 502 } 503 504 505 // --------------------------------------------------------------------------------------------- 506 uint32 line0Labeling_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne) 507 // --------------------------------------------------------------------------------------------- 1129 #elif FAST 1130 borderMerging_Fast_Rosenfeld_Dist(X, i, width, E, T, D, alpha); 1131 #else 1132 #error "Please define SLOW or FAST for the Rosenfeld version" 1133 #endif 1134 } 1135 #endif // !FEATURES 1136 1137 1138 #if FEATURES 1139 // ----------------------------------------------------------------------------------------------------------------------------------------------- 1140 static void borderMerging_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F) 1141 // ----------------------------------------------------------------------------------------------------------------------------------------------- 1142 { 1143 #if SLOW 1144 borderMerging_Slow_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F); 1145 #elif FAST 1146 borderMerging_Fast_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F); 1147 #else 1148 #error "Please define SLOW or FAST for the Rosenfeld version" 1149 #endif 1150 } 1151 #endif // FEATURES 1152 1153 1154 // ---------------------------------------------------------------------------------------------------- 1155 static uint32 line0Labeling_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne) 1156 // ---------------------------------------------------------------------------------------------------- 508 1157 { 509 1158 int j; … … 542 1191 543 1192 544 // ------------------------------------------------------------------------------------------------- 545 uint32 lineLabeling_Slow_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne) 546 // ------------------------------------------------------------------------------------------------- 1193 #if SLOW 1194 // -------------------------------------------------------------------------------------------------------- 1195 static uint32 lineLabeling_Slow_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne) 1196 // -------------------------------------------------------------------------------------------------------- 547 1197 { 548 1198 // version lineLabeling_Rosenfeld_UF_QU_8C avec Quick-Union … … 633 1283 634 1284 e = ui32MinNonNul4(r1, r2, r3, r4); 635 giet_pthread_assert(e != 0, "e = 0\n");636 1285 637 1286 // Quick-Union … … 707 1356 return ne; 708 1357 } 709 710 711 // ------------------------------------------------------------------------------------------------- 712 uint32 lineLabeling_Fast_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne) 713 // ------------------------------------------------------------------------------------------------- 714 { 1358 #endif // SLOW 1359 1360 1361 #if FAST 1362 // --------------------------------------------------------------------------------------------- 1363 static uint32 optimizedAccessLeft_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne) 1364 // --------------------------------------------------------------------------------------------- 1365 { 1366 // Decision Tree 8-connexe avec Quick-Union 1367 uint32 b, c, e; 1368 1369 b = E[i - 1][j]; 1370 if (b) { 1371 e = use1_QU_Rosenfeld(b, T); 1372 } 1373 else { 1374 c = E[i - 1][j + 1]; 1375 if (c) { 1376 e = use1_QU_Rosenfeld(c, T); 1377 } 1378 else { 1379 e = ++ne; 1380 } 1381 } 1382 E[i][j] = e; 1383 return ne; 1384 } 1385 #endif // FAST 1386 1387 1388 #if FAST 1389 // ---------------------------------------------------------------------------------------------- 1390 static uint32 optimizedAccessRight_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne) 1391 // ---------------------------------------------------------------------------------------------- 1392 { 1393 // Decision Tree 8-connexe avec Quick-Union 1394 uint32 a, b, d, e; 1395 1396 b = E[i - 1][j]; 1397 if (b) { 1398 e = use1_QU_Rosenfeld(b, T); 1399 } 1400 else { 1401 a = E[i - 1][j - 1]; 1402 if (a) { 1403 e = use1_QU_Rosenfeld(a, T); 1404 } 1405 else { 1406 d = E[i][j - 1]; 1407 if (d) { 1408 e = use1_QU_Rosenfeld(d, T); 1409 } 1410 else { 1411 e = ++ne; 1412 } 1413 } 1414 } 1415 E[i][j] = e; 1416 return ne; 1417 } 1418 #endif // FAST 1419 1420 1421 #if FAST 1422 // ----------------------------------------------------------------------------------------- 1423 static uint32 optimizedAccess_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne) 1424 // ----------------------------------------------------------------------------------------- 1425 { 1426 // Decision Tree 8-connexe avec Quick-Union 1427 uint32 a, b, c, d, e; 1428 1429 b = E[i - 1][j]; 1430 if (b) { 1431 e = use1_QU_Rosenfeld(b, T); 1432 } 1433 else { 1434 c = E[i - 1][j + 1]; 1435 if (c) { 1436 a = E[i - 1][j - 1]; 1437 if (a) { 1438 e = use2_QU_Rosenfeld(a, c, T); 1439 } 1440 else { 1441 d = E[i][j - 1]; 1442 if (d) { 1443 e = use2_QU_Rosenfeld(c, d, T); 1444 } 1445 else { 1446 e = use1_QU_Rosenfeld(c, T); 1447 } 1448 } 1449 } 1450 else { 1451 a = E[i - 1][j - 1]; 1452 if (a) { 1453 e = use1_QU_Rosenfeld(a, T); 1454 } 1455 else { 1456 d = E[i][j - 1]; 1457 if (d) { 1458 e = use1_QU_Rosenfeld(d, T); 1459 } 1460 else { 1461 e = ++ne; 1462 } 1463 } 1464 } 1465 } 1466 E[i][j] = e; 1467 return ne; 1468 } 1469 #endif // FAST 1470 1471 1472 1473 #if FAST 1474 // -------------------------------------------------------------------------------------------------------- 1475 static uint32 lineLabeling_Fast_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne) 1476 // -------------------------------------------------------------------------------------------------------- 1477 { 1478 uint8 x; 715 1479 // avec DT et QU 716 int j; 717 uint8 x; 718 719 for (j = 0; j < width; j++) { 720 x = X[i][j]; 1480 // Left Border 1481 x = X[i][0]; 1482 if (x) { 1483 ne = optimizedAccessLeft_DT_Rosenfeld(E, i, 0, T, ne); 1484 } 1485 else { 1486 E[i][0] = 0; 1487 } 1488 // Middle 1489 for (int j = 1; j < width - 1; j++) { 1490 uint8 x = X[i][j]; 721 1491 if (x) { 722 1492 ne = optimizedAccess_DT_Rosenfeld(E, i, j, T, ne); … … 726 1496 } 727 1497 } 1498 // Right Border 1499 x = X[i][width - 1]; 1500 if (x) { 1501 ne = optimizedAccessRight_DT_Rosenfeld(E, i, width - 1, T, ne); 1502 } 1503 else { 1504 E[i][width - 1] = 0; 1505 } 728 1506 return ne; 729 1507 } 730 731 732 // -------------------------------------------------------------------------------------------- 733 uint32 lineLabeling_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne) 734 // -------------------------------------------------------------------------------------------- 735 { 1508 #endif // FAST 1509 1510 1511 // --------------------------------------------------------------------------------------------------- 1512 static uint32 lineLabeling_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne) 1513 // --------------------------------------------------------------------------------------------------- 1514 { 1515 #if SLOW 736 1516 return lineLabeling_Slow_Rosenfeld(X, i, width, E, T, ne); 737 //return lineLabeling_Fast_Rosenfeld(X, i, width, E, T, ne); 738 } 739 740 741 // ---------------------------------------------------------------- 742 uint32 countTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1) 743 // ---------------------------------------------------------------- 1517 #elif FAST 1518 return lineLabeling_Fast_Rosenfeld(X, i, width, E, T, ne); 1519 #else 1520 #error "Please define SLOW or FAST for the Rosenfeld version" 1521 #endif 1522 } 1523 1524 1525 // ----------------------------------------------------------------------- 1526 static uint32 countTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1) 1527 // ----------------------------------------------------------------------- 744 1528 { 745 1529 uint32 e; … … 755 1539 756 1540 757 // -------------------------------------------------------------- 758 void solveTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1) 759 // -------------------------------------------------------------- 1541 #if !FEATURES 1542 // --------------------------------------------------------------------- 1543 static void solveTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1) 1544 // --------------------------------------------------------------------- 760 1545 { 761 1546 uint32 e, r; … … 766 1551 T[e] = r; // racine de la classe d'equivalence 767 1552 } 768 } 769 } 770 771 1553 } 1554 } 1555 #endif // !FEATURES 1556 1557 1558 #if FEATURES 1559 // ---------------------------------------------------------------------------------------------------------- 1560 static void solveTable_solveFeatures_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1, RegionStats * Stats) 1561 // ---------------------------------------------------------------------------------------------------------- 1562 { 1563 uint32 e, r; 1564 1565 for (e = e0; e <= e1; e++) { 1566 r = T[T[e]]; 1567 assert(r != 0); 1568 if (r < e) { 1569 T[e] = r; // racine de la classe d'equivalence 1570 RegionStats_Accumulate_Stats1_From_Index(Stats, r, e); 1571 } 1572 } 1573 } 1574 #endif // FEATURES 1575 1576 1577 #if !FEATURES 772 1578 // ------------------------------------- 773 1579 void MCA_Label_Rosenfeld_PAR1(MCA * mca) … … 775 1581 { 776 1582 if (mca->p == 0) { 777 MCA_VERBOSE1(printf("------------------------------\n"));778 MCA_VERBOSE1(printf("-- MCA_Label_Rosenfeld_PAR1 --\n"));779 MCA_VERBOSE1(printf("------------------------------\n"));780 }781 1583 printf("*** %s ***\n", __func__); 1584 } 1585 1586 CLOCK_THREAD_START_STEP(mca->p, 0); 1587 782 1588 int i0 = mca->i0; 783 1589 int i1 = mca->i1; … … 795 1601 if (mca->p == 0) { 796 1602 set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 797 // @QM : maintenant que c'est testé partout, en a-t-on encore besoin ? A priori non (a tester)798 1603 } 799 1604 else { … … 809 1614 810 1615 MCA_VERBOSE2(display_ui32matrix_positive(E, i0, i1, 0, width - 1, 5, "Ep"); printf("\n")); 811 if (mca->p == 0) { 1616 if (mca->p == 0) { 812 1617 MCA_VERBOSE2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_avant")); 813 1618 } … … 815 1620 // fermeture transitive sans pack 816 1621 solveTable_Range_Rosenfeld(T, e0, ne); 817 nr = countTable_Range_Rosenfeld(T, e0, ne);818 1622 mca->ne = ne; // Plus grande etiquette de l'intervalle [e0..e1] 819 1623 1624 MCA_VERBOSE2(nr = countTable_Range_Rosenfeld(T, e0, ne)); 820 1625 MCA_VERBOSE2(printf("p = %d : e = [%d..%d] -> ne = %d -> nr = %d\n", mca->p, e0, ne, (ne - e0 + 1), nr)); 821 if (mca->p == 0) { 1626 if (mca->p == 0) { 822 1627 MCA_VERBOSE2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_apres")); 823 1628 } 824 } 825 826 1629 1630 CLOCK_THREAD_END_STEP(mca->p, 0); 1631 } 1632 #endif // !FEATURES 1633 1634 1635 #if !FEATURES 827 1636 // ------------------------------------- 828 1637 void MCA_Label_Rosenfeld_PYR2(MCA * mca) … … 830 1639 { 831 1640 // input 832 int np = mca->mca->np; 833 834 // variables 835 int n = np; 836 int nb_level = i32log2(np); 837 if ((1 << nb_level) < np) { 838 nb_level++; // correction pour traiter n non puissance de 2 839 } 1641 int p = mca->p; 1642 int nb_level = mca->nb_level; 840 1643 841 1644 if (mca->p == 0) { 842 MCA_VERBOSE1(printf("------------------------------\n")); 843 MCA_VERBOSE1(printf("-- MCA_Label_Rosenfeld_PYR2 --\n")); 844 MCA_VERBOSE1(printf("------------------------------\n")); 1645 printf("*** %s ***\n", __func__); 845 1646 } 846 1647 … … 862 1663 uint32 ** D = mca->D; 863 1664 864 // @QM 865 // en fait, c'est compliqué. 866 // On pourrait optimiser en faisant faire un "break" aux procs qui n'ont plus jamais 867 // à faire d'itération, mais le problÚme est alors qu'il faut utiliser des barriÚres avec 868 // un nombre de procs à attendre différent à chaque fois, et qu'il faut les 869 // initialiser => il faut précalculer toutes ces valeurs et avoir une alloc dynamique 870 // du nombre de barriÚres. 871 // De plus, le problÚme est décuplé si le nombre de lignes n'est pas une puissance de 2, car 872 // dans ce cas certains threads ne doivent rien faire à une itération courante i, 873 // mais doivent être actifs à i + 1 => encore plus dur de calculer le nombre 874 // de threads à attendre à chaque barriÚre + surtout savoir s'il faut break ou continue 1665 CLOCK_THREAD_START_STEP(p, 1); 1666 #if PYR_BARRIERS 1667 // Version optimisée qui fait faire un break aux processeurs qui n'ont plus 1668 // à faire de merge. 1669 // Implique de pré-calculer le nombre de threads à chaque barriÚre 1670 if (p != 0) { // thread 0 never has any merge to do 1671 int been_active = 0; 1672 for (int level = 0; level < nb_level; level++) { 1673 if ((p + (1 << level)) % (1 << (level + 1)) == 0) { 1674 borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha); // en (i) et (i-1) 1675 been_active = 1; 1676 } 1677 else if (been_active) { 1678 break; 1679 } 1680 pthread_barrier_wait(&mca->barriers[level]); 1681 } 1682 } 1683 pthread_barrier_wait(&main_barrier); 1684 #else 875 1685 for (int level = 1; level <= nb_level; level++) { 876 if (( mca->p + (1 << (level - 1))) % (1 << level) == 0) {1686 if ((p + (1 << (level - 1))) % (1 << level) == 0) { 877 1687 // thread actif 878 //MCA_VERBOSE1(printf("### level = %d - p = %d\n", level, mca->p));879 1688 borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha); // en (i) et (i-1) 880 1689 } 881 barrier_wait(&main_barrier); 882 } 1690 pthread_barrier_wait(&main_barrier); 1691 } 1692 #endif 1693 CLOCK_THREAD_END_STEP(p, 1); 883 1694 884 1695 … … 887 1698 // --------------------------------- 888 1699 1700 CLOCK_THREAD_START_STEP(p, 2); 889 1701 for (uint32 e = e0; e <= e1; e++) { 890 1702 uint32 r = T[e]; // acces local 891 1703 if (r < e) { 892 1704 r = FindRoot_Dist(D, e, alpha); // acces distant 893 } 894 T[e] = r; 895 MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", mca->p, e, r)); 896 } 897 } 1705 T[e] = r; // @QM était en dehors du "if" (je pense que déjà demandé) 1706 } 1707 MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r)); 1708 } 1709 CLOCK_THREAD_END_STEP(p, 2); 1710 } 1711 #endif // !FEATURES 898 1712 899 1713 … … 904 1718 // input 905 1719 if (mca->p == 0) { 906 MCA_VERBOSE1(printf("------------------------------\n")); 907 MCA_VERBOSE1(printf("-- MCA_Label_Rosenfeld_PAR3 --\n")); 908 MCA_VERBOSE1(printf("------------------------------\n")); 1720 printf("*** %s ***\n", __func__); 909 1721 } 910 1722 … … 917 1729 uint32 * T = mca->T; 918 1730 1731 CLOCK_THREAD_START_STEP(mca->p, 3); 919 1732 for (int i = i0; i <= i1; i++) { 920 1733 for (int j = j0; j <= j1; j++) { … … 925 1738 } 926 1739 } 927 } 928 929 1740 CLOCK_THREAD_END_STEP(mca->p, 3); 1741 } 1742 1743 1744 #if FEATURES 1745 // ----------------------------------------------------- 1746 static void MCA_Label_Features_Rosenfeld_PAR1(MCA * mca) 1747 // ----------------------------------------------------- 1748 { 1749 if (mca->p == 0) { 1750 printf("*** %s ***\n", __func__); 1751 } 1752 1753 CLOCK_THREAD_START_STEP(mca->p, 0); 1754 1755 int i0 = mca->i0; 1756 int i1 = mca->i1; 1757 int width = mca->width; 1758 1759 uint32 e0 = mca->e0; 1760 uint32 e1 = mca->e1; 1761 uint32 ne = e0 - 1; 1762 uint32 nr = 0; 1763 1764 // local memory zones 1765 uint8 ** X = mca->X; 1766 uint32 ** E = mca->E; 1767 uint32 * T = mca->T; 1768 1769 RegionStats * stats = mca->stats; 1770 1771 // reset sous optimal (pour le moment = voir region32) 1772 if (mca->p == 0) { 1773 set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 1774 zero_RegionStatsVector(stats, e0 - 1, e1); 1775 } 1776 else { 1777 set_ui32vector_j(T, e0, e1); 1778 zero_RegionStatsVector(stats, e0, e1); 1779 } 1780 1781 if (mca->p == 0) { 1782 MCA_DISPLAY2(display_ui8matrix_positive(X, i0, i1, 0, width - 1, 5, "Xp"); printf("\n")); 1783 } 1784 1785 // ---------------------------- // 1786 // -- Etiquetage d'une bande -- // 1787 // ---------------------------- // 1788 1789 ne = line0Labeling_Rosenfeld(X, i0, width, E, T, ne); 1790 lineFeaturesComputation(E, i0, width, stats); 1791 1792 for (int i = i0 + 1; i <= i1; i++) { 1793 ne = lineLabeling_Rosenfeld(X, i, width, E, T, ne); // Slow or Fast 1794 lineFeaturesComputation(E, i, width, stats); 1795 } 1796 mca->ne = ne; //plus grande etiquette de l'intervalle [e0..e1] 1797 1798 if (mca->p == 0) { 1799 MCA_VERBOSE2(printf("ne = %d\n", ne)); 1800 MCA_DISPLAY2(display_ui32matrix_positive(E, i0, i1, 0, width - 1, 5, "Ep"); printf("\n")); 1801 MCA_DISPLAY2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_avant")); 1802 } 1803 1804 // ------------------------------------------------------ // 1805 // -- Fermeture transitive sans pack de chaque table T -- // 1806 // ------------------------------------------------------ // 1807 1808 solveTable_solveFeatures_Range_Rosenfeld(T, e0, ne, stats); 1809 1810 if (mca->p == 0) { 1811 MCA_VERBOSE2(nr = countTable_Range_Rosenfeld(T, e0, ne); 1812 printf("p = %d : e = [%d..%d] -> ne = %d -> nr = %d\n", mca->p, e0, ne, (ne - e0 + 1), nr)); 1813 MCA_DISPLAY2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_apres")); 1814 } 1815 CLOCK_THREAD_END_STEP(mca->p, 0); 1816 } 1817 #endif // FEATURES 1818 1819 1820 #if FEATURES && !PARMERGE 1821 // ----------------------------------------------------- 1822 static void MCA_Label_Features_Rosenfeld_PYR2(MCA * mca) 1823 // ----------------------------------------------------- 1824 { 1825 int p = mca->p; 1826 int nb_level = mca->nb_level; 1827 1828 if (mca->p == 0) { 1829 printf("*** %s ***\n", __func__); 1830 } 1831 1832 // ------------------------------ 1833 // -- pyramidal border merging -- 1834 // ------------------------------ 1835 1836 // local variables 1837 int i = mca->i0; 1838 int width = mca->width; 1839 int alpha = mca->alpha; 1840 uint32 e0 = mca->e0; 1841 uint32 e1 = mca->ne; 1842 1843 // local memory zones 1844 uint8 ** X = mca->X; 1845 uint32 ** E = mca->E; 1846 uint32 * T = mca->T; 1847 uint32 ** D = mca->D; 1848 RegionStats ** F = mca->F; 1849 1850 CLOCK_THREAD_START_STEP(p, 1); 1851 #if PYR_BARRIERS 1852 // Version optimisée qui fait faire un break aux processeurs qui n'ont plus 1853 // à faire de merge. 1854 // Implique de pré-calculer le nombre de threads à chaque barriÚre 1855 if (p != 0) { // thread 0 never has any merge to do 1856 int been_active = 0; 1857 for (int level = 0; level < nb_level; level++) { 1858 if ((p + (1 << level)) % (1 << (level + 1)) == 0) { 1859 borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F); // (i) et (i-1) 1860 been_active = 1; 1861 } 1862 else if (been_active) { 1863 break; 1864 } 1865 pthread_barrier_wait(&mca->barriers[level]); 1866 } 1867 } 1868 pthread_barrier_wait(&main_barrier); 1869 #else 1870 for (int level = 1; level <= nb_level; level++) { 1871 if ((p + (1 << (level - 1))) % (1 << level) == 0) { 1872 // thread actif 1873 borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F); // (i) et (i-1) 1874 } 1875 pthread_barrier_wait(&main_barrier); 1876 } 1877 #endif 1878 CLOCK_THREAD_END_STEP(p, 1); 1879 1880 1881 /** 1882 * To remove? 1883 // -- Affichage de debug 1884 if (mca->p == 0) { 1885 MCA_VERBOSE1(puts("-----------------------------")); 1886 MCA_VERBOSE1(puts("[PYR2]: avant pack sequentiel")); 1887 MCA_VERBOSE1(puts("-----------------------------")); 1888 1889 for (int p = 0; p < mca->np; p++) { 1890 1891 MCA* mca_par = mcas[p]; 1892 uint32 e0 = mca_par->e0; 1893 uint32 e1 = mca_par->ne; 1894 1895 uint32* T = mca_par->T; 1896 RegionStats* Stats = mca_par->Stats; 1897 1898 RegionStats_DisplayStats_Sparse(T, e0, e1, Stats, NULL); 1899 puts(""); 1900 } 1901 } 1902 */ 1903 1904 // --------------------------------- 1905 // -- parallel transitive closure -- 1906 // --------------------------------- 1907 // identique a la version sans Features 1908 1909 CLOCK_THREAD_START_STEP(p, 2); 1910 for (uint32 e = e0; e <= e1; e++) { 1911 uint32 r = T[e]; // acces local 1912 if (r < e) { 1913 r = FindRoot_Dist(D, e, alpha); // acces distant 1914 T[e] = r; 1915 } 1916 MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r)); 1917 } 1918 CLOCK_THREAD_END_STEP(p, 2); 1919 1920 // To avoid uninitialized accesses 1921 CLOCK_THREAD_START_STEP(p, 3); 1922 CLOCK_THREAD_END_STEP(p, 3); 1923 } 1924 #endif // FEATURES && !PARMERGE 1925 1926 1927 #if FEATURES && PARMERGE 1928 // ----------------------------------------------------- 1929 static void MCA_Label_Features_Rosenfeld_PAR2(MCA * mca) 1930 // ----------------------------------------------------- 1931 { 1932 int p = mca->p; 1933 int nb_level = mca->nb_level; 1934 1935 if (mca->p == 0) { 1936 printf("*** %s ***\n", __func__); 1937 } 1938 1939 // ------------------------------ 1940 // -- parallel border merging -- 1941 // ------------------------------ 1942 1943 // local variables 1944 int i = mca->i0; 1945 int width = mca->width; 1946 int alpha = mca->alpha; 1947 uint32 e0 = mca->e0; 1948 uint32 e1 = mca->ne; 1949 1950 // local memory zones 1951 uint8 ** X = mca->X; 1952 uint32 ** E = mca->E; 1953 uint32 * T = mca->T; 1954 uint32 ** D = mca->D; 1955 RegionStats ** F = mca->F; 1956 1957 CLOCK_THREAD_START_STEP(p, 1); 1958 if (p != 0) { // thread 0 never has any merge to do 1959 borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F); // (i) et (i-1) 1960 } 1961 pthread_barrier_wait(&main_barrier); 1962 CLOCK_THREAD_END_STEP(p, 1); 1963 1964 1965 // --------------------------------- 1966 // -- parallel transitive closure -- 1967 // --------------------------------- 1968 // identique a la version sans Features 1969 1970 CLOCK_THREAD_START_STEP(p, 2); 1971 for (uint32 e = e0; e <= e1; e++) { 1972 uint32 r = T[e]; // acces local 1973 if (r < e) { 1974 r = FindRoot_Dist(D, e, alpha); // acces distant 1975 T[e] = r; 1976 } 1977 MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r)); 1978 } 1979 CLOCK_THREAD_END_STEP(p, 2); 1980 1981 // To avoid uninitialized accesses 1982 CLOCK_THREAD_START_STEP(p, 3); 1983 CLOCK_THREAD_END_STEP(p, 3); 1984 } 1985 #endif // FEATURES 1986 1987 1988 1989 1990 #if !FEATURES 930 1991 // ============================================================= 1992 #if TARGET_OS == GIETVM 931 1993 __attribute__((constructor)) void MCA_Label_Rosenfeld(MCA * mca) 1994 #else 1995 void MCA_Label_Rosenfeld(MCA * mca) 1996 #endif 932 1997 // ============================================================= 933 1998 { 1999 #if TARGET_OS == GIETVM 2000 unsigned int x, y, lpid; 2001 giet_proc_xyp(&x, &y, &lpid); 2002 // Mettre à jour mca->p en fonction de x, y, lpid 2003 // pour que les allocations faites par le main soient locales, 2004 // i.e. 2005 mca->p = (x * Y_SIZE + y) * NB_PROCS_MAX + lpid; 2006 // We have : 2007 // mca->p = 4 pour (x = 0, y = 1, lpid = 0) 2008 // mca->p = 5 pour (x = 0, y = 1, lpid = 1) 2009 MCA_VERBOSE2(printf("mca->p = %d pour (x = %d, y = %d, lpid = %d)\n", mca->p, x, y, lpid)); 2010 #endif 2011 2012 CLOCK_THREAD_START(mca->p); 2013 CLOCK_THREAD_COMPUTE_START(mca->p); 2014 934 2015 MCA_Scatter_ImageX(mca); 935 barrier_wait(&main_barrier);2016 pthread_barrier_wait(&main_barrier); 936 2017 937 2018 MCA_Label_Rosenfeld_PAR1(mca); 938 barrier_wait(&main_barrier); 939 940 //MCA_Gather_ImageL(mca); 941 //barrier_wait(&main_barrier); 942 //MCA_VERBOSE2(display_ui32matrix_positive(mca->E, mca->i0, mca->i1, 0, mca->width - 1, 5, "E2")); 943 //barrier_wait(&main_barrier); 944 945 //MCA_Label_Rosenfeld_SEQ2(mca); 2019 pthread_barrier_wait(&main_barrier); 2020 946 2021 MCA_Label_Rosenfeld_PYR2(mca); 947 barrier_wait(&main_barrier); 948 //MCA_VERBOSE2(display_ui32matrix_positive(mca->E, mca->i0, mca->i1, 0, mca->width - 1, 5, "EPYR")); 949 //barrier_wait(&main_barrier); 2022 pthread_barrier_wait(&main_barrier); 950 2023 951 2024 MCA_Label_Rosenfeld_PAR3(mca); 952 barrier_wait(&main_barrier);2025 pthread_barrier_wait(&main_barrier); 953 2026 954 2027 MCA_Gather_ImageL(mca); 955 barrier_wait(&main_barrier); 956 //MCA_VERBOSE2(display_ui32matrix_positive(mca->E, mca->i0, mca->i1, 0, mca->width - 1, 5, "E3")); 957 //barrier_wait(&main_barrier); 958 2028 pthread_barrier_wait(&main_barrier); 2029 2030 CLOCK_THREAD_COMPUTE_END(mca->p); 2031 CLOCK_THREAD_END(mca->p); 2032 2033 #if TARGET_OS == GIETVM 959 2034 if (mca->p != 0) { 960 giet_pthread_exit(NULL); 961 } 962 } 2035 exit(0); 2036 } 2037 #endif 2038 } 2039 #endif // !FEATURES 2040 2041 2042 #if FEATURES 2043 // ====================================================================== 2044 #if TARGET_OS == GIETVM 2045 __attribute__((constructor)) void * MCA_Label_Features_Rosenfeld(void * arg) 2046 #else 2047 void * MCA_Label_Features_Rosenfeld(void * arg) 2048 #endif 2049 // ====================================================================== 2050 { 2051 MCA * mca = (MCA *) arg; 2052 #if TARGET_OS == GIETVM 2053 unsigned int x, y, lpid; 2054 giet_proc_xyp(&x, &y, &lpid); 2055 // Mettre à jour mca->p en fonction de x, y, lpid 2056 // pour que les allocations faites par le main soient locales, 2057 // i.e. 2058 mca->p = (x * Y_SIZE + y) * NB_PROCS_MAX + lpid; 2059 // We have : 2060 // mca->p = 4 pour (x = 0, y = 1, lpid = 0) 2061 // mca->p = 5 pour (x = 0, y = 1, lpid = 1) 2062 MCA_VERBOSE2(printf("mca->p = %d pour (x = %d, y = %d, lpid = %d)\n", mca->p, x, y, lpid)); 2063 #endif 2064 2065 CLOCK_THREAD_START(mca->p); 2066 CLOCK_THREAD_COMPUTE_START(mca->p); 2067 2068 MCA_Scatter_ImageX(mca); 2069 pthread_barrier_wait(&main_barrier); 2070 2071 MCA_Label_Features_Rosenfeld_PAR1(mca); 2072 pthread_barrier_wait(&main_barrier); 2073 2074 #if PARMERGE 2075 MCA_Label_Features_Rosenfeld_PAR2(mca); 2076 #else 2077 MCA_Label_Features_Rosenfeld_PYR2(mca); 2078 #endif 2079 pthread_barrier_wait(&main_barrier); 2080 2081 MCA_Label_Rosenfeld_PAR3(mca); 2082 pthread_barrier_wait(&main_barrier); 2083 2084 MCA_Gather_ImageL(mca); 2085 pthread_barrier_wait(&main_barrier); 2086 2087 CLOCK_THREAD_COMPUTE_END(mca->p); 2088 2089 if (display_features) { 2090 if (mca->p == 0) { 2091 int i = 1; 2092 printf("[STATS]\n"); 2093 for (int p = 0; p < mca->np; p++) { 2094 MCA * mca_par = mca->mca->mcas[p]; 2095 uint32 e0 = mca_par->e0; 2096 uint32 ne = mca_par->ne - mca_par->e0; // number of elements 2097 uint32 * T = mca_par->T; 2098 RegionStats * stats = mca_par->stats; 2099 RegionStats_DisplayStats_Sparse(T, e0, e0 + ne, stats, NULL, &i); 2100 } 2101 printf("[/STATS]\n"); 2102 } 2103 } 2104 2105 CLOCK_THREAD_END(mca->p); 2106 2107 #if TARGET_OS == GIETVM 2108 if (mca->p != 0) { 2109 exit(0); 2110 } 2111 #endif 2112 2113 return NULL; 2114 } 2115 #endif // FEATURES 2116 963 2117 964 2118 // Local Variables: -
soft/giet_vm/applications/rosenfeld/src/bmpNR.c
r798 r821 11 11 #include <math.h> 12 12 13 /* -- image -- */14 #ifdef CLI15 13 #include "nrc_os_config.h" 16 14 #include "nrtype.h" … … 18 16 #include "nrmacro.h" 19 17 #include "nralloc.h" 20 #endif21 18 22 19 #if TARGET_OS == LINUX … … 37 34 #define BI_RGB 0L 38 35 39 PRIVATE void ReadBMProw (int fd, long width, uint8 * row); 40 PRIVATE void WriteBMProw (uint8 * row, long width, int fd); 41 //PRIVATE void SetupPalette (RGBQUAD Palette[]); 42 43 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 44 //#pragma message("bmpio.h no WINDOWS echo") 45 PRIVATE void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]); 46 #endif 47 48 /* ------------------------------------- */ 49 uint8 *ui8ArrayAppend(uint8 *ptr, uint8 x) 50 /* ------------------------------------- */ 36 static void ReadBMProw(int fd, long width, uint8 * row); 37 static void WriteBMProw(uint8 * row, long width, int fd); 38 static void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]); 39 40 /* --------------------------------------- */ 41 uint8 * ui8ArrayAppend(uint8 * ptr, uint8 x) 42 /* --------------------------------------- */ 51 43 { 52 44 *ptr++ = x; 53 45 return ptr; 54 46 } 47 55 48 /* ---------------------------------------- */ 56 uint8 * ui16ArrayAppend(uint8 *ptr, uint16 x)57 49 uint8 * ui16ArrayAppend(uint8 * ptr, uint16 x) 50 /* ---------------------------------------- */ 58 51 { 59 52 uint8 x0, x1; … … 67 60 return ptr; 68 61 } 69 /* -------------------------------------- */ 70 uint8 *ui32ArrayAppend(uint8 *ptr, uint32 x) 71 /* -------------------------------------- */ 62 63 /* ---------------------------------------- */ 64 uint8 * ui32ArrayAppend(uint8 * ptr, uint32 x) 65 /* ---------------------------------------- */ 72 66 { 73 67 uint8 x0, x1, x2, x3; … … 85 79 return ptr; 86 80 } 81 87 82 // Seul moyen de cache dans la librairie ces putains de types windoze 88 83 89 84 // -------------------------------------------------------- 90 PRIVATE void ReadBMProw(int fd, long width, uint8 *row)91 85 static void ReadBMProw(int fd, long width, uint8 * row) 86 // -------------------------------------------------------- 92 87 { 93 88 // Le fichier est ouvert (en lecture) et ne sera pas ferme a la fin 94 89 read(fd, row, sizeof(uint8) * width); 95 90 } 91 96 92 // --------------------------------------------------------- 97 PRIVATE void WriteBMProw(uint8 *row, long width, int fd)98 93 static void WriteBMProw(uint8 * row, long width, int fd) 94 // --------------------------------------------------------- 99 95 { 100 96 // Le fichier est deja ouvert et ne sera pas ferme a la fin 101 97 write(fd, row, sizeof(uint8) * width); 102 98 } 103 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 104 //#pragma message("bmpio.h no WINDOWS echo") 99 105 100 /* ----------------------------------------------------------- */ 106 PRIVATE void Palette_RGBQuad2RGBQUAD(RGBQuad *src, RGBQUAD dst[])107 101 static void Palette_RGBQuad2RGBQUAD(RGBQuad * src, RGBQUAD dst[]) 102 /* ----------------------------------------------------------- */ 108 103 { 109 104 int i; … … 115 110 } 116 111 } 117 #endif 118 119 #if (!defined(WIN32) && !defined(_WINDOWS_) && !defined(_WINGDI_)) 120 //#pragma message("bmpio.h no WINDOWS echo") 121 /* --------------------------------------------------------------------------- */ 122 IMAGE_EXPORT(int) SaveBMP0_ui8matrix(uint8 **m, int width, int height, RGBQuad *palette_RGBQuad, char *filename) 112 113 IMAGE_EXPORT(int) SaveBMP0_ui8matrix(uint8 ** m, int width, int height, RGBQuad * palette_RGBQuad, char * filename) 123 114 /* --------------------------------------------------------------------------- */ 124 115 /* sauvegarde 'image' au format bmp dans le fichier 'filename' */ 125 116 { 126 int rc = 0;127 128 117 int v_offset = 0; // no more implemented image->v_offset; 129 118 int h_offset = 0; // no more implemented image->h_offset; 130 119 int vmax = height - v_offset; 131 //int hmax = width - h_offset; 132 int height_utile = height - 2*v_offset; 133 int width_utile = width - 2*h_offset; 120 int height_utile = height - 2 * v_offset; 121 int width_utile = width - 2 * h_offset; 134 122 int taille_utile = height_utile * width_utile; 135 123 136 //int size;137 124 int padding_len; 138 125 139 126 BITMAPFILEHEADER Bitmap_File_Header; 140 /*BITMAPINFO; Bitmap_Info; */141 142 127 BITMAPINFOHEADER Bitmap_Info_Header; 143 /*RGBQUAD RGB_Quad; */144 128 145 129 RGBQUAD palette_RGBQUAD[256]; /* Windows */ … … 156 140 157 141 /* --- Header --- */ 158 Bitmap_File_Header.bfType = (WORD) BM; /* BM */ 159 Bitmap_File_Header.bfSize = (DWORD) sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQuad)+taille_utile; /* taille avec header et palette */ 160 Bitmap_File_Header.bfReserved1 = (WORD) 0; /* 0 */ 161 Bitmap_File_Header.bfReserved2 = (WORD) 0; /* 0 */ 162 Bitmap_File_Header.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + 163 (DWORD) sizeof(BITMAPINFOHEADER) + 164 (DWORD) sizeof(RGBQUAD)*256; /* */ 142 Bitmap_File_Header.bfType = (WORD) BM; /* BM */ 143 /* taille avec header et palette */ 144 Bitmap_File_Header.bfSize = (DWORD) sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQuad) + taille_utile; 145 Bitmap_File_Header.bfReserved1 = (WORD) 0; /* 0 */ 146 Bitmap_File_Header.bfReserved2 = (WORD) 0; /* 0 */ 147 Bitmap_File_Header.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + (DWORD) sizeof(BITMAPINFOHEADER) + (DWORD) sizeof(RGBQUAD)*256; /* */ 165 148 166 149 … … 182 165 fd = open(filename, O_CREAT | O_TRUNC); 183 166 if (fd < 0) { 184 printf("*** Erreur : Ouverture du fichier impossible dans SaveBMP"); 167 printf("\n*** Erreur : Ouverture du fichier impossible dans SaveBMP\n"); 168 return -1; 185 169 } 186 170 … … 215 199 } 216 200 close(fd); 217 return rc;218 219 } 220 #endif 221 // ------------------------------------------------------------------------------------------------------------ 222 IMAGE_EXPORT(int) SaveBMP2_ui8matrix(uint8 ** m, int width, int height, RGBQuad *palette_RGBQuad, char *filename)223 //------------------------------------------------------------------------------------------------------------224 201 return 0; 202 203 } 204 205 // ---------------------------------------------------------------------------------------------------------------- 206 IMAGE_EXPORT(int) SaveBMP2_ui8matrix(uint8 ** m, int width, int height, RGBQuad * palette_RGBQuad, char * filename) 207 // ---------------------------------------------------------------------------------------------------------------- 208 // sauvegarde 'image' au format bmp dans le fichier 'filename' 225 209 { 226 210 int taille_utile = height * width; 227 228 //int size;229 211 int padding_len; 230 212 … … 241 223 int fd; 242 224 int i; 243 244 //#pragma message("BMP warnin' data structure aligment must be 2")245 //#pragma message(" sizeof( BitmapFileHeader) must = 14, not 16")246 225 247 226 //DEBUG(printf("BMP0 : %d %d\n", sizeof( BITMAPFILEHEADER), sizeof( BITMAPINFOHEADER))); … … 298 277 //printf(" SaveBMP %s %dx%d\n", filename, width, height); 299 278 300 fd = open(filename, O_CREAT | O_TRUNC); 279 #if TARGET_OS != GIETVM 280 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 281 #else 282 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC); 283 #endif 301 284 if (fd < 0) { 302 printf("*** Erreur : ouverture du fichier '%s' impossible dans SaveBMP", filename); 285 printf("\n*** Erreur : ouverture du fichier '%s' impossible dans SaveBMP\n", filename); 286 return -1; 303 287 } 304 288 … … 326 310 327 311 328 // en 2x car le compilo est trop con ...329 312 padding_len = width % 4; 330 313 padding_len = (4 - padding_len) % 4; -
soft/giet_vm/applications/rosenfeld/src/ecc_common.c
r798 r821 8 8 #include <math.h> 9 9 10 #ifdef CLI11 10 #include "nrc_os_config.h" 12 11 #include "nrc.h" 13 #endif14 12 15 13 #if TARGET_OS == LINUX … … 44 42 return (a > b ? a : b); 45 43 } 44 45 46 46 // ------------------------------------------ 47 47 uint32 ui32Max3(uint32 a, uint32 b, uint32 c) … … 50 50 return ui32Max2(ui32Max2(a, b), c); 51 51 } 52 53 52 54 // ---------------------------------------------------- 53 55 uint32 ui32Max4(uint32 a, uint32 b, uint32 c, uint32 d) … … 56 58 return ui32Max2(ui32Max2(a, b), ui32Max2(c,d)); 57 59 } 60 61 58 62 // -------------------------------- 59 63 uint32 ui32Min2(uint32 a, uint32 b) … … 62 66 return (a < b ? a : b); 63 67 } 68 69 64 70 // ------------------------------------------ 65 71 uint32 ui32Min3(uint32 a, uint32 b, uint32 c) … … 68 74 return ui32Min2(ui32Min2(a, b), c); 69 75 } 76 77 70 78 // ---------------------------------------------------- 71 79 uint32 ui32Min4(uint32 a, uint32 b, uint32 c, uint32 d) … … 74 82 return ui32Min2(ui32Min2(a, b), ui32Min2(c,d)); 75 83 } 84 85 76 86 /* ----------------------------------- */ 77 87 uint32 ui32MinNonNul2(uint32 a, uint32 b) … … 84 94 return a; 85 95 } 96 97 86 98 /* --------------------------------------------- */ 87 99 uint32 ui32MinNonNul3(uint32 a, uint32 b, uint32 c) … … 96 108 return m; 97 109 } 110 111 98 112 /* ---------------------------------------------------- */ 99 113 uint32 ui32MinNonNul3Cond(uint32 a0, uint32 a1, uint32 a2) … … 105 119 return m; 106 120 } 121 122 107 123 /* ----------------------------------------------------------- */ 108 124 uint32 ui32MinNonNul4(uint32 a0, uint32 a1, uint32 a2, uint32 a3) … … 118 134 return m; 119 135 } 136 137 120 138 /* ---------------------------------------------------------------------- */ 121 139 uint32 ui32MinNonNul5(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4) … … 132 150 return m; 133 151 } 152 153 134 154 /* -------------------------------------------------------------------------- */ 135 155 uint32 ui32MinNonNul5Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4) … … 141 161 return m; 142 162 } 163 164 143 165 /* ------------------------------------------------------------------------------------------------------- */ 144 166 uint32 ui32MinNonNul8(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7) … … 158 180 return m; 159 181 } 182 183 160 184 /* ------------------------------------------------------------------------------------------------------------------ */ 161 185 uint32 ui32MinNonNul9(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8) … … 176 200 return m; 177 201 } 202 203 178 204 /* ---------------------------------------------------------------------------------------------------------------------- */ 179 205 uint32 ui32MinNonNul9Cond(uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4, uint32 a5, uint32 a6, uint32 a7, uint32 a8) … … 190 216 return m; 191 217 } 192 // -------------------------------- 193 void initT(uint32 *T, uint32 nemax) 194 // -------------------------------- 218 219 220 // --------------------------------- 221 void initT(uint32 * T, uint32 nemax) 222 // --------------------------------- 195 223 { 196 224 int i; … … 199 227 } 200 228 } 229 230 201 231 /* -------------------------- */ 202 232 //void initA(uint32 *A, uint32 nemax) … … 208 238 } 209 239 }*/ 240 241 210 242 // -------------------------------- 211 243 void initZ(uint32 *T, uint32 nemax) … … 217 249 } 218 250 } 251 252 219 253 // -------------------------------------- 220 254 void check_initT(uint32 *T, uint32 nemax) … … 223 257 check_initT_range(T, 0, nemax, nemax); 224 258 } 259 260 225 261 // -------------------------------------- 226 262 void check_initZ(uint32 *T, uint32 nemax) … … 229 265 check_initZ_range(T, 0, nemax, nemax); 230 266 } 267 268 231 269 // --------------------------------------------------------------- 232 270 void check_initT_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1) … … 243 281 } 244 282 } 283 284 245 285 // --------------------------------------------------------------- 246 286 void check_initR_range(uint32 *R, uint32 i0, uint32 ii, uint32 i1) … … 257 297 } 258 298 } 299 300 259 301 // --------------------------------------------------------------- 260 302 void check_initZ_range(uint32 *T, uint32 i0, uint32 ii, uint32 i1) … … 271 313 } 272 314 } 315 316 273 317 /* --------------------------------------------------------------------------------------------------- */ 274 318 void binarisation_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 seuil, uint8 val, uint8 **Y) … … 309 353 } 310 354 } 311 /* ------------------------------------------------------------------------------- */ 312 void graphviz_write_ui8vector(uint8 *v, int i0, int i1, char *format, char *filename) 313 /* ------------------------------------------------------------------------------- */ 314 { 315 int i; 355 /* ---------------------------------------------------------------------------------- */ 356 void graphviz_write_ui8vector(uint8 * v, int i0, int i1, char * format, char * filename) 357 /* ---------------------------------------------------------------------------------- */ 358 { 359 int i; 360 char complete_filename[64]; 361 362 snprintf(complete_filename, 64, "%s.dot", filename); 363 364 #if TARGET_OS == GIETVM 316 365 int fd; 317 char complete_filename[64];318 319 snprintf(complete_filename, 64, "%s.dot", filename);320 321 366 fd = open(complete_filename, O_CREAT | O_TRUNC); 322 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }323 367 324 368 fprintf(fd, "digraph %s {\n", filename); … … 328 372 fprintf(fd, "}\n"); 329 373 close(fd); 330 } 331 /* --------------------------------------------------------------------------------- */ 332 void graphviz_write_ui16vector(uint16 *v, int i0, int i1, char *format, char *filename) 333 /* --------------------------------------------------------------------------------- */ 334 { 335 int i; 374 #elif TARGET_OS == LINUX 375 FILE * f; 376 f = fopen(complete_filename, "w"); 377 if (f == NULL) { 378 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 379 } 380 381 fprintf(f, "digraph %s {\n", filename); 382 for (i = i0; i <= i1; i++) { 383 fprintf(f, "%3d -> %3d;\n", i, v[i]); 384 } 385 fprintf(f, "}\n"); 386 fclose(f); 387 #endif 388 } 389 /* ------------------------------------------------------------------------------------ */ 390 void graphviz_write_ui16vector(uint16 * v, int i0, int i1, char * format, char * filename) 391 /* ------------------------------------------------------------------------------------ */ 392 { 393 int i; 394 char complete_filename[64]; 395 396 snprintf(complete_filename, 64, "%s.dot", filename); 397 398 #if TARGET_OS == GIETVM 336 399 int fd; 337 char complete_filename[64];338 339 snprintf(complete_filename, 64, "%s.dot", filename);340 341 342 400 fd = open(complete_filename, O_CREAT | O_TRUNC); 343 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }344 401 345 402 fprintf(fd, "digraph %s {\n", filename); … … 349 406 fprintf(fd, "}\n"); 350 407 close(fd); 351 } 352 /* --------------------------------------------------------------------------------- */ 353 void graphviz_write_ui32vector(uint32 *v, int i0, int i1, char *format, char *filename) 354 /* --------------------------------------------------------------------------------- */ 355 { 356 int i; 408 #elif TARGET_OS == LINUX 409 FILE * f; 410 f = fopen(complete_filename, "w"); 411 if (f == NULL) { 412 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 413 } 414 415 fprintf(f, "digraph %s {\n", filename); 416 for (i = i0; i <= i1; i++) { 417 fprintf(f, "%3d -> %3d;\n", i, v[i]); 418 } 419 fprintf(f, "}\n"); 420 fclose(f); 421 #endif 422 } 423 424 425 /* ------------------------------------------------------------------------------------ */ 426 void graphviz_write_ui32vector(uint32 * v, int i0, int i1, char * format, char * filename) 427 /* ------------------------------------------------------------------------------------ */ 428 { 429 int i; 430 char complete_filename[64]; 431 432 snprintf(complete_filename, 64, "%s.dot", filename); 433 434 #if TARGET_OS == GIETVM 357 435 int fd; 358 char complete_filename[64];359 360 snprintf(complete_filename, 64, "%s.dot", filename);361 362 363 436 fd = open(complete_filename, O_CREAT | O_TRUNC); 364 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }365 437 366 438 fprintf(fd, "digraph %s {\n", filename); … … 370 442 fprintf(fd, "}\n"); 371 443 close(fd); 372 } 373 /* ------------------------------------------------------------------------------ */ 374 void mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y) 375 /* ------------------------------------------------------------------------------ */ 444 #elif TARGET_OS == LINUX 445 FILE * f; 446 f = fopen(complete_filename, "w"); 447 if (f == NULL) { 448 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 449 } 450 451 fprintf(f, "digraph %s {\n", filename); 452 for (i = i0; i <= i1; i++) { 453 fprintf(f, "%3d -> %3d;\n", i, v[i]); 454 } 455 fprintf(f, "}\n"); 456 fclose(f); 457 #endif 458 } 459 460 461 /* -------------------------------------------------------------------------------- */ 462 void mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y) 463 /* -------------------------------------------------------------------------------- */ 376 464 { 377 465 int i, j; … … 382 470 } 383 471 } 384 // ------------------------------------------------------------------------------------------ 385 void positive_mod_ui32matrix_ui8matrix(uint32 **X, int i0, int i1, int j0, int j1, uint8 **Y) 386 // ------------------------------------------------------------------------------------------ 472 473 474 // -------------------------------------------------------------------------------------------- 475 void positive_mod_ui32matrix_ui8matrix(uint32 ** X, int i0, int i1, int j0, int j1, uint8 ** Y) 476 // -------------------------------------------------------------------------------------------- 387 477 { 388 478 int i, j; … … 392 482 if (X[i][j] < 255) { 393 483 Y[i][j] = X[i][j]; // pour que e=1 reste rouge 394 } else { 484 } 485 else { 395 486 Y[i][j] = (X[i][j] % 254) + 1; 396 487 } 397 } else { 488 } 489 else { 398 490 Y[i][j] = 0; 399 491 } … … 402 494 } 403 495 } 404 /* --------------------------------------------------------------------------------- */ 405 void graphviz_write_ui32vector_par(uint32 *v, int i0, int i1, char *format, char *filename) 406 /* --------------------------------------------------------------------------------- */ 407 { 408 int i; 496 497 498 /* ---------------------------------------------------------------------------------------- */ 499 void graphviz_write_ui32vector_par(uint32 * v, int i0, int i1, char * format, char * filename) 500 /* ---------------------------------------------------------------------------------------- */ 501 { 502 int i; 503 char complete_filename[64]; 504 505 snprintf(complete_filename, 64, "%s.dot", filename); 506 507 #if TARGET_OS == GIETVM 409 508 int fd; 410 char complete_filename[64];411 412 snprintf(complete_filename, 64, "%s.dot", filename);413 414 415 509 fd = open(complete_filename, O_CREAT | O_TRUNC); 416 //if(f == NULL) { nrerror("Can't open file in grawrite_bvector"); }417 510 418 511 fprintf(fd, "digraph %s {\n", filename); … … 422 515 fprintf(fd, "}\n"); 423 516 close(fd); 424 } 517 #else 518 FILE * f; 519 f = fopen(complete_filename, "w"); 520 if (f == NULL) { 521 fprintf(stderr, "Can't open file %s in %s\n", complete_filename, __func__); 522 } 523 fprintf(f, "digraph %s {\n", filename); 524 for (i = i0; i <= i1; i++) { 525 fprintf(f, "%3d -> %3d;\n", i, v[i]); 526 } 527 fprintf(f, "}\n"); 528 fclose(f); 529 #endif 530 } 531 532 425 533 // -------------------------------------- 426 534 uint32 mt19937_uint32(uint32 a, uint32 b) … … 431 539 uint32 x32; 432 540 433 if (b < a) return mt19937_uint32(b, a); 541 if (b < a) { 542 return mt19937_uint32(b, a); 543 } 434 544 435 545 //printf("a = %u b = %u\n", a, b); … … 441 551 return x32; 442 552 } 443 // ----------------------- 444 BOOL strto_Bool(char *str) 445 // ----------------------- 446 { 447 BOOL b = TRUE; 448 if (strcmp(str, "TRUE" ) == 0) b = TRUE; 449 if (strcmp(str, "true" ) == 0) b = TRUE; 450 451 if (strcmp(str, "FALSE") == 0) b = FALSE; 452 if (strcmp(str, "false") == 0) b = FALSE; 553 554 555 // ------------------------ 556 bool strto_Bool(char * str) 557 // ------------------------ 558 { 559 bool b = true; 560 if (strcmp(str, "TRUE" ) == 0) b = true; 561 if (strcmp(str, "true" ) == 0) b = true; 562 563 if (strcmp(str, "FALSE") == 0) b = false; 564 if (strcmp(str, "false") == 0) b = false; 453 565 454 566 return b; 455 567 } 456 // ------------------------------------------------------------ 457 void check_no_write(uint32 **T, int i0, int i1, int j0, int j1) 458 // ------------------------------------------------------------ 568 569 570 // ------------------------------------------------------------- 571 void check_no_write(uint32 ** T, int i0, int i1, int j0, int j1) 572 // ------------------------------------------------------------- 459 573 { 460 574 int i, j; … … 467 581 } 468 582 } 583 584 -
soft/giet_vm/applications/rosenfeld/src/ecc_features.c
r798 r821 10 10 // Caracteristiques d'une region / label 11 11 12 //#pragma message("------------------")13 //#pragma message("--- Features.c ---")14 //#pragma message("------------------")15 16 12 #include <stdio.h> 17 13 #include <stddef.h> 18 14 #include <stdlib.h> 19 15 #include <malloc.h> 20 21 22 #ifdef CLI 16 #include <string.h> 17 18 23 19 #include "nrc_os_config.h" 20 #include "config.h" 24 21 #include "nrc.h" 25 #endif26 27 22 28 23 … … 31 26 #include <sys/stat.h> 32 27 #include <fcntl.h> 28 #include <unistd.h> 33 29 #endif 34 30 35 31 36 #ifdef OPENMP37 #include <omp.h>38 #endif39 40 32 #include "ecc_features.h" 41 //#include "label.h" 33 34 #define BUFF_SIZE 1024 // for snprintf 35 36 37 // ------------------------------------------------------------- 38 void RegionStats_Constructor(RegionStats ** Stats, uint32 nemax) 39 // ------------------------------------------------------------- 40 { 41 *Stats = RegionStats_pConstructor(nemax); 42 } 43 44 45 // ------------------------------------------------- 46 RegionStats * RegionStats_pConstructor(uint32 nemax) 47 // ------------------------------------------------- 48 { 49 RegionStats * Stats; 50 51 Stats = (RegionStats *) malloc((nemax) * sizeof(RegionStats)); 52 if (Stats == NULL) { 53 nrerror("allocation failed in RegionStats_pConstructor"); 54 } 55 56 RegionStats_Clear(Stats, nemax); 57 58 return Stats; 59 } 60 42 61 43 62 // ------------------------------------------------------------ 44 void RegionStats_ Constructor(RegionStats **Stats, uint32 nemax)63 void RegionStats_Destructor(RegionStats ** Stats, uint32 nemax) 45 64 // ------------------------------------------------------------ 46 65 { 47 *Stats = RegionStats_pConstructor(nemax);48 }49 // ------------------------------------------------50 RegionStats* RegionStats_pConstructor(uint32 nemax)51 // ------------------------------------------------52 {53 RegionStats *Stats;54 55 Stats = (RegionStats*) malloc((nemax)*sizeof(RegionStats));56 if(Stats == NULL) nrerror("allocation failed in RegionStats_pConstructor");57 58 RegionStats_Clear(Stats, nemax);59 60 return Stats;61 }62 // -----------------------------------------------------------63 void RegionStats_Destructor(RegionStats **Stats, uint32 nemax)64 // -----------------------------------------------------------65 {66 66 RegionStats_pDestructor(*Stats, nemax); 67 67 } 68 // ----------------------------------------------------------- 69 void RegionStats_pDestructor(RegionStats *Stats, uint32 nemax) 70 // ----------------------------------------------------------- 68 69 70 // ------------------------------------------------------------ 71 void RegionStats_pDestructor(RegionStats * Stats, uint32 nemax) 72 // ------------------------------------------------------------ 71 73 { 72 74 RegionStats_Clear(Stats, nemax); 73 75 free(Stats); 74 76 } 75 // ----------------------------------------------------- 76 void RegionStats_Clear(RegionStats *Stats, uint32 nemax) 77 // ----------------------------------------------------- 78 { 79 int i; 80 for (i = 0; i < (int) nemax; i++) { 77 78 79 // ------------------------------------------------------ 80 void RegionStats_Clear(RegionStats * Stats, uint32 nemax) 81 // ------------------------------------------------------ 82 { 83 for (int i = 0; i < (int) nemax; i++) { 81 84 Stats[i].xmin = 65535; 82 85 Stats[i].xmax = 0; … … 86 89 Stats[i].S = 0; 87 90 88 Stats[i].x = 0;89 Stats[i].y = 0;90 91 91 Stats[i].Sx = 0; 92 92 Stats[i].Sy = 0; 93 94 #ifdef REGION_STATS2 95 Stats[i].Sx2 = 0; 96 Stats[i].Sxy = 0; 97 Stats[i].Sy2 = 0; 93 #if PARMERGE 94 pthread_spin_init(&Stats[i].lock, PTHREAD_PROCESS_PRIVATE); 98 95 #endif 99 96 } 100 97 } 101 // ---------------------------------------- 102 void RegionStats_Clear1(RegionStats *stats) 103 // ---------------------------------------- 98 99 100 // ----------------------------------------- 101 void RegionStats_Clear1(RegionStats * stats) 102 // ----------------------------------------- 104 103 { 105 104 stats->xmin = 0; … … 110 109 stats->S = 0; 111 110 112 stats->x = 0;113 stats->y = 0;114 115 111 stats->Sx = 0; 116 112 stats->Sy = 0; 117 #ifdef REGION_STATS2 118 stats->Sx2 = 0; 119 stats->Sxy = 0; 120 stats->Sy2 = 0; 121 #endif 122 } 123 // ------------------------------------------ 124 int RegionStats_Create_File(char *filename) 125 // ------------------------------------------ 113 } 114 115 116 // ----------------------------------------- 117 int RegionStats_Create_File(char * filename) 118 // ----------------------------------------- 126 119 { 127 120 int fd; … … 130 123 if (fd < 0) { 131 124 printf("RegionStats_Open_File : can't create file %s\n", filename); 132 giet_pthread_exit("");125 exit(1); 133 126 } 134 127 return fd; 135 128 } 136 // ---------------------------------------- 137 int RegionStats_Open_File(char *filename) 138 // ---------------------------------------- 129 130 131 // --------------------------------------- 132 int RegionStats_Open_File(char * filename) 133 // --------------------------------------- 139 134 { 140 135 int fd; … … 143 138 if (fd < 0) { 144 139 printf("RegionStats_Open_File : can't open file %s\n", filename); 145 giet_pthread_exit("");140 exit(1); 146 141 } 147 142 return fd; 148 143 } 149 // --------------------------------- 144 145 146 // -------------------------------- 150 147 void RegionStats_Close_File(int fd) 151 // -------------------------------- -148 // -------------------------------- 152 149 { 153 150 close(fd); 154 151 } 155 // --------------------------------- 152 153 154 #if 0 // pb : fscanf requires manipulating FILE * 155 // -------------------------------- 156 156 int RegionStats_Read_Header(int fd) 157 // -------------------------------- -157 // -------------------------------- 158 158 { 159 159 int ne = 0; 160 // @QM giet161 160 fscanf(fd, "%d", &ne); 162 161 return ne; 163 162 } 164 // ------------------------------------------- 163 #endif 164 165 166 // ------------------------------------------ 165 167 void RegionStats_Write_Header(int ne, int fd) 166 // ------------------------------------------- 167 { 168 fprintf(fd, "%d\n", ne); 169 } 168 // ------------------------------------------ 169 { 170 char buff[BUFF_SIZE]; 171 snprintf(buff, BUFF_SIZE, "%d\n", ne); 172 write(fd, buff, strlen(buff) + 1); 173 } 174 175 176 #if 0 170 177 // -------------------------------------------------------------- 171 void RegionStats_Read_Stats1(int fd, int ne, RegionStats * Stats)178 void RegionStats_Read_Stats1(int fd, int ne, RegionStats * Stats) 172 179 // -------------------------------------------------------------- 173 180 { … … 184 191 &(Stats[i].Sx), 185 192 &(Stats[i].Sy)); 186 187 Stats[i].x = Stats[i].Sx / Stats[i].S; 188 Stats[i].y = Stats[i].Sy / Stats[i].S; 189 190 } 191 } 192 // -------------------------------------------------------------- 193 void RegionStats_Read_Stats2(int fd, int ne, RegionStats *Stats) 194 // -------------------------------------------------------------- 195 { 196 #ifdef REGION_STATS2 197 int i, t; 198 199 int32 Sx2, Sxy, Sy2; 200 201 for (i = 1; i <= ne; i++) { 202 fscanf(f, "%d%d%d%d%d%d%d%d%d%d%d\n", 203 &t, 204 &(Stats[i].xmin), 205 &(Stats[i].xmax), 206 &(Stats[i].ymin), 207 &(Stats[i].ymax), 208 &(Stats[i].S), 209 &(Stats[i].Sx), 210 &(Stats[i].Sy), 211 &(Sx2), 212 &(Sxy), 213 &(Sy2)); 214 215 Stats[i].Sx2 = Sx2; 216 Stats[i].Sxy = Sxy; 217 Stats[i].Sy2 = Sy2; 218 219 Stats[i].x = Stats[i].Sx / Stats[i].S; 220 Stats[i].y = Stats[i].Sy / Stats[i].S; 221 } 222 #else 223 nrerror("RegionStats_Read_Stats2 REGION_STAT2 not defined"); 193 } 194 } 224 195 #endif 225 } 196 197 226 198 // --------------------------------------------------------------- 227 void RegionStats_Write_Stats1(RegionStats * Stats, int ne, int fd)199 void RegionStats_Write_Stats1(RegionStats * Stats, int ne, int fd) 228 200 // --------------------------------------------------------------- 229 201 { 230 int i;231 232 for (i = 1; i <= ne; i++) {233 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",202 char buff[BUFF_SIZE]; 203 204 for (int i = 1; i <= ne; i++) { 205 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 234 206 i, 235 207 Stats[i].xmin, … … 241 213 Stats[i].Sx, 242 214 Stats[i].Sy); 243 } 244 } 245 // -------------------------------------------------------------------------------------------------- 246 void RegionStats_Write_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, int fd) 247 // -------------------------------------------------------------------------------------------------- 215 write(fd, buff, strlen(buff) + 1); 216 } 217 } 218 219 220 // --------------------------------------------------------------------------------------------------- 221 void RegionStats_Write_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, int fd) 222 // --------------------------------------------------------------------------------------------------- 248 223 { 249 224 uint32 e; 225 char buff[BUFF_SIZE]; 250 226 251 227 for (e = ne0; e <= ne1; e++) { 252 228 if ((e == EQ[e]) && (Stats[e].S > 0)) { 253 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",229 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 254 230 e, 255 231 Stats[e].xmin, … … 261 237 Stats[e].Sx, 262 238 Stats[e].Sy); 263 } 264 } 265 } 266 // --------------------------------------------------------------- 267 void RegionStats_Write_Stats2(RegionStats *Stats, int ne, int fd) 268 // --------------------------------------------------------------- 269 { 270 #ifdef REGION_STATS2 271 int i; 272 for (i = 1; i <= ne; i++) { 273 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 274 i, 275 Stats[i].xmin, 276 Stats[i].xmax, 277 Stats[i].ymin, 278 Stats[i].ymax, 279 280 Stats[i].S, 281 Stats[i].Sx, 282 Stats[i].Sy, 283 284 (int32) Stats[i].Sx2, 285 (int32) Stats[i].Sxy, 286 (int32) Stats[i].Sy2); 287 } 288 #else 289 nrerror("RegionStats_Write_Stats2: REGION_STATS2 not defined"); 290 #endif 291 } 239 write(fd, buff, strlen(buff) + 1); 240 } 241 } 242 } 243 244 292 245 // ----------------------------------------------------------------- 293 void RegionStats_Write_pStats1(RegionStats ** Stats, int ne, int fd)246 void RegionStats_Write_pStats1(RegionStats ** Stats, int ne, int fd) 294 247 // ----------------------------------------------------------------- 295 248 { 296 int i;297 298 for (i = 1; i <= ne; i++) {299 fprintf(fd, "%4d %5d %5d %5d %5d %7d %8d %8d\n",249 char buff[BUFF_SIZE]; 250 251 for (int i = 1; i <= ne; i++) { 252 snprintf(buff, BUFF_SIZE, "%4d %5d %5d %5d %5d %7d %8d %8d\n", 300 253 i, 301 254 Stats[i]->xmin, … … 306 259 Stats[i]->Sx, 307 260 Stats[i]->Sy); 308 } 309 } 310 // ----------------------------------------------------------------- 311 void RegionStats_Write_pStats2(RegionStats **Stats, int ne, int fd) 312 // ----------------------------------------------------------------- 313 { 314 #ifdef REGION_STATS2 315 int i; 316 for (i = 1; i <= ne; i++) { 317 fprintf(fd, "%3d %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 318 i, 319 Stats[i]->xmin, 320 Stats[i]->xmax, 321 Stats[i]->ymin, 322 Stats[i]->ymax, 323 Stats[i]->S, 324 Stats[i]->Sx, 325 Stats[i]->Sy, 326 327 (int32) Stats[i]->Sx2, 328 (int32) Stats[i]->Sxy, 329 (int32) Stats[i]->Sy2); 330 } 331 #else 332 nrerror("RegionStats_Write_Stats2: REGION_STATS2 not defined"); 333 #endif 334 } 335 // ----------------------------------------------------------------------- 336 void RegionStats_Load_Stats1(char *filename, int *ne, RegionStats **Stats) 337 // ----------------------------------------------------------------------- 261 write(fd, buff, strlen(buff) + 1); 262 } 263 } 264 265 266 #if 0 267 // -------------------------------------------------------------------------- 268 void RegionStats_Load_Stats1(char * filename, int * ne, RegionStats ** Stats) 269 // -------------------------------------------------------------------------- 338 270 { 339 271 int fd; … … 347 279 RegionStats_Close_File(fd); 348 280 } 349 // ----------------------------------------------------------------------- 350 void RegionStats_Load_Stats2(char *filename, int *ne, RegionStats **Stats) 351 // ----------------------------------------------------------------------- 352 { 353 #ifdef REGION_STATS2 354 int fd; 355 356 fd = RegionStats_Open_File(filename); 357 358 *ne = RegionStats_Read_Header(fd); 359 360 RegionStats_Constructor(Stats, *ne); 361 RegionStats_Read_Stats2(fd, *ne, *Stats); 362 RegionStats_Close_File(fd); 363 #else 364 nrerror("RegionStats_Load_Stats2 : REGION_STATS2 not defined"); 365 #endif 366 } 367 // ----------------------------------------------------------------------- 368 void RegionStats_MLoad_Stats1(char *filename, int *ne, RegionStats *Stats) 369 // ----------------------------------------------------------------------- 281 282 283 // -------------------------------------------------------------------------- 284 void RegionStats_MLoad_Stats1(char * filename, int * ne, RegionStats * Stats) 285 // -------------------------------------------------------------------------- 370 286 { 371 287 int fd; … … 377 293 RegionStats_Close_File(fd); 378 294 } 295 #endif 296 379 297 // ----------------------------------------------------------------------- 380 void RegionStats_ MLoad_Stats2(char *filename, int *ne, RegionStats *Stats)298 void RegionStats_Save_Stats1(RegionStats * Stats, int ne, char * filename) 381 299 // ----------------------------------------------------------------------- 382 {383 #ifdef REGION_STATS2384 int fd385 386 fd = RegionStats_Open_File(filename);387 388 *ne = RegionStats_Read_Header(fd);389 RegionStats_Read_Stats2(fd, *ne, Stats);390 RegionStats_Close_File(fd);391 #else392 nrerror("RegionStats_MLoad_Stats2 : REGION_STATS2 not defined");393 #endif394 }395 // ---------------------------------------------------------------------396 void RegionStats_Save_Stats1(RegionStats *Stats, int ne, char *filename)397 // ---------------------------------------------------------------------398 300 { 399 301 int fd; … … 405 307 RegionStats_Close_File(fd); 406 308 } 407 // --------------------------------------------------------------------- 408 void RegionStats_Save_Stats2(RegionStats *Stats, int ne, char *filename) 409 // --------------------------------------------------------------------- 410 { 411 #ifdef REGION_STATS2 412 int fd; 413 414 fd = RegionStats_Create_File(filename); 415 416 RegionStats_Write_Header(ne, fd); 417 RegionStats_Write_Stats2(Stats, ne, fd); 418 RegionStats_Close_File(fd); 419 #else 420 nrerror("RegionStats_Save_Stats2 : REGION_STATS2 not defined"); 421 #endif 422 } 423 // ----------------------------------------------------------------------- 424 void RegionStats_Save_pStats1(RegionStats **Stats, int ne, char *filename) 425 // ----------------------------------------------------------------------- 309 310 311 // ------------------------------------------------------------------------- 312 void RegionStats_Save_pStats1(RegionStats ** Stats, int ne, char * filename) 313 // ------------------------------------------------------------------------- 426 314 { 427 315 int fd; … … 433 321 RegionStats_Close_File(fd); 434 322 } 435 // ----------------------------------------------------------------------- 436 void RegionStats_Save_pStats2(RegionStats **Stats, int ne, char *filename) 437 // ----------------------------------------------------------------------- 438 { 439 #ifdef REGION_STATS2 440 int fd; 441 442 fd = RegionStats_Create_File(filename); 443 444 RegionStats_Write_Header(ne, fd); 445 RegionStats_Write_pStats2(Stats, ne, fd); 446 RegionStats_Close_File(fd); 447 #else 448 nrerror("RegionStats_Save_Stats2 : REGION_STATS2 not defined"); 449 #endif 450 } 451 // -------------------------------------------------------------------- 452 void RegionStats_Display_Stats1(RegionStats *Stats, int ne, char *name) 453 // -------------------------------------------------------------------- 454 { 455 int i; 456 323 324 325 // ---------------------------------------------------------------------- 326 void RegionStats_Display_Stats1(RegionStats * Stats, int ne, char * name) 327 // ---------------------------------------------------------------------- 328 { 457 329 if (name != NULL) { 458 330 printf("%s : %d\n", name, ne); … … 461 333 printf("RegionStats : %d\n", ne); 462 334 } 463 for (i = 1; i <= ne; i++) {335 for (int i = 1; i <= ne; i++) { 464 336 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n", 465 337 i, … … 473 345 } 474 346 } 475 // -------------------------------------------------------------------- 476 void RegionStats_Display_Stats2(RegionStats *Stats, int ne, char *name) 477 // -------------------------------------------------------------------- 478 { 479 #ifdef REGION_STATS2 480 int i; 481 347 348 349 // ------------------------------------------------------------------------ 350 void RegionStats_Display_pStats1(RegionStats ** Stats, int ne, char * name) 351 // ------------------------------------------------------------------------ 352 { 482 353 if (name != NULL) { 483 354 printf("%s : %d\n", name, ne); … … 486 357 printf("RegionStats : %d\n", ne); 487 358 } 488 489 for (i = 1; i <= ne; i++) { 490 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 491 i, 492 Stats[i].xmin, 493 Stats[i].xmax, 494 Stats[i].ymin, 495 Stats[i].ymax, 496 Stats[i].S, 497 Stats[i].Sx, 498 Stats[i].Sy, 499 500 (int32) Stats[i].Sx2, 501 (int32) Stats[i].Sxy, 502 (int32) Stats[i].Sy2); 503 504 } 505 #else 506 nrerror("RegionStats_Display_Stats2 : REGION_STATS2 not defined"); 507 #endif 508 } 509 // ---------------------------------------------------------------------- 510 void RegionStats_Display_pStats1(RegionStats **Stats, int ne, char *name) 511 // ---------------------------------------------------------------------- 512 { 513 int i; 514 515 if (name != NULL) { 516 printf("%s : %d\n", name, ne); 517 } 518 else { 519 printf("RegionStats : %d\n", ne); 520 } 521 for (i = 1; i <= ne; i++) { 359 for (int i = 1; i <= ne; i++) { 522 360 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d\n", 523 361 i, … … 531 369 } 532 370 } 533 // ---------------------------------------------------------------------- 534 void RegionStats_Display_pStats2(RegionStats **Stats, int ne, char *name) 535 // ---------------------------------------------------------------------- 536 { 537 #ifdef REGION_STATS2 538 int i; 539 540 if (name != NULL) { 541 printf("%s : %d\n", name, ne); 542 } 543 else { 544 printf("RegionStats : %d\n", ne); 545 } 546 for (i = 1; i <= ne; i++) { 547 printf("#%3d: %4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 548 i, 549 Stats[i]->xmin, 550 Stats[i]->xmax, 551 Stats[i]->ymin, 552 Stats[i]->ymax, 553 Stats[i]->S, 554 Stats[i]->Sx, 555 Stats[i]->Sy, 556 557 (int32) Stats[i]->Sx2, 558 (int32) Stats[i]->Sxy, 559 (int32) Stats[i]->Sy2); 560 561 } 562 #else 563 nrerror("RegionStats_Display_Stats2 : REGION_STATS2 not defined"); 564 #endif 565 } 566 // --------------------------------------------------------------------------------------------- 567 void RegionStats_SetRectangle(RegionStats *Stats, int e, int ymin, int ymax, int xmin, int xmax) 568 // --------------------------------------------------------------------------------------------- 371 372 373 // ---------------------------------------------------------------------------------------------- 374 void RegionStats_SetRectangle(RegionStats * Stats, int e, int ymin, int ymax, int xmin, int xmax) 375 // ---------------------------------------------------------------------------------------------- 569 376 { 570 377 Stats[e].ymin = ymin; … … 573 380 Stats[e].xmax = xmax; 574 381 } 575 // ------------------------------------------------------- 576 void RegionStats_Copy1(RegionStats *src, RegionStats *dst) 577 // ------------------------------------------------------- 382 383 384 // --------------------------------------------------------- 385 void RegionStats_Copy1(RegionStats * src, RegionStats * dst) 386 // --------------------------------------------------------- 578 387 { 579 388 dst->xmin = src->xmin; … … 584 393 dst->S = src->S; 585 394 586 dst->x = src->x;587 dst->y = src->y;588 589 395 dst->Sx = src->Sx; 590 396 dst->Sy = src->Sy; 591 592 #ifdef REGION_STATS2 593 dst->Sx2 = src->Sx2; 594 dst->Sxy = src->Sxy; 595 dst->Sy2 = src->Sy2; 596 dst->teta = src->teta; 597 #endif 598 599 #ifdef REGION_STATS3 600 dst->Sx3 = src->Sx3; 601 dst->Sx2y = src->Sx2y; 602 dst->Sxy2 = src->Sxy2; 603 dst->Sy3 = src->Sy3; 604 605 dst->Mx2 = src->Mx2; 606 dst->Mxy = src->Mxy; 607 dst->My2 = src->My2; 608 609 dst->Mx3 = src->Mx3; 610 dst->Mx2y = src->Mx2y; 611 dst->Mxy2 = src->Mxy2; 612 dst->My3 = src->My3; 613 #endif 614 } 397 } 398 399 615 400 // =============================== 616 401 // === nouvelles versions 2009 === 617 402 // =============================== 618 403 619 // ------------------------------------------- 620 RegionStats * RegionStatsVector(int i0, int i1)621 // ------------------------------------------- 404 // -------------------------------------------- 405 RegionStats * RegionStatsVector(int i0, int i1) 406 // -------------------------------------------- 622 407 // allocate a float vector with subscript range v[i0..i1] 623 408 { … … 625 410 626 411 v = (RegionStats *) malloc((size_t) ((i1 - i0 + 1 + NR_END) * sizeof(RegionStats))); 627 if (!v) nrerror("allocation failure in RegionStatsVector()"); 628 if (!v) return NULL; 412 if (!v) { 413 nrerror("allocation failure in %s()", __func__); 414 return NULL; 415 } 416 RegionStats_Clear(v, i1 - i0 + 1 + NR_END); 629 417 return v - i0 + NR_END; 630 418 } 631 // ---------------------------------------------------------- 632 RegionStats* RegionStatsVector0(int i0, int i1) 633 // ---------------------------------------------------------- 419 420 421 #if TARGET_OS == GIETVM 422 // ----------------------------------------------------------------- 423 RegionStats * remote_RegionStatsVector(int i0, int i1, int x, int y) 424 // ----------------------------------------------------------------- 634 425 // allocate a float vector with subscript range v[i0..i1] 635 426 { 636 RegionStats *v; 427 RegionStats * v; 428 429 v = (RegionStats *) remote_malloc((size_t) ((i1 - i0 + 1 + NR_END) * sizeof(RegionStats)), x, y); 430 if (!v) { 431 nrerror("allocation failure in %s()", __func__); 432 return NULL; 433 } 434 RegionStats_Clear(v, i1 - i0 + 1 + NR_END); 435 return v - i0 + NR_END; 436 } 437 #endif 438 439 440 // --------------------------------------------- 441 RegionStats * RegionStatsVector0(int i0, int i1) 442 // --------------------------------------------- 443 // allocate a float vector with subscript range v[i0..i1] 444 { 445 RegionStats * v; 637 446 638 447 v = (RegionStats *) calloc((size_t) (i1 - i0 + 1 + NR_END), sizeof(RegionStats)); 639 if (!v) nrerror("allocation failure in RegionStatsVector0()"); 640 if (!v) return NULL; 448 if (!v) { 449 nrerror("allocation failure in RegionStatsVector0()"); 450 return NULL; 451 } 641 452 return v - i0 + NR_END; 642 453 } 643 // ---------------------------------------------------------------------- 644 void free_RegionStatsVector(RegionStats *v, int i0, int i1) 645 // ---------------------------------------------------------- 454 455 456 // --------------------------------------------------------- 457 void free_RegionStatsVector(RegionStats * v, int i0, int i1) 458 // --------------------------------------------------------- 646 459 // free a RegionStats vector allocated with vector() 647 460 { 648 free((FREE_ARG) (v + i0 - NR_END)); 649 } 650 // ------------------------------------------------------------ 651 RegionStats** RegionStatsMatrix(int i0, int i1, int j0, int j1) 652 // ------------------------------------------------------------ 461 free(v + i0 - NR_END); 462 } 463 464 465 // ------------------------------------------------------------- 466 RegionStats ** RegionStatsMatrix(int i0, int i1, int j0, int j1) 467 // ------------------------------------------------------------- 653 468 654 469 // allocate a RegionStats matrix with subscript range m[nrl..nrh][ncl..nch] 470 { 471 long nrow = i1 - i0 + 1; 472 long ncol = j1 - j0 + 1; 473 RegionStats ** m; 474 475 // allocate pointers to rows 476 m = (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats *))); 477 if (!m) { 478 nrerror("allocation failure 1 in RegionStatsMatrix()"); 479 } 480 m += NR_END; 481 m -= i0; 482 483 // allocate rows and set pointers to them 484 m[i0] = (RegionStats *) malloc((size_t) ((nrow * ncol + NR_END) * sizeof(RegionStats))); 485 if (!m[i0]) { 486 nrerror("allocation failure 2 in RegionStatsMatrix()"); 487 } 488 m[i0] += NR_END; 489 m[i0] -= j0; 490 491 for (int i = i0 + 1; i <= i1; i++) { 492 m[i] = m[i - 1] + ncol; 493 } 494 495 // return pointer to array of pointers to rows 496 return m; 497 } 498 499 500 // -------------------------------------------------------------- 501 RegionStats ** RegionStatsMatrix0(int i0, int i1, int j0, int j1) 502 // -------------------------------------------------------------- 503 // allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] 655 504 { 656 505 long i; 657 506 long nrow = i1 - i0 + 1; 658 507 long ncol = j1 - j0 + 1; 659 RegionStats ** m;508 RegionStats ** m; 660 509 661 510 // allocate pointers to rows 662 m = (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats *))); 663 if (!m) nrerror("allocation failure 1 in RegionStatsMatrix()"); 511 m= (RegionStats **) malloc((size_t) ((nrow + NR_END) * sizeof(RegionStats*))); 512 if (!m) { 513 nrerror("allocation failure 1 in RegionStatsMatrix()"); 514 } 664 515 m += NR_END; 665 516 m -= i0; 666 517 667 518 // allocate rows and set pointers to them 668 m[i0] = (RegionStats *) malloc((size_t) ((nrow * ncol + NR_END) * sizeof(RegionStats))); 669 if (!m[i0]) nrerror("allocation failure 2 in RegionStatsMatrix()"); 519 m[i0] = (RegionStats *) calloc((size_t) (nrow * ncol + NR_END), sizeof(RegionStats)); 520 if (!m[i0]) { 521 nrerror("allocation failure 2 in RegionStatsMatrix()"); 522 } 670 523 m[i0] += NR_END; 671 524 m[i0] -= j0; 672 525 673 for (i = i0 + 1; i <= i1; i++) {526 for (i = i0 + 1; i <= i1; i++) { 674 527 m[i] = m[i - 1] + ncol; 675 528 } … … 678 531 return m; 679 532 } 680 // ------------------------------------------------------------- 681 RegionStats** RegionStatsMatrix0(int i0, int i1, int j0, int j1) 682 // ------------------------------------------------------------- 683 684 // allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] 685 { 686 long i, nrow=i1-i0+1,ncol=j1-j0+1; 687 RegionStats **m; 688 689 // allocate pointers to rows 690 m=(RegionStats**) malloc((size_t)((nrow+NR_END)*sizeof(RegionStats*))); 691 if (!m) nrerror("allocation failure 1 in RegionStatsMatrix()"); 692 m += NR_END; 693 m -= i0; 694 695 // allocate rows and set pointers to them 696 m[i0]=(RegionStats*) calloc((size_t)(nrow*ncol+NR_END), sizeof(RegionStats)); 697 if (!m[i0]) nrerror("allocation failure 2 in RegionStatsMatrix()"); 698 m[i0] += NR_END; 699 m[i0] -= j0; 700 701 for(i=i0+1;i<=i1;i++) m[i]=m[i-1]+ncol; 702 703 // return pointer to array of pointers to rows 704 return m; 705 } 706 // ------------------------------------------------------------------------- 707 void free_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1) 708 // ------------------------------------------------------------------------- 709 { 710 free((FREE_ARG) (m[i0]+j0-NR_END)); 711 free((FREE_ARG) (m+i0-NR_END)); 712 } 713 // ---------------------------------- 714 void zero_RegionStats(RegionStats *x) 715 // ---------------------------------- 533 534 535 // -------------------------------------------------------------------------- 536 void free_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1) 537 // -------------------------------------------------------------------------- 538 { 539 free(m[i0] + j0 - NR_END); 540 free(m + i0 - NR_END); 541 } 542 543 544 // ----------------------------------- 545 void zero_RegionStats(RegionStats * x) 546 // ----------------------------------- 716 547 { 717 548 x->xmin = 32767; … … 723 554 x->Sx = 0; 724 555 x->Sy = 0; 725 726 #ifdef REGION_STATS2 727 x->Sx2 = 0; 728 x->Sxy = 0; 729 x->Sy2 = 0; 730 #endif 731 } 732 // -------------------------------------------------------- 733 void zero_RegionStatsVector(RegionStats *v, int i0, int i1) 734 // -------------------------------------------------------- 735 { 736 int i; 737 for(i=i0; i<=i1; i++) { 556 } 557 558 559 // --------------------------------------------------------- 560 void zero_RegionStatsVector(RegionStats * v, int i0, int i1) 561 // --------------------------------------------------------- 562 { 563 for (int i = i0; i <= i1; i++) { 738 564 zero_RegionStats(&v[i]); 739 565 } 740 566 } 741 // ------------------------------------------------------------------------- 742 void zero_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1) 743 // ------------------------------------------------------------------------- 744 { 745 int i, j; 746 for(i=i0; i<=i1; i++) { 747 for(j=j0; j<=j1; j++) { 567 568 569 // -------------------------------------------------------------------------- 570 void zero_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1) 571 // -------------------------------------------------------------------------- 572 { 573 for (int i = i0; i <= i1; i++) { 574 for (int j = j0; j <= j1; j++) { 748 575 zero_RegionStats(&(m[i][j])); 749 576 } 750 577 } 751 578 } 752 // ------------------------------------------------- 753 void display_RegionStats(RegionStats *x, char *name) 754 // ------------------------------------------------- 755 { 756 if(name != NULL) printf("%s : \n", name); 757 758 #ifndef REGION_STATS2 579 580 581 // --------------------------------------------------- 582 void display_RegionStats(RegionStats * x, char * name) 583 // --------------------------------------------------- 584 { 585 if (name != NULL) { 586 printf("%s : \n", name); 587 } 588 759 589 printf("%4d %4d %4d %4d %6d %8d %8d\n", 760 590 x->xmin, … … 766 596 x->Sx, 767 597 x->Sy); 768 #else 769 printf("%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 770 x->xmin, 771 x->xmax, 772 x->ymin, 773 x->ymax, 774 775 x->S, 776 x->Sx, 777 x->Sy, 778 779 x->Sx2, 780 x->Sxy, 781 x->Sy2); 782 #endif 783 } 784 // ----------------------------------------------------------------------- 785 void display_RegionStatsVector(RegionStats *v, int i0, int i1, char *name) 786 // ----------------------------------------------------------------------- 787 { 788 int i; 789 790 if(name != NULL) printf("%s : [%d..%d]\n", name, i0, i1); else printf("RegionStats : [%d..%d]\n", i0, i1); 791 for(i=i0; i<=i1; i++) { 598 } 599 600 601 // ------------------------------------------------------------------------ 602 void display_RegionStatsVector(RegionStats * v, int i0, int i1, char *name) 603 // ------------------------------------------------------------------------ 604 { 605 if (name != NULL) { 606 printf("%s : [%d..%d]\n", name, i0, i1); 607 } 608 else { 609 printf("RegionStats : [%d..%d]\n", i0, i1); 610 } 611 for (int i = i0; i <= i1; i++) { 792 612 printf("#%3d: ", i); 793 613 display_RegionStats(&(v[i]), NULL); 794 //puts(""); 795 } 796 } 797 // ---------------------------------------------------------------------------------------- 798 void display_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name) 799 // ---------------------------------------------------------------------------------------- 800 { 801 int i, j; 802 803 if (name != NULL) printf("%s : [%d..%d][%d..%d]\n", name, i0, i1, j0, j1); else printf("RegionStats : [%d..%d][%d..%d]\n", i0, i1, j0, j1); 804 for (i = i0; i <= i1; i++) { 805 for (j = j0; j <= j1; j++) { 614 } 615 } 616 617 618 // ------------------------------------------------------------------------------------------ 619 void display_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name) 620 // ------------------------------------------------------------------------------------------ 621 { 622 623 if (name != NULL) { 624 printf("%s : [%d..%d][%d..%d]\n", name, i0, i1, j0, j1); 625 } 626 else { 627 printf("RegionStats : [%d..%d][%d..%d]\n", i0, i1, j0, j1); 628 } 629 for (int i = i0; i <= i1; i++) { 630 for (int j = j0; j <= j1; j++) { 806 631 printf("#%3d: ", i); 807 632 display_RegionStats(&(m[i][j]), NULL); … … 809 634 } 810 635 } 811 // ---------------------------------------------- 812 void save_RegionStats(RegionStats *x, char *name) 813 // ---------------------------------------------- 636 637 638 // ------------------------------------------------ 639 void save_RegionStats(RegionStats * x, char * name) 640 // ------------------------------------------------ 814 641 { 815 642 int fd = -1; 643 char buff[BUFF_SIZE]; 816 644 817 645 if (name == NULL) { … … 824 652 printf("*** Erreur : ouverture du fichier %s dans %s\n", name, __func__); 825 653 } 826 fprintf(fd, "%s: ", name); 827 828 #ifndef REGION_STATS2 829 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d\n", 830 654 snprintf(buff, BUFF_SIZE, "%s: %4d %4d %4d %4d %6d %8d %8d\n", 655 name, 831 656 x->xmin, 832 657 x->xmax, … … 837 662 x->Sx, 838 663 x->Sy); 839 #else 840 fprintf(fd, "%4d %4d %4d %4d %6d %8d %8d %8d %8d %8d\n", 841 842 x->xmin, 843 x->xmax, 844 x->ymin, 845 x->ymax, 846 847 x->S, 848 x->Sx, 849 x->Sy, 850 851 x->Sx2, 852 x->Sxy, 853 x->Sy2); 854 #endif 664 write(fd, buff, strlen(buff) + 1); 855 665 856 666 if (name) { … … 858 668 } 859 669 } 860 // -------------------------------------------------------------------- 861 void save_RegionStatsVector(RegionStats *v, int i0, int i1, char *name) 862 // -------------------------------------------------------------------- 863 { 864 int i; 670 671 672 // ---------------------------------------------------------------------- 673 void save_RegionStatsVector(RegionStats * v, int i0, int i1, char * name) 674 // ---------------------------------------------------------------------- 675 { 865 676 int fd; 677 char buff[BUFF_SIZE]; 866 678 867 679 if (name == NULL) { … … 870 682 fd = RegionStats_Create_File(name); 871 683 872 fprintf(fd, "%s : [%d..%d]\n", name, i0, i1); 873 874 for (i = i0; i <= i1; i++) { 684 snprintf(buff, BUFF_SIZE, "%s : [%d..%d]\n", name, i0, i1); 685 write(fd, buff, strlen(buff) + 1); 686 687 for (int i = i0; i <= i1; i++) { 875 688 printf("#%3d: ", i); 876 689 save_RegionStats(&v[i], NULL); 877 printf("");878 690 } 879 691 RegionStats_Close_File(fd); 880 692 } 881 // ------------------------------------------------------------------------------------- 882 void save_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name) 883 // ------------------------------------------------------------------------------------- 884 { 885 int i, j; 693 694 695 // --------------------------------------------------------------------------------------- 696 void save_RegionStatsMatrix(RegionStats ** m, int i0, int i1, int j0, int j1, char * name) 697 // --------------------------------------------------------------------------------------- 698 { 886 699 int fd; 700 char buff[BUFF_SIZE]; 887 701 888 702 if (name == NULL) { … … 891 705 fd = RegionStats_Create_File(name); 892 706 893 fprintf(fd, "%s : [%d..%d]\n", name, i0, i1); 894 895 for (i = i0; i <= i1; i++) { 896 for (j = j0; j <= j1; j++) { 897 fprintf(fd, "#%3d: ", i); 707 snprintf(buff, BUFF_SIZE, "%s : [%d..%d]\n", name, i0, i1); 708 write(fd, buff, strlen(buff) + 1); 709 710 for (int i = i0; i <= i1; i++) { 711 for (int j = j0; j <= j1; j++) { 712 snprintf(buff, BUFF_SIZE, "#%3d: ", i); 713 write(fd, buff, strlen(buff) + 1); 898 714 save_RegionStats(&m[i][j], NULL); 899 715 } 900 printf("");901 716 } 902 717 RegionStats_Close_File(fd); 903 718 } 904 // ------------------------------------------------------------------------------ 905 void RegionStats_Calc1_Features_1Pass(RegionStats *Stats, uint32 e, int i, int j) 906 // ------------------------------------------------------------------------------ 719 720 721 // ------------------------------------------------------------------------------- 722 void RegionStats_Calc1_Features_1Pass(RegionStats * Stats, uint32 e, int i, int j) 723 // ------------------------------------------------------------------------------- 907 724 { 908 725 // calcul sur 1 point et non sur toute l'image 909 726 // Rectangle 910 727 911 if (i < Stats[e].ymin) Stats[e].ymin = i; 912 if (i > Stats[e].ymax) Stats[e].ymax = i; 913 914 if (j < Stats[e].xmin) Stats[e].xmin = j; 915 if (j > Stats[e].xmax) Stats[e].xmax = j; 728 if (i < Stats[e].ymin) { 729 Stats[e].ymin = i; 730 } 731 if (i > Stats[e].ymax) { 732 Stats[e].ymax = i; 733 } 734 735 if (j < Stats[e].xmin) { 736 Stats[e].xmin = j; 737 } 738 if (j > Stats[e].xmax) { 739 Stats[e].xmax = j; 740 } 916 741 917 742 // Moment1 … … 922 747 return; 923 748 } 749 750 924 751 // -------------------------------- 925 752 // --- fonctions de 2013 ---------- 926 753 // -------------------------------- 927 // ------------------------------------------------------------------------------------------- 928 void RegionStats_Calc_Rectangle_Moment1(uint32 **E, int height, int width, RegionStats *Stats) 929 // ------------------------------------------------------------------------------------------- 930 { 931 int i, j; 754 // --------------------------------------------------------------------------------------------- 755 void RegionStats_Calc_Rectangle_Moment1(uint32 ** E, int height, int width, RegionStats * Stats) 756 // --------------------------------------------------------------------------------------------- 757 { 932 758 uint32 x, y; 933 759 uint32 e; 934 760 935 for (i = 0; i < height; i++) {936 for ( j = 0; j < width; j++) {761 for (int i = 0; i < height; i++) { 762 for (int j = 0; j < width; j++) { 937 763 938 764 e = E[i][j]; 939 765 if (e) { 940 941 766 x = j; 942 767 y = i; 943 768 944 if (i<Stats[e].ymin) Stats[e].ymin = y; 945 if (i>Stats[e].ymax) Stats[e].ymax = y; 769 if (i < Stats[e].ymin) { 770 Stats[e].ymin = y; 771 } 772 if (i > Stats[e].ymax) { 773 Stats[e].ymax = y; 774 } 946 775 947 if (j<Stats[e].xmin) Stats[e].xmin = x; 948 if (j>Stats[e].xmax) Stats[e].xmax = x; 776 if (j < Stats[e].xmin) { 777 Stats[e].xmin = x; 778 } 779 if (j > Stats[e].xmax) { 780 Stats[e].xmax = x; 781 } 949 782 950 783 Stats[e].S += 1; … … 955 788 } 956 789 } 957 // ----------------------------------------------------------------------------------------------------------------------------- 958 void RegionStats_calc_Status(RegionStats *Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 *status) 959 // ----------------------------------------------------------------------------------------------------------------------------- 790 791 792 // ------------------------------------------------------------------------------------------------------------------------------- 793 void RegionStats_calc_Status(RegionStats * Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 * status) 794 // ------------------------------------------------------------------------------------------------------------------------------- 960 795 { 961 796 uint16 xmin, xmax, ymin, ymax, xsize, ysize; … … 983 818 } 984 819 } 985 // -------------------------------------------------------------------------- 986 uint32 RegionStats_UpdateEQ_with_Status(uint8 *status, uint32 ne, uint32 *EQ) 987 // -------------------------------------------------------------------------- 820 821 822 // ---------------------------------------------------------------------------- 823 uint32 RegionStats_UpdateEQ_with_Status(uint8 * status, uint32 ne, uint32 * EQ) 824 // ---------------------------------------------------------------------------- 988 825 { 989 826 uint32 e; … … 999 836 return na; 1000 837 } 1001 // ---------------------------------------------------------------------------- 1002 void RegionStats_UpdateStats_with_EQ(uint32 *EQ, uint32 ne, RegionStats *Stats) 1003 // ---------------------------------------------------------------------------- 838 839 840 // ------------------------------------------------------------------------------ 841 void RegionStats_UpdateStats_with_EQ(uint32 * EQ, uint32 ne, RegionStats * Stats) 842 // ------------------------------------------------------------------------------ 1004 843 { 1005 844 uint32 e, a; … … 1015 854 } 1016 855 } 1017 // --------------------------------------------------------------------------- 1018 void featuresComputation(uint32 **E, int height,int width, RegionStats *Stats) 1019 // --------------------------------------------------------------------------- 856 857 858 // ----------------------------------------------------------------------------- 859 void featuresComputation(uint32 ** E, int height,int width, RegionStats * Stats) 860 // ----------------------------------------------------------------------------- 1020 861 { 1021 862 //uint32 nemax = height * width /2; 1022 863 RegionStats_Calc_Rectangle_Moment1(E, height, width, Stats); 1023 864 } 1024 // ------------------------------------------------------------------------------ 1025 void pointFeaturesComputation_Dummy(uint32 **E, int i, int j, RegionStats *Stats) 1026 // ------------------------------------------------------------------------------ 1027 { 1028 // pour pointeur de fonction 1029 return; 1030 } 1031 // ------------------------------------------------------------------------- 1032 void pointFeaturesComputation( uint32 **E, int i, int j, RegionStats *Stats) 1033 // ------------------------------------------------------------------------- 865 866 867 // --------------------------------------------------------------------------- 868 void pointFeaturesComputation( uint32 ** E, int i, int j, RegionStats * Stats) 869 // --------------------------------------------------------------------------- 1034 870 { 1035 871 uint32 x, y; … … 1042 878 y = i; 1043 879 1044 if (i<Stats[e].ymin) Stats[e].ymin = y; 1045 if (i>Stats[e].ymax) Stats[e].ymax = y; 1046 1047 if (j<Stats[e].xmin) Stats[e].xmin = x; 1048 if (j>Stats[e].xmax) Stats[e].xmax = x; 880 if (i < Stats[e].ymin) { 881 Stats[e].ymin = y; 882 } 883 if (i > Stats[e].ymax) { 884 Stats[e].ymax = y; 885 } 886 887 if (j < Stats[e].xmin) { 888 Stats[e].xmin = x; 889 } 890 if (j > Stats[e].xmax) { 891 Stats[e].xmax = x; 892 } 1049 893 1050 894 Stats[e].S += 1; … … 1053 897 } 1054 898 } 1055 // ---------------------------------------------------------------------------------- 1056 void lineFeaturesComputation_Dummy( uint32 **E, int i, int width, RegionStats *Stats) 1057 // ---------------------------------------------------------------------------------- 1058 { 1059 // pour pointeur de fonction 1060 return; 1061 } 1062 // ---------------------------------------------------------------------------- 1063 void lineFeaturesComputation( uint32 **E, int i, int width, RegionStats *Stats) 1064 // ---------------------------------------------------------------------------- 899 900 901 // ----------------------------------------------------------------------------- 902 void lineFeaturesComputation(uint32 ** E, int i, int width, RegionStats * Stats) 903 // ----------------------------------------------------------------------------- 1065 904 { 1066 905 // line RegionStats_Calc_Rectangle_Moment1 1067 int j;1068 906 1069 907 uint32 x, y; 1070 908 uint32 e; 1071 909 1072 for ( j = 0; j < width; j++) {910 for (int j = 0; j < width; j++) { 1073 911 1074 912 e = E[i][j]; … … 1078 916 y = i; 1079 917 1080 if (i<Stats[e].ymin) Stats[e].ymin = y; 1081 if (i>Stats[e].ymax) Stats[e].ymax = y; 918 if (i < Stats[e].ymin) { 919 Stats[e].ymin = y; 920 } 921 if (i > Stats[e].ymax) { 922 Stats[e].ymax = y; 923 } 1082 924 1083 if (j<Stats[e].xmin) Stats[e].xmin = x; 1084 if (j>Stats[e].xmax) Stats[e].xmax = x; 925 if (j < Stats[e].xmin) { 926 Stats[e].xmin = x; 927 } 928 if (j > Stats[e].xmax) { 929 Stats[e].xmax = x; 930 } 1085 931 1086 932 Stats[e].S += 1; … … 1090 936 } 1091 937 } 1092 // ------------------------------------------------------------------------------------------ 1093 void bandFeaturesComputation_Dummy(uint32 **E, int i0, int i1, int width, RegionStats *Stats) 1094 // ------------------------------------------------------------------------------------------ 1095 { 1096 return; 1097 } 1098 // ------------------------------------------------------------------------------------ 1099 void bandFeaturesComputation(uint32 **E, int i0, int i1, int width, RegionStats *Stats) 1100 // ------------------------------------------------------------------------------------ 1101 { 1102 int i; 1103 for (i = i0; i <= i1; i++) { 938 939 940 // -------------------------------------------------------------------------------------- 941 void bandFeaturesComputation(uint32 ** E, int i0, int i1, int width, RegionStats * Stats) 942 // -------------------------------------------------------------------------------------- 943 { 944 for (int i = i0; i <= i1; i++) { 1104 945 lineFeaturesComputation(E, i, width, Stats); 1105 946 } 1106 947 } 1107 // --------------------------------------------------------------------------------------- 1108 void imageFeaturesComputation_Dummy(uint32 **E, int height, int width, RegionStats *Stats) 1109 // --------------------------------------------------------------------------------------- 1110 { 1111 // pour pointeur de fonction 1112 return; 1113 } 1114 // --------------------------------------------------------------------------------- 1115 void imageFeaturesComputation(uint32 **E, int height, int width, RegionStats *Stats) 1116 // --------------------------------------------------------------------------------- 948 949 950 // ----------------------------------------------------------------------------------- 951 void imageFeaturesComputation(uint32 ** E, int height, int width, RegionStats * Stats) 952 // ----------------------------------------------------------------------------------- 1117 953 { 1118 954 // image RegionStats_Calc_Rectangle_Moment1 1119 int i; 1120 for (i = 0; i < height; i++) { 955 for (int i = 0; i < height; i++) { 1121 956 lineFeaturesComputation(E, i, width, Stats); 1122 957 } 1123 958 } 959 960 1124 961 // --------------------------------------- 1125 962 // --- Fonctions 2014 -------------------- 1126 963 // --------------------------------------- 1127 964 1128 // -------------------------------------------------------------------------------------- 1129 void RegionStats_Copy_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index)1130 // -------------------------------------------------------------------------------------- 965 // --------------------------------------------------------------------------------------- 966 void RegionStats_Copy_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index) 967 // --------------------------------------------------------------------------------------- 1131 968 { 1132 969 // R[dst] = R[src] 1133 970 RegionStats_Copy1(&Stats[src_index], &Stats[dst_index]); 1134 971 } 1135 // -------------------------------------------------------------------------------------------- 1136 void RegionStats_Accumulate_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index) 1137 // -------------------------------------------------------------------------------------------- 972 973 974 // --------------------------------------------------------------------------------------------- 975 void RegionStats_Accumulate_Stats1_From_Index(RegionStats * Stats, int dst_index, int src_index) 976 // --------------------------------------------------------------------------------------------- 1138 977 { 1139 978 // R[dst] += R[src] … … 1147 986 Stats[dst_index].Sy += Stats[src_index].Sy; 1148 987 } 1149 // ----------------------------------------------------------------------------------------------------- 1150 void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name) 1151 // ----------------------------------------------------------------------------------------------------- 988 989 990 // --------------------------------------------------------------------------------------------------------------------------- 991 void RegionStats_DisplayStats_Sparse(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name, int * start_index) 992 // --------------------------------------------------------------------------------------------------------------------------- 1152 993 { 1153 994 // n'affiche que les racines. … … 1156 997 uint32 na; // compteur 1157 998 1158 if (name) printf(name); 1159 1160 na = RegionStats_Count_Roots_Sparse(Stats, EQ, ne0, ne1); 1161 printf("%d\n", na); 999 if (name) { 1000 printf(name); 1001 } 1002 1003 //na = RegionStats_Count_Roots_Sparse(Stats, EQ, ne0, ne1); 1004 //printf("%d\n", na); 1162 1005 1163 1006 for (e = ne0; e <= ne1; e++) { 1164 if ((e == EQ[e]) && (Stats[e].S > 0)) { 1165 printf("%5d ", e); 1007 if (e == EQ[e] && Stats[e].S > 0) { 1008 if (start_index != NULL) { 1009 printf("%5d ", *start_index); 1010 *start_index = *start_index + 1; 1011 } 1012 else { 1013 printf("%5d ", e); 1014 } 1166 1015 display_RegionStats(&Stats[e], NULL); 1167 1016 } 1168 1017 } 1169 1018 } 1170 // ---------------------------------------------------------------------------------------------------- 1171 void RegionStats_DisplayStats_Range(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name) 1172 // ---------------------------------------------------------------------------------------------------- 1019 1020 1021 // ------------------------------------------------------------------------------------------------------- 1022 void RegionStats_DisplayStats_Range(uint32 * EQ, uint32 ne0, uint32 ne1, RegionStats * Stats, char * name) 1023 // ------------------------------------------------------------------------------------------------------- 1173 1024 { 1174 1025 // affichage dense (apres un pack) … … 1176 1027 uint32 e; 1177 1028 1178 if (name) printf(name); 1029 if (name) { 1030 printf(name); 1031 } 1179 1032 1180 1033 for (e = ne0; e <= ne1; e++) { … … 1183 1036 } 1184 1037 } 1185 // -------------------------------------------------------------------------------------------------------- 1186 void RegionStats_Save_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, char *filename) 1187 // -------------------------------------------------------------------------------------------------------- 1038 1039 1040 // ----------------------------------------------------------------------------------------------------------- 1041 void RegionStats_Save_Stats1_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1, char * filename) 1042 // ----------------------------------------------------------------------------------------------------------- 1188 1043 { 1189 1044 int fd; … … 1197 1052 RegionStats_Close_File(fd); 1198 1053 } 1199 // ------------------------------------------------------------------------------------------ 1200 uint32 RegionStats_Count_Roots_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1) 1201 // ------------------------------------------------------------------------------------------ 1054 1055 1056 // -------------------------------------------------------------------------------------------- 1057 uint32 RegionStats_Count_Roots_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1) 1058 // -------------------------------------------------------------------------------------------- 1202 1059 { 1203 1060 uint32 e, c = 0; // compteur … … 1210 1067 return c; 1211 1068 } 1212 // --------------------------------------------------------------------------------- 1213 uint32 RegionStats_Count_Roots_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax) 1214 // --------------------------------------------------------------------------------- 1069 1070 1071 // ----------------------------------------------------------------------------------- 1072 uint32 RegionStats_Count_Roots_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax) 1073 // ----------------------------------------------------------------------------------- 1215 1074 { 1216 1075 return RegionStats_Count_Roots_Sparse(Stats, EQ, 1, nemax); 1217 1076 } 1218 // ------------------------------------------------------------------------------------------- 1219 uint32 RegionStats_Count_Labels_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1) 1220 // ------------------------------------------------------------------------------------------- 1077 1078 1079 // --------------------------------------------------------------------------------------------- 1080 uint32 RegionStats_Count_Labels_Sparse(RegionStats * Stats, uint32 * EQ, uint32 ne0, uint32 ne1) 1081 // --------------------------------------------------------------------------------------------- 1221 1082 { 1222 1083 uint32 e, c = 0; // compteur … … 1229 1090 return c; 1230 1091 } 1231 // ----------------------------*----------------------------------------------------- 1232 uint32 RegionStats_Count_Labels_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax) 1233 // ---------------------------*------------------------------------------------------ 1092 1093 1094 // ------------------------------------------------------------------------------------ 1095 uint32 RegionStats_Count_Labels_Sparse1(RegionStats * Stats, uint32 * EQ, uint32 nemax) 1096 // ------------------------------------------------------------------------------------ 1234 1097 { 1235 1098 return RegionStats_Count_Labels_Sparse(Stats, EQ, 1, nemax); 1236 1099 } 1237 // --------------------------------------------------------------------- 1238 void copy_features_ui32matrix(RegionStats *Stats, uint32 ne, uint32 **m) 1239 // --------------------------------------------------------------------- 1240 { 1241 int i; 1242 for (i = 0; i <= (int) ne; i++) { 1100 1101 1102 // ----------------------------------------------------------------------- 1103 void copy_features_ui32matrix(RegionStats * Stats, uint32 ne, uint32 ** m) 1104 // ----------------------------------------------------------------------- 1105 { 1106 for (int i = 0; i <= (int) ne; i++) { 1243 1107 1244 1108 m[i][0] = i; … … 1260 1124 } 1261 1125 } 1262 // --------------------------------------------------------------------- 1263 void copy_ui32matrix_features(uint32 **m, uint32 ne, RegionStats *Stats) 1264 // --------------------------------------------------------------------- 1265 { 1266 int i; 1267 for (i = 0; i <= (int) ne; i++) { 1126 1127 1128 // ----------------------------------------------------------------------- 1129 void copy_ui32matrix_features(uint32 ** m, uint32 ne, RegionStats * Stats) 1130 // ----------------------------------------------------------------------- 1131 { 1132 for (int i = 0; i <= (int) ne; i++) { 1268 1133 1269 1134 Stats[i].xmin = m[i][2] >> 16; … … 1277 1142 } 1278 1143 } 1279 // --------------------------------------------------------------------------- 1280 void sortv_ui32matrix_col(uint32 **m, int i0, int i1, int j0, int j1, int col) 1281 // --------------------------------------------------------------------------- 1144 1145 1146 // ---------------------------------------------------------------------------- 1147 void sortv_ui32matrix_col(uint32 ** m, int i0, int i1, int j0, int j1, int col) 1148 // ---------------------------------------------------------------------------- 1282 1149 { 1283 1150 // nrsort2 for NRC2 … … 1294 1161 * instead of copying the lines. 1295 1162 */ 1296 int i, j;1297 1163 1298 1164 uint32 x, min, pos; 1299 1165 uint32 * ptr; 1300 1166 1301 for (i = nrl; i < nrh; i++) {1167 for (int i = nrl; i < nrh; i++) { 1302 1168 min = m[i][nc]; 1303 1169 pos = i; 1304 for ( j = i + 1; j <= nrh; j++) {1170 for (int j = i + 1; j <= nrh; j++) { 1305 1171 x = m[j][nc]; 1306 1172 if (x < min) { … … 1314 1180 m[i] = m[pos]; 1315 1181 m[pos] = ptr; 1316 1317 1182 } // i 1318 1319 } 1320 // ------------------------------------------------------------ 1321 void RegionStats_SortFeatures(RegionStats *Stats, uint32 nemax) 1322 // ------------------------------------------------------------ 1183 } 1184 1185 1186 // ------------------------------------------------------------- 1187 void RegionStats_SortFeatures(RegionStats * Stats, uint32 nemax) 1188 // ------------------------------------------------------------- 1323 1189 { 1324 1190 uint32 ** m = NULL; … … 1330 1196 copy_ui32matrix_features(m, nemax, Stats); 1331 1197 } 1332 // -------------------------------------------------------------------------------------- 1333 void imageFeaturesComputation_omp0(uint32 **E, int height, int width, RegionStats *Stats) 1334 // -------------------------------------------------------------------------------------- 1335 { 1336 // version OpenMP 2.0 fausse (sans serialisation de la section critique) 1337 // pour evaluer l'impact de la synchro 1338 int i, j; 1339 1340 uint32 x, y; 1341 uint32 e; 1342 1343 #ifdef OPENMP 1344 #pragma omp parallel for private(height, width, i, j, x, y, e) shared (E, Stats) 1345 #endif 1346 for (i = 0; i < height; i++) { 1347 for (j = 0; j < width; j++) { 1348 1349 e = E[i][j]; 1350 if (e) { 1351 1352 x = j; 1353 y = i; 1354 1355 // min max reduction 1356 if (y < Stats[e].ymin) Stats[e].ymin = y; 1357 if (y > Stats[e].ymax) Stats[e].ymax = y; 1358 1359 if (x < Stats[e].xmin) Stats[e].xmin = x; 1360 if (x > Stats[e].xmax) Stats[e].xmax = x; 1361 1362 // + reduction 1363 Stats[e].S += 1; 1364 Stats[e].Sx += x; 1365 Stats[e].Sy += y; 1366 } 1367 } 1368 } 1369 } 1370 // -------------------------------------------------------------------------------------- 1371 void imageFeaturesComputation_omp2(uint32** E, int height, int width, RegionStats* Stats) 1372 // -------------------------------------------------------------------------------------- 1373 { 1374 // version OpenMP 2.0 classique avec "critical" 1375 1376 int i, j; 1377 1378 uint32 x, y; 1379 uint32 e; 1380 1381 1382 #ifdef OPENMP 1383 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1384 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1385 //#pragma omp for private (j) 1386 #endif 1387 for (i = 0; i < height; i++) { 1388 //printf("i = %d\n", i); 1389 //printf("omp_get_num_threads = %d\n", omp_get_num_threads()); 1390 1391 for (j = 0; j < width; j++) { 1392 1393 e = E[i][j]; 1394 if (e) { 1395 1396 x = j; 1397 y = i; 1398 1399 #ifdef OPENMP 1400 #pragma omp critical 1401 #endif 1402 { 1403 // min max reduction 1404 if (y < Stats[e].ymin) Stats[e].ymin = y; 1405 if (y > Stats[e].ymax) Stats[e].ymax = y; 1406 1407 if (x < Stats[e].xmin) Stats[e].xmin = x; 1408 if (x > Stats[e].xmax) Stats[e].xmax = x; 1409 1410 // + reduction 1411 Stats[e].S += 1; 1412 Stats[e].Sx += x; 1413 Stats[e].Sy += y; 1414 } // omp critical 1415 } // if e 1416 } // j 1417 } // i 1418 } 1419 // -------------------------------------------------------------------------------------- 1420 void imageFeaturesComputation_omp3(uint32** E, int height, int width, RegionStats* Stats) 1421 // -------------------------------------------------------------------------------------- 1422 { 1423 // version OpenMP 2.0 classique avec "critical" (from Laurent Cabaret with optimal use of critical and atomic) 1424 1425 int i, j; 1426 1427 uint32 x, y; 1428 uint32 e; 1429 1430 1431 #ifdef OPENMP 1432 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1433 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1434 #endif 1435 for (i = 0; i < height; i++) { 1436 1437 for (j = 0; j < width; j++) { 1438 1439 e = E[i][j]; 1440 if (e) { 1441 1442 x = j; 1443 y = i; 1444 1445 #ifdef OPENMP 1446 #pragma omp critical 1447 #endif 1448 { 1449 // min max reduction 1450 if (y < Stats[e].ymin) Stats[e].ymin = y; 1451 if (y > Stats[e].ymax) Stats[e].ymax = y; 1452 } 1453 #ifdef OPENMP 1454 #pragma omp critical 1455 #endif 1456 { 1457 if (x < Stats[e].xmin) Stats[e].xmin = x; 1458 if (x > Stats[e].xmax) Stats[e].xmax = x; 1459 } 1460 // + reduction 1461 #ifdef OPENMP 1462 #pragma omp atomic 1463 #endif 1464 Stats[e].S += 1; 1465 1466 #ifdef OPENMP 1467 #pragma omp atomic 1468 #endif 1469 Stats[e].Sx += x; 1470 1471 #ifdef OPENMP 1472 #pragma omp atomic 1473 Stats[e].Sy += y; 1474 #endif 1475 } // if e 1476 } // j 1477 } // i 1478 } 1479 // -------------------------------------------------------------------------------------------- 1480 void imageFeaturesComputation_range_omp2(uint32** E, int height, int width, RegionStats* Stats) 1481 // -------------------------------------------------------------------------------------------- 1482 { 1483 // version OpenMP 2.0 1484 1485 int i, j; 1486 1487 uint32 x, y; 1488 uint32 e; 1489 1490 1491 #ifdef OPENMP 1492 //#pragma omp parallel for private(height, width, i, j, x, y, e) shared(E, Stats) 1493 #pragma omp parallel for shared(E, Stats) private(height, width, i, j, x, y, e) schedule(dynamic) 1494 //#pragma omp for private (j) 1495 #endif 1496 for (i = 0; i < height; i++) { 1497 //printf("i = %d\n", i); 1498 //printf("omp_get_num_threads = %d\n", omp_get_num_threads()); 1499 1500 for (j = 0; j < width; j++) { 1501 1502 e = E[i][j]; 1503 if (e) { 1504 1505 x = j; 1506 y = i; 1507 1508 #ifdef OPENMP 1509 #pragma omp critical 1510 #endif 1511 { 1512 // min max reduction 1513 if (y < Stats[e].ymin) Stats[e].ymin = y; 1514 if (y > Stats[e].ymax) Stats[e].ymax = y; 1515 1516 if (x < Stats[e].xmin) Stats[e].xmin = x; 1517 if (x > Stats[e].xmax) Stats[e].xmax = x; 1518 1519 // + reduction 1520 Stats[e].S += 1; 1521 Stats[e].Sx += x; 1522 Stats[e].Sy += y; 1523 } // omp critical 1524 } // if e 1525 } // j 1526 } // i 1527 } 1528 // -------------------------------------------------------------------------------------------------------- 1529 void imageFeaturesComputation_omp4(uint32** restrict E, int height, int width, RegionStats* restrict Stats) 1530 // -------------------------------------------------------------------------------------------------------- 1531 { 1532 // version avec "task" (OpenMP 3.0) et "depend" (OpenMP 4.0) 1533 #ifdef OPENMP 1534 #pragma omp parallel private(height,width) shared(E,Stats) 1535 { 1536 #endif // OPENMP 1537 int i, j; 1538 1539 uint32 x, y; 1540 uint32 e; 1541 1542 #ifdef OPENMP4 1543 //#pragma omp task depend ( in:E[0:height-1][0:width-1]) depend( inout: E[1:height*width/4]) 1544 #pragma omp task depend( inout: E[1:height*width/4]) 1545 #endif 1546 for (i = 0; i < height; i++) { 1547 for (j = 0; j < width; j++) { 1548 1549 e = E[i][j]; 1550 if (e) { 1551 1552 x = j; 1553 y = i; 1554 1555 1556 // min max reduction 1557 if (y < Stats[e].ymin) Stats[e].ymin = y; 1558 if (y > Stats[e].ymax) Stats[e].ymax = y; 1559 1560 if (x < Stats[e].xmin) Stats[e].xmin = x; 1561 if (x > Stats[e].xmax) Stats[e].xmax = x; 1562 1563 // + reduction 1564 Stats[e].S += 1; 1565 Stats[e].Sx += x; 1566 Stats[e].Sy += y; 1567 } 1568 } 1569 } 1570 #ifdef OPENMP 1571 } 1572 #endif // OPENMP 1573 } 1574 // ------------------------------------------------------------------------------ 1575 void calc_xmin(uint32** restrict E, int height, int width, uint16* restrict Xmin) 1576 // ------------------------------------------------------------------------------ 1577 { 1578 int i, j; 1198 1199 1200 // -------------------------------------------------------------------------------- 1201 void calc_xmin(uint32 ** restrict E, int height, int width, uint16 * restrict Xmin) 1202 // -------------------------------------------------------------------------------- 1203 { 1579 1204 uint32 x; 1580 1205 uint32 e; 1581 /* 1582 #ifdef OPENMP 1583 #pragma omp critical 1584 #endif 1585 { printf("calc xmin %d x %d\n", width, height); } 1586 */ 1587 for (i = 0; i < height; i++) { 1588 for (j = 0; j < width; j++) { 1206 for (int i = 0; i < height; i++) { 1207 for (int j = 0; j < width; j++) { 1589 1208 e = E[i][j]; 1590 1209 if (e) { 1591 1210 x = j; 1592 if (x < Xmin[e]) Xmin[e] = x; 1593 } 1594 } 1595 } 1596 } 1597 // ------------------------------------------------------------------------------ 1598 void calc_xmax(uint32** restrict E, int height, int width, uint16* restrict Xmax) 1599 // ------------------------------------------------------------------------------ 1600 { 1601 int i, j; 1211 if (x < Xmin[e]) { 1212 Xmin[e] = x; 1213 } 1214 } 1215 } 1216 } 1217 } 1218 1219 1220 // -------------------------------------------------------------------------------- 1221 void calc_xmax(uint32 ** restrict E, int height, int width, uint16 * restrict Xmax) 1222 // -------------------------------------------------------------------------------- 1223 { 1602 1224 uint32 x; 1603 1225 uint32 e; 1604 /* 1605 #ifdef OPENMP 1606 #pragma omp critical 1607 #endif 1608 { printf("calc xmax %d x %d\n", width, height); } 1609 */ 1610 for (i = 0; i < height; i++) { 1611 for (j = 0; j < width; j++) { 1226 for (int i = 0; i < height; i++) { 1227 for (int j = 0; j < width; j++) { 1612 1228 e = E[i][j]; 1613 1229 if (e) { … … 1618 1234 } 1619 1235 } 1620 // ------------------------------------------------------------------------------ 1621 void calc_ymin(uint32** restrict E, int height, int width, uint16* restrict Ymin) 1622 // ------------------------------------------------------------------------------ 1623 { 1624 int i, j; 1236 1237 1238 // -------------------------------------------------------------------------------- 1239 void calc_ymin(uint32 ** restrict E, int height, int width, uint16 * restrict Ymin) 1240 // -------------------------------------------------------------------------------- 1241 { 1625 1242 uint32 y; 1626 1243 uint32 e; 1627 /* 1628 #ifdef OPENMP 1629 #pragma omp critical 1630 #endif 1631 { printf("calc ymin %d x %d\n", width, height); } 1632 */ 1633 for(i=0; i<height; i++) { 1634 for(j=0; j<width; j++) { 1244 for (int i = 0; i < height; i++) { 1245 for (int j = 0; j < width; j++) { 1635 1246 e = E[i][j]; 1636 if (e) {1247 if (e) { 1637 1248 y = i; 1638 if(y < Ymin[e]) Ymin[e] = y; 1639 } 1640 } 1641 } 1642 } 1643 // ------------------------------------------------------------------------------ 1644 void calc_ymax(uint32** restrict E, int height, int width, uint16* restrict Ymax) 1645 // ------------------------------------------------------------------------------ 1646 { 1647 int i, j; 1249 if (y < Ymin[e]) { 1250 Ymin[e] = y; 1251 } 1252 } 1253 } 1254 } 1255 } 1256 1257 1258 // -------------------------------------------------------------------------------- 1259 void calc_ymax(uint32 ** restrict E, int height, int width, uint16 * restrict Ymax) 1260 // -------------------------------------------------------------------------------- 1261 { 1648 1262 uint32 y; 1649 1263 uint32 e; 1650 /* 1651 #ifdef OPENMP 1652 #pragma omp critical 1653 #endif 1654 { printf("calc ymax %d x %d\n", width, height); } 1655 */ 1656 for(i=0; i<height; i++) { 1657 for(j=0; j<width; j++) { 1264 for (int i = 0; i < height; i++) { 1265 for (int j = 0; j < width; j++) { 1658 1266 e = E[i][j]; 1659 if (e) {1267 if (e) { 1660 1268 y = i; 1661 if(y > Ymax[e]) Ymax[e] = y; 1662 } 1663 } 1664 } 1665 } 1666 // ------------------------------------------------------------------------ 1667 void calc_s(uint32** restrict E, int height, int width, uint32* restrict S) 1668 // ------------------------------------------------------------------------ 1669 { 1670 int i, j; 1269 if (y > Ymax[e]) { 1270 Ymax[e] = y; 1271 } 1272 } 1273 } 1274 } 1275 } 1276 1277 1278 // -------------------------------------------------------------------------- 1279 void calc_s(uint32 ** restrict E, int height, int width, uint32 * restrict S) 1280 // -------------------------------------------------------------------------- 1281 { 1671 1282 uint32 e; 1672 /* 1673 #ifdef OPENMP 1674 #pragma omp critical 1675 #endif 1676 { printf("calc s %d x %d\n", width, height); } 1677 */ 1678 for(i=0; i<height; i++) { 1679 for(j=0; j<width; j++) { 1283 for (int i = 0; i < height; i++) { 1284 for (int j = 0; j < width; j++) { 1680 1285 e = E[i][j]; 1681 if (e) {1286 if (e) { 1682 1287 S[e] += 1; 1683 1288 } … … 1685 1290 } 1686 1291 } 1687 // -------------------------------------------------------------------------- 1688 void calc_sx(uint32** restrict E, int height, int width, uint32* restrict Sx) 1689 // -------------------------------------------------------------------------- 1690 { 1691 int i, j; 1292 1293 1294 // ---------------------------------------------------------------------------- 1295 void calc_sx(uint32 ** restrict E, int height, int width, uint32 * restrict Sx) 1296 // ---------------------------------------------------------------------------- 1297 { 1692 1298 uint32 e; 1693 /* 1694 #ifdef OPENMP 1695 #pragma omp critical 1696 #endif 1697 { printf("calc sx %d x %d\n", width, height); } 1698 */ 1699 for(i=0; i<height; i++) { 1700 for(j=0; j<width; j++) { 1299 for (int i = 0; i < height; i++) { 1300 for (int j = 0; j < width; j++) { 1701 1301 e = E[i][j]; 1702 if (e) {1302 if (e) { 1703 1303 Sx[e] += j; 1704 1304 } … … 1706 1306 } 1707 1307 } 1708 // -------------------------------------------------------------------------- 1709 void calc_sy(uint32** restrict E, int height, int width, uint32* restrict Sy) 1710 // -------------------------------------------------------------------------- 1711 { 1712 int i, j; 1308 1309 1310 // ---------------------------------------------------------------------------- 1311 void calc_sy(uint32 ** restrict E, int height, int width, uint32 * restrict Sy) 1312 // ---------------------------------------------------------------------------- 1313 { 1713 1314 uint32 e; 1714 /* 1715 #ifdef OPENMP 1716 #pragma omp critical 1717 #endif 1718 { printf("calc sy %d x %d\n", width, height); } 1719 */ 1720 for (i = 0; i < height; i++) { 1721 for (j = 0; j < width; j++) { 1315 for (int i = 0; i < height; i++) { 1316 for (int j = 0; j < width; j++) { 1722 1317 e = E[i][j]; 1723 1318 if (e) { … … 1727 1322 } 1728 1323 } 1729 // --------------------------------------------------------------------------------------------------------------------------------------------------------------- 1730 void imageFeaturesComputation_omp5(uint32** E, int height, int width, uint16* Xmin, uint16* Xmax, uint16* Ymin, uint16* Ymax, uint32* S, uint32* Sx, uint32* Sy) 1731 // --------------------------------------------------------------------------------------------------------------------------------------------------------------- 1732 { 1733 // version avec "task" (OpenMP 3.0) et "depend" (OpenMP 4.0) 1734 #ifdef OPENMP 1735 #pragma omp parallel shared(E,Xmin,Xmax,Ymin,Ymax,S,Sx,Sy) 1736 // ne sourtout pas mettre height et width en private 1737 { 1738 #endif // OPENMP 1739 1740 int id; // thread number 1741 1742 #ifdef OPENMP 1743 id = omp_get_thread_num(); 1744 #else 1745 id = 1; 1746 #endif 1747 1748 //printf("thread id = %d h = %d w = %d\n", id, height, width); 1749 1750 if (id == 0) { calc_xmin(E, height, width, Xmin); } 1751 if (id == 1) { calc_xmax(E, height, width, Xmax); } 1752 if (id == 2) { calc_ymin(E, height, width, Ymin); } 1753 if (id == 3) { calc_ymax(E, height, width, Ymax); } 1754 1755 if (id == 4) { calc_s (E, height, width, S); } 1756 if (id == 5) { calc_sx(E, height, width, Sx); } 1757 if (id == 6) { calc_sy(E, height, width, Sy); } 1758 #ifdef OPENMP 1759 } 1760 #endif // OPENMP 1761 } 1762 // ------------------------------------------------------ 1763 int RegionStats_Compare(RegionStats *S1, RegionStats *S2) 1764 // ------------------------------------------------------ 1324 1325 1326 // -------------------------------------------------------- 1327 int RegionStats_Compare(RegionStats * S1, RegionStats * S2) 1328 // -------------------------------------------------------- 1765 1329 { 1766 1330 //puts("----------------------------------------"); 1767 1331 //display_RegionStats(S1, "S1"); 1768 1332 //display_RegionStats(S2, "S2"); 1769 if ((S1->xmin == S2->xmin) &&1333 if ((S1->xmin == S2->xmin) && 1770 1334 (S1->xmax == S2->xmax) && 1771 1335 (S1->ymin == S2->ymin) && 1772 1336 (S1->ymax == S2->ymax) && 1773 (S1->S == S2->S) &&1774 (S1->Sx == S2->Sx) &&1775 (S1->Sy == S2->Sy ))1337 (S1->S == S2->S) && 1338 (S1->Sx == S2->Sx) && 1339 (S1->Sy == S2->Sy)) { 1776 1340 return 1; 1777 else 1341 } 1342 else { 1778 1343 return 0; 1779 } 1780 // ---------------------------------------------------------------------------- 1781 int RegionStatsVector_Compare(RegionStats *S1, int i0, int i1, RegionStats *S2) 1782 // ---------------------------------------------------------------------------- 1783 { 1784 int i; 1344 } 1345 } 1346 1347 1348 // ------------------------------------------------------------------------------ 1349 int RegionStatsVector_Compare(RegionStats * S1, int i0, int i1, RegionStats * S2) 1350 // ------------------------------------------------------------------------------ 1351 { 1785 1352 int c; // resultat de la comparaison 0 = identique, 1 = different 1786 1353 int s = 0; // somme 1787 1354 1788 for (i=i0; i<=i1; i++) {1355 for (int i = i0; i <= i1; i++) { 1789 1356 c = RegionStats_Compare(&S1[i], &S2[i]); 1790 1357 s += c; 1791 1792 /*if(c) {1793 puts("---------------------------------------------------");1794 printf("e = %d\n", i);1795 display_RegionStats(&S1[i], NULL);1796 display_RegionStats(&S2[i], NULL);1797 }*/1798 1799 1358 } 1800 1359 return s; 1801 1360 } 1802 // ------------------------------------------------------------------------------------------ 1803 int RegionStatsVector_Match(RegionStats *S1, int i0, int i1, RegionStats *S2, int j0, int j1) 1804 // ------------------------------------------------------------------------------------------ 1805 { 1806 int i, j, pos; 1361 1362 1363 // -------------------------------------------------------------------------------------------- 1364 int RegionStatsVector_Match(RegionStats * S1, int i0, int i1, RegionStats * S2, int j0, int j1) 1365 // -------------------------------------------------------------------------------------------- 1366 { 1367 int j, pos; 1807 1368 int c; // resultat de la comparaison 1 = identique, 0 = different 1808 1369 int a; // accumulateur de c 1809 1370 int s = 0; // somme 1810 1371 int perm = 0; // permutation de numero de features 1811 int n1 = i1 -i0+1;1812 int n2 = j1 -j0+1;1372 int n1 = i1 - i0 + 1; 1373 int n2 = j1 - j0 + 1; 1813 1374 1814 1375 //printf("[RegionStatsVector_Match]: [%d..%d]=%d vs [%d..%d]=%d\n", i0, i1, n1, j0,j1,n2); … … 1818 1379 } 1819 1380 1820 for (i = i0; i <= i1; i++) {1381 for (int i = i0; i <= i1; i++) { 1821 1382 a = 0; 1822 1383 pos = -1; … … 1825 1386 c = RegionStats_Compare(&S1[i], &S2[j]); 1826 1387 a = a + c; 1827 if (c) pos = j; 1388 if (c) { 1389 pos = j; 1390 } 1828 1391 } 1829 1392 s += a; … … 1833 1396 for (j = j0; j <= j1; j++) { 1834 1397 c = RegionStats_Compare(&S1[i], &S2[j]); 1835 if (c) printf("S2[%d] ", j); 1836 } 1837 printf(""); 1838 giet_pthread_exit(""); 1398 if (c) { 1399 printf("S2[%d] ", j); 1400 } 1401 } 1402 printf("\n"); 1403 exit(1); 1839 1404 } 1840 1405 … … 1855 1420 return n1 - s; 1856 1421 } 1422 1423 // Local Variables: 1424 // tab-width: 4 1425 // c-basic-offset: 4 1426 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 1427 // indent-tabs-mode: nil 1428 // End: 1429 1430 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 1431 -
soft/giet_vm/applications/rosenfeld/src/mt19937.c
r772 r821 54 54 55 55 static unsigned long mt[N]; /* the array for the state vector */ 56 static int mti =N+1;/* mti==N+1 means mt[N] is not initialized */56 static int mti = N + 1 ; /* mti==N+1 means mt[N] is not initialized */ 57 57 58 58 static int global_seed; … … 61 61 void init_genrand(unsigned long s) 62 62 { 63 mt[0] = s & 0xffffffffUL;63 mt[0] = s & 0xffffffffUL; 64 64 global_seed = s; // modif LL 65 for (mti=1; mti<N; mti++) { 66 mt[mti] = 67 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); 65 for (mti = 1; mti < N; mti++) { 66 mt[mti] = (1812433253UL * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti); 68 67 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ 69 68 /* In the previous versions, MSBs of the seed affect */ … … 84 83 //init_genrand(19650218UL); 85 84 init_genrand(global_seed); 86 i=1; j=0; 87 k = (N>key_length ? N : key_length); 85 i = 1; 86 j = 0; 87 k = (N > key_length ? N : key_length); 88 88 for (; k; k--) { 89 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL)) 90 + init_key[j] + j; /* non linear */ 91 mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 92 i++; j++; 93 if (i>=N) { mt[0] = mt[N-1]; i=1; } 94 if (j>=key_length) j=0; 95 } 96 for (k=N-1; k; k--) { 97 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) 98 - i; /* non linear */ 89 mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525UL)) + init_key[j] + j; /* non linear */ 99 90 mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 100 91 i++; 101 if (i>=N) { mt[0] = mt[N-1]; i=1; } 92 j++; 93 if (i >= N) { 94 mt[0] = mt[N - 1]; 95 i = 1; 96 } 97 if (j >= key_length) { 98 j = 0; 99 } 100 } 101 for (k = N - 1; k; k--) { 102 mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL)) - i; /* non linear */ 103 mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 104 i++; 105 if (i >= N) { 106 mt[0] = mt[N - 1]; 107 i = 1; 108 } 102 109 } 103 110 … … 109 116 { 110 117 unsigned long y; 111 static unsigned long mag01[2] ={0x0UL, MATRIX_A};118 static unsigned long mag01[2] = {0x0UL, MATRIX_A}; 112 119 /* mag01[x] = x * MATRIX_A for x=0,1 */ 113 120 … … 115 122 int kk; 116 123 117 if (mti == N +1)/* if init_genrand() has not been called, */124 if (mti == N + 1) { /* if init_genrand() has not been called, */ 118 125 //init_genrand(5489UL); /* a default initial seed is used */ 119 126 init_genrand(global_seed); 120 121 for (kk=0;kk<N-M;kk++) { 122 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK); 123 mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL]; 124 } 125 for (;kk<N-1;kk++) { 126 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK); 127 mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL]; 128 } 129 y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); 130 mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; 127 } 128 129 for (kk = 0;kk < N - M; kk++) { 130 y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK); 131 mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1UL]; 132 } 133 for (; kk < N - 1; kk++) { 134 y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK); 135 mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1UL]; 136 } 137 y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK); 138 mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1UL]; 131 139 132 140 mti = 0; … … 147 155 long genrand_int31(void) 148 156 { 149 return (long) (genrand_int32()>>1);157 return (long) (genrand_int32() >> 1); 150 158 } 151 159 … … 153 161 double genrand_real1(void) 154 162 { 155 return genrand_int32() *(1.0/4294967295.0);163 return genrand_int32() * (1.0 / 4294967295.0); 156 164 /* divided by 2^32-1 */ 157 165 } … … 160 168 double genrand_real2(void) 161 169 { 162 return genrand_int32() *(1.0/4294967296.0);170 return genrand_int32() * (1.0 / 4294967296.0); 163 171 /* divided by 2^32 */ 164 172 } … … 167 175 double genrand_real3(void) 168 176 { 169 return (((double) genrand_int32()) + 0.5)*(1.0/4294967296.0);177 return (((double) genrand_int32()) + 0.5) * (1.0 / 4294967296.0); 170 178 /* divided by 2^32 */ 171 179 } … … 174 182 double genrand_res53(void) 175 183 { 176 unsigned long a =genrand_int32()>>5, b=genrand_int32()>>6;177 return (a*67108864.0+b)*(1.0/9007199254740992.0);184 unsigned long a = genrand_int32() >> 5, b = genrand_int32() >> 6; 185 return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0); 178 186 } 179 187 /* These real versions are due to Isaku Wada, 2002/01/09 added */ … … 182 190 { 183 191 int i; 184 unsigned long init[4] ={0x123, 0x234, 0x345, 0x456}, length=4;192 unsigned long init[4] = {0x123, 0x234, 0x345, 0x456}, length = 4; 185 193 init_by_array(init, length); 186 194 printf("1000 outputs of genrand_int32()\n"); 187 for (i =0; i<1000; i++) {195 for (i = 0; i < 1000; i++) { 188 196 printf("%10lu ", genrand_int32()); 189 if (i%5==4) printf("\n"); 197 if (i % 5 == 4) { 198 printf("\n"); 199 } 190 200 } 191 201 printf("\n1000 outputs of genrand_real2()\n"); 192 for (i =0; i<1000; i++) {202 for (i = 0; i < 1000; i++) { 193 203 printf("%10.8f ", genrand_real2()); 194 if (i%5==4) printf("\n"); 204 if (i % 5 == 4) { 205 printf("\n"); 206 } 195 207 } 196 208 return 0; 197 209 } 210 211 212 // Local Variables: 213 // tab-width: 4 214 // c-basic-offset: 4 215 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 216 // indent-tabs-mode: nil 217 // End: 218 219 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 220 -
soft/giet_vm/applications/rosenfeld/src/palette.c
r772 r821 16 16 17 17 18 #ifdef CLI19 18 #include "nrc_os_config.h" 20 19 #include "nrc.h" 21 #endif22 20 23 21 #include "palette.h" 24 22 25 /* 26 * Modif : 98-11-18 ajout de Save 27 */ 28 29 /* ---------------------------------------------- */ 30 IMAGE_EXPORT(void) Palette_Display(RGBQuad *palette) 31 /* ---------------------------------------------- */ 23 24 /* --------------------------------- */ 25 void Palette_Display(RGBQuad * palette) 26 /* --------------------------------- */ 32 27 { 33 28 int i; … … 37 32 } 38 33 } 39 /* ----------------------------------------------------------- */ 40 //IMAGE_EXPORT(void) Palette_Save(RGBQuad *palette, char *filename) 41 /* ----------------------------------------------------------- */ 42 /*{ 43 int i, j; 44 int k = 32; 45 int hauteur = k, largeur = k*256; 46 uint8 **X; 47 Image *image; 48 49 50 IConstructor(&image, hauteur, largeur, 0); 51 X = (uint8**) Image_Get_Data(image); 52 for(i=0; i<hauteur; i++) { 53 for(j=0; j<largeur; j++) { 54 X[i][j] = j/k; 55 } 56 } 57 //SaveBMP(image, palette, filename); 58 IDestructor(&image); 59 }*/ 60 /* --------------------------------------------------------------------- */ 61 //IMAGE_EXPORT(void) Palette_SaveSub(RGBQuad *palette, int n, char *filename) 62 /* --------------------------------------------------------------------- */ 63 /*{ 64 int i, j; 65 int hauteur = 8, largeur = 8*n; 66 uint8 **X; 67 Image *image; 68 69 70 IConstructor(&image, largeur, hauteur, 0); 71 X = (uint8**) Image_Get_Data(image); 72 for(i=0; i<hauteur; i++) { 73 for(j=8; j<=largeur; j++) { 74 X[i][j] = j/8; 75 } 76 } 77 //SaveBMP(image, palette, filename); 78 IDestructor(&image); 79 }*/ 34 35 80 36 /* --------------------------------------------------- */ 81 37 IMAGE_EXPORT(void) Palette_GrayBlue2Red(RGBQuad *palette) 82 /* --------------------------------------------------- */ 83 /* ancien SetupPalette */ 84 { 85 int i; 86 38 /* --------------------------------------------------- */ 39 /* ancien SetupPalette */ 40 { 87 41 /* 88 42 * Partie basse : image en niveau de gris 89 43 */ 90 for (i=0; i<128; i++) {91 palette[i].blue = 2 *i;92 palette[i].green = 2 *i;93 palette[i].red = 2 *i;44 for (int i = 0; i < 128; i++) { 45 palette[i].blue = 2 * i; 46 palette[i].green = 2 * i; 47 palette[i].red = 2 * i; 94 48 palette[i].reserved = 0; 95 49 } … … 98 52 * degrade de bleus puis degrade de rouges 99 53 */ 100 for (i=0; i<128; i++) {101 palette[i +128].blue = 255 - 2*i;102 palette[i +128].green = 0;103 palette[i +128].red = 2*i+1;104 palette[i +128].reserved = 0;54 for (int i = 0; i < 128; i++) { 55 palette[i + 128].blue = 255 - 2 * i; 56 palette[i + 128].green = 0; 57 palette[i + 128].red = 2 * i + 1; 58 palette[i + 128].reserved = 0; 105 59 } 106 60 palette[128].blue = 255; … … 113 67 palette[255].red = 255; 114 68 palette[255].reserved = 0; 115 116 /*for(i=0; i<256; i++) { 117 palette[i].rgbBlue = i; 118 palette[i].rgbGreen = i; 119 palette[i].rgbRed = i; 120 palette[i].rgbReserved = 0; 121 }*/ 122 123 /*if(verbose) { 124 for(i=0; i<256; i++) { 125 printf("%d %3d %3d %3d\n", i, Palette[i].rgbRed, Palette[i].rgbGreen, Palette[i].rgbBlue); 126 } 127 }*/ 128 } 129 /* ---------------------------------------------- */ 130 IMAGE_EXPORT(void) Palette_Classic(RGBQuad *palette) 131 /* ---------------------------------------------- */ 132 { 133 int i; 134 135 for(i=0; i<256; i++) { 69 } 70 71 72 /* --------------------------------- */ 73 void Palette_Classic(RGBQuad * palette) 74 /* --------------------------------- */ 75 { 76 for (int i = 0; i < 256; i++) { 136 77 palette[i].blue = (uint8) i; 137 78 palette[i].green = (uint8) i; … … 140 81 } 141 82 } 142 /* ------------------------------------------- */ 143 IMAGE_EXPORT(void) Palette_Gray(RGBQuad *palette) 144 /* ------------------------------------------- */145 { 146 int i; 147 148 for (i=0; i<256; i++) {83 84 85 /* ------------------------------ */ 86 void Palette_Gray(RGBQuad * palette) 87 /* ------------------------------ */ 88 { 89 for (int i = 0; i < 256; i++) { 149 90 palette[i].blue = (uint8) i; 150 91 palette[i].green = (uint8) i; … … 154 95 } 155 96 156 /* ---------------------------------------------- */ 157 IMAGE_EXPORT(void) Palette_Pseudo1(RGBQuad *palette) 158 /* ---------------------------------------------- */ 159 { 160 int i; 161 for (i=0; i<255; i++) {162 palette[i].blue = (uint8) ((3 *i)%256);163 palette[i].green = (uint8) ((87 *i)%256);164 palette[i].red = (uint8) ((117 *i)%256);97 98 /* --------------------------------- */ 99 void Palette_Pseudo1(RGBQuad * palette) 100 /* --------------------------------- */ 101 { 102 for (int i = 0; i < 255; i++) { 103 palette[i].blue = (uint8) ((3 * i) % 256); 104 palette[i].green = (uint8) ((87 * i) % 256); 105 palette[i].red = (uint8) ((117 * i) % 256); 165 106 palette[i].reserved = 0; 166 107 } … … 170 111 palette[255].reserved = (uint8) 0; 171 112 } 172 /* ---------------------------------------------- */ 173 IMAGE_EXPORT(void) Palette_Pseudo2(RGBQuad *palette) 174 /* ---------------------------------------------- */ 175 { 176 int i; 177 for(i=0; i<255; i++) { 178 palette[i].blue = (uint8) (( 257*i)%256); /* nextprime(256) */ 179 palette[i].green = (uint8) (( 65537*i)%256); /* nextprime(256^2) */ 180 palette[i].red = (uint8) ((16777259*i)%256); /* nextprime(256^3) */ 113 114 115 /* --------------------------------- */ 116 void Palette_Pseudo2(RGBQuad * palette) 117 /* --------------------------------- */ 118 { 119 unsigned int i; 120 for (i = 0; i < 255; i++) { 121 palette[i].blue = (uint8) (( 257 * i) % 256); /* nextprime(256) */ 122 palette[i].green = (uint8) (( 65537 * i) % 256); /* nextprime(256^2) */ 123 palette[i].red = (uint8) ((16777259 * i) % 256); /* nextprime(256^3) */ 181 124 palette[i].reserved = 0; 182 125 } … … 186 129 palette[255].reserved = (uint8) 0; 187 130 } 188 /* ------------------------------------------ */ 189 IMAGE_EXPORT(void) Palette_Hue(RGBQuad *palette) 190 /* ------------------------------------------ */ 131 132 133 /* ----------------------------- */ 134 void Palette_Hue(RGBQuad * palette) 135 /* ----------------------------- */ 191 136 { 192 137 int i; 193 138 double k, r, g, b; /* alpha rgb */ 194 for (i=0; i<255; i++) {139 for (i = 0; i < 255; i++) { 195 140 196 141 k = (double) i / 256; 197 142 198 143 r = 2.0 * k * PI; 199 g = 2.0 * k * PI - (2.0* PI/3.0);200 b = 2.0 * k * PI - (4.0*PI/3.0);144 g = 2.0 * k * PI - (2.0* PI / 3.0); 145 b = 2.0 * k * PI - (4.0* PI / 3.0); 201 146 202 147 palette[i].blue = (uint8) (128.0 * (1.0 + cos(b))); … … 206 151 } 207 152 } 208 /* ------------------------------------------------ */ 209 IMAGE_EXPORT(void) Palette_RandomHue(RGBQuad *palette) 210 /* ------------------------------------------------ */ 153 154 155 /* ----------------------------------- */ 156 void Palette_RandomHue(RGBQuad * palette) 157 /* ----------------------------------- */ 211 158 { 212 159 int i, ii; 213 160 double k, r, g, b; /* alpha rgb */ 214 for (i=0; i<255; i++) {215 216 ii = (3 *i)%256;161 for (i = 0; i < 255; i++) { 162 163 ii = (3 * i) % 256; 217 164 k = (double) (ii / 256); 218 165 219 166 r = 2.0 * k * PI; 220 g = 2.0 * k * PI - (2.0 *PI/3.0);221 b = 2.0 * k * PI - (4.0*PI/3.0);167 g = 2.0 * k * PI - (2.0 * PI / 3.0); 168 b = 2.0 * k * PI - (4.0 * PI / 3.0); 222 169 223 170 palette[i].blue = (uint8) (128.0 * (1.0 + cos(b))); … … 227 174 } 228 175 } 229 /* -------------------------------------------- */ 230 IMAGE_EXPORT(void) Palette_HueBW(RGBQuad *palette) 231 /* -------------------------------------------- */ 176 177 178 /* ------------------------------- */ 179 void Palette_HueBW(RGBQuad * palette) 180 /* ------------------------------- */ 232 181 { 233 182 int i; 234 183 double k, r, g, b; /* alpha rgb */ 235 for (i=0; i<255; i++) {184 for (i = 0; i < 255; i++) { 236 185 237 186 k = (double) i / 256; 238 187 239 188 r = 2.0 * k * PI; 240 g = 2.0 * k * PI - (2.0 *PI/3.0);241 b = 2.0 * k * PI - (4.0*PI/3.0);189 g = 2.0 * k * PI - (2.0 * PI / 3.0); 190 b = 2.0 * k * PI - (4.0 * PI / 3.0); 242 191 243 192 palette[i].blue = (uint8) (128.0 * (1.0 + cos(b))); … … 256 205 palette[255].reserved = (uint8) 0; 257 206 } 258 /* -------------------------------------------------- */ 259 IMAGE_EXPORT(void) Palette_RandomHueBW(RGBQuad *palette) 260 /* -------------------------------------------------- */ 207 208 209 /* ------------------------------------- */ 210 void Palette_RandomHueBW(RGBQuad * palette) 211 /* ------------------------------------- */ 261 212 { 262 213 int i, ii, im; 263 214 double k, r, g, b; /* alpha rgb */ 264 for (i=0; i<255; i++) {265 266 ii = (7 *i)%256;215 for (i = 0; i < 255; i++) { 216 217 ii = (7 * i) % 256; 267 218 k = (double) ii / 256; 268 219 269 220 r = 2.0 * k * PI; 270 g = 2.0 * k * PI - (2.0 *PI/3.0);271 b = 2.0 * k * PI - (4.0*PI/3.0);272 273 im = (i -27)%255;221 g = 2.0 * k * PI - (2.0 * PI / 3.0); 222 b = 2.0 * k * PI - (4.0 * PI / 3.0); 223 224 im = (i - 27) % 255; 274 225 im = i; 275 226 palette[im].blue = (uint8) (128.0 * (1.0 + cos(b))); … … 288 239 palette[255].reserved = (uint8) 0; 289 240 } 290 /* ------------------------------------------------ */ 291 IMAGE_EXPORT(void) Palette_3ColorsBW(RGBQuad *palette) 292 /* ------------------------------------------------ */ 293 { 294 int i; 295 uint8 rr = 255,gg = 255, bb = 255; 241 242 243 /* ----------------------------------- */ 244 void Palette_3ColorsBW(RGBQuad * palette) 245 /* ----------------------------------- */ 246 { 247 uint8 rr = 255, gg = 255, bb = 255; 296 248 RGBQuad pattern[3]; 297 249 … … 308 260 pattern[2].blue = bb; 309 261 310 for (i=0; i<255; i++) {311 palette[1 +i].red = pattern[i%3].red;312 palette[1 +i].green = pattern[i%3].green;313 palette[1 +i].blue = pattern[i%3].blue;314 palette[1 +i].reserved = (uint8) 0;262 for (int i = 0; i < 255; i++) { 263 palette[1 + i].red = pattern[i % 3].red; 264 palette[1 + i].green = pattern[i % 3].green; 265 palette[1 + i].blue = pattern[i % 3].blue; 266 palette[1 + i].reserved = (uint8) 0; 315 267 } 316 268 palette[0].blue = (uint8) 0; … … 324 276 palette[255].reserved = (uint8) 0; 325 277 } 326 /* ---------------------------------------------- */ 327 IMAGE_EXPORT(void) Palette_3Colors(RGBQuad *palette) 328 /* ---------------------------------------------- */ 278 279 280 /* --------------------------------- */ 281 void Palette_3Colors(RGBQuad * palette) 282 /* --------------------------------- */ 329 283 { 330 284 int i; 331 uint8 rr = 255, gg = 255, bb = 255;285 uint8 rr = 255, gg = 255, bb = 255; 332 286 RGBQuad pattern[3]; 333 287 … … 344 298 pattern[2].blue = bb; 345 299 346 for(i=0; i<256; i++) { 347 palette[i].red = pattern[i%3].red; 348 palette[i].green = pattern[i%3].green; 349 palette[i].blue = pattern[i%3].blue; 350 palette[i].reserved = (uint8) 0; 351 } 352 } 353 /* -------------------------------------------------- */ 354 IMAGE_EXPORT(void) Palette_3Colors_Red(RGBQuad *palette) 355 /* -------------------------------------------------- */ 356 { 357 int i; 358 uint8 rr = 255,gg = 255, bb = 255; 300 for (i = 0; i < 256; i++) { 301 palette[i].red = pattern[i % 3].red; 302 palette[i].green = pattern[i % 3].green; 303 palette[i].blue = pattern[i % 3].blue; 304 palette[i].reserved = (uint8) 0; 305 } 306 } 307 308 309 /* ------------------------------------- */ 310 void Palette_3Colors_Red(RGBQuad * palette) 311 /* ------------------------------------- */ 312 { 313 uint8 rr = 255, gg = 255, bb = 255; 359 314 RGBQuad pattern[3]; 360 315 … … 376 331 palette[0].blue = pattern[0].blue; 377 332 378 for(i=0; i<255; i++) { 379 palette[1+i].red = pattern[1+i%2].red; 380 palette[1+i].green = pattern[1+i%2].green; 381 palette[1+i].blue = pattern[1+i%2].blue; 382 palette[1+i].reserved = (uint8) 0; 383 } 384 } 385 /* ------------------------------------------------ */ 386 IMAGE_EXPORT(void) Palette_6ColorsBW(RGBQuad *palette) 387 /* ------------------------------------------------ */ 388 { 389 int i; 390 uint8 rr = 255,gg = 255, bb = 255; 333 for (int i = 0; i < 255; i++) { 334 palette[1 + i].red = pattern[1 + i % 2].red; 335 palette[1 + i].green = pattern[1 + i % 2].green; 336 palette[1 + i].blue = pattern[1 + i % 2].blue; 337 palette[1 + i].reserved = (uint8) 0; 338 } 339 } 340 341 342 /* ----------------------------------- */ 343 void Palette_6ColorsBW(RGBQuad * palette) 344 /* ----------------------------------- */ 345 { 346 uint8 rr = 255, gg = 255, bb = 255; 391 347 RGBQuad pattern[6]; 392 348 … … 415 371 pattern[5].blue = bb; 416 372 417 for (i=0; i<255; i++) {418 palette[1 +i].red = pattern[i%6].red;419 palette[1 +i].green = pattern[i%6].green;420 palette[1 +i].blue = pattern[i%6].blue;421 palette[1 +i].reserved = (uint8) 0;373 for (int i = 0; i < 255; i++) { 374 palette[1 + i].red = pattern[i % 6].red; 375 palette[1 + i].green = pattern[i % 6].green; 376 palette[1 + i].blue = pattern[i % 6].blue; 377 palette[1 + i].reserved = (uint8) 0; 422 378 } 423 379 palette[0].blue = (uint8) 0; … … 431 387 palette[255].reserved = (uint8) 0; 432 388 } 433 /* ---------------------------------------------- */ 434 IMAGE_EXPORT(void) Palette_6Colors(RGBQuad *palette) 435 /* ---------------------------------------------- */ 436 { 437 int i; 438 uint8 rr = 255,gg = 255, bb = 255; 389 390 391 /* --------------------------------- */ 392 void Palette_6Colors(RGBQuad * palette) 393 /* --------------------------------- */ 394 { 395 uint8 rr = 255, gg = 255, bb = 255; 439 396 RGBQuad pattern[6]; 440 397 … … 463 420 pattern[5].blue = bb; 464 421 465 for(i=0; i<256; i++) { 466 palette[i].red = pattern[i%6].red; 467 palette[i].green = pattern[i%6].green; 468 palette[i].blue = pattern[i%6].blue; 469 palette[i].reserved = (uint8) 0; 470 } 471 } 472 /* -------------------------------------------------- */ 473 IMAGE_EXPORT(void) Palette_6Colors_Red(RGBQuad *palette) 474 /* -------------------------------------------------- */ 475 { 476 int i; 477 uint8 rr = 255,gg = 255, bb = 255; 422 for (int i = 0; i < 256; i++) { 423 palette[i].red = pattern[i % 6].red; 424 palette[i].green = pattern[i % 6].green; 425 palette[i].blue = pattern[i % 6].blue; 426 palette[i].reserved = (uint8) 0; 427 } 428 } 429 430 431 /* ------------------------------------- */ 432 void Palette_6Colors_Red(RGBQuad * palette) 433 /* ------------------------------------- */ 434 { 435 uint8 rr = 255, gg = 255, bb = 255; 478 436 RGBQuad pattern[6]; 479 437 … … 507 465 palette[0].blue = pattern[0].blue; 508 466 509 for(i=0; i<255; i++) { 510 palette[1+i].red = pattern[1+i%5].red; 511 palette[1+i].green = pattern[1+i%5].green; 512 palette[1+i].blue = pattern[1+i%5].blue; 513 palette[1+i].reserved = (uint8) 0; 514 } 515 } 516 /* ------------------------------------------------- */ 517 IMAGE_EXPORT(void) Palette_18ColorsBW(RGBQuad *palette) 518 /* ------------------------------------------------- */ 467 for (int i = 0; i < 255; i++) { 468 palette[1 + i].red = pattern[1 + i % 5].red; 469 palette[1 + i].green = pattern[1 + i % 5].green; 470 palette[1 + i].blue = pattern[1 + i % 5].blue; 471 palette[1 + i].reserved = (uint8) 0; 472 } 473 } 474 475 476 /* ------------------------------------ */ 477 void Palette_18ColorsBW(RGBQuad * palette) 478 /* ------------------------------------ */ 519 479 { 520 480 int i; 521 uint8 rr = 255, gg = 255, bb = 255;522 uint8 r =127, g = 127, b = 127;481 uint8 rr = 255, gg = 255, bb = 255; 482 uint8 r = 127, g = 127, b = 127; 523 483 524 484 RGBQuad pattern[18]; … … 596 556 pattern[17].blue = bb; 597 557 598 for (i=0; i<255; i++) {599 palette[1 +i].red = pattern[i%18].red;600 palette[1 +i].green = pattern[i%18].green;601 palette[1 +i].blue = pattern[i%18].blue;602 palette[1 +i].reserved = (uint8) 0;558 for (int i = 0; i < 255; i++) { 559 palette[1 + i].red = pattern[i % 18].red; 560 palette[1 + i].green = pattern[i % 18].green; 561 palette[1 + i].blue = pattern[i % 18].blue; 562 palette[1 + i].reserved = (uint8) 0; 603 563 } 604 564 palette[0].blue = (uint8) 0; … … 612 572 palette[255].reserved = (uint8) 0; 613 573 } 614 /* ----------------------------------------------- */ 615 IMAGE_EXPORT(void) Palette_18Colors(RGBQuad *palette) 616 /* ----------------------------------------------- */ 617 { 618 int i; 619 uint8 rr = 255,gg = 255, bb = 255; 620 uint8 r =127, g = 127, b = 127; 574 575 576 /* ---------------------------------- */ 577 void Palette_18Colors(RGBQuad * palette) 578 /* ---------------------------------- */ 579 { 580 uint8 rr = 255, gg = 255, bb = 255; 581 uint8 r = 127, g = 127, b = 127; 621 582 622 583 RGBQuad pattern[18]; … … 694 655 pattern[17].blue = bb; 695 656 696 for(i=0; i<256; i++) { 697 palette[i].red = pattern[i%18].red; 698 palette[i].green = pattern[i%18].green; 699 palette[i].blue = pattern[i%18].blue; 700 palette[i].reserved = (uint8) 0; 701 } 702 } 703 /* ------------------------------------------------- */ 704 IMAGE_EXPORT(void) Palette_64ColorsBW(RGBQuad *palette) 705 /* ------------------------------------------------- */ 706 { 707 int r, g, b; 708 int i, m; 657 for (int i = 0; i < 256; i++) { 658 palette[i].red = pattern[i % 18].red; 659 palette[i].green = pattern[i % 18].green; 660 palette[i].blue = pattern[i % 18].blue; 661 palette[i].reserved = (uint8) 0; 662 } 663 } 664 665 666 /* ------------------------------------ */ 667 void Palette_64ColorsBW(RGBQuad * palette) 668 /* ------------------------------------ */ 669 { 670 int m; 709 671 //uint8 x1 = 64, x2 = 128, x3 = 192, x4 = 255; 710 672 uint8 X[4]; … … 717 679 718 680 m = 1; 719 for (r=0; r<4; r++) {720 for (g=0; g<4; g++) {721 for (b=0; b<4; b++) {681 for (int r = 0; r < 4; r++) { 682 for (int g = 0; g < 4; g++) { 683 for (int b = 0; b < 4; b++) { 722 684 palette[m].red = X[r]; 723 685 palette[m].green = X[g]; … … 728 690 } 729 691 730 for (i=0; i<255-(1+m); i++) {731 palette[1 +m+i].red = palette[i%m].red;732 palette[1 +m+i].green = palette[i%m].green;733 palette[1 +m+i].blue = palette[i%m].blue;734 palette[1 +m+i].reserved = (uint8) 0;692 for (int i = 0; i < 255 - (1 + m); i++) { 693 palette[1 + m + i].red = palette[i % m].red; 694 palette[1 + m + i].green = palette[i % m].green; 695 palette[1 + m + i].blue = palette[i % m].blue; 696 palette[1 + m + i].reserved = (uint8) 0; 735 697 } 736 698 palette[0].blue = (uint8) 0; … … 744 706 palette[255].reserved = (uint8) 0; 745 707 } 746 /* ------------------------------------------------- */ 747 IMAGE_EXPORT(void) Palette_256ColorsBW(RGBQuad *palette) 748 /* ------------------------------------------------- */ 749 { 750 int r, g, b; 708 709 710 /* ------------------------------------- */ 711 void Palette_256ColorsBW(RGBQuad * palette) 712 /* ------------------------------------- */ 713 { 751 714 int m; 752 715 //uint8 x1 = 64, x2 = 128, x3 = 192, x4 = 255; … … 764 727 765 728 m = 1; 766 for (r=0; r<8; r++) {767 for (g=0; g<8; g++) {768 for (b=0; b<8; b++) {769 if (m<255) {729 for (int r = 0; r < 8; r++) { 730 for (int g = 0; g < 8; g++) { 731 for (int b = 0; b < 8; b++) { 732 if (m < 255) { 770 733 xr = X[r]; xg = X[g]; xb = X[b]; 771 734 palette[m].red = xr; 772 735 palette[m].green = xg; 773 736 palette[m].blue = xb; 774 if ((xr!=255) && (xg!=255) && (xb!=255)) m++;775 if ((xr!=000) && (xg!=000) && (xb!=000)) m++;737 if ((xr != 255) && (xg != 255) && (xb != 255)) m++; 738 if ((xr != 000) && (xg != 000) && (xb != 000)) m++; 776 739 } 777 740 } … … 789 752 palette[255].reserved = (uint8) 0; 790 753 } 791 /* ----------------------------------------------------- */ 792 IMAGE_EXPORT(void) Palette_18ColorsBW_Red(RGBQuad *palette) 793 /* ----------------------------------------------------- */ 794 { 795 int i; 796 uint8 rr = 255,gg = 255, bb = 255; 797 uint8 r =127, g = 127, b = 127; 754 755 756 /* ---------------------------------------- */ 757 void Palette_18ColorsBW_Red(RGBQuad * palette) 758 /* ---------------------------------------- */ 759 { 760 uint8 rr = 255, gg = 255, bb = 255; 761 uint8 r = 127, g = 127, b = 127; 798 762 799 763 RGBQuad pattern[18]; … … 871 835 pattern[17].blue = bb; 872 836 873 for (i=0; i<254; i++) {874 palette[2 +i].red = pattern[1+i%17].red;875 palette[2 +i].green = pattern[1+i%17].green;876 palette[2 +i].blue = pattern[1+i%17].blue;877 palette[2 +i].reserved = (uint8) 0;837 for (int i = 0; i < 254; i++) { 838 palette[2 + i].red = pattern[1 + i % 17].red; 839 palette[2 + i].green = pattern[1 + i % 17].green; 840 palette[2 + i].blue = pattern[1 + i % 17].blue; 841 palette[2 + i].reserved = (uint8) 0; 878 842 } 879 843 /* noir en 0 */ … … 890 854 palette[255].blue = gg; 891 855 } 892 /* -------------------------------------------------------------- */ 893 IMAGE_EXPORT(void) Palette_18ColorsBW_RedGreenBlue(RGBQuad *palette) 894 /* -------------------------------------------------------------- */ 895 { 896 int i; 856 857 858 /* ------------------------------------------------- */ 859 void Palette_18ColorsBW_RedGreenBlue(RGBQuad * palette) 860 /* ------------------------------------------------- */ 861 { 897 862 uint8 i0 = 255; 898 863 uint8 i1 = 127; … … 965 930 pattern[14].blue = i0; 966 931 967 for (i=0; i<=250; i++) {968 palette[4 +i].red = pattern[i%14].red;969 palette[4 +i].green = pattern[i%14].green;970 palette[4 +i].blue = pattern[i%14].blue;971 palette[4 +i].reserved = (uint8) 0;932 for (int i = 0; i <= 250; i++) { 933 palette[4 + i].red = pattern[i % 14].red; 934 palette[4 + i].green = pattern[i % 14].green; 935 palette[4 + i].blue = pattern[i % 14].blue; 936 palette[4 + i].reserved = (uint8) 0; 972 937 } 973 938 … … 997 962 palette[255].blue = i0; 998 963 } 999 /* ---------------------------------------------------- */ 1000 IMAGE_EXPORT(void) Palette_3ColorsGrayBW(RGBQuad *palette) 1001 /* ---------------------------------------------------- */1002 { 1003 int i; 1004 964 965 966 /* --------------------------------------- */ 967 void Palette_3ColorsGrayBW(RGBQuad * palette) 968 /* --------------------------------------- */ 969 { 1005 970 Palette_3ColorsBW(palette); 1006 971 1007 for(i=128; i<256; i++) { 1008 palette[i].red = 1 + 2*(i-128); 1009 palette[i].green = 1 + 2*(i-128); 1010 palette[i].blue = 1 + 2*(i-128); 1011 palette[i].reserved = (uint8) 0; 1012 } 1013 /* palette[255] = blanc <- OK */ 1014 } 1015 /* -------------------------------------------------- */ 1016 IMAGE_EXPORT(void) Palette_3ColorsGray(RGBQuad *palette) 1017 /* -------------------------------------------------- */ 1018 { 1019 int i; 1020 972 for (int i = 128; i < 256; i++) { 973 palette[i].red = 1 + 2 * (i - 128); 974 palette[i].green = 1 + 2 * (i - 128); 975 palette[i].blue = 1 + 2 * (i - 128); 976 palette[i].reserved = (uint8) 0; 977 } 978 } 979 980 981 /* ------------------------------------- */ 982 void Palette_3ColorsGray(RGBQuad * palette) 983 /* ------------------------------------- */ 984 { 1021 985 Palette_3Colors(palette); 1022 986 1023 for (i=128; i<256; i++) {1024 palette[i].red = 1 + 2 *(i-128);1025 palette[i].green = 1 + 2 *(i-128);1026 palette[i].blue = 1 + 2 *(i-128);1027 palette[i].reserved = (uint8) 0; 1028 } 1029 } 1030 /* ---------------------------------------------------- */ 1031 IMAGE_EXPORT(void) Palette_6ColorsGrayBW(RGBQuad *palette) 1032 /* ---------------------------------------------------- */1033 { 1034 int i; 1035 987 for (int i = 128; i < 256; i++) { 988 palette[i].red = 1 + 2 * (i - 128); 989 palette[i].green = 1 + 2 * (i - 128); 990 palette[i].blue = 1 + 2 * (i - 128); 991 palette[i].reserved = (uint8) 0; 992 } 993 } 994 995 996 /* --------------------------------------- */ 997 void Palette_6ColorsGrayBW(RGBQuad * palette) 998 /* --------------------------------------- */ 999 { 1036 1000 Palette_6ColorsBW(palette); 1037 1001 1038 for (i=128; i<256; i++) {1039 palette[i].red = 1 + 2 *(i-128);1040 palette[i].green = 1 + 2 *(i-128);1041 palette[i].blue = 1 + 2 *(i-128);1042 palette[i].reserved = (uint8) 0; 1043 } 1044 } 1045 /* -------------------------------------------------- */ 1046 IMAGE_EXPORT(void) Palette_6ColorsGray(RGBQuad *palette) 1047 /* -------------------------------------------------- */1048 { 1049 int i; 1050 1002 for (int i = 128; i < 256; i++) { 1003 palette[i].red = 1 + 2 * (i - 128); 1004 palette[i].green = 1 + 2 * (i - 128); 1005 palette[i].blue = 1 + 2 * (i - 128); 1006 palette[i].reserved = (uint8) 0; 1007 } 1008 } 1009 1010 1011 /* ------------------------------------- */ 1012 void Palette_6ColorsGray(RGBQuad * palette) 1013 /* ------------------------------------- */ 1014 { 1051 1015 Palette_6Colors(palette); 1052 1016 1053 for (i=128; i<256; i++) {1054 palette[i].red = 1 + 2 *(i-128);1055 palette[i].green = 1 + 2 *(i-128);1056 palette[i].blue = 1 + 2 *(i-128);1057 palette[i].reserved = (uint8) 0; 1058 } 1059 } 1060 /* ----------------------------------------------------- */ 1061 IMAGE_EXPORT(void) Palette_18ColorsGrayBW(RGBQuad *palette) 1062 /* ----------------------------------------------------- */1063 { 1064 int i; 1065 1017 for (int i = 128; i < 256; i++) { 1018 palette[i].red = 1 + 2 * (i - 128); 1019 palette[i].green = 1 + 2 * (i - 128); 1020 palette[i].blue = 1 + 2 * (i - 128); 1021 palette[i].reserved = (uint8) 0; 1022 } 1023 } 1024 1025 1026 /* ---------------------------------------- */ 1027 void Palette_18ColorsGrayBW(RGBQuad * palette) 1028 /* ---------------------------------------- */ 1029 { 1066 1030 Palette_18ColorsBW(palette); 1067 1031 1068 for (i=128; i<256; i++) {1069 palette[i].red = 1 + 2 *(i-128);1070 palette[i].green = 1 + 2 *(i-128);1071 palette[i].blue = 1 + 2 *(i-128);1072 palette[i].reserved = (uint8) 0; 1073 } 1074 } 1075 /* --------------------------------------------------- */ 1076 IMAGE_EXPORT(void) Palette_18ColorsGray(RGBQuad *palette) 1077 /* --------------------------------------------------- */1078 { 1079 int i; 1080 1032 for (int i = 128; i < 256; i++) { 1033 palette[i].red = 1 + 2 * (i - 128); 1034 palette[i].green = 1 + 2 * (i - 128); 1035 palette[i].blue = 1 + 2 * (i - 128); 1036 palette[i].reserved = (uint8) 0; 1037 } 1038 } 1039 1040 1041 /* -------------------------------------- */ 1042 void Palette_18ColorsGray(RGBQuad * palette) 1043 /* -------------------------------------- */ 1044 { 1081 1045 Palette_18Colors(palette); 1082 1046 1083 for(i=128; i<256; i++) { 1084 palette[i].red = 1 + 2*(i-128); 1085 palette[i].green = 1 + 2*(i-128); 1086 palette[i].blue = 1 + 2*(i-128); 1087 palette[i].reserved = (uint8) 0; 1088 } 1089 } 1090 /* -------------------------------------------------------------------- */ 1091 //IMAGE_EXPORT(void) Palette_PackGrayLower(Image *src, Lut *lut, Image *dst) 1092 /* -------------------------------------------------------------------- */ 1093 /*{ 1094 int k; 1095 uint8 *l = (uint8*) Lut_Get_Data(lut); 1096 1097 for(k=0; k<256; k++) { 1098 l[k] = (uint8) (k >> 1); 1099 } 1100 1101 Lut_Apply(src, lut, dst); 1102 }*/ 1103 /* -------------------------------------------------------------------- */ 1104 //IMAGE_EXPORT(void) Palette_PackGrayUpper(Image *src, Lut *lut, Image *dst) 1105 /* -------------------------------------------------------------------- */ 1106 /*{ 1107 int k; 1108 uint8 *l = (uint8*) Lut_Get_Data(lut); 1109 1110 for(k=0; k<256; k++) { 1111 l[k] = (uint8) 128 + (k >> 1); 1112 } 1113 1114 Lut_Apply(src, lut, dst); 1115 }*/ 1116 /* ---------------------------------------------- */ 1117 IMAGE_EXPORT(void) Palette_2Colors(RGBQuad *palette) 1118 /* ---------------------------------------------- */ 1119 { 1120 int i, level; 1047 for(int i = 128; i < 256; i++) { 1048 palette[i].red = 1 + 2 * (i - 128); 1049 palette[i].green = 1 + 2 * (i - 128); 1050 palette[i].blue = 1 + 2 * (i - 128); 1051 palette[i].reserved = (uint8) 0; 1052 } 1053 } 1054 1055 1056 /* --------------------------------- */ 1057 void Palette_2Colors(RGBQuad * palette) 1058 /* --------------------------------- */ 1059 { 1060 int level; 1121 1061 1122 1062 RGBQuad pattern[2]; … … 1132 1072 pattern[1].blue = level; 1133 1073 1134 for(i=0; i<256; i++) { 1135 palette[i].red = pattern[i%2].red; 1136 palette[i].green = pattern[i%2].green; 1137 palette[i].blue = pattern[i%2].blue; 1138 palette[i].reserved = (uint8) 0; 1139 } 1140 } 1141 /* ---------------------------------------------- */ 1142 IMAGE_EXPORT(void) Palette_4Colors(RGBQuad *palette) 1143 /* ---------------------------------------------- */ 1144 { 1145 int i, level; 1074 for (int i = 0; i < 256; i++) { 1075 palette[i].red = pattern[i % 2].red; 1076 palette[i].green = pattern[i % 2].green; 1077 palette[i].blue = pattern[i % 2].blue; 1078 palette[i].reserved = (uint8) 0; 1079 } 1080 } 1081 1082 1083 /* --------------------------------- */ 1084 void Palette_4Colors(RGBQuad * palette) 1085 /* --------------------------------- */ 1086 { 1087 int level; 1146 1088 1147 1089 RGBQuad pattern[4]; 1148 1090 1149 for (i=0; i<2; i++) {1150 level = (i <<8) - 1;1091 for (int i = 0; i < 2; i++) { 1092 level = (i << 8) - 1; 1151 1093 pattern[i].red = level; 1152 1094 pattern[0].green = level; … … 1154 1096 } 1155 1097 1156 for(i=0; i<256; i++) { 1157 palette[i].red = pattern[i%2].red; 1158 palette[i].green = pattern[i%2].green; 1159 palette[i].blue = pattern[i%2].blue; 1160 palette[i].reserved = (uint8) 0; 1161 } 1162 } 1163 /* ---------------------------------------------- */ 1164 IMAGE_EXPORT(void) Palette_16Colors(RGBQuad *palette) 1165 /* ---------------------------------------------- */ 1166 { 1167 int i, level; 1098 for (int i = 0; i < 256; i++) { 1099 palette[i].red = pattern[i % 2].red; 1100 palette[i].green = pattern[i % 2].green; 1101 palette[i].blue = pattern[i % 2].blue; 1102 palette[i].reserved = (uint8) 0; 1103 } 1104 } 1105 1106 1107 /* ---------------------------------- */ 1108 void Palette_16Colors(RGBQuad * palette) 1109 /* ---------------------------------- */ 1110 { 1111 int level; 1168 1112 1169 1113 RGBQuad pattern[16]; 1170 1114 1171 for (i=0; i<4; i++) {1172 level = (i <<8) - 1;1115 for (int i = 0; i < 4; i++) { 1116 level = (i << 8) - 1; 1173 1117 pattern[i].red = level; 1174 1118 pattern[0].green = level; … … 1176 1120 } 1177 1121 1178 for(i=0; i<256; i++) { 1179 palette[i].red = pattern[i%2].red; 1180 palette[i].green = pattern[i%2].green; 1181 palette[i].blue = pattern[i%2].blue; 1182 palette[i].reserved = (uint8) 0; 1183 } 1184 } 1122 for (int i = 0; i < 256; i++) { 1123 palette[i].red = pattern[i % 2].red; 1124 palette[i].green = pattern[i % 2].green; 1125 palette[i].blue = pattern[i % 2].blue; 1126 palette[i].reserved = (uint8) 0; 1127 } 1128 } 1129 1130 1131 // Local Variables: 1132 // tab-width: 4 1133 // c-basic-offset: 4 1134 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 1135 // indent-tabs-mode: nil 1136 // End: 1137 1138 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 1139 -
soft/giet_vm/applications/rosenfeld/src/str_ext.c
r777 r821 13 13 #include "nrc_os_config.h" 14 14 15 // -------------------------------------------- 16 void str_remove_ext(const char * src, char* dst)17 // -------------------------------------------- 15 // ---------------------------------------------- 16 void str_remove_ext(const char * src, char * dst) 17 // ---------------------------------------------- 18 18 { 19 19 int len; … … 47 47 dst[len] = '\0'; // do not forget to add null char, otherwise 48 48 } 49 50 49 51 // ------------------- 50 52 int str_len(char * str) -
soft/giet_vm/applications/rosenfeld/src/util.c
r772 r821 39 39 } 40 40 41 41 42 /* ------------- */ 42 43 uint8 ui8rand(void) … … 47 48 return x; 48 49 } 50 51 49 52 /* --------------- */ 50 53 uint32 ui32rand(void) … … 55 58 return x; 56 59 } 60 61 57 62 /* --------------- */ 58 63 float32 f32rand(void) … … 63 68 return x ; 64 69 } 70 71 65 72 /* --------------------------------------- */ 66 73 void rand_ui8vector(uint8 * X, int i0, int i1) 67 74 /* --------------------------------------- */ 68 75 { 69 int i; 70 71 for(i = i0; i <= i1; i++) { 76 for (int i = i0; i <= i1; i++) { 72 77 X[i] = ui8rand(); 73 78 } 74 79 } 80 81 75 82 /* ----------------------------------------- */ 76 83 void rand_ui32vector(uint32 *X, int i0, int i1) 77 84 /* ----------------------------------------- */ 78 85 { 79 int i; 80 81 for (i = i0; i <= i1; i++) { 86 for (int i = i0; i <= i1; i++) { 82 87 X[i] = ui32rand(); 83 88 } 84 89 } 90 91 85 92 /* ----------------------------------------- */ 86 93 void rand_f32vector(float32 *X, int i0, int i1) 87 94 /* ----------------------------------------- */ 88 95 { 89 int i; 90 91 for(i = i0; i <= i1; i++) { 96 for (int i = i0; i <= i1; i++) { 92 97 X[i] = f32rand(); 93 98 } 94 99 } 100 101 95 102 /* --------------- */ 96 103 int getIter(int size) … … 106 113 return 2; 107 114 } 115 116 108 117 /* ----------------- */ 109 118 int getIterAV(int size) … … 112 121 return 3 * getIter(size); 113 122 } 123 124 114 125 /* --------------------------------- */ 115 126 float32 gauss(float32 sigma, float32 x) … … 130 141 return cpp; 131 142 } 143 144 132 145 // -------------------------- 133 146 void printf_split12(double x) … … 160 173 return; 161 174 } 162 printf("");163 175 } 164 176 … … 199 211 return; 200 212 } 201 printf("");202 213 } 203 214 // -------------------------- … … 243 254 return; 244 255 } 245 printf(""); 246 } 256 } 257 258 247 259 // ------------------------ 248 260 void printf_split(double x) … … 253 265 //printf_split18(x); 254 266 } 255 267 268 // Local Variables: 269 // tab-width: 4 270 // c-basic-offset: 4 271 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 272 // indent-tabs-mode: nil 273 // End: 274 275 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 276
Note: See TracChangeset
for help on using the changeset viewer.