add stride info

main
Henri Vasserman 2021-04-11 23:29:54 +03:00
parent 28afef0324
commit 3249b05ae4
1 changed files with 4 additions and 3 deletions

View File

@ -18,6 +18,7 @@ typedef struct {
int y2;
int w;
int h;
int s;
SDL_Surface *surface;
SDL_Texture *texture;
uint32_t *pixels;
@ -37,11 +38,11 @@ static Picture *Picture_new(SDL_Renderer *rend,
p->w = w;
p->h = h;
p->color = color;
p->s = (w + 7) / 8 * 8;
int stride = (w + 7) / 8 * 8;
p->pixels = malloc(stride * h * sizeof(uint32_t));
p->pixels = malloc(p->s * h * sizeof(uint32_t));
p->surface = SDL_CreateRGBSurfaceWithFormatFrom(
p->pixels, w, h, 32, stride * sizeof(uint32_t),
p->pixels, w, h, 32, p->s * sizeof(uint32_t),
SDL_PIXELFORMAT_RGBA32);
Picture_render(p, rend);