mirror of
https://github.com/mpv-player/mpv
synced 2025-05-08 11:10:15 +00:00
video: make mp_image use mp_image_params directly
Minor cleanup, so that we can stuff more information into mp_image_params later.
This commit is contained in:
parent
44096073e9
commit
5e4e248dc2
@ -229,8 +229,8 @@ static void scale_sb_rgba(struct sub_bitmap *sb, struct mp_image *dst_format,
|
|||||||
unpremultiply_and_split_BGR32(sbisrc2, sba);
|
unpremultiply_and_split_BGR32(sbisrc2, sba);
|
||||||
|
|
||||||
struct mp_image *sbi = mp_image_alloc(dst_format->imgfmt, sb->dw, sb->dh);
|
struct mp_image *sbi = mp_image_alloc(dst_format->imgfmt, sb->dw, sb->dh);
|
||||||
sbi->colorspace = dst_format->colorspace;
|
sbi->params.colorspace = dst_format->params.colorspace;
|
||||||
sbi->levels = dst_format->levels;
|
sbi->params.colorlevels = dst_format->params.colorlevels;
|
||||||
mp_image_swscale(sbi, sbisrc2, SWS_BILINEAR);
|
mp_image_swscale(sbi, sbisrc2, SWS_BILINEAR);
|
||||||
|
|
||||||
talloc_free(sbisrc2);
|
talloc_free(sbisrc2);
|
||||||
@ -280,8 +280,8 @@ static void draw_ass(struct mp_draw_sub_cache *cache, struct mp_rect bb,
|
|||||||
struct mp_image *temp, int bits, struct sub_bitmaps *sbs)
|
struct mp_image *temp, int bits, struct sub_bitmaps *sbs)
|
||||||
{
|
{
|
||||||
struct mp_csp_params cspar = MP_CSP_PARAMS_DEFAULTS;
|
struct mp_csp_params cspar = MP_CSP_PARAMS_DEFAULTS;
|
||||||
cspar.colorspace.format = temp->colorspace;
|
cspar.colorspace.format = temp->params.colorspace;
|
||||||
cspar.colorspace.levels_in = temp->levels;
|
cspar.colorspace.levels_in = temp->params.colorlevels;
|
||||||
cspar.colorspace.levels_out = MP_CSP_LEVELS_PC; // RGB (libass.color)
|
cspar.colorspace.levels_out = MP_CSP_LEVELS_PC; // RGB (libass.color)
|
||||||
cspar.int_bits_in = bits;
|
cspar.int_bits_in = bits;
|
||||||
cspar.int_bits_out = 8;
|
cspar.int_bits_out = 8;
|
||||||
@ -393,8 +393,8 @@ static struct part *get_cache(struct mp_draw_sub_cache *cache,
|
|||||||
if (part) {
|
if (part) {
|
||||||
if (part->bitmap_pos_id != sbs->bitmap_pos_id
|
if (part->bitmap_pos_id != sbs->bitmap_pos_id
|
||||||
|| part->imgfmt != format->imgfmt
|
|| part->imgfmt != format->imgfmt
|
||||||
|| part->colorspace != format->colorspace
|
|| part->colorspace != format->params.colorspace
|
||||||
|| part->levels != format->levels)
|
|| part->levels != format->params.colorlevels)
|
||||||
{
|
{
|
||||||
talloc_free(part);
|
talloc_free(part);
|
||||||
part = NULL;
|
part = NULL;
|
||||||
@ -406,8 +406,8 @@ static struct part *get_cache(struct mp_draw_sub_cache *cache,
|
|||||||
.bitmap_pos_id = sbs->bitmap_pos_id,
|
.bitmap_pos_id = sbs->bitmap_pos_id,
|
||||||
.num_imgs = sbs->num_parts,
|
.num_imgs = sbs->num_parts,
|
||||||
.imgfmt = format->imgfmt,
|
.imgfmt = format->imgfmt,
|
||||||
.levels = format->levels,
|
.levels = format->params.colorlevels,
|
||||||
.colorspace = format->colorspace,
|
.colorspace = format->params.colorspace,
|
||||||
};
|
};
|
||||||
part->imgs = talloc_zero_array(part, struct sub_cache,
|
part->imgs = talloc_zero_array(part, struct sub_cache,
|
||||||
part->num_imgs);
|
part->num_imgs);
|
||||||
@ -461,8 +461,8 @@ static struct mp_image *chroma_up(struct mp_draw_sub_cache *cache, int imgfmt,
|
|||||||
// The temp image is always YUV, but src not necessarily.
|
// The temp image is always YUV, but src not necessarily.
|
||||||
// Reduce amount of conversions in YUV case (upsampling/shifting only)
|
// Reduce amount of conversions in YUV case (upsampling/shifting only)
|
||||||
if (src->flags & MP_IMGFLAG_YUV) {
|
if (src->flags & MP_IMGFLAG_YUV) {
|
||||||
temp->colorspace = src->colorspace;
|
temp->params.colorspace = src->params.colorspace;
|
||||||
temp->levels = src->levels;
|
temp->params.colorlevels = src->params.colorlevels;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src->imgfmt == IMGFMT_420P) {
|
if (src->imgfmt == IMGFMT_420P) {
|
||||||
|
@ -176,10 +176,7 @@ static void vf_fix_img_params(struct mp_image *img, struct mp_image_params *p)
|
|||||||
// If --colormatrix is used, decoder and filter chain disagree too.
|
// If --colormatrix is used, decoder and filter chain disagree too.
|
||||||
// In general, it's probably more convenient to force these here,
|
// In general, it's probably more convenient to force these here,
|
||||||
// instead of requiring filters to set these correctly.
|
// instead of requiring filters to set these correctly.
|
||||||
img->colorspace = p->colorspace;
|
img->params = *p;
|
||||||
img->levels = p->colorlevels;
|
|
||||||
img->chroma_location = p->chroma_location;
|
|
||||||
mp_image_set_display_size(img, p->d_w, p->d_h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a new image for filter output, with size and pixel format according to
|
// Get a new image for filter output, with size and pixel format according to
|
||||||
@ -411,17 +408,12 @@ int vf_next_config(struct vf_instance *vf,
|
|||||||
int width, int height, int d_width, int d_height,
|
int width, int height, int d_width, int d_height,
|
||||||
unsigned int voflags, unsigned int outfmt)
|
unsigned int voflags, unsigned int outfmt)
|
||||||
{
|
{
|
||||||
vf->fmt_out = (struct mp_image_params) {
|
vf->fmt_out = vf->fmt_in;
|
||||||
.imgfmt = outfmt,
|
vf->fmt_out.imgfmt = outfmt;
|
||||||
.w = width,
|
vf->fmt_out.w = width;
|
||||||
.h = height,
|
vf->fmt_out.h = height;
|
||||||
.d_w = d_width,
|
vf->fmt_out.d_w = d_width;
|
||||||
.d_h = d_height,
|
vf->fmt_out.d_h = d_height;
|
||||||
.colorspace = vf->fmt_in.colorspace,
|
|
||||||
.colorlevels = vf->fmt_in.colorlevels,
|
|
||||||
.chroma_location = vf->fmt_in.chroma_location,
|
|
||||||
.outputlevels = vf->fmt_in.outputlevels,
|
|
||||||
};
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ static void mp_image_alloc_planes(struct mp_image *mpi)
|
|||||||
void mp_image_setfmt(struct mp_image *mpi, int out_fmt)
|
void mp_image_setfmt(struct mp_image *mpi, int out_fmt)
|
||||||
{
|
{
|
||||||
struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(out_fmt);
|
struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(out_fmt);
|
||||||
|
mpi->params.imgfmt = fmt.id;
|
||||||
mpi->fmt = fmt;
|
mpi->fmt = fmt;
|
||||||
mpi->flags = fmt.flags;
|
mpi->flags = fmt.flags;
|
||||||
mpi->imgfmt = fmt.id;
|
mpi->imgfmt = fmt.id;
|
||||||
@ -179,8 +180,9 @@ void mp_image_set_size(struct mp_image *mpi, int w, int h)
|
|||||||
if (w >= (1 << 14) || h >= (1 << 14) || w < 0 || h < 0)
|
if (w >= (1 << 14) || h >= (1 << 14) || w < 0 || h < 0)
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
mpi->w = mpi->display_w = w;
|
mpi->w = mpi->params.w = w;
|
||||||
mpi->h = mpi->display_h = h;
|
mpi->h = mpi->params.h = h;
|
||||||
|
mp_image_set_display_size(mpi, mpi->w, mpi->h);
|
||||||
for (int n = 0; n < mpi->num_planes; n++) {
|
for (int n = 0; n < mpi->num_planes; n++) {
|
||||||
mpi->plane_w[n] = mp_chroma_div_up(mpi->w, mpi->fmt.xs[n]);
|
mpi->plane_w[n] = mp_chroma_div_up(mpi->w, mpi->fmt.xs[n]);
|
||||||
mpi->plane_h[n] = mp_chroma_div_up(mpi->h, mpi->fmt.ys[n]);
|
mpi->plane_h[n] = mp_chroma_div_up(mpi->h, mpi->fmt.ys[n]);
|
||||||
@ -191,10 +193,22 @@ void mp_image_set_size(struct mp_image *mpi, int w, int h)
|
|||||||
|
|
||||||
void mp_image_set_display_size(struct mp_image *mpi, int dw, int dh)
|
void mp_image_set_display_size(struct mp_image *mpi, int dw, int dh)
|
||||||
{
|
{
|
||||||
|
mpi->params.d_w = dw;
|
||||||
|
mpi->params.d_h = dh;
|
||||||
mpi->display_w = dw;
|
mpi->display_w = dw;
|
||||||
mpi->display_h = dh;
|
mpi->display_h = dh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mp_image_set_params(struct mp_image *image,
|
||||||
|
const struct mp_image_params *params)
|
||||||
|
{
|
||||||
|
image->params = *params;
|
||||||
|
// possibly reinitialize stuff
|
||||||
|
mp_image_setfmt(image, params->imgfmt);
|
||||||
|
mp_image_set_size(image, params->w, params->h);
|
||||||
|
mp_image_set_display_size(image, params->d_w, params->d_h);
|
||||||
|
}
|
||||||
|
|
||||||
struct mp_image *mp_image_alloc(int imgfmt, int w, int h)
|
struct mp_image *mp_image_alloc(int imgfmt, int w, int h)
|
||||||
{
|
{
|
||||||
struct mp_image *mpi = talloc_zero(NULL, struct mp_image);
|
struct mp_image *mpi = talloc_zero(NULL, struct mp_image);
|
||||||
@ -349,9 +363,9 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src)
|
|||||||
dst->display_h = src->display_h;
|
dst->display_h = src->display_h;
|
||||||
}
|
}
|
||||||
if ((dst->flags & MP_IMGFLAG_YUV) == (src->flags & MP_IMGFLAG_YUV)) {
|
if ((dst->flags & MP_IMGFLAG_YUV) == (src->flags & MP_IMGFLAG_YUV)) {
|
||||||
dst->colorspace = src->colorspace;
|
dst->params.colorspace = src->params.colorspace;
|
||||||
dst->levels = src->levels;
|
dst->params.colorlevels = src->params.colorlevels;
|
||||||
dst->chroma_location = src->chroma_location;
|
dst->params.chroma_location = src->params.chroma_location;
|
||||||
}
|
}
|
||||||
if ((dst->fmt.flags & MP_IMGFLAG_PAL) && (src->fmt.flags & MP_IMGFLAG_PAL)) {
|
if ((dst->fmt.flags & MP_IMGFLAG_PAL) && (src->fmt.flags & MP_IMGFLAG_PAL)) {
|
||||||
if (dst->planes[1] && src->planes[1])
|
if (dst->planes[1] && src->planes[1])
|
||||||
@ -446,28 +460,7 @@ bool mp_image_params_equals(const struct mp_image_params *p1,
|
|||||||
void mp_image_params_from_image(struct mp_image_params *params,
|
void mp_image_params_from_image(struct mp_image_params *params,
|
||||||
const struct mp_image *image)
|
const struct mp_image *image)
|
||||||
{
|
{
|
||||||
// (Ideally mp_image should use mp_image_params directly instead)
|
*params = image->params;
|
||||||
*params = (struct mp_image_params) {
|
|
||||||
.imgfmt = image->imgfmt,
|
|
||||||
.w = image->w,
|
|
||||||
.h = image->h,
|
|
||||||
.d_w = image->display_w,
|
|
||||||
.d_h = image->display_h,
|
|
||||||
.colorspace = image->colorspace,
|
|
||||||
.colorlevels = image->levels,
|
|
||||||
.chroma_location = image->chroma_location,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void mp_image_set_params(struct mp_image *image,
|
|
||||||
const struct mp_image_params *params)
|
|
||||||
{
|
|
||||||
mp_image_setfmt(image, params->imgfmt);
|
|
||||||
mp_image_set_size(image, params->w, params->h);
|
|
||||||
mp_image_set_display_size(image, params->d_w, params->d_h);
|
|
||||||
image->colorspace = params->colorspace;
|
|
||||||
image->levels = params->colorlevels;
|
|
||||||
image->chroma_location = params->chroma_location;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set most image parameters, but not image format or size.
|
// Set most image parameters, but not image format or size.
|
||||||
@ -490,18 +483,6 @@ void mp_image_set_attributes(struct mp_image *image,
|
|||||||
mp_image_set_params(image, &nparams);
|
mp_image_set_params(image, &nparams);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_image_set_colorspace_details(struct mp_image *image,
|
|
||||||
struct mp_csp_details *csp)
|
|
||||||
{
|
|
||||||
struct mp_image_params params;
|
|
||||||
mp_image_params_from_image(¶ms, image);
|
|
||||||
params.colorspace = csp->format;
|
|
||||||
params.colorlevels = csp->levels_in;
|
|
||||||
mp_image_params_guess_csp(¶ms);
|
|
||||||
image->colorspace = params.colorspace;
|
|
||||||
image->levels = params.colorlevels;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If details like params->colorspace/colorlevels are missing, guess them from
|
// If details like params->colorspace/colorlevels are missing, guess them from
|
||||||
// the other settings. Also, even if they are set, make them consistent with
|
// the other settings. Also, even if they are set, make them consistent with
|
||||||
// the colorspace as implied by the pixel format.
|
// the colorspace as implied by the pixel format.
|
||||||
@ -592,8 +573,8 @@ void mp_image_copy_fields_to_av_frame(struct AVFrame *dst,
|
|||||||
dst->repeat_pict = 1;
|
dst->repeat_pict = 1;
|
||||||
|
|
||||||
#if HAVE_AVFRAME_COLORSPACE
|
#if HAVE_AVFRAME_COLORSPACE
|
||||||
dst->colorspace = mp_csp_to_avcol_spc(src->colorspace);
|
dst->colorspace = mp_csp_to_avcol_spc(src->params.colorspace);
|
||||||
dst->color_range = mp_csp_levels_to_avcol_range(src->levels);
|
dst->color_range = mp_csp_levels_to_avcol_range(src->params.colorlevels);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,9 +72,11 @@ struct mp_image_params {
|
|||||||
*/
|
*/
|
||||||
typedef struct mp_image {
|
typedef struct mp_image {
|
||||||
unsigned int flags; // same as fmt.flags
|
unsigned int flags; // same as fmt.flags
|
||||||
struct mp_imgfmt_desc fmt;
|
|
||||||
|
|
||||||
// fields redundant to fmt, for convenience or compatibility
|
struct mp_image_params params;
|
||||||
|
|
||||||
|
// fields redundant to params.imgfmt, for convenience or compatibility
|
||||||
|
struct mp_imgfmt_desc fmt;
|
||||||
enum mp_imgfmt imgfmt;
|
enum mp_imgfmt imgfmt;
|
||||||
int num_planes;
|
int num_planes;
|
||||||
int chroma_x_shift; // horizontal
|
int chroma_x_shift; // horizontal
|
||||||
@ -97,10 +99,6 @@ typedef struct mp_image {
|
|||||||
int plane_w[MP_MAX_PLANES];
|
int plane_w[MP_MAX_PLANES];
|
||||||
int plane_h[MP_MAX_PLANES];
|
int plane_h[MP_MAX_PLANES];
|
||||||
|
|
||||||
enum mp_csp colorspace;
|
|
||||||
enum mp_csp_levels levels;
|
|
||||||
enum mp_chroma_location chroma_location;
|
|
||||||
|
|
||||||
/* only inside filter chain */
|
/* only inside filter chain */
|
||||||
double pts;
|
double pts;
|
||||||
/* memory management */
|
/* memory management */
|
||||||
@ -139,10 +137,6 @@ struct mp_image *mp_image_new_external_ref(struct mp_image *img, void *arg,
|
|||||||
bool (*is_unique)(void *arg),
|
bool (*is_unique)(void *arg),
|
||||||
void (*free)(void *arg));
|
void (*free)(void *arg));
|
||||||
|
|
||||||
struct mp_csp_details;
|
|
||||||
void mp_image_set_colorspace_details(struct mp_image *image,
|
|
||||||
struct mp_csp_details *csp);
|
|
||||||
|
|
||||||
void mp_image_params_guess_csp(struct mp_image_params *params);
|
void mp_image_params_guess_csp(struct mp_image_params *params);
|
||||||
|
|
||||||
bool mp_image_params_equals(const struct mp_image_params *p1,
|
bool mp_image_params_equals(const struct mp_image_params *p1,
|
||||||
|
@ -114,7 +114,7 @@ static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image,
|
|||||||
|
|
||||||
status = vaCopySurfaceGLX(p->display, p->vaglx_surface,
|
status = vaCopySurfaceGLX(p->display, p->vaglx_surface,
|
||||||
va_surface_id(hw_image),
|
va_surface_id(hw_image),
|
||||||
va_get_colorspace_flag(hw_image->colorspace));
|
va_get_colorspace_flag(hw_image->params.colorspace));
|
||||||
if (!CHECK_VA_STATUS(p, "vaCopySurfaceGLX()"))
|
if (!CHECK_VA_STATUS(p, "vaCopySurfaceGLX()"))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -1207,8 +1207,9 @@ static struct mp_image *read_output_surface(struct vo *vo,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct mp_image *image = mp_image_alloc(IMGFMT_BGR32, width, height);
|
struct mp_image *image = mp_image_alloc(IMGFMT_BGR32, width, height);
|
||||||
image->colorspace = MP_CSP_RGB;
|
image->params.colorspace = MP_CSP_RGB;
|
||||||
image->levels = vo->params->outputlevels; // hardcoded with conv. matrix
|
// hardcoded with conv. matrix
|
||||||
|
image->params.colorlevels = vo->params->outputlevels;
|
||||||
|
|
||||||
void *dst_planes[] = { image->planes[0] };
|
void *dst_planes[] = { image->planes[0] };
|
||||||
uint32_t dst_pitches[] = { image->stride[0] };
|
uint32_t dst_pitches[] = { image->stride[0] };
|
||||||
|
Loading…
Reference in New Issue
Block a user