+ for ( int dsty = 0; dsty < height; dsty++ )
+ {
+ // We need to calculate the source pixel to interpolate from - Y-axis
+ double srcpixy = double(dsty * M_IMGDATA->m_height) / height;
+ double dy = srcpixy - (int)srcpixy;
+
+ for ( int dstx = 0; dstx < width; dstx++ )
+ {
+ // X-axis of pixel to interpolate from
+ double srcpixx = double(dstx * M_IMGDATA->m_width) / width;
+ double dx = srcpixx - (int)srcpixx;
+
+ // Sums for each color channel
+ double sum_r = 0, sum_g = 0, sum_b = 0, sum_a = 0;
+
+ // Here we actually determine the RGBA values for the destination pixel
+ for ( int k = -1; k <= 2; k++ )
+ {
+ // Y offset
+ int y_offset = srcpixy + k < 0.0
+ ? 0
+ : srcpixy + k >= M_IMGDATA->m_height
+ ? M_IMGDATA->m_height - 1
+ : (int)(srcpixy + k);
+
+ // Loop across the X axis
+ for ( int i = -1; i <= 2; i++ )
+ {
+ // X offset
+ int x_offset = srcpixx + i < 0.0
+ ? 0
+ : srcpixx + i >= M_IMGDATA->m_width
+ ? M_IMGDATA->m_width - 1
+ : (int)(srcpixx + i);
+
+ // Calculate the exact position where the source data
+ // should be pulled from based on the x_offset and y_offset
+ int src_pixel_index = y_offset*M_IMGDATA->m_width + x_offset;
+
+ // Calculate the weight for the specified pixel according
+ // to the bicubic b-spline kernel we're using for
+ // interpolation
+ double
+ pixel_weight = spline_weight(i - dx)*spline_weight(k - dy);
+
+ // Create a sum of all velues for each color channel
+ // adjusted for the pixel's calculated weight
+ sum_r += src_data[src_pixel_index * 3 + 0] * pixel_weight;
+ sum_g += src_data[src_pixel_index * 3 + 1] * pixel_weight;
+ sum_b += src_data[src_pixel_index * 3 + 2] * pixel_weight;
+ if ( src_alpha )
+ sum_a += src_alpha[src_pixel_index] * pixel_weight;
+ }
+ }
+
+ // Put the data into the destination image. The summed values are
+ // of double data type and are rounded here for accuracy
+ dst_data[0] = (unsigned char)(sum_r + 0.5);
+ dst_data[1] = (unsigned char)(sum_g + 0.5);
+ dst_data[2] = (unsigned char)(sum_b + 0.5);
+ dst_data += 3;
+
+ if ( src_alpha )
+ *dst_alpha++ = (unsigned char)sum_a;
+ }
+ }
+
+ return ret_image;
+}
+
+// Blur in the horizontal direction
+wxImage wxImage::BlurHorizontal(int blurRadius) const
+{
+ wxImage ret_image;
+ ret_image.Create(M_IMGDATA->m_width, M_IMGDATA->m_height, false);
+
+ unsigned char* src_data = M_IMGDATA->m_data;
+ unsigned char* dst_data = ret_image.GetData();
+ unsigned char* src_alpha = M_IMGDATA->m_alpha;
+ unsigned char* dst_alpha = NULL;
+
+ // Check for a mask or alpha
+ if ( src_alpha )
+ {
+ ret_image.SetAlpha();
+ dst_alpha = ret_image.GetAlpha();
+ }
+ else if ( M_IMGDATA->m_hasMask )
+ {
+ ret_image.SetMaskColour(M_IMGDATA->m_maskRed,
+ M_IMGDATA->m_maskGreen,
+ M_IMGDATA->m_maskBlue);
+ }
+
+ // number of pixels we average over
+ const int blurArea = blurRadius*2 + 1;
+
+ // Horizontal blurring algorithm - average all pixels in the specified blur
+ // radius in the X or horizontal direction
+ for ( int y = 0; y < M_IMGDATA->m_height; y++ )
+ {
+ // Variables used in the blurring algorithm
+ long sum_r = 0,
+ sum_g = 0,
+ sum_b = 0,
+ sum_a = 0;
+
+ long pixel_idx;
+ const unsigned char *src;
+ unsigned char *dst;
+
+ // Calculate the average of all pixels in the blur radius for the first
+ // pixel of the row
+ for ( int kernel_x = -blurRadius; kernel_x <= blurRadius; kernel_x++ )
+ {
+ // To deal with the pixels at the start of a row so it's not
+ // grabbing GOK values from memory at negative indices of the
+ // image's data or grabbing from the previous row
+ if ( kernel_x < 0 )
+ pixel_idx = y * M_IMGDATA->m_width;
+ else
+ pixel_idx = kernel_x + y * M_IMGDATA->m_width;
+
+ src = src_data + pixel_idx*3;
+ sum_r += src[0];
+ sum_g += src[1];
+ sum_b += src[2];
+ if ( src_alpha )
+ sum_a += src_alpha[pixel_idx];
+ }
+
+ dst = dst_data + y * M_IMGDATA->m_width*3;
+ dst[0] = (unsigned char)(sum_r / blurArea);
+ dst[1] = (unsigned char)(sum_g / blurArea);
+ dst[2] = (unsigned char)(sum_b / blurArea);
+ if ( src_alpha )
+ dst_alpha[y * M_IMGDATA->m_width] = (unsigned char)(sum_a / blurArea);
+
+ // Now average the values of the rest of the pixels by just moving the
+ // blur radius box along the row
+ for ( int x = 1; x < M_IMGDATA->m_width; x++ )