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

Issue 5575010: Integration of most changes from the GoogleTV project around the convolver/sc... (Closed)

Created:
10 years ago by evannier
Modified:
9 years, 7 months ago
Reviewers:
brettw, Stephen White
CC:
chromium-reviews, Paweł Hajdan Jr., jamesr, egouriou_google.com
Visibility:
Public.

Description

Integration of most changes from the GoogleTV project around the convolver/scaler. This contains the following improvements: - Adding a few extra convolution filters on top of the existing LANCZOS3 (used internally in Chrome), and BOX (used in unit tests): - LANCZOS2: a variation of LANCZOS3 except that the windowed function is limited to the [-2:2] range. - HAMMING1: this uses a Hamming window using the [-1:-1] range. If we define the zoom down factor to z, and w the size of the window, the actual cost of each filter (CPU wise) is proportional to (w * 2 * z + 1). So, if we look at what happens when you zoom down by a factor of 4 (as often found when creating thumbnails), the cost would be 25 for LANCZOS3, 17 for LANCZOS2, and 9 for HAMMING. As a result, HAMMING1 can end up be roughly three times as fast as the typical LANCZOS3. In terms of visual quality, HAMMING1 will be obviously worse than filters that have a larger window. The motivation of this change is that not all processors are equally equipped, and while LANCZOS3 does provide good quality, it will be completely inadequate in speed on slower processors (as found on Google TV), and it would be worth trading some visual quality for speed. Because the definitions of what is acceptable from one platform to another will differ, this change adds generic enums describing various trade offs between quality and speed. And depending on the platform, these would then be mapped to different filters. This change does not contain the other changes made to the all the call sites to transform LANCZOS3 to the appropriate enum. Another CL will have to be checked in for the policy definition. - Improvements in speed by around 10% (the actual speed up depends on the parameters of the scale (scale ratios, sizes of images), as well as the actual processor on which this is run on. The 10% was measured on scale down of 1920x1080 images to 1920/4x1080/4 using the LANCZOS3 filter on a 32bit Atom based using the image_operations_bench. Actual numbers for a 64bit processor are discussed below. This optimization attempts to basically eliminate all zeroes on each side of the filter_size, since it is very likely that the calculated window will go one fraction of a pixel outside of the window where the function is actuall not zero. In many cases, this means it gets rid the convolution by one point. So, using the math above, (w * 2 * z + 1) will have 1 subtracted. The code though is generic and will get rid of more points if possible. - To measure speed, a small utility image_operations_bench was added. Its purpose is to simply measure speed of the actual speed of the convolution without any regards to the actual data. Run with --help for a list of options. The actual measured number is in MB/s (source MB + dest MB / time). The following numbers were found on a 64 bit Release build on a z600: | zero optimization | Filter | no | yes | Hamming1 | 459 | 495 | Lanczos2 | 276 | 294 | Lanczos3 | 202 | 207 | The command line was: for i in HAMMING1 LANCZOS2 LANCZOS3 ; do echo $i; out/Release/image_operations_bench -source 1920x1080 -destination 480x270 -m $i -iter 50 ; done The actual improvements for the zero optimization mentioned above are much more prevalent on a 32bit Atom. - Commented that there is half-pixel error inside the code in image_operations. Because this would effectively changes the results of many scales that are used in win_layout tests, this would effectively break them. As a result, the change here only adds comments about what needs to be changed, but does not fix the issue itself. A subsequent change will remove the comments and enable the fix, and also adds the corrected reference images used for the test. See bug 69999: http://code.google.com/p/chromium/issues/detail?id=69999 - Enhanced the convolver to support arbitrary strides, instead of the hard coded 4 * width. This value is correct on most platforms, but is not on GoogleTV since buffers allocated need to be 32 pixel multiples to exploit HW capabilities. - Added numerous unit tests to cover the new filters as well as adding other ones that are more rigourous than the existing ones. Such a test is the reason, we have found the half pixel error mentioned above. TEST=This was tested against the existing unit tests, and the added unit tests on a 64 bit Linux platform. The tests were then ran under valgrind to check for possible memory leaks/ and errors. The tests do come out clean (except the preexisting file descriptor 'leaks' coming from other tests that are linked with test_shell_tests Actual credit to most of the actual changes go to various contributors of the Google TV team. Note that there are two types of optimizations that are possible beyond these changes that are not done here: 1/ Use the fact that the filter coefficients will be periodic to reduce the cost of calculating the coefficients (though typically in the noise), but rather when the convolution is done to decrease cache misses on the coefficients. Experiments showed that on an Atom, this can yield 5 % improvement. 2/ This code is the prime target for the use of SIMD instructions. BUG=47447, 62820, 69999

Patch Set 1 #

Patch Set 2 : '' #

Patch Set 3 : '' #

Patch Set 4 : '' #

Patch Set 5 : '' #

Patch Set 6 : '' #

Patch Set 7 : Further attempt at getting the code to properly compile on Windows #

Patch Set 8 : Fixing another compile error on Windows #

Total comments: 4

Patch Set 9 : Fixes to address Brett's comments #

Total comments: 26

Patch Set 10 : Addessing the latest round of comments #

Patch Set 11 : Removing the fixes for the half pixel problem, since it currently breaks webkit tests #

Patch Set 12 : Remove some lint errors #

Total comments: 19

Patch Set 13 : Latest rounds of changes to address Brett's comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1152 lines, -63 lines) Patch
M skia/ext/convolver.h View 1 2 3 4 5 6 7 8 9 10 11 12 4 chunks +16 lines, -1 line 0 comments Download
M skia/ext/convolver.cc View 1 2 3 4 5 6 7 8 9 10 11 12 6 chunks +40 lines, -18 lines 0 comments Download
M skia/ext/convolver_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 5 chunks +84 lines, -4 lines 0 comments Download
M skia/ext/image_operations.h View 1 2 3 4 5 6 7 8 9 10 11 12 4 chunks +60 lines, -1 line 0 comments Download
M skia/ext/image_operations.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 chunks +119 lines, -10 lines 0 comments Download
A skia/ext/image_operations_bench.cc View 1 2 3 4 5 6 7 8 9 10 1 chunk +293 lines, -0 lines 0 comments Download
M skia/ext/image_operations_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 5 chunks +523 lines, -26 lines 0 comments Download
M skia/skia.gyp View 1 2 3 4 5 6 7 8 9 10 11 12 3 chunks +17 lines, -3 lines 0 comments Download

Messages

Total messages: 13 (0 generated)
evannier
As discussed over email, here is a list of some of the changes that were ...
10 years ago (2010-12-09 02:07:55 UTC) #1
brettw
Just the convolver part, I have to leave for the dentist now, will do the ...
10 years ago (2010-12-17 16:42:09 UTC) #2
evannier
I have addressed your comments, reran the unit tests (under valgrind), and benchmark. http://codereview.chromium.org/5575010/diff/39002/skia/ext/convolver.cc File ...
10 years ago (2010-12-17 18:51:12 UTC) #3
brettw
http://codereview.chromium.org/5575010/diff/62001/skia/ext/image_operations.cc File skia/ext/image_operations.cc (right): http://codereview.chromium.org/5575010/diff/62001/skia/ext/image_operations.cc#newcode121 skia/ext/image_operations.cc:121: case ImageOperations::RESIZE_LANCZOS2: Where is LANCZOS1 handled? Same below. http://codereview.chromium.org/5575010/diff/62001/skia/ext/image_operations.cc#newcode260 ...
10 years ago (2010-12-17 20:07:55 UTC) #4
evannier
I have addressed the comments and uploaded a new patch (and ran it again on ...
10 years ago (2010-12-19 00:15:03 UTC) #5
brettw
http://codereview.chromium.org/5575010/diff/62001/skia/ext/image_operations.cc File skia/ext/image_operations.cc (right): http://codereview.chromium.org/5575010/diff/62001/skia/ext/image_operations.cc#newcode260 skia/ext/image_operations.cc:260: float src_pixel = (static_cast<float>(dest_subset_i) + 0.5f) * inv_scale; That's ...
10 years ago (2010-12-20 18:18:45 UTC) #6
brettw
If the layout tests are causing problems for you, you can keep the "off-by-one-half-pixel" fix ...
9 years, 11 months ago (2011-01-18 17:52:35 UTC) #7
evannier
Sorry, I have been busy on other things. And yes, the webkit tests are indeed ...
9 years, 11 months ago (2011-01-18 17:56:29 UTC) #8
evannier
Thanks for the latest round of comments. The code should be ready for another round ...
9 years, 11 months ago (2011-01-18 21:51:52 UTC) #9
brettw
Thanks! I just have some minor style nits this time around. http://codereview.chromium.org/5575010/diff/94001/skia/ext/convolver.cc File skia/ext/convolver.cc (right): ...
9 years, 11 months ago (2011-01-20 21:48:06 UTC) #10
evannier
http://codereview.chromium.org/5575010/diff/94001/skia/ext/convolver.cc File skia/ext/convolver.cc (right): http://codereview.chromium.org/5575010/diff/94001/skia/ext/convolver.cc#newcode255 skia/ext/convolver.cc:255: while (first_non_zero < filter_length && filter_values[first_non_zero] == 0) { ...
9 years, 11 months ago (2011-01-24 21:09:58 UTC) #11
brettw
LGTM http://codereview.chromium.org/5575010/diff/94001/skia/ext/image_operations_unittest.cc File skia/ext/image_operations_unittest.cc (right): http://codereview.chromium.org/5575010/diff/94001/skia/ext/image_operations_unittest.cc#newcode15 skia/ext/image_operations_unittest.cc:15: #if DEBUG_BITMAP_GENERATION Right, that's what I meant.
9 years, 11 months ago (2011-01-26 20:19:43 UTC) #12
brettw
9 years, 10 months ago (2011-01-30 18:42:00 UTC) #13
Checked in as r73110

Powered by Google App Engine
This is Rietveld 408576698