[Scummvm-cvs-logs] scummvm master -> ac93f3512ffbad7b40ef62a3622367f24d6f5193

lordhoto lordhoto at gmail.com
Mon Nov 16 17:03:33 CET 2015


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

Summary:
eee8ef9dce GRAPHICS: Make PixelFormat::toString const.
1c7a5e5a01 GRAPHICS: Fix component order in PixelFormat::toString output.
aaca04cdfc GRAPHICS: Rewrite PixelFormat::toString to be easier to understand.
ac93f3512f GRAPHICS: Remove unused header include.


Commit: eee8ef9dce40c3f5be80f38822fe7e37ddadb432
    https://github.com/scummvm/scummvm/commit/eee8ef9dce40c3f5be80f38822fe7e37ddadb432
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-11-16T16:03:44+01:00

Commit Message:
GRAPHICS: Make PixelFormat::toString const.

Changed paths:
    graphics/pixelformat.cpp
    graphics/pixelformat.h



diff --git a/graphics/pixelformat.cpp b/graphics/pixelformat.cpp
index e7b5401..a712813 100644
--- a/graphics/pixelformat.cpp
+++ b/graphics/pixelformat.cpp
@@ -25,7 +25,7 @@
 
 namespace Graphics {
 
-Common::String PixelFormat::toString() {
+Common::String PixelFormat::toString() const {
 	if (bytesPerPixel == 1)
 		return "CLUT8";
 
diff --git a/graphics/pixelformat.h b/graphics/pixelformat.h
index 3e6c53b..9dd0624 100644
--- a/graphics/pixelformat.h
+++ b/graphics/pixelformat.h
@@ -262,7 +262,7 @@ struct PixelFormat {
 		return 0;
 	}
 
-	Common::String toString();
+	Common::String toString() const;
 };
 
 } // End of namespace Graphics


Commit: 1c7a5e5a0108e9368d24f381858e050277499432
    https://github.com/scummvm/scummvm/commit/1c7a5e5a0108e9368d24f381858e050277499432
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-11-16T16:28:01+01:00

Commit Message:
GRAPHICS: Fix component order in PixelFormat::toString output.

Formerly components were printed from bottom to top, common notation is from
top to bottom. For reference check how we name formats, like in for example:
backends/graphics/openglsdl/openglsdl-graphics.cpp:190-230
backends/graphics/surfacesdl/surfacesdl-graphics.cpp:409-490
sherlock/scalpel/scalpel.cpp:207

Changed paths:
    graphics/pixelformat.cpp



diff --git a/graphics/pixelformat.cpp b/graphics/pixelformat.cpp
index a712813..7443aab 100644
--- a/graphics/pixelformat.cpp
+++ b/graphics/pixelformat.cpp
@@ -42,18 +42,18 @@ Common::String PixelFormat::toString() const {
 
 	for (int c = 0; c < 4; c++) {
 		int compPos = -1;
-		int minshift = 100;
+		int maxshift = -1;
 
-		// Find minimal component
+		// Find maximal component
 		for (int i = 0; i < 4; i++)
-			if (component[i] >= 0 && component[i] < minshift) {
-				minshift = component[i];
+			if (component[i] >= 0 && component[i] > maxshift) {
+				maxshift = component[i];
 				compPos = i;
 			}
 
 		// Clean duplicates
 		for (int i = 0; i < 4; i++)
-			if (component[i] == minshift)
+			if (component[i] == maxshift)
 				component[i] = -1;
 
 		switch (compPos) {


Commit: aaca04cdfca22479bb7777d4d51e5e79ae397a39
    https://github.com/scummvm/scummvm/commit/aaca04cdfca22479bb7777d4d51e5e79ae397a39
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-11-16T16:58:23+01:00

Commit Message:
GRAPHICS: Rewrite PixelFormat::toString to be easier to understand.

Changed paths:
    graphics/pixelformat.cpp



diff --git a/graphics/pixelformat.cpp b/graphics/pixelformat.cpp
index 7443aab..b5919ba 100644
--- a/graphics/pixelformat.cpp
+++ b/graphics/pixelformat.cpp
@@ -22,6 +22,7 @@
 
 #include "graphics/pixelformat.h"
 #include "common/debug.h"
+#include "common/algorithm.h"
 
 namespace Graphics {
 
@@ -29,65 +30,33 @@ Common::String PixelFormat::toString() const {
 	if (bytesPerPixel == 1)
 		return "CLUT8";
 
+	// We apply a trick to simplify the code here. We encode all the shift,
+	// loss, and component name in the component entry. By having the shift as
+	// highest entry we can sort according to shift.
+	// This works because in valid RGB PixelFormats shift values needs to be
+	// distinct except when the loss is 8. However, components with loss value
+	// of 8 are not printed, thus their position does not matter.
 	int component[4];
-	char tmp[10];
-	tmp[0] = tmp[1] = 0;
+	component[0] = (rShift << 16) | (rLoss << 8) | 'R';
+	component[1] = (gShift << 16) | (gLoss << 8) | 'G';
+	component[2] = (bShift << 16) | (bLoss << 8) | 'B';
+	component[3] = (aShift << 16) | (aLoss << 8) | 'A';
 
-	component[0] = rShift;
-	component[1] = gShift;
-	component[2] = bShift;
-	component[3] = aShift;
+	// Sort components according to descending shift value.
+	Common::sort(component, component + ARRAYSIZE(component), Common::Greater<int>());
 
 	Common::String letters, digits;
+	for (int i = 0; i < ARRAYSIZE(component); ++i) {
+		const int componentLoss = (component[i] >> 8) & 0xFF;
+		// A loss of 8 means that the component does not exist.
+		if (componentLoss == 8) {
+			continue;
+		}
 
-	for (int c = 0; c < 4; c++) {
-		int compPos = -1;
-		int maxshift = -1;
-
-		// Find maximal component
-		for (int i = 0; i < 4; i++)
-			if (component[i] >= 0 && component[i] > maxshift) {
-				maxshift = component[i];
-				compPos = i;
-			}
-
-		// Clean duplicates
-		for (int i = 0; i < 4; i++)
-			if (component[i] == maxshift)
-				component[i] = -1;
+		const char componentName = component[i] & 0xFF;
 
-		switch (compPos) {
-		case 0:
-			if (rLoss != 8) {
-				letters += "R";
-				tmp[0] = '0' + 8 - rLoss;
-				digits += tmp;
-			}
-			break;
-		case 1:
-			if (gLoss != 8) {
-				letters += "G";
-				tmp[0] = '0' + 8 - gLoss;
-				digits += tmp;
-			}
-			break;
-		case 2:
-			if (bLoss != 8) {
-				letters += "B";
-				tmp[0] = '0' + 8 - bLoss;
-				digits += tmp;
-			}
-			break;
-		case 3:
-			if (aLoss != 8) {
-				letters += "A";
-				tmp[0] = '0' + 8 - aLoss;
-				digits += tmp;
-			}
-			break;
-		default:
-			break;
-		}
+		letters += componentName;
+		digits += '0' + 8 - componentLoss;
 	}
 
 	return letters + digits;


Commit: ac93f3512ffbad7b40ef62a3622367f24d6f5193
    https://github.com/scummvm/scummvm/commit/ac93f3512ffbad7b40ef62a3622367f24d6f5193
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-11-16T17:01:59+01:00

Commit Message:
GRAPHICS: Remove unused header include.

Changed paths:
    graphics/pixelformat.cpp



diff --git a/graphics/pixelformat.cpp b/graphics/pixelformat.cpp
index b5919ba..0a46411 100644
--- a/graphics/pixelformat.cpp
+++ b/graphics/pixelformat.cpp
@@ -21,7 +21,6 @@
  */
 
 #include "graphics/pixelformat.h"
-#include "common/debug.h"
 #include "common/algorithm.h"
 
 namespace Graphics {






More information about the Scummvm-git-logs mailing list