[Scummvm-git-logs] scummvm master -> 9cb227e000d8b06dcd6a1d486ad98bf3668563f3

bluegr noreply at scummvm.org
Thu Mar 14 06:42:11 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:
9cb227e000 GUI: Replace byte arrays with Palette class in image album dialog


Commit: 9cb227e000d8b06dcd6a1d486ad98bf3668563f3
    https://github.com/scummvm/scummvm/commit/9cb227e000d8b06dcd6a1d486ad98bf3668563f3
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-03-14T08:42:07+02:00

Commit Message:
GUI: Replace byte arrays with Palette class in image album dialog

Changed paths:
    engines/mtropolis/plugin/mti.cpp
    engines/testbed/misc.cpp
    gui/imagealbum-dialog.cpp
    gui/imagealbum-dialog.h


diff --git a/engines/mtropolis/plugin/mti.cpp b/engines/mtropolis/plugin/mti.cpp
index 7a913eee285..0a1d777e7a0 100644
--- a/engines/mtropolis/plugin/mti.cpp
+++ b/engines/mtropolis/plugin/mti.cpp
@@ -38,6 +38,7 @@
 #include "video/mpegps_decoder.h"
 
 #include "graphics/managed_surface.h"
+#include "graphics/palette.h"
 
 #include "common/file.h"
 namespace MTropolis {
@@ -416,7 +417,7 @@ class PrintModifierImageSupplier : public GUI::ImageAlbumImageSupplier {
 public:
 	PrintModifierImageSupplier(const Common::String &inputPath, bool isMacVersion);
 
-	bool loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, byte (&outPalette)[256 * 3], GUI::ImageAlbumImageMetadata &outMetadata) override;
+	bool loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, Graphics::Palette &outPalette, GUI::ImageAlbumImageMetadata &outMetadata) override;
 	void releaseImageSlot(uint slot) override;
 	uint getNumSlots() const override;
 	Common::U32String getDefaultFileNameForSlot(uint slot) const override;
@@ -437,7 +438,7 @@ PrintModifierImageSupplier::PrintModifierImageSupplier(const Common::String &inp
 		_decoder.reset(new Image::BitmapDecoder());
 }
 
