Commit deacb5b9 authored by nadro's avatar nadro

- Prepared interface for loading multiple images from file.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5258 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 48e75f34
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "IReferenceCounted.h" #include "IReferenceCounted.h"
#include "IImage.h" #include "IImage.h"
#include "path.h" #include "path.h"
#include "irrArray.h"
namespace irr namespace irr
{ {
...@@ -43,6 +44,16 @@ public: ...@@ -43,6 +44,16 @@ public:
/** \param file File handle to check. /** \param file File handle to check.
\return Pointer to newly created image, or 0 upon error. */ \return Pointer to newly created image, or 0 upon error. */
virtual IImage* loadImage(io::IReadFile* file) const = 0; virtual IImage* loadImage(io::IReadFile* file) const = 0;
//! Creates a multiple surfaces from the file eg. whole cube map.
/** \param file File handle to check.
\return Array of pointers to newly created images. */
virtual core::array<IImage*> IImageLoader::loadImages(io::IReadFile* file) const
{
core::array<IImage*> image;
return image;
}
}; };
......
...@@ -1184,6 +1184,26 @@ namespace video ...@@ -1184,6 +1184,26 @@ namespace video
\return The current texture creation flag enabled mode. */ \return The current texture creation flag enabled mode. */
virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const =0; virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const =0;
//! Creates a software images from a file.
/** No hardware texture will be created for those images. This
method is useful for example if you want to read a heightmap
for a terrain renderer.
\param filename Name of the file from which the images are created.
\return The array of created images.
If you no longer need those images, you should call IImage::drop() on each of them.
See IReferenceCounted::drop() for more information. */
virtual core::array<IImage*> createImagesFromFile(const io::path& filename) = 0;
//! Creates a software images from a file.
/** No hardware texture will be created for those images. This
method is useful for example if you want to read a heightmap
for a terrain renderer.
\param file File from which the image is created.
\return The array of created images.
If you no longer need those images, you should call IImage::drop() on each of them.
See IReferenceCounted::drop() for more information. */
virtual core::array<IImage*> createImagesFromFile(io::IReadFile* file) = 0;
//! Creates a software image from a file. //! Creates a software image from a file.
/** No hardware texture will be created for this image. This /** No hardware texture will be created for this image. This
method is useful for example if you want to read a heightmap method is useful for example if you want to read a heightmap
...@@ -1193,7 +1213,15 @@ namespace video ...@@ -1193,7 +1213,15 @@ namespace video
\return The created image. \return The created image.
If you no longer need the image, you should call IImage::drop(). If you no longer need the image, you should call IImage::drop().
See IReferenceCounted::drop() for more information. */ See IReferenceCounted::drop() for more information. */
virtual IImage* createImageFromFile(const io::path& filename) = 0; IImage* createImageFromFile(const io::path& filename)
{
core::array<IImage*> imageArray = createImagesFromFile(filename);
for (u32 i = 1; i < imageArray.size(); ++i)
imageArray[i]->drop();
return (imageArray.size() > 0) ? imageArray[0] : 0;
}
//! Creates a software image from a file. //! Creates a software image from a file.
/** No hardware texture will be created for this image. This /** No hardware texture will be created for this image. This
...@@ -1203,7 +1231,15 @@ namespace video ...@@ -1203,7 +1231,15 @@ namespace video
\return The created image. \return The created image.
If you no longer need the image, you should call IImage::drop(). If you no longer need the image, you should call IImage::drop().
See IReferenceCounted::drop() for more information. */ See IReferenceCounted::drop() for more information. */
virtual IImage* createImageFromFile(io::IReadFile* file) =0; IImage* createImageFromFile(io::IReadFile* file)
{
core::array<IImage*> imageArray = createImagesFromFile(file);
for (u32 i = 1; i < imageArray.size(); ++i)
imageArray[i]->drop();
return (imageArray.size() > 0) ? imageArray[0] : 0;
}
//! Writes the provided image to a file. //! Writes the provided image to a file.
/** Requires that there is a suitable image writer registered /** Requires that there is a suitable image writer registered
......
...@@ -1481,66 +1481,87 @@ bool CNullDriver::getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const ...@@ -1481,66 +1481,87 @@ bool CNullDriver::getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const
return (TextureCreationFlags & flag)!=0; return (TextureCreationFlags & flag)!=0;
} }
core::array<IImage*> CNullDriver::createImagesFromFile(const io::path& filename)
//! Creates a software image from a file.
IImage* CNullDriver::createImageFromFile(const io::path& filename)
{ {
if (!filename.size()) // TO-DO -> use 'move' feature from C++11 standard.
return 0;
IImage* image = 0; core::array<IImage*> imageArray;
io::IReadFile* file = FileSystem->createAndOpenFile(filename);
if (file) if (filename.size() > 0)
{ {
image = createImageFromFile(file); io::IReadFile* file = FileSystem->createAndOpenFile(filename);
file->drop();
if (file)
{
imageArray = createImagesFromFile(file);
file->drop();
}
else
os::Printer::log("Could not open file of image", filename, ELL_WARNING);
} }
else
os::Printer::log("Could not open file of image", filename, ELL_WARNING);
return image; return imageArray;
} }
core::array<IImage*> CNullDriver::createImagesFromFile(io::IReadFile* file)
//! Creates a software image from a file.
IImage* CNullDriver::createImageFromFile(io::IReadFile* file)
{ {
if (!file) // TO-DO -> use 'move' feature from C++11 standard.
return 0;
IImage* image = 0; core::array<IImage*> imageArray;
s32 i; if (file)
// try to load file based on file extension
for (i=SurfaceLoader.size()-1; i>=0; --i)
{ {
if (SurfaceLoader[i]->isALoadableFileExtension(file->getFileName())) s32 i;
// try to load file based on file extension
for (i = SurfaceLoader.size() - 1; i >= 0; --i)
{ {
// reset file position which might have changed due to previous loadImage calls if (SurfaceLoader[i]->isALoadableFileExtension(file->getFileName()))
file->seek(0); {
image = SurfaceLoader[i]->loadImage(file); // reset file position which might have changed due to previous loadImage calls
if (image) file->seek(0);
return image; imageArray = SurfaceLoader[i]->loadImages(file);
if (imageArray.size() == 0)
{
file->seek(0);
IImage* image = SurfaceLoader[i]->loadImage(file);
if (image)
imageArray.push_back(image);
}
if (imageArray.size() > 0)
return imageArray;
}
} }
}
// try to load file based on what is in it // try to load file based on what is in it
for (i=SurfaceLoader.size()-1; i>=0; --i) for (i = SurfaceLoader.size() - 1; i >= 0; --i)
{
// dito
file->seek(0);
if (SurfaceLoader[i]->isALoadableFileFormat(file))
{ {
// dito
file->seek(0); file->seek(0);
image = SurfaceLoader[i]->loadImage(file); if (SurfaceLoader[i]->isALoadableFileFormat(file))
if (image) {
return image; file->seek(0);
imageArray = SurfaceLoader[i]->loadImages(file);
if (imageArray.size() == 0)
{
file->seek(0);
IImage* image = SurfaceLoader[i]->loadImage(file);
if (image)
imageArray.push_back(image);
}
if (imageArray.size() > 0)
return imageArray;
}
} }
} }
return 0; // failed to load return imageArray;
} }
......
...@@ -341,11 +341,9 @@ namespace video ...@@ -341,11 +341,9 @@ namespace video
//! Returns if a texture creation flag is enabled or disabled. //! Returns if a texture creation flag is enabled or disabled.
virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const _IRR_OVERRIDE_; virtual bool getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const _IRR_OVERRIDE_;
//! Creates a software image from a file. virtual core::array<IImage*> createImagesFromFile(const io::path& filename) _IRR_OVERRIDE_;
virtual IImage* createImageFromFile(const io::path& filename) _IRR_OVERRIDE_;
//! Creates a software image from a file. virtual core::array<IImage*> createImagesFromFile(io::IReadFile* file) _IRR_OVERRIDE_;
virtual IImage* createImageFromFile(io::IReadFile* file) _IRR_OVERRIDE_;
//! Creates a software image from a byte array. //! Creates a software image from a byte array.
/** \param useForeignMemory: If true, the image will use the data pointer /** \param useForeignMemory: If true, the image will use the data pointer
...@@ -358,7 +356,6 @@ namespace video ...@@ -358,7 +356,6 @@ namespace video
//! Creates an empty software image. //! Creates an empty software image.
virtual IImage* createImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size) _IRR_OVERRIDE_; virtual IImage* createImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size) _IRR_OVERRIDE_;
//! Creates a software image from another image. //! Creates a software image from another image.
virtual IImage* createImage(ECOLOR_FORMAT format, IImage *imageToCopy) _IRR_OVERRIDE_; virtual IImage* createImage(ECOLOR_FORMAT format, IImage *imageToCopy) _IRR_OVERRIDE_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment