GRAPHICS: Add a basic copyBlit() function

This commit is contained in:
Cameron Cawley 2020-09-16 02:00:08 +01:00 committed by Eugene Sandulenko
parent 6d1ae2d9d3
commit ce2ad28477
2 changed files with 36 additions and 12 deletions

View File

@ -29,6 +29,25 @@ namespace Graphics {
// TODO: YUV to RGB conversion function
// Function to blit a rect
void copyBlit(byte *dst, const byte *src,
const uint dstPitch, const uint srcPitch,
const uint w, const uint h,
const uint bytesPerPixel) {
if (dst == src)
return;
if (dstPitch == srcPitch && ((w * bytesPerPixel) == dstPitch)) {
memcpy(dst, src, dstPitch * h);
} else {
for (uint i = 0; i < h; ++i) {
memcpy(dst, src, w * bytesPerPixel);
dst += dstPitch;
src += srcPitch;
}
}
}
namespace {
template<typename SrcColor, typename DstColor, bool backward>
@ -111,18 +130,7 @@ bool crossBlit(byte *dst, const byte *src,
// Don't perform unnecessary conversion
if (srcFmt == dstFmt) {
if (dst != src) {
if (dstPitch == srcPitch && ((w * dstFmt.bytesPerPixel) == dstPitch)) {
memcpy(dst, src, dstPitch * h);
} else {
for (uint i = 0; i < h; ++i) {
memcpy(dst, src, w * dstFmt.bytesPerPixel);
dst += dstPitch;
src += srcPitch;
}
}
}
copyBlit(dst, src, dstPitch, srcPitch, w, h, dstFmt.bytesPerPixel);
return true;
}

View File

@ -45,6 +45,22 @@ inline static void RGB2YUV(byte r, byte g, byte b, byte &y, byte &u, byte &v) {
// TODO: generic YUV to RGB blit
/**
* Blits a rectangle.
*
* @param dst the buffer which will recieve the converted graphics data
* @param src the buffer containing the original graphics data
* @param dstPitch width in bytes of one full line of the dest buffer
* @param srcPitch width in bytes of one full line of the source buffer
* @param w the width of the graphics data
* @param h the height of the graphics data
* @param bytesPerPixel the number of bytes per pixel
*/
void copyBlit(byte *dst, const byte *src,
const uint dstPitch, const uint srcPitch,
const uint w, const uint h,
const uint bytesPerPixel);
/**
* Blits a rectangle from one graphical format to another.
*