diff options
author | kdx <kikoodx@paranoici.org> | 2023-04-16 07:45:46 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-04-16 07:46:02 +0200 |
commit | 1d8bfedd168742bbef782b8ab453f036d9853006 (patch) | |
tree | 8c0f92c0d35f2b4efe4e4f167f1705dcbda735ab | |
parent | e8c38b4786c9103ed18f4508a0294cb7a555f1da (diff) | |
download | px-1d8bfedd168742bbef782b8ab453f036d9853006.tar.gz |
pset and pget
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/px.c | 23 | ||||
-rw-r--r-- | src/px.h | 6 |
3 files changed, 29 insertions, 3 deletions
@@ -16,6 +16,9 @@ main(void) pxClipReset(); pxCls(1); + pxPset(0, 0, 10); + pxPset(1, 0, 10); + pxPset(0, 1, pxPget(0, 0)); pxClip(25, 12, 32, 69); pxCls(2); @@ -44,9 +44,9 @@ pxRender(void) void pxCls(PxCol c) { - for (int y = pxclip.y; y < pxclip.y + pxclip.h - 1; y += 1) - for (int x = pxclip.x; x < pxclip.x + pxclip.w - 1; x += 1) - pxbuf[x + y * PX_WIDTH] = c; + for (int y = 0; y < PX_HEIGHT; y++) + for (int x = 0; x < PX_WIDTH; x++) + pxPset(x, y, c); } void @@ -64,6 +64,23 @@ pxClipReset(void) pxClip(0, 0, PX_WIDTH, PX_HEIGHT); } +void +pxPset(int x, int y, PxCol c) +{ + if (x < pxclip.x || x >= pxclip.x + pxclip.w || + y < pxclip.y || y >= pxclip.y + pxclip.h) + return; + pxbuf[x + y * PX_WIDTH] = c; +} + +uint8_t +pxPget(int x, int y) +{ + if (x < 0 || y < 0 || x >= PX_WIDTH || y >= PX_HEIGHT) + return 0; + return pxbuf[x + y * PX_WIDTH]; +} + int pxMin(int a, int b) { @@ -28,6 +28,12 @@ void pxClip(int x, int y, int w, int h); /* Reset the clipping region. */ void pxClipReset(void); +/* Put a pixel. */ +void pxPset(int x, int y, PxCol c); + +/* Get a pixel. */ +PxCol pxPget(int x, int y); + /*** MATH ***/ int pxMin(int a, int b); int pxMax(int a, int b); |