-
Notifications
You must be signed in to change notification settings - Fork 32
Core (LV::Video) Fix alpha blending of 32-bit videos (#230) #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e5f954a
Core (LV::Video): Clean up blit_overlay_alphasrc().
kaixiong 3a7d770
Core (LV::Video): Rewrite MMX alpha blending of 32-bit videos using i…
kaixiong 8cbfb5c
Core (Tests): Add test for LV::VideoBlit::blit_overlay_alphasrc().
kaixiong 0e95069
Core (LV::Video): Add explanatory note on calculation in blit_overlay…
kaixiong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #include "random.hpp" | ||
| #include <random> | ||
|
|
||
| namespace LV::Tests | ||
| { | ||
| LV::VideoPtr create_random_video (int width, int height, VisVideoDepth depth) | ||
| { | ||
| std::random_device device {}; | ||
| std::uniform_int_distribution<uint8_t> distrib {0, 255}; | ||
|
|
||
| auto video {LV::Video::create (width, height, depth)}; | ||
|
|
||
| auto bytes_per_pixel = video->get_bpp (); | ||
| auto pitch = video->get_pitch (); | ||
|
|
||
| auto content_bytes_per_row = bytes_per_pixel * video->get_width (); | ||
|
|
||
| auto pixel_row_ptr = static_cast<uint8_t *>(video->get_pixels ()); | ||
|
|
||
| for (int y = 0; y < video->get_height (); y++) { | ||
| auto pixel = pixel_row_ptr; | ||
| for (int c = 0; c < content_bytes_per_row; c++) { | ||
| *pixel = distrib (device); | ||
| pixel++; | ||
| } | ||
|
|
||
| pixel_row_ptr += pitch; | ||
| } | ||
|
|
||
| return video; | ||
| } | ||
| } // LV::Tests namespace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef _LV_TESTS_VIDEO_RANDOM_HPP | ||
| #define _LV_TESTS_VIDEO_RANDOM_HPP | ||
|
|
||
| #include <libvisual/libvisual.h> | ||
|
|
||
| namespace LV::Tests | ||
| { | ||
| LV::VideoPtr create_random_video (int width, int height, VisVideoDepth depth); | ||
|
|
||
| } // LV::Tests namespace | ||
|
|
||
| #endif // defined(_LV_TESTS_VIDEO_COMMON_HPP) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #include "test.h" | ||
| #include "random.hpp" | ||
| #include <libvisual/libvisual.h> | ||
| #include <cassert> | ||
|
|
||
| namespace | ||
| { | ||
| LV::VideoPtr clone_video (LV::VideoPtr const& source) | ||
| { | ||
| auto clone {LV::Video::create (source->get_width (), source->get_height (), source->get_depth ())}; | ||
|
|
||
| assert (clone->get_pitch () == source->get_pitch ()); | ||
| std::size_t buffer_size = static_cast<std::size_t> (clone->get_pitch () * clone->get_width ()); | ||
|
|
||
| visual_mem_copy (clone->get_pixels (), source->get_pixels (), buffer_size); | ||
|
|
||
| return clone; | ||
| } | ||
|
|
||
| void test_blit_overlay_alphasrc () | ||
| { | ||
| // Check that blit_overlay_alphasrc results are within +/- 1 of exact computation for each colour channel. The | ||
| // errors largely arise from the use of 256 instead of 255 as divisor for performance reasons. | ||
|
|
||
| int const test_width = 31; | ||
| int const test_height = 31; | ||
|
|
||
| auto source = LV::Tests::create_random_video (test_width, test_height, VISUAL_VIDEO_DEPTH_32BIT); | ||
| source->set_compose_type (VISUAL_VIDEO_COMPOSE_TYPE_SRC); | ||
|
|
||
| auto target = LV::Tests::create_random_video (test_width, test_height, VISUAL_VIDEO_DEPTH_32BIT); | ||
|
|
||
| auto actual {clone_video (target)}; | ||
| actual->blit (source, 0, 0, true); | ||
|
|
||
| for (int y = 0; y < test_height; y++) { | ||
| auto source_pixel = static_cast<uint8_t const*> (source->get_pixel_ptr (0, y)); | ||
| auto target_pixel = static_cast<uint8_t const*> (target->get_pixel_ptr (0, y)); | ||
| auto actual_pixel = static_cast<uint8_t const*> (actual->get_pixel_ptr (0, y)); | ||
|
|
||
| for (int x = 0; x < test_width; x++) { | ||
| LV_TEST_ASSERT (actual_pixel[3] == target_pixel[3]); | ||
|
|
||
| float source_alpha = static_cast<float> (source_pixel[3]) / 255.0f; | ||
| uint8_t b = source_alpha * source_pixel[0] + (1.0f - source_alpha) * target_pixel[0]; | ||
| uint8_t g = source_alpha * source_pixel[1] + (1.0f - source_alpha) * target_pixel[1]; | ||
| uint8_t r = source_alpha * source_pixel[2] + (1.0f - source_alpha) * target_pixel[2]; | ||
|
|
||
| LV_TEST_ASSERT (std::abs (static_cast<int16_t> (actual_pixel[0]) - static_cast<int16_t> (b)) <= 1); | ||
| LV_TEST_ASSERT (std::abs (static_cast<int16_t> (actual_pixel[1]) - static_cast<int16_t> (g)) <= 1); | ||
| LV_TEST_ASSERT (std::abs (static_cast<int16_t> (actual_pixel[2]) - static_cast<int16_t> (r)) <= 1); | ||
|
|
||
| source_pixel += 4; | ||
| target_pixel += 4; | ||
| actual_pixel += 4; | ||
| } | ||
| } | ||
| } | ||
| } // anonymous namespace | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| LV::System::init (argc, argv); | ||
| test_blit_overlay_alphasrc (); | ||
| LV::System::destroy (); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.