aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarisa-Chan2013-10-20 20:06:12 +0000
committerMarisa-Chan2013-10-20 20:06:12 +0000
commitdbdefe23e9861781af63608cd450cfaed86de89a (patch)
treee929cda7cdaf779d7938a44883aedd68b6eb0aa5
parentbbe29500ccf0dd6d31ebb5bfcbbf707c74a4500a (diff)
downloadscummvm-rg350-dbdefe23e9861781af63608cd450cfaed86de89a.tar.gz
scummvm-rg350-dbdefe23e9861781af63608cd450cfaed86de89a.tar.bz2
scummvm-rg350-dbdefe23e9861781af63608cd450cfaed86de89a.zip
ZVISION: New render functions for rendering surface-to-surface.
-rw-r--r--engines/zvision/render_manager.cpp167
-rw-r--r--engines/zvision/render_manager.h80
2 files changed, 247 insertions, 0 deletions
diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp
index 1406fbc828..a240e766df 100644
--- a/engines/zvision/render_manager.cpp
+++ b/engines/zvision/render_manager.cpp
@@ -159,6 +159,173 @@ void RenderManager::clearWorkingWindowTo555Color(uint16 color) {
}
}
+void RenderManager::copyRectToSurface(Graphics::Surface &src, Graphics::Surface &dst, const Common::Rect &_srcRect, const Common::Rect &_dstRect) {
+ if (src.format != dst.format)
+ return;
+
+ Common::Rect dstRect = _dstRect;
+ if (dstRect.isEmpty())
+ dstRect = Common::Rect(dst.w, dst.h);
+ dstRect.clip(dst.w, dst.h);
+
+ Common::Rect srcRect = _srcRect;
+ if (srcRect.isEmpty())
+ srcRect = Common::Rect(src.w, src.h);
+ srcRect.clip(src.w, src.h);
+
+ if (!srcRect.isValidRect() || !dstRect.isValidRect())
+ return;
+
+ Common::Rect rendRect = srcRect;
+ rendRect.clip(dstRect.width(), dstRect.height());
+
+ if (rendRect.isEmpty() || !rendRect.isValidRect())
+ return;
+
+ // Copy rendRect from src surface to dst surface
+ byte *src_buf = (byte *)src.getBasePtr(rendRect.left, rendRect.top);
+ byte *dst_buf = (byte *)dst.getBasePtr(dstRect.left, dstRect.top);
+
+ int32 w = rendRect.width();
+ int32 h = rendRect.height();
+
+ for (int32 y = 0; y < h; y++) {
+ memcpy(dst_buf, src_buf, w * src.format.bytesPerPixel);
+ src_buf += src.pitch;
+ dst_buf += dst.pitch;
+ }
+}
+
+void RenderManager::copyRectToSurface(Graphics::Surface &src, Graphics::Surface &dst, const Common::Rect &_srcRect, const Common::Rect &_dstRect, uint32 keycolor) {
+ if (src.format != dst.format)
+ return;
+
+ Common::Rect dstRect = _dstRect;
+ if (dstRect.isEmpty())
+ dstRect = Common::Rect(dst.w, dst.h);
+ dstRect.clip(dst.w, dst.h);
+
+ Common::Rect srcRect = _srcRect;
+ if (srcRect.isEmpty())
+ srcRect = Common::Rect(src.w, src.h);
+ srcRect.clip(src.w, src.h);
+
+ if (!srcRect.isValidRect() || !dstRect.isValidRect())
+ return;
+
+ Common::Rect rendRect = srcRect;
+ rendRect.clip(dstRect.width(), dstRect.height());
+
+ if (rendRect.isEmpty() || !rendRect.isValidRect())
+ return;
+
+ uint32 _keycolor = keycolor & ((1 << (src.format.bytesPerPixel << 3)) - 1);
+
+ // Copy rendRect from src surface to dst surface
+ byte *src_buf = (byte *)src.getBasePtr(rendRect.left, rendRect.top);
+ byte *dst_buf = (byte *)dst.getBasePtr(dstRect.left, dstRect.top);
+
+ int32 w = rendRect.width();
+ int32 h = rendRect.height();
+
+ for (int32 y = 0; y < h; y++) {
+ switch (src.format.bytesPerPixel) {
+ case 1: {
+ uint *src_tmp = (uint *)src_buf;
+ uint *dst_tmp = (uint *)dst_buf;
+ for (int32 x = 0; x < w; x++) {
+ if (*src_tmp != _keycolor)
+ *dst_tmp = *src_tmp;
+ src_tmp++;
+ dst_tmp++;
+ }
+ }
+ break;
+
+ case 2: {
+ uint16 *src_tmp = (uint16 *)src_buf;
+ uint16 *dst_tmp = (uint16 *)dst_buf;
+ for (int32 x = 0; x < w; x++) {
+ if (*src_tmp != _keycolor)
+ *dst_tmp = *src_tmp;
+ src_tmp++;
+ dst_tmp++;
+ }
+ }
+ break;
+
+ case 4: {
+ uint32 *src_tmp = (uint32 *)src_buf;
+ uint32 *dst_tmp = (uint32 *)dst_buf;
+ for (int32 x = 0; x < w; x++) {
+ if (*src_tmp != _keycolor)
+ *dst_tmp = *src_tmp;
+ src_tmp++;
+ dst_tmp++;
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ src_buf += src.pitch;
+ dst_buf += dst.pitch;
+ }
+}
+
+void RenderManager::copyRectToSurface(Graphics::Surface &src, Graphics::Surface &dst, const Common::Rect &srcRect, const Common::Point &dstPt) {
+ if (!Common::Rect(dst.w, dst.h).contains(dstPt))
+ return;
+ Common::Rect dstRect(dstPt.x, dstPt.y, dst.w, dst.h);
+ copyRectToSurface(src, dst, srcRect, dstRect);
+}
+
+void RenderManager::copyRectToSurface(Graphics::Surface &src, Graphics::Surface &dst, const Common::Rect &srcRect, const Common::Point &dstPt, uint32 keycolor) {
+ if (!Common::Rect(dst.w, dst.h).contains(dstPt))
+ return;
+ Common::Rect dstRect(dstPt.x, dstPt.y, dst.w, dst.h);
+ copyRectToSurface(src, dst, srcRect, dstRect, keycolor);
+}
+
+void RenderManager::renderImageToBackground(const Common::String &fileName, int16 destX, int16 destY) {
+ Graphics::Surface surface;
+ readImageToSurface(fileName, surface);
+
+ Common::Rect srcRect(surface.w, surface.h);
+ Common::Point dstPt(destX, destY);
+
+ copyRectToSurface(surface, _currentBackground, srcRect, dstPt);
+ moveBackground(0);
+}
+
+void RenderManager::renderImageToBackground(Graphics::Surface &surface, int16 destX, int16 destY) {
+ Common::Rect srcRect(surface.w, surface.h);
+ Common::Point dstPt(destX, destY);
+
+ copyRectToSurface(surface, _currentBackground, srcRect, dstPt);
+ moveBackground(0);
+}
+
+void RenderManager::renderImageToBackground(const Common::String &fileName, int16 destX, int16 destY, uint32 keycolor) {
+ Graphics::Surface surface;
+ readImageToSurface(fileName, surface);
+
+ Common::Rect srcRect(surface.w, surface.h);
+ Common::Point dstPt(destX, destY);
+
+ copyRectToSurface(surface, _currentBackground, srcRect, dstPt, keycolor);
+ moveBackground(0);
+}
+
+void RenderManager::renderImageToBackground(Graphics::Surface &surface, int16 destX, int16 destY, uint32 keycolor) {
+ Common::Rect srcRect(surface.w, surface.h);
+ Common::Point dstPt(destX, destY);
+
+ copyRectToSurface(surface, _currentBackground, srcRect, dstPt, keycolor);
+ moveBackground(0);
+}
+
void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap) {
int16 subRectX = 0;
int16 subRectY = 0;
diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h
index 9fedd1d8dd..37bfcfa20d 100644
--- a/engines/zvision/render_manager.h
+++ b/engines/zvision/render_manager.h
@@ -218,6 +218,86 @@ public:
void renderImageToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap = false);
/**
+ * Copies a rectangla of source surface and copy to destination rect.
+ *
+ * @param src Source surface
+ * @param dst Destenation surface
+ * @param srcRect Rect of source surface
+ * @param dstRect Rect for destenation surface
+ */
+ void copyRectToSurface(Graphics::Surface &src, Graphics::Surface &dst, const Common::Rect &srcRect, const Common::Rect &dstRect);
+
+ /**
+ * Copies a rectangla of source surface and copy to destination rect.
+ *
+ * @param src Source surface
+ * @param dst Destenation surface
+ * @param srcRect Rect of source surface
+ * @param dstRect Rect for destenation surface
+ * @param colorkey Transparent color
+ */
+ void copyRectToSurface(Graphics::Surface &src, Graphics::Surface &dst, const Common::Rect &srcRect, const Common::Rect &dstRect, uint32 colorkey);
+
+ /**
+ * Copies a rectangla of source surface and copy to destination rect.
+ *
+ * @param src Source surface
+ * @param dst Destenation surface
+ * @param srcRect Rect of source surface
+ * @param dstPt Point for destenation surface
+ */
+ void copyRectToSurface(Graphics::Surface &src, Graphics::Surface &dst, const Common::Rect &srcRect, const Common::Point &dstPt);
+
+ /**
+ * Copies a rectangla of source surface and copy to destination rect.
+ *
+ * @param src Source surface
+ * @param dst Destenation surface
+ * @param srcRect Rect of source surface
+ * @param dstPt Point for destenation surface
+ * @param colorkey Transparent color
+ */
+ void copyRectToSurface(Graphics::Surface &src, Graphics::Surface &dst, const Common::Rect &srcRect, const Common::Point &dstPt, uint32 colorkey);
+
+ /**
+ * Blits the image or a portion of the image to the background.
+ *
+ * @param fileName Name of the image file
+ * @param destinationX X position where the image should be put. Coords are in working window space, not screen space!
+ * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space!
+ */
+ void renderImageToBackground(const Common::String &fileName, int16 destinationX, int16 destinationY);
+
+ /**
+ * Blits the image or a portion of the image to the background.
+ *
+ * @param surface Surface to read the image data from
+ * @param destinationX X position where the image should be put. Coords are in working window space, not screen space!
+ * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space!
+ */
+ void renderImageToBackground(Graphics::Surface &surface, int16 destinationX, int16 destinationY);
+
+ /**
+ * Blits the image or a portion of the image to the background.
+ *
+ * @param fileName Name of the image file
+ * @param destinationX X position where the image should be put. Coords are in working window space, not screen space!
+ * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space!
+ * @param colorkey Transparent color
+ */
+ void renderImageToBackground(const Common::String &fileName, int16 destX, int16 destY, uint32 colorkey);
+
+ /**
+ * Blits the image or a portion of the image to the background.
+ *
+ * @param surface Surface to read the image data from
+ * @param destinationX X position where the image should be put. Coords are in working window space, not screen space!
+ * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space!
+ * @param colorkey Transparent color
+ */
+ void renderImageToBackground(Graphics::Surface &surface, int16 destX, int16 destY, uint32 colorkey);
+
+ /**
* Sets the current background image to be used by the RenderManager and immediately
* blits it to the screen. (It won't show up until the end of the frame)
*