Changeset 32725 for trunk/psLib/src/imageops/psImageConvolve.c
- Timestamp:
- Nov 20, 2011, 3:55:38 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageConvolve.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageConvolve.c
r32724 r32725 569 569 // Generate normalised Gaussian vector 570 570 #define IMAGE_SMOOTH_GAUSS(TARGET, SIZE, SIGMA, TYPE) \ 571 psVector *TARGET = psVectorAlloc(2 * SIZE + 1, PS_TYPE_##TYPE); /* Gaussian */ \571 TARGET = psVectorAlloc(2 * SIZE + 1, PS_TYPE_##TYPE); /* Gaussian */ \ 572 572 double sum = 0.0; /* Sum of Gaussian, for normalisation */ \ 573 573 double factor = -0.5/PS_SQR(SIGMA); /* Multiplier for exponential */ \ … … 587 587 psKernel *kernel = psKernelAlloc(-size, size, -size, size); // Kernel to return 588 588 589 psVector *gaussNorm = NULL; 589 590 IMAGE_SMOOTH_GAUSS(gaussNorm, size, sigma, F32); 590 591 psF32 *gauss = &gaussNorm->data.F32[size]; // Convenient kernel-like indexing for Gaussian … … 602 603 bool psImageSmooth(psImage *image, double sigma, double Nsigma) 603 604 { 604 PS_ASSERT_IMAGE_NON_NULL(image, NULL);605 PS_ASSERT_IMAGE_NON_NULL(image, false); 605 606 606 607 // relevant terms … … 612 613 case PS_TYPE_##TYPE: { \ 613 614 /* generate normalized gaussian */ \ 615 psVector *gaussnorm = NULL; \ 614 616 IMAGE_SMOOTH_GAUSS(gaussnorm, Nrange, sigma, TYPE) \ 615 617 ps##TYPE *gauss = &gaussnorm->data.TYPE[Nrange]; \ … … 765 767 } 766 768 767 // XXX NOTE : work to do : figure out the actual containers needed in there, pre-allocate them 768 bool psImageSmooth_PreAlloc_F32(psImage *image, double sigma, double Nsigma) 769 { 770 PS_ASSERT_IMAGE_NON_NULL(image, NULL); 771 // assert on data type 769 void psImageSmooth_PreAlloc_DataFree (psImageSmooth_PreAlloc_Data *smdata) { 770 psFree (smdata->resultX); 771 psFree (smdata->resultY); 772 psFree (smdata->kernel); 773 } 774 775 psImageSmooth_PreAlloc_Data *psImageSmooth_PreAlloc_DataAlloc (psImage *image, double sigma, double Nsigma) { 776 777 psImageSmooth_PreAlloc_Data *smdata = psAlloc(sizeof(psImageSmooth_PreAlloc_Data)); 778 psMemSetDeallocator(smdata, (psFreeFunc) psImageSmooth_PreAlloc_DataFree); 779 780 if (!image) { 781 // relevant terms 782 smdata->Nrange = sigma*Nsigma + 0.5; // Number of pixels either side for convolution kernel 783 smdata->Nx = 0; 784 smdata->Ny = 0; 785 smdata->kernel = NULL; 786 smdata->resultX = NULL; 787 smdata->resultY = NULL; 788 return smdata; 789 } 772 790 773 791 // relevant terms 774 int Nrange = sigma*Nsigma + 0.5; // Number of pixels either side for convolution kernel 775 int Nx = image->numCols; // Number of columns 776 int Ny = image->numRows; // Number of rows 777 778 IMAGE_SMOOTH_GAUSS(gaussnorm, Nrange, sigma, F32); 779 psF32 *gauss = &gaussnorm->data.F32[Nrange]; 792 smdata->Nrange = sigma*Nsigma + 0.5; // Number of pixels either side for convolution kernel 793 smdata->Nx = image->numCols; // Number of columns 794 smdata->Ny = image->numRows; // Number of rows 795 796 IMAGE_SMOOTH_GAUSS(smdata->kernel, smdata->Nrange, sigma, F32); 780 797 781 798 // use a temp running buffer for X and Y directions. 782 psF32 *resultX = (psF32 *) psAlloc(Nx * sizeof(psF32)); 783 memset (resultX, 0, Nx*sizeof(psF32)); 784 psF32 *resultY = (psF32 *) psAlloc(Ny * sizeof(psF32)); 785 memset (resultY, 0, Ny*sizeof(psF32)); 786 799 smdata->resultX = psAlloc(smdata->Nx * sizeof(psF32)); 800 memset (smdata->resultX, 0, smdata->Nx*sizeof(psF32)); 801 802 smdata->resultY = psAlloc(smdata->Ny * sizeof(psF32)); 803 memset (smdata->resultY, 0, smdata->Ny*sizeof(psF32)); 804 805 return smdata; 806 } 807 808 // we can use the same DATA structure on multiple images of the same size 809 bool psImageSmooth_PreAlloc_F32(psImage *image, psImageSmooth_PreAlloc_Data *smdata) 810 { 811 PS_ASSERT_IMAGE_NON_NULL(image, false); 812 // assert on data type 813 814 // relevant terms 815 int Nrange = smdata->Nrange; // Number of pixels either side for convolution kernel 816 int Nx = smdata->Nx; // Number of columns 817 int Ny = smdata->Ny; // Number of rows 818 819 psF32 *gauss = &smdata->kernel->data.F32[Nrange]; 820 psF32 *resultX = smdata->resultX; 821 psF32 *resultY = smdata->resultY; 822 787 823 /* Smooth in X direction */ 788 824 { … … 881 917 } 882 918 } 883 884 psFree(resultX);885 psFree(resultY);886 psFree(gaussnorm);887 888 919 return true; 889 920 } … … 973 1004 974 1005 // Generate normalized gaussian 1006 psVector *gaussNorm = NULL; 975 1007 IMAGE_SMOOTH_GAUSS(gaussNorm, size, sigma, F32); 976 1008 … … 1098 1130 1099 1131 // Generate normalized gaussian 1132 psVector *gaussNorm = NULL; 1100 1133 IMAGE_SMOOTH_GAUSS(gaussNorm, size, sigma, F32); 1101 1134 const psF32 *gauss = &gaussNorm->data.F32[size]; // Gaussian convolution kernel … … 1309 1342 1310 1343 // Generate normalized gaussian 1344 psVector *gaussNorm = NULL; 1311 1345 IMAGE_SMOOTH_GAUSS(gaussNorm, size, sigma, F32); 1312 1346 … … 1445 1479 1446 1480 /* generate normalized gaussian */ 1481 psVector *gaussnorm = NULL; 1447 1482 IMAGE_SMOOTH_GAUSS(gaussnorm, Nrange, sigma, F32); 1448 1483 psF32 *gauss = &gaussnorm->data.F32[Nrange];
Note:
See TracChangeset
for help on using the changeset viewer.
