Given a single-chael bitmap (alpha) represented by unsigned char*, what are the ways of making an SDL_Surface out of it? The bitmap has no extra data.
From what I understand, it is done by first calling SDL_CreateRGBSurfaceFrom(bitmap, width, height, depth, pitch, r, g, b, amasks).
1) One (naive & dirty) way I tried, was creating a bitmap represented by unsigned int*, where 75% of it's space was 0xFF, then a call to:SDL_CreateRGBSurfaceFrom(bitmap, width, height, 32, 4 * width, 0xff000000, 0xff0000, 0xff00, 0xff) did it for me. (opaque is white and down to transparent, again, because 0xFF was used).
But I would prefer another way, because this way I need to allocate memory and do an O^2 for-loop.
auto bitmap = new unsigned int[bitmapW * bitmapH];
for(auto j = 0; j < bitmapH; ++j) {
for(auto i = 0; i < bitmapW; ++i) {
int idx = j * bitmapW + i;
bitmap[idx] = tmpBitmap[idx] | 0xFFFFFF00;
}
}
2) The second way I tried, was by using depth = 8, and therefore I didn't need to allocate any new bitmap, and instead (needed?) an SDL_Pallete. auto surf = SDL_CreateRGBSurfaceFrom(bitmap, bitmapW, bitmapH, 8, bitmapW, 0, 0, 0, 0xff); SDL_Color colors[256]; for(int i = 0; i < 256; ++i) { colors[i].r = colors[i].g = colors[i].b = 0xff; colors[i].a = i; } SDL_SetPaletteColors(surf->format->palette, colors, 0, 256); This is by far cheaper in memory, and is constant.
Yet, performance is not the coerstone for me, as I'd like to know, if there is a way I could still use the original call to CreateRGBSurface and simply give it a better mask or something. Thanks.
p.s. I've tried a bunch, yet the closest and fuiest I got, was this, where it's all blood and the texture repeats itself 3 times in width:
http://i.stack.imgur.com/kvBkW.png
