~ubuntu-branches/ubuntu/wily/aegisub/wily-proposed

« back to all changes in this revision

Viewing changes to src/dialog_video_properties.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel, Pascal De Vuyst, Juan Picca, Sebastian Reichel
  • Date: 2015-08-04 21:40:50 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150804214050-y2aghm9vdksoc8t7
Tags: 3.2.2+dfsg-1
[ Pascal De Vuyst ]
* Fix Typo in package description (Closes: #739219)

[ Juan Picca ]
* Add patch to fix reproducible build (Closes: #789728)

[ Sebastian Reichel ]
* New upstream release
 - remove vendor directory from orig tarball
* Update Debian Standards Version to 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2014, Thomas Goyne <plorkyeran@aegisub.org>
 
2
//
 
3
// Permission to use, copy, modify, and distribute this software for any
 
4
// purpose with or without fee is hereby granted, provided that the above
 
5
// copyright notice and this permission notice appear in all copies.
 
6
//
 
7
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
8
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
9
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 
10
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
11
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 
12
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 
13
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
14
//
 
15
// Aegisub Project http://www.aegisub.org/
 
16
 
 
17
#include "ass_file.h"
 
18
#include "async_video_provider.h"
 
19
#include "format.h"
 
20
#include "help_button.h"
 
21
#include "options.h"
 
22
#include "resolution_resampler.h"
 
23
 
 
24
#include <wx/dialog.h>
 
25
#include <wx/intl.h>
 
26
#include <wx/radiobox.h>
 
27
#include <wx/sizer.h>
 
28
#include <wx/stattext.h>
 
29
 
 
30
namespace {
 
31
enum {
 
32
        MISMATCH_IGNORE,
 
33
        MISMATCH_PROMPT,
 
34
        MISMATCH_RESAMPLE,
 
35
        MISMATCH_SET
 
36
};
 
37
enum {
 
38
        FIX_IGNORE,
 
39
        FIX_SET,
 
40
        FIX_RESAMPLE
 
41
};
 
42
 
 
43
int prompt(wxWindow *parent, bool ar_changed, int sx, int sy, int vx, int vy) {
 
44
        wxDialog d(parent, -1, _("Resolution mismatch"));
 
45
 
 
46
        auto label_text = fmt_tl("The resolution of the loaded video and the resolution specified for the subtitles don't match.\n\nVideo resolution:\t%d x %d\nScript resolution:\t%d x %d\n\nChange subtitles resolution to match video?", vx, vy, sx, sy);
 
47
 
 
48
        auto sizer = new wxBoxSizer(wxVERTICAL);
 
49
        sizer->Add(new wxStaticText(&d, -1, label_text), wxSizerFlags().Border());
 
50
 
 
51
        wxRadioBox *rb;
 
52
        if (ar_changed) {
 
53
                wxString choices[] = {
 
54
                        _("Set to video resolution"),
 
55
                        _("Resample script (stretch to new aspect ratio)"),
 
56
                        _("Resample script (add borders)"),
 
57
                        _("Resample script (remove borders)")
 
58
                };
 
59
                rb = new wxRadioBox(&d, -1, "", wxDefaultPosition, wxDefaultSize, 4, choices, 1);
 
60
        }
 
61
        else {
 
62
                wxString choices[] = {
 
63
                        _("Set to video resolution"),
 
64
                        _("Resample script"),
 
65
                };
 
66
                rb = new wxRadioBox(&d, -1, "", wxDefaultPosition, wxDefaultSize, 2, choices, 1);
 
67
        }
 
68
        sizer->Add(rb, wxSizerFlags().Border(wxALL & ~wxTOP).Expand());
 
69
        sizer->Add(d.CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP), wxSizerFlags().Border().Expand());
 
70
 
 
71
        unsigned int sel = OPT_GET("Video/Last Script Resolution Mismatch Choice")->GetInt();
 
72
        rb->SetSelection(std::min(sel - 1, rb->GetCount()));
 
73
 
 
74
        d.SetSizerAndFit(sizer);
 
75
        d.CenterOnParent();
 
76
 
 
77
        d.Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { d.EndModal(rb->GetSelection() + 1); }, wxID_OK);
 
78
        d.Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { d.EndModal(0); }, wxID_CANCEL);
 
79
        d.Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { HelpButton::OpenPage("Resolution mismatch"); }, wxID_HELP);
 
