Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #if !defined(ioPNG_INCLUDE_ONCE)
00033 #define ioPNG_INCLUDE_ONCE
00034
00035 #include <vlCore/ResourceLoadWriter.hpp>
00036 #include <vlCore/ResourceDatabase.hpp>
00037 #include <vlCore/Image.hpp>
00038
00039 namespace vl
00040 {
00041 class VirtualFile;
00042 class String;
00043 class Image;
00044
00045 VLCORE_EXPORT ref<Image> loadPNG(VirtualFile* file);
00046 VLCORE_EXPORT ref<Image> loadPNG(const String& path);
00047 VLCORE_EXPORT bool isPNG(VirtualFile* file);
00048 VLCORE_EXPORT bool savePNG(const Image* src, const String& path, int compression = 6);
00049 VLCORE_EXPORT bool savePNG(const Image* src, VirtualFile* file, int compression = 6);
00050
00051
00052
00053
00057 class LoadWriterPNG: public ResourceLoadWriter
00058 {
00059 VL_INSTRUMENT_CLASS(vl::LoadWriterPNG, ResourceLoadWriter)
00060
00061 public:
00062 LoadWriterPNG(): ResourceLoadWriter("|png|", "|png|"), mCompression(6)
00063 {
00064 VL_DEBUG_SET_OBJECT_NAME()
00065 }
00066
00067 ref<ResourceDatabase> loadResource(const String& path) const
00068 {
00069 ref<ResourceDatabase> res_db = new ResourceDatabase;
00070 ref<Image> img = loadPNG(path);
00071 if (img)
00072 res_db->resources().push_back(img);
00073 return res_db;
00074 }
00075
00076 ref<ResourceDatabase> loadResource(VirtualFile* file) const
00077 {
00078 ref<ResourceDatabase> res_db = new ResourceDatabase;
00079 ref<Image> img = loadPNG(file);
00080 if (img)
00081 res_db->resources().push_back(img);
00082 return res_db;
00083 }
00084
00085 bool writeResource(const String& path, ResourceDatabase* resource) const
00086 {
00087 bool ok = true;
00088 for(unsigned i=0; i<resource->count<Image>(); ++i)
00089 ok &= savePNG(resource->get<Image>(i), path, compression());
00090 return ok;
00091 }
00092
00093 bool writeResource(VirtualFile* file, ResourceDatabase* resource) const
00094 {
00095 bool ok = true;
00096 for(unsigned i=0; i<resource->count<Image>(); ++i)
00097 ok &= savePNG(resource->get<Image>(i), file, compression());
00098 return ok;
00099 }
00100
00101 int compression() const { return mCompression; }
00103 void setCompression(int compression) { mCompression = compression; }
00104
00105 protected:
00106 int mCompression;
00107 };
00108 }
00109
00110 #endif