summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-04-16 07:45:46 +0200
committerkdx <kikoodx@paranoici.org>2023-04-16 07:46:02 +0200
commit1d8bfedd168742bbef782b8ab453f036d9853006 (patch)
tree8c0f92c0d35f2b4efe4e4f167f1705dcbda735ab
parente8c38b4786c9103ed18f4508a0294cb7a555f1da (diff)
downloadpx-1d8bfedd168742bbef782b8ab453f036d9853006.tar.gz
pset and pget
-rw-r--r--src/main.c3
-rw-r--r--src/px.c23
-rw-r--r--src/px.h6
3 files changed, 29 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 29f8a56..db6a715 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
diff --git a/src/px.c b/src/px.c
index 769cd33..3ac1ab7 100644
--- a/src/px.c
+++ b/src/px.c
@@ -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)
{
diff --git a/src/px.h b/src/px.h
index cd2df57..871ff54 100644
--- a/src/px.h
+++ b/src/px.h
@@ -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);