00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include "flgrCoreMalloc.h"
00025 #include "flgrCoreData.h"
00026 #include "flgrCoreCopy.h"
00027 #include "flgrCoreDataIO.h"
00028 #include "flgrCoreDispatch.h"
00029 #include "flgrCoreNhbFill.h"
00030
00031
00058
00059
00064
00065 int flgr_normalize_coordinate(int axis_coord, int axis_length) {
00066 int axis_true = (-1*axis_coord-1);
00067 int axis_false;
00068 int axis_test;
00069
00070
00071
00072 axis_coord = ((axis_coord<0) ? (axis_true) : axis_coord);
00073
00074 axis_test = ((axis_coord/axis_length)%2);
00075 axis_true = axis_length - (axis_coord%axis_length) - 1;
00076 axis_false = axis_coord%axis_length;
00077
00078 axis_coord = ((axis_coord>=axis_length) && (axis_test)) ? (axis_true) : (axis_coord);
00079 axis_coord = ((axis_coord>=axis_length) && !(axis_test)) ? (axis_false) : (axis_coord);
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 return axis_coord;
00093 }
00094
00095
00096
00097
00098
00099
00106
00112
00113 #define FLGR_MACRO_CREATE1D(dtype, dtypename) \
00114 FLGR_Data1D *dat; \
00115 \
00116 \
00117 if(length<0) { \
00118 POST_ERROR("Negative length!\n"); \
00119 return NULL; \
00120 } \
00121 if(spp<1) { \
00122 POST_ERROR("Sample Per Pixel (spp) must be > 0 !\n"); \
00123 return NULL; \
00124 } \
00125 dat = (FLGR_Data1D*) flgr_malloc(sizeof(FLGR_Data1D)); \
00126 dat->dim = 1; \
00127 dat->size_struct = sizeof(FLGR_Data1D); \
00128 dat->bps = flgr_get_bps_from_type(dtypename); \
00129 dat->ref2d = -1; \
00130 dat->shape = shape; \
00131 dat->spp = spp; \
00132 dat->length = length; \
00133 dat->array_phantom = flgr_malloc_align((length*dat->bps*spp)/8+64,16);\
00134 dat->array = dat->array_phantom+32; \
00135 dat->type = dtypename; \
00136 \
00137 return dat
00138
00139
00140 FLGR_Data1D *flgr1d_create_fgBIT(int length, int spp, FLGR_Shape shape) {
00141 FLGR_MACRO_CREATE1D(fgBIT, FLGR_BIT);
00142 }
00143 FLGR_Data1D *flgr1d_create_fgUINT8(int length, int spp, FLGR_Shape shape) {
00144 FLGR_MACRO_CREATE1D(fgUINT8, FLGR_UINT8);
00145 }
00146 FLGR_Data1D *flgr1d_create_fgUINT16(int length, int spp, FLGR_Shape shape) {
00147 FLGR_MACRO_CREATE1D(fgUINT16, FLGR_UINT16);
00148 }
00149 FLGR_Data1D *flgr1d_create_fgUINT32(int length, int spp, FLGR_Shape shape) {
00150 FLGR_MACRO_CREATE1D(fgUINT32, FLGR_UINT32);
00151 }
00152 FLGR_Data1D *flgr1d_create_fgINT8(int length, int spp, FLGR_Shape shape) {
00153 FLGR_MACRO_CREATE1D(fgINT8, FLGR_INT8);
00154 }
00155 FLGR_Data1D *flgr1d_create_fgINT16(int length, int spp, FLGR_Shape shape) {
00156 FLGR_MACRO_CREATE1D(fgINT16, FLGR_INT16);
00157 }
00158 FLGR_Data1D *flgr1d_create_fgINT32(int length, int spp, FLGR_Shape shape) {
00159 FLGR_MACRO_CREATE1D(fgINT32, FLGR_INT32);
00160 }
00161 FLGR_Data1D *flgr1d_create_fgFLOAT32(int length, int spp, FLGR_Shape shape) {
00162 FLGR_MACRO_CREATE1D(fgFLOAT32, FLGR_FLOAT32);
00163 }
00164 FLGR_Data1D *flgr1d_create_fgFLOAT64(int length, int spp, FLGR_Shape shape) {
00165 FLGR_MACRO_CREATE1D(fgFLOAT64, FLGR_FLOAT64);
00166 }
00167
00169
00176
00177 FLGR_Data1D *flgr1d_create(int length, int spp, FLGR_Type type, FLGR_Shape shape) {
00178
00179
00180
00181 if(type==FLGR_BIT) return flgr1d_create_fgBIT(length, spp, shape);
00182 if(type==FLGR_UINT8) return flgr1d_create_fgUINT8(length, spp, shape);
00183 if(type==FLGR_UINT16) return flgr1d_create_fgUINT16(length, spp, shape);
00184 if(type==FLGR_UINT32) return flgr1d_create_fgUINT32(length, spp, shape);
00185 if(type==FLGR_INT8) return flgr1d_create_fgINT8(length, spp, shape);
00186 if(type==FLGR_INT16) return flgr1d_create_fgINT16(length, spp, shape);
00187 if(type==FLGR_INT32) return flgr1d_create_fgINT32(length, spp, shape);
00188 if(type==FLGR_FLOAT32) return flgr1d_create_fgFLOAT32(length, spp, shape);
00189 if(type==FLGR_FLOAT64) return flgr1d_create_fgFLOAT64(length, spp, shape);
00190
00191 POST_ERROR("Type unknown!\n");
00192 return NULL;
00193 }
00194
00196
00200
00201 FLGR_Data1D *flgr1d_create_from(FLGR_Data1D *dat) {
00202
00203
00204 if(dat==NULL) {
00205 POST_ERROR("Null objects!\n");
00206 return NULL;
00207 }
00208 return flgr1d_create(dat->length, dat->spp, dat->type, dat->shape);
00209 }
00210
00212
00218
00219 FLGR_Data1D *flgr1d_create_signal(int length, int spp, FLGR_Type type) {
00220
00221
00222 return flgr1d_create(length, spp, type, FLGR_NO_SHAPE);
00223 }
00224
00226
00230
00231 FLGR_Data1D *flgr1d_create_signal_from(FLGR_Data1D *dat) {
00232
00233
00234 if(dat==NULL) {
00235 POST_ERROR("Null objects!\n");
00236 return NULL;
00237 }
00238 return flgr1d_create(dat->length, dat->spp, dat->type, FLGR_NO_SHAPE);
00239 }
00240
00242
00249
00250 FLGR_Data1D *flgr1d_create_neighborhood(int length, int spp, FLGR_Type type, FLGR_Shape shape) {
00251 FLGR_Data1D *tmp;
00252 FLGR_Ret ret;
00253
00254
00255
00256 tmp = flgr1d_create(length, spp, type, shape);
00257
00258 if(tmp == NULL) return NULL;
00259
00260 ret = flgr1d_fill_neighborhood(tmp,shape,length);
00261
00262 if(ret != FLGR_RET_OK) {
00263 POST_ERROR("Could not fill the nhb definition\n");
00264 flgr1d_destroy(tmp);
00265 return NULL;
00266 }
00267
00268 return tmp;
00269
00270 }
00271
00273
00277
00278 FLGR_Data1D *flgr1d_create_neighborhood_from(FLGR_Data1D *dat) {
00279
00280
00281 if(dat==NULL) {
00282 POST_ERROR("Null objects!\n");
00283 return NULL;
00284 }
00285 return flgr1d_create_neighborhood(dat->length,dat->spp,dat->type,dat->shape);
00286 }
00287
00288
00290
00294
00295 FLGR_Ret flgr1d_destroy(FLGR_Data1D *dat) {
00296
00297
00298 if(dat==NULL) {
00299 POST_ERROR("Null objects!\n");
00300 return FLGR_RET_NULL_OBJECT;
00301 }
00302
00303 flgr_free_align(dat->array_phantom);
00304 flgr_free(dat);
00305
00306 return FLGR_RET_OK;
00307 }
00308
00310
00315
00316 FLGR_Ret flgr1d_is_data_same_length(FLGR_Data1D *dat1, FLGR_Data1D *dat2) {
00317
00318
00319 if((dat1==NULL) || (dat2==NULL)) {
00320 POST_ERROR("Null objects!\n");
00321 return FLGR_RET_NULL_OBJECT;
00322 }
00323
00324 if((dat1->length!=dat2->length)) {
00325 return FLGR_RET_SIZE_ERROR;
00326 }
00327 return FLGR_RET_OK;
00328 }
00329
00331
00337
00338 FLGR_Ret flgr1d_is_data_same_type(FLGR_Data1D *dat1, FLGR_Data1D *dat2) {
00339 FLGR_Ret ret;
00340
00341
00342
00343 if((dat1==NULL) || (dat2==NULL)) {
00344 POST_ERROR("Null objects!\n");
00345 return FLGR_RET_NULL_OBJECT;
00346 }
00347
00348
00349 if((ret=flgr_is_data_type_valid(dat1->type))!=FLGR_RET_OK) return ret;
00350 if((ret=flgr_is_data_type_valid(dat2->type))!=FLGR_RET_OK) return ret;
00351
00352 if(dat1->type != dat2->type) return FLGR_RET_TYPE_DIFFERENT;
00353
00354 return FLGR_RET_OK;
00355 }
00356
00358
00364
00365 FLGR_Ret flgr1d_is_data_same_spp(FLGR_Data1D *dat1, FLGR_Data1D *dat2) {
00366
00367
00368 if((dat1==NULL) || (dat2==NULL)) {
00369 POST_ERROR("Null objects!\n");
00370 return FLGR_RET_NULL_OBJECT;
00371 }
00372
00373
00374 if(dat1->spp <0) return FLGR_RET_VECTOR_SIZE_DIFFERENT;
00375 if(dat2->spp <0) return FLGR_RET_VECTOR_SIZE_DIFFERENT;
00376
00377 if(dat1->spp != dat2->spp) return FLGR_RET_VECTOR_SIZE_DIFFERENT;
00378
00379 return FLGR_RET_OK;
00380 }
00381
00382
00384
00390
00391 FLGR_Ret flgr1d_is_data_same_attributes(FLGR_Data1D *data1, FLGR_Data1D *data2, const char *callingFunction) {
00392 FLGR_Ret ret;
00393
00394
00395
00396
00397 if((data1==NULL) || (data2==NULL)) {
00398 POST_ERROR("Null objects!\n");
00399 return FLGR_RET_NULL_OBJECT;
00400 }
00401
00402 if( (ret=flgr_is_data_type_valid(data1->type))!=FLGR_RET_OK) {
00403 EPRINTF("%s: unknown type\r\n", callingFunction);
00404 return ret;
00405 }
00406
00407 if( (ret=flgr_is_data_type_valid(data2->type))!=FLGR_RET_OK) {
00408 EPRINTF("%s: unknown type\r\n", callingFunction);
00409 return ret;
00410 }
00411
00412 if((ret=flgr1d_is_data_same_type(data1, data2))!=FLGR_RET_OK) {
00413 EPRINTF("%s : source and destination have a different type\r\n", callingFunction);
00414 return ret;
00415 }
00416
00417 if((ret=flgr1d_is_data_same_spp(data1, data2))!=FLGR_RET_OK) {
00418 EPRINTF("%s : source and destination have a different vector size (spp)\r\n", callingFunction);
00419 return ret;
00420 }
00421
00422 if((ret=flgr1d_is_data_same_length(data1, data2))!=FLGR_RET_OK) {
00423 EPRINTF("%s : source and destination have a different size\r\n", callingFunction);
00424 return ret;
00425 }
00426
00427 return FLGR_RET_OK;
00428 }
00429
00430
00432
00437
00438 int flgr1d_data_is_shape(FLGR_Data1D *data, FLGR_Shape shape) {
00439
00440
00441 if(data==NULL) {
00442 POST_ERROR("Null objects!\n");
00443 return 0;
00444 }
00445 return (data->shape==shape);
00446 }
00447
00448
00449 int flgr1d_data_is_type_fgBIT(FLGR_Data1D *data) {
00450 return (data->type==FLGR_BIT);
00451 }
00452 int flgr1d_data_is_type_fgUINT8(FLGR_Data1D *data) {
00453 return (data->type==FLGR_UINT8);
00454 }
00455 int flgr1d_data_is_type_fgUINT16(FLGR_Data1D *data) {
00456 return (data->type==FLGR_UINT16);
00457 }
00458 int flgr1d_data_is_type_fgUINT32(FLGR_Data1D *data) {
00459 return (data->type==FLGR_UINT32);
00460 }
00461 int flgr1d_data_is_type_fgINT8(FLGR_Data1D *data) {
00462 return (data->type==FLGR_INT8);
00463 }
00464 int flgr1d_data_is_type_fgINT16(FLGR_Data1D *data) {
00465 return (data->type==FLGR_INT16);
00466 }
00467 int flgr1d_data_is_type_fgINT32(FLGR_Data1D *data) {
00468 return (data->type==FLGR_INT32);
00469 }
00470 int flgr1d_data_is_type_fgFLOAT32(FLGR_Data1D *data) {
00471 return (data->type==FLGR_FLOAT32);
00472 }
00473 int flgr1d_data_is_type_fgFLOAT64(FLGR_Data1D *data) {
00474 return (data->type==FLGR_FLOAT64);
00475 }
00477
00482
00483 int flgr1d_data_is_type(FLGR_Data1D *data, FLGR_Type type) {
00484
00485
00486 if(data==NULL) {
00487 POST_ERROR("Null objects!\n");
00488 return 0;
00489 }
00490 FLGR_DISPATCH_FUNCTION(FLGR_FALSE,type,flgr1d_data_is_type,data);
00491 }
00492
00494
00499
00500 FLGR_Ret flgr1d_data_set_shape(FLGR_Data1D *dat, FLGR_Shape shape) {
00501
00502
00503 if(dat==NULL) {
00504 POST_ERROR("Null objects!\n");
00505 return FLGR_RET_NULL_OBJECT;
00506 }
00507
00508 dat->shape = shape;
00509
00510 return FLGR_RET_OK;
00511 }
00512
00513
00515
00519
00520 FLGR_Ret flgr1d_clear_all(FLGR_Data1D *data) {
00521
00522
00523 if(data==NULL) {
00524 POST_ERROR("Null objects!\n");
00525 return FLGR_RET_NULL_OBJECT;
00526 }
00527
00528 memset(data->array, 0, (data->length*data->bps*data->spp)/8+32);
00529 return FLGR_RET_OK;
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00549
00555
00556
00557 #define FLGR_MACRO_CREATE2D(dtype, dtypename) \
00558 int i; \
00559 FLGR_Data2D *dat; \
00560 \
00561 \
00562 \
00563 if(size_y<0) { \
00564 POST_ERROR("Number of rows is negative !\n"); \
00565 return NULL; \
00566 } \
00567 \
00568 if(size_x<0) { \
00569 POST_ERROR("Number of columns is negative !\n"); \
00570 return NULL; \
00571 } \
00572 \
00573 if(spp<1) { \
00574 POST_ERROR("Sample Per Pixel (spp) must be > 0 !\n"); \
00575 return NULL; \
00576 } \
00577 \
00578 dat = (FLGR_Data2D*) flgr_malloc(sizeof(FLGR_Data2D)); \
00579 dat->row = (FLGR_Data1D**) flgr_malloc((size_y+16)* \
00580 sizeof(FLGR_Data1D*)); \
00581 dat->array = flgr_malloc((size_y+16)*sizeof(dtype*)); \
00582 dat->dim = 2; \
00583 dat->size_struct = sizeof(FLGR_Data2D); \
00584 dat->bps = flgr_get_bps_from_type(dtypename); \
00585 dat->spp = spp; \
00586 dat->shape = shape; \
00587 dat->connexity = connexity; \
00588 dat->size_y=size_y; \
00589 dat->size_x=size_x; \
00590 dat->type = dtypename; \
00591 dat->link_overlap = -1; \
00592 dat->link_position = -1; \
00593 dat->link_number = -1; \
00594 \
00595 for(i=0;i<(size_y+16);i++) { \
00596 dat->row[i] = flgr1d_create_##dtype(size_x, spp,FLGR_NO_SHAPE); \
00597 dat->row[i]->ref2d = i; \
00598 dat->array[i] = dat->row[i]->array; \
00599 } \
00600 \
00601 return dat
00602
00603 FLGR_Data2D *flgr2d_create_fgBIT(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00604 FLGR_MACRO_CREATE2D(fgBIT, FLGR_BIT);
00605 }
00606 FLGR_Data2D *flgr2d_create_fgUINT8(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00607 FLGR_MACRO_CREATE2D(fgUINT8, FLGR_UINT8);
00608 }
00609 FLGR_Data2D *flgr2d_create_fgUINT16(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00610 FLGR_MACRO_CREATE2D(fgUINT16, FLGR_UINT16);
00611 }
00612 FLGR_Data2D *flgr2d_create_fgUINT32(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00613 FLGR_MACRO_CREATE2D(fgUINT32, FLGR_UINT32);
00614 }
00615 FLGR_Data2D *flgr2d_create_fgINT8(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00616 FLGR_MACRO_CREATE2D(fgINT8, FLGR_INT8);
00617 }
00618 FLGR_Data2D *flgr2d_create_fgINT16(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00619 FLGR_MACRO_CREATE2D(fgINT16, FLGR_INT16);
00620 }
00621 FLGR_Data2D *flgr2d_create_fgINT32(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00622 FLGR_MACRO_CREATE2D(fgINT32, FLGR_INT32);
00623 }
00624 FLGR_Data2D *flgr2d_create_fgFLOAT32(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00625 FLGR_MACRO_CREATE2D(fgFLOAT32, FLGR_FLOAT32);
00626 }
00627 FLGR_Data2D *flgr2d_create_fgFLOAT64(int size_y, int size_x, int spp, FLGR_Shape shape, FLGR_Connexity connexity) {
00628 FLGR_MACRO_CREATE2D(fgFLOAT64, FLGR_FLOAT64);
00629 }
00630
00631 FLGR_Data2D *flgr2d_create(int size_y, int size_x, int spp, FLGR_Type type, FLGR_Shape shape, FLGR_Connexity connexity) {
00632
00633
00634 if(type==FLGR_BIT) return flgr2d_create_fgBIT(size_y, size_x, spp, shape, connexity);
00635 if(type==FLGR_UINT8) return flgr2d_create_fgUINT8(size_y, size_x, spp, shape, connexity);
00636 if(type==FLGR_UINT16) return flgr2d_create_fgUINT16(size_y, size_x, spp, shape, connexity);
00637 if(type==FLGR_UINT32) return flgr2d_create_fgUINT32(size_y, size_x, spp, shape, connexity);
00638 if(type==FLGR_INT8) return flgr2d_create_fgINT8(size_y, size_x, spp, shape, connexity);
00639 if(type==FLGR_INT16) return flgr2d_create_fgINT16(size_y, size_x, spp, shape, connexity);
00640 if(type==FLGR_INT32) return flgr2d_create_fgINT32(size_y, size_x, spp, shape, connexity);
00641 if(type==FLGR_FLOAT32) return flgr2d_create_fgFLOAT32(size_y, size_x, spp, shape, connexity);
00642 if(type==FLGR_FLOAT64) return flgr2d_create_fgFLOAT64(size_y, size_x, spp, shape, connexity);
00643
00644 POST_ERROR("Type unknown!\n");
00645 return NULL;
00646
00647 }
00648
00649 FLGR_Data2D *flgr2d_create_from(FLGR_Data2D *datsrc) {
00650
00651
00652 if(datsrc==NULL) {
00653 POST_ERROR("Null objects!\n");
00654 return NULL;
00655 }
00656 return flgr2d_create(datsrc->size_y,datsrc->size_x,datsrc->spp,datsrc->type,datsrc->shape,datsrc->connexity);
00657 }
00658
00659
00661
00668
00669 FLGR_Data2D *flgr2d_create_pixmap(int size_y, int size_x, int spp, FLGR_Type type) {
00670
00671
00672 return flgr2d_create(size_y, size_x, spp, type, FLGR_NO_SHAPE, FLGR_NO_CONNEX);
00673 }
00674
00676
00680
00681 FLGR_Data2D *flgr2d_create_pixmap_from(FLGR_Data2D *imgsrc) {
00682
00683
00684 if(imgsrc==NULL) {
00685 POST_ERROR("Null objects!\n");
00686 return NULL;
00687 }
00688 return flgr2d_create(imgsrc->size_y, imgsrc->size_x, imgsrc->spp, imgsrc->type, FLGR_NO_SHAPE, FLGR_NO_CONNEX);
00689 }
00690
00692
00701
00702 FLGR_Data2D *flgr2d_create_neighborhood(int size_y, int size_x, int spp, FLGR_Type type,
00703 FLGR_Shape shape, FLGR_Connexity connexity) {
00704 FLGR_Data2D *nhb;
00705
00706
00707
00708 if((size_x%2)==0) {
00709 POST_WARNING("Warning NhbWidth(%d) is even! Changing to the next odd value (%d) \n", size_x, size_x+1);
00710 size_x++;
00711 }
00712 if((size_y%2)==0) {
00713 POST_WARNING("Warning NhbWidth(%d) is even! Changing to the next odd value (%d) \n", size_y, size_y+1);
00714 size_y++;
00715 }
00716
00717 if( (connexity != FLGR_4_CONNEX) && (connexity != FLGR_6_CONNEX) && (connexity != FLGR_8_CONNEX)) {
00718 POST_ERROR("bad connexity : %d\n", connexity);
00719 return NULL;
00720 }
00721
00722 if((nhb=flgr2d_create(size_y, size_x, spp, type, shape, connexity))==NULL) return NULL;
00723
00724 if(flgr2d_fill_neighborhood(nhb, shape, size_x,size_y)!=FLGR_RET_OK) {
00725 flgr2d_destroy(nhb);
00726 return NULL;
00727 }
00728
00729 return nhb;
00730
00731 }
00732
00734
00739
00740 FLGR_Data2D *flgr2d_create_neighborhood_from(FLGR_Data2D *nhbsrc) {
00741
00742
00743 if(nhbsrc==NULL) {
00744 POST_ERROR("Null objects!\n");
00745 return NULL;
00746 }
00747 return flgr2d_create_neighborhood(nhbsrc->size_y, nhbsrc->size_x, nhbsrc->spp,
00748 nhbsrc->type, nhbsrc->shape, nhbsrc->connexity);
00749 }
00750
00752
00758
00759 FLGR_Data2D *flgr2d_create_neighborhood_from_connexity(int spp, FLGR_Type type, FLGR_Connexity connexity) {
00760
00761
00762 switch(connexity) {
00763 case FLGR_8_CONNEX:
00764 return flgr2d_create_neighborhood(3, 3, spp, type, FLGR_RECT, FLGR_8_CONNEX);
00765
00766 case FLGR_6_CONNEX:
00767 return flgr2d_create_neighborhood(3, 3, spp, type, FLGR_HEX, FLGR_6_CONNEX);
00768
00769 case FLGR_4_CONNEX:
00770 return flgr2d_create_neighborhood(3, 3, spp, type, FLGR_CROSS, FLGR_4_CONNEX);
00771
00772 default:
00773 POST_ERROR("bad connexity : %d\n", connexity);
00774 return NULL;
00775 }
00776 }
00777
00778
00780
00784
00785 FLGR_Ret flgr2d_destroy(FLGR_Data2D *dat) {
00786 int i;
00787
00788
00789
00790 if(dat==NULL) {
00791 POST_ERROR("Null objects!\n");
00792 return FLGR_RET_NULL_OBJECT;
00793 }
00794
00795 if(dat->link_overlap > -1) {
00796 POST_WARNING("Destroying a linked data, branching to flgr2d_destroy_link\n");
00797 return flgr2d_destroy_link(dat);
00798 }
00799
00800 for(i=0 ; i<dat->size_y+16 ; i++) {
00801 flgr1d_destroy(dat->row[i]);
00802 }
00803
00804 flgr_free(dat->array);
00805 flgr_free(dat->row);
00806 flgr_free(dat);
00807
00808 return FLGR_RET_OK;
00809 }
00810
00811
00812
00814
00821
00822 FLGR_Data2D *flgr2d_create_pixmap_link(FLGR_Data2D *datain, int partsNumber, int partIndex, int overlapSize) {
00823 FLGR_Data2D *dat;
00824 int i,k,nbrow,startin;
00825
00826
00827
00828 if(overlapSize < 0) {
00829 POST_ERROR("overlapSize could not be < 0 !\n");
00830 return NULL;
00831 }
00832
00833 if(partsNumber < 1) {
00834 POST_ERROR("Number of parts must be > 0 !\n");
00835 return NULL;
00836 }
00837
00838 if(partIndex >= partsNumber) {
00839 POST_ERROR("Index reference (%d) does not exists!\n",partIndex);
00840 return NULL;
00841 }
00842
00843 if(partIndex < 0) {
00844 POST_ERROR("Index reference (%d) does not exists!\n",partIndex);
00845 return NULL;
00846 }
00847
00848 dat = (FLGR_Data2D*) flgr_malloc(sizeof(FLGR_Data2D));
00849 dat->link_overlap = overlapSize;
00850 dat->link_position = partIndex;
00851 dat->link_number = partsNumber;
00852 dat->dim = 2;
00853 dat->size_struct = sizeof(FLGR_Data2D);
00854 dat->bps = datain->bps;
00855 dat->spp = datain->spp;
00856 dat->shape = FLGR_NO_SHAPE;
00857 dat->connexity = FLGR_NO_CONNEX;
00858 dat->size_x = datain->size_x;
00859 dat->type = datain->type;
00860
00861 startin = (datain->size_y * partIndex) / partsNumber;
00862
00863 if(partIndex == 0) {
00864 nbrow = datain->size_y/partsNumber + overlapSize;
00865
00866 dat->row = (FLGR_Data1D**) flgr_malloc( (nbrow+16) * sizeof(FLGR_Data1D*));
00867 dat->array = flgr_malloc( (nbrow+16) * sizeof(void*));
00868 dat->size_y = nbrow;
00869
00870 for(i=0 ; i<nbrow-overlapSize ; i++) {
00871 dat->row[i] = datain->row[i];
00872 dat->row[i]->ref2d = i;
00873 dat->array[i] = dat->row[i]->array;
00874 }
00875
00876 for(i=nbrow-overlapSize ; i<nbrow ; i++) {
00877 dat->row[i] = flgr1d_create(dat->size_x, dat->spp, dat->type, FLGR_NO_SHAPE);
00878 dat->row[i]->ref2d = i;
00879 dat->array[i] = dat->row[i]->array;
00880 flgr1d_copy(dat->row[i],datain->row[i]);
00881 }
00882
00883 for(i=nbrow ; i<nbrow+16 ; i++) {
00884 dat->row[i] = flgr1d_create(dat->size_x, dat->spp, dat->type, FLGR_NO_SHAPE);
00885 dat->row[i]->ref2d = i;
00886 dat->array[i] = dat->row[i]->array;
00887 }
00888
00889
00890
00891
00892 }else if(partIndex == (partsNumber-1)) {
00893 nbrow = datain->size_y/partsNumber + overlapSize;
00894
00895 dat->row = (FLGR_Data1D**) flgr_malloc( (nbrow+16) * sizeof(FLGR_Data1D*));
00896 dat->array = flgr_malloc( (nbrow+16) * sizeof(void*));
00897 dat->size_y = nbrow;
00898
00899 i = startin-overlapSize;
00900 k=0;
00901
00902 for( ; k<overlapSize ; i++,k++) {
00903 dat->row[k] = flgr1d_create(dat->size_x, dat->spp, dat->type, FLGR_NO_SHAPE);
00904 dat->row[k]->ref2d = k;
00905 dat->array[k] = dat->row[k]->array;
00906 flgr1d_copy(dat->row[k],datain->row[i]);
00907 }
00908
00909 for( ; k<nbrow ; i++,k++) {
00910 dat->row[k] = datain->row[i];
00911 dat->row[k]->ref2d = k;
00912 dat->array[k] = dat->row[k]->array;
00913 }
00914
00915 for( ; k<nbrow+16 ; k++) {
00916 dat->row[k] = flgr1d_create(dat->size_x, dat->spp, dat->type, FLGR_NO_SHAPE);
00917 dat->row[k]->ref2d = k;
00918 dat->array[k] = dat->row[k]->array;
00919 }
00920
00921
00922
00923
00924
00925
00926 }else {
00927 nbrow = datain->size_y/partsNumber + 2*overlapSize;
00928
00929 dat->row = (FLGR_Data1D**) flgr_malloc( (nbrow+16) * sizeof(FLGR_Data1D*));
00930 dat->array = flgr_malloc( (nbrow+16) * sizeof(void*));
00931 dat->size_y = nbrow;
00932
00933 i = startin-overlapSize;
00934 k=0;
00935
00936 for( ; k<overlapSize ; i++,k++) {
00937 dat->row[k] = flgr1d_create(dat->size_x, dat->spp, dat->type, FLGR_NO_SHAPE);
00938 dat->row[k]->ref2d = k;
00939 dat->array[k] = dat->row[k]->array;
00940 flgr1d_copy(dat->row[k],datain->row[i]);
00941 }
00942
00943 for( ; k<nbrow-overlapSize ; i++,k++) {
00944 dat->row[k] = datain->row[i];
00945 dat->row[k]->ref2d = k;
00946 dat->array[k] = dat->row[k]->array;
00947 }
00948
00949 for( ; k<nbrow ; i++,k++) {
00950 dat->row[k] = flgr1d_create(dat->size_x, dat->spp, dat->type, FLGR_NO_SHAPE);
00951 dat->row[k]->ref2d = k;
00952 dat->array[k] = dat->row[k]->array;
00953 flgr1d_copy(dat->row[k],datain->row[i]);
00954 }
00955
00956 for( ; k<nbrow+16 ; k++) {
00957 dat->row[k] = flgr1d_create(dat->size_x, dat->spp, dat->type, FLGR_NO_SHAPE);
00958 dat->row[k]->ref2d = k;
00959 dat->array[k] = dat->row[k]->array;
00960 }
00961
00962 }
00963
00964
00965
00966 return dat;
00967 }
00968
00969
00971
00975
00976 FLGR_Ret flgr2d_destroy_link(FLGR_Data2D *dat) {
00977 int k;
00978
00979
00980
00981 if(dat==NULL) {
00982 POST_ERROR("Null objects!\n");
00983 return FLGR_RET_NULL_OBJECT;
00984 }
00985
00986 if(dat->link_overlap == -1) {
00987 POST_WARNING("Destroying a non-linked data, branching to flgr2d_destroy\n");
00988 return flgr2d_destroy(dat);
00989 }
00990
00991 if(dat->link_position == 0) {
00992 for(k=dat->size_y-dat->link_overlap ; k<dat->size_y+16 ; k++) {
00993 flgr1d_destroy(dat->row[k]);
00994 }
00995
00996 }else if( dat->link_position == (dat->link_number - 1) ) {
00997 for(k=0 ; k<dat->link_overlap ; k++) {
00998 flgr1d_destroy(dat->row[k]);
00999 }
01000
01001 for(k=dat->size_y ; k<dat->size_y+16 ; k++) {
01002 flgr1d_destroy(dat->row[k]);
01003 }
01004
01005 }else {
01006 for(k=0 ; k<dat->link_overlap ; k++) {
01007 flgr1d_destroy(dat->row[k]);
01008 }
01009 for(k=dat->size_y-dat->link_overlap ; k<dat->size_y+16 ; k++) {
01010 flgr1d_destroy(dat->row[k]);
01011 }
01012 }
01013
01014 flgr_free(dat->array);
01015 flgr_free(dat->row);
01016 flgr_free(dat);
01017
01018 return FLGR_RET_OK;
01019 }
01020
01021
01022
01024
01029
01030 FLGR_Ret flgr2d_is_data_same_type(FLGR_Data2D *data1, FLGR_Data2D *data2) {
01031 FLGR_Ret ret;
01032
01033
01034
01035 if((data1==NULL) || (data2==NULL)) {
01036 POST_ERROR("Null objects!\n");
01037 return FLGR_RET_NULL_OBJECT;
01038 }
01039
01040 if( (ret=flgr_is_data_type_valid(data1->type)) != FLGR_RET_OK ) return ret;
01041 if( (ret=flgr_is_data_type_valid(data2->type)) != FLGR_RET_OK ) return ret;
01042
01043 if(data1->type != data2->type) {
01044 return FLGR_RET_TYPE_DIFFERENT;
01045 }
01046
01047 return FLGR_RET_OK;
01048 }
01049
01051
01057
01058 FLGR_Ret flgr2d_is_data_same_spp(FLGR_Data2D *dat1, FLGR_Data2D *dat2) {
01059
01060
01061 if((dat1==NULL) || (dat2==NULL)) {
01062 POST_ERROR("Null objects!\n");
01063 return FLGR_RET_NULL_OBJECT;
01064 }
01065
01066
01067 if(dat1->spp <0) return FLGR_RET_VECTOR_SIZE_DIFFERENT;
01068 if(dat2->spp <0) return FLGR_RET_VECTOR_SIZE_DIFFERENT;
01069
01070 if(dat1->spp != dat2->spp) return FLGR_RET_VECTOR_SIZE_DIFFERENT;
01071
01072 return FLGR_RET_OK;
01073 }
01074
01076
01081
01082 FLGR_Ret flgr2d_is_data_same_size(FLGR_Data2D *data1, FLGR_Data2D *data2) {
01083
01084
01085
01086 if((data1==NULL) || (data2==NULL)) {
01087 POST_ERROR("Null objects!\n");
01088 return FLGR_RET_NULL_OBJECT;
01089 }
01090
01091 if((data1->size_y!=data2->size_y)||(data1->size_x!=data2->size_x)) {
01092 return FLGR_RET_SIZE_ERROR;
01093 }
01094
01095 return FLGR_RET_OK;
01096 }
01097
01099
01105
01106 FLGR_Ret flgr2d_is_data_same_attributes(FLGR_Data2D *data1, FLGR_Data2D *data2, const char *callingFunction) {
01107 FLGR_Ret ret;
01108
01109
01110
01111 if((data1==NULL) || (data2==NULL)) {
01112 POST_ERROR("Null objects!\n");
01113 return FLGR_RET_NULL_OBJECT;
01114 }
01115
01116 if( (ret=flgr_is_data_type_valid(data1->type))!=FLGR_RET_OK) {
01117 EPRINTF("ERROR: Function %s: unknown type\r\n", callingFunction);
01118 return ret;
01119 }
01120
01121 if( (ret=flgr_is_data_type_valid(data2->type))!=FLGR_RET_OK) {
01122 EPRINTF("ERROR: Function %s: unknown type\r\n", callingFunction);
01123 return ret;
01124 }
01125
01126 if((ret=flgr2d_is_data_same_type(data1, data2))!=FLGR_RET_OK) {
01127 EPRINTF("ERROR: Function %s: source and destination have a different type\r\n", callingFunction);
01128 return ret;
01129 }
01130
01131 if((ret=flgr2d_is_data_same_spp(data1, data2))!=FLGR_RET_OK) {
01132 EPRINTF("ERROR: Function %s: source and destination have a different vector size(spp)\r\n", callingFunction);
01133 return ret;
01134 }
01135
01136 if((data1->size_y!=data2->size_y)||(data1->size_x!=data2->size_x)) {
01137 EPRINTF("ERROR: Function %s: source and destination have a different size\r\n", callingFunction);
01138 return FLGR_RET_SIZE_ERROR;
01139 }
01140
01141 return FLGR_RET_OK;
01142 }
01143
01144
01145
01146
01148
01153
01154 int flgr2d_data_is_shape(FLGR_Data2D *data, FLGR_Shape shape) {
01155
01156
01157 if(data==NULL) {
01158 POST_ERROR("Null objects!\n");
01159 return 0;
01160 }
01161
01162 return (data->shape==shape);
01163 }
01164
01166
01171
01172 int flgr2d_data_is_connexity(FLGR_Data2D *data, FLGR_Connexity connexity) {
01173
01174
01175 if(data==NULL) {
01176 POST_ERROR("Null objects!\n");
01177 return 0;
01178 }
01179
01180 return (data->connexity==connexity);
01181 }
01182
01183 int flgr2d_data_is_type_fgBIT(FLGR_Data2D *data) {
01184 return (data->type==FLGR_BIT);
01185 }
01186 int flgr2d_data_is_type_fgUINT8(FLGR_Data2D *data) {
01187 return (data->type==FLGR_UINT8);
01188 }
01189 int flgr2d_data_is_type_fgUINT16(FLGR_Data2D *data) {
01190 return (data->type==FLGR_UINT16);
01191 }
01192 int flgr2d_data_is_type_fgUINT32(FLGR_Data2D *data) {
01193 return (data->type==FLGR_UINT32);
01194 }
01195 int flgr2d_data_is_type_fgINT8(FLGR_Data2D *data) {
01196 return (data->type==FLGR_INT8);
01197 }
01198 int flgr2d_data_is_type_fgINT16(FLGR_Data2D *data) {
01199 return (data->type==FLGR_INT16);
01200 }
01201 int flgr2d_data_is_type_fgINT32(FLGR_Data2D *data) {
01202 return (data->type==FLGR_INT32);
01203 }
01204 int flgr2d_data_is_type_fgFLOAT32(FLGR_Data2D *data) {
01205 return (data->type==FLGR_FLOAT32);
01206 }
01207 int flgr2d_data_is_type_fgFLOAT64(FLGR_Data2D *data) {
01208 return (data->type==FLGR_FLOAT64);
01209 }
01210
01212
01217
01218 int flgr2d_data_is_type(FLGR_Data2D *data, FLGR_Type type) {
01219
01220
01221 if(data==NULL) {
01222 POST_ERROR("Null objects!\n");
01223 return 0;
01224 }
01225
01226 FLGR_DISPATCH_FUNCTION(FLGR_FALSE,type,flgr2d_data_is_type,data);
01227 }
01228
01230
01235
01236 FLGR_Ret flgr2d_data_set_shape(FLGR_Data2D *dat, FLGR_Shape shape) {
01237
01238
01239 if(dat==NULL) {
01240 POST_ERROR("Null objects!\n");
01241 return 0;
01242 }
01243
01244 dat->shape = shape;
01245
01246 return FLGR_RET_OK;
01247 }
01248
01250
01255
01256 FLGR_Ret flgr2d_data_set_connexity(FLGR_Data2D *dat, FLGR_Connexity connexity) {
01257
01258
01259 if(dat==NULL) {
01260 POST_ERROR("Null objects!\n");
01261 return 0;
01262 }
01263
01264 dat->connexity = connexity;
01265 return FLGR_RET_OK;
01266 }
01267
01268
01270
01274
01275 FLGR_Ret flgr2d_clear_all(FLGR_Data2D *data) {
01276 int i;
01277
01278
01279
01280 if(data==NULL) {
01281 POST_ERROR("Null objects!\n");
01282 return FLGR_RET_NULL_OBJECT;
01283 }
01284
01285
01286 for(i=0 ; i<data->size_y ; i++) flgr1d_clear_all(data->row[i]);
01287
01288 return FLGR_RET_OK;
01289 }
01290
01291
01293