summaryrefslogtreecommitdiff
path: root/drivers/png
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/png')
-rw-r--r--drivers/png/SCsub19
-rw-r--r--drivers/png/image_loader_png.cpp11
-rw-r--r--drivers/png/image_loader_png.h4
-rw-r--r--drivers/png/png_driver_common.cpp12
-rw-r--r--drivers/png/png_driver_common.h9
-rw-r--r--drivers/png/resource_saver_png.cpp6
-rw-r--r--drivers/png/resource_saver_png.h6
7 files changed, 41 insertions, 26 deletions
diff --git a/drivers/png/SCsub b/drivers/png/SCsub
index db08be0c47..26508dc612 100644
--- a/drivers/png/SCsub
+++ b/drivers/png/SCsub
@@ -5,6 +5,9 @@ Import("env")
env_png = env.Clone()
# Thirdparty source files
+
+thirdparty_obj = []
+
if env["builtin_libpng"]:
thirdparty_dir = "#thirdparty/libpng/"
thirdparty_sources = [
@@ -41,7 +44,7 @@ if env["builtin_libpng"]:
env_thirdparty = env_png.Clone()
env_thirdparty.disable_warnings()
- env_thirdparty.add_source_files(env.drivers_sources, thirdparty_sources)
+ env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
if use_neon:
env_neon = env_thirdparty.Clone()
@@ -52,9 +55,17 @@ if env["builtin_libpng"]:
neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/filter_neon_intrinsics.c"))
neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/filter_neon.S"))
neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/palette_neon_intrinsics.c"))
- env.drivers_sources += neon_sources
+ thirdparty_obj += neon_sources
+
+ env.drivers_sources += thirdparty_obj
+
# Godot source files
-env_png.add_source_files(env.drivers_sources, "*.cpp")
-Export("env")
+driver_obj = []
+
+env_png.add_source_files(driver_obj, "*.cpp")
+env.drivers_sources += driver_obj
+
+# Needed to force rebuilding the driver files when the thirdparty library is updated.
+env.Depends(driver_obj, thirdparty_obj)
diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp
index 8af58a7ed7..854c6706e6 100644
--- a/drivers/png/image_loader_png.cpp
+++ b/drivers/png/image_loader_png.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,7 +31,7 @@
#include "image_loader_png.h"
#include "core/os/os.h"
-#include "core/print_string.h"
+#include "core/string/print_string.h"
#include "drivers/png/png_driver_common.h"
#include <string.h>
@@ -50,7 +50,7 @@ Error ImageLoaderPNG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force
f->close();
}
const uint8_t *reader = file_buffer.ptr();
- return PNGDriverCommon::png_to_image(reader, buffer_size, p_image);
+ return PNGDriverCommon::png_to_image(reader, buffer_size, p_force_linear, p_image);
}
void ImageLoaderPNG::get_recognized_extensions(List<String> *p_extensions) const {
@@ -61,7 +61,8 @@ Ref<Image> ImageLoaderPNG::load_mem_png(const uint8_t *p_png, int p_size) {
Ref<Image> img;
img.instance();
- Error err = PNGDriverCommon::png_to_image(p_png, p_size, img);
+ // the value of p_force_linear does not matter since it only applies to 16 bit
+ Error err = PNGDriverCommon::png_to_image(p_png, p_size, false, img);
ERR_FAIL_COND_V(err, Ref<Image>());
return img;
diff --git a/drivers/png/image_loader_png.h b/drivers/png/image_loader_png.h
index 0154be0398..b4a58616f6 100644
--- a/drivers/png/image_loader_png.h
+++ b/drivers/png/image_loader_png.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/drivers/png/png_driver_common.cpp b/drivers/png/png_driver_common.cpp
index 77d5e68826..9e848a2253 100644
--- a/drivers/png/png_driver_common.cpp
+++ b/drivers/png/png_driver_common.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -58,7 +58,7 @@ static bool check_error(const png_image &image) {
return false;
}
-Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) {
+Error png_to_image(const uint8_t *p_source, size_t p_size, bool p_force_linear, Ref<Image> p_image) {
png_image png_img;
zeromem(&png_img, sizeof(png_img));
png_img.version = PNG_IMAGE_VERSION;
@@ -99,6 +99,11 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) {
return ERR_UNAVAILABLE;
}
+ if (!p_force_linear) {
+ // assume 16 bit pngs without sRGB or gAMA chunks are in sRGB format
+ png_img.flags |= PNG_IMAGE_FLAG_16BIT_sRGB;
+ }
+
const png_uint_32 stride = PNG_IMAGE_ROW_STRIDE(png_img);
Vector<uint8_t> buffer;
Error err = buffer.resize(PNG_IMAGE_BUFFER_SIZE(png_img, stride));
@@ -198,5 +203,4 @@ Error image_to_png(const Ref<Image> &p_image, Vector<uint8_t> &p_buffer) {
return OK;
}
-
} // namespace PNGDriverCommon
diff --git a/drivers/png/png_driver_common.h b/drivers/png/png_driver_common.h
index 12129f034e..003b587913 100644
--- a/drivers/png/png_driver_common.h
+++ b/drivers/png/png_driver_common.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,17 +31,16 @@
#ifndef PNG_DRIVER_COMMON_H
#define PNG_DRIVER_COMMON_H
-#include "core/image.h"
+#include "core/io/image.h"
namespace PNGDriverCommon {
// Attempt to load png from buffer (p_source, p_size) into p_image
-Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image);
+Error png_to_image(const uint8_t *p_source, size_t p_size, bool p_force_linear, Ref<Image> p_image);
// Append p_image, as a png, to p_buffer.
// Contents of p_buffer is unspecified if error returned.
Error image_to_png(const Ref<Image> &p_image, Vector<uint8_t> &p_buffer);
-
} // namespace PNGDriverCommon
#endif
diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp
index 3a0b319a45..f47fc403cc 100644
--- a/drivers/png/resource_saver_png.cpp
+++ b/drivers/png/resource_saver_png.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,7 +30,7 @@
#include "resource_saver_png.h"
-#include "core/image.h"
+#include "core/io/image.h"
#include "core/os/file_access.h"
#include "drivers/png/png_driver_common.h"
#include "scene/resources/texture.h"
diff --git a/drivers/png/resource_saver_png.h b/drivers/png/resource_saver_png.h
index c32b383521..c924438224 100644
--- a/drivers/png/resource_saver_png.h
+++ b/drivers/png/resource_saver_png.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,7 +31,7 @@
#ifndef RESOURCE_SAVER_PNG_H
#define RESOURCE_SAVER_PNG_H
-#include "core/image.h"
+#include "core/io/image.h"
#include "core/io/resource_saver.h"
class ResourceSaverPNG : public ResourceFormatSaver {