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

bluegr noreply at scummvm.org
Tue Feb 3 20:05:19 UTC 2026


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

Summary:
0a34752638 IMAGE: Combine writeBMP() and writePalettedBMP()
9b41a94bf0 IMAGE: Support creating PNG images with palettes
7dd583c358 IMAGE: Avoid writing alpha channels to PNG files if not required
52414ed284 IMAGE: Remove unused parameter
aba2a17d9d IMAGE: Fix whitespace


Commit: 0a34752638723591fb25222729b2204678ebb0d2
    https://github.com/scummvm/scummvm/commit/0a34752638723591fb25222729b2204678ebb0d2
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2026-02-03T22:05:13+02:00

Commit Message:
IMAGE: Combine writeBMP() and writePalettedBMP()

Changed paths:
    image/bmp.cpp
    image/bmp.h


diff --git a/image/bmp.cpp b/image/bmp.cpp
index b498ca89229..6eaa375e69f 100644
--- a/image/bmp.cpp
+++ b/image/bmp.cpp
@@ -147,64 +147,37 @@ bool BitmapDecoder::loadStream(Common::SeekableReadStream &stream) {
 	return true;
 }
 
-bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette) {
+
+bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const Graphics::Palette &palette, uint paletteCount = 256) {
+	return writeBMP(out, input, palette.data(), palette.size());
+}
+
+bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette, uint paletteCount) {
+	const Graphics::PixelFormat requiredFormat_1byte = Graphics::PixelFormat::createFormatCLUT8();
 	const Graphics::PixelFormat requiredFormat_3byte = Graphics::PixelFormat::createFormatBGR24();
 
 	Graphics::Surface *tmp = NULL;
 	const Graphics::Surface *surface;
+	uint bitsPerPixel;
 
-	if (input.format == requiredFormat_3byte) {
+	if (input.format == requiredFormat_1byte) {
 		surface = &input;
+		bitsPerPixel = 8;
+	} else if (input.format == requiredFormat_3byte) {
+		surface = &input;
+		bitsPerPixel = 24;
+		paletteCount = 0;
 	} else {
 		surface = tmp = input.convertTo(requiredFormat_3byte, palette);
+		bitsPerPixel = 24;
+		paletteCount = 0;
 	}
 
-	int dstPitch = surface->w * 3;
-	int extraDataLength = (dstPitch % 4) ? 4 - (dstPitch % 4) : 0;
-	int padding = 0;
-
-	out.writeByte('B');
-	out.writeByte('M');
-	out.writeUint32LE(surface->h * dstPitch + 54);
-	out.writeUint32LE(0);
-	out.writeUint32LE(54);
-	out.writeUint32LE(40);
-	out.writeUint32LE(surface->w);
-	out.writeUint32LE(surface->h);
-	out.writeUint16LE(1);
-	out.writeUint16LE(24);
-	out.writeUint32LE(0);
-	out.writeUint32LE(0);
-	out.writeUint32LE(0);
-	out.writeUint32LE(0);
-	out.writeUint32LE(0);
-	out.writeUint32LE(0);
-
-
-	for (uint y = surface->h; y-- > 0;) {
-		out.write((const void *)surface->getBasePtr(0, y), dstPitch);
-		out.write(&padding, extraDataLength);
-	}
-
-	// free tmp surface
-	if (tmp) {
-		tmp->free();
-		delete tmp;
-	}
-
-	return true;
-}
-
-bool writePalettedBMP(Common::WriteStream &out, const Graphics::Surface &surface, const byte *palette) {
-	// We assume surface is already 8bpp indexed
-	// surface->pitch should be >= surface->w
-
-	const int bytesPerPixel = 1;
-	const int rowSize = surface.w * bytesPerPixel;
+	const int rowSize = surface->w * surface->format.bytesPerPixel;
 	const int rowPadding = (4 - (rowSize & 3)) & 3;
 
-	const uint32 paletteSize = 256 * 4;
-	const uint32 pixelDataSize = (rowSize + rowPadding) * surface.h;
+	const uint32 paletteSize = paletteCount * 4;
+	const uint32 pixelDataSize = (rowSize + rowPadding) * surface->h;
 	const uint32 dataOffset = 14 + 40 + paletteSize;
 	const uint32 fileSize = dataOffset + pixelDataSize;
 
@@ -218,21 +191,21 @@ bool writePalettedBMP(Common::WriteStream &out, const Graphics::Surface &surface
 
 	/* === BITMAPINFOHEADER === */
 	out.writeUint32LE(40);                // biSize
-	out.writeUint32LE(surface.w);
-	out.writeUint32LE(surface.h);
+	out.writeUint32LE(surface->w);
+	out.writeUint32LE(surface->h);
 	out.writeUint16LE(1);                 // planes
-	out.writeUint16LE(8);                 // bit count
+	out.writeUint16LE(bitsPerPixel);
 	out.writeUint32LE(0);                 // BI_RGB
 	out.writeUint32LE(pixelDataSize);
 	out.writeUint32LE(0);                 // x ppm
 	out.writeUint32LE(0);                 // y ppm
-	out.writeUint32LE(256);               // colors used
-	out.writeUint32LE(256);               // important colors
+	out.writeUint32LE(paletteCount);      // colors used
+	out.writeUint32LE(paletteCount);      // important colors
 
 	/* === PALETTE === */
 	// Input palette: RGBRGBRGB...
 	// BMP palette: B G R 0
-	for (int i = 0; i < 256; i++) {
+	for (int i = 0; i < paletteCount; i++) {
 		out.writeByte(palette[i * 3 + 2]); // B
 		out.writeByte(palette[i * 3 + 1]); // G
 		out.writeByte(palette[i * 3 + 0]); // R
@@ -242,12 +215,18 @@ bool writePalettedBMP(Common::WriteStream &out, const Graphics::Surface &surface
 	/* === PIXEL DATA (bottom-up) === */
 	byte pad[3] = { 0, 0, 0 };
 
-	for (int y = surface.h - 1; y >= 0; y--) {
-		out.write(surface.getBasePtr(0, y), rowSize);
+	for (uint y = surface->h; y-- > 0;) {
+		out.write(surface->getBasePtr(0, y), rowSize);
 		if (rowPadding)
 			out.write(pad, rowPadding);
 	}
 
+	// free tmp surface
+	if (tmp) {
+		tmp->free();
+		delete tmp;
+	}
+
 	return true;
 }
 
diff --git a/image/bmp.h b/image/bmp.h
index 9bbc7d4d2f4..98e2a0183c6 100644
--- a/image/bmp.h
+++ b/image/bmp.h
@@ -85,13 +85,22 @@ private:
 
 /**
  * Outputs an uncompressed BMP stream of the given input surface.
+ *
+ *  @param out  Stream to which to write the BMP image.
+ *  @param input The surface to save as a BMP image..
+ *  @param palette    The palette (in RGB888), if the source format has a bpp of 1.
+ *  @param paletteCount Number of colors in the palette (default: 256).
  */
-bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette = nullptr);
+bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette = nullptr, uint paletteCount = 256);
 
 /**
- * Outputs an uncompressed BMP stream of the given paletted input surface, without converting it to 24 bpp.
+ * Outputs an uncompressed BMP stream of the given input surface.
+ *
+ *  @param out  Stream to which to write the BMP image.
+ *  @param input The surface to save as a BMP image..
+ *  @param palette    The palette if the source format has a bpp of 1.
  */
-bool writePalettedBMP(Common::WriteStream &out, const Graphics::Surface &surface, const byte *palette);
+bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const Graphics::Palette &palette);
 
 /** @} */
 } // End of namespace Image


Commit: 9b41a94bf04483fdb79d153a518d49a69dbbf7cc
    https://github.com/scummvm/scummvm/commit/9b41a94bf04483fdb79d153a518d49a69dbbf7cc
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2026-02-03T22:05:13+02:00

Commit Message:
IMAGE: Support creating PNG images with palettes

Changed paths:
    image/png.cpp


diff --git a/image/png.cpp b/image/png.cpp
index d88926b7cb3..0d91213f2b5 100644
--- a/image/png.cpp
+++ b/image/png.cpp
@@ -299,6 +299,7 @@ bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const Gr
 
 bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const byte *palette, uint paletteCount) {
 #ifdef USE_PNG
+	const Graphics::PixelFormat requiredFormat_1byte = Graphics::PixelFormat::createFormatCLUT8();
 	const Graphics::PixelFormat requiredFormat_3byte = Graphics::PixelFormat::createFormatRGB24();
 	const Graphics::PixelFormat requiredFormat_4byte = Graphics::PixelFormat::createFormatRGBA32();
 
@@ -306,7 +307,10 @@ bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const by
 	Graphics::Surface *tmp = NULL;
 	const Graphics::Surface *surface;
 
-	if (input.format == requiredFormat_3byte) {
+	if (input.format == requiredFormat_1byte) {
+		surface = &input;
+		colorType = PNG_COLOR_TYPE_PALETTE;
+	} else if (input.format == requiredFormat_3byte) {
 		surface = &input;
 		colorType = PNG_COLOR_TYPE_RGB;
 	} else {
@@ -341,6 +345,17 @@ bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const by
 
 	png_set_write_fn(pngPtr, &out, pngWriteToStream, pngFlushStream);
 
+	Common::Array<png_color> colorPtr;
+	if (colorType == PNG_COLOR_TYPE_PALETTE) {
+		colorPtr.resize(paletteCount);
+	        for (int i = 0; i < paletteCount; i++) {
+			colorPtr[i].red   = palette[i * 3 + 0];
+			colorPtr[i].green = palette[i * 3 + 1];
+			colorPtr[i].blue  = palette[i * 3 + 2];
+	        }
+		png_set_PLTE(pngPtr, infoPtr, colorPtr.data(), paletteCount);
+	}
+
 	png_set_IHDR(pngPtr, infoPtr, surface->w, surface->h, 8, colorType, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
 
 	Common::Array<const uint8 *> rows;


Commit: 7dd583c3581542afced5394905b026583069196f
    https://github.com/scummvm/scummvm/commit/7dd583c3581542afced5394905b026583069196f
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2026-02-03T22:05:13+02:00

Commit Message:
IMAGE: Avoid writing alpha channels to PNG files if not required

Changed paths:
    image/png.cpp


diff --git a/image/png.cpp b/image/png.cpp
index 0d91213f2b5..06fcebc219a 100644
--- a/image/png.cpp
+++ b/image/png.cpp
@@ -313,12 +313,14 @@ bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const by
 	} else if (input.format == requiredFormat_3byte) {
 		surface = &input;
 		colorType = PNG_COLOR_TYPE_RGB;
+	} else if (input.format == requiredFormat_4byte) {
+		surface = &input;
+		colorType = PNG_COLOR_TYPE_RGB_ALPHA;
+	} else if (input.format.aBits() == 0) {
+		surface = tmp = input.convertTo(requiredFormat_3byte, palette, paletteCount);
+		colorType = PNG_COLOR_TYPE_RGB;
 	} else {
-		if (input.format == requiredFormat_4byte) {
-			surface = &input;
-		} else {
-			surface = tmp = input.convertTo(requiredFormat_4byte, palette, paletteCount);
-		}
+		surface = tmp = input.convertTo(requiredFormat_4byte, palette, paletteCount);
 		colorType = PNG_COLOR_TYPE_RGB_ALPHA;
 	}
 


Commit: 52414ed284614849539e18ca60b2136cd0d1e7fd
    https://github.com/scummvm/scummvm/commit/52414ed284614849539e18ca60b2136cd0d1e7fd
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-02-03T22:05:13+02:00

Commit Message:
IMAGE: Remove unused parameter

Changed paths:
    image/bmp.cpp


diff --git a/image/bmp.cpp b/image/bmp.cpp
index 6eaa375e69f..ad13f262ca5 100644
--- a/image/bmp.cpp
+++ b/image/bmp.cpp
@@ -148,7 +148,7 @@ bool BitmapDecoder::loadStream(Common::SeekableReadStream &stream) {
 }
 
 
-bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const Graphics::Palette &palette, uint paletteCount = 256) {
+bool writeBMP(Common::WriteStream &out, const Graphics::Surface &input, const Graphics::Palette &palette) {
 	return writeBMP(out, input, palette.data(), palette.size());
 }
 


Commit: aba2a17d9d445c6df074f1a1b0af524aeca3bb83
    https://github.com/scummvm/scummvm/commit/aba2a17d9d445c6df074f1a1b0af524aeca3bb83
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-02-03T22:05:13+02:00

Commit Message:
IMAGE: Fix whitespace

Changed paths:
    image/png.cpp


diff --git a/image/png.cpp b/image/png.cpp
index 06fcebc219a..67c441fc25f 100644
--- a/image/png.cpp
+++ b/image/png.cpp
@@ -350,11 +350,11 @@ bool writePNG(Common::WriteStream &out, const Graphics::Surface &input, const by
 	Common::Array<png_color> colorPtr;
 	if (colorType == PNG_COLOR_TYPE_PALETTE) {
 		colorPtr.resize(paletteCount);
-	        for (int i = 0; i < paletteCount; i++) {
+		for (int i = 0; i < paletteCount; i++) {
 			colorPtr[i].red   = palette[i * 3 + 0];
 			colorPtr[i].green = palette[i * 3 + 1];
 			colorPtr[i].blue  = palette[i * 3 + 2];
-	        }
+		}
 		png_set_PLTE(pngPtr, infoPtr, colorPtr.data(), paletteCount);
 	}
 




More information about the Scummvm-git-logs mailing list