blit
Loading...
Searching...
No Matches
rgn1.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025, Roy Ratcliffe, Northumberland, United Kingdom
3 * SPDX-License-Identifier: MIT
4 */
14#ifndef __BLIT_RGN1_H__
15#define __BLIT_RGN1_H__
16
17#include <assert.h>
18#include <stdbool.h>
19
26struct blit_rgn1 {
30 int origin;
34 int extent;
39};
40
49static inline void blit_rgn1_norm(struct blit_rgn1 *rgn1) {
50 /*
51 * Normalise the extents. Extents are normally positive. A negative extent
52 * means the destination and source origins specify the far edge of the
53 * rectangle. Two's-complement negative extents and put the origins at the
54 * rectangle's origins.
55 */
56 if (rgn1->extent < 0) {
57 rgn1->extent = -rgn1->extent;
58 rgn1->origin -= rgn1->extent;
59 rgn1->origin_source -= rgn1->extent;
60 }
61 assert(rgn1->extent >= 0);
62}
63
76static inline bool blit_rgn1_slip(struct blit_rgn1 *rgn1) {
77 int offset = rgn1->origin < 0
78 ? (rgn1->origin < rgn1->origin_source ? -rgn1->origin
79 : -rgn1->origin_source)
80 : (rgn1->origin_source < 0 ? -rgn1->origin_source : 0);
81 assert(offset >= 0);
82 if (offset >= rgn1->extent)
83 return false;
84 rgn1->origin += offset;
85 rgn1->origin_source += offset;
86 rgn1->extent -= offset;
87 assert(rgn1->origin >= 0 && rgn1->origin_source >= 0 && 0 < rgn1->extent);
88 return true;
89}
90
102static inline bool blit_rgn1_clip(struct blit_rgn1 *rgn1, int extent) {
103 if (0 >= extent)
104 return false;
105 if (extent < rgn1->extent)
106 rgn1->extent = extent;
107 return true;
108}
109
110#endif /* __BLIT_RGN1_H__ */
One-dimensional region structure.
Definition rgn1.h:26
int origin
Origin of the region.
Definition rgn1.h:30
int origin_source
Source origin of the region.
Definition rgn1.h:38
int extent
Extent of the region.
Definition rgn1.h:34