80
 
 
81
        return d.ShowModal();
 
82
}
 
83
 
 
84
bool update_video_properties(AssFile *file, const AsyncVideoProvider *new_provider, wxWindow *parent) {
 
85
        bool commit_subs = false;
 
86
 
 
87
        // When opening dummy video only want to set the script properties if
 
88
        // they were previously unset
 
89
        bool set_properties = new_provider->ShouldSetVideoProperties();
 
90
 
 
91
        auto matrix = new_provider->GetColorSpace();
 
92
        if (set_properties && matrix != file->GetScriptInfo("YCbCr Matrix")) {
 
93
                file->SetScriptInfo("YCbCr Matrix", matrix);
 
94
                commit_subs = true;
 
95
        }
 
96
 
 
97
        // Check that the script resolution matches the video resolution
 
98
        int sx = file->GetScriptInfoAsInt("PlayResX");
 
99
        int sy = file->GetScriptInfoAsInt("PlayResY");
 
100
        int vx = new_provider->GetWidth();
 
101
        int vy = new_provider->GetHeight();
 
102
 
 
103
        // If the script resolution hasn't been set at all just force it to the
 
104
        // video resolution
 
105
        if (sx == 0 && sy == 0) {
 
106
                file->SetScriptInfo("PlayResX", std::to_string(vx));
 
107
                file->SetScriptInfo("PlayResY", std::to_string(vy));
 
108
                return true;
 
109
        }
 
110
 
 
111
        if (!set_properties)
 
112
                return false;
 
113
 
 
114
        // Treat exact multiples of the video resolution as equaling the resolution
 
115
        // for the people who use that for subpixel precision (which is mostly
 
116
        // pointless these days due to decimals being supported almost everywhere)
 
117
        if (sx % vx == 0 && sy % vy == 0)
 
118
                return commit_subs;
 
119
 
 
120
        auto sar = double(sx) / sy;
 
121
        auto var = double(vx) / vy;
 
122
        bool ar_changed = abs(sar - var) / var > .01;
 
123
 
 
124
        switch (OPT_GET("Video/Script Resolution Mismatch")->GetInt()) {
 
125
        case MISMATCH_IGNORE: default:
 
126
                return commit_subs;
 
127
 
 
128
        case MISMATCH_SET:
 
129
                file->SetScriptInfo("PlayResX", std::to_string(vx));
 
130
                file->SetScriptInfo("PlayResY", std::to_string(vy));
 
131
                return true;
 
132
 
 
133
        case MISMATCH_RESAMPLE:
 
134
                // Fallthrough to prompt if the AR changed
 
135
                if (!ar_changed) {
 
136
                        ResampleResolution(file, {
 
137
                                {0, 0, 0, 0},
 
138
                                sx, sy, vx, vy,
 
139
                                ResampleARMode::Stretch,
 
140
                                YCbCrMatrix::rgb, YCbCrMatrix::rgb
 
141
                        });
 
142
                        return true;
 
143
                }
 
144
 
 
145
        case MISMATCH_PROMPT:
 
146
                int res = prompt(parent, ar_changed, sx, sy, vx, vy);
 
147
                if (res == FIX_IGNORE) return commit_subs;
 
148
                OPT_SET("Video/Last Script Resolution Mismatch Choice")->SetInt(res);
 
149
 
 
150
                ResampleResolution(file, {
 
151
                        {0, 0, 0, 0},
 
152
                        sx, sy, vx, vy,
 
153
                        static_cast<ResampleARMode>(res - FIX_RESAMPLE),
 
154
                        YCbCrMatrix::rgb, YCbCrMatrix::rgb
 
155
                });
 
156
                return true;
 
157
        }
 
158
}
 
159
}
 
160
 
 
161
void UpdateVideoProperties(AssFile *file, const AsyncVideoProvider *new_provider, wxWindow *parent) {
 
162
        if (update_video_properties(file, new_provider, parent))
 
163
                file->Commit(_("change script resolution"), AssFile::COMMIT_SCRIPTINFO);
 
164
}