forked from mia/Aegisub
Fix some issues with resampling drawings
The X scale/offset was being used for both X and Y coordinates. Only non-negative integers were supported. xy-VSFilter and libass both now support non-integer coordinates, and negative coordinates have of course always been valid. Resampled coordinates are now rounded to eighth-pixels rather than whole pixels.
This commit is contained in:
parent
13d31d17ef
commit
52d67accb4
4 changed files with 21 additions and 12 deletions
|
@ -21,9 +21,11 @@
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <libaegisub/of_type_adaptor.h>
|
#include <libaegisub/of_type_adaptor.h>
|
||||||
#include <libaegisub/split.h>
|
#include <libaegisub/split.h>
|
||||||
|
#include <libaegisub/util.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
@ -44,14 +46,16 @@ namespace {
|
||||||
final.reserve(drawing.size());
|
final.reserve(drawing.size());
|
||||||
|
|
||||||
for (auto const& cur : agi::Split(drawing, ' ')) {
|
for (auto const& cur : agi::Split(drawing, ' ')) {
|
||||||
if (std::all_of(begin(cur), end(cur), isdigit)) {
|
double val;
|
||||||
int val = boost::lexical_cast<int>(agi::str(cur));
|
if (agi::util::try_parse(agi::str(cur), &val)) {
|
||||||
if (is_x)
|
if (is_x)
|
||||||
val = (int)((val + shift_x) * scale_x + .5);
|
val = (val + shift_x) * scale_x;
|
||||||
else
|
else
|
||||||
val = (int)((val + shift_y) * scale_y + .5);
|
val = (val + shift_y) * scale_y;
|
||||||
final += std::to_string(val);
|
val = int(val * 8 + .5) / 8.0; // round to eighth-pixels
|
||||||
|
final += float_to_string(val);
|
||||||
final += ' ';
|
final += ' ';
|
||||||
|
is_x = !is_x;
|
||||||
}
|
}
|
||||||
else if (cur.size() == 1) {
|
else if (cur.size() == 1) {
|
||||||
char c = tolower(cur[0]);
|
char c = tolower(cur[0]);
|
||||||
|
|
|
@ -86,6 +86,14 @@ wxString PrettySize(int bytes) {
|
||||||
return wxString::Format(fmt, size) + " " + suffix[i];
|
return wxString::Format(fmt, size) + " " + suffix[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string float_to_string(double val) {
|
||||||
|
std::string s = str(boost::format("%.3f") % val);
|
||||||
|
size_t pos = s.find_last_not_of("0");
|
||||||
|
if (pos != s.find(".")) ++pos;
|
||||||
|
s.erase(begin(s) + pos, end(s));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void StatusTimeout(wxString const& msg, int ms) {
|
void StatusTimeout(wxString const& msg, int ms) {
|
||||||
wxGetApp().frame->StatusTimeout(msg, ms);
|
wxGetApp().frame->StatusTimeout(msg, ms);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ class wxWindow;
|
||||||
|
|
||||||
wxString PrettySize(int bytes);
|
wxString PrettySize(int bytes);
|
||||||
|
|
||||||
|
std::string float_to_string(double val);
|
||||||
|
|
||||||
void StatusTimeout(wxString const& msg, int ms = 10000);
|
void StatusTimeout(wxString const& msg, int ms = 10000);
|
||||||
|
|
||||||
/// @brief Get the smallest power of two that is greater or equal to x
|
/// @brief Get the smallest power of two that is greater or equal to x
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
#include "vector2d.h"
|
#include "vector2d.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
@ -86,13 +88,6 @@ std::string Vector2D::DStr(char sep) const {
|
||||||
return str(boost::format("%d%c%d") % (int)x % sep % (int)y);
|
return str(boost::format("%d%c%d") % (int)x % sep % (int)y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string float_to_string(float val) {
|
|
||||||
std::string s = str(boost::format("%.3f") % val);
|
|
||||||
size_t pos = s.find_last_not_of("0");
|
|
||||||
if (pos != s.find(".")) ++pos;
|
|
||||||
return s.substr(0, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Vector2D::Str(char sep) const {
|
std::string Vector2D::Str(char sep) const {
|
||||||
return float_to_string(x) + sep + float_to_string(y);
|
return float_to_string(x) + sep + float_to_string(y);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue