[Scummvm-git-logs] scummvm master -> fa5bb0d5897df8c7384d6996f35b9bf839f2fb32

dreammaster noreply at scummvm.org
Fri May 24 04:59:08 UTC 2024


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

Summary:
fa5bb0d589 M4: Further endian fixes


Commit: fa5bb0d5897df8c7384d6996f35b9bf839f2fb32
    https://github.com/scummvm/scummvm/commit/fa5bb0d5897df8c7384d6996f35b9bf839f2fb32
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2024-05-23T21:59:04-07:00

Commit Message:
M4: Further endian fixes

Changed paths:
    engines/m4/wscript/ws_load.cpp


diff --git a/engines/m4/wscript/ws_load.cpp b/engines/m4/wscript/ws_load.cpp
index a492ddca782..04159294e4e 100644
--- a/engines/m4/wscript/ws_load.cpp
+++ b/engines/m4/wscript/ws_load.cpp
@@ -841,7 +841,6 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
 	byteSwap = false;
 	// If the chunk is PAL info - celsType == CELS_LAP_ indicates the chunk needs to be byte-swapped.
 	if ((*celsType == CELS__PAL) || (*celsType == CELS_LAP_)) {
-
 		// Read the chunk size, and the number of palette colors, and byte-swap if necessary
 		if (!GetNextint32(parseAssetPtr, endOfAssetBlock, celsSize)) {
 			ws_LogErrorMsg(FL, "Unable to read the SS PAL chunk size.");
@@ -892,10 +891,11 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
 		if (myPalette) {
 			tempPtr = (int32 *)(&palData[1]);
 			for (i = 0; i < *numColors; i++) {
-				j = (*tempPtr & 0xff000000) >> 24;
-				myPalette[j].r = (*tempPtr & 0x00ff0000) >> 14;
-				myPalette[j].g = (*tempPtr & 0x0000ff00) >> 6;
-				myPalette[j].b = (*tempPtr & 0x000000ff) << 2;
+				uint rgb = READ_LE_UINT32(tempPtr);
+				j = (rgb & 0xff000000) >> 24;
+				myPalette[j].r = (rgb & 0x00ff0000) >> 14;
+				myPalette[j].g = (rgb & 0x0000ff00) >> 6;
+				myPalette[j].b = (rgb & 0x000000ff) << 2;
 				tempPtr++;
 			}
 		}
@@ -944,7 +944,6 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
 
 	// Check to see if we need to byte-swap the header information.
 	if (byteSwap) {
-
 		// The chunk header begins at (*data)[2]
 		// byte-swap the entire chunk header
 		tempPtr = &(data[2]);
@@ -953,7 +952,7 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
 			tempPtr++;
 		}
 
-		if ((int32)(data[CELS_COUNT]) <= 0) {
+		if (FROM_LE_32(data[CELS_COUNT]) <= 0) {
 			ws_LogErrorMsg(FL, "SS info has been corrupted");
 			return -1;
 		}
@@ -962,7 +961,7 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
 		// offsets into the chunk, which indicate where each individual sprite can be found.
 		offsetPtr = &(data[CELS_OFFSETS]);
 		tempPtr = offsetPtr;
-		for (i = 0; i < data[CELS_COUNT]; i++) {
+		for (i = 0; i < (int32)FROM_LE_32(data[CELS_COUNT]); i++) {
 			*tempPtr = SWAP_INT32(*tempPtr);
 			tempPtr++;
 		}
@@ -970,8 +969,7 @@ static int32 ProcessCELS(const char * /*assetName*/, char **parseAssetPtr, char
 		// dataPtr points to the beginning of the block which is a concatenation of
 		// all the sprites.  Loop through and byteswap each individual sprite header.
 		dataPtr = tempPtr;
-		for (i = 0; i < data[CELS_COUNT]; i++) {
-
+		for (i = 0; i < (int32)FROM_LE_32(data[CELS_COUNT]); i++) {
 			// The beginning of sprite i is the dataPtr + the number of bytes in the offset table
 			tempPtr = (int32 *)((intptr)dataPtr + offsetPtr[i]);
 
@@ -998,10 +996,11 @@ static void RestoreSSPaletteInfo(RGB8 *myPalette, int32 *palPtr) {
 	if (myPalette) {
 		tempPtr = (uint32 *)(&palPtr[1]);
 		for (i = 0; i < FROM_LE_32(palPtr[0]); i++) {
-			j = (*tempPtr & 0xff000000) >> 24;
-			myPalette[j].r = (FROM_LE_32(*tempPtr) & 0x00ff0000) >> 14;
-			myPalette[j].g = (FROM_LE_32(*tempPtr) & 0x0000ff00) >> 6;
-			myPalette[j].b = (FROM_LE_32(*tempPtr) & 0x000000ff) << 2;
+			uint32 rgb = READ_LE_UINT32(tempPtr);
+			j = (rgb & 0xff000000) >> 24;
+			myPalette[j].r = (rgb & 0x00ff0000) >> 14;
+			myPalette[j].g = (rgb & 0x0000ff00) >> 6;
+			myPalette[j].b = (rgb & 0x000000ff) << 2;
 			tempPtr++;
 		}
 	}
@@ -1218,7 +1217,7 @@ int32 GetWSAssetCELCount(uint32 hash) {
 
 	// Find and return the number of sprites in the SS
 	celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
-	return celsPtr[CELS_COUNT];
+	return FROM_LE_32(celsPtr[CELS_COUNT]);
 }
 
 
@@ -1245,7 +1244,7 @@ int32 GetWSAssetCELFrameRate(uint32 hash) {
 
 	// Find and return the frame rate for the SS
 	celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
-	return celsPtr[CELS_FRAME_RATE];
+	return FROM_LE_32(celsPtr[CELS_FRAME_RATE]);
 }
 
 
@@ -1272,7 +1271,7 @@ int32 GetWSAssetCELPixSpeed(uint32 hash) {
 
 	// Find and return the pix speed for the SS
 	celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
-	return celsPtr[CELS_PIX_SPEED];
+	return FROM_LE_32(celsPtr[CELS_PIX_SPEED]);
 }
 
 int32 ws_get_sprite_width(uint32 hash, int32 index) {
@@ -1301,7 +1300,7 @@ int32 ws_get_sprite_width(uint32 hash, int32 index) {
 	celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
 
 	// Check that the index into the series requested is within a valid range
-	numCels = celsPtr[CELS_COUNT];
+	numCels = FROM_LE_32(celsPtr[CELS_COUNT]);
 	if (index >= numCels) {
 		ws_LogErrorMsg(FL, "ws_get_sprite_width: Sprite index out of range - max index: %d, requested index: %d, hash: %d",
 			numCels - 1, index, hash);
@@ -1315,9 +1314,9 @@ int32 ws_get_sprite_width(uint32 hash, int32 index) {
 	data = &celsPtr[CELS_OFFSETS + numCels];
 
 	// Find the sprite data for the specific sprite in the series
-	myCelSource = (uint32 *)((intptr)data + offsets[index]);
+	myCelSource = (uint32 *)((intptr)data + FROM_LE_32(offsets[index]));
 
-	return myCelSource[CELS_W];
+	return FROM_LE_32(myCelSource[CELS_W]);
 }
 
 int32 ws_get_sprite_height(uint32 hash, int32 index) {
@@ -1346,7 +1345,7 @@ int32 ws_get_sprite_height(uint32 hash, int32 index) {
 	celsPtr = (uint32 *)((intptr)*(_GWS(globalCELSHandles)[hash]) + (uint32)(_GWS(globalCELSoffsets)[hash]));
 
 	// Check that the index into the series requested is within a valid range
-	numCels = celsPtr[CELS_COUNT];
+	numCels = FROM_LE_32(celsPtr[CELS_COUNT]);
 	if (index >= numCels) {
 		ws_LogErrorMsg(FL, "ws_get_sprite_height: Sprite index out of range - max index: %d, requested index: %d, hash: %d",
 			numCels - 1, index, hash);
@@ -1360,9 +1359,9 @@ int32 ws_get_sprite_height(uint32 hash, int32 index) {
 	data = &celsPtr[CELS_OFFSETS + numCels];
 
 	// Find the sprite data for the specific sprite in the series
-	myCelSource = (uint32 *)((intptr)data + offsets[index]);
+	myCelSource = (uint32 *)((intptr)data + FROM_LE_32(offsets[index]));
 
-	return myCelSource[CELS_H];
+	return FROM_LE_32(myCelSource[CELS_H]);
 }
 
 MemHandle ws_GetSEQU(uint32 hash, int32 *numLocalVars, int32 *offset) {
@@ -1719,7 +1718,7 @@ bool ws_OpenSSstream(SysFile *sysFile, Anim8 *anim8) {
 
 	// Automatically set some of the sequence registers
 	celsPtr = myCCB->streamSSHeader;
-	numSprites = celsPtr[CELS_COUNT];
+	numSprites = FROM_LE_32(celsPtr[CELS_COUNT]);
 	myRegs[IDX_CELS_INDEX] = -(1 << 16);	// First frame inc will make it 0
 	myRegs[IDX_CELS_COUNT] = numSprites << 16;
 	myRegs[IDX_CELS_FRAME_RATE] = celsPtr[CELS_FRAME_RATE] << 16;
@@ -1809,13 +1808,14 @@ bool ws_GetNextSSstreamCel(Anim8 *anim8) {
 
 	// Check whether the end of the SS has been streamed
 	frameNum = anim8->myRegs[IDX_CELS_INDEX] >> 16;
-	if (frameNum >= celsPtr[CELS_COUNT]) {
+	if (frameNum >= FROM_LE_32(celsPtr[CELS_COUNT])) {
 		ws_LogErrorMsg(FL, "No more frames available to stream");
 		return false;
 	}
 
 	// Read the next sprite from the stream.  Note the offset table was converted to absolute size when the stream was opened.
-	if (f_stream_Read((strmRequest *)myCCB->myStream, (uint8 **)(&myCCB->streamSpriteSource), offsets[frameNum]) < (int)offsets[frameNum]) {
+	if (f_stream_Read((strmRequest *)myCCB->myStream, (uint8 **)(&myCCB->streamSpriteSource), FROM_LE_32(offsets[frameNum]))
+			< (int32)FROM_LE_32(offsets[frameNum])) {
 		ws_LogErrorMsg(FL, "Unable to read the next stream frame");
 		return false;
 	}
@@ -1829,15 +1829,12 @@ bool ws_GetNextSSstreamCel(Anim8 *anim8) {
 	myCelSource = myCCB->streamSpriteSource;
 	mySprite = myCCB->source;
 
-	mySprite->xOffset = (int32)convert_intel32((uint32)myCelSource[CELS_X]);
-	mySprite->yOffset = (int32)convert_intel32((uint32)myCelSource[CELS_Y]);
-	mySprite->w = (int32)convert_intel32((uint32)myCelSource[CELS_W]);
-	mySprite->h = (int32)convert_intel32((uint32)myCelSource[CELS_H]);
+	mySprite->xOffset = FROM_LE_32(myCelSource[CELS_X]);
+	mySprite->yOffset = FROM_LE_32(myCelSource[CELS_Y]);
+	mySprite->w = FROM_LE_32(myCelSource[CELS_W]);
+	mySprite->h = FROM_LE_32(myCelSource[CELS_H]);
 
-	{
-		uint32 temp = (uint8)myCelSource[CELS_COMP];
-		mySprite->encoding = (uint8)convert_intel32(temp);
-	}
+	mySprite->encoding = (uint8)FROM_LE_32(myCelSource[CELS_COMP]);
 
 	mySprite->data = (uint8 *)&myCelSource[CELS_DATA];
 




More information about the Scummvm-git-logs mailing list