diff --git a/source/core/support/imageutil.cpp b/source/core/support/imageutil.cpp
index ae50e194e..3619cfe8f 100644
--- a/source/core/support/imageutil.cpp
+++ b/source/core/support/imageutil.cpp
@@ -1388,11 +1388,17 @@ ImageData *Copy_Image(ImageData *Old)
void Destroy_Image(ImageData *image)
{
if ((image == nullptr) || (--(image->References) > 0))
- return;
+ return;
+
+ image->data = nullptr; // Prevent the image from being deleted. Images are now cached.
+ delete image;
+}
+void Remove_Cached_Image(Image* image) {
delete image;
}
+
ImageData::~ImageData()
{
#ifdef POV_VIDCAP_IMPL
diff --git a/source/core/support/imageutil.h b/source/core/support/imageutil.h
index b4bf41bc2..c86959443 100644
--- a/source/core/support/imageutil.h
+++ b/source/core/support/imageutil.h
@@ -143,6 +143,7 @@ int map_pos(const Vector3d& EPoint, const ImageData* pImage, DBL *xcoor, DBL *yc
ImageData *Copy_Image(ImageData *old);
ImageData *Create_Image(void);
void Destroy_Image(ImageData *image);
+void Remove_Cached_Image(Image* image);
/// @}
///
diff --git a/source/parser/ImageCache.cpp b/source/parser/ImageCache.cpp
new file mode 100644
index 000000000..d48919619
--- /dev/null
+++ b/source/parser/ImageCache.cpp
@@ -0,0 +1,135 @@
+//******************************************************************************
+///
+/// @file parser/ImageCache.cpp
+///
+/// This module implements a cache for images used in a scene so they only heve
+/// to be loaded once during animation rendering or between manual renders
+///
+/// @copyright
+/// @parblock
+///
+/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
+/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
+///
+/// POV-Ray is free software: you can redistribute it and/or modify
+/// it under the terms of the GNU Affero General Public License as
+/// published by the Free Software Foundation, either version 3 of the
+/// License, or (at your option) any later version.
+///
+/// POV-Ray is distributed in the hope that it will be useful,
+/// but WITHOUT ANY WARRANTY; without even the implied warranty of
+/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+/// GNU Affero General Public License for more details.
+///
+/// You should have received a copy of the GNU Affero General Public License
+/// along with this program. If not, see .
+///
+/// ----------------------------------------------------------------------------
+///
+/// POV-Ray is based on the popular DKB raytracer version 2.12.
+/// DKBTrace was originally written by David K. Buck.
+/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
+///
+/// @endparblock
+///
+//******************************************************************************
+
+
+// C++ variants of C standard header files
+#include