Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: skia/ext/convolver_unittest.cc

Issue 13947013: Complete (but inefficient) implementation of the image retargetting method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string.h> 5 #include <string.h>
6 #include <time.h> 6 #include <time.h>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 311 }
312 r1 += result_c.rowBytes(); 312 r1 += result_c.rowBytes();
313 r2 += result_sse.rowBytes(); 313 r2 += result_sse.rowBytes();
314 } 314 }
315 } 315 }
316 } 316 }
317 } 317 }
318 #endif 318 #endif
319 } 319 }
320 320
321 TEST(Convolver, SeparableSingleConvolution) {
322 static const int kSize = 1024;
323 static const int kChannelCount = 3;
324 static const int kStrideSlack = 22;
325 ConvolutionFilter1D filter;
326 const float box[5] = { 0.2, 0.2, 0.2, 0.2, 0.2 };
327 filter.AddFilter(0, box, 5);
328
329 // Allocate a source image and set to 0.
330 int img_width = kSize;
331 int img_height = kSize;
332 int src_row_stride = img_width * kChannelCount + kStrideSlack;
333 int src_byte_count = src_row_stride * img_height;
334 std::vector<unsigned char> input;
335 int signal_x = img_width / 2;
336 int signal_y = img_height / 2;
337 input.resize(src_byte_count, 0);
338 // The image has a single impulse pixel in channel 1, smack in the middle.
339 int non_zero_pixel_index =
340 signal_y * src_row_stride + signal_x * kChannelCount + 1;
341 input[non_zero_pixel_index] = 255;
342
343 // Destination will be a single channel image with stide matching width.
344 int dest_row_stride = img_width;
345 int dest_byte_count = dest_row_stride * img_height;
346 std::vector<unsigned char> output;
347 output.resize(dest_byte_count);
348
349 // Apply convolution in X.
350 SingleChannelConvolve1D_X(&input[0], src_row_stride, 1, kChannelCount,
351 filter, SkISize::Make(img_width, img_height),
352 &output[0], dest_row_stride, 0, 1, false);
353 for (int x = signal_x - 2; x <= signal_x + 2; ++x) {
354 EXPECT_GT(output[signal_y * dest_row_stride + x], 0);
355 }
356 EXPECT_EQ(output[signal_y * dest_row_stride + signal_x - 3], 0);
357 EXPECT_EQ(output[signal_y * dest_row_stride + signal_x + 3], 0);
358
359 // Apply convolution in Y.
360 SingleChannelConvolve1D_Y(&input[0], src_row_stride, 1, kChannelCount,
361 filter, SkISize::Make(img_width, img_height),
362 &output[0], dest_row_stride, 0, 1, false);
363 for (int y = signal_y - 2; y <= signal_y + 2; ++y) {
364 EXPECT_GT(output[y * dest_row_stride + signal_x], 0);
365 }
366
367 EXPECT_EQ(output[(signal_y - 3) * dest_row_stride + signal_x], 0);
368 EXPECT_EQ(output[(signal_y + 3) * dest_row_stride + signal_x], 0);
369
370 EXPECT_EQ(output[signal_y * dest_row_stride + signal_x - 1], 0);
371 EXPECT_EQ(output[signal_y * dest_row_stride + signal_x + 1], 0);
372 }
373
321 } // namespace skia 374 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698