X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fimage%2Fconsumer%2Fimage_consumer.cpp;h=21fdafb0db7601a0a793d4a81d70f06e6dc50fc8;hb=a3bcf2e33433f4163bce96dd63c09ce7b1e23d61;hp=b4b7db10cf38ed3e2ec5da4f0d903ee5a584179d;hpb=c760758af51ab007f511be5d70b96604e20f0eee;p=casparcg diff --git a/modules/image/consumer/image_consumer.cpp b/modules/image/consumer/image_consumer.cpp index b4b7db10c..21fdafb0d 100644 --- a/modules/image/consumer/image_consumer.cpp +++ b/modules/image/consumer/image_consumer.cpp @@ -1,30 +1,33 @@ /* -* copyright (c) 2010 Sveriges Television AB +* Copyright 2013 Sveriges Television AB http://casparcg.com/ * -* This file is part of CasparCG. +* This file is part of CasparCG (www.casparcg.com). * -* CasparCG 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 3 of the License, or -* (at your option) any later version. +* CasparCG 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 3 of the License, or +* (at your option) any later version. * -* CasparCG 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 CasparCG. If not, see . +* CasparCG 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 CasparCG. If not, see . * +* Author: Robert Nagy, ronag89@gmail.com */ - + #include "image_consumer.h" #include #include #include #include +#include +#include #include #include #include @@ -32,39 +35,74 @@ #include #include -#include - #include - #include +#include + +#include "../util/image_view.h" namespace caspar { namespace image { - + +void write_cropped_png( + const safe_ptr& frame, + const core::video_format_desc& format_desc, + const boost::filesystem::wpath& output_file, + int width, + int height) +{ + auto bitmap = std::shared_ptr(FreeImage_Allocate(width, height, 32), FreeImage_Unload); + image_view destination_view(FreeImage_GetBits(bitmap.get()), width, height); + image_view complete_frame(const_cast(frame->image_data().begin()), format_desc.width, format_desc.height); + auto thumbnail_view = complete_frame.subview(0, 0, width, height); + + std::copy(thumbnail_view.begin(), thumbnail_view.end(), destination_view.begin()); + FreeImage_FlipVertical(bitmap.get()); + FreeImage_SaveU(FIF_PNG, bitmap.get(), output_file.string().c_str(), 0); +} + struct image_consumer : public core::frame_consumer { - core::video_format_desc format_desc_; + core::video_format_desc format_desc_; + std::wstring filename_; public: // frame_consumer + image_consumer(const std::wstring& filename) + : filename_(filename) + { + } + virtual void initialize(const core::video_format_desc& format_desc, int) override { format_desc_ = format_desc; } + + virtual int64_t presentation_frame_age_millis() const override + { + return 0; + } - virtual bool send(const safe_ptr& frame) override + virtual boost::unique_future send(const safe_ptr& frame) override { auto format_desc = format_desc_; - boost::thread async([format_desc, frame] + auto filename = filename_; + + boost::thread async([format_desc, frame, filename] { try { - auto filename = narrow(env::data_folder()) + boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time()) + ".png"; + auto filename2 = filename; + + if (filename2.empty()) + filename2 = env::media_folder() + widen(boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time())) + L".png"; + else + filename2 = env::media_folder() + filename2 + L".png"; auto bitmap = std::shared_ptr(FreeImage_Allocate(format_desc.width, format_desc.height, 32), FreeImage_Unload); memcpy(FreeImage_GetBits(bitmap.get()), frame->image_data().begin(), frame->image_size()); FreeImage_FlipVertical(bitmap.get()); - FreeImage_Save(FIF_PNG, bitmap.get(), filename.c_str(), 0); + FreeImage_SaveU(FIF_PNG, bitmap.get(), filename2.c_str(), 0); } catch(...) { @@ -73,7 +111,7 @@ public: }); async.detach(); - return false; + return wrap_as_future(false); } virtual std::wstring print() const override @@ -81,6 +119,13 @@ public: return L"image[]"; } + virtual boost::property_tree::wptree info() const override + { + boost::property_tree::wptree info; + info.add(L"type", L"image-consumer"); + return info; + } + virtual size_t buffer_depth() const override { return 0; @@ -92,12 +137,17 @@ public: } }; -safe_ptr create_consumer(const std::vector& params) +safe_ptr create_consumer(const core::parameters& params) { - if(params.size() < 1 || params[0] != L"IMAGE") + if(params.size() < 1 || params.at(0) != L"IMAGE") return core::frame_consumer::empty(); - return make_safe(); + std::wstring filename; + + if (params.size() > 1) + filename = params.at(1); + + return make_safe(filename); } }}