diff options
author | Siim Meerits <sh0@yutani.ee> | 2020-07-27 17:37:00 +0300 |
---|---|---|
committer | Siim Meerits <sh0@yutani.ee> | 2020-07-27 17:37:00 +0300 |
commit | 456a1d598bccc260b233d2e91c469be452e0fbef (patch) | |
tree | c1288655494c94292f6e2eb26d722958899c7107 /libgphoto2/ahd_bayer.c | |
parent | af2c0e0558e78cae06371abef36f43ca74a9c5c0 (diff) | |
download | libgphoto2-456a1d598bccc260b233d2e91c469be452e0fbef.tar.gz |
Remove trailing whitespace from all *.h and *.c files.
Diffstat (limited to 'libgphoto2/ahd_bayer.c')
-rw-r--r-- | libgphoto2/ahd_bayer.c | 238 |
1 files changed, 119 insertions, 119 deletions
diff --git a/libgphoto2/ahd_bayer.c b/libgphoto2/ahd_bayer.c index 98d44b68a..80117a133 100644 --- a/libgphoto2/ahd_bayer.c +++ b/libgphoto2/ahd_bayer.c @@ -1,22 +1,22 @@ /** \file ahd_bayer.c - * + * * \brief Adaptive Homogeneity-Directed Bayer array conversion routine. * * \author Copyright March 12, 2008 Theodore Kilgore <kilgota@auburn.edu> * * \par * gp_ahd_interpolate() from Eero Salminen <esalmine@gmail.com> - * and Theodore Kilgore. The work of Eero Salminen is for partial completion - * of a Diploma in Information and Computer Science, + * and Theodore Kilgore. The work of Eero Salminen is for partial completion + * of a Diploma in Information and Computer Science, * Helsinki University of Technology, Finland. * * \par * The algorithm is based upon the paper * * \par - * Adaptive Homogeneity-Directed Democsaicing Algorithm, - * Keigo Hirakawa and Thomas W. Parks, presented in the - * IEEE Transactions on Image Processing, vol. 14, no. 3, March 2005. + * Adaptive Homogeneity-Directed Democsaicing Algorithm, + * Keigo Hirakawa and Thomas W. Parks, presented in the + * IEEE Transactions on Image Processing, vol. 14, no. 3, March 2005. * * \par License * This library is free software; you can redistribute it and/or @@ -36,7 +36,7 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ - + #include <stdio.h> @@ -60,21 +60,21 @@ static int dRGB(int i1, int i2, unsigned char *RGB); static -int do_rb_ctr_row(unsigned char *image_h, unsigned char *image_v, int w, +int do_rb_ctr_row(unsigned char *image_h, unsigned char *image_v, int w, int h, int y, int *pos_code); static -int do_green_ctr_row(unsigned char *image, unsigned char *image_h, +int do_green_ctr_row(unsigned char *image, unsigned char *image_h, unsigned char *image_v, int w, int h, int y, int *pos_code); static -int get_diffs_row2(unsigned char * hom_buffer_h, unsigned char *hom_buffer_v, +int get_diffs_row2(unsigned char * hom_buffer_h, unsigned char *hom_buffer_v, unsigned char * buffer_h, unsigned char *buffer_v, int w); #define AD(x, y, w) ((y)*(w)*3+3*(x)) /** - * \brief This function computes distance^2 between two sets of pixel data. + * \brief This function computes distance^2 between two sets of pixel data. * \param i1 location of a pixel * \param i2 location of another pixel - * \param RGB some RGB data. + * \param RGB some RGB data. */ static int dRGB(int i1, int i2, unsigned char *RGB) { @@ -89,39 +89,39 @@ int dRGB(int i1, int i2, unsigned char *RGB) { * \param image_h three-row window, horizontal interpolation of row 1 is done * \param image_v three-row window, vertical interpolation of row 1 is done * \param w width of image - * \param h height of image. + * \param h height of image. * \param y row number from image which is under construction * \param pos_code position code related to Bayer tiling in use */ static -int do_rb_ctr_row(unsigned char *image_h, unsigned char *image_v, int w, - int h, int y, int *pos_code) +int do_rb_ctr_row(unsigned char *image_h, unsigned char *image_v, int w, + int h, int y, int *pos_code) { int x, bayer; int value,value2,div,color; /* - * pos_code[0] = red. green lrtb, blue diagonals - * pos_code[1] = green. red lr, blue tb - * pos_code[2] = green. blue lr, red tb - * pos_code[3] = blue. green lrtb, red diagonals + * pos_code[0] = red. green lrtb, blue diagonals + * pos_code[1] = green. red lr, blue tb + * pos_code[2] = green. blue lr, red tb + * pos_code[3] = blue. green lrtb, red diagonals * * The Red channel reconstruction is R=G+L(Rs-Gs), in which * G = interpolated & known Green * Rs = known Red * Gs = values of G at the positions of Rs - * L()= should be a 2D lowpass filter, now we'll check + * L()= should be a 2D lowpass filter, now we'll check * them from a 3x3 square - * L-functions' convolution matrix is + * L-functions' convolution matrix is * [1/4 1/2 1/4;1/2 1 1/2; 1/4 1/2 1/4] - * + * * The Blue channel reconstruction uses exactly the same methods. */ - for (x = 0; x < w; x++) + for (x = 0; x < w; x++) { bayer = (x&1?0:1) + (y&1?0:2); for (color=0; color < 3; color+=2) { - if ((color==RED && bayer == pos_code[3]) - || (color==BLUE + if ((color==RED && bayer == pos_code[3]) + || (color==BLUE && bayer == pos_code[0])) { value=value2=div=0; if (x > 0 && y > 0) { @@ -159,8 +159,8 @@ int do_rb_ctr_row(unsigned char *image_h, unsigned char *image_v, int w, image_v[AD(x,1,w)+color]= CLAMP(image_v[AD(x,1,w)+GREEN] +value2/div); - } else if ((color==RED && bayer == pos_code[2]) - || (color==BLUE + } else if ((color==RED && bayer == pos_code[2]) + || (color==BLUE && bayer == pos_code[1])) { value=value2=div=0; if (y > 0) { @@ -185,8 +185,8 @@ int do_rb_ctr_row(unsigned char *image_h, unsigned char *image_v, int w, CLAMP( image_v[AD(x,1,w)+GREEN] +value2/div); - } else if ((color==RED && bayer == pos_code[1]) - || (color==BLUE + } else if ((color==RED && bayer == pos_code[1]) + || (color==BLUE && bayer == pos_code[2])) { value=value2=div=0; if (x > 0) { @@ -224,19 +224,19 @@ int do_rb_ctr_row(unsigned char *image_h, unsigned char *image_v, int w, * \param image_h three-row window, horizontal interpolation of row 1 is done * \param image_v three-row window, vertical interpolation of row 1 is done * \param w width of image - * \param h height of image. + * \param h height of image. * \param y row number from image which is under construction * \param pos_code position code related to Bayer tiling in use */ static -int do_green_ctr_row(unsigned char *image, unsigned char *image_h, +int do_green_ctr_row(unsigned char *image, unsigned char *image_h, unsigned char *image_v, int w, int h, int y, int *pos_code) { int x, bayer; int value,div; /* - * The horizontal green estimation on a red-green row is + * The horizontal green estimation on a red-green row is * G(x) = (2*R(x)+2*G(x+1)+2*G(x-1)-R(x-2)-R(x+2))/4 * The estimation on a green-blue row works in the same * way. @@ -254,7 +254,7 @@ int do_green_ctr_row(unsigned char *image, unsigned char *image_h, div+=2; if (x < (w-1)) { value += 2*image[AD(x+1,y,w)+GREEN]; - div+=2; + div+=2; } if (x < (w-2)) { if (bayer==pos_code[0]) @@ -275,9 +275,9 @@ int do_green_ctr_row(unsigned char *image, unsigned char *image_h, div--; } image_h[AD(x,1,w)+GREEN] = CLAMP(value / div); - /* The method for vertical estimation is just like - * what is done for horizontal estimation, with only - * the obvious difference that it is done vertically. + /* The method for vertical estimation is just like + * what is done for horizontal estimation, with only + * the obvious difference that it is done vertically. */ div=value=0; if (bayer==pos_code[0]) @@ -287,7 +287,7 @@ int do_green_ctr_row(unsigned char *image, unsigned char *image_h, div+=2; if (y < (h-1)) { value += 2*image[AD(x,y+1,w)+GREEN]; - div+=2; + div+=2; } if (y < (h-2)) { if (bayer==pos_code[0]) @@ -308,7 +308,7 @@ int do_green_ctr_row(unsigned char *image, unsigned char *image_h, div--; } image_v[AD(x,1,w)+GREEN] = CLAMP(value / div); - + } } return GP_OK; @@ -324,7 +324,7 @@ int do_green_ctr_row(unsigned char *image, unsigned char *image_h, */ static -int get_diffs_row2(unsigned char * hom_buffer_h, unsigned char *hom_buffer_v, +int get_diffs_row2(unsigned char * hom_buffer_h, unsigned char *hom_buffer_v, unsigned char * buffer_h, unsigned char *buffer_v, int w) { int i,j; @@ -336,23 +336,23 @@ int get_diffs_row2(unsigned char * hom_buffer_h, unsigned char *hom_buffer_v, Usize_h=0; Usize_v=0; - /* - * Data collected here for adaptive estimates. First we take + /* + * Data collected here for adaptive estimates. First we take * at the given pixel vertical diffs if working in window_v; * left and right diffs if working in window_h. We then choose - * of these two diffs as a permissible epsilon-radius within - * which to work. Checking within this radius, we will - * compute scores for the various possibilities. The score - * added in each step is either 1, if the directional change - * is within the prescribed epsilon, or 0 if it is not. + * of these two diffs as a permissible epsilon-radius within + * which to work. Checking within this radius, we will + * compute scores for the various possibilities. The score + * added in each step is either 1, if the directional change + * is within the prescribed epsilon, or 0 if it is not. */ - + RGBeps=MIN( MAX(dRGB(i,i-3,buffer_h),dRGB(i,i+3,buffer_h)), MAX(dRGB(i,i-3*w,buffer_v),dRGB(i,i+3*w,buffer_v)) ); /* - * The scores for the homogeneity mapping. These will be used + * The scores for the homogeneity mapping. These will be used * in the choice algorithm to choose the best value. */ @@ -387,35 +387,35 @@ int get_diffs_row2(unsigned char * hom_buffer_h, unsigned char *hom_buffer_v, * \param tile how the 2x2 bayer array is laid out * * This function interpolates a bayer array which has been pre-expanded - * by gp_bayer_expand() to an RGB image. It applies the method of adaptive - * homogeneity-directed demosaicing. + * by gp_bayer_expand() to an RGB image. It applies the method of adaptive + * homogeneity-directed demosaicing. * * \return a gphoto error code * * \par - * In outline, the interpolation algorithm used here does the + * In outline, the interpolation algorithm used here does the * following: * * \par - * In principle, the first thing which is done is to split off from the - * image two copies. In one of these, interpolation will be done in the - * vertical direction only, and in the other copy only in the - * horizontal direction. "Cross-color" data is used throughout, on the - * principle that it can be used as a corrector for brightness even if it is - * derived from the "wrong" color. Finally, at each pixel there is a choice - * criterion to decide whether to use the result of the vertical - * interpolation, the horizontal interpolation, or an average of the two. + * In principle, the first thing which is done is to split off from the + * image two copies. In one of these, interpolation will be done in the + * vertical direction only, and in the other copy only in the + * horizontal direction. "Cross-color" data is used throughout, on the + * principle that it can be used as a corrector for brightness even if it is + * derived from the "wrong" color. Finally, at each pixel there is a choice + * criterion to decide whether to use the result of the vertical + * interpolation, the horizontal interpolation, or an average of the two. * * \par - * Memory use and speed are optimized by using two sliding windows, one - * for the vertical interpolation and the other for the horizontal - * interpolation instead of using two copies of the entire input image. The + * Memory use and speed are optimized by using two sliding windows, one + * for the vertical interpolation and the other for the horizontal + * interpolation instead of using two copies of the entire input image. The * nterpolation and the choice algorithm are then implemented entirely within * these windows, too. When this has been done, a completed row is written back - * to the image. Then the windows are moved, and the process repeats. + * to the image. Then the windows are moved, and the process repeats. */ -int gp_ahd_interpolate (unsigned char *image, int w, int h, BayerTile tile) +int gp_ahd_interpolate (unsigned char *image, int w, int h, BayerTile tile) { int i, j, k, x, y; int p[4]; @@ -460,53 +460,53 @@ int gp_ahd_interpolate (unsigned char *image, int w, int h, BayerTile tile) break; } - /* - * Once the algorithm is initialized and running, one cycle of the + /* + * Once the algorithm is initialized and running, one cycle of the * algorithm can be described thus: - * + * * Step 1 - * Write from row y+3 of the image to row 5 in window_v and in - * window_h. + * Write from row y+3 of the image to row 5 in window_v and in + * window_h. * * Step 2 * Interpolate missing green data on row 5 in each window. Data from - * the image only is needed for this, not data from the windows. + * the image only is needed for this, not data from the windows. * * Step 3 - * Now interpolate the missing red or blue data on row 4 in both - * windows. We need to do this inside the windows; what is required - * is the real or interpolated green data from rows 3 and 5, and the - * real data on rows 3 and 5 about the color being interpolated on - * row 4, so all of this information is available in the two windows. - * Note that for this operation we are interpolating the center row - * of cur_window_v and cur_window_h. - * + * Now interpolate the missing red or blue data on row 4 in both + * windows. We need to do this inside the windows; what is required + * is the real or interpolated green data from rows 3 and 5, and the + * real data on rows 3 and 5 about the color being interpolated on + * row 4, so all of this information is available in the two windows. + * Note that for this operation we are interpolating the center row + * of cur_window_v and cur_window_h. + * * Step 4 * Now we have five completed rows in each window, 0 through 4 (rows - * 0 - 3 having been done in previous cycles). Completed rows 0 - 4 - * are what is required in order to run the choice algorithm at - * each pixel location across row 2, to decide whether to choose the - * data for that pixel from window_v or from window_h. We run the - * choice algorithm, sending the data from row 2 over to row y of the - * image, pixel by pixel. + * 0 - 3 having been done in previous cycles). Completed rows 0 - 4 + * are what is required in order to run the choice algorithm at + * each pixel location across row 2, to decide whether to choose the + * data for that pixel from window_v or from window_h. We run the + * choice algorithm, sending the data from row 2 over to row y of the + * image, pixel by pixel. * * Step 5 * Move the windows down (or the data in them up) by one row. * Increment y, the row counter for the image. Go to Step 1. - * - * Initialization of the algorithm clearly requires some special - * steps, which are described below as they occur. + * + * Initialization of the algorithm clearly requires some special + * steps, which are described below as they occur. */ - cur_window_h = window_h+9*w; - cur_window_v = window_v+9*w; + cur_window_h = window_h+9*w; + cur_window_v = window_v+9*w; /* * Getting started. Copy row 0 from image to line 4 of windows - * and row 1 from image to line 5 of windows. + * and row 1 from image to line 5 of windows. */ memcpy (window_h+12*w, image, 6*w); memcpy (window_v+12*w, image, 6*w); /* - * Now do the green interpolation in row 4 of the windows, the + * Now do the green interpolation in row 4 of the windows, the * "center" row of cur_window_v and _h, with the help of image row 0 * and image row 1. */ @@ -514,38 +514,38 @@ int gp_ahd_interpolate (unsigned char *image, int w, int h, BayerTile tile) /* this does the green interpolation in row 5 of the windows */ do_green_ctr_row(image, cur_window_h+3*w, cur_window_v+3*w, w, h, 1, p); /* - * we are now ready to do the rb interpolation on row 4 of the - * windows, which relates to row 0 of the image. - */ + * we are now ready to do the rb interpolation on row 4 of the + * windows, which relates to row 0 of the image. + */ do_rb_ctr_row(cur_window_h, cur_window_v, w, h, 0, p); /* * Row row 4, which will be mapped to image row 0, is finished in both - * windows. Row 5 has had only the green interpolation. + * windows. Row 5 has had only the green interpolation. */ memmove(window_h, window_h+3*w,15*w); memmove(window_v, window_v+3*w,15*w); memcpy (window_h+15*w, image+6*w, 3*w); memcpy (window_v+15*w, image+6*w, 3*w); /* - * now we have shifted backwards and we have row 0 of the image in + * now we have shifted backwards and we have row 0 of the image in * row 3 of the windows. Row 4 of the window contains row 1 of image - * and needs the rb interpolation. We have copied row 2 of the image - * into row 5 of the windows and need to do green interpolation. + * and needs the rb interpolation. We have copied row 2 of the image + * into row 5 of the windows and need to do green interpolation. */ do_green_ctr_row(image, cur_window_h+3*w, cur_window_v+3*w, w, h, 2, p); do_rb_ctr_row(cur_window_h, cur_window_v, w, h, 1, p); memmove (window_h, window_h+3*w, 15*w); - memmove(window_v, window_v+3*w,15*w); + memmove(window_v, window_v+3*w,15*w); /* - * We have shifted one more time. Row 2 of the two windows is - * the original row 0 of the image, now fully interpolated. Rows 3 - * and 4 of the windows contain the original rows 1 and 2 of the - * image, also fully interpolated. They will be used while applying + * We have shifted one more time. Row 2 of the two windows is + * the original row 0 of the image, now fully interpolated. Rows 3 + * and 4 of the windows contain the original rows 1 and 2 of the + * image, also fully interpolated. They will be used while applying * the choice algorithm on row 2, in order to write it back to row - * 0 of the image. The algorithm is now fully initialized. We enter + * 0 of the image. The algorithm is now fully initialized. We enter * the loop which will complete the algorithm for the whole image. */ - + for (y = 0; y < h; y++) { if(y<h-3) { memcpy (window_v+15*w,image+3*y*w+9*w, 3*w); @@ -554,16 +554,16 @@ int gp_ahd_interpolate (unsigned char *image, int w, int h, BayerTile tile) memset(window_v+15*w, 0, 3*w); memset(window_h+15*w, 0, 3*w); } - if (y<h-3) - do_green_ctr_row(image, cur_window_h+3*w, + if (y<h-3) + do_green_ctr_row(image, cur_window_h+3*w, cur_window_v+3*w, w, h, y+3, p); - if (y<h-2) + if (y<h-2) do_rb_ctr_row(cur_window_h, cur_window_v, w, h, y+2, p); /* - * The next function writes row 2 of diffs, which is the set of - * diff scores for row y+1 of the image, which is row 3 of our + * The next function writes row 2 of diffs, which is the set of + * diff scores for row y+1 of the image, which is row 3 of our * windows. When starting with row 0 of the image, this is all - * we need. As we continue, the results of this calculation + * we need. As we continue, the results of this calculation * will also be rotated; in general we need the diffs for rows * y-1, y, and y+1 in order to carry out the choice algorithm * for writing row y. @@ -572,15 +572,15 @@ int gp_ahd_interpolate (unsigned char *image, int w, int h, BayerTile tile) memset(homo_ch, 0, w); memset(homo_cv, 0, w); - /* The choice algorithm now will use the sum of the nine diff - * scores computed at the pixel location and at its eight - * nearest neighbors. The direction with highest score will - * be used; if the scores are equal an average is used. + /* The choice algorithm now will use the sum of the nine diff + * scores computed at the pixel location and at its eight + * nearest neighbors. The direction with highest score will + * be used; if the scores are equal an average is used. */ for (x=0; x < w; x++) { for (i=-1; i < 2;i++) { for (k=0; k < 3;k++) { - j=i+x+w*k; + j=i+x+w*k; if ((j >= 0) && ( j < w*3)) { homo_ch[x]+=homo_h[j]; homo_cv[x]+=homo_v[j]; @@ -629,10 +629,10 @@ int gp_ahd_interpolate (unsigned char *image, int w, int h, BayerTile tile) * 2x2 RGB pixel set out of this data. * * This function expands and interpolates the bayer array to 3 times larger - * bitmap with RGB values interpolated. It does the same job as + * bitmap with RGB values interpolated. It does the same job as * gp_bayer_decode() but it calls gp_ahd_interpolate() instead of calling - * gp_bayer_interpolate(). Use this instead of gp_bayer_decode() if you - * want to use or to test AHD interpolation in a camera library. + * gp_bayer_interpolate(). Use this instead of gp_bayer_decode() if you + * want to use or to test AHD interpolation in a camera library. * \return a gphoto error code */ |