-bool PrintModifierImageSupplier::loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, byte (&outPalette)[256 * 3], GUI::ImageAlbumImageMetadata &outMetadata) {
+bool PrintModifierImageSupplier::loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, Graphics::Palette &outPalette, GUI::ImageAlbumImageMetadata &outMetadata) {
 	Common::ScopedPtr<Common::SeekableReadStream> dataStream(createReadStreamForSlot(slot));
 
 	if (!dataStream)
@@ -454,7 +455,7 @@ bool PrintModifierImageSupplier::loadImageSlot(uint slot, const Graphics::Surfac
 	outHasPalette = _decoder->hasPalette();
 
 	if (_decoder->hasPalette())
-		memcpy(outPalette + _decoder->getPaletteStartIndex() * 3, _decoder->getPalette(), _decoder->getPaletteColorCount() * 3);
+		outPalette.set(_decoder->getPalette(), _decoder->getPaletteStartIndex(), _decoder->getPaletteColorCount());
 
 	outMetadata = GUI::ImageAlbumImageMetadata();
 	outMetadata._orientation = GUI::kImageAlbumImageOrientationLandscape;
diff --git a/engines/testbed/misc.cpp b/engines/testbed/misc.cpp
index f809b8df18e..1c38fe3fb94 100644
--- a/engines/testbed/misc.cpp
+++ b/engines/testbed/misc.cpp
@@ -23,6 +23,8 @@
 #include "common/timer.h"
 #include "common/file.h"
 
+#include "graphics/palette.h"
+
 #include "gui/dialog.h"
 #include "gui/imagealbum-dialog.h"
 
@@ -192,7 +194,7 @@ class ImageAlbumImageSupplier : public GUI::ImageAlbumImageSupplier {
 public:
 	void addFile(const Common::Path &path, Common::FormatInfo::FormatID format, bool dontReportFormat);
 
-	bool loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, byte (&outPalette)[256 * 3], GUI::ImageAlbumImageMetadata &outMetadata) override;
+	bool loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, Graphics::Palette &outPalette, GUI::ImageAlbumImageMetadata &outMetadata) override;
 	void releaseImageSlot(uint slot) override;
 	bool getFileFormatForImageSlot(uint slot, Common::FormatInfo::FormatID &outFormat) const override;
 	Common::SeekableReadStream *createReadStreamForSlot(uint slot) override;
@@ -217,7 +219,7 @@ void ImageAlbumImageSupplier::addFile(const Common::Path &path, Common::FormatIn
 	_slots.push_back(FileInfo(path, format, dontReportFormat));
 }
 
-bool ImageAlbumImageSupplier::loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, byte (&outPalette)[256 * 3], GUI::ImageAlbumImageMetadata &outMetadata) {
+bool ImageAlbumImageSupplier::loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, Graphics::Palette &outPalette, GUI::ImageAlbumImageMetadata &outMetadata) {
 
 	FileInfo &fi = _slots[slot];
 
@@ -244,7 +246,7 @@ bool ImageAlbumImageSupplier::loadImageSlot(uint slot, const Graphics::Surface *
 	outSurface = fi._decoder->getSurface();
 	outHasPalette = fi._decoder->hasPalette();
 	if (fi._decoder->hasPalette())
-		memcpy(outPalette, fi._decoder->getPalette() + fi._decoder->getPaletteStartIndex() * 3, fi._decoder->getPaletteColorCount() * 3);
+		outPalette.set(fi._decoder->getPalette(), fi._decoder->getPaletteStartIndex(), fi._decoder->getPaletteColorCount());
 	outMetadata = GUI::ImageAlbumImageMetadata();
 
 	return true;
diff --git a/gui/imagealbum-dialog.cpp b/gui/imagealbum-dialog.cpp
index 3fe57a53971..f64e95fd6f0 100644
--- a/gui/imagealbum-dialog.cpp
+++ b/gui/imagealbum-dialog.cpp
@@ -21,6 +21,8 @@
 
 #include "gui/imagealbum-dialog.h"
 
+#include "graphics/palette.h"
+
 #include "gui/dialog.h"
 #include "gui/filebrowser-dialog.h"
 #include "gui/gui-manager.h"
@@ -164,12 +166,9 @@ void ImageAlbumDialog::changeToSlot(uint slot) {
 
 		const Graphics::Surface *surf = nullptr;
 		bool hasPalette = false;
-		byte palette[256 * 3];
+		Graphics::Palette palette(256);
 		ImageAlbumImageMetadata metadata;
 
-		for (byte &paletteByte : palette)
-			paletteByte = 0;
-
 		if (_imageSupplier->loadImageSlot(slot, surf, hasPalette, palette, metadata)) {
 			if (!canSaveImage) {
 				// If we can't always save the image (meaning we don't have an image write-out function) then see if we can
@@ -215,7 +214,7 @@ void ImageAlbumDialog::changeToSlot(uint slot) {
 			Graphics::ManagedSurface rescaledGraphic;
 			rescaledGraphic.create(scaledWidth, scaledHeight, surf->format);
 			if (hasPalette)
-				rescaledGraphic.setPalette(palette, 0, 256);
+				rescaledGraphic.setPalette(palette.data(), 0, 256);
 
 			if (needs90Rotate) {
 				bool isClockwise = metadata._viewTransformation == kImageAlbumViewTransformationRotate90CW;
@@ -251,7 +250,7 @@ void ImageAlbumDialog::changeToSlot(uint slot) {
 			_imageSupplier->releaseImageSlot(slot);
 
 			if (rescaledGraphic.format.bytesPerPixel == 1)
-				rescaledGraphic.convertToInPlace(Graphics::createPixelFormat<888>(), palette, 0, 256);
+				rescaledGraphic.convertToInPlace(Graphics::createPixelFormat<888>(), palette.data(), 0, 256);
 
 			int32 xCoord = (static_cast<int32>(_imageContainer->getWidth()) - static_cast<int32>(scaledWidth)) / 2u;
 			int32 yCoord = (static_cast<int32>(_imageContainer->getHeight()) - static_cast<int32>(scaledHeight)) / 2u;
@@ -379,12 +378,9 @@ void ImageAlbumDialog::saveImageInSlot(uint slot) {
 	if (needsConversion) {
 		const Graphics::Surface *surf = nullptr;
 		bool hasPalette = false;
-		byte palette[256 * 3];
+		Graphics::Palette palette(256);
 		ImageAlbumImageMetadata metadata;
 
-		for (byte &paletteByte : palette)
-			paletteByte = 0;
-
 		if (_imageSupplier->loadImageSlot(slot, surf, hasPalette, palette, metadata)) {
 			Common::ScopedPtr<Common::SeekableWriteStream> writeStream;
 
@@ -400,7 +396,7 @@ void ImageAlbumDialog::saveImageInSlot(uint slot) {
 					assert(saveCallback);
 
 					Common::FormatInfo::ImageSaveProperties saveProps;
-					saveCallback(*writeStream, *surf, hasPalette ? palette : nullptr, saveProps);
+					saveCallback(*writeStream, *surf, hasPalette ? palette.data() : nullptr, saveProps);
 				} else {
 					warning("Failed to open image output stream");
 				}
diff --git a/gui/imagealbum-dialog.h b/gui/imagealbum-dialog.h
index dffd884db56..e2c032876c9 100644
--- a/gui/imagealbum-dialog.h
+++ b/gui/imagealbum-dialog.h
@@ -34,6 +34,7 @@ class SeekableReadStream;
 
 namespace Graphics {
 
+class Palette;
 struct Surface;
 
 } // End of namespace Graphics
@@ -81,7 +82,7 @@ public:
 	 * @param outMetadata             Outputted metadata for the image
 	 * @return True if the image loaded successfully, false if it failed
 	 */
-	virtual bool loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, byte (&outPalette)[256 * 3], ImageAlbumImageMetadata &outMetadata) = 0;
+	virtual bool loadImageSlot(uint slot, const Graphics::Surface *&outSurface, bool &outHasPalette, Graphics::Palette &outPalette, ImageAlbumImageMetadata &outMetadata) = 0;
 
 	/**
 	 * @brief Releases any resources for an image loaded with loadImageSlot




More information about the Scummvm-git-logs mailing list