Skip to content

Commit 9d4671a

Browse files
committed
Cleanup & minor improvements
1 parent 67a2af1 commit 9d4671a

File tree

19 files changed

+88
-90
lines changed

19 files changed

+88
-90
lines changed

kos/include/libsvgadrv/chipset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ typedef __ATTR_NONNULL_T((2, 3)) __ssize_t
165165

166166

167167
struct svga_palette_color {
168+
/* TODO: Instead of this, just use `video_color_t' (so libvideo doesn't have to use an intermediate buffer) */
168169
__uint8_t spc_r; /* Red */
169170
__uint8_t spc_g; /* Green */
170171
__uint8_t spc_b; /* Blue */

kos/include/libvideo/gfx/gfx.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,9 +1259,6 @@ struct video_gfxhdr {
12591259
// video_dim_t vxh_bydim; /* [== vxh_byend - vxh_bymin][<= vxh_cydim] I/O Rect height */
12601260
};
12611261

1262-
#define _video_gfxhdr_bxsiz(self) ((self)->vxh_bxend - (self)->vxh_bxmin)
1263-
#define _video_gfxhdr_bysiz(self) ((self)->vxh_byend - (self)->vxh_bymin)
1264-
12651262
struct video_gfx {
12661263
struct video_surface vx_surf; /* Video surface with which to interact. */
12671264
/* TODO: Rename "video_gfxhdr" to something like "video_gfxclip" (and also rename `vx_hdr' to `vx_clip') */

kos/src/libvideo/gfx/buffer/custom.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ custom_buffer__subregion_impl(struct video_surface const *__restrict surface,
197197
__video_buffer_init_subregion(result, surface, parent, rect);
198198
result->cbsr_xoff = parent_xoff + rect->vcr_xmin;
199199
result->cbsr_yoff = parent_yoff + rect->vcr_ymin;
200-
video_codec_xcoord_to_offset(result->vb_codec, result->cbsr_xoff,
200+
video_codec_xcoord_to_offset(video_buffer_getcodec(result), result->cbsr_xoff,
201201
&result->cbsr_bxoff, &result->cbsr_bxrem);
202202
result->vb_ops = !result->cbsr_xoff && !result->cbsr_yoff
203203
? _custom_buffer_subregion_nooff_ops()
@@ -364,7 +364,7 @@ custom_buffer__rlockregion(struct video_buffer *__restrict self,
364364
if (rlock) {
365365
int result;
366366
size_t xoff;
367-
video_codec_xcoord_to_offset(me->vb_codec,
367+
video_codec_xcoord_to_offset(video_buffer_getcodec(me),
368368
lock->_vrl_rect.vcr_xmin,
369369
&xoff, &lock->vrl_xbas);
370370
result = (*rlock)(me->cbc_cookie, &lock->vrl_lock);
@@ -400,7 +400,7 @@ custom_buffer__wlockregion(struct video_buffer *__restrict self,
400400
if (wlock) {
401401
int result;
402402
size_t xoff;
403-
video_codec_xcoord_to_offset(me->vb_codec,
403+
video_codec_xcoord_to_offset(video_buffer_getcodec(me),
404404
lock->_vrl_rect.vcr_xmin,
405405
&xoff, &lock->vrl_xbas);
406406
result = (*wlock)(me->cbc_cookie, &lock->vrl_lock);
@@ -426,7 +426,7 @@ NOTHROW(FCC custom_buffer__unlockregion)(struct video_buffer *__restrict self,
426426
} else if (me->cbc_unlock) {
427427
size_t xoff;
428428
video_coord_t xrem;
429-
video_codec_xcoord_to_offset(self->vb_codec,
429+
video_codec_xcoord_to_offset(video_buffer_getcodec(self),
430430
lock->_vrl_rect.vcr_xmin,
431431
&xoff, &xrem);
432432
assert(xrem == lock->vrl_xbas);

kos/src/libvideo/gfx/buffer/lockable.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ lockable_buffer__subregion_impl(struct video_surface const *__restrict surface,
151151
result->lb_stride = self->lb_stride;
152152
result->lb_data += base_yoff * result->lb_stride;
153153
result->lb_data += base_yoff * result->lb_stride;
154-
video_codec_xcoord_to_offset(result->vb_codec, base_xoff,
155-
&result->lbsb_bxoff,
156-
&result->lbsb_bxrem);
154+
video_codec_xcoord_to_offset(video_buffer_getcodec(result), base_xoff,
155+
&result->lbsb_bxoff, &result->lbsb_bxrem);
157156
result->lbsb_xoff = base_xoff;
158157
result->lbsb_yoff = base_yoff;
159158
result->lbsb_lockable = self;
@@ -732,7 +731,7 @@ lockable_buffer_subregion__initgfx(struct video_gfx *__restrict self) {
732731
INTERN ATTR_PURE WUNUSED ATTR_IN(1) bool CC
733732
libvideo_buffer_islockable(struct video_buffer const *__restrict self) {
734733
/* List of RAM-domain buffers that are known to always be lockable */
735-
if (self->vb_domain == &libvideo_ramdomain) {
734+
if (video_buffer_getdomain(self) == &libvideo_ramdomain) {
736735
if (self->vb_ops == &lockable_buffer_ops)
737736
goto yes;
738737
if (self->vb_ops == &lockable_buffer_subregion_norem_ops)

kos/src/libvideo/gfx/buffer/region.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ INTERN ATTR_RETNONNULL ATTR_INOUT(1) struct video_gfx *FCC
215215
region_buffer__initgfx(struct video_gfx *__restrict self) {
216216
struct region_buffer *me = (struct region_buffer *)video_gfx_getbuffer(self);
217217
self = (*(self->vx_surf.vs_buffer = me->rbf_base)->vb_ops->vi_initgfx)(self);
218-
return (*self->vx_hdr.vxh_ops->vgfo_clip)(self, me->rbf_cxoff, me->rbf_cyoff,
219-
video_buffer_getxdim(me), video_buffer_getydim(me));
218+
return video_gfx_clip(self, me->rbf_cxoff, me->rbf_cyoff,
219+
video_buffer_getxdim(me),
220+
video_buffer_getydim(me));
220221
}
221222

222223

kos/src/libvideo/gfx/display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ libvideo_display_forbuffer(struct video_buffer *__restrict buffer) {
103103
result = (REF struct dummy_display *)malloc(sizeof(struct dummy_display));
104104
if unlikely(!result)
105105
goto err;
106-
result->vd_domain = buffer->vb_domain;
106+
result->vd_domain = video_buffer_getdomain(buffer);
107107
result->vd_ops = _dummy_display_ops();
108108
result->vd_refcnt = 1;
109109
result->dd_buffer = buffer;

kos/src/libvideo/gfx/gfx-palettize.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ hist_palettize(struct video_gfx const *__restrict self,
242242

243243
/* Check if the histogram is usable */
244244
if (fail_if_too_many_bins) {
245-
video_dim_t io_sx = _video_gfxhdr_bxsiz(&self->vx_hdr);
246-
video_dim_t io_sy = _video_gfxhdr_bysiz(&self->vx_hdr);
245+
video_dim_t io_sx = video_gfx_getioxdim(self);
246+
video_dim_t io_sy = video_gfx_getioydim(self);
247247
size_t io_pixels = (size_t)io_sx * io_sy;
248248
video_pixel_t i;
249249
size_t pal_pixels = 0;
@@ -265,8 +265,8 @@ hist_palettize(struct video_gfx const *__restrict self,
265265
video_pixel_t i;
266266
uint64_t pal_pixels_adj;
267267
size_t pal_pixels = 0;
268-
video_dim_t io_sx = _video_gfxhdr_bxsiz(&self->vx_hdr);
269-
video_dim_t io_sy = _video_gfxhdr_bysiz(&self->vx_hdr);
268+
video_dim_t io_sx = video_gfx_getioxdim(self);
269+
video_dim_t io_sy = video_gfx_getioydim(self);
270270
size_t io_pixels = (size_t)io_sx * io_sy;
271271
for (i = 0; i < palsize; ++i) {
272272
video_color_t c = h->h_colors[i].hb_color;
@@ -471,7 +471,7 @@ PRIVATE WUNUSED ATTR_PURE video_color_t LIBVIDEO_GFX_FCC
471471
median_io_gfx(void const *cookie, mc_index_t i) {
472472
/* Fallback median-cut I/O callback using direct GFX color reads (slow) */
473473
struct video_gfx const *self = (struct video_gfx const *)cookie;
474-
video_dim_t io_sx = _video_gfxhdr_bxsiz(&self->vx_hdr);
474+
video_dim_t io_sx = video_gfx_getioxdim(self);
475475
video_coord_t y = self->vx_hdr.vxh_bymin + (i / io_sx);
476476
video_coord_t x = self->vx_hdr.vxh_bxmin + (i % io_sx);
477477
/* TODO: Check that "self" is SW-based */
@@ -490,10 +490,10 @@ median_cut_start(struct video_gfx const *__restrict self,
490490
video_color_t constant_alpha) {
491491
struct median_io io;
492492
if (video_gfx_issurfio(self) &&
493-
/* TODO: This actually works for any XXXX8888 codec. Just need to
494-
* "video_gfx_getbuffer(self)->vb_codec->vc_color2pixel" the
495-
* produced palette entries afterwards, and always pass the
496-
* codec's alpha-mask instead of "constant_alpha". */
493+
/* TODO: This actually works for any XXXX8888 codec. Just need to
494+
* "video_gfx_getcodec(self)->vc_color2pixel" the produced
495+
* palette entries afterwards, and always pass the codec's
496+
* alpha-mask instead of "constant_alpha". */
497497
video_gfx_getcodec(self)->vc_codec == VIDEO_CODEC_RGBA8888) {
498498
struct video_lock lock;
499499
if (video_buffer_rlock(video_gfx_getbuffer(self), &lock) == 0) {
@@ -537,8 +537,8 @@ median_cut_palettize(struct video_gfx const *__restrict self,
537537
* its speed against mine (maybe mine just sucks?)
538538
* TODO: Live with median_cut being slow, and adjust documentation accordingly. */
539539
mc_index_t i, io_pixels, *gfx_indices;
540-
video_dim_t io_sx = _video_gfxhdr_bxsiz(&self->vx_hdr);
541-
video_dim_t io_sy = _video_gfxhdr_bysiz(&self->vx_hdr);
540+
video_dim_t io_sx = video_gfx_getioxdim(self);
541+
video_dim_t io_sy = video_gfx_getioydim(self);
542542
shift_t pal_depth;
543543
if (OVERFLOW_UMUL(io_sx, io_sy, &io_pixels)) {
544544
errno = EOVERFLOW;

kos/src/libvideo/gfx/gfx.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,22 @@ libvideo_gfx_offset2coord__generic(struct video_gfx const *__restrict self,
219219
video_offset_t x, video_offset_t y,
220220
video_coord_t coords[2]) {
221221
if (video_gfx_getflags(self) & VIDEO_GFX_F_XMIRROR)
222-
x = (self->vx_hdr.vxh_cxdim - 1) - x;
222+
x = (video_gfx_getclipxdim(self) - 1) - x;
223223
if (video_gfx_getflags(self) & VIDEO_GFX_F_YMIRROR)
224-
y = (self->vx_hdr.vxh_cydim - 1) - y;
224+
y = (video_gfx_getclipydim(self) - 1) - y;
225225
if (video_gfx_getflags(self) & VIDEO_GFX_F_XWRAP)
226-
x = wrap(x, self->vx_hdr.vxh_cxdim);
226+
x = wrap(x, video_gfx_getclipxdim(self));
227227
if (video_gfx_getflags(self) & VIDEO_GFX_F_YWRAP)
228-
x = wrap(x, self->vx_hdr.vxh_cxdim);
229-
x += self->vx_hdr.vxh_cxoff;
230-
y += self->vx_hdr.vxh_cyoff;
231-
if unlikely((video_coord_t)x < self->vx_hdr.vxh_bxmin)
228+
y = wrap(y, video_gfx_getclipydim(self));
229+
x += video_gfx_getclipxmin(self);
230+
y += video_gfx_getclipymin(self);
231+
if unlikely((video_coord_t)x < video_gfx_getioxmin(self))
232232
goto fail;
233-
if unlikely((video_coord_t)y < self->vx_hdr.vxh_bymin)
233+
if unlikely((video_coord_t)y < video_gfx_getioymin(self))
234234
goto fail;
235-
if unlikely((video_coord_t)x >= self->vx_hdr.vxh_bxend)
235+
if unlikely((video_coord_t)x >= video_gfx_getioxend(self))
236236
goto fail;
237-
if unlikely((video_coord_t)y >= self->vx_hdr.vxh_byend)
237+
if unlikely((video_coord_t)y >= video_gfx_getioyend(self))
238238
goto fail;
239239
if (video_gfx_getflags(self) & VIDEO_GFX_F_XYSWAP) {
240240
video_offset_t temp;
@@ -265,20 +265,20 @@ libvideo_gfx_coord2offset__generic(struct video_gfx const *__restrict self,
265265
x = y;
266266
y = temp;
267267
}
268-
if unlikely(x < self->vx_hdr.vxh_bxmin)
268+
if unlikely(x < video_gfx_getioxmin(self))
269269
goto fail;
270-
if unlikely(y < self->vx_hdr.vxh_bymin)
270+
if unlikely(y < video_gfx_getioymin(self))
271271
goto fail;
272-
if unlikely(x >= self->vx_hdr.vxh_bxend)
272+
if unlikely(x >= video_gfx_getioxend(self))
273273
goto fail;
274-
if unlikely(y >= self->vx_hdr.vxh_byend)
274+
if unlikely(y >= video_gfx_getioyend(self))
275275
goto fail;
276-
x -= self->vx_hdr.vxh_cxoff;
277-
y -= self->vx_hdr.vxh_cyoff;
276+
x -= video_gfx_getclipxmin(self);
277+
y -= video_gfx_getclipymin(self);
278278
if (video_gfx_getflags(self) & VIDEO_GFX_F_XMIRROR)
279-
x = (self->vx_hdr.vxh_cxdim - 1) - x;
279+
x = (video_gfx_getclipxdim(self) - 1) - x;
280280
if (video_gfx_getflags(self) & VIDEO_GFX_F_YMIRROR)
281-
y = (self->vx_hdr.vxh_cydim - 1) - y;
281+
y = (video_gfx_getclipydim(self) - 1) - y;
282282
offsets[0] = (video_offset_t)x;
283283
offsets[1] = (video_offset_t)y;
284284
return true;

kos/src/libvideo/gfx/io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ frame2anim(REF struct video_buffer *frame) {
126126
PRIVATE WUNUSED NONNULL((1, 2)) REF struct video_buffer *CC
127127
convert_to_wanted_domain(struct video_domain const *__restrict domain,
128128
/*inherit(always)*/ REF struct video_buffer *__restrict self) {
129-
if unlikely(self->vb_domain != domain) {
129+
if unlikely(video_buffer_getdomain(self) != domain) {
130130
REF struct video_buffer *converted;
131131
struct video_buffer_format result_format;
132132
video_buffer_getformat(self, &result_format);

kos/src/libvideo/gfx/io/bmp.c.inl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ fix_missing_alpha_channel(struct video_buffer *__restrict self) {
194194
};
195195
video_coord_t y;
196196
struct video_rambuffer *me = (struct video_rambuffer *)self;
197-
assert(me->vb_domain == &libvideo_ramdomain);
197+
assert(video_buffer_getdomain(me) == &libvideo_ramdomain);
198198
assert(me->vb_ops == &rambuffer_ops ||
199199
me->vb_ops == &rambuffer_formem_ops);
200-
assert(me->vb_codec->vc_codec == VIDEO_CODEC_RGBA8888);
201-
assert(me->vb_surf.vs_pal == NULL);
200+
assert(video_buffer_getcodec(me)->vc_codec == VIDEO_CODEC_RGBA8888);
201+
assert(video_buffer_getpalette(me) == NULL);
202202
for (y = 0; y < video_buffer_getydim(me); ++y) {
203203
struct pixel *iter, *end;
204204
iter = (struct pixel *)(me->rb_data + y * me->rb_stride);

0 commit comments

Comments
 (0)