[Scummvm-git-logs] scummvm master -> 716fc4f568ad5eb1c0b532a394f327c433e9b076

dreammaster noreply at scummvm.org
Fri Jan 19 05:57:40 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:
716fc4f568 M4: Fixes for initial display of save dialog


Commit: 716fc4f568ad5eb1c0b532a394f327c433e9b076
    https://github.com/scummvm/scummvm/commit/716fc4f568ad5eb1c0b532a394f327c433e9b076
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2024-01-18T21:57:24-08:00

Commit Message:
M4: Fixes for initial display of save dialog

Changed paths:
    engines/m4/burger/gui/game_menu.cpp
    engines/m4/graphics/gr_sprite.cpp
    engines/m4/graphics/gr_sprite.h


diff --git a/engines/m4/burger/gui/game_menu.cpp b/engines/m4/burger/gui/game_menu.cpp
index e46db29841a..7912a9789ea 100644
--- a/engines/m4/burger/gui/game_menu.cpp
+++ b/engines/m4/burger/gui/game_menu.cpp
@@ -56,7 +56,7 @@ void CreateLoadMenu(RGB8 *myPalette);
 Sprite *menu_CreateThumbnail(int32 *spriteSize) {
 	Sprite *thumbNailSprite;
 	GrBuff *thumbNail;
-	Buffer *scrnBuff, *intrBuff, *destBuff;
+	Buffer *scrnBuff, *intrBuff, *destBuff, RLE8Buff;
 	uint8 *srcPtr, *srcPtr2, *srcPtr3, *srcRowPtr, *destPtr;
 	ScreenContext *gameScreen;
 	int32 i, status;
@@ -204,16 +204,27 @@ Sprite *menu_CreateThumbnail(int32 *spriteSize) {
 		memset(destPtr, 21, (destBuff->h - (currRow / 3)) * destBuff->stride);
 	}
 
+	// Compress the thumbNail data into the RLE8Buff
+	if ((*spriteSize = (int32)gr_sprite_RLE8_encode(destBuff, &RLE8Buff)) <= 0) {
+		return nullptr;
+	}
+
 	// Fill in the Sprite structure
 	thumbNailSprite->w = destBuff->w;
 	thumbNailSprite->h = destBuff->h;
-	thumbNailSprite->encoding = NO_COMPRESS;
-	thumbNailSprite->data = destBuff->data;
+	thumbNailSprite->encoding = RLE8;
+	thumbNailSprite->data = nullptr;
 	if ((thumbNailSprite->sourceHandle = NewHandle(*spriteSize, "thumbNail source")) == nullptr) {
 		return nullptr;
 	}
 	thumbNailSprite->sourceOffset = 0;
 
+	// Now copy the RLE8Buff into the thumbNail source handle
+	HLock(thumbNailSprite->sourceHandle);
+	thumbNailSprite->data = (uint8 *)(*(thumbNailSprite->sourceHandle));
+	memcpy(thumbNailSprite->data, RLE8Buff.data, *spriteSize);
+	HUnLock(thumbNailSprite->sourceHandle);
+
 	// Release all buffers
 	_G(gameDrawBuff)->release();
 	if (intrBuff) {
@@ -221,8 +232,9 @@ Sprite *menu_CreateThumbnail(int32 *spriteSize) {
 	}
 	thumbNail->release();
 
-	// Free up the thumbNail
+	// Free up both the thumbNail and the RLE8Buff
 	delete thumbNail;
+	mem_free((void *)RLE8Buff.data);
 
 	return thumbNailSprite;
 }
@@ -2390,7 +2402,8 @@ bool menu_EventHandler(void *theMenu, int32 eventType, int32 parm1, int32 parm2,
 
 	// Initialize the vars
 	handled = false;
-	*currScreen = false;
+	if (currScreen)
+		*currScreen = false;
 
 	// Make sure the screen exists and is active
 	myScreen = vmng_screen_find(theMenu, &status);
diff --git a/engines/m4/graphics/gr_sprite.cpp b/engines/m4/graphics/gr_sprite.cpp
index 09994ed0787..9e2f0e97a8a 100644
--- a/engines/m4/graphics/gr_sprite.cpp
+++ b/engines/m4/graphics/gr_sprite.cpp
@@ -108,6 +108,7 @@ uint8 gr_sprite_draw(DrawRequest *drawReq) {
 
 	// Copy DrawReq->Src to source buffer
 	source = *drawReq->Src;
+	assert(source.data);
 
 	// if it's RLE encoded, ensure the sprite will decode to match the expected size
 	if (source.encoding & RLE8) {
@@ -176,4 +177,83 @@ uint8 gr_sprite_draw(DrawRequest *drawReq) {
 	return 0;
 }
 
+//----------------------------------------------------------------------------------------
+//RLE8 COMPRESSION CODE...
+
+#define ESC     ((uint8)0)
+#define EOL	((uint8)0)
+#define EOB	((uint8)1)
+#define DELTA	((uint8)2)
+
+#define OutBuffSize(x)	((x) + (((x) + 254) / 255 + 1) * 2 + 2)
+
+static uint16 EncodeScan(uint8 *pi, uint8 *po, uint16 scanlen, uint8 EndByte) {
+	uint8 *ps = pi + 1;
+	uint16 outlen = 0, limit, run;
+
+	while (scanlen) {
+		limit = (scanlen < 255) ? scanlen : 255;
+		//imath_min(scanlen, 255);
+		for (run = 1; run < limit && *pi == *ps; ++run, ++ps) {}
+
+		if (run > 1) {
+			scanlen -= run;
+			*po++ = run;
+			*po++ = *pi;
+			outlen += 2;
+			pi = ps++;
+		} else if (scanlen < 3) {
+			for (; scanlen; --scanlen) {
+				*po++ = 1;
+				*po++ = *pi++;
+				outlen += 2;
+			}
+		} else {
+			--ps;
+			do {
+				++ps;
+				while ((*ps != *(ps + 1) || *ps != *(ps + 2) || *ps != *(ps + 3)) && (ps - pi) < limit)
+					++ps;
+			} while ((run = ps - pi) < 3);
+
+			scanlen -= run;
+			*po++ = ESC;
+			*po++ = run;
+			outlen += (run + 2);
+
+			for (limit = 0; limit < run; ++limit)
+				*po++ = *pi++;
+			++ps;
+		}
+	}
+
+	*po++ = ESC;
+	*po = EndByte;
+	outlen += 2;
+	return outlen;
+}
+
+uint32 gr_sprite_RLE8_encode(Buffer *Source, Buffer *Dest) {
+	int i;
+	uint32 Offset = 0;
+
+	Dest->w = Source->w;
+	Dest->h = Source->h;
+	Dest->encoding = RLE8;
+	Dest->stride = Source->stride;
+
+	if (!(Dest->data = (uint8 *)mem_alloc(Source->h * OutBuffSize(Source->stride), "sprite data"))) {
+		return 0;
+	}
+
+	for (i = 0; i < Source->h - 1; ++i)
+		Offset += EncodeScan(Source->data + i * Source->stride, Dest->data + Offset, Source->w, EOL);
+
+	Offset += EncodeScan(Source->data + i * Source->stride, Dest->data + Offset, Source->w, EOB);
+
+	Dest->data = (uint8 *)mem_realloc(Dest->data, Offset, "rle8 sprite data");
+
+	return Offset;
+}
+
 } // namespace M4
diff --git a/engines/m4/graphics/gr_sprite.h b/engines/m4/graphics/gr_sprite.h
index 058ae4a4bba..3e050f79fa6 100644
--- a/engines/m4/graphics/gr_sprite.h
+++ b/engines/m4/graphics/gr_sprite.h
@@ -49,7 +49,6 @@ struct DrawRequest {
 
 uint32 gr_sprite_RLE8_encode(Buffer *Source, Buffer *Dest);
 uint8 gr_sprite_draw(DrawRequest *DrawReq);
-void gr_sprite_draw_scaled(M4sprite *srcSprite, Buffer *destBuf, int32 destX, int32 destY, int32 scale);
 
 } // namespace M4
 




More information about the Scummvm-git-logs mailing list