* Helper function creating aligned buffer * @param bpp bytes per pixel * @param width number of pixel in row * @param height number of rows * @return pointer to memory */
| 66 | * @return pointer to memory |
| 67 | */ |
| 68 | inline void* NewAligned(int bpp, int width, int height) |
| 69 | { |
| 70 | const int pitch = GetPitch(bpp, width); |
| 71 | const int total = pitch * height; |
| 72 | void* buffer = 0; |
| 73 | |
| 74 | #ifndef _WIN32 |
| 75 | |
| 76 | #ifdef __MORPHOS__ |
| 77 | |
| 78 | buffer = calloc( total, 1 ); |
| 79 | if (!buffer) |
| 80 | { |
| 81 | throw Exception("Failed to allocate surface"); |
| 82 | } |
| 83 | |
| 84 | #else |
| 85 | int rc; |
| 86 | if ((rc = posix_memalign(&buffer, 16, total))) |
| 87 | { |
| 88 | throw Exception(strerror(rc)); |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | #else |
| 93 | |
| 94 | // of course Windows has to be difficult about this! |
| 95 | buffer = _aligned_malloc(total, 16); |
| 96 | if (!buffer) |
| 97 | { |
| 98 | throw Exception("Failed to allocate surface"); |
| 99 | } |
| 100 | |
| 101 | #endif |
| 102 | |
| 103 | memset(buffer, 0, total); |
| 104 | return buffer; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Helper function release aligned memory |