[Scummvm-git-logs] scummvm branch-2-9 -> 6afb5ec11cf8497ebb1f8418595b3156c5eb6236

lephilousophe noreply at scummvm.org
Sat Dec 28 12:16:34 UTC 2024


This automated email contains information about 7 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6522ca8e60 PSP: Fix PNG palette loading
4c645e728b PSP: Better error handling and reporting for PNG loading
90a03e754f PSP: Avoid parsing the PNG headers twice
643707a389 BUILD: On PSP -O3 and dynamic detection work well now
2316334bb5 COMMON: Remove undefined behaviours from RNC decoder
fa0cc818e7 BACKENDS: ANDROID: Add build script for release
6afb5ec11c BACKENDS: ANDROID: Make the build script executable


Commit: 6522ca8e60ac62d11256e22e34225ab2fc3b61ab
    https://github.com/scummvm/scummvm/commit/6522ca8e60ac62d11256e22e34225ab2fc3b61ab
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-12-28T13:12:29+01:00

Commit Message:
PSP: Fix PNG palette loading

libpng never returns the palette size when the palette pointer argument
is nullptr.
If it worked before, it's because paletteSize was uninitialized and luck.

Changed paths:
    backends/platform/psp/png_loader.cpp


diff --git a/backends/platform/psp/png_loader.cpp b/backends/platform/psp/png_loader.cpp
index 4cc443028bb..eba6bf43bfc 100644
--- a/backends/platform/psp/png_loader.cpp
+++ b/backends/platform/psp/png_loader.cpp
@@ -129,8 +129,10 @@ bool PngLoader::basicImageLoad() {
 	_channels = png_get_channels(_pngPtr, _infoPtr);
 
 	if (_colorType & PNG_COLOR_MASK_PALETTE) {
-		int paletteSize;
-		png_get_PLTE(_pngPtr, _infoPtr, nullptr, &paletteSize);
+		int paletteSize = 0;
+		png_colorp palettePtr = nullptr;
+		png_uint_32 ret = png_get_PLTE(_pngPtr, _infoPtr, &palettePtr, &paletteSize);
+		assert(ret == PNG_INFO_PLTE);
 		_paletteSize = paletteSize;
 	}
 


Commit: 4c645e728be3d1a0bf20d472502c77ef2d0afc05
    https://github.com/scummvm/scummvm/commit/4c645e728be3d1a0bf20d472502c77ef2d0afc05
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-12-28T13:12:53+01:00

Commit Message:
PSP: Better error handling and reporting for PNG loading

Changed paths:
    backends/platform/psp/png_loader.cpp
    backends/platform/psp/png_loader.h


diff --git a/backends/platform/psp/png_loader.cpp b/backends/platform/psp/png_loader.cpp
index eba6bf43bfc..b383a7f0acb 100644
--- a/backends/platform/psp/png_loader.cpp
+++ b/backends/platform/psp/png_loader.cpp
@@ -93,6 +93,13 @@ bool PngLoader::load() {
 
 void PngLoader::warningFn(png_structp png_ptr, png_const_charp warning_msg) {
 	// ignore PNG warnings
+	PSP_ERROR("Got PNG warning: %s\n", warning_msg);
+}
+
+void PngLoader::errorFn(png_structp png_ptr, png_const_charp error_msg) {
+	// ignore PNG warnings
+	PSP_ERROR("Got PNG error: %s\n", error_msg);
+	abort();
 }
 
 // Read function for png library to be able to read from our SeekableReadStream
@@ -100,7 +107,8 @@ void PngLoader::warningFn(png_structp png_ptr, png_const_charp warning_msg) {
 void PngLoader::libReadFunc(png_structp pngPtr, png_bytep data, png_size_t length) {
 	Common::SeekableReadStream &file = *(Common::SeekableReadStream *)png_get_io_ptr(pngPtr);
 
-	file.read(data, length);
+	uint32 ret = file.read(data, length);
+	assert(ret == length);
 }
 
 bool PngLoader::basicImageLoad() {
@@ -109,7 +117,7 @@ bool PngLoader::basicImageLoad() {
 	if (!_pngPtr)
 		return false;
 
-	png_set_error_fn(_pngPtr, (png_voidp) nullptr, (png_error_ptr) nullptr, warningFn);
+	png_set_error_fn(_pngPtr, (png_voidp) nullptr, (png_error_ptr) errorFn, warningFn);
 
 	_infoPtr = png_create_info_struct(_pngPtr);
 	if (!_infoPtr) {
diff --git a/backends/platform/psp/png_loader.h b/backends/platform/psp/png_loader.h
index 7212292c318..80a18c9edcb 100644
--- a/backends/platform/psp/png_loader.h
+++ b/backends/platform/psp/png_loader.h
@@ -31,6 +31,7 @@ private:
 	bool loadImageIntoBuffer();
 
 	static void warningFn(png_structp png_ptr, png_const_charp warning_msg);
+	static void errorFn(png_structp png_ptr, png_const_charp warning_msg);
 	static void libReadFunc(png_structp pngPtr, png_bytep data, png_size_t length);
 
 	Common::SeekableReadStream &_file;


Commit: 90a03e754f78b6b2b1a5a08da2b418445ae30670
    https://github.com/scummvm/scummvm/commit/90a03e754f78b6b2b1a5a08da2b418445ae30670
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-12-28T13:12:53+01:00

Commit Message:
PSP: Avoid parsing the PNG headers twice

This avoids rewinding the stream which is always bad when loading the
PNG from a Zip archive.

Changed paths:
    backends/platform/psp/png_loader.cpp
    backends/platform/psp/png_loader.h


diff --git a/backends/platform/psp/png_loader.cpp b/backends/platform/psp/png_loader.cpp
index b383a7f0acb..77e9c170db2 100644
--- a/backends/platform/psp/png_loader.cpp
+++ b/backends/platform/psp/png_loader.cpp
@@ -33,6 +33,13 @@
 
 #include "backends/platform/psp/trace.h"
 
+PngLoader::~PngLoader() {
+	if (!_pngPtr) {
+		return;
+	}
+	png_destroy_read_struct(&_pngPtr, &_infoPtr, nullptr);
+}
+
 PngLoader::Status PngLoader::allocate() {
 	DEBUG_ENTER_FUNC();
 
@@ -76,9 +83,8 @@ PngLoader::Status PngLoader::allocate() {
 
 bool PngLoader::load() {
 	DEBUG_ENTER_FUNC();
-	// Try to load the image
-	_file.seek(0);	// Go back to start
 
+	// Try to really load the image
 	if (!loadImageIntoBuffer()) {
 		PSP_DEBUG_PRINT("failed to load image\n");
 		return false;
@@ -121,15 +127,11 @@ bool PngLoader::basicImageLoad() {
 
 	_infoPtr = png_create_info_struct(_pngPtr);
 	if (!_infoPtr) {
-		png_destroy_read_struct(&_pngPtr, nullptr, nullptr);
 		return false;
 	}
 	// Set the png lib to use our read function
 	png_set_read_fn(_pngPtr, &_file, libReadFunc);
 
-	unsigned int sig_read = 0;
-
-	png_set_sig_bytes(_pngPtr, sig_read);
 	png_read_info(_pngPtr, _infoPtr);
 	int interlaceType;
 	png_get_IHDR(_pngPtr, _infoPtr, (png_uint_32 *)&_width, (png_uint_32 *)&_height, &_bitDepth,
@@ -154,7 +156,6 @@ bool PngLoader::findImageDimensions() {
 	bool status = basicImageLoad();
 
 	PSP_DEBUG_PRINT("width[%d], height[%d], paletteSize[%d], bitDepth[%d], channels[%d], rowBytes[%d]\n", _width, _height, _paletteSize, _bitDepth, _channels, png_get_rowbytes(_pngPtr, _infoPtr));
-	png_destroy_read_struct(&_pngPtr, &_infoPtr, nullptr);
 	return status;
 }
 
@@ -164,10 +165,9 @@ bool PngLoader::findImageDimensions() {
 bool PngLoader::loadImageIntoBuffer() {
 	DEBUG_ENTER_FUNC();
 
-	if (!basicImageLoad()) {
-		png_destroy_read_struct(&_pngPtr, &_infoPtr, nullptr);
-		return false;
-	}
+	// Everything has already been set up in allocate
+	assert(_pngPtr);
+
 	png_set_strip_16(_pngPtr);		// Strip off 16 bit channels in case they occur
 
 	if (_paletteSize) {
@@ -206,7 +206,6 @@ bool PngLoader::loadImageIntoBuffer() {
 
 	unsigned char *line = (unsigned char*) malloc(rowBytes);
 	if (!line) {
-		png_destroy_read_struct(&_pngPtr, nullptr, nullptr);
 		PSP_ERROR("Couldn't allocate line\n");
 		return false;
 	}
@@ -217,7 +216,6 @@ bool PngLoader::loadImageIntoBuffer() {
 	}
 	free(line);
 	png_read_end(_pngPtr, _infoPtr);
-	png_destroy_read_struct(&_pngPtr, &_infoPtr, nullptr);
 
 	return true;
 }
diff --git a/backends/platform/psp/png_loader.h b/backends/platform/psp/png_loader.h
index 80a18c9edcb..975678045aa 100644
--- a/backends/platform/psp/png_loader.h
+++ b/backends/platform/psp/png_loader.h
@@ -63,6 +63,7 @@ public:
 			_width(0), _height(0), _paletteSize(0),
 			_bitDepth(0), _sizeBy(sizeBy), _pngPtr(0),
 			_infoPtr(0), _colorType(0), _channels(0) {}
+	~PngLoader();
 
 	PngLoader::Status allocate();
 	bool load();


Commit: 643707a389f4ebf4b3ac392f22ad804201fca903
    https://github.com/scummvm/scummvm/commit/643707a389f4ebf4b3ac392f22ad804201fca903
Author: rsn8887 (rsn8887 at users.noreply.github.com)
Date: 2024-12-28T13:12:53+01:00

Commit Message:
BUILD: On PSP -O3 and dynamic detection work well now

Changed paths:
    configure


diff --git a/configure b/configure
index cacc10675e3..b0e0fbce084 100755
--- a/configure
+++ b/configure
@@ -3367,8 +3367,12 @@ EOF
 		add_line_to_config_h "#define PREFIX \"${prefix}\""
 		;;
 	psp)
-		_optimization_level=-O2
+		_optimization_level=-O3
 		_freetypepath="$PSPDEV/psp/bin"
+		if test "$_dynamic_modules" = yes ; then
+			_detection_features_static=no
+			_plugins_default=dynamic
+		fi
 		append_var CXXFLAGS "-I$PSPSDK/include"
 		# FIXME: Why is the following in CXXFLAGS and not in DEFINES? Change or document this.
 		append_var CXXFLAGS "-D_PSP_FW_VERSION=150"


Commit: 2316334bb5ad817df13b48e96c0c185246e17c46
    https://github.com/scummvm/scummvm/commit/2316334bb5ad817df13b48e96c0c185246e17c46
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-12-28T13:14:58+01:00

Commit Message:
COMMON: Remove undefined behaviours from RNC decoder

Shifting an amount of 16 on a 16 bits variable is UB.
Make the variables larger to not fall inside it and avoid branches.

Changed paths:
    common/compression/rnc_deco.cpp


diff --git a/common/compression/rnc_deco.cpp b/common/compression/rnc_deco.cpp
index 9f3151f92c5..103425d20de 100644
--- a/common/compression/rnc_deco.cpp
+++ b/common/compression/rnc_deco.cpp
@@ -86,17 +86,20 @@ uint16 RncDecoder::crcBlock(const uint8 *block, uint32 size) {
 }
 
 uint16 RncDecoder::inputBits(uint8 amount) {
-	uint16 newBitBuffh = _bitBuffh;
-	uint16 newBitBuffl = _bitBuffl;
+	// Although we are manipulating 16 bits values, use 32 bits variables
+	// This avoids triggering UB when shifting an amount of 0 or 16.
+	uint32 newBitBuffh = _bitBuffh;
+	uint32 newBitBuffl = _bitBuffl;
 	int16 newBitCount = _bitCount;
-	uint16 remBits, returnVal;
+	uint32 remBits;
+	uint16 returnVal;
 
 	returnVal = ((1 << amount) - 1) & newBitBuffl;
 	newBitCount -= amount;
 
 	if (newBitCount < 0) {
 		newBitCount += amount;
-		remBits = (newBitBuffh << (16 - newBitCount));
+		remBits = (newBitBuffh << (16 - newBitCount)) & 0xffff;
 		newBitBuffh >>= newBitCount;
 		newBitBuffl >>= newBitCount;
 		newBitBuffl |= remBits;
@@ -114,7 +117,7 @@ uint16 RncDecoder::inputBits(uint8 amount) {
 		amount -= newBitCount;
 		newBitCount = 16 - amount;
 	}
-	remBits = (newBitBuffh << (16 - amount));
+	remBits = (newBitBuffh << (16 - amount)) & 0xffff;
 	_bitBuffh = newBitBuffh >> amount;
 	_bitBuffl = (newBitBuffl >> amount) | remBits;
 	_bitCount = (uint8)newBitCount;


Commit: fa0cc818e737f7a5efa8249c3c3db492baee5d6d
    https://github.com/scummvm/scummvm/commit/fa0cc818e737f7a5efa8249c3c3db492baee5d6d
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-12-28T13:15:11+01:00

Commit Message:
BACKENDS: ANDROID: Add build script for release

It builds a fat AAB for Google Play submission and several slim APKs for
the website.
It also uses the proper flags for configure and handles games bundling.

Changed paths:
  A backends/platform/android/build-release.sh


diff --git a/backends/platform/android/build-release.sh b/backends/platform/android/build-release.sh
new file mode 100644
index 00000000000..cb2c3202908
--- /dev/null
+++ b/backends/platform/android/build-release.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+
+set -ex
+
+# Run from the build folder
+
+ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/../../.." && pwd)
+NPROC=$(nproc)
+
+if [ -n "$1" ]; then
+	GAMES_FOLDER=$(CDPATH= cd -- "$1" && pwd)
+fi
+
+# Get the version code and patch it for every build
+VERSION_CODE=$(sed -n -e '/versionCode /s/[\t ]*versionCode //p' "${ROOT}/dists/android/build.gradle")
+# Make sure the last digit is 0
+VERSION_CODE=$((${VERSION_CODE} / 10 * 10))
+
+patch_version() {
+	local dir
+	dir=$2
+	if [ -z "$dir" ]; then
+		dir=.
+	fi
+	# Make sure the file exists before patching
+	make -C "$dir" android_project/build.gradle
+	sed -i -e "/versionCode /s/\\([\t ]*versionCode \\).*/\\1$1/" "$dir/android_project/build.gradle"
+}
+
+# We don't handle games change correctly, force refresh
+rm -rf "./android_project/mainAssets/src/main/assets/assets/games"
+
+"${ROOT}/configure" --host=android-arm-v7a --disable-debug --enable-release
+
+# Make sure we use the proper versionCode
+patch_version ${VERSION_CODE}
+
+# Build an AAB bundle with games
+make -j${NPROC} androidfatbundlerelease GAMES_BUNDLE_DIRECTORY="$GAMES_FOLDER"
+
+# For APK strip out the games
+if [ -n "$GAMES_FOLDER" ]; then
+	rm -rf "./android_project/mainAssets/src/main/assets/assets/games"
+fi
+
+# Reuse what we just built to create APKs
+
+# Cleanup fat shared objects
+rm -rf ./android_project/lib/*
+
+plat_build() {
+	local subcode subarch subbuild
+	subcode=$1
+	subarch=$2
+	subbuild=$3
+	if [ -z "$subbuild" ]; then
+		subbuild=build-android${subarch}
+	fi
+	patch_version $((${VERSION_CODE} + ${subcode})) "${subbuild}"
+	make -j${NPROC} -C ${subbuild} androidrelease
+	mv ${subbuild}/ScummVM-release-unsigned.apk ScummVM-release-unsigned-${subarch}.apk
+}
+
+# Build ARMv7a with versionCode 1
+plat_build 1 armeabi-v7a .
+
+# Build ARM64 with versionCode 2
+plat_build 2 arm64-v8a
+
+# Build x86 with versionCode 3
+plat_build 3 x86
+
+# Build x86_64 with versionCode 4
+plat_build 4 x86_64


Commit: 6afb5ec11cf8497ebb1f8418595b3156c5eb6236
    https://github.com/scummvm/scummvm/commit/6afb5ec11cf8497ebb1f8418595b3156c5eb6236
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-12-28T13:15:11+01:00

Commit Message:
BACKENDS: ANDROID: Make the build script executable

Changed paths:
    backends/platform/android/build-release.sh


diff --git a/backends/platform/android/build-release.sh b/backends/platform/android/build-release.sh
old mode 100644
new mode 100755




More information about the Scummvm-git-logs mailing list