aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-07-28 05:47:48 +0200
committerkdx <kikoodx@paranoici.org>2023-07-28 05:47:48 +0200
commitf892633ce689c5ddf71a9b8e259142535a371418 (patch)
treecd1386bd1d607957e45485078760d7bebc933aaf
parent53ea822e9cb3426c2a045ec09ad11ea183e56685 (diff)
downloadkld-f892633ce689c5ddf71a9b8e259142535a371418.tar.gz
remove image from kldImage functions
-rw-r--r--main.c22
-rw-r--r--src/image.c78
-rw-r--r--src/image.h52
-rw-r--r--tests.c36
4 files changed, 94 insertions, 94 deletions
diff --git a/main.c b/main.c
index e2977fa..aa5c35c 100644
--- a/main.c
+++ b/main.c
@@ -8,22 +8,22 @@ main(int argc, char **argv)
{
mysrand(time(NULL));
- KldImage *cloud = kldImage_load("samples/cloud.jpg");
- KldImage *sky = kldImage_load("samples/sky.jpg");
+ KldImage *cloud = kld_load("samples/cloud.jpg");
+ KldImage *sky = kld_load("samples/sky.jpg");
- kldImage_resize(cloud, sky->width, sky->height, 0);
+ kld_resize(cloud, sky->width, sky->height, 0);
- kldImage_vflip(cloud);
+ kld_vflip(cloud);
- kldImage_invert(sky);
+ kld_invert(sky);
const int m = (argc > 1) ? atoi(argv[1]) : 255;
- kldImage_mod(sky, KLD_COLOR(m, m, m, 255));
+ kld_mod(sky, KLD_COLOR(m, m, m, 255));
- kldImage_sub(cloud, sky);
- kldImage_movechans(cloud, KLD_COLOR(3, 3, 2, -1));
- kldImage_writePAM(cloud, stdout);
+ kld_sub(cloud, sky);
+ kld_movechans(cloud, KLD_COLOR(3, 3, 2, -1));
+ kld_writePAM(cloud, stdout);
- kldImage_free(sky);
- kldImage_free(cloud);
+ kld_free(sky);
+ kld_free(cloud);
return 0;
}
diff --git a/src/image.c b/src/image.c
index 35d6ee5..02e5ced 100644
--- a/src/image.c
+++ b/src/image.c
@@ -23,7 +23,7 @@
#define NULL_SAFETY(X) NULL_SAFETY_EX(img, X)
KldImage *
-kldImage_alloc(size_t w, size_t h)
+kld_alloc(size_t w, size_t h)
{
if (w == 0) {
log_error("width is zero");
@@ -66,7 +66,7 @@ kldImage_alloc(size_t w, size_t h)
}
void
-kldImage_free(KldImage *img)
+kld_free(KldImage *img)
{
NULL_SAFETY();
if (img->data != NULL)
@@ -75,7 +75,7 @@ kldImage_free(KldImage *img)
}
KldImage *
-kldImage_load(const char *path)
+kld_load(const char *path)
{
if (path == NULL) {
log_error("path is NULL");
@@ -95,9 +95,9 @@ kldImage_load(const char *path)
return NULL;
}
- KldImage *img = kldImage_alloc(w, h);
+ KldImage *img = kld_alloc(w, h);
if (img == NULL) {
- log_error("kldImage_alloc failed");
+ log_error("kld_alloc failed");
stbi_image_free(data);
return NULL;
}
@@ -114,7 +114,7 @@ kldImage_load(const char *path)
}
KldColor
-kldImage_get(KldImage *img, int x, int y)
+kld_get(KldImage *img, int x, int y)
{
NULL_SAFETY(0);
@@ -128,7 +128,7 @@ kldImage_get(KldImage *img, int x, int y)
}
void
-kldImage_set(KldImage *img, int x, int y, KldColor col)
+kld_set(KldImage *img, int x, int y, KldColor col)
{
NULL_SAFETY();
@@ -142,13 +142,13 @@ kldImage_set(KldImage *img, int x, int y, KldColor col)
}
KldImage *
-kldImage_dup(KldImage *img)
+kld_dup(KldImage *img)
{
NULL_SAFETY(NULL);
- KldImage *copy = kldImage_alloc(img->width, img->height);
+ KldImage *copy = kld_alloc(img->width, img->height);
if (copy == NULL) {
- log_error("kldImage_alloc failed");
+ log_error("kld_alloc failed");
return NULL;
}
@@ -161,17 +161,17 @@ kldImage_dup(KldImage *img)
/* XXX: this can be optimized by modifying the image in place when possible */
int
-kldImage_resize(KldImage *img, size_t w, size_t h, KldColor bg)
+kld_resize(KldImage *img, size_t w, size_t h, KldColor bg)
{
NULL_SAFETY(-1);
- KldImage *new_img = kldImage_alloc(w, h);
+ KldImage *new_img = kld_alloc(w, h);
if (new_img == NULL) {
- log_error("kldImage_alloc failed");
+ log_error("kld_alloc failed");
return -1;
}
- kldImage_clear(new_img, bg);
- kldImage_copy(new_img, img, 0, 0, 0, 0);
+ kld_clear(new_img, bg);
+ kld_copy(new_img, img, 0, 0, 0, 0);
/* move new_img to img */
free(img->data);
@@ -186,16 +186,16 @@ kldImage_resize(KldImage *img, size_t w, size_t h, KldColor bg)
/* XXX: this can be optimized by modifying the image in place when possible */
int
-kldImage_resizetiled(KldImage *img, size_t w, size_t h)
+kld_resizetiled(KldImage *img, size_t w, size_t h)
{
NULL_SAFETY(-1);
- KldImage *new_img = kldImage_alloc(w, h);
+ KldImage *new_img = kld_alloc(w, h);
if (new_img == NULL) {
- log_error("kldImage_alloc failed");
+ log_error("kld_alloc failed");
return -1;
}
- kldImage_copytiled(new_img, img, 0, 0, 0, 0);
+ kld_copytiled(new_img, img, 0, 0, 0, 0);
/* move new_img to img */
free(img->data);
@@ -209,7 +209,7 @@ kldImage_resizetiled(KldImage *img, size_t w, size_t h)
}
int
-kldImage_writePAM(KldImage *img, FILE *fp)
+kld_writePAM(KldImage *img, FILE *fp)
{
NULL_SAFETY(-1);
@@ -246,7 +246,7 @@ kldImage_writePAM(KldImage *img, FILE *fp)
}
void
-kldImage_clear(KldImage *img, KldColor color)
+kld_clear(KldImage *img, KldColor color)
{
NULL_SAFETY();
@@ -255,7 +255,7 @@ kldImage_clear(KldImage *img, KldColor color)
}
void
-kldImage_copy(KldImage *dest, KldImage *src, int x, int y, int w, int h)
+kld_copy(KldImage *dest, KldImage *src, int x, int y, int w, int h)
{
NULL_SAFETY_EX_NO_RV(dest);
NULL_SAFETY_EX_NO_RV(src);
@@ -280,7 +280,7 @@ kldImage_copy(KldImage *dest, KldImage *src, int x, int y, int w, int h)
dx = x;
}
while (ix < src->width && dx < dest->width && --h != 0) {
- kldImage_set(dest, dx, dy, kldImage_get(src, ix, iy));
+ kld_set(dest, dx, dy, kld_get(src, ix, iy));
dx += 1;
ix += 1;
}
@@ -290,7 +290,7 @@ kldImage_copy(KldImage *dest, KldImage *src, int x, int y, int w, int h)
}
void
-kldImage_copytiled(KldImage *dest, KldImage *src, int x, int y, int w, int h)
+kld_copytiled(KldImage *dest, KldImage *src, int x, int y, int w, int h)
{
NULL_SAFETY_EX_NO_RV(dest);
NULL_SAFETY_EX_NO_RV(src);
@@ -301,7 +301,7 @@ kldImage_copytiled(KldImage *dest, KldImage *src, int x, int y, int w, int h)
size_t ix = -x;
size_t dx = 0;
while (dx < dest->width && --w != 0) {
- kldImage_set(dest, dx, dy, kldImage_get(src, ix, iy));
+ kld_set(dest, dx, dy, kld_get(src, ix, iy));
dx += 1;
ix += 1;
}
@@ -311,7 +311,7 @@ kldImage_copytiled(KldImage *dest, KldImage *src, int x, int y, int w, int h)
}
void
-kldImage_hflip(KldImage *img)
+kld_hflip(KldImage *img)
{
NULL_SAFETY();
@@ -327,7 +327,7 @@ kldImage_hflip(KldImage *img)
}
void
-kldImage_vflip(KldImage *img)
+kld_vflip(KldImage *img)
{
NULL_SAFETY();
@@ -344,7 +344,7 @@ kldImage_vflip(KldImage *img)
}
void
-kldImage_swapdims(KldImage *img)
+kld_swapdims(KldImage *img)
{
NULL_SAFETY();
@@ -354,7 +354,7 @@ kldImage_swapdims(KldImage *img)
}
void
-kldImage_invert(KldImage *img)
+kld_invert(KldImage *img)
{
NULL_SAFETY();
@@ -368,7 +368,7 @@ kldImage_invert(KldImage *img)
}
void
-kldImage_invertalpha(KldImage *img)
+kld_invertalpha(KldImage *img)
{
NULL_SAFETY();
@@ -382,7 +382,7 @@ kldImage_invertalpha(KldImage *img)
}
void
-kldImage_grayscale(KldImage *img)
+kld_grayscale(KldImage *img)
{
NULL_SAFETY();
@@ -397,7 +397,7 @@ kldImage_grayscale(KldImage *img)
}
void
-kldImage_chaos3(KldImage *img)
+kld_chaos3(KldImage *img)
{
NULL_SAFETY();
@@ -413,7 +413,7 @@ kldImage_chaos3(KldImage *img)
}
void
-kldImage_bit3(KldImage *img)
+kld_bit3(KldImage *img)
{
NULL_SAFETY();
@@ -429,7 +429,7 @@ kldImage_bit3(KldImage *img)
}
void
-kldImage_mod(KldImage *img, KldColor mask)
+kld_mod(KldImage *img, KldColor mask)
{
NULL_SAFETY();
@@ -445,7 +445,7 @@ kldImage_mod(KldImage *img, KldColor mask)
}
void
-kldImage_movechans(KldImage *img, KldColor cmd)
+kld_movechans(KldImage *img, KldColor cmd)
{
NULL_SAFETY();
@@ -474,7 +474,7 @@ kldImage_movechans(KldImage *img, KldColor cmd)
}
int
-kldImage_blend(KldImage *img, KldImage *other, float ratio)
+kld_blend(KldImage *img, KldImage *other, float ratio)
{
NULL_SAFETY(-1);
NULL_SAFETY_EX(other, -1);
@@ -502,7 +502,7 @@ kldImage_blend(KldImage *img, KldImage *other, float ratio)
}
int
-kldImage_add(KldImage *img, KldImage *other)
+kld_add(KldImage *img, KldImage *other)
{
NULL_SAFETY(-1);
NULL_SAFETY_EX(other, -1);
@@ -533,7 +533,7 @@ kldImage_add(KldImage *img, KldImage *other)
}
int
-kldImage_sub(KldImage *img, KldImage *other)
+kld_sub(KldImage *img, KldImage *other)
{
NULL_SAFETY(-1);
NULL_SAFETY_EX(other, -1);
@@ -563,7 +563,7 @@ kldImage_sub(KldImage *img, KldImage *other)
}
int
-kldImage_subalpha(KldImage *img, KldImage *other)
+kld_subalpha(KldImage *img, KldImage *other)
{
NULL_SAFETY(-1);
NULL_SAFETY_EX(other, -1);
diff --git a/src/image.h b/src/image.h
index 95fe32f..a919561 100644
--- a/src/image.h
+++ b/src/image.h
@@ -4,69 +4,69 @@
#include <stdio.h>
/* return NULL on error */
-KldImage *kldImage_alloc(size_t w, size_t h);
+KldImage *kld_alloc(size_t w, size_t h);
-void kldImage_free(KldImage *img);
+void kld_free(KldImage *img);
-KldColor kldImage_get(KldImage *img, int x, int y);
+KldColor kld_get(KldImage *img, int x, int y);
-void kldImage_set(KldImage *img, int x, int y, KldColor col);
+void kld_set(KldImage *img, int x, int y, KldColor col);
/* return NULL on error */
-KldImage *kldImage_load(const char *path);
+KldImage *kld_load(const char *path);
/* return NULL on error */
-KldImage *kldImage_dup(KldImage *img);
+KldImage *kld_dup(KldImage *img);
/* on error, return -1 and make no change */
-int kldImage_resize(KldImage *img, size_t w, size_t h, KldColor bg);
+int kld_resize(KldImage *img, size_t w, size_t h, KldColor bg);
/* on error, return -1 and make no change */
-int kldImage_resizetiled(KldImage *img, size_t w, size_t h);
+int kld_resizetiled(KldImage *img, size_t w, size_t h);
/* return -1 on error */
-int kldImage_writePAM(KldImage *img, FILE *fp);
+int kld_writePAM(KldImage *img, FILE *fp);
-void kldImage_clear(KldImage *img, KldColor color);
+void kld_clear(KldImage *img, KldColor color);
-void kldImage_copy(KldImage *dest, KldImage *src, int x, int y, int w, int h);
+void kld_copy(KldImage *dest, KldImage *src, int x, int y, int w, int h);
-void kldImage_copytiled(KldImage *dest, KldImage *src, int x, int y, int w, int h);
+void kld_copytiled(KldImage *dest, KldImage *src, int x, int y, int w, int h);
/* hflip should be faster than vflip */
-void kldImage_hflip(KldImage *img);
+void kld_hflip(KldImage *img);
-void kldImage_vflip(KldImage *img);
+void kld_vflip(KldImage *img);
-void kldImage_swapdims(KldImage *img);
+void kld_swapdims(KldImage *img);
/* doesn't affect alpha */
-void kldImage_invert(KldImage *img);
+void kld_invert(KldImage *img);
-void kldImage_invertalpha(KldImage *img);
+void kld_invertalpha(KldImage *img);
-void kldImage_grayscale(KldImage *img);
+void kld_grayscale(KldImage *img);
-void kldImage_chaos3(KldImage *img);
+void kld_chaos3(KldImage *img);
-void kldImage_bit3(KldImage *img);
+void kld_bit3(KldImage *img);
-void kldImage_mod(KldImage *img, KldColor mask);
+void kld_mod(KldImage *img, KldColor mask);
/* cmd examples:
* KLD_COLOR(-1, -1, -1, -1) does nothing
* KLD_COLOR(2, 3, 1, -1) R->G G->B B->R A->A
* KLD_COLOR(4, -1, 0, 3) R->A B->0 A->B */
-void kldImage_movechans(KldImage *img, KldColor cmd);
+void kld_movechans(KldImage *img, KldColor cmd);
/* return -1 if sizes are not equal */
-int kldImage_blend(KldImage *img, KldImage *other, float ratio);
+int kld_blend(KldImage *img, KldImage *other, float ratio);
/* return -1 if sizes are not equal */
-int kldImage_add(KldImage *img, KldImage *other);
+int kld_add(KldImage *img, KldImage *other);
/* return -1 if sizes are not equal; ignores alpha */
-int kldImage_sub(KldImage *img, KldImage *other);
+int kld_sub(KldImage *img, KldImage *other);
/* return -1 if sizes are not equal */
-int kldImage_subalpha(KldImage *img, KldImage *other);
+int kld_subalpha(KldImage *img, KldImage *other);
diff --git a/tests.c b/tests.c
index d35afaf..c8bc18c 100644
--- a/tests.c
+++ b/tests.c
@@ -6,72 +6,72 @@
static void
alloc_clear_free(size_t w, size_t h, bool expect_null)
{
- KldImage *img = kldImage_alloc(w, h);
+ KldImage *img = kld_alloc(w, h);
if (expect_null)
ok(img == NULL, "alloc_clear_free %lu x %lu", w, h);
else
ok(img != NULL, "alloc_clear_free %lu x %lu", w, h);
- kldImage_clear(img, KLD_COLOR(255, 0, 255, 255));
- kldImage_free(img);
+ kld_clear(img, KLD_COLOR(255, 0, 255, 255));
+ kld_free(img);
}
static void
alloc_swapdims_free(size_t w, size_t h, bool expect_null)
{
- KldImage *img = kldImage_alloc(w, h);
- kldImage_swapdims(img);
+ KldImage *img = kld_alloc(w, h);
+ kld_swapdims(img);
if (expect_null)
ok(img == NULL, "alloc_swapdims_free %lu x %lu", w, h);
else
ok(img != NULL && img->width == h && img->height == w,
"alloc_swapdims_free %lu x %lu", w, h);
- kldImage_free(img);
+ kld_free(img);
}
static void
alloc_dup_free(size_t w, size_t h, bool expect_null)
{
- KldImage *img = kldImage_alloc(w, h);
- KldImage *copy = kldImage_dup(img);
+ KldImage *img = kld_alloc(w, h);
+ KldImage *copy = kld_dup(img);
if (expect_null)
ok(img == NULL && copy == NULL, "alloc_dup_free %lu x %lu", w, h);
else
ok(img != NULL && copy != NULL, "alloc_dup_free %lu x %lu", w, h);
- kldImage_free(copy);
- kldImage_free(img);
+ kld_free(copy);
+ kld_free(img);
}
static void
alloc_small_resize_free(size_t w, size_t h, bool expect_null)
{
- KldImage *img = kldImage_alloc(1, 1);
- if ((kldImage_resize(img, w, h, 0) != 0) ^ expect_null)
+ KldImage *img = kld_alloc(1, 1);
+ if ((kld_resize(img, w, h, 0) != 0) ^ expect_null)
ok(false, "small_resize_free %lu x %lu", w, h);
else
ok(true, "small_resize_free %lu x %lu", w, h);
- kldImage_free(img);
+ kld_free(img);
}
static void
alloc_small_resizetiled_free(size_t w, size_t h, bool expect_null)
{
- KldImage *img = kldImage_alloc(1, 1);
- if ((kldImage_resizetiled(img, w, h) != 0) ^ expect_null)
+ KldImage *img = kld_alloc(1, 1);
+ if ((kld_resizetiled(img, w, h) != 0) ^ expect_null)
ok(false, "small_resizetiled_free %lu x %lu", w, h);
else
ok(true, "small_resizetiled_free %lu x %lu", w, h);
- kldImage_free(img);
+ kld_free(img);
}
static void
load_free(const char *path, bool expect_null)
{
- KldImage *img = kldImage_load(path);
+ KldImage *img = kld_load(path);
if (expect_null)
ok(img == NULL, "load_free '%s'", path ? path : "(null)");
else
ok(img != NULL, "load_free '%s'", path ? path : "(null)");
- kldImage_free(img);
+ kld_free(img);
}
#define TEST_BATCH(W, H, B) do { \