_resolution = Resolution (node->optional_number_child<int>("Resolution").get_value_or (RESOLUTION_2K));
}
-/** J2K-encode this frame on the local host.
- * @return Encoded data.
- */
-Data
-DCPVideo::encode_locally (dcp::NoteHandler note)
+shared_ptr<dcp::OpenJPEGImage>
+DCPVideo::convert_to_xyz (shared_ptr<const PlayerVideo> frame, dcp::NoteHandler note)
{
shared_ptr<dcp::OpenJPEGImage> xyz;
- shared_ptr<Image> image = _frame->image (AV_PIX_FMT_RGB48LE, note);
- if (_frame->colour_conversion()) {
+ shared_ptr<Image> image = frame->image (AV_PIX_FMT_RGB48LE, note);
+ if (frame->colour_conversion()) {
xyz = dcp::rgb_to_xyz (
image->data()[0],
image->size(),
image->stride()[0],
- _frame->colour_conversion().get(),
+ frame->colour_conversion().get(),
note
);
} else {
xyz = dcp::xyz_to_xyz (image->data()[0], image->size(), image->stride()[0]);
}
+ return xyz;
+}
+
+/** J2K-encode this frame on the local host.
+ * @return Encoded data.
+ */
+Data
+DCPVideo::encode_locally (dcp::NoteHandler note)
+{
+ shared_ptr<dcp::OpenJPEGImage> xyz = convert_to_xyz (_frame, note);
+
/* Set the max image and component sizes based on frame_rate */
int max_cs_len = ((float) _j2k_bandwidth) / 8 / _frames_per_second;
if (_frame->eyes() == EYES_LEFT || _frame->eyes() == EYES_RIGHT) {
bool same (boost::shared_ptr<const DCPVideo> other) const;
+ static boost::shared_ptr<dcp::OpenJPEGImage> convert_to_xyz (boost::shared_ptr<const PlayerVideo> frame, dcp::NoteHandler note);
+
private:
void add_metadata (xmlpp::Element *) const;
}
/** @param n Component index.
- * @return Number of lines in the image for the given component.
+ * @return Number of samples (i.e. pixels, unless sub-sampled) in each direction for this component.
*/
-int
-Image::lines (int n) const
+dcp::Size
+Image::sample_size (int n) const
{
- return rint (ceil (static_cast<double>(size().height) / line_factor (n)));
+ int horizontal_factor = 1;
+ if (n > 0) {
+ AVPixFmtDescriptor const * d = av_pix_fmt_desc_get (_pixel_format);
+ if (!d) {
+ throw PixelFormatError ("sample_size()", _pixel_format);
+ }
+ horizontal_factor = pow (2.0f, d->log2_chroma_w);
+ }
+
+ return dcp::Size (
+ rint (ceil (static_cast<double>(size().width) / horizontal_factor)),
+ rint (ceil (static_cast<double>(size().height) / line_factor (n)))
+ );
}
-/** @return Number of components */
int
Image::components () const
{
throw PixelFormatError ("components()", _pixel_format);
}
+ return d->nb_components;
+}
+
+/** @return Number of planes */
+int
+Image::planes () const
+{
+ AVPixFmtDescriptor const * d = av_pix_fmt_desc_get(_pixel_format);
+ if (!d) {
+ throw PixelFormatError ("planes()", _pixel_format);
+ }
+
if ((d->flags & PIX_FMT_PLANAR) == 0) {
return 1;
}
}
/* Prepare input data pointers with crop */
- uint8_t* scale_in_data[components()];
- for (int c = 0; c < components(); ++c) {
+ uint8_t* scale_in_data[planes()];
+ for (int c = 0; c < planes(); ++c) {
/* To work out the crop in bytes, start by multiplying
the crop by the (average) bytes per pixel. Then
round down so that we don't crop a subsampled pixel until
/* Corner of the image within out_size */
Position<int> const corner ((out_size.width - inter_size.width) / 2, (out_size.height - inter_size.height) / 2);
- uint8_t* scale_out_data[out->components()];
- for (int c = 0; c < out->components(); ++c) {
+ uint8_t* scale_out_data[out->planes()];
+ for (int c = 0; c < out->planes(); ++c) {
scale_out_data[c] = out->data()[c] + int (rint (out->bytes_per_pixel(c) * corner.x)) + out->stride()[c] * corner.y;
}
void
Image::yuv_16_black (uint16_t v, bool alpha)
{
- memset (data()[0], 0, lines(0) * stride()[0]);
+ memset (data()[0], 0, sample_size(0).height * stride()[0]);
for (int i = 1; i < 3; ++i) {
int16_t* p = reinterpret_cast<int16_t*> (data()[i]);
- for (int y = 0; y < lines(i); ++y) {
+ int const lines = sample_size(i).height;
+ for (int y = 0; y < lines; ++y) {
/* We divide by 2 here because we are writing 2 bytes at a time */
for (int x = 0; x < line_size()[i] / 2; ++x) {
p[x] = v;
}
if (alpha) {
- memset (data()[3], 0, lines(3) * stride()[3]);
+ memset (data()[3], 0, sample_size(3).height * stride()[3]);
}
}
case PIX_FMT_YUV422P:
case PIX_FMT_YUV444P:
case PIX_FMT_YUV411P:
- memset (data()[0], 0, lines(0) * stride()[0]);
- memset (data()[1], eight_bit_uv, lines(1) * stride()[1]);
- memset (data()[2], eight_bit_uv, lines(2) * stride()[2]);
+ memset (data()[0], 0, sample_size(0).height * stride()[0]);
+ memset (data()[1], eight_bit_uv, sample_size(1).height * stride()[1]);
+ memset (data()[2], eight_bit_uv, sample_size(2).height * stride()[2]);
break;
case PIX_FMT_YUVJ420P:
case PIX_FMT_YUVJ422P:
case PIX_FMT_YUVJ444P:
- memset (data()[0], 0, lines(0) * stride()[0]);
- memset (data()[1], eight_bit_uv + 1, lines(1) * stride()[1]);
- memset (data()[2], eight_bit_uv + 1, lines(2) * stride()[2]);
+ memset (data()[0], 0, sample_size(0).height * stride()[0]);
+ memset (data()[1], eight_bit_uv + 1, sample_size(1).height * stride()[1]);
+ memset (data()[2], eight_bit_uv + 1, sample_size(2).height * stride()[2]);
break;
case PIX_FMT_YUV422P9LE:
case PIX_FMT_RGB555LE:
case PIX_FMT_RGB48LE:
case PIX_FMT_RGB48BE:
- memset (data()[0], 0, lines(0) * stride()[0]);
+ memset (data()[0], 0, sample_size(0).height * stride()[0]);
break;
case PIX_FMT_UYVY422:
{
- int const Y = lines(0);
+ int const Y = sample_size(0).height;
int const X = line_size()[0];
uint8_t* p = data()[0];
for (int y = 0; y < Y; ++y) {
throw PixelFormatError ("make_transparent()", _pixel_format);
}
- memset (data()[0], 0, lines(0) * stride()[0]);
+ memset (data()[0], 0, sample_size(0).height * stride()[0]);
}
void
void
Image::read_from_socket (shared_ptr<Socket> socket)
{
- for (int i = 0; i < components(); ++i) {
+ for (int i = 0; i < planes(); ++i) {
uint8_t* p = data()[i];
- for (int y = 0; y < lines(i); ++y) {
+ int const lines = sample_size(i).height;
+ for (int y = 0; y < lines; ++y) {
socket->read (p, line_size()[i]);
p += stride()[i];
}
void
Image::write_to_socket (shared_ptr<Socket> socket) const
{
- for (int i = 0; i < components(); ++i) {
+ for (int i = 0; i < planes(); ++i) {
uint8_t* p = data()[i];
- for (int y = 0; y < lines(i); ++y) {
+ int const lines = sample_size(i).height;
+ for (int y = 0; y < lines; ++y) {
socket->write (p, line_size()[i]);
p += stride()[i];
}
throw PixelFormatError ("bytes_per_pixel()", _pixel_format);
}
- if (c >= components()) {
+ if (c >= planes()) {
return 0;
}
_stride = (int *) wrapped_av_malloc (4 * sizeof (int));
_stride[0] = _stride[1] = _stride[2] = _stride[3] = 0;
- for (int i = 0; i < components(); ++i) {
+ for (int i = 0; i < planes(); ++i) {
_line_size[i] = ceil (_size.width * bytes_per_pixel(i));
_stride[i] = stride_round_up (i, _line_size, _aligned ? 32 : 1);
so I'll just over-allocate by 32 bytes and have done with it. Empirical
testing suggests that it works.
*/
- _data[i] = (uint8_t *) wrapped_av_malloc (_stride[i] * lines (i) + 32);
+ _data[i] = (uint8_t *) wrapped_av_malloc (_stride[i] * sample_size(i).height + 32);
}
}
{
allocate ();
- for (int i = 0; i < components(); ++i) {
+ for (int i = 0; i < planes(); ++i) {
uint8_t* p = _data[i];
uint8_t* q = other._data[i];
- for (int j = 0; j < lines(i); ++j) {
+ int const lines = sample_size(i).height;
+ for (int j = 0; j < lines; ++j) {
memcpy (p, q, _line_size[i]);
p += stride()[i];
q += other.stride()[i];
{
allocate ();
- for (int i = 0; i < components(); ++i) {
+ for (int i = 0; i < planes(); ++i) {
uint8_t* p = _data[i];
uint8_t* q = frame->data[i];
- for (int j = 0; j < lines(i); ++j) {
+ int const lines = sample_size(i).height;
+ for (int j = 0; j < lines; ++j) {
memcpy (p, q, _line_size[i]);
p += stride()[i];
/* AVFrame's linesize is what we call `stride' */
{
allocate ();
- for (int i = 0; i < components(); ++i) {
+ for (int i = 0; i < planes(); ++i) {
DCPOMATIC_ASSERT (line_size()[i] == other->line_size()[i]);
uint8_t* p = _data[i];
uint8_t* q = other->data()[i];
- for (int j = 0; j < lines(i); ++j) {
+ int const lines = sample_size(i).height;
+ for (int j = 0; j < lines; ++j) {
memcpy (p, q, line_size()[i]);
p += stride()[i];
q += other->stride()[i];
/** Destroy a Image */
Image::~Image ()
{
- for (int i = 0; i < components(); ++i) {
+ for (int i = 0; i < planes(); ++i) {
av_free (_data[i]);
}
return _data;
}
-int *
+int const *
Image::line_size () const
{
return _line_size;
bool
operator== (Image const & a, Image const & b)
{
- if (a.components() != b.components() || a.pixel_format() != b.pixel_format() || a.aligned() != b.aligned()) {
+ if (a.planes() != b.planes() || a.pixel_format() != b.pixel_format() || a.aligned() != b.aligned()) {
return false;
}
- for (int c = 0; c < a.components(); ++c) {
- if (a.lines(c) != b.lines(c) || a.line_size()[c] != b.line_size()[c] || a.stride()[c] != b.stride()[c]) {
+ for (int c = 0; c < a.planes(); ++c) {
+ if (a.sample_size(c).height != b.sample_size(c).height || a.line_size()[c] != b.line_size()[c] || a.stride()[c] != b.stride()[c]) {
return false;
}
uint8_t* p = a.data()[c];
uint8_t* q = b.data()[c];
- for (int y = 0; y < a.lines(c); ++y) {
+ int const lines = a.sample_size(c).height;
+ for (int y = 0; y < lines; ++y) {
if (memcmp (p, q, a.line_size()[c]) != 0) {
return false;
}
/* 8-bit */
for (int c = 0; c < 3; ++c) {
uint8_t* p = data()[c];
- for (int y = 0; y < lines(c); ++y) {
+ int const lines = sample_size(c).height;
+ for (int y = 0; y < lines; ++y) {
uint8_t* q = p;
for (int x = 0; x < line_size()[c]; ++x) {
*q = int (float (*q) * f);
int const stride_pixels = stride()[c] / 2;
int const line_size_pixels = line_size()[c] / 2;
uint16_t* p = reinterpret_cast<uint16_t*> (data()[c]);
- for (int y = 0; y < lines(c); ++y) {
+ int const lines = sample_size(c).height;
+ for (int y = 0; y < lines; ++y) {
uint16_t* q = p;
for (int x = 0; x < line_size_pixels; ++x) {
*q = int (float (*q) * f);
int const stride_pixels = stride()[c] / 2;
int const line_size_pixels = line_size()[c] / 2;
uint16_t* p = reinterpret_cast<uint16_t*> (data()[c]);
- for (int y = 0; y < lines(c); ++y) {
+ int const lines = sample_size(c).height;
+ for (int y = 0; y < lines; ++y) {
uint16_t* q = p;
for (int x = 0; x < line_size_pixels; ++x) {
*q = swap_16 (int (float (swap_16 (*q)) * f));
case PIX_FMT_UYVY422:
{
- int const Y = lines(0);
+ int const Y = sample_size(0).height;
int const X = line_size()[0];
uint8_t* p = data()[0];
for (int y = 0; y < Y; ++y) {
~Image ();
uint8_t * const * data () const;
- int * line_size () const;
+ int const * line_size () const;
int const * stride () const;
dcp::Size size () const;
bool aligned () const;
+ int planes () const;
int components () const;
int line_factor (int) const;
- int lines (int) const;
+ dcp::Size sample_size (int) const;
boost::shared_ptr<Image> scale (dcp::Size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat, bool aligned) const;
boost::shared_ptr<Image> crop_scale_window (Crop c, dcp::Size, dcp::Size, dcp::YUVToRGB yuv_to_rgb, AVPixelFormat, bool aligned) const;
* @brief The main DCP-o-matic GUI.
*/
+#include "wx/film_viewer.h"
+#include "wx/film_editor.h"
+#include "wx/job_manager_view.h"
+#include "wx/config_dialog.h"
+#include "wx/wx_util.h"
+#include "wx/new_film_dialog.h"
+#include "wx/wx_signal_manager.h"
+#include "wx/about_dialog.h"
+#include "wx/kdm_dialog.h"
+#include "wx/servers_list_dialog.h"
+#include "wx/hints_dialog.h"
+#include "wx/update_dialog.h"
+#include "wx/content_panel.h"
+#include "wx/report_problem_dialog.h"
+#include "wx/video_waveform_dialog.h"
#include "lib/film.h"
#include "lib/config.h"
#include "lib/util.h"
#include "lib/cross.h"
#include "lib/content_factory.h"
#include "lib/compose.hpp"
-#include "wx/film_viewer.h"
-#include "wx/film_editor.h"
-#include "wx/job_manager_view.h"
-#include "wx/config_dialog.h"
-#include "wx/wx_util.h"
-#include "wx/new_film_dialog.h"
-#include "wx/wx_signal_manager.h"
-#include "wx/about_dialog.h"
-#include "wx/kdm_dialog.h"
-#include "wx/servers_list_dialog.h"
-#include "wx/hints_dialog.h"
-#include "wx/update_dialog.h"
-#include "wx/content_panel.h"
-#include "wx/report_problem_dialog.h"
#include <dcp/exceptions.h>
#include <wx/generic/aboutdlgg.h>
#include <wx/stdpaths.h>
ID_jobs_make_kdms,
ID_jobs_send_dcp_to_tms,
ID_jobs_show_dcp,
+ ID_tools_video_waveform,
ID_tools_hints,
ID_tools_encoding_servers,
ID_tools_check_for_updates,
public:
DOMFrame (wxString const & title)
: wxFrame (NULL, -1, title)
+ , _video_waveform_dialog (0)
, _hints_dialog (0)
, _servers_list_dialog (0)
, _config_dialog (0)
Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_make_kdms, this), ID_jobs_make_kdms);
Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_send_dcp_to_tms, this), ID_jobs_send_dcp_to_tms);
Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::jobs_show_dcp, this), ID_jobs_show_dcp);
+ Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_video_waveform, this), ID_tools_video_waveform);
Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_hints, this), ID_tools_hints);
Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_encoding_servers, this), ID_tools_encoding_servers);
Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
#endif
}
+ void tools_video_waveform ()
+ {
+ if (!_video_waveform_dialog) {
+ _video_waveform_dialog = new VideoWaveformDialog (this, _film_viewer);
+ }
+
+ _video_waveform_dialog->Show ();
+ }
+
void tools_hints ()
{
if (!_hints_dialog) {
add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_CPL);
wxMenu* tools = new wxMenu;
+ add_item (tools, _("Video waveform..."), ID_tools_video_waveform, NEEDS_FILM);
add_item (tools, _("Hints..."), ID_tools_hints, 0);
add_item (tools, _("Encoding servers..."), ID_tools_encoding_servers, 0);
add_item (tools, _("Check for updates"), ID_tools_check_for_updates, 0);
FilmEditor* _film_editor;
FilmViewer* _film_viewer;
+ VideoWaveformDialog* _video_waveform_dialog;
HintsDialog* _hints_dialog;
ServersListDialog* _servers_list_dialog;
wxPreferencesEditor* _config_dialog;
_player_connection = _player->Changed.connect (boost::bind (&FilmViewer::player_changed, this, _1));
calculate_sizes ();
- get (_position, _last_get_accurate);
+ refresh ();
setup_sensitivity ();
}
if (!pvf.empty ()) {
try {
_frame = pvf.front()->image (PIX_FMT_RGB24, boost::bind (&Log::dcp_log, _film->log().get(), _1, _2));
+ ImageChanged (pvf.front ());
dcp::YUVToRGB yuv_to_rgb = dcp::YUV_TO_RGB_REC601;
if (pvf.front()->colour_conversion()) {
_panel_size.height = ev.GetSize().GetHeight();
calculate_sizes ();
- get (_position, _last_get_accurate);
+ refresh ();
update_position_label ();
update_position_slider ();
}
}
calculate_sizes ();
- get (_position, _last_get_accurate);
+ refresh ();
update_position_label ();
update_position_slider ();
}
setup_sensitivity ();
}
}
+
+/** Re-get the current frame */
+void
+FilmViewer::refresh ()
+{
+ get (_position, _last_get_accurate);
+}
return _position;
}
+ void refresh ();
+
+ boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
+
private:
void paint_panel ();
void panel_sized (wxSizeEvent &);
--- /dev/null
+/*
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "video_waveform_dialog.h"
+#include "video_waveform_plot.h"
+#include "film_viewer.h"
+#include "wx_util.h"
+#include <boost/bind.hpp>
+
+using std::cout;
+using boost::bind;
+
+VideoWaveformDialog::VideoWaveformDialog (wxWindow* parent, FilmViewer* viewer)
+ : wxDialog (parent, wxID_ANY, _("Video Waveform"), wxDefaultPosition, wxSize (640, 512), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE)
+ , _viewer (viewer)
+{
+ wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
+
+ wxBoxSizer* controls = new wxBoxSizer (wxHORIZONTAL);
+
+ _component = new wxChoice (this, wxID_ANY);
+ _component->Append (wxT ("X"));
+ _component->Append (wxT ("Y"));
+ _component->Append (wxT ("Z"));
+ add_label_to_sizer (controls, this, _("Component"), true);
+ controls->Add (_component, 1, wxALL, DCPOMATIC_SIZER_X_GAP);
+
+ add_label_to_sizer (controls, this, _("Contrast"), true);
+ _contrast = new wxSlider (this, wxID_ANY, 0, 0, 256);
+ controls->Add (_contrast, 1, wxALL, DCPOMATIC_SIZER_X_GAP);
+
+ overall_sizer->Add (controls, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_X_GAP);
+
+ _plot = new VideoWaveformPlot (this, _viewer);
+ overall_sizer->Add (_plot, 1, wxALL | wxEXPAND, 12);
+
+#ifdef DCPOMATIC_LINUX
+ wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE);
+ if (buttons) {
+ overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+ }
+#endif
+
+ SetSizer (overall_sizer);
+ overall_sizer->Layout ();
+ overall_sizer->SetSizeHints (this);
+
+ Bind (wxEVT_SHOW, bind (&VideoWaveformDialog::shown, this, _1));
+ _component->Bind (wxEVT_COMMAND_CHOICE_SELECTED, bind (&VideoWaveformDialog::component_changed, this));
+ _contrast->Bind (wxEVT_SCROLL_THUMBTRACK, bind (&VideoWaveformDialog::contrast_changed, this));
+
+ _component->SetSelection (0);
+ _contrast->SetValue (32);
+
+ component_changed ();
+ contrast_changed ();
+}
+
+void
+VideoWaveformDialog::shown (wxShowEvent& ev)
+{
+ _plot->set_enabled (ev.IsShown ());
+ if (ev.IsShown ()) {
+ _viewer->refresh ();
+ }
+}
+
+void
+VideoWaveformDialog::component_changed ()
+{
+ _plot->set_component (_component->GetCurrentSelection ());
+}
+
+void
+VideoWaveformDialog::contrast_changed ()
+{
+ _plot->set_contrast (_contrast->GetValue ());
+}
--- /dev/null
+/*
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <wx/wx.h>
+
+class VideoWaveformPlot;
+class FilmViewer;
+
+class VideoWaveformDialog : public wxDialog
+{
+public:
+ VideoWaveformDialog (wxWindow* parent, FilmViewer* viewer);
+
+private:
+ void shown (wxShowEvent &);
+ void component_changed ();
+ void contrast_changed ();
+
+ FilmViewer* _viewer;
+ VideoWaveformPlot* _plot;
+ wxChoice* _component;
+ wxSlider* _contrast;
+};
--- /dev/null
+/*
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "video_waveform_plot.h"
+#include "film_viewer.h"
+#include "wx_util.h"
+#include "lib/image.h"
+#include "lib/raw_convert.h"
+#include "lib/dcp_video.h"
+#include <dcp/openjpeg_image.h>
+#include <wx/rawbmp.h>
+#include <wx/graphics.h>
+#include <boost/bind.hpp>
+
+using std::cout;
+using std::min;
+using std::string;
+using boost::weak_ptr;
+using boost::shared_ptr;
+
+int const VideoWaveformPlot::_vertical_margin = 8;
+
+VideoWaveformPlot::VideoWaveformPlot (wxWindow* parent, FilmViewer* viewer)
+ : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
+ , _dirty (true)
+ , _enabled (false)
+ , _component (0)
+ , _contrast (0)
+{
+#ifndef __WXOSX__
+ SetDoubleBuffered (true);
+#endif
+
+ _viewer_connection = viewer->ImageChanged.connect (boost::bind (&VideoWaveformPlot::set_image, this, _1));
+
+ Bind (wxEVT_PAINT, boost::bind (&VideoWaveformPlot::paint, this));
+ Bind (wxEVT_SIZE, boost::bind (&VideoWaveformPlot::sized, this, _1));
+
+ SetMinSize (wxSize (640, 512));
+ SetBackgroundColour (wxColour (0, 0, 0));
+}
+
+void
+VideoWaveformPlot::paint ()
+{
+ wxPaintDC dc (this);
+
+ if (_dirty) {
+ create_waveform ();
+ _dirty = false;
+ }
+
+ if (!_waveform) {
+ return;
+ }
+
+ wxGraphicsContext* gc = wxGraphicsContext::Create (dc);
+ if (!gc) {
+ return;
+ }
+
+ int const axis_x = 48;
+ int const height = _waveform->size().height;
+
+ gc->SetPen (wxPen (wxColour (255, 255, 255), 1, wxPENSTYLE_SOLID));
+
+ gc->SetFont (gc->CreateFont (*wxSMALL_FONT, wxColour (255, 255, 255)));
+ double label_width;
+ double label_height;
+ double label_descent;
+ double label_leading;
+ gc->GetTextExtent (wxT ("1024"), &label_width, &label_height, &label_descent, &label_leading);
+
+ double extra[3];
+ double w;
+ gc->GetTextExtent (wxT ("0"), &w, &label_height, &label_descent, &label_leading);
+ extra[0] = label_width - w;
+ gc->GetTextExtent (wxT ("64"), &w, &label_height, &label_descent, &label_leading);
+ extra[1] = label_width - w;
+ gc->GetTextExtent (wxT ("512"), &w, &label_height, &label_descent, &label_leading);
+ extra[2] = label_width - w;
+
+ int label_gaps = 2;
+ while (height / label_gaps > 64) {
+ label_gaps *= 2;
+ }
+
+ for (int i = 0; i < label_gaps + 1; ++i) {
+ wxGraphicsPath p = gc->CreatePath ();
+ int const y = _vertical_margin + height - (i * height / label_gaps) - 1;
+ p.MoveToPoint (label_width + 8, y);
+ p.AddLineToPoint (axis_x, y);
+ gc->StrokePath (p);
+ int x = 4;
+ int const n = i * 4096 / label_gaps;
+ if (n < 10) {
+ x += extra[0];
+ } else if (n < 100) {
+ x += extra[1];
+ } else if (n < 1000) {
+ x += extra[2];
+ }
+ gc->DrawText (std_to_wx (raw_convert<string> (n)), x, y - (label_height / 2));
+ }
+
+ wxImage waveform (_waveform->size().width, height, _waveform->data()[0], true);
+ wxBitmap bitmap (waveform);
+ gc->DrawBitmap (bitmap, axis_x + 4, _vertical_margin, _waveform->size().width, height);
+
+ delete gc;
+}
+
+void
+VideoWaveformPlot::create_waveform ()
+{
+ _waveform.reset ();
+
+ if (!_image) {
+ return;
+ }
+
+ dcp::Size const size = _image->size();
+ _waveform.reset (new Image (PIX_FMT_RGB24, dcp::Size (size.width, size.height), true));
+
+ for (int x = 0; x < size.width; ++x) {
+
+ /* Work out one vertical `slice' of waveform pixels. Each value in
+ strip is the number of samples in image with the corresponding group of
+ values.
+ */
+ int strip[size.height];
+ for (int i = 0; i < size.height; ++i) {
+ strip[i] = 0;
+ }
+
+ int* ip = _image->data (_component) + x;
+ for (int y = 0; y < size.height; ++y) {
+ strip[*ip * size.height / 4096]++;
+ ip += size.width;
+ }
+
+ /* Copy slice into the waveform */
+ uint8_t* wp = _waveform->data()[0] + x * 3;
+ for (int y = size.height - 1; y >= 0; --y) {
+ wp[0] = wp[1] = wp[2] = min (255, (strip[y] * 255 / size.height) * _contrast);
+ wp += _waveform->stride()[0];
+ }
+ }
+
+ _waveform = _waveform->scale (
+ dcp::Size (GetSize().GetWidth() - 32, GetSize().GetHeight() - _vertical_margin * 2),
+ dcp::YUV_TO_RGB_REC709, PIX_FMT_RGB24, false
+ );
+}
+
+static void
+note ()
+{
+
+}
+
+void
+VideoWaveformPlot::set_image (weak_ptr<PlayerVideo> image)
+{
+ if (!_enabled) {
+ return;
+ }
+
+ shared_ptr<PlayerVideo> pv = image.lock ();
+ _image = DCPVideo::convert_to_xyz (pv, boost::bind (¬e));
+ _dirty = true;
+ Refresh ();
+}
+
+void
+VideoWaveformPlot::sized (wxSizeEvent &)
+{
+ _dirty = true;
+}
+
+void
+VideoWaveformPlot::set_enabled (bool e)
+{
+ _enabled = e;
+}
+
+void
+VideoWaveformPlot::set_component (int c)
+{
+ _component = c;
+ _dirty = true;
+ Refresh ();
+}
+
+/** Set `contrast', i.e. a fudge multiplication factor to make low-level signals easier to see,
+ * between 0 and 256.
+ */
+void
+VideoWaveformPlot::set_contrast (int b)
+{
+ _contrast = b;
+ _dirty = true;
+ Refresh ();
+}
--- /dev/null
+/*
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <wx/wx.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+#include <boost/signals2.hpp>
+
+namespace dcp {
+ class OpenJPEGImage;
+}
+
+class PlayerVideo;
+class Image;
+class FilmViewer;
+
+class VideoWaveformPlot : public wxPanel
+{
+public:
+ VideoWaveformPlot (wxWindow* parent, FilmViewer* viewer);
+
+ void set_enabled (bool e);
+ void set_component (int c);
+ void set_contrast (int b);
+
+private:
+ void paint ();
+ void sized (wxSizeEvent &);
+ void create_waveform ();
+ void set_image (boost::weak_ptr<PlayerVideo>);
+
+ boost::shared_ptr<dcp::OpenJPEGImage> _image;
+ boost::shared_ptr<const Image> _waveform;
+ bool _dirty;
+ bool _enabled;
+ int _component;
+ int _contrast;
+
+ static int const _vertical_margin;
+
+ boost::signals2::connection _viewer_connection;
+};
timing_panel.cc
update_dialog.cc
video_panel.cc
+ video_waveform_dialog.cc
+ video_waveform_plot.cc
wx_util.cc
wx_signal_manager.cc
"""
shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, dcp::Size (1998, 1080), true));
uint8_t* p = image->data()[0];
- for (int i = 0; i < image->components(); ++i) {
+ for (int i = 0; i < image->planes(); ++i) {
uint8_t* p = image->data()[i];
for (int j = 0; j < image->line_size()[i]; ++j) {
*p++ = j % 256;
BOOST_AUTO_TEST_CASE (aligned_image_test)
{
Image* s = new Image (PIX_FMT_RGB24, dcp::Size (50, 50), true);
- BOOST_CHECK_EQUAL (s->components(), 1);
+ BOOST_CHECK_EQUAL (s->planes(), 1);
/* 160 is 150 aligned to the nearest 32 bytes */
BOOST_CHECK_EQUAL (s->stride()[0], 160);
BOOST_CHECK_EQUAL (s->line_size()[0], 150);
/* copy constructor */
Image* t = new Image (*s);
- BOOST_CHECK_EQUAL (t->components(), 1);
+ BOOST_CHECK_EQUAL (t->planes(), 1);
BOOST_CHECK_EQUAL (t->stride()[0], 160);
BOOST_CHECK_EQUAL (t->line_size()[0], 150);
BOOST_CHECK (t->data()[0]);
/* assignment operator */
Image* u = new Image (PIX_FMT_YUV422P, dcp::Size (150, 150), false);
*u = *s;
- BOOST_CHECK_EQUAL (u->components(), 1);
+ BOOST_CHECK_EQUAL (u->planes(), 1);
BOOST_CHECK_EQUAL (u->stride()[0], 160);
BOOST_CHECK_EQUAL (u->line_size()[0], 150);
BOOST_CHECK (u->data()[0]);
BOOST_AUTO_TEST_CASE (compact_image_test)
{
Image* s = new Image (PIX_FMT_RGB24, dcp::Size (50, 50), false);
- BOOST_CHECK_EQUAL (s->components(), 1);
+ BOOST_CHECK_EQUAL (s->planes(), 1);
BOOST_CHECK_EQUAL (s->stride()[0], 50 * 3);
BOOST_CHECK_EQUAL (s->line_size()[0], 50 * 3);
BOOST_CHECK (s->data()[0]);
/* copy constructor */
Image* t = new Image (*s);
- BOOST_CHECK_EQUAL (t->components(), 1);
+ BOOST_CHECK_EQUAL (t->planes(), 1);
BOOST_CHECK_EQUAL (t->stride()[0], 50 * 3);
BOOST_CHECK_EQUAL (t->line_size()[0], 50 * 3);
BOOST_CHECK (t->data()[0]);
/* assignment operator */
Image* u = new Image (PIX_FMT_YUV422P, dcp::Size (150, 150), true);
*u = *s;
- BOOST_CHECK_EQUAL (u->components(), 1);
+ BOOST_CHECK_EQUAL (u->planes(), 1);
BOOST_CHECK_EQUAL (u->stride()[0], 50 * 3);
BOOST_CHECK_EQUAL (u->line_size()[0], 50 * 3);
BOOST_CHECK (u->data()[0]);
*/
/** @file src/pixel_formats_test.cc
- * @brief Make sure that Image::lines() and Image::bytes_per_pixel() return the right
+ * @brief Make sure that Image::sample_size() and Image::bytes_per_pixel() return the right
* things for various pixel formats.
*
* @see test/image_test.cc
{
Case (AVPixelFormat f, int c, int l0, int l1, int l2, float b0, float b1, float b2)
: format(f)
- , components(c)
+ , planes(c)
{
lines[0] = l0;
lines[1] = l1;
}
AVPixelFormat format;
- int components;
+ int planes;
int lines[3];
float bpp[3];
};
f->format = static_cast<int> (i->format);
av_frame_get_buffer (f, true);
Image t (f);
- BOOST_CHECK_EQUAL(t.components(), i->components);
- BOOST_CHECK_EQUAL(t.lines(0), i->lines[0]);
- BOOST_CHECK_EQUAL(t.lines(1), i->lines[1]);
- BOOST_CHECK_EQUAL(t.lines(2), i->lines[2]);
+ BOOST_CHECK_EQUAL(t.planes(), i->planes);
+ BOOST_CHECK_EQUAL(t.sample_size(0).height, i->lines[0]);
+ BOOST_CHECK_EQUAL(t.sample_size(1).height, i->lines[1]);
+ BOOST_CHECK_EQUAL(t.sample_size(2).height, i->lines[2]);
BOOST_CHECK_EQUAL(t.bytes_per_pixel(0), i->bpp[0]);
BOOST_CHECK_EQUAL(t.bytes_per_pixel(1), i->bpp[1]);
BOOST_CHECK_EQUAL(t.bytes_per_pixel(2), i->bpp[2]);