viewer: fixed crop matrix for export dialog
This commit is contained in:
+15
-6
@@ -54,14 +54,14 @@ TexturePtr Renderer::CreateTexture(const VideoParams ¶ms, const void *data,
|
||||
return CreateTexture(params, Texture::k2D, data, linesize);
|
||||
}
|
||||
|
||||
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, Texture *destination, bool clear_destination, const QMatrix4x4 &matrix)
|
||||
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, Texture *destination, bool clear_destination, const QMatrix4x4 &matrix, const QMatrix4x4 &crop_matrix)
|
||||
{
|
||||
BlitColorManagedInternal(color_processor, source, source_is_premultiplied, destination, destination->params(), clear_destination, matrix);
|
||||
BlitColorManagedInternal(color_processor, source, source_is_premultiplied, destination, destination->params(), clear_destination, matrix, crop_matrix);
|
||||
}
|
||||
|
||||
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, VideoParams params, bool clear_destination, const QMatrix4x4& matrix)
|
||||
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, VideoParams params, bool clear_destination, const QMatrix4x4& matrix, const QMatrix4x4 &crop_matrix)
|
||||
{
|
||||
BlitColorManagedInternal(color_processor, source, source_is_premultiplied, nullptr, params, clear_destination, matrix);
|
||||
BlitColorManagedInternal(color_processor, source, source_is_premultiplied, nullptr, params, clear_destination, matrix, crop_matrix);
|
||||
}
|
||||
|
||||
void Renderer::Destroy()
|
||||
@@ -95,6 +95,7 @@ bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::Colo
|
||||
shader_frag.append(QStringLiteral("// Main texture input\n"
|
||||
"uniform sampler2D ove_maintex;\n"
|
||||
"uniform int ove_maintex_alpha;\n"
|
||||
"uniform mat4 ove_cropmatrix;\n"
|
||||
"\n"
|
||||
"// Macros defining `ove_maintex_alpha` state\n"
|
||||
"// Matches `AlphaAssociated` C++ enum\n"
|
||||
@@ -127,7 +128,13 @@ bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::Colo
|
||||
"}\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" vec4 col = texture(ove_maintex, ove_texcoord);\n"
|
||||
" vec2 cropped_coord = (vec4(ove_texcoord-vec2(0.5, 0.5), 0.0, 1.0)*inverse(ove_cropmatrix)).xy + vec2(0.5, 0.5);\n"
|
||||
" if (cropped_coord.x < 0.0 || cropped_coord.x >= 1.0 || cropped_coord.y < 0.0 || cropped_coord.y >= 1.0) {\n"
|
||||
" fragColor = vec4(0.0);\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" vec4 col = texture(ove_maintex, cropped_coord);\n"
|
||||
"\n"
|
||||
" // If alpha is associated, de-associate now\n"
|
||||
" if (ove_maintex_alpha == ALPHA_ASSOC) {\n"
|
||||
@@ -225,7 +232,8 @@ bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::Colo
|
||||
|
||||
void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source,
|
||||
bool source_is_premultiplied, Texture *destination,
|
||||
VideoParams params, bool clear_destination, const QMatrix4x4& matrix)
|
||||
VideoParams params, bool clear_destination, const QMatrix4x4& matrix,
|
||||
const QMatrix4x4& crop_matrix)
|
||||
{
|
||||
ColorContext color_ctx;
|
||||
if (!GetColorContext(color_processor, &color_ctx)) {
|
||||
@@ -236,6 +244,7 @@ void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, Textu
|
||||
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), NodeValue(NodeValue::kTexture, QVariant::fromValue(source)));
|
||||
job.InsertValue(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, matrix));
|
||||
job.InsertValue(QStringLiteral("ove_cropmatrix"), NodeValue(NodeValue::kMatrix, crop_matrix));
|
||||
|
||||
AlphaAssociated associated;
|
||||
if (source->channel_count() == VideoParams::kRGBAChannelCount) {
|
||||
|
||||
@@ -63,8 +63,8 @@ public:
|
||||
Blit(shader, job, nullptr, params, clear_destination);
|
||||
}
|
||||
|
||||
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, Texture* destination, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4());
|
||||
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, VideoParams params, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4());
|
||||
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, Texture* destination, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4());
|
||||
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, bool source_is_premultiplied, VideoParams params, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4());
|
||||
|
||||
void Destroy();
|
||||
|
||||
@@ -122,7 +122,7 @@ private:
|
||||
void BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source,
|
||||
bool source_is_premultiplied,
|
||||
Texture* destination, VideoParams params, bool clear_destination,
|
||||
const QMatrix4x4 &matrix);
|
||||
const QMatrix4x4 &matrix, const QMatrix4x4 &crop_matrix);
|
||||
|
||||
QHash<QString, ColorContext> color_cache_;
|
||||
|
||||
|
||||
@@ -301,9 +301,9 @@ void ViewerWidget::SetColorMenuEnabled(bool enabled)
|
||||
|
||||
void ViewerWidget::SetMatrix(const QMatrix4x4 &mat)
|
||||
{
|
||||
display_widget_->SetMatrixZoom(mat);
|
||||
display_widget_->SetMatrixCrop(mat);
|
||||
foreach (ViewerWindow* vw, windows_) {
|
||||
vw->display_widget()->SetMatrixZoom(mat);
|
||||
vw->display_widget()->SetMatrixCrop(mat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,13 @@ void ViewerDisplayWidget::SetMatrixZoom(const QMatrix4x4 &mat)
|
||||
UpdateMatrix();
|
||||
}
|
||||
|
||||
void ViewerDisplayWidget::SetMatrixCrop(const QMatrix4x4 &mat)
|
||||
{
|
||||
crop_matrix_ = mat;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ViewerDisplayWidget::UpdateCursor()
|
||||
{
|
||||
if (Core::instance()->tool() == Tool::kHand) {
|
||||
@@ -355,11 +362,9 @@ void ViewerDisplayWidget::OnPaint()
|
||||
VideoParams device_params(device_width, device_height, device_format, VideoParams::kInternalChannelCount);
|
||||
|
||||
renderer()->BlitColorManaged(color_service(), texture_to_draw, true, device_params, false,
|
||||
combined_matrix_flipped_);
|
||||
combined_matrix_flipped_, crop_matrix_);
|
||||
}
|
||||
|
||||
QTransform world_transform = GenerateWorldTransform();
|
||||
|
||||
// Draw gizmos if we have any
|
||||
if (gizmos_) {
|
||||
NodeTraverser gt;
|
||||
@@ -378,7 +383,7 @@ void ViewerDisplayWidget::OnPaint()
|
||||
// Draw action/title safe areas
|
||||
if (safe_margin_.is_enabled()) {
|
||||
QPainter p(inner_widget());
|
||||
p.setWorldTransform(world_transform);
|
||||
p.setWorldTransform(GenerateWorldTransform());
|
||||
|
||||
p.setPen(Qt::lightGray);
|
||||
p.setBrush(Qt::NoBrush);
|
||||
|
||||
@@ -115,6 +115,8 @@ public slots:
|
||||
*/
|
||||
void SetMatrixZoom(const QMatrix4x4& mat);
|
||||
|
||||
void SetMatrixCrop(const QMatrix4x4& mat);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables whether this color at the cursor should be emitted
|
||||
*
|
||||
@@ -257,6 +259,11 @@ private:
|
||||
*/
|
||||
QMatrix4x4 scale_matrix_;
|
||||
|
||||
/**
|
||||
* @brief Crop only matrix
|
||||
*/
|
||||
QMatrix4x4 crop_matrix_;
|
||||
|
||||
/**
|
||||
* @brief Cached result of translate_matrix_ and scale_matrix_ multiplied
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user