Skip to content

Commit

Permalink
postprocessor: Add Yuv420ToRgb override passing a destination pointer
Browse files Browse the repository at this point in the history
Allow the caller to allocate buffers use use for the conversion
externally.

Signed-off-by: Naushir Patuck <[email protected]>
  • Loading branch information
naushir committed May 14, 2024
1 parent 3b37b76 commit d38e17a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions post_processing_stages/post_processing_stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ void PostProcessingStage::Teardown()
std::vector<uint8_t> PostProcessingStage::Yuv420ToRgb(const uint8_t *src, StreamInfo &src_info, StreamInfo &dst_info)
{
std::vector<uint8_t> output(dst_info.height * dst_info.stride);
Yuv420ToRgb(output.data(), src, src_info, dst_info);
return output;
}

void PostProcessingStage::Yuv420ToRgb(uint8_t *dst, const uint8_t *src, StreamInfo &src_info, StreamInfo &dst_info)
{
assert(src_info.width >= dst_info.width && src_info.height >= dst_info.height);
int off_x = ((src_info.width - dst_info.width) / 2) & ~1, off_y = ((src_info.height - dst_info.height) / 2) & ~1;
int src_Y_size = src_info.height * src_info.stride, src_U_size = (src_info.height / 2) * (src_info.stride / 2);
Expand All @@ -59,7 +64,7 @@ std::vector<uint8_t> PostProcessingStage::Yuv420ToRgb(const uint8_t *src, Stream
const uint8_t *src_U = src + src_Y_size + ((y + off_y) / 2) * (src_info.stride / 2) + off_x / 2;
const uint8_t *src_V = src_U + src_U_size;
const uint8_t *src_Y1 = src_Y0 + src_info.stride;
uint8_t *dst0 = &output[y * dst_info.stride];
uint8_t *dst0 = &dst[y * dst_info.stride];
uint8_t *dst1 = dst0 + dst_info.stride;

unsigned int x = 0;
Expand Down Expand Up @@ -213,7 +218,7 @@ std::vector<uint8_t> PostProcessingStage::Yuv420ToRgb(const uint8_t *src, Stream
const uint8_t *src_Y0 = src + (y + off_y) * src_info.stride + off_x;
const uint8_t *src_U = src + src_Y_size + ((y + off_y) / 2) * (src_info.stride / 2) + off_x / 2;
const uint8_t *src_V = src_U + src_U_size;
uint8_t *dst0 = &output[y * dst_info.stride];
uint8_t *dst0 = &dst[y * dst_info.stride];

unsigned int x = 0;
for (; x < dst_info.width; x++)
Expand All @@ -240,8 +245,6 @@ std::vector<uint8_t> PostProcessingStage::Yuv420ToRgb(const uint8_t *src, Stream
*(dst0++) = B0;
}
}

return output;
}

static std::map<std::string, StageCreateFunc> &stages()
Expand Down
1 change: 1 addition & 0 deletions post_processing_stages/post_processing_stage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PostProcessingStage
// Convert YUV420 image to RGB. We crop from the centre of the image if the src
// image is larger than the destination.
static std::vector<uint8_t> Yuv420ToRgb(const uint8_t *src, StreamInfo &src_info, StreamInfo &dst_info);
static void Yuv420ToRgb(uint8_t *dst, const uint8_t *src, StreamInfo &src_info, StreamInfo &dst_info)

protected:
// Helper to calculate the execution time of any callable object and return it in as a std::chrono::duration.
Expand Down

0 comments on commit d38e17a

Please sign in to comment.