00001
00017 #include "global.h"
00018 #include "memalloc.h"
00019
00020 #if !defined(USEMMX)
00021
00030 int init_top_bot_planes(imgpel **imgFrame, int dim0, imgpel ***imgTopField, imgpel ***imgBotField)
00031 {
00032 int i;
00033
00034 if((*imgTopField = (imgpel**) malloc((dim0>>1) * sizeof(imgpel*))) == NULL)
00035 no_mem_exit("init_top_bot_planes: imgTopField");
00036
00037 if((*imgBotField = (imgpel**) malloc((dim0>>1) * sizeof(imgpel*))) == NULL)
00038 no_mem_exit("init_top_bot_planes: imgBotField");
00039
00040 for(i = 0; i < (dim0>>1); i++)
00041 {
00042 (*imgTopField)[i] = imgFrame[2 * i ];
00043 (*imgBotField)[i] = imgFrame[2 * i + 1];
00044 }
00045
00046 return dim0 * sizeof(imgpel*);
00047 }
00048
00057 void free_top_bot_planes(imgpel **imgTopField, imgpel **imgBotField)
00058 {
00059 free (imgTopField);
00060 free (imgBotField);
00061 }
00062
00071 int get_mem2Ddist(DistortionData ***array2D, int dim0, int dim1)
00072 {
00073 int i;
00074
00075 if((*array2D = (DistortionData**)malloc(dim0 * sizeof(DistortionData*))) == NULL)
00076 no_mem_exit("get_mem2Ddist: array2D");
00077 if((*(*array2D) = (DistortionData* )calloc(dim0 * dim1,sizeof(DistortionData ))) == NULL)
00078 no_mem_exit("get_mem2Ddist: array2D");
00079
00080 for(i = 1 ; i < dim0; i++)
00081 (*array2D)[i] = (*array2D)[i-1] + dim1;
00082
00083 return dim0 * (sizeof(DistortionData*) + dim1 * sizeof(DistortionData));
00084 }
00085
00094 int get_mem2Dlm(LambdaParams ***array2D, int dim0, int dim1)
00095 {
00096 int i;
00097
00098 if((*array2D = (LambdaParams**)malloc(dim0 * sizeof(LambdaParams*))) == NULL)
00099 no_mem_exit("get_mem2Dlm: array2D");
00100 if((*(*array2D) = (LambdaParams* )calloc(dim0 * dim1,sizeof(LambdaParams ))) == NULL)
00101 no_mem_exit("get_mem2Dlm: array2D");
00102
00103 for(i = 1 ; i < dim0; i++)
00104 (*array2D)[i] = (*array2D)[i-1] + dim1;
00105
00106 return dim0 * (sizeof(LambdaParams*) + dim1 * sizeof(LambdaParams));
00107 }
00108
00116 void free_mem2Ddist(DistortionData **array2D)
00117 {
00118 if (array2D)
00119 {
00120 if (*array2D)
00121 free (*array2D);
00122 else
00123 error ("free_mem2Ddist: trying to free unused memory",100);
00124
00125 free (array2D);
00126 }
00127 else
00128 {
00129 error ("free_mem2Ddist: trying to free unused memory",100);
00130 }
00131 }
00132
00140 void free_mem2Dlm(LambdaParams **array2D)
00141 {
00142 if (array2D)
00143 {
00144 if (*array2D)
00145 free (*array2D);
00146 else
00147 error ("free_mem2Dlm: trying to free unused memory",100);
00148
00149 free (array2D);
00150 }
00151 else
00152 {
00153 error ("free_mem2Dlm: trying to free unused memory",100);
00154 }
00155 }
00156
00165 int get_mem2Dmp(PicMotionParams2 ***array2D, int dim0, int dim1)
00166 {
00167 int i;
00168
00169 if((*array2D = (PicMotionParams2**)malloc(dim0 * sizeof(PicMotionParams2*))) == NULL)
00170 no_mem_exit("get_mem2Dmv: array2D");
00171 if((*(*array2D) = (PicMotionParams2* )calloc(dim0 * dim1,sizeof(PicMotionParams2 ))) == NULL)
00172 no_mem_exit("get_mem2Dmp: array2D");
00173
00174 for(i = 1 ; i < dim0; i++)
00175 (*array2D)[i] = (*array2D)[i-1] + dim1;
00176
00177 return dim0 * (sizeof(PicMotionParams2*) + dim1 * sizeof(PicMotionParams2));
00178 }
00179
00189 int get_mem3Dmp(PicMotionParams2 ****array3D, int dim0, int dim1, int dim2)
00190 {
00191 int i, mem_size = dim0 * sizeof(PicMotionParams2**);
00192
00193 if(((*array3D) = (PicMotionParams2***)malloc(dim0 * sizeof(PicMotionParams2**))) == NULL)
00194 no_mem_exit("get_mem3Dmp: array3D");
00195
00196 mem_size += get_mem2Dmp(*array3D, dim0 * dim1, dim2);
00197
00198 for(i = 1; i < dim0; i++)
00199 (*array3D)[i] = (*array3D)[i - 1] + dim1;
00200
00201 return mem_size;
00202 }
00203
00211 void free_mem2Dmp(PicMotionParams2 **array2D)
00212 {
00213 if (array2D)
00214 {
00215 if (*array2D)
00216 free (*array2D);
00217 else
00218 error ("free_mem2Dmp: trying to free unused memory",100);
00219
00220 free (array2D);
00221 }
00222 else
00223 {
00224 error ("free_mem2Dmp: trying to free unused memory",100);
00225 }
00226 }
00227
00228
00236 void free_mem3Dmp(PicMotionParams2 ***array3D)
00237 {
00238 if (array3D)
00239 {
00240 free_mem2Dmp(*array3D);
00241 free (array3D);
00242 }
00243 else
00244 {
00245 error ("free_mem3Dmp: trying to free unused memory",100);
00246 }
00247 }
00248
00249
00250
00259 int get_mem2Dquant(LevelQuantParams ***array2D, int dim0, int dim1)
00260 {
00261 int i;
00262
00263 if((*array2D = (LevelQuantParams**) malloc(dim0 * sizeof(LevelQuantParams*))) == NULL)
00264 no_mem_exit("get_mem2Dquant: array2D");
00265 if((*(*array2D) = (LevelQuantParams* ) calloc(dim0 * dim1,sizeof(LevelQuantParams ))) == NULL)
00266 no_mem_exit("get_mem2Dquant: array2D");
00267
00268 for(i = 1 ; i < dim0; i++)
00269 (*array2D)[i] = (*array2D)[i-1] + dim1;
00270
00271 return dim0 * (sizeof(LevelQuantParams*) + dim1 * sizeof(LevelQuantParams));
00272 }
00273
00283 int get_mem3Dquant(LevelQuantParams ****array3D, int dim0, int dim1, int dim2)
00284 {
00285 int i, mem_size = dim0 * sizeof(LevelQuantParams**);
00286
00287 if(((*array3D) = (LevelQuantParams***)malloc(dim0 * sizeof(LevelQuantParams**))) == NULL)
00288 no_mem_exit("get_mem3Dquant: array3D");
00289
00290 mem_size += get_mem2Dquant(*array3D, dim0 * dim1, dim2);
00291
00292 for(i = 1; i < dim0; i++)
00293 (*array3D)[i] = (*array3D)[i - 1] + dim1;
00294
00295 return mem_size;
00296 }
00297
00307 int get_mem4Dquant(LevelQuantParams *****array4D, int dim0, int dim1, int dim2, int dim3)
00308 {
00309 int i, mem_size = dim0 * sizeof(LevelQuantParams***);
00310
00311 if(((*array4D) = (LevelQuantParams****)malloc(dim0 * sizeof(LevelQuantParams***))) == NULL)
00312 no_mem_exit("get_mem4Dquant: array4D");
00313
00314 mem_size += get_mem3Dquant(*array4D, dim0 * dim1, dim2, dim3);
00315
00316 for(i = 1; i < dim0; i++)
00317 (*array4D)[i] = (*array4D)[i - 1] + dim1;
00318
00319 return mem_size;
00320 }
00321
00331 int get_mem5Dquant(LevelQuantParams ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4)
00332 {
00333 int i, mem_size = dim0 * sizeof(LevelQuantParams***);
00334
00335 if(((*array5D) = (LevelQuantParams*****)malloc(dim0 * sizeof(LevelQuantParams****))) == NULL)
00336 no_mem_exit("get_mem5Dquant: array5D");
00337
00338 mem_size += get_mem4Dquant(*array5D, dim0 * dim1, dim2, dim3, dim4);
00339
00340 for(i = 1; i < dim0; i++)
00341 (*array5D)[i] = (*array5D)[i - 1] + dim1;
00342
00343 return mem_size;
00344 }
00345
00353 void free_mem2Dquant(LevelQuantParams **array2D)
00354 {
00355 if (array2D)
00356 {
00357 if (*array2D)
00358 free (*array2D);
00359 else
00360 error ("free_mem2Dquant: trying to free unused memory",100);
00361
00362 free (array2D);
00363 }
00364 else
00365 {
00366 error ("free_mem2Dquant: trying to free unused memory",100);
00367 }
00368 }
00369
00370
00378 void free_mem3Dquant(LevelQuantParams ***array3D)
00379 {
00380 if (array3D)
00381 {
00382 free_mem2Dquant(*array3D);
00383 free (array3D);
00384 }
00385 else
00386 {
00387 error ("free_mem3Dquant: trying to free unused memory",100);
00388 }
00389 }
00390
00398 void free_mem4Dquant(LevelQuantParams ****array4D)
00399 {
00400 if (array4D)
00401 {
00402 free_mem3Dquant(*array4D);
00403 free (array4D);
00404 }
00405 else
00406 {
00407 error ("free_mem4Dquant: trying to free unused memory",100);
00408 }
00409 }
00410
00418 void free_mem5Dquant(LevelQuantParams *****array5D)
00419 {
00420 if (array5D)
00421 {
00422 free_mem4Dquant(*array5D);
00423 free (array5D);
00424 }
00425 else
00426 {
00427 error ("free_mem5Dquant: trying to free unused memory",100);
00428 }
00429 }
00430
00431
00432
00433
00442 int get_mem2Dmv(MotionVector ***array2D, int dim0, int dim1)
00443 {
00444 int i;
00445
00446 if((*array2D = (MotionVector**)malloc(dim0 * sizeof(MotionVector*))) == NULL)
00447 no_mem_exit("get_mem2Dmv: array2D");
00448 if((*(*array2D) = (MotionVector* )calloc(dim0 * dim1,sizeof(MotionVector ))) == NULL)
00449 no_mem_exit("get_mem2Dmv: array2D");
00450
00451 for(i = 1 ; i < dim0; i++)
00452 (*array2D)[i] = (*array2D)[i-1] + dim1;
00453
00454 return dim0 * (sizeof(MotionVector*) + dim1 * sizeof(MotionVector));
00455 }
00456
00466 int get_mem3Dmv(MotionVector ****array3D, int dim0, int dim1, int dim2)
00467 {
00468 int i, mem_size = dim0 * sizeof(MotionVector**);
00469
00470 if(((*array3D) = (MotionVector***)malloc(dim0 * sizeof(MotionVector**))) == NULL)
00471 no_mem_exit("get_mem3Dmv: array3D");
00472
00473 mem_size += get_mem2Dmv(*array3D, dim0 * dim1, dim2);
00474
00475 for(i = 1; i < dim0; i++)
00476 (*array3D)[i] = (*array3D)[i - 1] + dim1;
00477
00478 return mem_size;
00479 }
00480
00490 int get_mem4Dmv(MotionVector *****array4D, int dim0, int dim1, int dim2, int dim3)
00491 {
00492 int i, mem_size = dim0 * sizeof(MotionVector***);
00493
00494 if(((*array4D) = (MotionVector****)malloc(dim0 * sizeof(MotionVector***))) == NULL)
00495 no_mem_exit("get_mem4Dpel: array4D");
00496
00497 mem_size += get_mem3Dmv(*array4D, dim0 * dim1, dim2, dim3);
00498
00499 for(i = 1; i < dim0; i++)
00500 (*array4D)[i] = (*array4D)[i - 1] + dim1;
00501
00502 return mem_size;
00503 }
00504
00514 int get_mem5Dmv(MotionVector ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4)
00515 {
00516 int i, mem_size = dim0 * sizeof(MotionVector***);
00517
00518 if(((*array5D) = (MotionVector*****)malloc(dim0 * sizeof(MotionVector****))) == NULL)
00519 no_mem_exit("get_mem5Dpel: array5D");
00520
00521 mem_size += get_mem4Dmv(*array5D, dim0 * dim1, dim2, dim3, dim4);
00522
00523 for(i = 1; i < dim0; i++)
00524 (*array5D)[i] = (*array5D)[i - 1] + dim1;
00525
00526 return mem_size;
00527 }
00528
00536 void free_mem2Dmv(MotionVector **array2D)
00537 {
00538 if (array2D)
00539 {
00540 if (*array2D)
00541 free (*array2D);
00542 else
00543 error ("free_mem2Dmv: trying to free unused memory",100);
00544
00545 free (array2D);
00546 }
00547 else
00548 {
00549 error ("free_mem2Dmv: trying to free unused memory",100);
00550 }
00551 }
00552
00553
00561 void free_mem3Dmv(MotionVector ***array3D)
00562 {
00563 if (array3D)
00564 {
00565 free_mem2Dmv(*array3D);
00566 free (array3D);
00567 }
00568 else
00569 {
00570 error ("free_mem3Dmv: trying to free unused memory",100);
00571 }
00572 }
00573
00581 void free_mem4Dmv(MotionVector ****array4D)
00582 {
00583 if (array4D)
00584 {
00585 free_mem3Dmv(*array4D);
00586 free (array4D);
00587 }
00588 else
00589 {
00590 error ("free_mem4Dmv: trying to free unused memory",100);
00591 }
00592 }
00593
00601 void free_mem5Dmv(MotionVector *****array5D)
00602 {
00603 if (array5D)
00604 {
00605 free_mem4Dmv(*array5D);
00606 free (array5D);
00607 }
00608 else
00609 {
00610 error ("free_mem5Dmv: trying to free unused memory",100);
00611 }
00612 }
00613
00622 int get_mem1Dpel(imgpel **array1D, int dim0)
00623 {
00624 if((*array1D = (imgpel*)calloc(dim0, sizeof(imgpel))) == NULL)
00625 no_mem_exit("get_mem1Dpel: arra12D");
00626
00627 return (sizeof(imgpel*) + dim0 * sizeof(imgpel));
00628 }
00629
00638 int get_mem2Dpel(imgpel ***array2D, int dim0, int dim1)
00639 {
00640 int i;
00641
00642 if((*array2D = (imgpel**)malloc(dim0 * sizeof(imgpel*))) == NULL)
00643 no_mem_exit("get_mem2Dpel: array2D");
00644 if((*(*array2D) = (imgpel* )calloc(dim0 * dim1,sizeof(imgpel ))) == NULL)
00645 no_mem_exit("get_mem2Dpel: array2D");
00646
00647 for(i = 1 ; i < dim0; i++)
00648 (*array2D)[i] = (*array2D)[i-1] + dim1;
00649
00650 return dim0 * (sizeof(imgpel*) + dim1 * sizeof(imgpel));
00651 }
00652
00653
00663 int get_mem3Dpel(imgpel ****array3D, int dim0, int dim1, int dim2)
00664 {
00665 int i, mem_size = dim0 * sizeof(imgpel**);
00666
00667 if(((*array3D) = (imgpel***)malloc(dim0 * sizeof(imgpel**))) == NULL)
00668 no_mem_exit("get_mem3Dpel: array3D");
00669
00670 mem_size += get_mem2Dpel(*array3D, dim0 * dim1, dim2);
00671
00672 for(i = 1; i < dim0; i++)
00673 (*array3D)[i] = (*array3D)[i - 1] + dim1;
00674
00675 return mem_size;
00676 }
00686 int get_mem4Dpel(imgpel *****array4D, int dim0, int dim1, int dim2, int dim3)
00687 {
00688 int i, mem_size = dim0 * sizeof(imgpel***);
00689
00690 if(((*array4D) = (imgpel****)malloc(dim0 * sizeof(imgpel***))) == NULL)
00691 no_mem_exit("get_mem4Dpel: array4D");
00692
00693 mem_size += get_mem3Dpel(*array4D, dim0 * dim1, dim2, dim3);
00694
00695 for(i = 1; i < dim0; i++)
00696 (*array4D)[i] = (*array4D)[i - 1] + dim1;
00697
00698 return mem_size;
00699 }
00700
00710 int get_mem5Dpel(imgpel ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4)
00711 {
00712 int i, mem_size = dim0 * sizeof(imgpel****);
00713
00714 if(((*array5D) = (imgpel*****)malloc(dim0 * sizeof(imgpel****))) == NULL)
00715 no_mem_exit("get_mem5Dpel: array5D");
00716
00717 mem_size += get_mem4Dpel(*array5D, dim0 * dim1, dim2, dim3, dim4);
00718
00719 for(i = 1; i < dim0; i++)
00720 (*array5D)[i] = (*array5D)[i - 1] + dim1;
00721
00722 return mem_size;
00723 }
00724
00725
00733 void free_mem1Dpel(imgpel *array1D)
00734 {
00735 if (array1D)
00736 {
00737 free (array1D);
00738 }
00739 else
00740 {
00741 error ("free_mem1Dpel: trying to free unused memory",100);
00742 }
00743 }
00744
00752 void free_mem2Dpel(imgpel **array2D)
00753 {
00754 if (array2D)
00755 {
00756 if (*array2D)
00757 free (*array2D);
00758 else
00759 error ("free_mem2Dpel: trying to free unused memory",100);
00760
00761 free (array2D);
00762 }
00763 else
00764 {
00765 error ("free_mem2Dpel: trying to free unused memory",100);
00766 }
00767 }
00768
00769
00777 void free_mem3Dpel(imgpel ***array3D)
00778 {
00779 if (array3D)
00780 {
00781 free_mem2Dpel(*array3D);
00782 free (array3D);
00783 }
00784 else
00785 {
00786 error ("free_mem3Dpel: trying to free unused memory",100);
00787 }
00788 }
00796 void free_mem4Dpel(imgpel ****array4D)
00797 {
00798 if (array4D)
00799 {
00800 free_mem3Dpel(*array4D);
00801 free (array4D);
00802 }
00803 else
00804 {
00805 error ("free_mem4Dpel: trying to free unused memory",100);
00806 }
00807 }
00815 void free_mem5Dpel(imgpel *****array5D)
00816 {
00817 if (array5D)
00818 {
00819 free_mem4Dpel(*array5D);
00820 free (array5D);
00821 }
00822 else
00823 {
00824 error ("free_mem5Dpel: trying to free unused memory",100);
00825 }
00826 }
00827
00836 int get_mem2D(byte ***array2D, int dim0, int dim1)
00837 {
00838 int i;
00839
00840 if(( *array2D = (byte**)malloc(dim0 * sizeof(byte*))) == NULL)
00841 no_mem_exit("get_mem2D: array2D");
00842 if((*(*array2D) = (byte* )calloc(dim0 * dim1,sizeof(byte ))) == NULL)
00843 no_mem_exit("get_mem2D: array2D");
00844
00845 for(i = 1; i < dim0; i++)
00846 (*array2D)[i] = (*array2D)[i-1] + dim1;
00847
00848 return dim0 * (sizeof(byte*) + dim1 * sizeof(byte));
00849 }
00850
00860 int get_mem2Dint(int ***array2D, int dim0, int dim1)
00861 {
00862 int i;
00863
00864 if((*array2D = (int**)malloc(dim0 * sizeof(int*))) == NULL)
00865 no_mem_exit("get_mem2Dint: array2D");
00866 if((*(*array2D) = (int* )calloc(dim0 * dim1, sizeof(int ))) == NULL)
00867 no_mem_exit("get_mem2Dint: array2D");
00868
00869 for(i = 1 ; i < dim0; i++)
00870 (*array2D)[i] = (*array2D)[i-1] + dim1;
00871
00872 return dim0 * (sizeof(int*) + dim1 * sizeof(int));
00873 }
00874
00884 int get_mem2Dint64(int64 ***array2D, int dim0, int dim1)
00885 {
00886 int i;
00887
00888 if((*array2D = (int64**)malloc(dim0 * sizeof(int64*))) == NULL)
00889 no_mem_exit("get_mem2Dint64: array2D");
00890 if((*(*array2D) = (int64* )calloc(dim0 * dim1,sizeof(int64 ))) == NULL)
00891 no_mem_exit("get_mem2Dint64: array2D");
00892
00893 for(i = 1; i < dim0; i++)
00894 (*array2D)[i] = (*array2D)[i-1] + dim1;
00895
00896 return dim0 * (sizeof(int64*) + dim1 * sizeof(int64));
00897 }
00898
00908 int get_mem3D(byte ****array3D, int dim0, int dim1, int dim2)
00909 {
00910 int i, mem_size = dim0 * sizeof(byte**);
00911
00912 if(((*array3D) = (byte***)malloc(dim0 * sizeof(byte**))) == NULL)
00913 no_mem_exit("get_mem3D: array3D");
00914
00915 mem_size += get_mem2D(*array3D, dim0 * dim1, dim2);
00916
00917 for(i = 1; i < dim0; i++)
00918 (*array3D)[i] = (*array3D)[i-1] + dim1;
00919
00920 return mem_size;
00921 }
00922
00932 int get_mem4D(byte *****array4D, int dim0, int dim1, int dim2, int dim3)
00933 {
00934 int i, mem_size = dim0 * sizeof(byte***);
00935
00936 if(((*array4D) = (byte****)malloc(dim0 * sizeof(byte***))) == NULL)
00937 no_mem_exit("get_mem4D: array4D");
00938
00939 mem_size += get_mem3D(*array4D, dim0 * dim1, dim2, dim3);
00940
00941 for(i = 1; i < dim0; i++)
00942 (*array4D)[i] = (*array4D)[i-1] + dim1;
00943
00944 return mem_size;
00945 }
00946
00956 int get_mem3Dint(int ****array3D, int dim0, int dim1, int dim2)
00957 {
00958 int i, mem_size = dim0 * sizeof(int**);
00959
00960 if(((*array3D) = (int***)malloc(dim0 * sizeof(int**))) == NULL)
00961 no_mem_exit("get_mem3Dint: array3D");
00962
00963 mem_size += get_mem2Dint(*array3D, dim0 * dim1, dim2);
00964
00965 for(i = 1; i < dim0; i++)
00966 (*array3D)[i] = (*array3D)[i-1] + dim1;
00967
00968 return mem_size;
00969 }
00970
00980 int get_mem3Dint64(int64 ****array3D, int dim0, int dim1, int dim2)
00981 {
00982 int i, mem_size = dim0 * sizeof(int64**);
00983
00984 if(((*array3D) = (int64***)malloc(dim0 * sizeof(int64**))) == NULL)
00985 no_mem_exit("get_mem3Dint64: array3D");
00986
00987 mem_size += get_mem2Dint64(*array3D, dim0 * dim1, dim2);
00988
00989 for(i = 1; i < dim0; i++)
00990 (*array3D)[i] = (*array3D)[i-1] + dim1;
00991
00992 return mem_size;
00993 }
00994
01004 int get_mem4Dint(int *****array4D, int dim0, int dim1, int dim2, int dim3)
01005 {
01006 int i, mem_size = dim0 * sizeof(int***);
01007
01008 if(((*array4D) = (int****)malloc(dim0 * sizeof(int***))) == NULL)
01009 no_mem_exit("get_mem4Dint: array4D");
01010
01011 mem_size += get_mem3Dint(*array4D, dim0 * dim1, dim2, dim3);
01012
01013 for(i = 1; i < dim0; i++)
01014 (*array4D)[i] = (*array4D)[i-1] + dim1;
01015
01016 return mem_size;
01017 }
01018
01028 int get_mem5Dint(int ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4)
01029 {
01030 int i, mem_size = dim0 * sizeof(int****);
01031
01032 if(((*array5D) = (int*****)malloc(dim0 * sizeof(int****))) == NULL)
01033 no_mem_exit("get_mem5Dint: array5D");
01034
01035 mem_size += get_mem4Dint(*array5D, dim0 * dim1, dim2, dim3, dim4);
01036
01037 for(i = 1; i < dim0; i++)
01038 (*array5D)[i] = (*array5D)[i-1] + dim1;
01039
01040 return mem_size;
01041 }
01042
01043
01051 void free_mem2D(byte **array2D)
01052 {
01053 if (array2D)
01054 {
01055 if (*array2D)
01056 free (*array2D);
01057 else
01058 error ("free_mem2D: trying to free unused memory",100);
01059
01060 free (array2D);
01061 }
01062 else
01063 {
01064 error ("free_mem2D: trying to free unused memory",100);
01065 }
01066 }
01067
01075 void free_mem2Dint(int **array2D)
01076 {
01077 if (array2D)
01078 {
01079 if (*array2D)
01080 free (*array2D);
01081 else
01082 error ("free_mem2Dint: trying to free unused memory",100);
01083
01084 free (array2D);
01085 }
01086 else
01087 {
01088 error ("free_mem2Dint: trying to free unused memory",100);
01089 }
01090 }
01091
01099 void free_mem2Dint64(int64 **array2D)
01100 {
01101 if (array2D)
01102 {
01103 if (*array2D)
01104 free (*array2D);
01105 else
01106 error ("free_mem2Dint64: trying to free unused memory",100);
01107 free (array2D);
01108 }
01109 else
01110 {
01111 error ("free_mem2Dint64: trying to free unused memory",100);
01112 }
01113 }
01114
01115
01123 void free_mem3D(byte ***array3D)
01124 {
01125 if (array3D)
01126 {
01127 free_mem2D(*array3D);
01128 free (array3D);
01129 }
01130 else
01131 {
01132 error ("free_mem3D: trying to free unused memory",100);
01133 }
01134 }
01135
01143 void free_mem4D(byte ****array4D)
01144 {
01145 if (array4D)
01146 {
01147 free_mem3D(*array4D);
01148 free (array4D);
01149 }
01150 else
01151 {
01152 error ("free_mem4D: trying to free unused memory",100);
01153 }
01154 }
01155
01163 void free_mem3Dint(int ***array3D)
01164 {
01165 if (array3D)
01166 {
01167 free_mem2Dint(*array3D);
01168 free (array3D);
01169 }
01170 else
01171 {
01172 error ("free_mem3Dint: trying to free unused memory",100);
01173 }
01174 }
01175
01176
01184 void free_mem3Dint64(int64 ***array3D)
01185 {
01186 if (array3D)
01187 {
01188 free_mem2Dint64(*array3D);
01189 free (array3D);
01190 }
01191 else
01192 {
01193 error ("free_mem3Dint64: trying to free unused memory",100);
01194 }
01195 }
01196
01204 void free_mem4Dint(int ****array4D)
01205 {
01206 if (array4D)
01207 {
01208 free_mem3Dint( *array4D);
01209 free (array4D);
01210 } else
01211 {
01212 error ("free_mem4Dint: trying to free unused memory",100);
01213 }
01214 }
01215
01223 void free_mem5Dint(int *****array5D)
01224 {
01225 if (array5D)
01226 {
01227 free_mem4Dint( *array5D);
01228 free (array5D);
01229 } else
01230 {
01231 error ("free_mem5Dint: trying to free unused memory",100);
01232 }
01233 }
01234
01243 void no_mem_exit(char *where)
01244 {
01245 snprintf(errortext, ET_SIZE, "Could not allocate memory: %s",where);
01246 error (errortext, 100);
01247 }
01248
01249
01259 int get_mem2Duint16(uint16 ***array2D, int dim0, int dim1)
01260 {
01261 int i;
01262
01263 if(( *array2D = (uint16**)malloc(dim0 * sizeof(uint16*))) == NULL)
01264 no_mem_exit("get_mem2Duint16: array2D");
01265
01266 if((*(*array2D) = (uint16* )calloc(dim0 * dim1,sizeof(uint16 ))) == NULL)
01267 no_mem_exit("get_mem2Duint16: array2D");
01268
01269 for(i = 1; i < dim0; i++)
01270 (*array2D)[i] = (*array2D)[i-1] + dim1;
01271
01272 return dim0 * (sizeof(uint16*) + dim1 * sizeof(uint16));
01273 }
01274
01284 int get_mem3Duint16(uint16 ****array3D,int dim0, int dim1, int dim2)
01285 {
01286 int i, mem_size = dim0 * sizeof(uint16**);
01287
01288 if(((*array3D) = (uint16***)malloc(dim0 * sizeof(uint16**))) == NULL)
01289 no_mem_exit("get_mem3Duint16: array3D");
01290
01291 mem_size += get_mem2Duint16(*array3D, dim0 * dim1, dim2);
01292
01293 for(i = 1; i < dim0; i++)
01294 (*array3D)[i] = (*array3D)[i-1] + dim1;
01295
01296 return mem_size;
01297 }
01298
01299
01309 int get_mem4Duint16(uint16 *****array4D, int dim0, int dim1, int dim2, int dim3)
01310 {
01311 int i, mem_size = dim0 * sizeof(uint16***);
01312
01313 if(((*array4D) = (uint16****)malloc(dim0 * sizeof(uint16***))) == NULL)
01314 no_mem_exit("get_mem4Duint16: array4D");
01315
01316 mem_size += get_mem3Duint16(*array4D, dim0 * dim1, dim2, dim3);
01317
01318 for(i = 1; i < dim0; i++)
01319 (*array4D)[i] = (*array4D)[i-1] + dim1;
01320
01321 return mem_size;
01322 }
01323
01333 int get_mem2Dshort(short ***array2D, int dim0, int dim1)
01334 {
01335 int i;
01336
01337 if(( *array2D = (short**)malloc(dim0 * sizeof(short*))) == NULL)
01338 no_mem_exit("get_mem2Dshort: array2D");
01339 if((*(*array2D) = (short* )calloc(dim0 * dim1,sizeof(short ))) == NULL)
01340 no_mem_exit("get_mem2Dshort: array2D");
01341
01342 for(i = 1; i < dim0; i++)
01343 (*array2D)[i] = (*array2D)[i-1] + dim1;
01344
01345 return dim0 * (sizeof(short*) + dim1 * sizeof(short));
01346 }
01347
01357 int get_mem3Dshort(short ****array3D,int dim0, int dim1, int dim2)
01358 {
01359 int i, mem_size = dim0 * sizeof(short**);
01360
01361 if(((*array3D) = (short***)malloc(dim0 * sizeof(short**))) == NULL)
01362 no_mem_exit("get_mem3Dshort: array3D");
01363
01364 mem_size += get_mem2Dshort(*array3D, dim0 * dim1, dim2);
01365
01366 for(i = 1; i < dim0; i++)
01367 (*array3D)[i] = (*array3D)[i-1] + dim1;
01368
01369 return mem_size;
01370 }
01371
01372
01382 int get_mem4Dshort(short *****array4D, int dim0, int dim1, int dim2, int dim3)
01383 {
01384 int i, mem_size = dim0 * sizeof(short***);
01385
01386 if(((*array4D) = (short****)malloc(dim0 * sizeof(short***))) == NULL)
01387 no_mem_exit("get_mem4Dshort: array4D");
01388
01389 mem_size += get_mem3Dshort(*array4D, dim0 * dim1, dim2, dim3);
01390
01391 for(i = 1; i < dim0; i++)
01392 (*array4D)[i] = (*array4D)[i-1] + dim1;
01393
01394 return mem_size;
01395 }
01396
01406 int get_mem5Dshort(short ******array5D, int dim0, int dim1, int dim2, int dim3, int dim4)
01407 {
01408 int i, mem_size = dim0 * sizeof(short****);
01409
01410 if(((*array5D) = (short*****)malloc(dim0 * sizeof(short****))) == NULL)
01411 no_mem_exit("get_mem5Dshort: array5D");
01412
01413 mem_size += get_mem4Dshort(*array5D, dim0 * dim1, dim2, dim3, dim4);
01414
01415 for(i = 1; i < dim0; i++)
01416 (*array5D)[i] = (*array5D)[i-1] + dim1;
01417
01418 return mem_size;
01419 }
01420
01430 int get_mem6Dshort(short *******array6D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5)
01431 {
01432 int i, mem_size = dim0 * sizeof(short*****);
01433
01434 if(((*array6D) = (short******)malloc(dim0 * sizeof(short*****))) == NULL)
01435 no_mem_exit("get_mem6Dshort: array6D");
01436
01437 mem_size += get_mem5Dshort(*array6D, dim0 * dim1, dim2, dim3, dim4, dim5);
01438
01439 for(i = 1; i < dim0; i++)
01440 (*array6D)[i] = (*array6D)[i-1] + dim1;
01441
01442 return mem_size;
01443 }
01444
01454 int get_mem7Dshort(short ********array7D, int dim0, int dim1, int dim2, int dim3, int dim4, int dim5, int dim6)
01455 {
01456 int i, mem_size = dim0 * sizeof(short******);
01457
01458 if(((*array7D) = (short*******)malloc(dim0 * sizeof(short******))) == NULL)
01459 no_mem_exit("get_mem7Dshort: array7D");
01460
01461 mem_size += get_mem6Dshort(*array7D, dim0 * dim1, dim2, dim3, dim4, dim5, dim6);
01462
01463 for(i = 1; i < dim0; i++)
01464 (*array7D)[i] = (*array7D)[i-1] + dim1;
01465
01466 return mem_size;
01467 }
01468
01476 void free_mem2Duint16(uint16 **array2D)
01477 {
01478 if (array2D)
01479 {
01480 if (*array2D)
01481 free (*array2D);
01482 else error ("free_mem2Duint16: trying to free unused memory",100);
01483
01484 free (array2D);
01485 }
01486 else
01487 {
01488 error ("free_mem2Duint16: trying to free unused memory",100);
01489 }
01490 }
01491
01499 void free_mem3Duint16(uint16 ***array3D)
01500 {
01501 if (array3D)
01502 {
01503 free_mem2Duint16(*array3D);
01504 free (array3D);
01505 }
01506 else
01507 {
01508 error ("free_mem3Duint16: trying to free unused memory",100);
01509 }
01510 }
01511
01519 void free_mem4Duint16(uint16 ****array4D)
01520 {
01521 if (array4D)
01522 {
01523 free_mem3Duint16( *array4D);
01524 free (array4D);
01525 }
01526 else
01527 {
01528 error ("free_mem4Duint16: trying to free unused memory",100);
01529 }
01530 }
01531
01539 void free_mem2Dshort(short **array2D)
01540 {
01541 if (array2D)
01542 {
01543 if (*array2D)
01544 free (*array2D);
01545 else error ("free_mem2Dshort: trying to free unused memory",100);
01546
01547 free (array2D);
01548 }
01549 else
01550 {
01551 error ("free_mem2Dshort: trying to free unused memory",100);
01552 }
01553 }
01554
01562 void free_mem3Dshort(short ***array3D)
01563 {
01564 if (array3D)
01565 {
01566 free_mem2Dshort(*array3D);
01567 free (array3D);
01568 }
01569 else
01570 {
01571 error ("free_mem3Dshort: trying to free unused memory",100);
01572 }
01573 }
01574
01582 void free_mem4Dshort(short ****array4D)
01583 {
01584 if (array4D)
01585 {
01586 free_mem3Dshort( *array4D);
01587 free (array4D);
01588 }
01589 else
01590 {
01591 error ("free_mem4Dshort: trying to free unused memory",100);
01592 }
01593 }
01594
01602 void free_mem5Dshort(short *****array5D)
01603 {
01604 if (array5D)
01605 {
01606 free_mem4Dshort( *array5D) ;
01607 free (array5D);
01608 }
01609 else
01610 {
01611 error ("free_mem5Dshort: trying to free unused memory",100);
01612 }
01613 }
01614
01622 void free_mem6Dshort(short ******array6D)
01623 {
01624 if (array6D)
01625 {
01626 free_mem5Dshort( *array6D);
01627 free (array6D);
01628 }
01629 else
01630 {
01631 error ("free_mem6Dshort: trying to free unused memory",100);
01632 }
01633 }
01634
01642 void free_mem7Dshort(short *******array7D)
01643 {
01644 if (array7D)
01645 {
01646 free_mem6Dshort( *array7D);
01647 free (array7D);
01648 }
01649 else
01650 {
01651 error ("free_mem7Dshort: trying to free unused memory",100);
01652 }
01653 }
01654
01664 int get_mem2Ddouble(double ***array2D, int dim0, int dim1)
01665 {
01666 int i;
01667
01668 if((*array2D = (double**)malloc(dim0 * sizeof(double*))) == NULL)
01669 no_mem_exit("get_mem2Ddouble: array2D");
01670
01671 if(((*array2D)[0] = (double* )calloc(dim0 * dim1,sizeof(double ))) == NULL)
01672 no_mem_exit("get_mem2Ddouble: array2D");
01673
01674 for(i=1 ; i<dim0 ; i++)
01675 (*array2D)[i] = (*array2D)[i-1] + dim1 ;
01676
01677 return dim0 * (sizeof(double*) + dim1 * sizeof(double));
01678 }
01679
01690 int get_mem2Dodouble(double ***array2D, int dim0, int dim1, int offset)
01691 {
01692 int i;
01693
01694 if((*array2D = (double**)malloc(dim0 * sizeof(double*))) == NULL)
01695 no_mem_exit("get_mem2Dodouble: array2D");
01696 if(((*array2D)[0] = (double* )calloc(dim0 * dim1, sizeof(double ))) == NULL)
01697 no_mem_exit("get_mem2Dodouble: array2D");
01698
01699 (*array2D)[0] += offset;
01700
01701 for(i=1 ; i<dim0 ; i++)
01702 (*array2D)[i] = (*array2D)[i-1] + dim1 ;
01703
01704 return dim0 * (sizeof(double*) + dim1 * sizeof(double));
01705 }
01706
01716 int get_mem3Dodouble(double ****array3D, int dim0, int dim1, int dim2, int offset)
01717 {
01718 int i,j;
01719
01720 if(((*array3D) = (double***)malloc(dim0 * sizeof(double**))) == NULL)
01721 no_mem_exit("get_mem3Dodouble: array3D");
01722
01723 if(((*array3D)[0] = (double** )calloc(dim0 * dim1, sizeof(double*))) == NULL)
01724 no_mem_exit("get_mem3Dodouble: array3D");
01725
01726 (*array3D) [0] += offset;
01727
01728 for(i=1 ; i<dim0 ; i++)
01729 (*array3D)[i] = (*array3D)[i-1] + dim1 ;
01730
01731 for (i = 0; i < dim0; i++)
01732 for (j = -offset; j < dim1 - offset; j++)
01733 if(((*array3D)[i][j] = (double* )calloc(dim2, sizeof(double))) == NULL)
01734 no_mem_exit("get_mem3Dodouble: array3D");
01735
01736 return dim0*( sizeof(double**) + dim1 * ( sizeof(double*) + dim2 * sizeof(double)));
01737 }
01738
01739
01750 int get_offset_mem2Dshort(short ***array2D, int dim0, int dim1, int offset_y, int offset_x)
01751 {
01752 int i;
01753
01754 if((*array2D = (short**)malloc(dim0 * sizeof(short*))) == NULL)
01755 no_mem_exit("get_offset_mem2Dshort: array2D");
01756
01757 if(((*array2D)[0] = (short* )calloc(dim0 * dim1, sizeof(short))) == NULL)
01758 no_mem_exit("get_offset_mem2Dshort: array2D");
01759 (*array2D)[0] += offset_x + offset_y * dim1;
01760
01761 for(i=-1 ; i > -offset_y - 1; i--)
01762 {
01763 (*array2D)[i] = (*array2D)[i+1] - dim1;
01764 }
01765
01766 for(i=1 ; i < dim1 - offset_y; i++)
01767 (*array2D)[i] = (*array2D)[i-1] + dim1;
01768
01769 return dim0 * (sizeof(short*) + dim1 * sizeof(short));
01770 }
01771
01781 int get_mem3Doint(int ****array3D, int dim0, int dim1, int dim2, int offset)
01782 {
01783 int i,j;
01784
01785 if(((*array3D) = (int***)malloc(dim0 * sizeof(int**))) == NULL)
01786 no_mem_exit("get_mem3Doint: array3D");
01787
01788 if(((*array3D)[0] = (int** )calloc(dim0 * dim1, sizeof(int*))) == NULL)
01789 no_mem_exit("get_mem3Doint: array3D");
01790
01791 (*array3D) [0] += offset;
01792
01793 for(i=1 ; i<dim0 ; i++)
01794 (*array3D)[i] = (*array3D)[i-1] + dim1 ;
01795
01796 for (i = 0; i < dim0; i++)
01797 for (j = -offset; j < dim1 - offset; j++)
01798 if(((*array3D)[i][j] = (int* )calloc(dim2, sizeof(int))) == NULL)
01799 no_mem_exit("get_mem3Doint: array3D");
01800
01801 return dim0 * (sizeof(int**) + dim1 * (sizeof(int*) + dim2 * sizeof(int)));
01802 }
01803
01814 int get_mem2Doint(int ***array2D, int dim0, int dim1, int offset)
01815 {
01816 int i;
01817
01818 if((*array2D = (int**)malloc(dim0 * sizeof(int*))) == NULL)
01819 no_mem_exit("get_mem2Dint: array2D");
01820 if(((*array2D)[0] = (int* )calloc(dim0 * dim1, sizeof(int))) == NULL)
01821 no_mem_exit("get_mem2Dint: array2D");
01822
01823 (*array2D)[0] += offset;
01824
01825 for(i=1 ; i<dim0 ; i++)
01826 (*array2D)[i] = (*array2D)[i-1] + dim1 ;
01827
01828 return dim0 * (sizeof(int*) + dim1 * sizeof(int));
01829 }
01830
01831
01841
01842 int get_mem3Ddouble(double ****array3D, int dim0, int dim1, int dim2)
01843 {
01844 int j, mem_size = dim0 * sizeof(double**);
01845
01846 double **array2D;
01847
01848 if(((*array3D) = (double***)malloc(dim0 * sizeof(double**))) == NULL)
01849 no_mem_exit("get_mem3Ddouble: array3D");
01850
01851 mem_size += get_mem2Ddouble(&array2D, dim0 * dim1, dim2);
01852
01853 for(j = 0; j < dim0; j++)
01854 {
01855 (*array3D)[j] = &array2D[j * dim1];
01856 }
01857
01858 return mem_size;
01859 }
01860
01868 void free_mem2Ddouble(double **array2D)
01869 {
01870 if (array2D)
01871 {
01872 if (*array2D)
01873 free (*array2D);
01874 else
01875 error ("free_mem2Ddouble: trying to free unused memory",100);
01876
01877 free (array2D);
01878
01879 }
01880 else
01881 {
01882 error ("free_mem2Ddouble: trying to free unused memory",100);
01883 }
01884 }
01885
01886
01894 void free_mem2Dodouble(double **array2D, int offset)
01895 {
01896 if (array2D)
01897 {
01898 array2D[0] -= offset;
01899 if (array2D[0])
01900 free (array2D[0]);
01901 else error ("free_mem2Dodouble: trying to free unused memory",100);
01902
01903 free (array2D);
01904
01905 } else
01906 {
01907 error ("free_mem2Dodouble: trying to free unused memory",100);
01908 }
01909 }
01910
01917 void free_mem3Dodouble(double ***array3D, int dim0, int dim1, int offset)
01918 {
01919 int i, j;
01920
01921 if (array3D)
01922 {
01923 for (i = 0; i < dim0; i++)
01924 {
01925 for (j = -offset; j < dim1 - offset; j++)
01926 {
01927 if (array3D[i][j])
01928 free(array3D[i][j]);
01929 else
01930 error ("free_mem3Dodouble: trying to free unused memory",100);
01931 }
01932 }
01933 array3D[0] -= offset;
01934 if (array3D[0])
01935 free(array3D[0]);
01936 else
01937 error ("free_mem3Dodouble: trying to free unused memory",100);
01938 free (array3D);
01939 }
01940 else
01941 {
01942 error ("free_mem3Dodouble: trying to free unused memory",100);
01943 }
01944 }
01945
01952 void free_mem3Doint(int ***array3D, int dim0, int dim1, int offset)
01953 {
01954 int i, j;
01955
01956 if (array3D)
01957 {
01958 for (i = 0; i < dim0; i++)
01959 {
01960 for (j = -offset; j < dim1 - offset; j++)
01961 {
01962 if (array3D[i][j])
01963 free(array3D[i][j]);
01964 else
01965 error ("free_mem3Doint: trying to free unused memory",100);
01966 }
01967 }
01968 array3D[0] -= offset;
01969 if (array3D[0])
01970 free(array3D[0]);
01971 else
01972 error ("free_mem3Doint: trying to free unused memory",100);
01973 free (array3D);
01974 }
01975 else
01976 {
01977 error ("free_mem3Doint: trying to free unused memory",100);
01978 }
01979 }
01980
01981
01989 void free_mem2Doint(int **array2D, int offset)
01990 {
01991 if (array2D)
01992 {
01993 array2D[0] -= offset;
01994 if (array2D[0])
01995 free (array2D[0]);
01996 else
01997 error ("free_mem2Doint: trying to free unused memory",100);
01998
01999 free (array2D);
02000
02001 }
02002 else
02003 {
02004 error ("free_mem2Doint: trying to free unused memory",100);
02005 }
02006 }
02007
02015 void free_offset_mem2Dshort(short **array2D, int dim1, int offset_y, int offset_x)
02016 {
02017 if (array2D)
02018 {
02019 array2D[0] -= offset_x + offset_y * dim1;
02020 if (array2D[0])
02021 free (array2D[0]);
02022 else
02023 error ("free_offset_mem2Dshort: trying to free unused memory",100);
02024
02025 free (array2D);
02026
02027 }
02028 else
02029 {
02030 error ("free_offset_mem2Dshort: trying to free unused memory",100);
02031 }
02032 }
02033
02041 void free_mem3Ddouble(double ***array3D)
02042 {
02043 if (array3D)
02044 {
02045 free_mem2Ddouble(*array3D);
02046 free (array3D);
02047 }
02048 else
02049 {
02050 error ("free_mem3D: trying to free unused memory",100);
02051 }
02052 }
02053
02054
02065 int get_mem2Dolm(LambdaParams ***array2D, int dim0, int dim1, int offset)
02066 {
02067 int i;
02068
02069 if((*array2D = (LambdaParams**) malloc(dim0 * sizeof(LambdaParams*))) == NULL)
02070 no_mem_exit("get_mem2Dolm: array2D");
02071 if(((*array2D)[0] = (LambdaParams* ) calloc(dim0 * dim1, sizeof(LambdaParams))) == NULL)
02072 no_mem_exit("get_mem2Dolm: array2D");
02073
02074 (*array2D)[0] += offset;
02075
02076 for(i=1 ; i<dim0 ; i++)
02077 (*array2D)[i] = (*array2D)[i-1] + dim1 ;
02078
02079 return dim0 * (sizeof(LambdaParams*) + dim1 * sizeof(LambdaParams));
02080 }
02081
02082
02090 void free_mem2Dolm(LambdaParams **array2D, int offset)
02091 {
02092 if (array2D)
02093 {
02094 array2D[0] -= offset;
02095 if (array2D[0])
02096 free (array2D[0]);
02097 else
02098 error ("free_mem2Dolm: trying to free unused memory",100);
02099
02100 free (array2D);
02101
02102 }
02103 else
02104 {
02105 error ("free_mem2Dolm: trying to free unused memory",100);
02106 }
02107 }
02108
02109 #endif