25 #ifndef GRAPHICS_IMAGES_UTIL_H 26 #define GRAPHICS_IMAGES_UTIL_H 44 if ((width < 0) || (width >= 0x8000) || (height < 0) || (height >= 0x8000))
49 return width * height * 3;
52 return width * height * 4;
56 return width * height * 2;
59 return MAX<uint32>( 8, ((width + 3) / 4) * ((height + 3) / 4) * 8);
63 return MAX<uint32>(16, ((width + 3) / 4) * ((height + 3) / 4) * 16);
74 if ((width < 0) || (width >= 0x8000) || (height < 0) || (height >= 0x8000))
96 if ((width <= 0) || (height <= 0) || (bpp <= 0))
99 const size_t halfWidth = width / 2;
100 const size_t pitch = bpp * width;
104 while (height-- > 0) {
105 byte *dataStart = data;
106 byte *dataEnd = data + pitch - bpp;
108 for (
size_t j = 0; j < halfWidth; j++) {
109 memcpy(buffer.
get(), dataStart , bpp);
110 memcpy(dataStart , dataEnd , bpp);
111 memcpy(dataEnd , buffer.
get(), bpp);
123 if ((width <= 0) || (height <= 0) || (bpp <= 0))
126 const size_t pitch = bpp * width;
128 byte *dataStart = data;
129 byte *dataEnd = data + (pitch * height) - pitch;
133 size_t halfHeight = height / 2;
134 while (halfHeight--) {
135 memcpy(buffer.get(), dataStart , pitch);
136 memcpy(dataStart , dataEnd , pitch);
137 memcpy(dataEnd , buffer.get(), pitch);
145 static inline void rotate90(
byte *data,
int width,
int height,
int bpp,
int steps) {
146 if ((width <= 0) || (height <= 0) || (bpp <= 0))
149 assert(width == height);
151 while (steps-- > 0) {
152 const size_t n = width;
154 const size_t w = n / 2;
155 const size_t h = (n + 1) / 2;
157 for (
size_t x = 0; x < w; x++) {
158 for (
size_t y = 0; y < h; y++) {
159 const size_t d0 = ( y * n + x ) * bpp;
160 const size_t d1 = ((n - 1 - x) * n + y ) * bpp;
161 const size_t d2 = ((n - 1 - y) * n + (n - 1 - x)) * bpp;
162 const size_t d3 = ( x * n + (n - 1 - y)) * bpp;
164 for (
size_t p = 0; p < (size_t) bpp; p++) {
165 const byte tmp = data[d0 + p];
167 data[d0 + p] = data[d1 + p];
168 data[d1 + p] = data[d2 + p];
169 data[d2 + p] = data[d3 + p];
186 while (width | height) {
188 offset |= (x & 0x01) << shiftCount;
197 offset |= (y & 0x01) << shiftCount;
211 #endif // GRAPHICS_IMAGES_UTIL_H static int intLog2(uint32 v)
static bool hasValidDimensions(PixelFormatRaw format, int32 width, int32 height)
Are these image dimensions valid for this format?
A simple scoped smart pointer template.
Basic exceptions to throw.
static uint32 deSwizzleOffset(uint32 x, uint32 y, uint32 width, uint32 height)
De-"swizzle" a texture pixel offset.
static void flipHorizontally(byte *data, int width, int height, int bpp)
Flip an image horizontally.
static void rotate90(byte *data, int width, int height, int bpp, int steps)
Rotate a square image in 90° steps, clock-wise.
Utility templates and functions.
Low-level type definitions to handle fixed width types portably.
static uint32 getDataSize(PixelFormatRaw format, int32 width, int32 height)
Return the number of bytes necessary to hold an image of these dimensions and in this format...
PointerType get() const
Returns the plain pointer value.
static void flipVertically(byte *data, int width, int height, int bpp)
Flip an image vertically.