Checkpoint in pixels_blit, and avoid doing undefined behaviour when source and destination is the same.

Seems a reasonnable point to observe when refactoring, since it's called on most image data.
This commit is contained in:
Laurent Fasnacht 2014-06-12 06:54:15 +02:00
parent da8559fa34
commit b7fe81c55c

View file

@ -31,6 +31,7 @@
#include <math.h>
#include <assert.h>
#include "checkpoint.h"
#include "sao.h"
/**
@ -703,6 +704,25 @@ void pixels_blit(const pixel * const orig, pixel * const dst,
assert(width <= orig_stride);
assert(width <= dst_stride);
#ifdef CHECKPOINTS
for (y = 0; y < height; ++y) {
char buffer[3*width];
int p;
for (p = 0; p < width; ++p) {
sprintf((buffer + 3*p), "%02X ", orig[y*orig_stride]);
}
buffer[3*width] = 0;
CHECKPOINT("pixels_blit: %04d: %s", y, buffer);
}
#endif //CHECKPOINTS
if (orig == dst) {
//If we have the same array, then we should have the same stride
assert(orig_stride == dst_stride);
return;
}
assert(orig != dst || orig_stride == dst_stride);
for (y = 0; y < height; ++y) {
memcpy(&dst[y*dst_stride], &orig[y*orig_stride], width * sizeof(pixel));
}