Skip to content

Commit e15c933

Browse files
committed
SVT: fix writing alpha plane as dummy 4:2:0
1 parent a076f8b commit e15c933

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

libheif/plugins/encoder_svt.cc

+28-1
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,39 @@ struct heif_error svt_encode_image(void* encoder_raw, const struct heif_image* i
815815
auto* input_picture_buffer = (EbSvtIOFormat*) input_buffer.p_buffer;
816816

817817
int bytesPerPixel = bitdepth_y > 8 ? 2 : 1;
818+
std::vector<uint8_t> dummy_color_plane;
818819
if (input_class == heif_image_input_class_alpha) {
819820
int stride;
820821
input_picture_buffer->luma = (uint8_t*) heif_image_get_plane_readonly(image, heif_channel_Y, &stride);
821822
input_picture_buffer->y_stride = stride / bytesPerPixel;
822823
input_buffer.n_filled_len = stride * encoded_height;
824+
825+
uint32_t uvWidth = get_subsampled_size_h(encoded_width, heif_channel_Cb, heif_chroma_420, scaling_mode::round_up);
826+
uint32_t uvHeight = get_subsampled_size_v(encoded_height, heif_channel_Cb, heif_chroma_420, scaling_mode::round_up);
827+
dummy_color_plane.resize(uvWidth * uvHeight);
828+
829+
if (bitdepth_y <= 8) {
830+
uint8_t val = 1 << (bitdepth_y - 1);
831+
memset(dummy_color_plane.data(), val, uvWidth * uvHeight * bytesPerPixel);
832+
}
833+
else {
834+
assert(bitdepth_y > 8 && bitdepth_y <= 16);
835+
uint16_t val = 1 << (bitdepth_y - 1);
836+
uint8_t high = static_cast<uint8_t>((val >> 8) & 0xFF);
837+
uint8_t low = static_cast<uint8_t>(val & 0xFF);
838+
839+
for (uint32_t i=0;i<uvWidth*uvHeight;i++) {
840+
dummy_color_plane[2*i ] = low;
841+
dummy_color_plane[2*i+1] = high;
842+
}
843+
}
844+
845+
input_buffer.n_filled_len += 2* uvWidth * uvHeight;
846+
input_picture_buffer->cb_stride = uvWidth;
847+
input_picture_buffer->cr_stride = uvWidth;
848+
849+
input_picture_buffer->cb = dummy_color_plane.data();
850+
input_picture_buffer->cr = dummy_color_plane.data();
823851
}
824852
else {
825853
int stride;
@@ -853,7 +881,6 @@ struct heif_error svt_encode_image(void* encoder_raw, const struct heif_image* i
853881
}
854882

855883

856-
857884
// --- flush encoder
858885

859886
EbErrorType ret = EB_ErrorNone;

0 commit comments

Comments
 (0)