00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <string.h>
00023 #include "flgrCoreData.h"
00024 #include "flgrCoreDispatch.h"
00025 #include "flgrCoreIO.h"
00026 #include "flgrCoreRoI.h"
00027
00033 #define FLGR_MACRO_EXTRACT_REGION_1D(dtype) \
00034 int spp = datroi->spp; \
00035 int length = datroi->length*spp; \
00036 dtype *proi,*psrc; \
00037 \
00038 \
00039 \
00040 psrc = (dtype*) datsrc->array+x*spp; \
00041 proi = (dtype*) datroi->array; \
00042 \
00043 memcpy(proi,psrc,length*sizeof(dtype))
00044
00045 void flgr1d_extract_region_fgBIT(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00046 int j,k;
00047 int length = (datroi->length+x)*datroi->spp;
00048 fgBIT *proi,*psrc,val;
00049
00050
00051
00052 psrc = (fgBIT*) datsrc->array;
00053 proi = (fgBIT*) datroi->array;
00054
00055 for(j=x,k=0 ; j<length ; j++,k++) {
00056 val = flgr_get_array_fgBIT(psrc,j);
00057 flgr_set_array_fgBIT(proi,k,val);
00058 }
00059
00060 }
00061 void flgr1d_extract_region_fgUINT8(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00062 FLGR_MACRO_EXTRACT_REGION_1D(fgUINT8);
00063 }
00064 void flgr1d_extract_region_fgUINT16(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00065 FLGR_MACRO_EXTRACT_REGION_1D(fgUINT16);
00066 }
00067 void flgr1d_extract_region_fgUINT32(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00068 FLGR_MACRO_EXTRACT_REGION_1D(fgUINT32);
00069 }
00070 void flgr1d_extract_region_fgINT8(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00071 FLGR_MACRO_EXTRACT_REGION_1D(fgINT8);
00072 }
00073 void flgr1d_extract_region_fgINT16(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00074 FLGR_MACRO_EXTRACT_REGION_1D(fgINT16);
00075 }
00076 void flgr1d_extract_region_fgINT32(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00077 FLGR_MACRO_EXTRACT_REGION_1D(fgINT32);
00078 }
00079 void flgr1d_extract_region_fgFLOAT32(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00080 FLGR_MACRO_EXTRACT_REGION_1D(fgFLOAT32);
00081 }
00082 void flgr1d_extract_region_fgFLOAT64(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00083 FLGR_MACRO_EXTRACT_REGION_1D(fgFLOAT64);
00084 }
00086
00092
00093 FLGR_Ret flgr1d_extract_region(FLGR_Data1D *datroi, FLGR_Data1D *datsrc, int x) {
00094 FLGR_Ret ret;
00095
00096
00097
00098 if((datroi==NULL) || (datsrc==NULL)) {
00099 POST_ERROR("Null objects!\n");
00100 return FLGR_RET_NULL_OBJECT;
00101 }
00102
00103 if( (ret=flgr1d_is_data_same_type(datsrc,datroi)) != FLGR_RET_OK ) {
00104 POST_ERROR("ROI and destination have different or illegal types");
00105 return ret;
00106 }
00107
00108 if( (ret=flgr1d_is_data_same_spp(datsrc,datroi)) != FLGR_RET_OK ) {
00109 POST_ERROR("ROI and destination have different sample per pixels");
00110 return ret;
00111 }
00112
00113 if( (x+datroi->length) > datsrc->length ) {
00114 POST_ERROR("The region of interest is too large");
00115 return FLGR_RET_SIZE_ERROR;
00116 }
00117
00118 FLGR_DISPATCH_PROCEDURE(datsrc->type,flgr1d_extract_region,datroi,datsrc,x);
00119 }
00120
00121
00122
00123
00124
00125 #define FLGR_MACRO_EXTRACT_REGION_2D(dtype) \
00126 FLGR_Data1D **psrc = datsrc->row+y; \
00127 FLGR_Data1D **proi = datroi->row; \
00128 int i; \
00129 \
00130 \
00131 \
00132 for(i=0 ; i<datroi->size_y ; i++,psrc++,proi++) { \
00133 flgr1d_extract_region_##dtype(*proi,*psrc, x); \
00134 } \
00135 return
00136
00137 void flgr2d_extract_region_fgBIT(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00138 FLGR_MACRO_EXTRACT_REGION_2D(fgBIT);
00139 }
00140 void flgr2d_extract_region_fgUINT8(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00141 FLGR_MACRO_EXTRACT_REGION_2D(fgUINT8);
00142 }
00143 void flgr2d_extract_region_fgUINT16(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00144 FLGR_MACRO_EXTRACT_REGION_2D(fgUINT16);
00145 }
00146 void flgr2d_extract_region_fgUINT32(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00147 FLGR_MACRO_EXTRACT_REGION_2D(fgUINT32);
00148 }
00149 void flgr2d_extract_region_fgINT8(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00150 FLGR_MACRO_EXTRACT_REGION_2D(fgINT8);
00151 }
00152 void flgr2d_extract_region_fgINT16(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00153 FLGR_MACRO_EXTRACT_REGION_2D(fgINT16);
00154 }
00155 void flgr2d_extract_region_fgINT32(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00156 FLGR_MACRO_EXTRACT_REGION_2D(fgINT32);
00157 }
00158 void flgr2d_extract_region_fgFLOAT32(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00159 FLGR_MACRO_EXTRACT_REGION_2D(fgFLOAT32);
00160 }
00161 void flgr2d_extract_region_fgFLOAT64(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00162 FLGR_MACRO_EXTRACT_REGION_2D(fgFLOAT64);
00163 }
00165
00172
00173 FLGR_Ret flgr2d_extract_region(FLGR_Data2D *datroi, FLGR_Data2D *datsrc, int x, int y) {
00174 FLGR_Ret ret;
00175
00176
00177
00178 if((datroi==NULL) || (datsrc==NULL)) {
00179 POST_ERROR("Null objects!\n");
00180 return FLGR_RET_NULL_OBJECT;
00181 }
00182
00183 if( (ret=flgr2d_is_data_same_type(datsrc,datroi)) != FLGR_RET_OK ) {
00184 POST_ERROR("ROI and destination have different or illegal types");
00185 return ret;
00186 }
00187
00188 if( (ret=flgr2d_is_data_same_spp(datsrc,datroi)) != FLGR_RET_OK ) {
00189 POST_ERROR("ROI and destination have different sample per pixels");
00190 return ret;
00191 }
00192
00193 if( (x+datroi->size_x) > datsrc->size_x ) {
00194 POST_ERROR("The region of interest is too large");
00195 return FLGR_RET_SIZE_ERROR;
00196 }
00197
00198 if( (y+datroi->size_y) > datsrc->size_y ) {
00199 POST_ERROR("The region of interest is too large");
00200 return FLGR_RET_SIZE_ERROR;
00201 }
00202
00203 FLGR_DISPATCH_PROCEDURE(datsrc->type,flgr2d_extract_region,datroi,datsrc,x,y);
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 #define FLGR_MACRO_INSERT_REGION_1D(dtype) \
00220 int spp = datroi->spp; \
00221 int length = datroi->length*spp; \
00222 dtype *proi,*pdest; \
00223 \
00224 \
00225 \
00226 pdest = (dtype*) datdest->array+x*spp; \
00227 proi = (dtype*) datroi->array; \
00228 \
00229 memcpy(pdest,proi,length*sizeof(dtype))
00230
00231 void flgr1d_insert_region_fgBIT(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00232 int j,k;
00233 int length = (datroi->length+x)*datroi->spp;
00234 fgBIT *proi,*pdest,val;
00235
00236
00237
00238 pdest = (fgBIT*) datdest->array;
00239 proi = (fgBIT*) datroi->array;
00240
00241 for(j=x,k=0 ; j<length ; j++,k++) {
00242 val = flgr_get_array_fgBIT(proi,k);
00243 flgr_set_array_fgBIT(pdest,j,val);
00244 }
00245
00246 }
00247 void flgr1d_insert_region_fgUINT8(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00248 FLGR_MACRO_INSERT_REGION_1D(fgUINT8);
00249 }
00250 void flgr1d_insert_region_fgUINT16(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00251 FLGR_MACRO_INSERT_REGION_1D(fgUINT16);
00252 }
00253 void flgr1d_insert_region_fgUINT32(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00254 FLGR_MACRO_INSERT_REGION_1D(fgUINT32);
00255 }
00256 void flgr1d_insert_region_fgINT8(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00257 FLGR_MACRO_INSERT_REGION_1D(fgINT8);
00258 }
00259 void flgr1d_insert_region_fgINT16(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00260 FLGR_MACRO_INSERT_REGION_1D(fgINT16);
00261 }
00262 void flgr1d_insert_region_fgINT32(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00263 FLGR_MACRO_INSERT_REGION_1D(fgINT32);
00264 }
00265 void flgr1d_insert_region_fgFLOAT32(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00266 FLGR_MACRO_INSERT_REGION_1D(fgFLOAT32);
00267 }
00268 void flgr1d_insert_region_fgFLOAT64(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00269 FLGR_MACRO_INSERT_REGION_1D(fgFLOAT64);
00270 }
00272
00278
00279 FLGR_Ret flgr1d_insert_region(FLGR_Data1D *datdest, FLGR_Data1D *datroi, int x) {
00280 FLGR_Ret ret;
00281
00282
00283
00284 if((datroi==NULL) || (datdest==NULL)) {
00285 POST_ERROR("Null objects!\n");
00286 return FLGR_RET_NULL_OBJECT;
00287 }
00288
00289 if( (ret=flgr1d_is_data_same_type(datroi,datroi)) != FLGR_RET_OK ) {
00290 POST_ERROR("ROI and destination have different or illegal types");
00291 return ret;
00292 }
00293
00294 if( (ret=flgr1d_is_data_same_spp(datroi,datroi)) != FLGR_RET_OK ) {
00295 POST_ERROR("ROI and destination have different sample per pixels");
00296 return ret;
00297 }
00298
00299 if( (x+datroi->length) > datdest->length ) {
00300 POST_ERROR("The region of interest is too large");
00301 return FLGR_RET_SIZE_ERROR;
00302 }
00303
00304 FLGR_DISPATCH_PROCEDURE(datdest->type,flgr1d_insert_region,datdest,datroi,x);
00305 }
00306
00307
00308
00309
00310
00311
00312 #define FLGR_MACRO_INSERT_REGION_2D(dtype) \
00313 FLGR_Data1D **pdest = datdest->row+y; \
00314 FLGR_Data1D **proi = datroi->row; \
00315 int i; \
00316 \
00317 \
00318 \
00319 for(i=0 ; i<datroi->size_y ; i++,pdest++,proi++) { \
00320 flgr1d_insert_region_##dtype(*pdest,*proi, x); \
00321 } \
00322 return
00323
00324 void flgr2d_insert_region_fgBIT(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00325 FLGR_MACRO_INSERT_REGION_2D(fgBIT);
00326 }
00327 void flgr2d_insert_region_fgUINT8(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00328 FLGR_MACRO_INSERT_REGION_2D(fgUINT8);
00329 }
00330 void flgr2d_insert_region_fgUINT16(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00331 FLGR_MACRO_INSERT_REGION_2D(fgUINT16);
00332 }
00333 void flgr2d_insert_region_fgUINT32(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00334 FLGR_MACRO_INSERT_REGION_2D(fgUINT32);
00335 }
00336 void flgr2d_insert_region_fgINT8(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00337 FLGR_MACRO_INSERT_REGION_2D(fgINT8);
00338 }
00339 void flgr2d_insert_region_fgINT16(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00340 FLGR_MACRO_INSERT_REGION_2D(fgINT16);
00341 }
00342 void flgr2d_insert_region_fgINT32(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00343 FLGR_MACRO_INSERT_REGION_2D(fgINT32);
00344 }
00345 void flgr2d_insert_region_fgFLOAT32(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00346 FLGR_MACRO_INSERT_REGION_2D(fgFLOAT32);
00347 }
00348 void flgr2d_insert_region_fgFLOAT64(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00349 FLGR_MACRO_INSERT_REGION_2D(fgFLOAT64);
00350 }
00352
00359
00360 FLGR_Ret flgr2d_insert_region(FLGR_Data2D *datdest, FLGR_Data2D *datroi, int x, int y) {
00361 FLGR_Ret ret;
00362
00363
00364
00365 if((datroi==NULL) || (datdest==NULL)) {
00366 POST_ERROR("Null objects!\n");
00367 return FLGR_RET_NULL_OBJECT;
00368 }
00369
00370 if( (ret=flgr2d_is_data_same_type(datroi,datroi)) != FLGR_RET_OK ) {
00371 POST_ERROR("ROI and destination have different or illegal types");
00372 return ret;
00373 }
00374
00375 if( (ret=flgr2d_is_data_same_spp(datroi,datroi)) != FLGR_RET_OK ) {
00376 POST_ERROR("ROI and destination have different sample per pixels");
00377 return ret;
00378 }
00379
00380 if( (x+datroi->size_x) > datdest->size_x ) {
00381 POST_ERROR("The region of interest is too large");
00382 return FLGR_RET_SIZE_ERROR;
00383 }
00384
00385 if( (y+datroi->size_y) > datdest->size_y ) {
00386 POST_ERROR("The region of interest is too large");
00387 return FLGR_RET_SIZE_ERROR;
00388 }
00389
00390 FLGR_DISPATCH_PROCEDURE(datdest->type,flgr2d_insert_region,datdest,datroi,x,y);
00391 }
00392
00393