Austin Schuh | 8c794d5 | 2019-03-03 21:17:37 -0800 | [diff] [blame^] | 1 | /* |
| 2 | # |
| 3 | # File : add_fileformat.h |
| 4 | # ( C++ header file - CImg plug-in ) |
| 5 | # |
| 6 | # Description : CImg plug-in that adds loading/saving support for a personalized |
| 7 | # file format (determined by its extension, here ".foo"). |
| 8 | # This file is a part of the CImg Library project. |
| 9 | # ( http://cimg.eu ) |
| 10 | # |
| 11 | # Copyright : David Tschumperle |
| 12 | # ( http://tschumperle.users.greyc.fr/ ) |
| 13 | # |
| 14 | # License : CeCILL v2.0 |
| 15 | # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) |
| 16 | # |
| 17 | # This software is governed by the CeCILL license under French law and |
| 18 | # abiding by the rules of distribution of free software. You can use, |
| 19 | # modify and/ or redistribute the software under the terms of the CeCILL |
| 20 | # license as circulated by CEA, CNRS and INRIA at the following URL |
| 21 | # "http://www.cecill.info". |
| 22 | # |
| 23 | # As a counterpart to the access to the source code and rights to copy, |
| 24 | # modify and redistribute granted by the license, users are provided only |
| 25 | # with a limited warranty and the software's author, the holder of the |
| 26 | # economic rights, and the successive licensors have only limited |
| 27 | # liability. |
| 28 | # |
| 29 | # In this respect, the user's attention is drawn to the risks associated |
| 30 | # with loading, using, modifying and/or developing or reproducing the |
| 31 | # software by the user in light of its specific status of free software, |
| 32 | # that may mean that it is complicated to manipulate, and that also |
| 33 | # therefore means that it is reserved for developers and experienced |
| 34 | # professionals having in-depth computer knowledge. Users are therefore |
| 35 | # encouraged to load and test the software's suitability as regards their |
| 36 | # requirements in conditions enabling the security of their systems and/or |
| 37 | # data to be ensured and, more generally, to use and operate it in the |
| 38 | # same conditions as regards security. |
| 39 | # |
| 40 | # The fact that you are presently reading this means that you have had |
| 41 | # knowledge of the CeCILL license and that you accept its terms. |
| 42 | # |
| 43 | */ |
| 44 | |
| 45 | #ifndef cimg_plugin_addfileformat |
| 46 | #define cimg_plugin_addfileformat |
| 47 | |
| 48 | // These functions load ".foo" filenames |
| 49 | //--------------------------------------- |
| 50 | static CImg<T> get_load_foo(const char *filename) { |
| 51 | std::fprintf(stderr,"Load '%s' here..\n",filename); |
| 52 | return CImg<T>(512,512,1,3,0).noise(30); |
| 53 | } |
| 54 | |
| 55 | CImg& load_foo(const char *filename) { |
| 56 | return get_load_foo(filename).swap(*this); |
| 57 | } |
| 58 | |
| 59 | // This function saves the instance image into a ".foo" file. |
| 60 | //----------------------------------------------------------- |
| 61 | const CImg& save_foo(const char *filename) const { |
| 62 | std::fprintf(stderr,"Save '%s' here..\n",filename); |
| 63 | return *this; |
| 64 | } |
| 65 | |
| 66 | // The code below allows to add the support for the specified extension. |
| 67 | //--------------------------------------------------------------------- |
| 68 | #ifndef cimg_load_plugin |
| 69 | #define cimg_load_plugin(filename) \ |
| 70 | if (!cimg::strncasecmp(cimg::split_filename(filename),"foo",3)) return load_foo(filename); |
| 71 | #endif |
| 72 | #ifndef cimg_save_plugin |
| 73 | #define cimg_save_plugin(filename) \ |
| 74 | if (!cimg::strncasecmp(cimg::split_filename(filename),"foo",3)) return save_foo(filename); |
| 75 | #endif |
| 76 | |
| 77 | // End of the plugin. |
| 78 | //------------------- |
| 79 | #endif /* cimg_plugin_addfileformat */ |