Tidy up test film naming.
[dcpomatic.git] / src / lib / dcp_video_frame.cc
index e074b1cd16cf7955ea2fe46a160a1ac37fc4e7ee..916a57bc8f64e6773b2584da4674ecc1b7f289ea 100644 (file)
@@ -142,7 +142,6 @@ DCPVideoFrame::~DCPVideoFrame ()
 
        if (_parameters) {
                free (_parameters->cp_comment);
-               free (_parameters->cp_matrice);
        }
        
        delete _parameters;
@@ -161,14 +160,14 @@ DCPVideoFrame::encode_locally ()
        shared_ptr<Image> prepared = _input->scale_and_convert_to_rgb (_out_size, _padding, _scaler);
 
        if (_subtitle) {
-               Rectangle tx = subtitle_transformed_area (
+               Rect tx = subtitle_transformed_area (
                        float (_out_size.width) / _input->size().width,
                        float (_out_size.height) / _input->size().height,
                        _subtitle->area(), _subtitle_offset, _subtitle_scale
                        );
 
-               shared_ptr<Image> im = _subtitle->image()->scale (Size (tx.w, tx.h), _scaler);
-               prepared->alpha_blend (im, Position (tx.x, tx.y));
+               shared_ptr<Image> im = _subtitle->image()->scale (tx.size(), _scaler);
+               prepared->alpha_blend (im, tx.position());
        }
 
        create_openjpeg_container ();
@@ -276,6 +275,9 @@ DCPVideoFrame::encode_locally ()
 
        /* get a J2K compressor handle */
        _cinfo = opj_create_compress (CODEC_J2K);
+       if (_cinfo == 0) {
+               throw EncodeError ("could not create JPEG2000 encoder");
+       }
 
        /* Set event manager to null (openjpeg 1.3 bug) */
        _cinfo->event_mgr = 0;
@@ -284,10 +286,13 @@ DCPVideoFrame::encode_locally ()
        opj_setup_encoder (_cinfo, _parameters, _image);
 
        _cio = opj_cio_open ((opj_common_ptr) _cinfo, 0, 0);
+       if (_cio == 0) {
+               throw EncodeError ("could not open JPEG2000 stream");
+       }
 
        int const r = opj_encode (_cinfo, _cio, _image, 0);
        if (r == 0) {
-               throw EncodeError ("jpeg2000 encoding failed");
+               throw EncodeError ("JPEG2000 encoding failed");
        }
 
        _log->log (String::compose ("Finished locally-encoded frame %1", _frame));
@@ -312,25 +317,31 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv)
        socket->connect (*endpoint_iterator, 30);
 
        stringstream s;
-       s << "encode "
-         << _input->size().width << " " << _input->size().height << " "
-         << _input->pixel_format() << " "
-         << _out_size.width << " " << _out_size.height << " "
-         << _padding << " "
-         << _subtitle_offset << " "
-         << _subtitle_scale << " "
-         << _scaler->id () << " "
-         << _frame << " "
-         << _frames_per_second << " "
-         << (_post_process.empty() ? "none" : _post_process) << " "
-         << Config::instance()->colour_lut_index () << " "
-         << Config::instance()->j2k_bandwidth () << " ";
+       s << "encode please\n"
+         << "input_width " << _input->size().width << "\n"
+         << "input_height " << _input->size().height << "\n"
+         << "input_pixel_format " << _input->pixel_format() << "\n"
+         << "output_width " << _out_size.width << "\n"
+         << "output_height " << _out_size.height << "\n"
+         << "padding " <<  _padding << "\n"
+         << "subtitle_offset " << _subtitle_offset << "\n"
+         << "subtitle_scale " << _subtitle_scale << "\n"
+         << "scaler " << _scaler->id () << "\n"
+         << "frame " << _frame << "\n"
+         << "frames_per_second " << _frames_per_second << "\n";
+
+       if (!_post_process.empty()) {
+               s << "post_process " << _post_process << "\n";
+       }
+       
+       s << "colour_lut " << Config::instance()->colour_lut_index () << "\n"
+         << "j2k_bandwidth " << Config::instance()->j2k_bandwidth () << "\n";
 
        if (_subtitle) {
-               s << _subtitle->position().x << " " << _subtitle->position().y << " "
-                 << _subtitle->image()->size().width << " " << _subtitle->image()->size().height;
-       } else {
-               s << "-1 -1 0 0";
+               s << "subtitle_x " << _subtitle->position().x << "\n"
+                 << "subtitle_y " << _subtitle->position().y << "\n"
+                 << "subtitle_width " << _subtitle->image()->size().width << "\n"
+                 << "subtitle_height " << _subtitle->image()->size().height << "\n";
        }
 
        socket->write ((uint8_t *) s.str().c_str(), s.str().length() + 1, 30);