[Scummvm-cvs-logs] SF.net SVN: scummvm:[44097] scummvm/trunk/engines/sci/gfx

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Tue Sep 15 09:18:17 CEST 2009


Revision: 44097
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44097&view=rev
Author:   thebluegr
Date:     2009-09-15 07:18:16 +0000 (Tue, 15 Sep 2009)

Log Message:
-----------
Slight cleanup of the resource palette modification code

Modified Paths:
--------------
    scummvm/trunk/engines/sci/gfx/gfx_res_options.cpp
    scummvm/trunk/engines/sci/gfx/gfx_res_options.h
    scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp

Modified: scummvm/trunk/engines/sci/gfx/gfx_res_options.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_res_options.cpp	2009-09-15 04:14:08 UTC (rev 44096)
+++ scummvm/trunk/engines/sci/gfx/gfx_res_options.cpp	2009-09-15 07:18:16 UTC (rev 44097)
@@ -32,53 +32,21 @@
 
 namespace Sci {
 
-//#define DEBUG
-
-static int matches_patternlist(gfx_res_pattern_t *patterns, int nr, int val) {
+static bool matches_patternlist(gfx_res_pattern_t *patterns, int nr, int val) {
 	for (int i = 0; i < nr; i++)
-		if (patterns[i].min <= val
-		        && patterns[i].max >= val)
-			return 1;
+		if (patterns[i].min <= val && patterns[i].max >= val)
+			return true;
 
-	return 0;
+	return false;
 }
 
-#ifdef DEBUG
-static void print_pattern(gfx_res_pattern_t *pat) {
-	fprintf(stderr, "[%d..%d]",
-	        pat->min, pat->max);
-}
-#endif
-
-static int resource_matches_patternlists(gfx_res_conf_t *conf, int type, int nr, int loop, int cel) {
+static bool resource_matches_patternlists(gfx_res_conf_t *conf, int type, int nr, int loop, int cel) {
 	int loc;
-#ifdef DEBUG
-	int i;
-	fprintf(stderr, "[DEBUG:gfx-res] Trying to match against %d/%d/%d choices\n",
-	        conf->patterns_nr, conf->loops_nr, conf->cels_nr);
-	for (i = 0; i < conf->patterns_nr; i++) {
-		fprintf(stderr, "[DEBUG:gfx-res] Pat #%d: ", i);
-		print_pattern(conf->patterns + i);
-		fprintf(stderr, "\n");
-	}
-	loc = conf->patterns_nr;
-	for (i = 0; i < conf->loops_nr; i++) {
-		fprintf(stderr, "[DEBUG:gfx-res] Loop #%d: ", i);
-		print_pattern(conf->patterns + i + loc);
-		fprintf(stderr, "\n");
-	}
-	loc += conf->loops_nr;
-	for (i = 0; i < conf->cels_nr; i++) {
-		fprintf(stderr, "[DEBUG:gfx-res] Cel #%d: ", i);
-		print_pattern(conf->patterns + i + loc);
-		fprintf(stderr, "\n");
-	}
-#endif
 	if (conf->patterns_nr && !matches_patternlist(conf->patterns, conf->patterns_nr, nr))
-		return 0;
+		return false;
 
 	if (type == GFX_RESOURCE_TYPE_CURSOR)
-		return 1;
+		return true;
 
 	/* Otherwise, we must match at least the loop (pic)
 	** and, for views, the cel as well  */
@@ -87,27 +55,23 @@
 	        !matches_patternlist(conf->patterns + loc,
 	                             conf->loops_nr,
 	                             loop))
-		return 0;
+		return false;
 
 	if (type != GFX_RESOURCE_TYPE_VIEW)
-		return 1;
+		return true;
 
 	loc += conf->loops_nr;
 
 	if (!conf->cels_nr)
-		return 1;
+		return true;
 
 	return matches_patternlist(conf->patterns + loc, conf->cels_nr, cel);
 }
 
 static gfx_res_conf_t *find_match(gfx_res_conf_t *conflist, int type, int nr, int loop, int cel) {
 	while (conflist) {
-		if (resource_matches_patternlists(conflist, type, nr, loop, cel)) {
-#ifdef DEBUG
-			fprintf(stderr, "[DEBUG:gfx-res] Found match!\n");
-#endif
+		if (resource_matches_patternlists(conflist, type, nr, loop, cel))
 			return conflist;
-		}
 
 		conflist = conflist->next;
 	}
@@ -115,11 +79,11 @@
 	return NULL;
 }
 
-void apply_mod(byte *factor, gfx_pixmap_t *pxm) {
+void apply_mod(byte rFactor, byte gFactor, byte bFactor, gfx_pixmap_t *pxm) {
 	Palette *pal = pxm->palette;
 	int i, pal_size = pal ? pal->size() : 0;
 
-	// Does not have a dynamically allocated palette? Must dup current one
+	// Id the pixmap's palette is shared, duplicate it
 	if (pal && pal->isShared()) {
 		pal = pxm->palette->copy();
 		pxm->palette->free();
@@ -127,25 +91,15 @@
 	}
 
 	for (i = 0; i < pal_size; i++) {
-		int v;
-
-#define UPDATE_COL(nm, idx)                        \
-		v = nm;             \
-		v *= factor[idx]; \
-		v >>= 4;                   \
-		nm = (v > 255)? 255 : v;
-
 		PaletteEntry c = pal->getColor(i);
-		UPDATE_COL(c.r, 0);
-		UPDATE_COL(c.g, 1);
-		UPDATE_COL(c.b, 2);
+		c.r = CLIP<int>((c.r * rFactor) >> 4, 0, 255);
+		c.g = CLIP<int>((c.g * gFactor) >> 4, 0, 255);
+		c.b = CLIP<int>((c.b * bFactor) >> 4, 0, 255);
 		pal->setColor(i, c.r, c.g, c.b);
-
-#undef UPDATE_COL
 	}
 }
 
-int gfx_get_res_config(gfx_options_t *options, gfx_pixmap_t *pxm) {
+int gfx_get_res_config(gfx_res_fullconf_t res_conf, gfx_pixmap_t *pxm) {
 	int restype = GFXR_RES_TYPE(pxm->ID);
 	int nr = GFXR_RES_NR(pxm->ID);
 	int loop = pxm->loop;
@@ -153,35 +107,30 @@
 
 	gfx_res_conf_t *conf;
 
-#ifdef DEBUG
-	fprintf(stderr, "[DEBUG:gfx-res] Trying to conf %d/%d/%d/%d (ID=%d)\n",
-	        restype, nr, loop, cel, pxm->ID);
-#endif
-
 	if (pxm->ID < 0 || restype < 0 || restype >= GFX_RESOURCE_TYPES_NR)
 		return 1; // Not appropriate
 
-	conf = find_match(options->res_conf.assign[restype], restype, nr, loop, cel);
-
+	// Find assignment config, if available
+	conf = find_match(res_conf.assign[restype], restype, nr, loop, cel);
 	if (conf) {
 		// Assign palette
 		if (pxm->palette)
 			pxm->palette->free();
 
-		pxm->palette = new Palette(conf->conf.assign.assign.palette.colors,
-								   conf->conf.assign.assign.palette.colors_nr);
+		pxm->palette = new Palette(conf->colors,
+								   conf->colors_nr);
 		pxm->palette->name = "res";
 	}
 
-	conf = options->res_conf.mod[restype];
+	// Find mod config, if available
+	conf = res_conf.mod[restype];
 	while (conf) {
 		conf = find_match(conf, restype, nr, loop, cel);
 		if (conf) {
-			apply_mod(conf->conf.factor, pxm);
+			apply_mod(conf->rFactor, conf->gFactor, conf->bFactor, pxm);
 			conf = conf->next;
 		}
 	}
-	fflush(NULL);
 
 	return 0;
 }

Modified: scummvm/trunk/engines/sci/gfx/gfx_res_options.h
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_res_options.h	2009-09-15 04:14:08 UTC (rev 44096)
+++ scummvm/trunk/engines/sci/gfx/gfx_res_options.h	2009-09-15 07:18:16 UTC (rev 44097)
@@ -41,19 +41,6 @@
 };
 
 /**
- * GFX resource assignments.
- */
-struct gfx_res_assign_t {
-	union {
-		struct {
-			int colors_nr;
-			PaletteEntry *colors;
-		} palette;
-	} assign;
-};
-
-
-/**
  * GFX resource modifications/
  */
 struct gfx_res_conf_t {
@@ -67,20 +54,17 @@
 
 	gfx_res_pattern_t *patterns;
 
-	union {
-		gfx_res_assign_t assign;
-		byte factor[3]; /**< divide by 16 to retrieve factor */
-	} conf; /**< The actual configuration */
+	int colors_nr;
+	PaletteEntry *colors;
+	byte rFactor, gFactor, bFactor;
 
 	gfx_res_conf_t *next;
 };
 
 
-typedef gfx_res_conf_t *gfx_res_conf_p_t;
-
 struct gfx_res_fullconf_t {
-	gfx_res_conf_p_t assign[GFX_RESOURCE_TYPES_NR];
-	gfx_res_conf_p_t mod[GFX_RESOURCE_TYPES_NR];
+	gfx_res_conf_t *assign[GFX_RESOURCE_TYPES_NR];
+	gfx_res_conf_t *mod[GFX_RESOURCE_TYPES_NR];
 };
 
 
@@ -92,12 +76,12 @@
  * Modifies pxm as considered appropriate by configuration options. Does
  * not do anything in colour index mode.
  *
- * @param[in] options	The options according to which configuration
+ * @param[in] res_conf	The resource options according to which modifications
  * 						should be performed
  * @param[in] pxm		The pixmap to configure
  * @return				0 on success, non-zero otherwise
  */
-int gfx_get_res_config(gfx_options_t *options, gfx_pixmap_t *pxm);
+int gfx_get_res_config(gfx_res_fullconf_t res_conf, gfx_pixmap_t *pxm);
 
 /** @} */
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp	2009-09-15 04:14:08 UTC (rev 44096)
+++ scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp	2009-09-15 07:18:16 UTC (rev 44097)
@@ -277,11 +277,11 @@
 	if (maps & key) { \
 		if (res->unscaled_data.pic&& (force || !res->unscaled_data.pic->entry->data)) { \
 				if (key == GFX_MASK_VISUAL) \
-					gfx_get_res_config(options, res->unscaled_data.pic->entry); \
+					gfx_get_res_config(options->res_conf, res->unscaled_data.pic->entry); \
 			        gfx_xlate_pixmap(res->unscaled_data.pic->entry, mode, filter); \
 		} if (scaled && res->scaled_data.pic && (force || !res->scaled_data.pic->entry->data)) { \
 				if (key == GFX_MASK_VISUAL) \
-					gfx_get_res_config(options, res->scaled_data.pic->entry); \
+					gfx_get_res_config(options->res_conf, res->scaled_data.pic->entry); \
 				gfx_xlate_pixmap(res->scaled_data.pic->entry, mode, filter); \
 		} \
 	}
@@ -579,7 +579,7 @@
 	if (!cel_data->data) {
 		if (!cel_data->palette)
 			cel_data->palette = view->palette->getref();
-		gfx_get_res_config(_options, cel_data);
+		gfx_get_res_config(_options->res_conf, cel_data);
 		gfx_xlate_pixmap(cel_data, _driver->getMode());
 	}
 
@@ -662,7 +662,7 @@
 			gfx_free_pixmap(res->unscaled_data.pointer);
 		}
 #ifdef CUSTOM_GRAPHICS_OPTIONS
-		gfx_get_res_config(_options, cursor);
+		gfx_get_res_config(_options->res_conf, cursor);
 		gfx_xlate_pixmap(cursor, _driver->getMode());
 #else
 		gfx_xlate_pixmap(cursor, _driver->getMode());


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list