-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix various aspect ratio issues with qtblend filter/transition #1064
Open
j-b-m
wants to merge
1
commit into
mltframework:master
Choose a base branch
from
j-b-m:work/qtblend-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* filter_lightshow.cpp -- animate color to the audio | ||
* filter_qtblend.cpp -- Qt composite filter | ||
* Copyright (C) 2015 Meltytech, LLC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to update the copyright date in all of these files that are changed. |
||
* | ||
* This library is free software; you can redistribute it and/or | ||
|
@@ -66,19 +66,22 @@ static int filter_get_image(mlt_frame frame, | |
1.0}; | ||
int b_width = mlt_properties_get_int(frame_properties, "meta.media.width"); | ||
int b_height = mlt_properties_get_int(frame_properties, "meta.media.height"); | ||
bool distort = mlt_properties_get_int(properties, "distort"); | ||
|
||
if (b_height == 0) { | ||
b_width = normalized_width; | ||
b_height = normalized_height; | ||
} | ||
// Special case - aspect_ratio = 0 | ||
if (mlt_frame_get_aspect_ratio(frame) == 0) { | ||
double output_ar = mlt_profile_sar(profile); | ||
mlt_frame_set_aspect_ratio(frame, output_ar); | ||
mlt_frame_set_aspect_ratio(frame, consumer_ar); | ||
} | ||
double b_ar = mlt_frame_get_aspect_ratio(frame); | ||
double b_dar = b_ar * b_width / b_height; | ||
double opacity = 1.0; | ||
|
||
// If the _qtblend_scaled property is defined, a qtblend filter was already applied | ||
int qtblendRescaled = mlt_properties_get_int(frame_properties, "_qtblend_scaled"); | ||
if (mlt_properties_get(properties, "rect")) { | ||
rect = mlt_properties_anim_get_rect(properties, "rect", position, length); | ||
if (::strchr(mlt_properties_get(properties, "rect"), '%')) { | ||
|
@@ -87,30 +90,81 @@ static int filter_get_image(mlt_frame frame, | |
rect.w *= normalized_width; | ||
rect.h *= normalized_height; | ||
} | ||
double scale = mlt_profile_scale_width(profile, *width); | ||
if (scale != 1.0) { | ||
rect.x *= scale; | ||
rect.w *= scale; | ||
} | ||
scale = mlt_profile_scale_height(profile, *height); | ||
if (scale != 1.0) { | ||
rect.y *= scale; | ||
rect.h *= scale; | ||
} | ||
transform.translate(rect.x, rect.y); | ||
opacity = rect.o; | ||
hasAlpha = rect.o < 1 || rect.x != 0 || rect.y != 0 || rect.w != *width | ||
|| rect.h != *height; | ||
if (qtblendRescaled) { | ||
// Another qtblend filter was already applied | ||
// In this case, the *width and *height are set to the source resolution to ensure we don't lose too much details on multiple scaling operations | ||
// We requested a image with full media resolution, adjust rect to profile | ||
// Check if we have consumer scaling enabled since we cannot use *width and *height | ||
double consumerScale = mlt_properties_get_double(frame_properties, "_qtblend_scalex"); | ||
if (consumerScale > 0.) { | ||
b_width *= consumerScale; | ||
b_height *= consumerScale; | ||
} | ||
|
||
if (mlt_properties_get_int(properties, "distort") == 0) { | ||
b_height = qMax(1, qMin(qRound(rect.h), b_height)); | ||
b_width = qMax(1, qRound(b_height * b_dar / b_ar / consumer_ar)); | ||
// Always request an image that follows the consumer aspect ratio | ||
double consumer_dar = normalized_width * consumer_ar / normalized_height; | ||
int tmpWidth = b_width; | ||
int tmpHeight = b_height; | ||
double scaleFactor = qMax(*width / rect.w, *height / rect.h); | ||
if (scaleFactor > 1.) { | ||
// Use the highest necessary resolution image | ||
tmpWidth *= scaleFactor; | ||
tmpHeight *= scaleFactor; | ||
} | ||
if (consumer_dar > b_dar) { | ||
*width = qBound(qRound(normalized_width * consumerScale), | ||
tmpWidth, | ||
MLT_QTBLEND_MAX_DIMENSION); | ||
*height = qRound(*width * consumer_ar * normalized_height / normalized_width); | ||
} else { | ||
*height = qBound(qRound(normalized_height * consumerScale), | ||
tmpHeight, | ||
MLT_QTBLEND_MAX_DIMENSION); | ||
*width = qRound(*height * normalized_width / normalized_height / consumer_ar); | ||
} | ||
// Adjust rect to new scaling | ||
double scale = (double) *width / normalized_width; | ||
if (scale != 1.0) { | ||
rect.x *= scale; | ||
rect.w *= scale; | ||
} | ||
scale = (double) *height / normalized_height; | ||
if (scale != 1.0) { | ||
rect.y *= scale; | ||
rect.h *= scale; | ||
} | ||
} else { | ||
b_width = qMax(1, qRound(b_width * b_ar / consumer_ar)); | ||
} | ||
if (!hasAlpha && (b_width < *width || b_height < *height)) { | ||
hasAlpha = true; | ||
// First instance of a qtblend filter | ||
double scale = mlt_profile_scale_width(profile, *width); | ||
// Store consumer scaling for further uses | ||
mlt_properties_set_int(frame_properties, "_qtblend_scaled", 1); | ||
mlt_properties_set_double(frame_properties, "_qtblend_scalex", scale); | ||
// Apply scaling | ||
if (scale != 1.0) { | ||
rect.x *= scale; | ||
rect.w *= scale; | ||
if (distort) { | ||
b_width *= scale; | ||
} else { | ||
// Apply consumer scaling to the source image request | ||
b_width *= scale; | ||
b_height *= scale; | ||
} | ||
} | ||
scale = mlt_profile_scale_height(profile, *height); | ||
if (scale != 1.0) { | ||
rect.y *= scale; | ||
rect.h *= scale; | ||
if (distort) { | ||
b_height *= scale; | ||
} | ||
} | ||
} | ||
transform.translate(rect.x, rect.y); | ||
opacity = rect.o; | ||
hasAlpha = rect.o < 1 || rect.x != 0 || rect.y != 0 || rect.w != *width || rect.h != *height | ||
|| rect.w / b_dar < *height || rect.h * b_dar < *width || b_width < *width | ||
|| b_height < *height; | ||
} else { | ||
b_width = *width; | ||
b_height = *height; | ||
|
@@ -154,7 +208,6 @@ static int filter_get_image(mlt_frame frame, | |
// fetch image | ||
*format = mlt_image_rgba; | ||
uint8_t *src_image = NULL; | ||
|
||
error = mlt_frame_get_image(frame, &src_image, format, &b_width, &b_height, 0); | ||
|
||
// Put source buffer into QImage | ||
|
@@ -164,13 +217,12 @@ static int filter_get_image(mlt_frame frame, | |
int image_size = mlt_image_format_size(*format, *width, *height, NULL); | ||
|
||
// resize to rect | ||
if (mlt_properties_get_int(properties, "distort")) { | ||
if (distort) { | ||
transform.scale(rect.w / b_width, rect.h / b_height); | ||
} else { | ||
// Determine scale with respect to aspect ratio. | ||
double geometry_dar = rect.w * consumer_ar / rect.h; | ||
double scale; | ||
if (b_dar > geometry_dar) { | ||
double resize_dar = rect.w * consumer_ar / rect.h; | ||
if (b_dar >= resize_dar) { | ||
scale = rect.w / b_width; | ||
} else { | ||
scale = rect.h / b_height * b_ar; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this defined here if it is only used in filter_qtblend.cpp