Index: skia/ext/convolver_unittest.cc |
diff --git a/skia/ext/convolver_unittest.cc b/skia/ext/convolver_unittest.cc |
index f61b685daf5e748da8e9f584dcf3d427c1d0f6f4..9acba1c2233a89d0bb3f3be21083ffe324f6b75b 100644 |
--- a/skia/ext/convolver_unittest.cc |
+++ b/skia/ext/convolver_unittest.cc |
@@ -318,4 +318,57 @@ TEST(Convolver, SIMDVerification) { |
#endif |
} |
+TEST(Convolver, SeparableSingleConvolution) { |
+ static const int kSize = 1024; |
+ static const int kChannelCount = 3; |
+ static const int kStrideSlack = 22; |
+ ConvolutionFilter1D filter; |
+ const float box[5] = { 0.2, 0.2, 0.2, 0.2, 0.2 }; |
+ filter.AddFilter(0, box, 5); |
+ |
+ // Allocate a source image and set to 0. |
+ int img_width = kSize; |
+ int img_height = kSize; |
+ int src_row_stride = img_width * kChannelCount + kStrideSlack; |
+ int src_byte_count = src_row_stride * img_height; |
+ std::vector<unsigned char> input; |
+ int signal_x = img_width / 2; |
+ int signal_y = img_height / 2; |
+ input.resize(src_byte_count, 0); |
+ // The image has a single impulse pixel in channel 1, smack in the middle. |
+ int non_zero_pixel_index = |
+ signal_y * src_row_stride + signal_x * kChannelCount + 1; |
+ input[non_zero_pixel_index] = 255; |
+ |
+ // Destination will be a single channel image with stide matching width. |
+ int dest_row_stride = img_width; |
+ int dest_byte_count = dest_row_stride * img_height; |
+ std::vector<unsigned char> output; |
+ output.resize(dest_byte_count); |
+ |
+ // Apply convolution in X. |
+ SingleChannelConvolve1D_X(&input[0], src_row_stride, 1, kChannelCount, |
+ filter, SkISize::Make(img_width, img_height), |
+ &output[0], dest_row_stride, 0, 1, false); |
+ for (int x = signal_x - 2; x <= signal_x + 2; ++x) { |
+ EXPECT_GT(output[signal_y * dest_row_stride + x], 0); |
+ } |
+ EXPECT_EQ(output[signal_y * dest_row_stride + signal_x - 3], 0); |
+ EXPECT_EQ(output[signal_y * dest_row_stride + signal_x + 3], 0); |
+ |
+ // Apply convolution in Y. |
+ SingleChannelConvolve1D_Y(&input[0], src_row_stride, 1, kChannelCount, |
+ filter, SkISize::Make(img_width, img_height), |
+ &output[0], dest_row_stride, 0, 1, false); |
+ for (int y = signal_y - 2; y <= signal_y + 2; ++y) { |
+ EXPECT_GT(output[y * dest_row_stride + signal_x], 0); |
+ } |
+ |
+ EXPECT_EQ(output[(signal_y - 3) * dest_row_stride + signal_x], 0); |
+ EXPECT_EQ(output[(signal_y + 3) * dest_row_stride + signal_x], 0); |
+ |
+ EXPECT_EQ(output[signal_y * dest_row_stride + signal_x - 1], 0); |
+ EXPECT_EQ(output[signal_y * dest_row_stride + signal_x + 1], 0); |
+} |
+ |
} // namespace skia |