Skip to content

Commit

Permalink
GRAPHICS: Use ScopedArray in the flip* utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Oct 26, 2016
1 parent 94a5246 commit e8927e5
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/graphics/images/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <cstring>

#include "src/common/types.h"
#include "src/common/scopedptr.h"
#include "src/common/util.h"
#include "src/common/maths.h"
#include "src/common/error.h"
Expand Down Expand Up @@ -98,25 +99,23 @@ static inline void flipHorizontally(byte *data, int width, int height, int bpp)
const size_t halfWidth = width / 2;
const size_t pitch = bpp * width;

byte *buffer = new byte[bpp];
Common::ScopedArray<byte> buffer(new byte[bpp]);

while (height-- > 0) {
byte *dataStart = data;
byte *dataEnd = data + pitch - bpp;

for (size_t j = 0; j < halfWidth; j++) {
memcpy(buffer , dataStart, bpp);
memcpy(dataStart, dataEnd , bpp);
memcpy(dataEnd , buffer , bpp);
memcpy(buffer.get(), dataStart , bpp);
memcpy(dataStart , dataEnd , bpp);
memcpy(dataEnd , buffer.get(), bpp);

dataStart += bpp;
dataEnd -= bpp;
}

data += pitch;
}

delete[] buffer;
}

/** Flip an image vertically. */
Expand All @@ -129,19 +128,17 @@ static inline void flipVertically(byte *data, int width, int height, int bpp) {
byte *dataStart = data;
byte *dataEnd = data + (pitch * height) - pitch;

byte *buffer = new byte[pitch];
Common::ScopedArray<byte> buffer(new byte[pitch]);

size_t halfHeight = height / 2;
while (halfHeight--) {
memcpy(buffer , dataStart, pitch);
memcpy(dataStart, dataEnd , pitch);
memcpy(dataEnd , buffer , pitch);
memcpy(buffer.get(), dataStart , pitch);
memcpy(dataStart , dataEnd , pitch);
memcpy(dataEnd , buffer.get(), pitch);

dataStart += pitch;
dataEnd -= pitch;
}

delete[] buffer;
}

/** Rotate a square image in 90° steps. */
Expand Down

0 comments on commit e8927e5

Please sign in to comment.