if (_opt->apply_crop) {
size_after_crop = _fs->cropped_size (native_size ());
- fs << crop_string (Position (_fs->left_crop, _fs->top_crop), size_after_crop);
+ fs << crop_string (Position (_fs->crop.left, _fs->crop.top), size_after_crop);
} else {
size_after_crop = native_size ();
fs << crop_string (Position (0, 0), size_after_crop);
void
Film::set_left_crop (int c)
{
- if (c == _state.left_crop) {
+ if (c == _state.crop.left) {
return;
}
- _state.left_crop = c;
- signal_changed (LEFT_CROP);
+ _state.crop.left = c;
+ signal_changed (CROP);
}
/** Set the number of pixels by which to crop the right of the source video */
void
Film::set_right_crop (int c)
{
- if (c == _state.right_crop) {
+ if (c == _state.crop.right) {
return;
}
- _state.right_crop = c;
- signal_changed (RIGHT_CROP);
+ _state.crop.right = c;
+ signal_changed (CROP);
}
/** Set the number of pixels by which to crop the top of the source video */
void
Film::set_top_crop (int c)
{
- if (c == _state.top_crop) {
+ if (c == _state.crop.top) {
return;
}
- _state.top_crop = c;
- signal_changed (TOP_CROP);
+ _state.crop.top = c;
+ signal_changed (CROP);
}
/** Set the number of pixels by which to crop the bottom of the source video */
void
Film::set_bottom_crop (int c)
{
- if (c == _state.bottom_crop) {
+ if (c == _state.crop.bottom) {
return;
}
- _state.bottom_crop = c;
- signal_changed (BOTTOM_CROP);
+ _state.crop.bottom = c;
+ signal_changed (CROP);
}
/** Set the filters to apply to the image when generating thumbnails
stringstream s;
s << _state.format->id()
<< "_" << _state.content_digest
- << "_" << left_crop() << "_" << right_crop() << "_" << top_crop() << "_" << bottom_crop()
+ << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
<< "_" << f.first << "_" << f.second
<< "_" << _state.scaler->id();
return _state.name;
}
- /** @return number of pixels to crop from the top of the original picture */
- int top_crop () const {
- return _state.top_crop;
- }
-
- /** @return number of pixels to crop from the bottom of the original picture */
- int bottom_crop () const {
- return _state.bottom_crop;
- }
-
- /** @return number of pixels to crop from the left-hand side of the original picture */
- int left_crop () const {
- return _state.left_crop;
- }
-
- /** @return number of pixels to crop from the right-hand side of the original picture */
- int right_crop () const {
- return _state.right_crop;
+ /** @return number of pixels to crop from the sides of the original picture */
+ Crop crop () const {
+ return _state.crop;
}
/** @return the format to present this film in (flat, scope, etc.) */
CONTENT,
DCP_CONTENT_TYPE,
FORMAT,
- LEFT_CROP,
- RIGHT_CROP,
- TOP_CROP,
- BOTTOM_CROP,
+ CROP,
FILTERS,
SCALER,
DCP_FRAMES,
if (format) {
f << "format " << format->as_metadata () << "\n";
}
- f << "left_crop " << left_crop << "\n";
- f << "right_crop " << right_crop << "\n";
- f << "top_crop " << top_crop << "\n";
- f << "bottom_crop " << bottom_crop << "\n";
+ f << "left_crop " << crop.left << "\n";
+ f << "right_crop " << crop.right << "\n";
+ f << "top_crop " << crop.top << "\n";
+ f << "bottom_crop " << crop.bottom << "\n";
for (vector<Filter const *>::const_iterator i = filters.begin(); i != filters.end(); ++i) {
f << "filter " << (*i)->id () << "\n";
}
} else if (k == "format") {
format = Format::from_metadata (v);
} else if (k == "left_crop") {
- left_crop = atoi (v.c_str ());
+ crop.left = atoi (v.c_str ());
} else if (k == "right_crop") {
- right_crop = atoi (v.c_str ());
+ crop.right = atoi (v.c_str ());
} else if (k == "top_crop") {
- top_crop = atoi (v.c_str ());
+ crop.top = atoi (v.c_str ());
} else if (k == "bottom_crop") {
- bottom_crop = atoi (v.c_str ());
+ crop.bottom = atoi (v.c_str ());
} else if (k == "filter") {
filters.push_back (Filter::from_id (v));
} else if (k == "scaler") {
Size
FilmState::cropped_size (Size s) const
{
- s.width -= left_crop + right_crop;
- s.height -= top_crop + bottom_crop;
+ s.width -= crop.left + crop.right;
+ s.height -= crop.top + crop.bottom;
return s;
}
: dcp_content_type (0)
, frames_per_second (0)
, format (0)
- , left_crop (0)
- , right_crop (0)
- , top_crop (0)
- , bottom_crop (0)
, scaler (Scaler::from_id ("bicubic"))
, dcp_frames (0)
, dcp_trim_action (CUT)
float frames_per_second;
/** The format to present this Film in (flat, scope, etc.) */
Format const * format;
- /** Number of pixels to crop from the left-hand side of the original picture */
- int left_crop;
- /** Number of pixels to crop from the right-hand side of the original picture */
- int right_crop;
- /** Number of pixels to crop from the top of the original picture */
- int top_crop;
- /** Number of pixels to crop from the bottom of the original picture */
- int bottom_crop;
+ Crop crop;
/** Video filters that should be used when generating DCPs */
std::vector<Filter const *> filters;
/** Scaler algorithm to use */
return 96000;
}
+
+bool operator== (Crop const & a, Crop const & b)
+{
+ return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom);
+}
+
+bool operator!= (Crop const & a, Crop const & b)
+{
+ return !(a == b);
+}
int height;
};
+struct Crop
+{
+ Crop () : left (0), right (0), top (0), bottom (0) {}
+
+ int left;
+ int right;
+ int top;
+ int bottom;
+};
+
+extern bool operator== (Crop const & a, Crop const & b);
+extern bool operator!= (Crop const & a, Crop const & b);
+
struct Position
{
Position ()
return;
}
- _ignore_changes = Film::LEFT_CROP;
+ _ignore_changes = Film::CROP;
_film->set_left_crop (_left_crop->GetValue ());
_ignore_changes = Film::NONE;
}
return;
}
- _ignore_changes = Film::RIGHT_CROP;
+ _ignore_changes = Film::CROP;
_film->set_right_crop (_right_crop->GetValue ());
_ignore_changes = Film::NONE;
}
return;
}
- _ignore_changes = Film::TOP_CROP;
+ _ignore_changes = Film::CROP;
_film->set_top_crop (_top_crop->GetValue ());
_ignore_changes = Film::NONE;
}
return;
}
- _ignore_changes = Film::BOTTOM_CROP;
+ _ignore_changes = Film::CROP;
_film->set_bottom_crop (_bottom_crop->GetValue ());
_ignore_changes = Film::NONE;
}
case Film::FORMAT:
_format->SetSelection (Format::as_index (_film->format ()));
break;
- case Film::LEFT_CROP:
- _left_crop->SetValue (_film->left_crop ());
- break;
- case Film::RIGHT_CROP:
- _right_crop->SetValue (_film->right_crop ());
- break;
- case Film::TOP_CROP:
- _top_crop->SetValue (_film->top_crop ());
- break;
- case Film::BOTTOM_CROP:
- _bottom_crop->SetValue (_film->bottom_crop ());
+ case Film::CROP:
+ _left_crop->SetValue (_film->crop().left);
+ _right_crop->SetValue (_film->crop().right);
+ _top_crop->SetValue (_film->crop().top);
+ _bottom_crop->SetValue (_film->crop().bottom);
break;
case Film::FILTERS:
{
film_changed (Film::CONTENT);
film_changed (Film::DCP_CONTENT_TYPE);
film_changed (Film::FORMAT);
- film_changed (Film::LEFT_CROP);
- film_changed (Film::RIGHT_CROP);
- film_changed (Film::TOP_CROP);
- film_changed (Film::BOTTOM_CROP);
+ film_changed (Film::CROP);
film_changed (Film::FILTERS);
film_changed (Film::DCP_FRAMES);
film_changed (Film::DCP_TRIM_ACTION);
, _film (film)
, _image (0)
, _bitmap (0)
- , _left_crop (0)
- , _right_crop (0)
- , _top_crop (0)
- , _bottom_crop (0)
{
}
_current_image = _pending_image;
setup ();
}
-
+
+ if (_current_crop != _pending_crop) {
+ _current_crop = _pending_crop;
+ setup ();
+ }
+
wxPaintDC dc (this);
if (_bitmap) {
dc.DrawBitmap (*_bitmap, 0, 0, false);
}
setup ();
+ Refresh ();
}
void set (string f)
Refresh ();
}
- void set_crop (int l, int r, int t, int b)
+ void set_crop (Crop c)
{
- _left_crop = l;
- _right_crop = r;
- _top_crop = t;
- _bottom_crop = b;
- setup ();
+ _pending_crop = c;
+ Refresh ();
}
void set_film (Film* f)
_film = f;
if (!_film) {
clear ();
+ Refresh ();
} else {
setup ();
+ Refresh ();
}
}
float const target = _film->format() ? _film->format()->ratio_as_float () : 1.78;
_cropped_image = _image->GetSubImage (
- wxRect (_left_crop, _top_crop, _image->GetWidth() - (_left_crop + _right_crop), _image->GetHeight() - (_top_crop + _bottom_crop))
+ wxRect (
+ _current_crop.left,
+ _current_crop.top,
+ _image->GetWidth() - (_current_crop.left + _current_crop.right),
+ _image->GetHeight() - (_current_crop.top + _current_crop.bottom)
+ )
);
if ((float (vw) / vh) > target) {
delete _bitmap;
_bitmap = new wxBitmap (_cropped_image);
-
- Refresh ();
}
Film* _film;
std::string _pending_image;
wxImage _cropped_image;
wxBitmap* _bitmap;
- int _left_crop;
- int _right_crop;
- int _top_crop;
- int _bottom_crop;
+ Crop _current_crop;
+ Crop _pending_crop;
};
BEGIN_EVENT_TABLE (ThumbPanel, wxPanel)
void
FilmViewer::film_changed (Film::Property p)
{
- if (p == Film::LEFT_CROP || p == Film::RIGHT_CROP || p == Film::TOP_CROP || p == Film::BOTTOM_CROP) {
- _thumb_panel->set_crop (_film->left_crop(), _film->right_crop(), _film->top_crop(), _film->bottom_crop ());
+ if (p == Film::CROP) {
+ _thumb_panel->set_crop (_film->crop ());
} else if (p == Film::THUMBS) {
if (_film && _film->num_thumbs() > 1) {
_slider->SetRange (0, _film->num_thumbs () - 1);
BOOST_CHECK_EQUAL (g.name(), "fred");
BOOST_CHECK_EQUAL (g.dcp_content_type(), DCPContentType::from_pretty_name ("Short"));
BOOST_CHECK_EQUAL (g.format(), Format::from_nickname ("Flat"));
- BOOST_CHECK_EQUAL (g.left_crop(), 1);
- BOOST_CHECK_EQUAL (g.right_crop(), 2);
- BOOST_CHECK_EQUAL (g.top_crop(), 3);
- BOOST_CHECK_EQUAL (g.bottom_crop(), 4);
+ BOOST_CHECK_EQUAL (g.crop().left, 1);
+ BOOST_CHECK_EQUAL (g.crop().right, 2);
+ BOOST_CHECK_EQUAL (g.crop().top, 3);
+ BOOST_CHECK_EQUAL (g.crop().bottom, 4);
vector<Filter const *> g_filters = g.filters ();
BOOST_CHECK_EQUAL (g_filters.size(), 2);
BOOST_CHECK_EQUAL (g_filters.front(), Filter::from_id ("pphb"));