Skip to content

Commit

Permalink
resize: simplified a bit
Browse files Browse the repository at this point in the history
Generalized handling a bit - there are only 2 cases in general - output
is 16 bit (if resize input is /eg. converted/ RG48) or 8 bit RGB.
  • Loading branch information
MartinPulec committed Nov 13, 2023
1 parent 4c2778b commit d1a8e93
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/capture_filter/resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,23 @@ reconfigure_if_needed(struct state_resize *s, const struct video_frame *in)
}
struct video_desc dec_desc = video_desc_from_frame(in);
s->out_desc = video_desc_from_frame(in);
const codec_t supp_rgb_in_codecs[] = { SUPPORTED_RGB_IN_INIT,
const codec_t supp_in_codecs[] = { RESIZE_SUPPORTED_PIXFMT_INIT,
VIDEO_CODEC_NONE };
if (codec_is_in_set(in->color_spec, supp_rgb_in_codecs)) {
s->out_desc.color_spec = RGB;
if (codec_is_in_set(in->color_spec, supp_in_codecs)) {
dec_desc.color_spec = in->color_spec;
s->decoder = vc_memcpy;
} else {
const codec_t out_cand[] = { SUPPORTED_RGB_IN_INIT, RG48,
VIDEO_CODEC_NONE };
s->decoder = get_best_decoder_from(in->color_spec, out_cand,
s->decoder = get_best_decoder_from(in->color_spec, supp_in_codecs,
&dec_desc.color_spec);
if (s->decoder == NULL) {
MSG(ERROR,
"Cannot decode %s to neither of supported input formats!\n",
get_codec_name(in->color_spec));
return false;
}
s->out_desc.color_spec = dec_desc.color_spec == RG48 ? RG48 : RGB;
}
s->out_desc.color_spec =
get_bits_per_component(dec_desc.color_spec) == DEPTH8 ? RGB : RG48;
MSG(INFO, "Decoding through %s to output pixfmt %s.\n",
get_codec_name(dec_desc.color_spec),
get_codec_name(s->out_desc.color_spec));
Expand Down
5 changes: 3 additions & 2 deletions src/capture_filter/resize_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static Mat ug_to_rgb_mat(codec_t codec, int width, int height, char *indata) {
static int
get_out_cv_data_type(codec_t pixfmt)
{
return pixfmt == RG48 ? CV_16UC3 : CV_8UC3;
return get_bits_per_component(pixfmt) == DEPTH16 ? CV_16UC3 : CV_8UC3;
}

void
Expand All @@ -133,7 +133,8 @@ resize_frame(char *indata, codec_t in_color, char *outdata, unsigned int width,
unsigned int height, unsigned int target_width,
unsigned int target_height)
{
const codec_t out_color = in_color == RG48 ? RG48 : RGB;
const codec_t out_color =
get_bits_per_component(in_color) == 16 ? RG48 : RGB;
Mat rgb = ug_to_rgb_mat(in_color, (int) width, (int) height, indata);

double in_aspect = (double) width / height;
Expand Down
2 changes: 1 addition & 1 deletion src/capture_filter/resize_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
extern "C" {
#endif

#define SUPPORTED_RGB_IN_INIT RGB, RGBA, I420, UYVY, YUYV
#define RESIZE_SUPPORTED_PIXFMT_INIT RGB, RGBA, I420, UYVY, YUYV, RG48

void resize_frame_factor(char *indata, codec_t in_color, char *outdata,
unsigned int width, unsigned int height,
Expand Down
7 changes: 7 additions & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ enum hw_accel_type {
HWACCEL_COUNT
};

enum depth {
DEPTH8 = 8,
DEPTH10 = 10,
DEPTH12 = 12,
DEPTH16 = 16,
};

enum subsampling {
SUBS_420 = 4200,
SUBS_422 = 4220,
Expand Down

0 comments on commit d1a8e93

Please sign in to comment.