Forráskód Böngészése

png: Split library to thirdparty dir and allow unbundling

Uses the new structure agreed upon in #6157, but the thirdparty/ folder
does not behave following a logic similar to that of modules/ yet.

The png driver can't be moved to a module as discussed in #6157, as it's
required by core together with a few other ImageLoader implementations
(see drivers/register_driver_types.cpp:register_core_driver_types())

Dropped the possibility to disable PNG support, it's a core component
of Godot.
Rémi Verschelde 8 éve
szülő
commit
5fef84a135

+ 1 - 3
SConstruct

@@ -127,7 +127,7 @@ opts.Add('theora','Theora Video (yes/no)','yes')
 opts.Add('theoralib','Theora Video (yes/no)','no')
 opts.Add('freetype','Freetype support in editor','builtin')
 opts.Add('xml','XML Save/Load support (yes/no)','yes')
-opts.Add('png','PNG Image loader support (yes/no)','yes')
+opts.Add('libpng','libpng library for image loader support (system/builtin)','builtin')
 opts.Add('jpg','JPG Image loader support (yes/no)','yes')
 opts.Add('webp','WEBP Image loader support (yes/no)','yes')
 opts.Add('dds','DDS Texture loader support (yes/no)','yes')
@@ -350,8 +350,6 @@ if selected_platform in platform_list:
 	if (env['theoralib']=='yes'):
 		env.Append(CPPFLAGS=['-DTHEORALIB_ENABLED']);
 
-	if (env['png']=='yes'):
-		env.Append(CPPFLAGS=['-DPNG_ENABLED']);
 	if (env['dds']=='yes'):
 		env.Append(CPPFLAGS=['-DDDS_ENABLED']);
 	if (env['pvr']=='yes'):

+ 1 - 2
drivers/SCsub

@@ -26,8 +26,7 @@ if (env['openssl']!='no'):
 	SConscript('openssl/SCsub')
 
 
-if (env["png"]=="yes"):
-	SConscript("png/SCsub");
+SConscript("png/SCsub");
 if (env["jpg"]=="yes"):
 	#SConscript("jpg/SCsub");
 	SConscript("jpegd/SCsub");

+ 43 - 36
drivers/png/SCsub

@@ -1,42 +1,49 @@
 Import('env')
 Import('env_drivers')
 
+# Thirdparty source files
 
-png_sources = [
-	"png/png.c",
-	"png/pngerror.c",
-	"png/pngget.c",
-	"png/pngmem.c",
-	"png/pngpread.c",
-	"png/pngread.c",
-	"png/pngrio.c",
-	"png/pngrtran.c",
-	"png/pngrutil.c",
-	"png/pngset.c",
-	"png/pngtrans.c",
-	"png/pngwio.c",
-	"png/pngwrite.c",
-	"png/pngwtran.c",
-	"png/pngwutil.c",
-	"png/resource_saver_png.cpp",
-	"png/image_loader_png.cpp"
-]
-
-# Currently .ASM filter_neon.S does not compile on NT.
-import os
-if ("neon_enabled" in env and env["neon_enabled"]) and os.name!="nt":
-	env_drivers.Append(CPPFLAGS=["-DPNG_ARM_NEON_OPT=2"])
-	env_neon = env_drivers.Clone();
-	if "S_compiler" in env:
-		env_neon['CC'] = env['S_compiler']
-	#env_neon.Append(CPPFLAGS=["-DPNG_ARM_NEON"])
-	png_sources.append(env_neon.Object("#drivers/png/arm/arm_init.c"))
-	png_sources.append(env_neon.Object("#drivers/png/arm/filter_neon.S"))
-else:
-	env_drivers.Append(CPPFLAGS=["-DPNG_ARM_NEON_OPT=0"])
-
-env.drivers_sources+=png_sources
-
-#env.add_source_files(env.drivers_sources, png_sources)
+if (env["libpng"] == "builtin"):
+	thirdparty_dir = "#thirdparty/libpng/"
+	thirdparty_png_sources = [
+		thirdparty_dir + "png.c",
+		thirdparty_dir + "pngerror.c",
+		thirdparty_dir + "pngget.c",
+		thirdparty_dir + "pngmem.c",
+		thirdparty_dir + "pngpread.c",
+		thirdparty_dir + "pngread.c",
+		thirdparty_dir + "pngrio.c",
+		thirdparty_dir + "pngrtran.c",
+		thirdparty_dir + "pngrutil.c",
+		thirdparty_dir + "pngset.c",
+		thirdparty_dir + "pngtrans.c",
+		thirdparty_dir + "pngwio.c",
+		thirdparty_dir + "pngwrite.c",
+		thirdparty_dir + "pngwtran.c",
+		thirdparty_dir + "pngwutil.c",
+	]
 
