Skip to content

Commit

Permalink
🚸 (video): Center images
Browse files Browse the repository at this point in the history
Essentially for pictos
  • Loading branch information
YannLocatelli committed May 22, 2022
1 parent b184e1e commit 8cdd254
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions drivers/CoreVideo/include/internal/corevideo_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace lcd {
// TODO : it should be instanciated and passed to objects that need it
namespace property {

inline constexpr uint8_t pixel_memory_size = 4; // ARGB, in bytes

// clang-format off
inline constexpr uint16_t VSA = lcd::otm8009a::landscape::vsync; // Vertical start active time in units of lines
inline constexpr uint16_t VBP = lcd::otm8009a::landscape::vbp; // Vertical Back Porch time in units of lines
Expand Down
11 changes: 10 additions & 1 deletion drivers/CoreVideo/source/CoreDMA2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ void CoreDMA2D::transferImage(uint32_t width, uint32_t height, uint32_t width_of
_hdma2d.LayerCfg[1].InputOffset = width_offset;
_hdma2d.Init.OutputOffset = lcd::dimension::width - width;

transferData(jpeg::decoded_buffer_address, lcd::frame_buffer_address, width, height);
auto memory_offset_to_center = [](auto image_width, auto image_height) {
auto unoccupied_width = lcd::dimension::width - image_width;
auto unoccupied_height = lcd::dimension::height - image_height;

return lcd::property::pixel_memory_size *
(unoccupied_width / 2 + unoccupied_height / 2 * lcd::dimension::width);
};

transferData(jpeg::decoded_buffer_address, lcd::frame_buffer_address + memory_offset_to_center(width, height),
width, height);
}

auto CoreDMA2D::getHandle() -> DMA2D_HandleTypeDef &
Expand Down
17 changes: 12 additions & 5 deletions drivers/CoreVideo/tests/CoreDMA2D_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,25 @@ TEST_F(CoreDMA2DTest, transferImage)
ASSERT_EQ(handle.Init.OutputOffset, lcd::dimension::width - image_width);
}

TEST_F(CoreDMA2DTest, transferImageDifferentWidth)
TEST_F(CoreDMA2DTest, transferImageCentered)
{
uint16_t image_width = 400;
uint16_t image_height = 400;
uint16_t image_width = 123;
uint16_t image_height = 456;

auto left_pixels_offset_to_center = (lcd::dimension::width - image_width) / 2;
auto top_pixel_offset_to_center = (lcd::dimension::height - image_height) / 2;

auto memory_offset_to_center = lcd::property::pixel_memory_size *
(left_pixels_offset_to_center + top_pixel_offset_to_center * lcd::dimension::width);

{
InSequence seq;

EXPECT_CALL(halmock, HAL_DMA2D_Init).Times(1).WillRepeatedly(Return(HAL_OK));
EXPECT_CALL(halmock, HAL_DMA2D_ConfigLayer).Times(1).WillRepeatedly(Return(HAL_OK));
EXPECT_CALL(halmock, HAL_DMA2D_Start_IT(_, jpeg::decoded_buffer_address, lcd::frame_buffer_address, image_width,
image_height))
EXPECT_CALL(halmock,
HAL_DMA2D_Start_IT(_, jpeg::decoded_buffer_address,
lcd::frame_buffer_address + memory_offset_to_center, image_width, image_height))
.Times(1);
}

Expand Down

0 comments on commit 8cdd254

Please sign in to comment.