2 Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
23 #include "image_store.h"
25 #include <libavutil/buffer.h>
29 using std::shared_ptr;
33 ImageStore::buffer_free(void* opaque, uint8_t* data)
35 reinterpret_cast<ImageStore*>(opaque)->buffer_free2(data);
40 ImageStore::buffer_free2(uint8_t* data)
42 boost::mutex::scoped_lock lm(_mutex);
43 auto iter = _images.find(data);
44 if (iter != _images.end()) {
45 iter->second.second--;
46 if (iter->second.second == 0) {
54 ImageStore::create_buffer(shared_ptr<const Image> image, int component)
56 boost::mutex::scoped_lock lm(_mutex);
57 auto key = image->data()[component];
58 auto iter = _images.find(key);
59 if (iter != _images.end()) {
60 iter->second.second++;
62 _images[key] = { image, 1 };
65 return av_buffer_create(image->data()[component], image->stride()[component] * image->size().height, &buffer_free, this, 0);