+	# Currently .ASM filter_neon.S does not compile on NT.
+	import os
+	if ("neon_enabled" in env and env["neon_enabled"]) and os.name!="nt":
+		env_drivers.Append(CPPFLAGS=["-DPNG_ARM_NEON_OPT=2"])
+		env_neon = env_drivers.Clone();
+		if "S_compiler" in env:
+			env_neon['CC'] = env['S_compiler']
+		#env_neon.Append(CPPFLAGS=["-DPNG_ARM_NEON"])
+		thirdparty_png_sources.append(env_neon.Object(thirdparty_dir + "/arm/arm_init.c"))
+		thirdparty_png_sources.append(env_neon.Object(thirdparty_dir + "/arm/filter_neon.S"))
+	else:
+		env_drivers.Append(CPPFLAGS=["-DPNG_ARM_NEON_OPT=0"])
+
+	#env_drivers.add_source_files(env.drivers_sources, thirdparty_png_sources)
+	env.drivers_sources += thirdparty_png_sources # Concatenation necessary for neon objects it seems?
+	env_drivers.Append(CPPPATH = [thirdparty_dir])
+
+
+# Godot's own source files
+
+env_drivers.add_source_files(env.drivers_sources, "*.cpp")
+
+Export('env_drivers')
 Export('env')

+ 1 - 0
drivers/png/image_loader_png.cpp

@@ -30,6 +30,7 @@
 
 #include "print_string.h"
 #include "os/os.h"
+
 #include <string.h>
 
 

+ 2 - 1
drivers/png/image_loader_png.h

@@ -30,7 +30,8 @@
 #define IMAGE_LOADER_PNG_H
 
 #include "io/image_loader.h"
-#include "drivers/png/png.h"
+
+#include <png.h>
 
 /**
 	@author Juan Linietsky <[email protected]>

+ 6 - 4
drivers/png/resource_saver_png.cpp

@@ -27,11 +27,13 @@
 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
 /*************************************************************************/
 #include "resource_saver_png.h"
-#include "scene/resources/texture.h"
-#include "drivers/png/png.h"
-#include "os/file_access.h"
-#include "globals.h"
+
 #include "core/image.h"
