[Scummvm-cvs-logs] scummvm master -> 68b5de7cd4e1ee335ca710fe0ba44251a7c4b28d

lordhoto lordhoto at gmail.com
Sun Aug 4 01:19:21 CEST 2013


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

Summary:
058c22ddaa GRAPHICS: Allow to query a Surface describing a subarea in Surface.
68b5de7cd4 Merge pull request #364 from lordhoto/sub-surface


Commit: 058c22ddaa073a1584993b2d68b2db02ad80d088
    https://github.com/scummvm/scummvm/commit/058c22ddaa073a1584993b2d68b2db02ad80d088
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2013-08-02T09:47:00-07:00

Commit Message:
GRAPHICS: Allow to query a Surface describing a subarea in Surface.

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



diff --git a/graphics/surface.cpp b/graphics/surface.cpp
index 010389c..b90ddd2 100644
--- a/graphics/surface.cpp
+++ b/graphics/surface.cpp
@@ -97,6 +97,34 @@ void Surface::copyFrom(const Surface &surf) {
 	}
 }
 
+Surface Surface::getSubArea(const Common::Rect &area) {
+	Common::Rect effectiveArea(area);
+	effectiveArea.clip(w, h);
+
+	Surface subSurface;
+	subSurface.w = effectiveArea.width();
+	subSurface.h = effectiveArea.height();
+	subSurface.pitch = pitch;
+	subSurface.pixels = getBasePtr(area.left, area.top);
+	subSurface.format = format;
+	return subSurface;
+}
+
+const Surface Surface::getSubArea(const Common::Rect &area) const {
+	Common::Rect effectiveArea(area);
+	effectiveArea.clip(w, h);
+
+	Surface subSurface;
+	subSurface.w = effectiveArea.width();
+	subSurface.h = effectiveArea.height();
+	subSurface.pitch = pitch;
+	// We need to cast the const away here because a Surface always has a
+	// pointer to modifiable pixel data.
+	subSurface.pixels = const_cast<void *>(getBasePtr(area.left, area.top));
+	subSurface.format = format;
+	return subSurface;
+}
+
 void Surface::hLine(int x, int y, int x2, uint32 color) {
 	// Clipping
 	if (y < 0 || y >= h)
diff --git a/graphics/surface.h b/graphics/surface.h
index 6c9e464..21b491e 100644
--- a/graphics/surface.h
+++ b/graphics/surface.h
@@ -135,10 +135,42 @@ struct Surface {
 	void copyFrom(const Surface &surf);
 
 	/**
+	 * Creates a Surface which represents a sub-area of this Surface object.
+	 *
+	 * The pixel (0, 0) of the returned Surface will be the same as Pixel
+	 * (area.x, area.y) of this Surface. Changes to any of the Surface objects
+	 * will change the shared pixel data.
+	 *
+	 * Note that the Surface returned is only valid as long as this Surface
+	 * object is still alive (i.e. its pixel data is not destroyed or
+	 * reallocated). Do *never* try to free the returned Surface.
+	 *
+	 * @param area The area which should be represented. Note that the area
+	 *             will get clipped in case it does not fit!
+	 */
+	Surface getSubArea(const Common::Rect &area);
+
+	/**
+	 * Creates a Surface which represents a sub-area of this Surface object.
+	 *
+	 * The pixel (0, 0) of the returned Surface will be the same as Pixel
+	 * (area.x, area.y) of this Surface.
+	 *
+	 * Note that the Surface returned is only valid as long as this Surface
+	 * object is still alive (i.e. its pixel data is not destroyed or
+	 * reallocated). Do *never* try to free the returned Surface.
+	 *
+	 * @param area The area which should be represented. Note that the area
+	 *             will get clipped in case it does not fit!
+	 */
+	const Surface getSubArea(const Common::Rect &area) const;
+
+	/**
 	 * Convert the data to another pixel format.
 	 *
 	 * This works in-place. This means it will not create an additional buffer
-	 * for the conversion process. The value of pixels might change though.
+	 * for the conversion process. The value of 'pixels' might change though
+	 * (that means it might realloc the pixel data).
 	 *
 	 * Note that you should only use this, when you created the Surface data via
 	 * create! Otherwise this function has undefined behavior.


Commit: 68b5de7cd4e1ee335ca710fe0ba44251a7c4b28d
    https://github.com/scummvm/scummvm/commit/68b5de7cd4e1ee335ca710fe0ba44251a7c4b28d
Author: Johannes Schickel (lordhoto at gmail.com)
Date: 2013-08-03T16:18:35-07:00

Commit Message:
Merge pull request #364 from lordhoto/sub-surface

GRAPHICS: Allow to query a Surface describing a subarea in Surface.

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









More information about the Scummvm-git-logs mailing list