I got quite a problem with the way I do things in SDL. I internally use my own image format, which is RGB888 in a uint8_t *** array, and to blit it I turn my final screen image into a regular SDL_Surface, the problem being that the process of turning my custom made array into a SDL_Surface is extremely expensive. Here's how I do it :
The first dimension of the array is the colour layer, the second the X axis and the third the Y axis. Of course I'm aware that calling putpixel this many times isn't good and should probably merge the two functions, but I don't think it will cut it.
Basically what I'd like to know is what's the very fastest way to blit my RGB888 array to the screen SDL_Surface, so if anyone has made any code that can apply in this type of situation, wlel feel free to share. And if I didn't make myself very clear well sorry about that it's the end of the day for me
Code:
void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to set */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 4:
*(Uint32 *)p = pixel;
break;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
} else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 1:
*p = pixel;
break;
}
}
void surf_array(SDL_Surface **surf, uint8_t ***image, uint16_t width, uint16_t height)
{
uint16_t ix, iy;
for (ix=0; ix<width; ix++)
for (iy=0; iy<height; iy++)
putpixel(*surf, ix, iy, SDL_MapRGB((*surf)->format, image[0][ix][iy], image[1][ix][iy], image[2][ix][iy]));
}
The first dimension of the array is the colour layer, the second the X axis and the third the Y axis. Of course I'm aware that calling putpixel this many times isn't good and should probably merge the two functions, but I don't think it will cut it.
Basically what I'd like to know is what's the very fastest way to blit my RGB888 array to the screen SDL_Surface, so if anyone has made any code that can apply in this type of situation, wlel feel free to share. And if I didn't make myself very clear well sorry about that it's the end of the day for me