mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
refactor: break out stride calculation to new function
This commit is contained in:
parent
8aa53d1508
commit
33b5210a6a
3 changed files with 13 additions and 6 deletions
4
font.c
4
font.c
|
|
@ -10,6 +10,7 @@
|
|||
#define LOG_MODULE "font"
|
||||
#define LOG_ENABLE_DBG 0
|
||||
#include "log.h"
|
||||
#include "stride.h"
|
||||
|
||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
|
|
@ -392,8 +393,7 @@ glyph_for_wchar(struct font *font, wchar_t wc, struct glyph *glyph)
|
|||
break;
|
||||
}
|
||||
|
||||
/* Calculate stride. Copied from cairoint.h:CAIRO_STRIDE_FOR_WIDTH_BPP */
|
||||
int stride = (((PIXMAN_FORMAT_BPP(pix_format) * width + 7) / 8 + 4 - 1) & -4);
|
||||
int stride = stride_for_format_and_width(pix_format, width);
|
||||
assert(stride >= bitmap->pitch);
|
||||
|
||||
uint8_t *data = malloc(rows * stride);
|
||||
|
|
|
|||
6
shm.c
6
shm.c
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#define LOG_MODULE "shm"
|
||||
#include "log.h"
|
||||
#include "stride.h"
|
||||
#include "tllist.h"
|
||||
|
||||
static tll(struct buffer) buffers;
|
||||
|
|
@ -69,10 +70,7 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies)
|
|||
goto err;
|
||||
}
|
||||
|
||||
/* TODO: copied from font.c */
|
||||
/* Calculate stride. Copied from cairoint.h:CAIRO_STRIDE_FOR_WIDTH_BPP */
|
||||
int bpp = 32;
|
||||
const int stride = (((bpp * width + 7) / 8 + 4 - 1) & -4);
|
||||
const int stride = stride_for_format_and_width(PIXMAN_a8r8g8b8, width);
|
||||
|
||||
/* Total size */
|
||||
size = stride * height;
|
||||
|
|
|
|||
9
stride.h
Normal file
9
stride.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <pixman.h>
|
||||
|
||||
static inline int
|
||||
stride_for_format_and_width(pixman_format_code_t format, int width)
|
||||
{
|
||||
return (((PIXMAN_FORMAT_BPP(format) * width + 7) / 8 + 4 - 1) & -4);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue