File indexing completed on 2024-05-05 16:57:02
0001 /*************************************************************************** 0002 * Copyright (C) 2013-2016 by Linuxstopmotion contributors; * 0003 * see the AUTHORS file for details. * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 #include "imagecache.h" 0022 #include "loadcache.h" 0023 0024 #include <QPixmap> 0025 #include <memory> 0026 0027 struct SurfaceLoader { 0028 typedef QPixmap value_t; 0029 static value_t* load(const char*); 0030 static void free(value_t*); 0031 }; 0032 0033 SurfaceLoader::value_t* SurfaceLoader::load(const char* path) { 0034 std::unique_ptr<QPixmap> p(new QPixmap); 0035 if (p->load(path)) { 0036 return p.release(); 0037 } 0038 return 0; 0039 } 0040 0041 void SurfaceLoader::free(SurfaceLoader::value_t* s) { 0042 delete s; 0043 } 0044 0045 ImageCache::ImageCache(int cacheSize) : delegate(0) { 0046 delegate = new LoadCache<SurfaceLoader>(cacheSize); 0047 } 0048 0049 ImageCache::~ImageCache() { 0050 delete delegate; 0051 } 0052 0053 QPixmap* ImageCache::get(const char* path) { 0054 if (!path) 0055 return 0; 0056 return delegate->get(path); 0057 } 0058 0059 void ImageCache::drop(const char* path) { 0060 delegate->drop(path); 0061 } 0062 0063 void ImageCache::clear() { 0064 delegate->clear(); 0065 }