+#include "globals.h"
+#include "os/file_access.h"
+#include "scene/resources/texture.h"
+
+#include <png.h>
 
 static void _write_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length) {
 

+ 1 - 15
drivers/register_driver_types.cpp

@@ -29,8 +29,8 @@
 #include "register_driver_types.h"
 
 #include "png/image_loader_png.h"
-#include "webp/image_loader_webp.h"
 #include "png/resource_saver_png.h"
+#include "webp/image_loader_webp.h"
 #include "jpegd/image_loader_jpegd.h"
 #include "dds/texture_loader_dds.h"
 #include "etc1/texture_loader_pkm.h"
@@ -75,14 +75,11 @@
 #include "mpc/audio_stream_mpc.h"
 #endif
 
-#ifdef PNG_ENABLED
 static ImageLoaderPNG *image_loader_png=NULL;
 static ResourceSaverPNG *resource_saver_png=NULL;
-#endif
 
 #ifdef WEBP_ENABLED
 static ImageLoaderWEBP *image_loader_webp=NULL;
-//static ResourceSaverPNG *resource_saver_png=NULL;
 #endif
 
 #ifdef JPG_ENABLED
@@ -132,22 +129,15 @@ static ResourceFormatPBM * pbm_loader=NULL;
 
 void register_core_driver_types() {
 
-#ifdef PNG_ENABLED
 	image_loader_png = memnew( ImageLoaderPNG );
 	ImageLoader::add_image_format_loader( image_loader_png );
 
 	resource_saver_png = memnew( ResourceSaverPNG );
 	ResourceSaver::add_resource_format_saver(resource_saver_png);
 
-#endif
-
 #ifdef WEBP_ENABLED
 	image_loader_webp = memnew( ImageLoaderWEBP );
 	ImageLoader::add_image_format_loader( image_loader_webp );
-
-//	resource_saver_png = memnew( ResourceSaverPNG );
-//	ResourceSaver::add_resource_format_saver(resource_saver_png);
-
 #endif
 
 #ifdef JPG_ENABLED
@@ -165,18 +155,14 @@ void register_core_driver_types() {
 
 void unregister_core_driver_types() {
 
-#ifdef PNG_ENABLED
 	if (image_loader_png)
 		memdelete( image_loader_png );
 	if (resource_saver_png)
 		memdelete( resource_saver_png );
-#endif
 
 #ifdef WEBP_ENABLED
 	if (image_loader_webp)
 		memdelete( image_loader_webp );
-//	if (resource_saver_png)
-//		memdelete( resource_saver_png );
 #endif
 
 #ifdef JPG_ENABLED

+ 5 - 3
platform/x11/detect.py

@@ -71,10 +71,10 @@ def get_flags():
 	('builtin_zlib', 'no'),
 	('glew', 'yes'),
 	("openssl", "yes"),
-	('freetype','yes'), #use system freetype
-
+	('freetype','yes'), # use system freetype
+	('libpng', 'system'),
 	#("theora","no"),
-        ]
+	]
 
 
 
@@ -143,6 +143,8 @@ def configure(env):
 	if (env["openssl"]=="yes"):
 		env.ParseConfig('pkg-config openssl --cflags --libs')
 
+	if (env["libpng"] == "system"):
+		env.ParseConfig('pkg-config libpng --cflags --libs')
 
 	if (env["freetype"]=="yes"):
 		env.ParseConfig('pkg-config freetype2 --cflags --libs')

+ 16 - 0
thirdparty/README.md

@@ -0,0 +1,16 @@
+# Third party libraries
+
+
+## libpng
+
+- Upstream: http://libpng.org/pub/png/libpng.html
+- Version: 1.6.23
+- License: libpng/zlib
+
+Files extracted from upstream source:
+
+- all .c and .h files of the main directory, except from:
+  * example.c
+  * pngtest.c
+- the arm/ folder
+- scripts/pnglibconf.h.prebuilt as pnglibconf.h

+ 130 - 0
thirdparty/libpng/LICENSE

@@ -0,0 +1,130 @@
+
+This copy of the libpng notices is provided for your convenience.  In case of
+any discrepancy between this copy and the notices in the file png.h that is
+included in the libpng distribution, the latter shall prevail.
+
+COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
+
+If you modify libpng you may insert additional notices immediately following
+this sentence.
+
+This code is released under the libpng license.
+
+libpng versions 1.0.7, July 1, 2000 through 1.6.23, June 9, 2016 are
+Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
+derived from libpng-1.0.6, and are distributed according to the same
+disclaimer and license as libpng-1.0.6 with the following individuals
+added to the list of Contributing Authors:
+
+   Simon-Pierre Cadieux
+   Eric S. Raymond
+   Mans Rullgard
+   Cosmin Truta
+   Gilles Vollant
+   James Yu
+
+and with the following additions to the disclaimer:
+
+   There is no warranty against interference with your enjoyment of the
+   library or against infringement.  There is no warranty that our
+   efforts or the library will fulfill any of your particular purposes
+   or needs.  This library is provided with all faults, and the entire
+   risk of satisfactory quality, performance, accuracy, and effort is with
+   the user.
+
+Some files in the "contrib" directory and some configure-generated
+files that are distributed with libpng have other copyright owners and
+are released under other open source licenses.
+
+libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
+Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
+libpng-0.96, and are distributed according to the same disclaimer and
+license as libpng-0.96, with the following individuals added to the list
+of Contributing Authors:
+
+   Tom Lane
+   Glenn Randers-Pehrson
+   Willem van Schaik
+
+libpng versions 0.89, June 1996, through 0.96, May 1997, are
+Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
+and are distributed according to the same disclaimer and license as
+libpng-0.88, with the following individuals added to the list of
+Contributing Authors:
+
+   John Bowler
+   Kevin Bracey
+   Sam Bushell
+   Magnus Holmgren
+   Greg Roelofs
+   Tom Tanner
+
+Some files in the "scripts" directory have other copyright owners
+but are released under this license.
+
+libpng versions 0.5, May 1995, through 0.88, January 1996, are
+Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
+
+For the purposes of this copyright and license, "Contributing Authors"
+is defined as the following set of individuals:
+
+   Andreas Dilger
+   Dave Martindale
+   Guy Eric Schalnat
+   Paul Schmidt
+   Tim Wegner
+
+The PNG Reference Library is supplied "AS IS".  The Contributing Authors
+and Group 42, Inc. disclaim all warranties, expressed or implied,
+including, without limitation, the warranties of merchantability and of
+fitness for any purpose.  The Contributing Authors and Group 42, Inc.
+assume no liability for direct, indirect, incidental, special, exemplary,
+or consequential damages, which may result from the use of the PNG
+Reference Library, even if advised of the possibility of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+source code, or portions hereof, for any purpose, without fee, subject
+to the following restrictions:
+
+  1. The origin of this source code must not be misrepresented.
+
+  2. Altered versions must be plainly marked as such and must not
+     be misrepresented as being the original source.
+
+  3. This Copyright notice may not be removed or altered from any
+     source or altered source distribution.
+
+The Contributing Authors and Group 42, Inc. specifically permit, without
+fee, and encourage the use of this source code as a component to
+supporting the PNG file format in commercial products.  If you use this
+source code in a product, acknowledgment is not required but would be
+appreciated.
+
+END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
+
+TRADEMARK:
+
+The name "libpng" has not been registered by the Copyright owner
+as a trademark in any jurisdiction.  However, because libpng has
+been distributed and maintained world-wide, continually since 1995,
+the Copyright owner claims "common-law trademark protection" in any
+jurisdiction where common-law trademark is recognized.
+
+OSI CERTIFICATION:
+
+Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is
+a certification mark of the Open Source Initiative. OSI has not addressed
+the additional disclaimers inserted at version 1.0.7.
+
+EXPORT CONTROL:
+
+The Copyright owner believes that the Export Control Classification
+Number (ECCN) for libpng is EAR99, which means not subject to export
+controls or International Traffic in Arms Regulations (ITAR) because
+it is open source, publicly available software, that does not contain
+any encryption software.  See the EAR, paragraphs 734.3(b)(3) and
+734.7(b).
+
+Glenn Randers-Pehrson
+glennrp at users.sourceforge.net
+June 9, 2016

+ 0 - 0
drivers/png/arm/arm_init.c → thirdparty/libpng/arm/arm_init.c


+ 0 - 0
drivers/png/arm/filter_neon.S → thirdparty/libpng/arm/filter_neon.S


+ 0 - 0
drivers/png/arm/filter_neon_intrinsics.c → thirdparty/libpng/arm/filter_neon_intrinsics.c


+ 0 - 0
drivers/png/png.c → thirdparty/libpng/png.c


+ 0 - 0
drivers/png/png.h → thirdparty/libpng/png.h


+ 0 - 0
drivers/png/pngconf.h → thirdparty/libpng/pngconf.h


+ 0 - 0
drivers/png/pngdebug.h → thirdparty/libpng/pngdebug.h


+ 0 - 0
drivers/png/pngerror.c → thirdparty/libpng/pngerror.c


+ 0 - 0
drivers/png/pngget.c → thirdparty/libpng/pngget.c


+ 0 - 0
drivers/png/pnginfo.h → thirdparty/libpng/pnginfo.h


+ 0 - 0
drivers/png/pnglibconf.h → thirdparty/libpng/pnglibconf.h


+ 0 - 0
drivers/png/pngmem.c → thirdparty/libpng/pngmem.c


+ 0 - 0
drivers/png/pngpread.c → thirdparty/libpng/pngpread.c


+ 0 - 0
drivers/png/pngpriv.h → thirdparty/libpng/pngpriv.h


+ 0 - 0
drivers/png/pngread.c → thirdparty/libpng/pngread.c


+ 0 - 0
drivers/png/pngrio.c → thirdparty/libpng/pngrio.c


+ 0 - 0
drivers/png/pngrtran.c → thirdparty/libpng/pngrtran.c


+ 0 - 0
drivers/png/pngrutil.c → thirdparty/libpng/pngrutil.c


+ 0 - 0
drivers/png/pngset.c → thirdparty/libpng/pngset.c


+ 0 - 0
drivers/png/pngstruct.h → thirdparty/libpng/pngstruct.h


+ 0 - 0
drivers/png/pngtrans.c → thirdparty/libpng/pngtrans.c


+ 0 - 0
drivers/png/pngwio.c → thirdparty/libpng/pngwio.c


+ 0 - 0
drivers/png/pngwrite.c → thirdparty/libpng/pngwrite.c


+ 0 - 0
drivers/png/pngwtran.c → thirdparty/libpng/pngwtran.c


+ 0 - 0
drivers/png/pngwutil.c → thirdparty/libpng/pngwutil.c