Browse Source

Use a generic slow path for ImageData:paste between formats when we don't already have a faster path for it, instead of erroring.

Alex Szpakowski 5 years ago
parent
commit
2bf5a04937
1 changed files with 14 additions and 1 deletions
  1. 14 1
      src/modules/image/ImageData.cpp

+ 14 - 1
src/modules/image/ImageData.cpp

@@ -710,6 +710,9 @@ void ImageData::paste(ImageData *src, int dx, int dy, int sx, int sy, int sw, in
 	uint8 *s = (uint8 *) src->getData();
 	uint8 *d = (uint8 *) getData();
 
+	auto getfunction = src->pixelGetFunction;
+	auto setfunction = pixelSetFunction;
+
 	// If the dimensions match up, copy the entire memory stream in one go
 	if (srcformat == dstformat && (sw == dstW && dstW == srcW && sh == dstH && dstH == srcH))
 	{
@@ -755,7 +758,17 @@ void ImageData::paste(ImageData *src, int dx, int dy, int sx, int sy, int sw, in
 				pasteRGBA32FtoRGBA16F(rowsrc, rowdst, sw);
 
 			else
-				throw love::Exception("Unsupported pixel format combination in ImageData:paste.");
+			{
+				// Slow path: convert src -> Colorf -> dst.
+				Colorf c;
+				for (int x = 0; x < sw; x++)
+				{
+					auto srcp = (const Pixel *) (rowsrc.u8 + x * srcpixelsize);
+					auto dstp = (Pixel *) (rowdst.u8 + x * dstpixelsize);
+					getfunction(srcp, c);
+					setfunction(c, dstp);
+				}
+			}
 		}
 	}
 }