Gfxprim
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- 929 discussions
16 Jun '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 1969d4407b36047206e4e846594570086f4d5dde (commit)
from 4e298cb7cb11a0e161a4522d4f5a8496baac8f3c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/1969d4407b36047206e4e846594570086f4d…
commit 1969d4407b36047206e4e846594570086f4d5dde
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 16 11:56:09 2013 +0200
loaders: Add forgotten PNM header.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/include/loaders/GP_PNM.h b/include/loaders/GP_PNM.h
new file mode 100644
index 0000000..917a10d
--- /dev/null
+++ b/include/loaders/GP_PNM.h
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#ifndef LOADERS_GP_PNM_H
+#define LOADERS_GP_PNM_H
+
+#include "core/GP_Context.h"
+#include "core/GP_ProgressCallback.h"
+
+/*
+ * PBM Bitmap
+ */
+GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback);
+
+int GP_SavePBM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback);
+
+/*
+ * PGM Graymap
+ */
+GP_Context *GP_LoadPGM(const char *src_path,
+ GP_ProgressCallback *callback);
+
+int GP_SavePGM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback);
+
+/*
+ * PPM Pixmap
+ */
+GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback);
+
+int GP_SavePPM(GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback);
+
+/*
+ * PNM Anymap (All of above)
+ */
+GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback);
+
+int GP_SavePNM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback);
+
+/*
+ * ASCII or rawbits Bitmap.
+ */
+int GP_MatchPBM(const void *buf);
+
+/*
+ * ASCII or rawbits Graymap.
+ */
+int GP_MatchPGM(const void *buf);
+
+/*
+ * ASCII or rawbits Pixmap.
+ */
+int GP_MatchPPM(const void *buf);
+
+/*
+ * All of above.
+ */
+int GP_MatchPNM(const void *buf);
+
+#endif /* LOADERS_GP_PNM_H */
-----------------------------------------------------------------------
Summary of changes:
include/loaders/{GP_JPG.h => GP_PNM.h} | 64 +++++++++++++++++++-------------
1 files changed, 38 insertions(+), 26 deletions(-)
copy include/loaders/{GP_JPG.h => GP_PNM.h} (60%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
16 Jun '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 4e298cb7cb11a0e161a4522d4f5a8496baac8f3c (commit)
via 4233e033b8b0c03a3a370a86e1e2d87bd3ba3d40 (commit)
from 3354fbc9c92960230a3111ac5ae82064bc8c63a2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/4e298cb7cb11a0e161a4522d4f5a8496baac…
commit 4e298cb7cb11a0e161a4522d4f5a8496baac8f3c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 16 11:46:48 2013 +0200
tests: loaders: First simple PBM tests.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/tests/loaders/Makefile b/tests/loaders/Makefile
index d8c1fcb..304e956 100644
--- a/tests/loaders/Makefile
+++ b/tests/loaders/Makefile
@@ -3,7 +3,7 @@ include $(TOPDIR)/pre.mk
CSOURCES=$(shell echo *.c)
-APPS=loaders_suite PNG
+APPS=loaders_suite PNG PBM
include ../tests.mk
diff --git a/tests/loaders/PBM.c b/tests/loaders/PBM.c
new file mode 100644
index 0000000..2c76792
--- /dev/null
+++ b/tests/loaders/PBM.c
@@ -0,0 +1,196 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include <core/GP_Context.h>
+#include <core/GP_GetPutPixel.h>
+#include <loaders/GP_Loaders.h>
+
+#include "tst_test.h"
+
+struct testcase {
+ GP_Size w;
+ GP_Size h;
+ GP_Pixel pix;
+ char *path;
+};
+
+static int test_load_PBM(struct testcase *test)
+{
+ GP_Context *img;
+ unsigned int x, y, err = 0;
+
+ errno = 0;
+
+ img = GP_LoadPBM(test->path, NULL);
+
+ if (img == NULL) {
+ switch (errno) {
+ case ENOSYS:
+ tst_msg("Not Implemented");
+ return TST_SKIPPED;
+ default:
+ tst_msg("Got %s", strerror(errno));
+ return TST_FAILED;
+ }
+ }
+
+ if (img->w != test->w || img->h != test->h) {
+ tst_msg("Invalid image size have %ux%u expected %ux%u",
+ img->w, img->h, test->w, test->h);
+ GP_ContextFree(img);
+ return TST_FAILED;
+ }
+
+ for (x = 0; x < img->w; x++) {
+ for (y = 0; y < img->h; y++) {
+
+ GP_Pixel pix = GP_GetPixel(img, x, y);
+
+ if (pix != test->pix) {
+ if (err < 5)
+ tst_msg("%08x instead of %08x (%ux%u)",
+ pix, test->pix, x, y);
+ err++;
+ }
+ }
+ }
+
+ GP_ContextFree(img);
+
+ if (err)
+ return TST_FAILED;
+
+ return TST_SUCCESS;
+}
+
+static int test_load_fail_PBM(const char *path)
+{
+ GP_Context *img;
+
+ errno = 0;
+
+ img = GP_LoadPBM(path, NULL);
+
+ if (img != NULL) {
+ tst_msg("Succeeded unexpectedly");
+ GP_ContextFree(img);
+ return TST_FAILED;
+ }
+
+ switch (errno) {
+ case ENOSYS:
+ tst_msg("Not Implemented");
+ return TST_SKIPPED;
+ default:
+ tst_msg("Got %s", strerror(errno));
+ return TST_SUCCESS;
+ }
+}
+
+struct testcase black_1x1_1 = {
+ .w = 1,
+ .h = 1,
+ .pix = 0,
+ .path = "black_1x1_1.pbm",
+};
+
+struct testcase black_1x1_2 = {
+ .w = 1,
+ .h = 1,
+ .pix = 0,
+ .path = "black_1x1_2.pbm",
+};
+
+struct testcase black_1x1_3 = {
+ .w = 1,
+ .h = 1,
+ .pix = 0,
+ .path = "black_1x1_3.pbm",
+};
+
+struct testcase black_1x1_4 = {
+ .w = 1,
+ .h = 1,
+ .pix = 0,
+ .path = "black_1x1_4.pbm",
+};
+
+struct testcase white_1x1 = {
+ .w = 1,
+ .h = 1,
+ .pix = 1,
+ .path = "white_1x1.pbm",
+};
+
+const struct tst_suite tst_suite = {
+ .suite_name = "PBM",
+ .tests = {
+ {.name = "PBM Load 1x1 (black)",
+ .tst_fn = test_load_PBM,
+ //TODO: Add copy to to res path
+ .res_path = "data/pbm/valid/black_1x1_1.pbm",
+ .data = &black_1x1_1,
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PBM Load 1x1 (white)",
+ .tst_fn = test_load_PBM,
+ .res_path = "data/pbm/valid/white_1x1.pbm",
+ .data = &white_1x1,
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PBM Load 1x1 +comments",
+ .tst_fn = test_load_PBM,
+ .res_path = "data/pbm/valid/black_1x1_2.pbm",
+ .data = &black_1x1_2,
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PBM Load 1x1 +comments +whitespaces",
+ .tst_fn = test_load_PBM,
+ .res_path = "data/pbm/valid/black_1x1_3.pbm",
+ .data = &black_1x1_3,
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PBM Load 1x1 (invalid loadable)",
+ .tst_fn = test_load_PBM,
+ .res_path = "data/pbm/valid/black_1x1_4.pbm",
+ .data = &black_1x1_4,
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PBM Load corrupt",
+ .tst_fn = test_load_fail_PBM,
+ .res_path = "data/pbm/corrupt/short.pbm",
+ .data = "short.pbm",
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = "PBM Load empty",
+ .tst_fn = test_load_fail_PBM,
+ .res_path = "data/pbm/corrupt/empty.pbm",
+ .data = "empty.pbm",
+ .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+
+ {.name = NULL},
+ }
+};
diff --git a/tests/loaders/data/pbm/corrupt/empty.pbm b/tests/loaders/data/pbm/corrupt/empty.pbm
new file mode 100644
index 0000000..e69de29
diff --git a/tests/loaders/data/pbm/corrupt/short.pbm b/tests/loaders/data/pbm/corrupt/short.pbm
new file mode 100644
index 0000000..77eee90
--- /dev/null
+++ b/tests/loaders/data/pbm/corrupt/short.pbm
@@ -0,0 +1,3 @@
+P1
+10 10
+1 0 0 1
diff --git a/tests/loaders/data/pbm/valid/black_1x1_1.pbm b/tests/loaders/data/pbm/valid/black_1x1_1.pbm
new file mode 100644
index 0000000..d089e44
--- /dev/null
+++ b/tests/loaders/data/pbm/valid/black_1x1_1.pbm
@@ -0,0 +1,3 @@
+P1
+1 1
+1
diff --git a/tests/loaders/data/pbm/valid/black_1x1_2.pbm b/tests/loaders/data/pbm/valid/black_1x1_2.pbm
new file mode 100644
index 0000000..c0e1188
--- /dev/null
+++ b/tests/loaders/data/pbm/valid/black_1x1_2.pbm
@@ -0,0 +1,4 @@
+P1
+# Comment
+1 1
+1
diff --git a/tests/loaders/data/pbm/valid/black_1x1_3.pbm b/tests/loaders/data/pbm/valid/black_1x1_3.pbm
new file mode 100644
index 0000000..85e3a7a
--- /dev/null
+++ b/tests/loaders/data/pbm/valid/black_1x1_3.pbm
@@ -0,0 +1,8 @@
+P1
+# Comment
+
+
+
+1 1
+# Comment
+ 1
diff --git a/tests/loaders/data/pbm/valid/black_1x1_4.pbm b/tests/loaders/data/pbm/valid/black_1x1_4.pbm
new file mode 100644
index 0000000..37f4e62
--- /dev/null
+++ b/tests/loaders/data/pbm/valid/black_1x1_4.pbm
@@ -0,0 +1,4 @@
+P1 invalid but works
+1 1
+ # invalid comment
+ 1
diff --git a/tests/loaders/data/pbm/valid/white_1x1.pbm b/tests/loaders/data/pbm/valid/white_1x1.pbm
new file mode 100644
index 0000000..d013b84
--- /dev/null
+++ b/tests/loaders/data/pbm/valid/white_1x1.pbm
@@ -0,0 +1,3 @@
+P1
+1 1
+0
diff --git a/tests/loaders/test_list.txt b/tests/loaders/test_list.txt
index f4a8fe1..8a20a1d 100644
--- a/tests/loaders/test_list.txt
+++ b/tests/loaders/test_list.txt
@@ -1,3 +1,4 @@
# Loaders testsuite
loaders_suite
PNG
+PBM
http://repo.or.cz/w/gfxprim.git/commit/4233e033b8b0c03a3a370a86e1e2d87bd3ba…
commit 4233e033b8b0c03a3a370a86e1e2d87bd3ba3d40
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jun 15 00:39:13 2013 +0200
lib: loaders: Rewrite PNM loaders.
* Not yet finished
* Loading and saving ASCII format works fine
* Binary are on TODO
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt
index 683c410..9820d2f 100644
--- a/build/syms/Loaders_symbols.txt
+++ b/build/syms/Loaders_symbols.txt
@@ -38,25 +38,21 @@ GP_OpenTIFF
GP_ReadTIFF
GP_LoadTIFF
-GP_SavePPM
-GP_LoadPPM
+GP_SavePBM
+GP_LoadPBM
+GP_MatchPBM
GP_SavePGM
GP_LoadPGM
+GP_MatchPGM
-GP_ReadPNM
-GP_WritePNM
-
-GP_SavePBM
-GP_LoadPBM
+GP_SavePPM
+GP_LoadPPM
+GP_MatchPPM
-GP_PXMSave1bpp
-GP_PXMSave2bpp
-GP_PXMSave8bpp
-GP_PXMLoad1bpp
-GP_PXMLoad2bpp
-GP_PXMLoad4bpp
-GP_PXMLoad8bpp
+GP_LoadPNM
+GP_SavePNM
+GP_MatchPNM
GP_SaveTmpFile
GP_LoadTmpFile
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index ee9d349..d74eb0f 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -981,7 +981,7 @@ static void save_by_fmt(struct GP_Context *bitmap, const char *name, const char
progress_prefix = "Saving Image";
if (!strcmp(fmt, "ppm"))
- ret = GP_SavePPM(name, bitmap, "b", progress_callback);
+ ret = GP_SavePPM(bitmap, name, progress_callback);
else if (!strcmp(fmt, "jpg"))
ret = GP_SaveJPG(bitmap, name, progress_callback);
else if (!strcmp(fmt, "png"))
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h
index 5ee30b3..31066d3 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_Loaders.h
@@ -35,10 +35,7 @@
#include "core/GP_Context.h"
#include "core/GP_ProgressCallback.h"
-#include "GP_PBM.h"
-#include "GP_PGM.h"
-#include "GP_PPM.h"
-
+#include "GP_PNM.h"
#include "GP_BMP.h"
#include "GP_PNG.h"
#include "GP_JPG.h"
diff --git a/include/loaders/GP_PBM.h b/include/loaders/GP_PBM.h
deleted file mode 100644
index 1603aff..0000000
--- a/include/loaders/GP_PBM.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#ifndef LOADERS_GP_PBM_H
-#define LOADERS_GP_PBM_H
-
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-
-/*
- * Loads 1-bit Grayscale image from portable bitmap format.
- */
-GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback);
-
-/*
- * Save 1-bit Grayscale image into portable bitmap format.
- *
- * On success zero is returned, otherwise non-zero is returned and errno is
- * filled:
- *
- * EINVAL - context pixel type was not 1 bit grayscale.
- *
- */
-int GP_SavePBM(const GP_Context *src, const char *res_path,
- GP_ProgressCallback *callback);
-
-#endif /* LOADERS_GP_PBM_H */
diff --git a/include/loaders/GP_PGM.h b/include/loaders/GP_PGM.h
deleted file mode 100644
index 7b930cd..0000000
--- a/include/loaders/GP_PGM.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#ifndef LOADERS_GP_PGM_H
-#define LOADERS_GP_PGM_H
-
-#include "core/GP_Context.h"
-
-GP_Context *GP_LoadPGM(const char *src_path,
- GP_ProgressCallback *callback);
-
-int GP_SavePGM(const GP_Context *src, const char *res_path,
- GP_ProgressCallback *callback);
-
-#endif /* LOADERS_GP_PGM_H */
diff --git a/include/loaders/GP_PPM.h b/include/loaders/GP_PPM.h
deleted file mode 100644
index 4ac1bf1..0000000
--- a/include/loaders/GP_PPM.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#ifndef LOADERS_GP_PPM_H
-#define LOADERS_GP_PPM_H
-
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-
-GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback);
-
-/*
- * The fmt may be either "a" for ASCII or "b" for BINARY.
- */
-int GP_SavePPM(const char *res_path, GP_Context *src, char *fmt,
- GP_ProgressCallback *callback);
-
-#endif /* LOADERS_GP_PPM_H */
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index 4e154e9..fb1bee0 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -51,8 +51,8 @@ static GP_Loader psp_loader = {
static GP_Loader pbm_loader = {
.Load = GP_LoadPBM,
.Save = GP_SavePBM,
- .Match = NULL,
- .fmt_name = "Netpbm portable bitmap",
+ .Match = GP_MatchPBM,
+ .fmt_name = "Netpbm portable Bitmap",
.next = &psp_loader,
.extensions = {"pbm", NULL},
};
@@ -60,8 +60,8 @@ static GP_Loader pbm_loader = {
static GP_Loader pgm_loader = {
.Load = GP_LoadPGM,
.Save = GP_SavePGM,
- .Match = NULL,
- .fmt_name = "Netpbm portable graymap",
+ .Match = GP_MatchPGM,
+ .fmt_name = "Netpbm portable Graymap",
.next = &pbm_loader,
.extensions = {"pgm", NULL},
};
@@ -69,18 +69,31 @@ static GP_Loader pgm_loader = {
static GP_Loader ppm_loader = {
.Load = GP_LoadPPM,
.Save = NULL,
- .Match = NULL,
- .fmt_name = "Netpbm portable pixmap",
+ .Match = GP_MatchPPM,
+ .fmt_name = "Netpbm portable Pixmap",
.next = &pgm_loader,
.extensions = {"ppm", NULL},
};
+static GP_Loader pnm_loader = {
+ .Load = GP_LoadPNM,
+ .Save = NULL,
+ /*
+ * Avoid double Match
+ * This format is covered by PBM, PGM and PPM
+ */
+ .Match = NULL,
+ .fmt_name = "Netpbm portable Anymap",
+ .next = &ppm_loader,
+ .extensions = {"pnm", NULL},
+};
+
static GP_Loader bmp_loader = {
.Load = GP_LoadBMP,
.Save = GP_SaveBMP,
.Match = GP_MatchBMP,
.fmt_name = "BMP",
- .next = &ppm_loader,
+ .next = &pnm_loader,
.extensions = {"bmp", "dib", NULL},
};
diff --git a/libs/loaders/GP_PBM.c b/libs/loaders/GP_PBM.c
deleted file mode 100644
index e481684..0000000
--- a/libs/loaders/GP_PBM.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-/*
-
- PBM portable bitmap loader/saver.
-
- Format:
-
- a magick number value of 'P' and '1'
- whitespace (blanks, TABs, CRs, LFs).
- ascii width
- whitespace
- ascii height
- whitespace
- width * height symbols '1' or '0' ('1' == black, '0' == white)
-
- lines starting with '#' are comments to the end of line
-
- */
-
-#include <stdio.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <errno.h>
-
-#include "GP_PXMCommon.h"
-#include "GP_PBM.h"
-
-GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback)
-{
- FILE *f;
- GP_Context *ret;
- uint32_t w, h;
- int err;
-
- f = fopen(src_path, "r");
-
- if (f == NULL)
- return NULL;
-
- if (fgetc(f) != 'P' || fgetc(f) != '1') {
- err = feof(f) ? EIO : EINVAL;
- goto err1;
- }
-
- if (fscanf(f, "%"PRIu32"%"PRIu32, &w, &h) < 2) {
- err = EIO;
- goto err1;
- }
-
- ret = GP_ContextAlloc(w, h, GP_PIXEL_G1);
-
- if (ret == NULL) {
- err = ENOMEM;
- goto err1;
- }
-
- if (GP_PXMLoad1bpp(f, ret)) {
- err = EINVAL;
- goto err2;
- }
-
- fclose(f);
- return ret;
-err2:
- free(ret);
-err1:
- fclose(f);
- errno = err;
- return NULL;
-}
-
-int GP_SavePBM(const GP_Context *src, const char *res_path,
- GP_ProgressCallback *callback)
-{
- FILE *f;
-
- if (src->pixel_type != GP_PIXEL_G1) {
- errno = EINVAL;
- return 1;
- }
-
- f = fopen(res_path, "w");
-
- if (f == NULL)
- return 1;
-
- if (fprintf(f, "P1n%u %un# Generated by gfxprimn",
- (unsigned int) src->w, (unsigned int) src->h) < 2)
- goto err;
-
- if (GP_PXMSave1bpp(f, src))
- goto err;
-
- if (fclose(f))
- return 1;
-
- return 0;
-err:
- fclose(f);
- //TODO: better errors
- errno = EIO;
- return 1;
-}
diff --git a/libs/loaders/GP_PGM.c b/libs/loaders/GP_PGM.c
deleted file mode 100644
index 4a2321d..0000000
--- a/libs/loaders/GP_PGM.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-/*
-
- PGM portable graymap loader/saver.
-
- Format:
-
- a magick number value of 'P' and '2'
- whitespace (blanks, TABs, CRs, LFs).
- ascii width
- whitespace
- ascii height
- whitespace
- maximal gray value (interval is 0 ... max)
- width * height ascii gray values
-
- lines starting with '#' are comments to the end of line
-
- */
-
-#include <stdio.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <string.h>
-#include <ctype.h>
-
-#include <GP_Debug.h>
-
-#include "GP_PXMCommon.h"
-#include "GP_PGM.h"
-
-static void try_read_comments(FILE *f)
-{
- char c1, c2;
-
- while (isspace(c1 = fgetc(f)));
-
- ungetc(c1, f);
-
- while ((c1 = fgetc(f)) == '#') {
- do {
- c2 = fgetc(f);
- } while (c2 != 'n' && c2 != EOF);
- }
-
- ungetc(c1, f);
-}
-
-GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback)
-{
- FILE *f;
- GP_Context *ret;
- uint32_t w, h, gray;
- GP_PixelType type;
- char h1, h2;
- int err = EIO;
-
- f = fopen(src_path, "r");
-
- if (f == NULL) {
- err = errno;
- GP_DEBUG(1, "Failed to open file '%s': %s",
- src_path, strerror(errno));
- goto err0;
- }
-
- h1 = fgetc(f);
- h2 = fgetc(f);
-
- if (feof(f)) {
- err = EIO;
- goto err1;
- }
-
- if (h1 != 'P' || h2 != '2') {
- GP_DEBUG(1, "Invalid PGM header '%c%c' (0x%2x 0x%2x)",
- isprint(h1) ? h1 : ' ', isprint(h2) ? h2 : ' ',
- h1, h2);
- err = EINVAL;
- goto err1;
- }
-
- try_read_comments(f);
-
- if (fscanf(f, "%"PRIu32, &w) < 1) {
- err = errno;
- GP_DEBUG(1, "Failed to read PGM header width");
- goto err1;
- }
-
- try_read_comments(f);
-
- if (fscanf(f, "%"PRIu32, &h) < 1) {
- err = errno;
- GP_DEBUG(1, "Failed to read PGM header height");
- goto err1;
- }
-
- try_read_comments(f);
-
- if (fscanf(f, "%"PRIu32, &gray) < 1) {
- err = errno;
- GP_DEBUG(1, "Failed to read PGM header gray");
- goto err1;
- }
-
- switch (gray) {
- case 1:
- type = GP_PIXEL_G1;
- break;
- case 3:
- type = GP_PIXEL_G2;
- break;
- case 15:
- type = GP_PIXEL_G4;
- break;
- case 255:
- type = GP_PIXEL_G8;
- break;
- default:
- GP_DEBUG(1, "Invalid number of grays %u", gray);
- err = EINVAL;
- goto err1;
- }
-
- ret = GP_ContextAlloc(w, h, type);
-
- if (ret == NULL) {
- err = ENOMEM;
- goto err1;
- }
-
- //TODO: errno here
- switch (gray) {
- case 1:
- if (GP_PXMLoad1bpp(f, ret))
- goto err2;
- break;
- case 3:
- if (GP_PXMLoad2bpp(f, ret))
- goto err2;
- break;
- case 15:
- if (GP_PXMLoad4bpp(f, ret))
- goto err2;
- break;
- case 255:
- if (GP_PXMLoad8bpp(f, ret))
- goto err2;
- break;
- }
-
- fclose(f);
- return ret;
-err2:
- GP_ContextFree(ret);
-err1:
- fclose(f);
-err0:
- errno = err;
- return NULL;
-}
-
-int GP_SavePGM(const GP_Context *src, const char *res_path,
- GP_ProgressCallback *callback)
-{
- FILE *f;
- uint32_t gray;
- int err = EIO;
-
- switch (src->pixel_type) {
- case GP_PIXEL_G1:
- gray = 1;
- break;
- case GP_PIXEL_G2:
- gray = 3;
- break;
- case GP_PIXEL_G4:
- gray = 15;
- break;
- case GP_PIXEL_G8:
- gray = 255;
- break;
- default:
- GP_DEBUG(1, "Invalid pixel type '%s'",
- GP_PixelTypeName(src->pixel_type));
- errno = EINVAL;
- return 1;
- }
-
- f = fopen(res_path, "w");
-
- if (f == NULL) {
- err = errno;
- GP_DEBUG(1, "Failed to open file '%s': %s",
- res_path, strerror(errno));
- goto err0;
- }
-
- if (fprintf(f, "P2n%u %un%un# Generated by gfxprimn",
- (unsigned int) src->w, (unsigned int) src->h, gray) < 3)
- goto err1;
-
- //TODO: errno
- switch (gray) {
- case 1:
- if (GP_PXMSave1bpp(f, src))
- goto err1;
- break;
- case 3:
- if (GP_PXMSave2bpp(f, src))
- goto err1;
- break;
- //TODO
- case 255:
- if (GP_PXMSave8bpp(f, src))
- goto err1;
- break;
- default:
- err = ENOSYS;
- goto err1;
- }
-
- if (fclose(f)) {
- err = errno;
- GP_DEBUG(1, "Failed to close file '%s': %s",
- res_path, strerror(errno));
- goto err0;
- }
-
- return 0;
-err1:
- fclose(f);
-err0:
- errno = err;
- return 1;
-}
diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c
index 6e7946e..1104f8f 100644
--- a/libs/loaders/GP_PNM.c
+++ b/libs/loaders/GP_PNM.c
@@ -16,35 +16,24 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-#include <stdint.h>
-#include <inttypes.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <string.h>
-
-#include <GP_Debug.h>
-
-#include "GP_PNM.h"
-
/*
PNM portable bitmap header
--------------------------
-
+
Format:
- a magick number value of 'P' and one of
- '1' - PBM 2bpp gray ASCII
- '2' - PGM gray ASCII
- '3' - PPM rgb888 ASCII
- '4' - PBM 2bpp gray BINARY
- '5' - PGM gray BINARY
- '6' - PPM rgb888 BINARY
+ a magic number value of 'P' and one of
+ '1' - PBM Bitmap ASCII
+ '2' - PGM Gray ASCII
+ '3' - PPM RGB ASCII
+ '4' - PBM Bitmap Binary
+ '5' - PGM Gray Binary
+ '6' - PPM RGB Binary
whitespace (blanks, TABs, CRs, LFs).
ascii width
whitespace
@@ -57,135 +46,839 @@
*/
-static void try_read_comments(FILE *f)
-{
- char c1, c2;
+#include <stdio.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <ctype.h>
- while (isspace(c1 = fgetc(f)));
-
- ungetc(c1, f);
+#include <string.h>
- while ((c1 = fgetc(f)) == '#') {
- do {
- c2 = fgetc(f);
- } while (c2 != 'n' && c2 != EOF);
- }
+#include "core/GP_Debug.h"
+#include "core/GP_Context.h"
+#include "core/GP_GetPutPixel.h"
- ungetc(c1, f);
-}
+#include "loaders/GP_PNM.h"
+struct pnm_header {
+ char magic;
+ uint32_t w;
+ uint32_t h;
+ uint32_t depth;
+};
static char *pnm_names[] = {
"ASCII encoded PBM",
"ASCII encoded PGM",
"ASCII encoded PPM",
- "BINARY encoded PBM",
- "BINARY encoded PGM",
- "BINARY encoded PPM",
+ "Binary encoded PBM",
+ "Binary encoded PGM",
+ "Binary encoded PPM",
};
-FILE *GP_ReadPNM(const char *src_path, char *fmt,
- uint32_t *w, uint32_t *h, uint32_t *depth)
+static const char *pnm_magic_name(char magic)
{
- FILE *f = fopen(src_path, "r");
- int ch, err;
+ return pnm_names[magic - '1'];
+}
- if (f == NULL) {
- GP_DEBUG(1, "Failed to open file '%s': %s",
- src_path, strerror(errno));
- return NULL;
+/*
+ * P1 == ascii
+ * P4 == rawbits
+ */
+static int is_bitmap(char magic)
+{
+ return magic == '1' || magic == '4';
+}
+
+int GP_MatchPBM(const void *buf)
+{
+ const char *b = buf;
+
+ return b[0] == 'P' && is_bitmap(b[1]);
+}
+
+/*
+ * P2 == ascii
+ * P5 == rawbits
+ */
+static int is_graymap(char magic)
+{
+ return magic == '2' || magic == '5';
+}
+
+int GP_MatchPGM(const void *buf)
+{
+ const char *b = buf;
+
+ return b[0] == 'P' && is_graymap(b[1]);
+}
+
+/*
+ * P3 == ascii
+ * P6 == rawbits
+ */
+static int is_pixmap(char magic)
+{
+ return magic == '3' || magic == '6';
+}
+
+int GP_MatchPPM(const void *buf)
+{
+ const char *b = buf;
+
+ return b[0] == 'P' && is_pixmap(b[1]);
+}
+
+static int magic_is_valid(char magic)
+{
+ switch (magic) {
+ case '1' ... '9':
+ return 1;
+ default:
+ return 0;
}
+}
- ch = fgetc(f);
+int GP_MatchPNM(const void *buf)
+{
+ const char *b = buf;
- if (ch == EOF) {
- err = EIO;
- goto err1;
+ return b[0] == 'P' && magic_is_valid(b[1]);
+}
+
+/*
+ * Header parser
+ */
+enum state {
+ S_START,
+ S_COMMENT,
+ S_INT,
+};
+
+static int load_header(FILE *f, struct pnm_header *header)
+{
+ int h1, h2, c, state = S_START, val = 0, i = 0, err;
+
+ h1 = fgetc(f);
+ h2 = fgetc(f);
+
+ if (h1 == EOF || h2 == EOF) {
+ GP_DEBUG(1, "Failed to read header");
+ return EIO;
}
- if (ch != 'P') {
- GP_DEBUG(1, "Invalid PNM header start '%c' (0x%2x) expecting 'P'",
- isprint(ch) ? ch : ' ', ch);
- err = EINVAL;
- goto err1;
+ if (h1 != 'P' || !magic_is_valid(h2)) {
+ GP_DEBUG(1, "Invalid magic 0x%02x 0x%02x (%c %c)",
+ h1, h2, isprint(h1) ? h1 : ' ', isprint(h2) ? h2 : ' ');
+ return EINVAL;
}
- ch = fgetc(f);
+ header->magic = h2;
+ header->depth = 1;
+ header->h = 0;
+ header->w = 0;
- switch (ch) {
- case '4':
- case '1':
- *depth = 1;
- break;
- case '2':
- case '3':
- case '5':
- case '6':
- break;
- default:
- GP_DEBUG(1, "Invalid PNM format 'P%c' (0x%2x)",
- isprint(ch) ? ch : ' ', ch);
- err = EINVAL;
- goto err1;
+ for (;;) {
+ c = fgetc(f);
+
+ if (c == EOF) {
+ err = EIO;
+ goto err;
+ }
+
+ switch (state) {
+ case S_START:
+ switch (c) {
+ case '#':
+ state = S_COMMENT;
+ break;
+ case '0' ... '9':
+ val = c - '0';
+ state = S_INT;
+ break;
+ case 'n':
+ case 't':
+ case ' ':
+ case 'r':
+ break;
+ default:
+ GP_WARN("Ignoring character 0x%02x (%c)",
+ c, isprint(c) ? c : ' ');
+ }
+ break;
+ case S_COMMENT:
+ if (c == 'n')
+ state = S_START;
+ break;
+ case S_INT:
+ switch (c) {
+ case '0' ... '9':
+ val *= 10;
+ val += c - '0';
+ break;
+ default:
+ switch (i++) {
+ case 0:
+ header->w = val;
+ break;
+ case 1:
+ header->h = val;
+ if (is_bitmap(header->magic))
+ goto out;
+ break;
+ case 2:
+ header->depth = val;
+ goto out;
+ }
+ ungetc(c, f);
+ state = S_START;
+ break;
+ }
+ break;
+ }
+ }
+
+out:
+ GP_DEBUG(1, "Have header P%c (%s) %"PRIu32"x%"PRIu32" depth=%"PRIu32,
+ header->magic, pnm_magic_name(header->magic),
+ header->w, header->h, header->depth);
+ return 0;
+err:
+ GP_DEBUG(1, "Unexpected end of file when reading header");
+ return err;
+}
+
+/*
+ * ASCII data parser
+ */
+static int get_ascii_int(FILE *f, int *val)
+{
+ int c, in_number = 0;
+ *val = 0;
+
+ for (;;) {
+ c = fgetc(f);
+
+ switch (c) {
+ case EOF:
+ if (!in_number) {
+ GP_DEBUG(1, "Unexpected end of file");
+ return EIO;
+ }
+
+ return 0;
+ case '0' ... '9':
+ *val *= 10;
+ *val += c - '0';
+ in_number = 1;
+ break;
+ case 'n':
+ case 't':
+ case ' ':
+ case 'r':
+ if (in_number)
+ return 0;
+ break;
+ default:
+ if (in_number)
+ return 0;
+ else
+ GP_WARN("Ignoring unexpected character 0x%02x %c",
+ c, isprint(c) ? c : ' ');
+ }
+ }
+}
+
+static int load_ascii_g1(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb)
+{
+ uint32_t x, y;
+ int val, err;
+
+ for (y = 0; y < ctx->h; y++) {
+ for (x = 0; x < ctx->w; x++) {
+
+ if ((err = get_ascii_int(f, &val)))
+ return err;
+
+ GP_PutPixel_Raw_1BPP_LE(ctx, x, y, !val);
+ }
+
+ if (GP_ProgressCallbackReport(cb, y, ctx->h, ctx->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ return ECANCELED;
+ }
+ }
+
+ GP_ProgressCallbackDone(cb);
+ return 0;
+}
+
+static int load_ascii_g2(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb)
+{
+ uint32_t x, y;
+ int val, err;
+
+ for (y = 0; y < ctx->h; y++) {
+ for (x = 0; x < ctx->w; x++) {
+
+ if ((err = get_ascii_int(f, &val)))
+ return err;
+
+ if (val > 3) {
+ GP_WARN("Value too large for 2BPP (%i)", val);
+ val = 3;
+ }
+
+ GP_PutPixel_Raw_2BPP_LE(ctx, x, y, val);
+ }
+
+ if (GP_ProgressCallbackReport(cb, y, ctx->h, ctx->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ return ECANCELED;
+ }
+ }
+
+ GP_ProgressCallbackDone(cb);
+ return 0;
+}
+
+static int load_ascii_g4(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb)
+{
+ uint32_t x, y;
+ int val, err;
+
+ for (y = 0; y < ctx->h; y++) {
+ for (x = 0; x < ctx->w; x++) {
+
+ if ((err = get_ascii_int(f, &val)))
+ return err;
+
+ if (val > 15) {
+ GP_WARN("Value too large for 4BPP (%i)", val);
+ val = 3;
+ }
+
+ GP_PutPixel_Raw_4BPP_LE(ctx, x, y, val);
+ }
+
+ if (GP_ProgressCallbackReport(cb, y, ctx->h, ctx->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ return ECANCELED;
+ }
}
-
- *fmt = ch;
- try_read_comments(f);
+ GP_ProgressCallbackDone(cb);
+ return 0;
+}
+
+static int load_ascii_g8(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb)
+{
+ uint32_t x, y;
+ int val, err;
+
+ for (y = 0; y < ctx->h; y++) {
+ for (x = 0; x < ctx->w; x++) {
+
+ if ((err = get_ascii_int(f, &val)))
+ return err;
+
+ if (val > 15) {
+ GP_WARN("Value too large for 4BPP (%i)", val);
+ val = 3;
+ }
+
+ GP_PutPixel_Raw_8BPP(ctx, x, y, val);
+ }
+
+ if (GP_ProgressCallbackReport(cb, y, ctx->h, ctx->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ return ECANCELED;
+ }
+ }
+
+ GP_ProgressCallbackDone(cb);
+ return 0;
+}
+
+static int load_ascii_rgb888(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb)
+{
+ uint32_t x, y;
+ int r, g, b, err;
+
+ for (y = 0; y < ctx->h; y++) {
+ for (x = 0; x < ctx->w; x++) {
+
+ if ((err = get_ascii_int(f, &r)))
+ return err;
+
+ if (r > 255) {
+ GP_WARN("R value too large (%i)", r);
+ r = 255;
+ }
+
+ if ((err = get_ascii_int(f, &g)))
+ return err;
+
+ if (g > 255) {
+ GP_WARN("G value too large (%i)", r);
+ g = 255;
+ }
+
+ if ((err = get_ascii_int(f, &b)))
+ return err;
+
+ if (b > 255) {
+ GP_WARN("G value too large (%i)", r);
+ b = 255;
+ }
+
+ GP_PutPixel_Raw_24BPP(ctx, x, y,
+ GP_Pixel_CREATE_RGB888(r, g, b));
+ }
+
+ if (GP_ProgressCallbackReport(cb, y, ctx->h, ctx->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ return ECANCELED;
+ }
+ }
+
+ GP_ProgressCallbackDone(cb);
+ return 0;
+}
+
+static int load_bin_rgb888(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb)
+{
+ uint32_t x, y;
+ int r, g, b, err;
+
+ for (y = 0; y < ctx->h; y++) {
+ for (x = 0; x < ctx->w; x++) {
+ r = fgetc(f);
+ g = fgetc(f);
+ b = fgetc(f);
+
+ if (r == EOF || g == EOF || b == EOF) {
+ err = errno;
+ GP_DEBUG(1, "Unexpected end of PBM file");
+ return err;
+ }
+
+ GP_PutPixel_Raw_24BPP(ctx, x, y,
+ GP_Pixel_CREATE_RGB888(r, g, b));
+ }
+ if (GP_ProgressCallbackReport(cb, y, ctx->h, ctx->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ return ECANCELED;
+ }
+ }
+
+ GP_ProgressCallbackDone(cb);
+ return 0;
+}
+
+static int save_ascii(FILE *f, const GP_Context *ctx, GP_ProgressCallback *cb)
+{
+ uint32_t x, y;
+ int err;
+
+ for (y = 0; y < ctx->h; y++) {
+ for (x = 0; x < ctx->w; x++) {
+
+ if (fprintf(f, "%i ", GP_GetPixel_Raw(ctx, x, y)) != 1) {
+ err = errno;
+ GP_DEBUG(1, "Failed to write data");
+ return err;
+ }
+
+ }
+ if (GP_ProgressCallbackReport(cb, y, ctx->h, ctx->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ return ECANCELED;
+ }
+ fprintf(f, "n");
+ }
- if (fscanf(f, "%"PRIu32"n", w) < 1) {
- GP_DEBUG(1, "Failed to read PNM header width");
+ GP_ProgressCallbackDone(cb);
+ return 0;
+}
+
+static FILE *read_header(const char *src_path, struct pnm_header *header)
+{
+ FILE *f;
+ int err;
+
+ f = fopen(src_path, "r");
+
+ if (f == NULL)
+ return NULL;
+
+ if ((err = load_header(f, header))) {
+ fclose(f);
+ return NULL;
+ }
+
+ return f;
+}
+
+static GP_Context *read_bitmap(FILE *f, struct pnm_header *header, int flag,
+ GP_ProgressCallback *callback)
+{
+ GP_Context *ret;
+ int err;
+
+ if (!is_bitmap(header->magic)) {
+ GP_DEBUG(1, "Invalid Bitmap magic P%c", header->magic);
err = EINVAL;
+ goto err0;
+ }
+
+ ret = GP_ContextAlloc(header->w, header->h, GP_PIXEL_G1);
+
+ if (ret == NULL) {
+ err = ENOMEM;
goto err1;
}
+
+ if ((err = load_ascii_g1(f, ret, callback)))
+ goto err1;
+
+ if (flag)
+ fclose(f);
+
+ return ret;
+err1:
+ GP_ContextFree(ret);
+
+ if (flag)
+ fclose(f);
+err0:
+ errno = err;
+ return NULL;
+}
+
+GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback)
+{
+ struct pnm_header header;
+ FILE *f;
+
+ f = read_header(src_path, &header);
+
+ if (f == NULL)
+ return NULL;
+
+ return read_bitmap(f, &header, 1, callback);
+}
+
+int GP_SavePBM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ FILE *f;
+
+ if (src->pixel_type != GP_PIXEL_G1) {
+ errno = EINVAL;
+ return 1;
+ }
- try_read_comments(f);
+ f = fopen(dst_path, "w");
+
+ if (f == NULL)
+ return 1;
+
+ if (fprintf(f, "P1n%u %u",
+ (unsigned int) src->w, (unsigned int) src->h) < 2)
+ goto err;
+
+ if (save_ascii(f, src, callback))
+ goto err;
+
+ if (fclose(f))
+ return 1;
+
+ return 0;
+err:
+ fclose(f);
+ errno = EIO;
+ return 1;
+}
+
+static GP_Pixel depth_to_pixel(int depth)
+{
+ switch (depth) {
+ case 1:
+ return GP_PIXEL_G1;
+ case 3:
+ return GP_PIXEL_G2;
+ case 15:
+ return GP_PIXEL_G4;
+ case 255:
+ return GP_PIXEL_G8;
+ default:
+ return GP_PIXEL_UNKNOWN;
+ }
+}
+
+static GP_Context *read_graymap(FILE *f, struct pnm_header *header, int flag,
+ GP_ProgressCallback *callback)
+{
+ GP_Context *ret;
+ GP_PixelType pixel_type;
+ int err;
- if (fscanf(f, "%"PRIu32"n", h) < 1) {
- GP_DEBUG(1, "Failed to read PNM header height");
+ if (!is_graymap(header->magic)) {
+ GP_DEBUG(1, "Invalid graymap magic P%c", header->magic);
err = EINVAL;
+ goto err0;
+ }
+
+ if ((pixel_type = depth_to_pixel(header->depth)) == GP_PIXEL_UNKNOWN) {
+ GP_DEBUG(1, "Invalid number of grays %u", header->depth);
+ err = EINVAL;
+ goto err0;
+ }
+
+ ret = GP_ContextAlloc(header->w, header->h, pixel_type);
+
+ if (ret == NULL) {
+ err = ENOMEM;
goto err1;
}
- GP_DEBUG(2, "Have %s size %"PRIu32"x%"PRIu32,
- pnm_names[*fmt - '1'], *w, *h);
+ switch (header->depth) {
+ case 1:
+ if ((err = load_ascii_g1(f, ret, callback)))
+ goto err1;
+ break;
+ case 3:
+ if ((err = load_ascii_g2(f, ret, callback)))
+ goto err1;
+ break;
+ case 15:
+ if ((err = load_ascii_g4(f, ret, callback)))
+ goto err1;
+ break;
+ case 255:
+ if ((err = load_ascii_g8(f, ret, callback)))
+ goto err1;
+ break;
+ }
+
+ if (flag)
+ fclose(f);
- if (*fmt == '1' || *fmt == '3')
- return f;
+ return ret;
+err1:
+ GP_ContextFree(ret);
- try_read_comments(f);
+ if (flag)
+ fclose(f);
+err0:
+ errno = err;
+ return NULL;
+}
+
+GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback)
+{
+ struct pnm_header header;
+ FILE *f;
+
+ f = read_header(src_path, &header);
+
+ if (f == NULL)
+ return NULL;
+
+ return read_graymap(f, &header, 1, callback);
+}
+
+static int pixel_to_depth(GP_Pixel pixel)
+{
+ switch (pixel) {
+ case GP_PIXEL_G1:
+ return 1;
+ case GP_PIXEL_G2:
+ return 3;
+ case GP_PIXEL_G4:
+ return 15;
+ case GP_PIXEL_G8:
+ return 255;
+ default:
+ return -1;
+ }
+}
+
+int GP_SavePGM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ FILE *f;
+ int depth;
+ int err = EIO;
+
+ if ((depth = pixel_to_depth(src->pixel_type)) == -1) {
+ GP_DEBUG(1, "Invalid pixel type '%s'",
+ GP_PixelTypeName(src->pixel_type));
+ errno = EINVAL;
+ return 1;
+ }
- if (fscanf(f, "%"PRIu32"n", depth) < 1) {
- GP_DEBUG(1, "Failed to read PNM header depth");
- err = EINVAL;
+ f = fopen(dst_path, "w");
+
+ if (f == NULL) {
+ err = errno;
+ GP_DEBUG(1, "Failed to open file '%s': %s",
+ dst_path, strerror(errno));
+ goto err0;
+ }
+
+ if (fprintf(f, "P2n%u %un%un# Generated by gfxprimn",
+ (unsigned int) src->w, (unsigned int) src->h, depth) < 3)
goto err1;
+
+ if ((err = save_ascii(f, src, callback)))
+ goto err1;
+
+ if (fclose(f)) {
+ err = errno;
+ GP_DEBUG(1, "Failed to close file '%s': %s",
+ dst_path, strerror(errno));
+ goto err0;
}
- return f;
+ return 0;
err1:
fclose(f);
+err0:
errno = err;
- return NULL;
+ return 1;
}
-#define GFXPRIM_SIGNATURE "# Generated by gfxprim http://gfxprim.ucw.czn"
-
-FILE *GP_WritePNM(const char *dst_path, char fmt,
- uint32_t w, uint32_t h, uint32_t depth)
+static GP_Context *read_pixmap(FILE *f, struct pnm_header *header, int flag,
+ GP_ProgressCallback *callback)
{
- FILE *f = fopen(dst_path, "w");
- int ret;
+ GP_Context *ret;
+ int err;
+
+ if (!is_pixmap(header->magic)) {
+ GP_DEBUG(1, "Invalid Pixmap magic P%c", header->magic);
+ err = EINVAL;
+ goto err0;
+ }
+
+ if (header->depth != 255) {
+ GP_DEBUG(1, "Unsupported depth %"PRIu32, header->depth);
+ err = ENOSYS;
+ goto err0;
+ }
- ret = fprintf(f, "P%cn"GFXPRIM_SIGNATURE
- "%"PRIu32" %"PRIu32"n%"PRIu32"n",
- fmt, w, h, depth);
+ ret = GP_ContextAlloc(header->w, header->h, GP_PIXEL_RGB888);
+
+ if (ret == NULL) {
+ err = ENOMEM;
+ goto err0;
+ }
- if (ret < 0) {
- GP_DEBUG(1, "Failed to write PNM header '%s' : %s",
- dst_path, strerror(errno));
+ switch (header->magic) {
+ case '3':
+ if ((err = load_ascii_rgb888(f, ret, callback)))
+ goto err1;
+ break;
+ case '6':
+ if ((err = load_bin_rgb888(f, ret, callback)))
+ goto err1;
+ break;
+ }
+
+ if (flag)
fclose(f);
+
+ return ret;
+err1:
+ GP_ContextFree(ret);
+
+ if (flag)
+ fclose(f);
+err0:
+ errno = err;
+ return NULL;
+}
+
+GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback)
+{
+ struct pnm_header header;
+ FILE *f;
+
+ f = read_header(src_path, &header);
+
+ if (f == NULL)
return NULL;
+
+ return read_pixmap(f, &header, 1, callback);
+}
+
+static int write_binary_ppm(FILE *f, GP_Context *src)
+{
+ uint32_t x, y;
+
+ for (y = 0; y < src->h; y++)
+ for (x = 0; x < src->w; x++) {
+ GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, x, y);
+
+ uint8_t buf[3] = {GP_Pixel_GET_R_RGB888(pix),
+ GP_Pixel_GET_G_RGB888(pix),
+ GP_Pixel_GET_B_RGB888(pix)};
+
+ if (fwrite(buf, 3, 1, f) < 1)
+ return 1;
+ }
+
+ return 0;
+}
+
+int GP_SavePPM(GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback)
+{
+
+ FILE *f;
+ GP_Context *ret = NULL;
+ struct pnm_header header;
+ int err;
+
+ f = fopen(src_path, "r");
+
+ if (f == NULL) {
+ err = errno;
+ GP_DEBUG(1, "Failed to open file '%s': %s",
+ src_path, strerror(errno));
+ goto err0;
}
- return f;
+ if ((err = load_header(f, &header)))
+ goto err1;
+
+ if (is_bitmap(header.magic))
+ ret = read_bitmap(f, &header, 1, callback);
+
+ if (is_graymap(header.magic))
+ ret = read_graymap(f, &header, 1, callback);
+
+ if (is_pixmap(header.magic))
+ ret = read_pixmap(f, &header, 1, callback);
+
+ return ret;
+err1:
+ fclose(f);
+err0:
+ errno = err;
+ return NULL;
+}
+
+int GP_SavePNM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ errno = ENOSYS;
+ return -1;
}
diff --git a/libs/loaders/GP_PNM.h b/libs/loaders/GP_PNM.h
deleted file mode 100644
index 2ce48a3..0000000
--- a/libs/loaders/GP_PNM.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-/*
-
- Common PNM functions.
-
- */
-
-#ifndef GP_PNM_H
-#define GP_PNM_H
-
-#include <stdint.h>
-
-/*
- * Loads image header, returns pointer to FILE* (with file position pointing
- * to the start of the data stream) on success, fills image metadata into
- * arguments.
- */
-FILE *GP_ReadPNM(const char *src_path, char *fmt,
- uint32_t *w, uint32_t *h, uint32_t *depth);
-
-/*
- * Writes image header.
- */
-FILE *GP_WritePNM(const char *dst_path, char fmt,
- uint32_t w, uint32_t h, uint32_t depth);
-
-
-#endif /* GP_PNM_H */
diff --git a/libs/loaders/GP_PPM.c b/libs/loaders/GP_PPM.c
deleted file mode 100644
index b739b43..0000000
--- a/libs/loaders/GP_PPM.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-/*
-
- PPM portable bitmap loader/saver.
-
- */
-
-#include <stdint.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <string.h>
-
-#include <GP_Debug.h>
-#include <GP_Context.h>
-#include <GP_Pixel.h>
-#include <GP_GetPutPixel.h>
-
-#include "GP_PNM.h"
-#include "GP_PPM.h"
-
-static int load_binary_ppm(FILE *f, uint32_t depth __attribute__((unused)),
- GP_Context *res)
-{
- uint32_t x, y;
- int r, g, b;
-
- for (y = 0; y < res->h; y++)
- for (x = 0; x < res->w; x++) {
- r = fgetc(f);
- g = fgetc(f);
- b = fgetc(f);
-
- if (r == EOF || g == EOF || b == EOF) {
- GP_DEBUG(1, "Unexpected end of PBM file");
- return 1;
- }
-
- //TODO depth
- GP_Pixel pix = GP_Pixel_CREATE_RGB888(r, g, b);
- GP_PutPixel_Raw_24BPP(res, x, y, pix);
- }
-
- return 0;
-}
-
-GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback)
-{
- uint32_t w, h, depth;
- char fmt;
- FILE *f;
- GP_Context *ret;
- int err;
-
- f = GP_ReadPNM(src_path, &fmt, &w, &h, &depth);
-
- if (f == NULL) {
- err = errno;
- goto err0;
- }
-
- if (fmt != '3' && fmt != '6') {
- GP_DEBUG(1, "Asked to load PPM but header is 'P%c'", fmt);
- err = EINVAL;
- goto err1;
- }
-
- if (depth != 255) {
- GP_DEBUG(1, "Unsupported depth %"PRIu32, depth);
- err = ENOSYS;
- goto err1;
- }
-
- ret = GP_ContextAlloc(w, h, GP_PIXEL_RGB888);
-
- if (ret == NULL) {
- err = ENOMEM;
- goto err1;
- }
-
- switch (fmt) {
- case '3':
- //TODO
- err = ENOSYS;
- goto err2;
- case '6':
- //TODO: errno
- if (load_binary_ppm(f, depth, ret))
- goto err2;
- break;
- }
-
- fclose(f);
- return ret;
-err2:
- GP_ContextFree(ret);
-err1:
- fclose(f);
-err0:
- errno = err;
- return NULL;
-}
-
-static int write_binary_ppm(FILE *f, GP_Context *src)
-{
- uint32_t x, y;
-
- for (y = 0; y < src->h; y++)
- for (x = 0; x < src->w; x++) {
- GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, x, y);
-
- uint8_t buf[3] = {GP_Pixel_GET_R_RGB888(pix),
- GP_Pixel_GET_G_RGB888(pix),
- GP_Pixel_GET_B_RGB888(pix)};
-
- if (fwrite(buf, 3, 1, f) < 1)
- return 1;
- }
-
- return 0;
-}
-
-int GP_SavePPM(const char *res_path, GP_Context *src, char *fmt,
- GP_ProgressCallback *callback)
-{
- char hfmt;
- FILE *f;
- int err;
-
- if (src->pixel_type != GP_PIXEL_RGB888) {
- errno = EINVAL;
- return 1;
- }
-
- switch (*fmt) {
- /* ASCII */
- case 'a':
- errno = ENOSYS;
- return 1;
- break;
- /* binary */
- case 'b':
- hfmt = '6';
- GP_DEBUG(1, "Writing binary PPM %ux%u '%s'",
- src->w, src->h, res_path);
- break;
- default:
- errno = EINVAL;
- return 1;
- }
-
- f = GP_WritePNM(res_path, hfmt, src->w, src->h, 255);
-
- if (f == NULL)
- return 1;
-
- if (write_binary_ppm(f, src)) {
- GP_DEBUG(1, "Failed to write buffer");
- err = EIO;
- goto err1;
- }
-
- if (fclose(f) < 0) {
- err = errno;
- GP_DEBUG(1, "Failed to close file '%s' : %s",
- res_path, strerror(errno));
- goto err0;
- }
-
- return 0;
-err1:
- fclose(f);
-err0:
- errno = err;
- return 1;
-}
diff --git a/libs/loaders/GP_PXMCommon.c b/libs/loaders/GP_PXMCommon.c
deleted file mode 100644
index e2738ab..0000000
--- a/libs/loaders/GP_PXMCommon.c
+++ /dev/null
@@ -1,388 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include <stdint.h>
-#include <inttypes.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <string.h>
-
-#include <GP_Debug.h>
-
-#include "GP_PXMCommon.h"
-
-static int read_comment(FILE *f)
-{
- for (;;) {
- switch (fgetc(f)) {
- case 'n':
- return 0;
- case EOF:
- return 1;
- }
- }
-}
-
-int GP_PXMLoad1bpp(FILE *f, GP_Context *context)
-{
- uint8_t *pixel = context->pixels;
- uint32_t x, y;
-
- for (y = 0; y < context->h; y++) {
- for (x = 0; x < context->w;) {
- int run = 1;
-
- while (run) {
- switch (fgetc(f)) {
- case EOF:
- return EIO;
- case '#':
- if (read_comment(f))
- return EIO;
- break;
- case '0':
- *pixel &= ~(0x80>>(x%8));
- run = 0;
- break;
- case '1':
- *pixel |= 0x80>>(x%8);
- run = 0;
- break;
- default:
- break;
- }
- }
-
- x++;
-
- if (x%8 == 0)
- pixel++;
- }
-
- if (context->w%8)
- pixel++;
- }
-
- return 0;
-}
-
-int GP_PXMLoad2bpp(FILE *f, GP_Context *context)
-{
- uint8_t *pixel = context->pixels;
- uint32_t x, y;
-
- for (y = 0; y < context->h; y++) {
- for (x = 0; x < context->w;) {
- int run = 1;
-
- while (run) {
- switch (fgetc(f)) {
- case EOF:
- return EIO;
- case '#':
- if (read_comment(f))
- return EIO;
- break;
- case '0':
- *pixel &= ~(0xc0>>(2*(x%4)));
- run = 0;
- break;
- case '1':
- *pixel &= ~(0x80>>(2*(x%4)));
- *pixel |= 0x40>>(2*(x%4));
- run = 0;
- break;
- case '2':
- *pixel |= 0x80>>(2*(x%4));
- *pixel &= ~(0x40>>(2*(x%4)));
- run = 0;
- break;
- case '3':
- *pixel |= 0xc0>>(2*(x%4));
- run = 0;
- break;
- default:
- break;
- }
- }
-
- x++;
-
- if (x%4 == 0)
- pixel++;
- }
-
- if (context->w%4)
- pixel++;
- }
-
- return 0;
-}
-
-int GP_PXMLoad4bpp(FILE *f, GP_Context *context)
-{
- uint8_t *pixel = context->pixels;
- uint32_t x, y;
-
- for (y = 0; y < context->h; y++) {
- for (x = 0; x < context->w;) {
- int run = 1;
- int val = 0;
- char ch;
-
- while (run) {
- switch (fgetc(f)) {
- case EOF:
- return EIO;
- case '#':
- if (read_comment(f))
- return EIO;
- break;
- case '1':
- ch = fgetc(f);
- val = 1;
- if (ch >= 0 && ch <= 5)
- val = 10 + ch - '0';
- case '0':
- run = 0;
-
- *pixel = (*pixel & 0xf0>>4*(x%2)) |
- val<<(4*(!x%2));
- break;
- }
- }
-
- x++;
-
- if (x%2 == 0)
- pixel++;
- }
-
- if (context->w%2)
- pixel++;
- }
-
- return 0;
-}
-
-int GP_PXMLoad8bpp(FILE *f, GP_Context *context)
-{
- uint8_t *pixel = context->pixels;
- uint32_t x, y;
-
- for (y = 0; y < context->h; y++) {
- for (x = 0; x < context->w; x++) {
- int run = 1;
- int val = 0;
- char ch;
-
- while (run) {
- switch (ch = fgetc(f)) {
- case EOF:
- return EIO;
- case '#':
- if (read_comment(f))
- return EIO;
- break;
- case '1' ... '9':
- val = ch - '0';
- ch = fgetc(f);
- if (ch >= '0' && ch <= '9') {
- val = val * 10 + ch - '0';
- ch = fgetc(f);
- if (ch >= '0' && ch <= '9')
- val = val * 10 + ch - '0';
- }
-
- if (val > 255)
- return EIO;
- case '0':
- run = 0;
-
- *pixel = val;
- break;
- default:
- break;
- }
- }
-
- pixel++;
- }
- }
-
- return 0;
-}
-
-#define BITMASK(byte, bit) (!!((byte)&(0x80>>(bit))))
-
-static int write_line_1bpp(FILE *f, const uint8_t *data, const GP_Context *src)
-{
- uint32_t x, max = src->bytes_per_row;
- int ret;
-
- if (src->w % 8)
- max--;
-
- for (x = 0; x < max; x++) {
-
- if (x != 0)
- if (fprintf(f, " ") < 0)
- return EIO;
-
- ret = fprintf(f, "%u %u %u %u %u %u %u %u",
- BITMASK(data[x], 0),
- BITMASK(data[x], 1),
- BITMASK(data[x], 2),
- BITMASK(data[x], 3),
- BITMASK(data[x], 4),
- BITMASK(data[x], 5),
- BITMASK(data[x], 6),
- BITMASK(data[x], 7));
- if (ret < 0)
- return EIO;
- }
-
- for (x = 0; x < (src->w % 8); x++) {
- ret = fprintf(f, " %u", BITMASK(data[max], x));
-
- if (ret < 0)
- return EIO;
- }
-
- if (fprintf(f, "n") < 0)
- return EIO;
-
- return 0;
-}
-
-int GP_PXMSave1bpp(FILE *f, const GP_Context *context)
-{
- uint32_t y;
- int ret;
-
- for (y = 0; y < context->h; y++) {
- ret = write_line_1bpp(f, context->pixels + context->bytes_per_row * y,
- context);
-
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-#define MASK_2BPP(byte, pix) (0x03 & (byte>>((3 - pix)<<1)))
-
-static int write_line_2bpp(FILE *f, const uint8_t *data, const GP_Context *src)
-{
- uint32_t x, max = src->bytes_per_row;
- int ret;
-
- if (src->w % 4)
- max--;
-
- for (x = 0; x < max; x++) {
-
- if (x != 0)
- if (fprintf(f, " ") < 0)
- return EIO;
-
- ret = fprintf(f, "%u %u %u %u",
- MASK_2BPP(data[x], 0),
- MASK_2BPP(data[x], 1),
- MASK_2BPP(data[x], 2),
- MASK_2BPP(data[x], 3));
- if (ret < 0)
- return EIO;
- }
-
- for (x = 0; x < (src->w % 4); x++) {
- ret = fprintf(f, " %u", MASK_2BPP(data[max], x));
-
- if (ret < 0)
- return EIO;
- }
-
- if (fprintf(f, "n") < 0)
- return EIO;
-
- return EIO;
-}
-
-int GP_PXMSave2bpp(FILE *f, const GP_Context *context)
-{
- uint32_t y;
- int ret;
-
- for (y = 0; y < context->h; y++) {
- ret = write_line_2bpp(f, context->pixels + context->bytes_per_row * y,
- context);
-
- if (ret)
- return ret;
- }
-
- return EIO;
-}
-
-static int write_line_8bpp(FILE *f, const uint8_t *data, const GP_Context *src)
-{
- uint32_t x;
- int ret;
-
- for (x = 0; x < src->w; x++) {
-
- if (x != 0)
- if (fprintf(f, " ") < 0)
- return EIO;
-
- ret = fprintf(f, "%u", data[x]);
-
- if (ret < 0)
- return EIO;
- }
-
- if (fprintf(f, "n") < 0)
- return EIO;
-
- return 0;
-}
-
-int GP_PXMSave8bpp(FILE *f, const GP_Context *context)
-{
- uint32_t y;
- int ret;
-
- for (y = 0; y < context->h; y++) {
- ret = write_line_8bpp(f, context->pixels + context->bytes_per_row * y,
- context);
-
- if (ret)
- return ret;
- }
-
- return 0;
-}
diff --git a/libs/loaders/GP_PXMCommon.h b/libs/loaders/GP_PXMCommon.h
deleted file mode 100644
index 1780eec..0000000
--- a/libs/loaders/GP_PXMCommon.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-/*
-
- Common bytes to ascci and ascii to bytes functions.
-
- */
-
-#ifndef LOADERS_GP_PXM_COMMON_H
-#define LOADERS_GP_PXM_COMMON_H
-
-#include <stdio.h>
-#include "core/GP_Core.h"
-
-/*
- * Save context to ascii file.
- *
- * The pixel type is not checked here as these are internal funcitons.
- */
-int GP_PXMSave1bpp(FILE *f, const GP_Context *context);
-int GP_PXMSave2bpp(FILE *f, const GP_Context *context);
-int GP_PXMSave4bpp(FILE *f, const GP_Context *context);
-int GP_PXMSave8bpp(FILE *f, const GP_Context *context);
-
-/*
- * Load context from ascii file.
- */
-int GP_PXMLoad1bpp(FILE *f, GP_Context *context);
-int GP_PXMLoad2bpp(FILE *f, GP_Context *context);
-int GP_PXMLoad4bpp(FILE *f, GP_Context *context);
-int GP_PXMLoad8bpp(FILE *f, GP_Context *context);
-
-/*
- * Loads image header, returns pointer to FILE* on success, fills image
- * metadata into arguments.
- */
-FILE *GP_ReadHeaderPNM(const char *src_path, char *fmt,
- uint32_t *w, uint32_t *h, uint32_t *depth);
-
-FILE *GP_WriteHeaderPNM(const char *dst_path, char *fmt,
- uint32_t w, uint32_t h, uint32_t depth);
-
-
-#endif /* LOADERS_GP_PXM_COMMON_H */
diff --git a/pylib/gfxprim/loaders/loaders.i b/pylib/gfxprim/loaders/loaders.i
index 33a2fbd..e651a1c 100644
--- a/pylib/gfxprim/loaders/loaders.i
+++ b/pylib/gfxprim/loaders/loaders.i
@@ -59,10 +59,10 @@ ERROR_ON_NONZERO(GP_SavePNG);
ERROR_ON_NULL(GP_LoadPBM);
ERROR_ON_NULL(GP_LoadPGM);
ERROR_ON_NULL(GP_LoadPPM);
+ERROR_ON_NULL(GP_LoadPNM);
ERROR_ON_NONZERO(GP_SavePBM);
ERROR_ON_NONZERO(GP_SavePGM);
ERROR_ON_NONZERO(GP_SavePPM);
+ERROR_ON_NONZERO(GP_SavePNM);
-%include "GP_PBM.h"
-%include "GP_PGM.h"
-%include "GP_PPM.h"
+%include "GP_PNM.h"
-----------------------------------------------------------------------
Summary of changes:
build/syms/Loaders_symbols.txt | 24 +-
demos/grinder/grinder.c | 2 +-
include/loaders/GP_Loaders.h | 5 +-
include/loaders/GP_PBM.h | 49 --
include/loaders/GP_PGM.h | 37 -
include/loaders/GP_PPM.h | 37 -
libs/loaders/GP_Loader.c | 27 +-
libs/loaders/GP_PBM.c | 127 ---
libs/loaders/GP_PGM.c | 262 ------
libs/loaders/GP_PNM.c | 893 +++++++++++++++++---
libs/loaders/GP_PNM.h | 49 --
libs/loaders/GP_PPM.c | 196 -----
libs/loaders/GP_PXMCommon.c | 388 ---------
libs/loaders/GP_PXMCommon.h | 67 --
pylib/gfxprim/loaders/loaders.i | 6 +-
tests/loaders/Makefile | 2 +-
tests/loaders/PBM.c | 196 +++++
.../emptyfile.bmp => pbm/corrupt/empty.pbm} | 0
tests/loaders/data/pbm/corrupt/short.pbm | 3 +
tests/loaders/data/pbm/valid/black_1x1_1.pbm | 3 +
tests/loaders/data/pbm/valid/black_1x1_2.pbm | 4 +
tests/loaders/data/pbm/valid/black_1x1_3.pbm | 8 +
tests/loaders/data/pbm/valid/black_1x1_4.pbm | 4 +
tests/loaders/data/pbm/valid/white_1x1.pbm | 3 +
tests/loaders/test_list.txt | 1 +
25 files changed, 1051 insertions(+), 1342 deletions(-)
delete mode 100644 include/loaders/GP_PBM.h
delete mode 100644 include/loaders/GP_PGM.h
delete mode 100644 include/loaders/GP_PPM.h
delete mode 100644 libs/loaders/GP_PBM.c
delete mode 100644 libs/loaders/GP_PGM.c
delete mode 100644 libs/loaders/GP_PNM.h
delete mode 100644 libs/loaders/GP_PPM.c
delete mode 100644 libs/loaders/GP_PXMCommon.c
delete mode 100644 libs/loaders/GP_PXMCommon.h
create mode 100644 tests/loaders/PBM.c
copy tests/loaders/data/{bmp/bitmaps/corrupt/emptyfile.bmp => pbm/corrupt/empty.pbm} (100%)
create mode 100644 tests/loaders/data/pbm/corrupt/short.pbm
create mode 100644 tests/loaders/data/pbm/valid/black_1x1_1.pbm
create mode 100644 tests/loaders/data/pbm/valid/black_1x1_2.pbm
create mode 100644 tests/loaders/data/pbm/valid/black_1x1_3.pbm
create mode 100644 tests/loaders/data/pbm/valid/black_1x1_4.pbm
create mode 100644 tests/loaders/data/pbm/valid/white_1x1.pbm
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
15 Jun '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 3354fbc9c92960230a3111ac5ae82064bc8c63a2 (commit)
via 1342b492e9166913d023318d038dd7ee1a7af664 (commit)
via 3ccc04bfd1972d26ef574696f69df38f0e3cac3d (commit)
from bb3d38ce1cc2b6877b7bc70344a91a01fcbfdbb5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/3354fbc9c92960230a3111ac5ae82064bc8c…
commit 3354fbc9c92960230a3111ac5ae82064bc8c63a2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jun 15 00:34:35 2013 +0200
demos: c_simple: blittest: Add check.
Add check if sprite was sucesfully loaded.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/demos/c_simple/blittest.c b/demos/c_simple/blittest.c
index 9130b57..1e84efd 100644
--- a/demos/c_simple/blittest.c
+++ b/demos/c_simple/blittest.c
@@ -154,6 +154,13 @@ int main(void)
print_instructions();
+ bitmap_raw = GP_LoadImage(sprite, NULL);
+
+ if (!bitmap_raw) {
+ fprintf(stderr, "Failed to load '%s'n", sprite);
+ return 1;
+ }
+
win = GP_BackendInit(backend_opts, "Blit Test", stderr);
if (win == NULL) {
@@ -162,8 +169,6 @@ int main(void)
return 1;
}
- bitmap_raw = GP_LoadImage(sprite, NULL);
-
bitmap_conv = GP_ContextConvertAlloc(bitmap_raw,
win->context->pixel_type);
change_bitmap();
http://repo.or.cz/w/gfxprim.git/commit/1342b492e9166913d023318d038dd7ee1a7a…
commit 1342b492e9166913d023318d038dd7ee1a7af664
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 14 23:52:17 2013 +0200
build: check_symbols: Add loaders.
Loaders are separate library now, add symbol checks for them too.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/check_symbols.sh b/build/check_symbols.sh
index a229912..a26b92c 100755
--- a/build/check_symbols.sh
+++ b/build/check_symbols.sh
@@ -53,8 +53,10 @@ function do_check
do_check libGP.so syms/Core_symbols.txt syms/Input_symbols.txt syms/Filters_symbols.txt syms/GFX_symbols.txt - syms/Loaders_symbols.txt syms/Text_symbols.txt
+ syms/Text_symbols.txt
do_check libGP_backends.so syms/Backend_symbols.txt
do_check libGP_grabbers.so syms/Grabbers_symbols.txt
+
+do_check libGP_loaders.so syms/Loaders_symbols.txt
http://repo.or.cz/w/gfxprim.git/commit/3ccc04bfd1972d26ef574696f69df38f0e3c…
commit 3ccc04bfd1972d26ef574696f69df38f0e3cac3d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 14 23:00:12 2013 +0200
demos: c_simple: blittest: Correct caption.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/demos/c_simple/blittest.c b/demos/c_simple/blittest.c
index 57a11fa..9130b57 100644
--- a/demos/c_simple/blittest.c
+++ b/demos/c_simple/blittest.c
@@ -154,7 +154,7 @@ int main(void)
print_instructions();
- win = GP_BackendInit(backend_opts, "Line Test", stderr);
+ win = GP_BackendInit(backend_opts, "Blit Test", stderr);
if (win == NULL) {
fprintf(stderr, "Failed to initalize backend '%s'n",
-----------------------------------------------------------------------
Summary of changes:
build/check_symbols.sh | 4 +++-
demos/c_simple/blittest.c | 11 ++++++++---
2 files changed, 11 insertions(+), 4 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
14 Jun '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via bb3d38ce1cc2b6877b7bc70344a91a01fcbfdbb5 (commit)
from 050cbfbf2c0d6aec3c941a20c6ea16d467a72751 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/bb3d38ce1cc2b6877b7bc70344a91a01fcbf…
commit bb3d38ce1cc2b6877b7bc70344a91a01fcbfdbb5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 14 19:37:50 2013 +0200
backends: Linux FB: Fix div by zero.
This backend wasn't converted to the new InputQueue().
(The GP_EventQueueInit() was not added)
Which caused div by zero in put_event() in InputQueue code.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c
index 54516d9..b203109 100644
--- a/libs/backends/GP_LinuxFB.c
+++ b/libs/backends/GP_LinuxFB.c
@@ -314,6 +314,8 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag)
backend->Wait = flag ? fb_wait : NULL;
backend->fd = fb->con_fd;
+ GP_EventQueueInit(&backend->event_queue, vscri.xres, vscri.yres, 0);
+
return backend;
err3:
close(fd);
-----------------------------------------------------------------------
Summary of changes:
libs/backends/GP_LinuxFB.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
13 Jun '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 050cbfbf2c0d6aec3c941a20c6ea16d467a72751 (commit)
via 75e84dc25b607438e0141db5710fd678a6e0c4a8 (commit)
via 1528b95aef19ee5bb49272d83c3ac7d91f6ce727 (commit)
via c02f7e5b2c18615e370b15581cd1b29c18a4bc79 (commit)
from 0c37dfaea46213d3c1564499de0849c451e1f326 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/050cbfbf2c0d6aec3c941a20c6ea16d467a7…
commit 050cbfbf2c0d6aec3c941a20c6ea16d467a72751
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 12 22:57:44 2013 +0200
doc: general: Update BMP implementation state.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/doc/general.txt b/doc/general.txt
index a8b6438..23de40d 100644
--- a/doc/general.txt
+++ b/doc/general.txt
@@ -88,7 +88,7 @@ images into various standard formats (PNG, JPEG, GIF, BMP, PNM, etc...).
| BMP | |
[green]*Yes* |
- [green]#RLE and RGB Bitfields not implemented# |
+ [green]#RLE4 and some less common bitfiels not supported# |
[green]#RGB888 only#
| TIFF |
http://repo.or.cz/w/gfxprim.git/commit/75e84dc25b607438e0141db5710fd678a6e0…
commit 75e84dc25b607438e0141db5710fd678a6e0c4a8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 12 22:57:32 2013 +0200
doc: Update core docs.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/doc/core.txt b/doc/core.txt
index eb38437..ec172a2 100644
--- a/doc/core.txt
+++ b/doc/core.txt
@@ -17,12 +17,18 @@ GP_MIN(a, b);
GP_MAX(a, b);
+GP_MAX3(a, b, c);
+
GP_ABS(a);
GP_SWAP(a, b);
GP_SIGN(a);
+GP_ARRAY_SIZE(arr);
+
+GP_CONTAINER_OF(ptr, structure, member);
+
-------------------------------------------------------------------------------
These common macros implements basic functions such as minimum, maximum,
@@ -30,6 +36,12 @@ absolute value, swap and sign.
All macros use 'typeof()' in order to evaluate their arguments exactly once.
+The 'GP_ARRAY_SIZE()' macro computes size of statically defined array (i.e.
+returns +sizeof(array) / sizeof(elem)+).
+
+The 'GP_CONTAINER_OF()' macro computes pointer to a structure given pointer to
+its member.
+
[source,c]
-------------------------------------------------------------------------------
#include <core/GP_Clamp.h>
http://repo.or.cz/w/gfxprim.git/commit/1528b95aef19ee5bb49272d83c3ac7d91f6c…
commit 1528b95aef19ee5bb49272d83c3ac7d91f6ce727
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 12 22:50:58 2013 +0200
doc: Update pixels docs.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/doc/pixels.txt b/doc/pixels.txt
index b226453..d6c18e8 100644
--- a/doc/pixels.txt
+++ b/doc/pixels.txt
@@ -1,15 +1,11 @@
Pixel Description
-----------------
-This pages describes library core functions for handling pixels.
+This pages describes library core functions for handling pixel types.
Pixel Type
~~~~~~~~~~
-Pixels are described by a pixel type, which is enumeration type. The enum is
-defined at the generated 'GP_Pixel.gen.h' header and must contain at least
-following members:
-
[source,c]
-------------------------------------------------------------------------------
#include <GP.h>
@@ -26,13 +22,28 @@ typedef enum GP_PixelType {
GP_PIXEL_G2,
GP_PIXEL_G4,
GP_PIXEL_G8,
+ ...
GP_PIXEL_MAX,
} GP_PixelType;
+/*
+ * The same values are also defined as macros so it's possible to
+ * use them with ifdef as follows.
+ */
+#ifdef GP_PIXEL_RGB555
+
+...
+
+#endif /* GP_PIXEL_RGB555 */
+
-------------------------------------------------------------------------------
-Each pixel type has accompanying record in global array of pixel types
-declared as follows:
+Pixels are described by a pixel type, which is enumeration type. The enum is
+defined in the generated 'GP_Pixel.gen.h' header and must contain at least the
+members listed above.
+
+The same names as are the enum values are also defined (to themselves) as
+macros so that it's possible to use them with 'ifdef'.
[source,c]
-------------------------------------------------------------------------------
@@ -46,12 +57,21 @@ typedef struct {
uint8_t size; /* Bit-size */
} GP_PixelTypeChannel;
+typedef enum GP_PixelFlags {
+ GP_PIXEL_HAS_ALPHA = 0x01,
+ GP_PIXEL_IS_RGB = 0x02,
+ GP_PIXEL_IS_PALETTE = 0x04,
+ GP_PIXEL_IS_CMYK = 0x08,
+ GP_PIXEL_IS_GRAYSCALE = 0x10,
+} GP_PixelFlags;
+
typedef struct {
GP_PixelType type; /* Number of the type */
const char name[16]; /* Name */
uint8_t size; /* Size in bits */
GP_BIT_ENDIAN bit_endian; /* Order of pixels in a byte */
uint8_t numchannels; /* Number of channels */
+ GP_PixelFlags flags;
/* String describing the bit-representaton (as in "RRRRRGGGGGGBBBBB")*/
const char bitmap[GP_PIXEL_BITS + 1];
/* Individual channels */
@@ -60,13 +80,44 @@ typedef struct {
extern const GP_PixelTypeDescription const GP_PixelTypes[];
+const GP_PixelTypeDescription *GP_PixelTypeDesc(GP_PixelType type);
+
const char *GP_PixelTypeName(GP_PixelType type);
uint32_t GP_PixelSize(GP_PixelType type);
+
+int GP_PixelHasFlags(GP_PixelType pixel_type, GP_PixelFlags flags);
-------------------------------------------------------------------------------
-There are also pixel matching functions that returns pixel type given RGB
-channel masks or sizes and offsets:
+Each pixel type has accompanying record in global array describing pixel types.
+
+You should not use this array directly, use the 'GP_PixelTypeDesc()' function
+to query the pixel type description.
+
+The 'GP_PixelTypeName()' function returns static string with pixel type name.
+
+The 'GP_PixelSize()' returns pixel size in bits.
+
+The 'GP_PixelHasFlags()' function returns true if particular pixel type
+contains the bitmask of pixel flags.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <GP.h>
+/* or */
+#include <core/GP_Pixel.h>
+
+void GP_PixelPrint(GP_Pixel pixel, GP_PixelType type);
+
+void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel pixel, GP_PixelType type);
+-------------------------------------------------------------------------------
+
+Pretty print pixel value given the pixel type.
+
+.Sample output from the functions
+-------------------------------------------------------------------------------
+RGB888 0xffffff R=255 G=255 B=255
+-------------------------------------------------------------------------------
[source,c]
-------------------------------------------------------------------------------
@@ -85,3 +136,5 @@ GP_PixelType GP_PixelRGBLookup(uint32_t rsize, uint32_t roff,
uint8_t bits_per_pixel);
-------------------------------------------------------------------------------
+Returns pixel type given either RGB masks or RGB sizes and offsets. If no
+matching pixel was found 'GP_PIXEL_UNKNOWN' is returned.
http://repo.or.cz/w/gfxprim.git/commit/c02f7e5b2c18615e370b15581cd1b29c18a4…
commit c02f7e5b2c18615e370b15581cd1b29c18a4bc79
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 12 22:15:16 2013 +0200
demos: c_simple: Add pretty print example.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile
index 3202c84..e086f75 100644
--- a/demos/c_simple/Makefile
+++ b/demos/c_simple/Makefile
@@ -18,7 +18,7 @@ APPS=backend_example loaders_example loaders filters_symmetry gfx_koch v4l2_show v4l2_grab convolution weighted_median shapetest koch input_example fileview linetest randomshapetest fonttest loaders_register blittest textaligntest abort sin_AA x11_windows- debug_handler gaussian_noise byte_utils version
+ debug_handler gaussian_noise byte_utils version pretty_print
ifeq ($(HAVE_LIBSDL),yes)
APPS+=SDL_glue
diff --git a/demos/c_simple/pretty_print.c b/demos/c_simple/pretty_print.c
new file mode 100644
index 0000000..ef010da
--- /dev/null
+++ b/demos/c_simple/pretty_print.c
@@ -0,0 +1,43 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+
+ Pretty print function for pixel and context.
+
+ */
+
+#include <GP.h>
+
+int main(void)
+{
+ GP_Context *ctx = GP_ContextAlloc(100, 100, GP_PIXEL_RGB888);
+ GP_Pixel pix = ~(GP_Pixel)0;
+
+ /* Pretty prints pixel values */
+ GP_PixelPrint(pix, GP_PIXEL_RGB888);
+
+ /* Pretty prints context info */
+ GP_ContextPrintInfo(ctx);
+
+ return 0;
+}
-----------------------------------------------------------------------
Summary of changes:
demos/c_simple/Makefile | 2 +-
demos/c_simple/{version.c => pretty_print.c} | 12 +++-
doc/core.txt | 12 ++++
doc/general.txt | 2 +-
doc/pixels.txt | 71 ++++++++++++++++++++++---
5 files changed, 85 insertions(+), 14 deletions(-)
copy demos/c_simple/{version.c => pretty_print.c} (86%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
12 Jun '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 0c37dfaea46213d3c1564499de0849c451e1f326 (commit)
via 9f103b51400ce326ec4d1d80693e3547a6ad2d24 (commit)
via a0cc425717d82517e00ec3f5e02f5231c60fd6e1 (commit)
via dc2499537b2ddc6bcc24015366d37df87653b1d9 (commit)
via 027536fe29c61495b170e8ce0e04736496c619df (commit)
from 1a6ee3086c94fc16d12a2115ca78501255758ea3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/0c37dfaea46213d3c1564499de0849c451e1…
commit 0c37dfaea46213d3c1564499de0849c451e1f326
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 12 21:49:50 2013 +0200
core: Fix warning on GP_GET_BITS(0, 32, val).
The change is cosmetic as the generated code remains the same
(at least for x86_64).
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/include/core/GP_GetSetBits.h b/include/core/GP_GetSetBits.h
index d724828..40d6b81 100644
--- a/include/core/GP_GetSetBits.h
+++ b/include/core/GP_GetSetBits.h
@@ -17,14 +17,25 @@
* Boston, MA 02110-1301 USA *
* *
* Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
- * Copyright (C) 2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2011-2013 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
- The macros are taking generally three arguments
-
+ Helper macros to get/set bits given offset and lenght.
+
+ The GP_GET_BITS() and GP_SET_BITS() works __ONLY__ on aligned data types.
+ Which means that you can only pass value that is suitably aligned for it's
+ type, for example passing an 32 bit integer is OK, passing a char buffer
+ casted to 32 bit integer is not (unless you made sure that the start address
+ is multiple of 4).
+
+ Now the align-safe variants first gets the value from a buffer, byte by byte
+ and then uses the GP_GET_BITS() or GP_SET_BITS(). The number in their name
+ tells how much bytes are touched, as we need to touch minimal number of
+ bytes needed.
+
*/
#ifndef CORE_GP_GET_SET_BITS_H
@@ -37,12 +48,12 @@
* Note: operates with value types same as val
*/
#define GP_GET_BITS(offset, len, val) - ( ( (val)>>(offset) ) & ( ((((typeof(val))1)<<(len)) - 1) ) )
+ (sizeof(val) * 8 <= len ? + (val)>>(offset) : + ((val)>>(offset)) & (((((typeof(val))1)<<(len)) - 1)))
/*
* Align-safe getbits
- *
- * TODO: Fix big endian
*/
#define GP_GET_BITS4_ALIGNED(offset, len, val) ({ uint32_t v; @@ -90,9 +101,9 @@
* GP_SET_BITS does both
*/
#define GP_CLEAR_BITS(offset, len, dest) - ( (dest) &= ~(((((typeof(dest))1) << (len)) - 1) << (offset)) )
+ ((dest) &= ~(((((typeof(dest))1) << (len)) - 1) << (offset)))
-#define GP_SET_BITS_OR(offset, dest, val) ( (dest) |= ((val)<<(offset)) )
+#define GP_SET_BITS_OR(offset, dest, val) ((dest) |= ((val)<<(offset)))
#define GP_SET_BITS(offset, len, dest, val) do { GP_CLEAR_BITS(offset, len, dest); diff --git a/libs/core/GP_Pixel.gen.c.t b/libs/core/GP_Pixel.gen.c.t
index 077f4be..9dc56f8 100644
--- a/libs/core/GP_Pixel.gen.c.t
+++ b/libs/core/GP_Pixel.gen.c.t
@@ -61,8 +61,6 @@ const GP_PixelTypeDescription const GP_PixelTypes [GP_PIXEL_MAX] = {
%% endfor
};
-#warning FIXME: do generic get set bit for pixel printing
-
%% for pt in pixeltypes
%% if not pt.is_unknown()
/*
http://repo.or.cz/w/gfxprim.git/commit/9f103b51400ce326ec4d1d80693e3547a6ad…
commit 9f103b51400ce326ec4d1d80693e3547a6ad2d24
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 12 21:49:21 2013 +0200
tests: core: Add GetSetBits test.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/tests/core/GetSetBits.gen.c.t b/tests/core/GetSetBits.gen.c.t
new file mode 100644
index 0000000..1f28cfd
--- /dev/null
+++ b/tests/core/GetSetBits.gen.c.t
@@ -0,0 +1,130 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+%% extends "base.test.c.t"
+
+{% block descr %}GP_GET_BITS() and GP_SET_BITS() tests.{% endblock %}
+
+%% block body
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <core/GP_GetSetBits.h>
+#include <core/GP_Common.h>
+#include "tst_test.h"
+
+static const uint32_t patterns[] = {
+ 0x00000000,
+ 0xffffffff,
+ 0x55555555,
+ 0xaaaaaaaa,
+ 0x43f8af32,
+};
+
+%% for len in range(1, 33)
+%% for off in range(0, 33 - len)
+static int getbits_{{ off }}_{{ len }}(void)
+{
+ uint32_t p_exp, p_get;
+ unsigned int i, fail = 0;
+
+ for (i = 0; i < GP_ARRAY_SIZE(patterns); i++) {
+ p_get = GP_GET_BITS({{ off }}, {{ len }}, patterns[i]);
+ p_exp = (patterns[i] >> {{ off }}) & {{ hex((2 ** len) - 1) }};
+
+ if (p_get != p_exp) {
+ tst_msg("Pattern 0x%08x differs get 0x%08x, expected 0x%08x",
+ patterns[i], p_get, p_exp);
+ fail++;
+ } else {
+ tst_msg("Pattern 0x%08x have 0x%08x", patterns[i], p_get);
+ }
+ }
+
+ if (fail)
+ return TST_FAILED;
+
+ return TST_SUCCESS;
+}
+%% endfor
+%% endfor
+
+%% macro mask(off, len)
+~{{ hex((2 ** len - 1) * (2 ** off)) }}
+%%- endmacro
+
+%% for len in range(1, 33)
+%% for off in range(0, 33 - len)
+static int setbits_{{ off }}_{{ len }}(void)
+{
+ uint32_t p_exp, canary1, p_get, canary2, val;
+ unsigned int i, j, fail = 0;
+
+ for (i = 0; i < GP_ARRAY_SIZE(patterns); i++) {
+ for (j = 0; j < GP_ARRAY_SIZE(patterns); j++) {
+ {# GP_SET_BITS() needs value clamped to the len #}
+ val = patterns[j] & {{ hex(2 ** len - 1) }};
+
+ canary1 = 0;
+ canary2 = 0;
+ p_get = patterns[i];
+ GP_SET_BITS({{ off }}, {{ len }}, p_get, val);
+
+ p_exp = patterns[i] & {{ mask(off, len) }};
+ p_exp |= val<<{{ off }};
+
+ if (p_get != p_exp || canary1 != 0 || canary2 != 0) {
+ tst_msg("BG 0x%08x FG 0x%08x differs get 0x%08x, expected 0x%08x",
+ patterns[i], val, p_get, p_exp);
+ fail++;
+ }
+ }
+ }
+
+ if (fail)
+ return TST_FAILED;
+
+ return TST_SUCCESS;
+}
+%% endfor
+%% endfor
+
+const struct tst_suite tst_suite = {
+ .suite_name = "GetSetBits testsuite",
+ .tests = {
+%% for len in range(1, 33)
+%% for off in range(0, 33 - len)
+ {.name = "GP_GET_BITS off={{ off }} len={{ len }}",
+ .tst_fn = getbits_{{ off }}_{{ len }}},
+%% endfor
+%% endfor
+%% for len in range(1, 33)
+%% for off in range(0, 33 - len)
+ {.name = "GP_SET_BITS off={{ off }} len={{ len }}",
+ .tst_fn = setbits_{{ off }}_{{ len }}},
+%% endfor
+%% endfor
+ {.name = NULL}
+ }
+};
+
+%% endblock body
diff --git a/tests/core/Makefile b/tests/core/Makefile
index c770fc5..3568fd0 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -5,10 +5,10 @@ include $(TOPDIR)/pre.mk
CSOURCES=Context.c Pixel.c
GENSOURCES+=WritePixel.gen.c GetPutPixel.gen.c Convert.gen.c BlitConv.gen.c - Convert_Scale.gen.c
+ Convert_Scale.gen.c GetSetBits.gen.c
APPS=WritePixel.gen Pixel Context GetPutPixel.gen Convert.gen BlitConv.gen - Convert_Scale.gen
+ Convert_Scale.gen GetSetBits.gen
include ../tests.mk
diff --git a/tests/core/test_list.txt b/tests/core/test_list.txt
index 3edab32..5fbaeba 100644
--- a/tests/core/test_list.txt
+++ b/tests/core/test_list.txt
@@ -2,6 +2,7 @@
WritePixel.gen
Context
Pixel
+GetSetBits.gen
GetPutPixel.gen
Convert.gen
Convert_Scale.gen
http://repo.or.cz/w/gfxprim.git/commit/a0cc425717d82517e00ec3f5e02f5231c60f…
commit a0cc425717d82517e00ec3f5e02f5231c60fd6e1
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 12 19:49:18 2013 +0200
pylib: Propagate floor() and ceil() to templates.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/pylib/gp_codegen/render_utils.py b/pylib/gp_codegen/render_utils.py
index cf3d7d4..c5433ea 100644
--- a/pylib/gp_codegen/render_utils.py
+++ b/pylib/gp_codegen/render_utils.py
@@ -6,6 +6,7 @@ import logging as log
import os
import time
import re
+from math import floor, ceil
# Custom filters
@@ -56,6 +57,8 @@ def create_environment(config, template_dir):
env.globals['int'] = int
env.globals['float'] = float
env.globals['round'] = round
+ env.globals['floor'] = floor
+ env.globals['ceil'] = ceil
env.globals['min'] = min
env.globals['max'] = max
# Add custom filters
http://repo.or.cz/w/gfxprim.git/commit/dc2499537b2ddc6bcc24015366d37df87653…
commit dc2499537b2ddc6bcc24015366d37df87653b1d9
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 9 18:11:00 2013 +0200
core: Cleanup the GP_Pixel(SN)Print functions.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Core_symbols.txt b/build/syms/Core_symbols.txt
index c04e144..10f0e5d 100644
--- a/build/syms/Core_symbols.txt
+++ b/build/syms/Core_symbols.txt
@@ -35,6 +35,9 @@ GP_PixelRGBMatch
GP_PixelTypeByName
GP_RGB888ToPixel
+GP_PixelPrint
+GP_PixelSNPrint
+
GP_BlitXYXY
GP_BlitXYXY_Fast
GP_BlitXYWH
diff --git a/include/core/GP_Pixel.gen.h.t b/include/core/GP_Pixel.gen.h.t
index aab38df..e0c0a61 100644
--- a/include/core/GP_Pixel.gen.h.t
+++ b/include/core/GP_Pixel.gen.h.t
@@ -57,11 +57,6 @@ typedef enum GP_PixelType {
%% endfor
*/
-/*
- * snprintf a human readable value of pixel type {{ pt.name }}
- */
-void GP_PixelSNPrint_{{ pt.name }}(char *buf, size_t len, GP_Pixel p);
-
/*
* macros to get channels of pixel type {{ pt.name }}
*/
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h
index 4a0806e..642f8b3 100644
--- a/include/core/GP_Pixel.h
+++ b/include/core/GP_Pixel.h
@@ -157,21 +157,12 @@ static inline const GP_PixelTypeDescription *GP_PixelTypeDesc(GP_PixelType type)
* Print a human-readable representation of a pixel value to a string.
* Arguments as for snprintf().
*/
-static inline void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel pixel,
- GP_PixelType type)
-{
- GP_FN_PER_PIXELTYPE(GP_PixelSNPrint, type, buf, len, pixel);
-}
+void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel pixel, GP_PixelType type);
/*
- * "printf" out a human-readable representation of pixel value.
+ * Prints human-readable representation of pixel value into the stdout.
*/
-static inline void GP_PixelPrint(GP_Pixel pixel, GP_PixelType type)
-{
- char buf[256];
- GP_PixelSNPrint(buf, 256, pixel, type);
- printf("%s", buf);
-}
+void GP_PixelPrint(GP_Pixel pixel, GP_PixelType type);
/*
* Returns pixel type for passed human-readable name (e.g. RGB888).
diff --git a/libs/core/GP_Pixel.gen.c.t b/libs/core/GP_Pixel.gen.c.t
index 0511120..077f4be 100644
--- a/libs/core/GP_Pixel.gen.c.t
+++ b/libs/core/GP_Pixel.gen.c.t
@@ -44,7 +44,7 @@ Pixel type definitions and functions
* Description of all known pixel types
*/
const GP_PixelTypeDescription const GP_PixelTypes [GP_PIXEL_MAX] = {
-%% for pt in pixeltypes
+%% for pt in pixeltypes
/* GP_PIXEL_{{ pt.name }} */ {
.type = GP_PIXEL_{{ pt.name }},
.name = "{{ pt.name }}",
@@ -54,26 +54,39 @@ const GP_PixelTypeDescription const GP_PixelTypes [GP_PIXEL_MAX] = {
.bitmap = "{{ pt.bits|join("") }}",
.flags = 0{{ getflags(pt) }},
.channels = {
-%% for c in pt.chanslist
+%% for c in pt.chanslist
{ .name = "{{ c[0] }}", .offset = {{ c[1] }}, .size = {{ c[2] }} },
-%% endfor
+%% endfor
} },
-%% endfor
+%% endfor
};
#warning FIXME: do generic get set bit for pixel printing
-%% for pt in pixeltypes
-%% if not pt.is_unknown()
+%% for pt in pixeltypes
+%% if not pt.is_unknown()
/*
* snprintf a human readable value of pixel type {{pt.name}}
*/
-void GP_PixelSNPrint_{{ pt.name }}(char *buf, size_t len, GP_Pixel p)
+static void GP_PixelSNPrint_{{ pt.name }}(char *buf, size_t len, GP_Pixel p)
{
- snprintf(buf, len, "<{{ pt.name }} 0x%0{{ (pt.pixelsize.size+3)//4 }}x{% for c in pt.chanslist %} {{ c[0] }}=%d{% endfor %}>",
- GP_GET_BITS(0, {{ pt.pixelsize.size }}, p){% for c in pt.chanslist %}, GP_GET_BITS({{ c[1] }}, {{ c[2] }}, p){% endfor %});
+ snprintf(buf, len, "{{ pt.name }} 0x%0{{ (pt.pixelsize.size+3)//4 }}x{% for c in pt.chanslist %} {{ c[0] }}=%d{% endfor %}",
+ GP_GET_BITS(0, {{ pt.pixelsize.size }}, p){% for c in pt.chanslist %}, GP_Pixel_GET_{{ c.name}}_{{ pt.name }}(p){% endfor %});
+}
+
+%% endif
+%% endfor
+
+void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel p, GP_PixelType pixel_type)
+{
+ GP_FN_PER_PIXELTYPE(GP_PixelSNPrint, pixel_type, buf, len, p);
+}
+
+void GP_PixelPrint(GP_Pixel p, GP_PixelType pixel_type)
+{
+ char buf[256];
+ GP_PixelSNPrint(buf, sizeof(buf), p, pixel_type);
+ puts(buf);
}
-%% endif
-%% endfor
%% endblock body
http://repo.or.cz/w/gfxprim.git/commit/027536fe29c61495b170e8ce0e04736496c6…
commit 027536fe29c61495b170e8ce0e04736496c619df
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 9 15:28:32 2013 +0200
build: Update list of exported symbols.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Input_symbols.txt b/build/syms/Input_symbols.txt
index de44378..2062806 100644
--- a/build/syms/Input_symbols.txt
+++ b/build/syms/Input_symbols.txt
@@ -9,6 +9,8 @@ GP_InputDriverKBDEventPut
GP_EventQueueSetCursorPosition
GP_EventQueueSetScreenSize
GP_EventQueueGet
+GP_EventQueuePeek
+GP_EventQueuePutBack
GP_EventQueueEventsQueued
GP_EventQueueInit
GP_EventQueueFree
-----------------------------------------------------------------------
Summary of changes:
build/syms/Core_symbols.txt | 3 +
build/syms/Input_symbols.txt | 2 +
include/core/GP_GetSetBits.h | 27 ++++++---
include/core/GP_Pixel.gen.h.t | 5 --
include/core/GP_Pixel.h | 15 +----
libs/core/GP_Pixel.gen.c.t | 37 +++++++----
pylib/gp_codegen/render_utils.py | 3 +
tests/core/GetSetBits.gen.c.t | 130 ++++++++++++++++++++++++++++++++++++++
tests/core/Makefile | 4 +-
tests/core/test_list.txt | 1 +
10 files changed, 187 insertions(+), 40 deletions(-)
create mode 100644 tests/core/GetSetBits.gen.c.t
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
04 Jun '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 1a6ee3086c94fc16d12a2115ca78501255758ea3 (commit)
via 0e3b39d5a7f1768f2376ab976d06e96005ce9976 (commit)
via 38cc4005d4cc548821fe46e9fdbdc49b1d6df89b (commit)
from 783b82f4bafe393e889c536cd6dfe743f21f732d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/1a6ee3086c94fc16d12a2115ca7850125575…
commit 1a6ee3086c94fc16d12a2115ca78501255758ea3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jun 4 22:52:00 2013 +0200
pylib: Add custom comment filter and use it descr
Add custom comment filter that adds ' *' to each line of the input.
Make use of the filter to convert descr block into nice C comment.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/pylib/gp_codegen/render_utils.py b/pylib/gp_codegen/render_utils.py
index be9b32d..cf3d7d4 100644
--- a/pylib/gp_codegen/render_utils.py
+++ b/pylib/gp_codegen/render_utils.py
@@ -7,6 +7,26 @@ import os
import time
import re
+# Custom filters
+
+def comment(lines):
+ """Adds space and asterisk before each line from lines"""
+ ret = ''
+ l = lines.split('n')
+
+ # Remove leading empty line
+ if l[0] == '':
+ l = l[1:]
+
+ # Remove traling empty line
+ if l[-1] == '':
+ l.pop()
+
+ for i in l:
+ ret += ' * ' + i + 'n'
+
+ return ret
+
try:
import jinja2
except:
@@ -33,11 +53,13 @@ def create_environment(config, template_dir):
env.globals['error'] = template_error
env.globals['hex'] = lambda x: hex(x).rstrip('L')
# Propagate some python buildins
- env.globals['int'] = int;
- env.globals['float'] = float;
- env.globals['round'] = round;
- env.globals['min'] = min;
- env.globals['max'] = max;
+ env.globals['int'] = int
+ env.globals['float'] = float
+ env.globals['round'] = round
+ env.globals['min'] = min
+ env.globals['max'] = max
+ # Add custom filters
+ env.filters['comment'] = comment
return env
@@ -65,7 +87,6 @@ def render_file(env, source, result):
finally:
result_file.close()
-
def load_gfxprimconfig(config_file = None):
"""Initialize GfxPrimConfig from a given or guessed config file.
Looks for the file by parameter, in env['PIXELTYPE_DEFS'] and
diff --git a/pylib/templates/base.c.t b/pylib/templates/base.c.t
index 57c957a..d8575e3 100644
--- a/pylib/templates/base.c.t
+++ b/pylib/templates/base.c.t
@@ -4,7 +4,10 @@
* GENERATED on {{ date }} from {{ template }}
* DO NOT MODIFY THIS FILE DIRECTLY!
*
- * {% block descr %}{% endblock %}
+%% filter comment()
+%% block descr
+%% endblock
+%% endfilter
*/
%% block pre_body_guard
http://repo.or.cz/w/gfxprim.git/commit/0e3b39d5a7f1768f2376ab976d06e96005ce…
commit 0e3b39d5a7f1768f2376ab976d06e96005ce9976
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jun 4 22:50:44 2013 +0200
templates: Fix description block id, add description
The description block id is descr not description
Add description block where it's missing
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/include/core/GP_FnPerBpp.gen.h.t b/include/core/GP_FnPerBpp.gen.h.t
index a53fbd5..11d5002 100644
--- a/include/core/GP_FnPerBpp.gen.h.t
+++ b/include/core/GP_FnPerBpp.gen.h.t
@@ -22,7 +22,7 @@
%% extends 'base.h.t'
-{% block description %}All FnPerBpp macros{% endblock %}
+{% block descr %}All FnPerBpp macros{% endblock %}
{% block body %}
diff --git a/include/core/GP_Pixel.gen.h.t b/include/core/GP_Pixel.gen.h.t
index d6e7659..aab38df 100644
--- a/include/core/GP_Pixel.gen.h.t
+++ b/include/core/GP_Pixel.gen.h.t
@@ -24,7 +24,7 @@
%% extends "base.h.t"
%% block descr
-Pixel type definitions and functions
+Pixel type definitions and functions.
Do not include directly, use GP_Pixel.h
%% endblock
diff --git a/include/core/GP_WritePixel.gen.h.t b/include/core/GP_WritePixel.gen.h.t
index 91237bc..b4ce29e 100644
--- a/include/core/GP_WritePixel.gen.h.t
+++ b/include/core/GP_WritePixel.gen.h.t
@@ -22,7 +22,7 @@
%% extends 'base.h.t'
-{% block description %}Write Pixels generated header{% endblock %}
+{% block descr %}Write Pixels generated header{% endblock %}
{% block body %}
diff --git a/include/gfx/GP_HLine.gen.h.t b/include/gfx/GP_HLine.gen.h.t
index 873f727..8e696a7 100644
--- a/include/gfx/GP_HLine.gen.h.t
+++ b/include/gfx/GP_HLine.gen.h.t
@@ -22,7 +22,7 @@
%% extends 'base.h.t'
-{% block description %}HLine generated header{% endblock %}
+{% block descr %}HLine generated header{% endblock %}
{% block body %}
diff --git a/include/gfx/GP_VLine.gen.h.t b/include/gfx/GP_VLine.gen.h.t
index 296e69a..11a8702 100644
--- a/include/gfx/GP_VLine.gen.h.t
+++ b/include/gfx/GP_VLine.gen.h.t
@@ -22,7 +22,7 @@
%% extends 'base.h.t'
-{% block description %}VLine generated header{% endblock %}
+{% block descr %}VLine generated header{% endblock %}
{% block body %}
diff --git a/libs/gfx/GP_VLine.gen.c.t b/libs/gfx/GP_VLine.gen.c.t
index 8700d8f..ad949e9 100644
--- a/libs/gfx/GP_VLine.gen.c.t
+++ b/libs/gfx/GP_VLine.gen.c.t
@@ -22,7 +22,7 @@
%% extends 'base.h.t'
-{% block description %}Vertical Line{% endblock %}
+{% block descr %}Vertical Line{% endblock %}
{% block body %}
diff --git a/tests/core/BlitConv.gen.c.t b/tests/core/BlitConv.gen.c.t
index 3305c0e..b6d02af 100644
--- a/tests/core/BlitConv.gen.c.t
+++ b/tests/core/BlitConv.gen.c.t
@@ -22,6 +22,8 @@
%% extends "base.test.c.t"
+{% block descr %}Blit conversions tests.{% endblock %}
+
%% block body
#include <stdio.h>
diff --git a/tests/core/Convert.gen.c.t b/tests/core/Convert.gen.c.t
index 3c418b0..8e9cf2a 100644
--- a/tests/core/Convert.gen.c.t
+++ b/tests/core/Convert.gen.c.t
@@ -22,6 +22,8 @@
%% extends "base.test.c.t"
+{% block descr %}Pixel conversions tests.{% endblock %}
+
%% block body
#include <stdio.h>
diff --git a/tests/core/Convert_Scale.gen.c.t b/tests/core/Convert_Scale.gen.c.t
index 8e67da4..f61e9bd 100644
--- a/tests/core/Convert_Scale.gen.c.t
+++ b/tests/core/Convert_Scale.gen.c.t
@@ -22,6 +22,8 @@
%% extends "base.test.c.t"
+{% block descr %}ConvertScale tests.{% endblock %}
+
%% block body
#include <stdio.h>
diff --git a/tests/core/GetPutPixel.gen.c.t b/tests/core/GetPutPixel.gen.c.t
index 05ffbdd..a843509 100644
--- a/tests/core/GetPutPixel.gen.c.t
+++ b/tests/core/GetPutPixel.gen.c.t
@@ -22,6 +22,8 @@
%% extends "base.test.c.t"
+{% block descr %}GetPutPixel tests.{% endblock %}
+
%% block body
#include <stdio.h>
diff --git a/tests/core/WritePixel.gen.c.t b/tests/core/WritePixel.gen.c.t
index c1aff24..9ec20c6 100644
--- a/tests/core/WritePixel.gen.c.t
+++ b/tests/core/WritePixel.gen.c.t
@@ -22,6 +22,8 @@
%% extends "base.test.c.t"
+{% block descr %}WritePixel tests.{% endblock %}
+
%% block body
#include <stdio.h>
diff --git a/tests/filters/APICoverage.gen.c.t b/tests/filters/APICoverage.gen.c.t
index b7d153f..ab22dd0 100644
--- a/tests/filters/APICoverage.gen.c.t
+++ b/tests/filters/APICoverage.gen.c.t
@@ -29,6 +29,8 @@
%% extends "base.test.c.t"
+{% block descr %}Filters API coverage tests.{% endblock %}
+
%% block body
#include <stdio.h>
diff --git a/tests/gfx/APICoverage.gen.c.t b/tests/gfx/APICoverage.gen.c.t
index 453e1ed..1afea7e 100644
--- a/tests/gfx/APICoverage.gen.c.t
+++ b/tests/gfx/APICoverage.gen.c.t
@@ -29,6 +29,8 @@
%% extends "base.test.c.t"
+{% block descr %}GFX API converage tests.{% endblock %}
+
%% block body
#include <stdio.h>
http://repo.or.cz/w/gfxprim.git/commit/38cc4005d4cc548821fe46e9fdbdc49b1d6d…
commit 38cc4005d4cc548821fe46e9fdbdc49b1d6df89b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Jun 3 20:12:55 2013 +0200
pywrap: Remove silence_swig_warnings.mk
Different swig versions vs compiler versions generate different
warnings. There is no point in silencing just one of them.
And swig authors seems to be good enough in fixing these, just make sure
to update to new enough swig and this shouldn't be a problem.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/pylib/gfxprim/backends/Makefile b/pylib/gfxprim/backends/Makefile
index 320165e..2353ed9 100644
--- a/pylib/gfxprim/backends/Makefile
+++ b/pylib/gfxprim/backends/Makefile
@@ -10,5 +10,3 @@ INSTALL_FILES+=_extend_backend.py
include $(TOPDIR)/pywrap.mk
include $(TOPDIR)/post.mk
-
-include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/core/Makefile b/pylib/gfxprim/core/Makefile
index ada5a6c..476d623 100644
--- a/pylib/gfxprim/core/Makefile
+++ b/pylib/gfxprim/core/Makefile
@@ -9,5 +9,3 @@ $(SWIG_C): ../common.i
INSTALL_FILES+=C.py
include $(TOPDIR)/post.mk
-
-include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/filters/Makefile b/pylib/gfxprim/filters/Makefile
index a7f3dbe..b1faad7 100644
--- a/pylib/gfxprim/filters/Makefile
+++ b/pylib/gfxprim/filters/Makefile
@@ -5,5 +5,3 @@ INCLUDE=core
include $(TOPDIR)/pre.mk
include $(TOPDIR)/pywrap.mk
include $(TOPDIR)/post.mk
-
-include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/gfx/Makefile b/pylib/gfxprim/gfx/Makefile
index b0e7e60..8b16fee 100644
--- a/pylib/gfxprim/gfx/Makefile
+++ b/pylib/gfxprim/gfx/Makefile
@@ -8,5 +8,3 @@ INSTALL_FILES+=C.py
include $(TOPDIR)/pywrap.mk
include $(TOPDIR)/post.mk
-
-include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/grabbers/Makefile b/pylib/gfxprim/grabbers/Makefile
index c864378..2a80492 100644
--- a/pylib/gfxprim/grabbers/Makefile
+++ b/pylib/gfxprim/grabbers/Makefile
@@ -8,5 +8,3 @@ LDLIBS+=$(LDLIBS_GRABBERS)
include $(TOPDIR)/pywrap.mk
include $(TOPDIR)/post.mk
-
-include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/input/Makefile b/pylib/gfxprim/input/Makefile
index 3430bc9..76eaaf8 100644
--- a/pylib/gfxprim/input/Makefile
+++ b/pylib/gfxprim/input/Makefile
@@ -4,5 +4,3 @@ LIBNAME=input
include $(TOPDIR)/pre.mk
include $(TOPDIR)/pywrap.mk
include $(TOPDIR)/post.mk
-
-include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/loaders/Makefile b/pylib/gfxprim/loaders/Makefile
index 883a266..600d233 100644
--- a/pylib/gfxprim/loaders/Makefile
+++ b/pylib/gfxprim/loaders/Makefile
@@ -11,5 +11,3 @@ include $(TOPDIR)/pywrap.mk
$(SWIG_C): ../common.i
include $(TOPDIR)/post.mk
-
-include ../silence_swig_warnings.mk
diff --git a/pylib/gfxprim/silence_swig_warnings.mk b/pylib/gfxprim/silence_swig_warnings.mk
deleted file mode 100644
index 38916e0..0000000
--- a/pylib/gfxprim/silence_swig_warnings.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-#
-# Turn off warnings generated bugs in swig implementation
-#
-CFLAGS+=-Wno-missing-field-initializers -Wno-unused-parameter
diff --git a/pylib/gfxprim/text/Makefile b/pylib/gfxprim/text/Makefile
index 2ae37f9..7cd01e7 100644
--- a/pylib/gfxprim/text/Makefile
+++ b/pylib/gfxprim/text/Makefile
@@ -8,5 +8,3 @@ INSTALL_FILES+=C.py
include $(TOPDIR)/pywrap.mk
include $(TOPDIR)/post.mk
-
-include ../silence_swig_warnings.mk
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_FnPerBpp.gen.h.t | 2 +-
include/core/GP_Pixel.gen.h.t | 2 +-
include/core/GP_WritePixel.gen.h.t | 2 +-
include/gfx/GP_HLine.gen.h.t | 2 +-
include/gfx/GP_VLine.gen.h.t | 2 +-
libs/gfx/GP_VLine.gen.c.t | 2 +-
pylib/gfxprim/backends/Makefile | 2 -
pylib/gfxprim/core/Makefile | 2 -
pylib/gfxprim/filters/Makefile | 2 -
pylib/gfxprim/gfx/Makefile | 2 -
pylib/gfxprim/grabbers/Makefile | 2 -
pylib/gfxprim/input/Makefile | 2 -
pylib/gfxprim/loaders/Makefile | 2 -
pylib/gfxprim/silence_swig_warnings.mk | 4 ---
pylib/gfxprim/text/Makefile | 2 -
pylib/gp_codegen/render_utils.py | 33 ++++++++++++++++++++++++++-----
pylib/templates/base.c.t | 5 +++-
tests/core/BlitConv.gen.c.t | 2 +
tests/core/Convert.gen.c.t | 2 +
tests/core/Convert_Scale.gen.c.t | 2 +
tests/core/GetPutPixel.gen.c.t | 2 +
tests/core/WritePixel.gen.c.t | 2 +
tests/filters/APICoverage.gen.c.t | 2 +
tests/gfx/APICoverage.gen.c.t | 2 +
24 files changed, 51 insertions(+), 33 deletions(-)
delete mode 100644 pylib/gfxprim/silence_swig_warnings.mk
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
01 Jun '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 783b82f4bafe393e889c536cd6dfe743f21f732d (commit)
from 71f52a5f96a206b5aeb9562de37143a731d6bbc4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/783b82f4bafe393e889c536cd6dfe743f21f…
commit 783b82f4bafe393e889c536cd6dfe743f21f732d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jun 1 15:26:41 2013 +0200
loaders: BMP: Initial code for RLE8.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index 7530794..44fb147 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -480,6 +480,8 @@ static uint8_t get_idx(struct bitmap_info_header *header,
return 0;
}
+#include "GP_BMP_RLE.h"
+
static int read_palette(FILE *f, struct bitmap_info_header *header,
GP_Context *context, GP_ProgressCallback *callback)
{
@@ -504,7 +506,7 @@ static int read_palette(FILE *f, struct bitmap_info_header *header,
GP_DEBUG(1, "Failed to read row %"PRId32, y);
return EIO;
}
-
+
for (x = 0; x < header->w; x++) {
uint8_t idx = get_idx(header, row, x);
GP_Pixel p;
@@ -589,6 +591,9 @@ static int read_bitfields_or_rgb(FILE *f, struct bitmap_info_header *header,
static int read_bitmap_pixels(FILE *f, struct bitmap_info_header *header,
GP_Context *context, GP_ProgressCallback *callback)
{
+ if (header->compress_type == COMPRESS_RLE8)
+ return read_RLE8(f, header, context, callback);
+
switch (header->bpp) {
case 1:
/* I haven't been able to locate 2bpp palette bmp file => not tested */
@@ -679,6 +684,7 @@ GP_Context *GP_ReadBMP(FILE *f, GP_ProgressCallback *callback)
case COMPRESS_RGB:
case COMPRESS_BITFIELDS:
case COMPRESS_ALPHABITFIELDS:
+ case COMPRESS_RLE8:
break;
default:
GP_DEBUG(2, "Unknown/Unimplemented compression type");
diff --git a/libs/loaders/GP_BMP_RLE.h b/libs/loaders/GP_BMP_RLE.h
new file mode 100644
index 0000000..19c30f8
--- /dev/null
+++ b/libs/loaders/GP_BMP_RLE.h
@@ -0,0 +1,316 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+
+ BMP RLE decoder.
+
+ */
+
+enum RLE_state {
+ RLE_START,
+ /* end of RLE or bitmap was reached */
+ RLE_STOP,
+ /* in the middle of repeat sequence */
+ RLE_REPEAT,
+ /* in the middle of undecoded run */
+ RLE_UNDECODED,
+};
+
+struct RLE {
+ /* current state */
+ uint8_t state;
+
+ /* image size */
+ uint32_t w;
+ uint32_t h;
+
+ /* current position */
+ uint32_t x;
+ uint32_t y;
+
+ uint8_t rep;
+ uint8_t flag:1;
+ /* set to 1 if next pixel is in c */
+ uint8_t move:2;
+
+ /* current value */
+ int c;
+};
+
+#define DECLARE_RLE(name, iw, ih) struct RLE name = { + .state = RLE_START, + .w = iw, .h = ih, + .x = 0, .y = 0, + .rep = 0+}
+
+#define GETC(f, rle) do { + rle->c = fgetc(f); + + if (rle->c == EOF) + return EIO; +} while (0)
+
+static void RLE8_move(struct RLE *rle)
+{
+ if (!rle->move)
+ return;
+
+ if (++rle->x >= rle->w) {
+ /* wrap around the end of line */
+ rle->x = 0;
+
+ /* all pixels filled */
+ if (++rle->y >= rle->h) {
+ GP_DEBUG(4, "y >= h, stop");
+ rle->state = RLE_STOP;
+ }
+ }
+
+ //GP_DEBUG(4, "RLE Move to %u %u", rle->x, rle->y);
+
+ rle->move = 0;
+}
+
+static int RLE8_end_of_scanline(struct RLE *rle)
+{
+ GP_DEBUG(4, "End of scanline at %u %u", rle->x, rle->y);
+
+ rle->x = 0;
+ rle->y++;
+ rle->move = 0;
+
+ if (rle->y >= rle->h) {
+ GP_DEBUG(4, "y >= h, stop");
+ rle->state = RLE_STOP;
+ }
+
+ return 0;
+}
+
+static int RLE8_end_of_bitmap(struct RLE *rle)
+{
+ GP_DEBUG(4, "End of bitmap data");
+
+ rle->state = RLE_STOP;
+
+ return 0;
+}
+
+static int RLE8_repeat(FILE *f, uint8_t rep, struct RLE *rle)
+{
+ GETC(f, rle);
+
+ GP_DEBUG(4, "RLE Repeat %i x 0x%02x", rep, rle->c);
+
+ rle->rep = rep;
+ rle->state = RLE_REPEAT;
+
+ return 0;
+}
+
+static int RLE8_offset(FILE *f, struct RLE *rle)
+{
+ int x, y;
+
+ x = fgetc(f);
+ y = fgetc(f);
+
+ if (x == EOF || y == EOF)
+ return EIO;
+
+ GP_DEBUG(1, "RLE offset %i %i", x, y);
+
+ if (rle->x + (uint32_t)x >= rle->w || rle->y + (uint32_t)y >= rle->h) {
+ GP_DEBUG(1, "RLE offset out of image, stop");
+ rle->state = RLE_STOP;
+ }
+
+ rle->x += x;
+ rle->y += y;
+
+ return 0;
+}
+
+static int RLE8_next_undecoded(FILE *f, struct RLE *rle)
+{
+ GETC(f, rle);
+
+ RLE8_move(rle);
+
+ //GP_DEBUG(4, "RLE unencoded %u %u -> %02x", rle->x, rle->y, rle->c);
+
+ if (--rle->rep == 0) {
+ rle->state = RLE_START;
+ /* must be padded to odd number of bytes */
+ if (rle->flag)
+ fgetc(f);
+ }
+
+ rle->move = 1;
+
+ return 0;
+}
+
+static int RLE8_next_repeat(struct RLE *rle)
+{
+ RLE8_move(rle);
+
+ //GP_DEBUG(4, "RLE repeat %u %u -> %02x", rle->x, rle->y, rle->c);
+
+ if (--rle->rep == 0)
+ rle->state = RLE_START;
+
+ rle->move = 1;
+
+ return 0;
+}
+
+static int RLE8_esc(FILE *f, struct RLE *rle)
+{
+ GETC(f, rle);
+
+ GP_DEBUG(4, "RLE ESC %02x", rle->c);
+
+ switch (rle->c) {
+ case 0x00:
+ return RLE8_end_of_scanline(rle);
+ case 0x01:
+ return RLE8_end_of_bitmap(rle);
+ case 0x02:
+ return RLE8_offset(f, rle);
+ /* Undecoded sequence */
+ default:
+ GP_DEBUG(4, "RLE Undecoded x %i", rle->c);
+ rle->state = RLE_UNDECODED;
+ rle->rep = rle->c;
+ rle->flag = rle->c % 2;
+ return 0;
+ }
+}
+
+static int RLE8_start(FILE *f, struct RLE *rle)
+{
+ GETC(f, rle);
+
+ switch (rle->c) {
+ case 0x00:
+ return RLE8_esc(f, rle);
+ default:
+ return RLE8_repeat(f, rle->c, rle);
+ }
+}
+
+static int RLE8_next(FILE *f, struct RLE *rle)
+{
+ int err;
+
+ for (;;) {
+ switch (rle->state) {
+ case RLE_START:
+ if ((err = RLE8_start(f, rle)))
+ return err;
+ break;
+ case RLE_REPEAT:
+ return RLE8_next_repeat(rle);
+ case RLE_UNDECODED:
+ return RLE8_next_undecoded(f, rle);
+ case RLE_STOP:
+ return 0;
+ default:
+ /* Shouldn't be reached */
+ GP_BUG("Invalid RLE state %u", rle->state);
+ return EINVAL;
+ }
+ }
+}
+
+static int read_RLE8(FILE *f, struct bitmap_info_header *header,
+ GP_Context *context, GP_ProgressCallback *callback)
+{
+ uint32_t palette_size = get_palette_size(header);
+ GP_Pixel palette[get_palette_size(header)];
+ DECLARE_RLE(rle, header->w, GP_ABS(header->h));
+ int err;
+
+ if ((err = read_bitmap_palette(f, header, palette)))
+ return err;
+
+ if ((err = seek_pixels_offset(header, f)))
+ return err;
+
+ int cnt = 0;
+
+ uint32_t x, y;
+
+ /*
+ * Fill the image with first palette color.
+ *
+ * TODO: Untouched pixels should be treated as
+ * 1 bit transpanrency (in header3+)
+ */
+ for (y = 0; y < context->h; y++) {
+ for (x = 0; x < context->w; x++)
+ GP_PutPixel_Raw_24BPP(context, x, y, palette[0]);
+ }
+
+ for (;;) {
+ if ((err = RLE8_next(f, &rle)))
+ return err;
+
+ if (rle.state == RLE_STOP)
+ break;
+
+ GP_Pixel p;
+
+ uint8_t idx = rle.c;
+
+ if (idx >= palette_size) {
+ GP_DEBUG(1, "Index out of palette, ignoring");
+ p = 0;
+ } else {
+ p = palette[idx];
+ }
+
+ int32_t ry;
+
+ if (header->h < 0)
+ ry = rle.y;
+ else
+ ry = GP_ABS(header->h) - 1 - rle.y;
+
+ GP_PutPixel_Raw_24BPP(context, rle.x, ry, p);
+
+ if (cnt++ > header->w) {
+ cnt = 0;
+ if (GP_ProgressCallbackReport(callback, rle.y,
+ context->h, context->w)) {
+ GP_DEBUG(1, "Operation aborted");
+ return ECANCELED;
+ }
+ }
+ }
+
+ GP_ProgressCallbackDone(callback);
+ return 0;
+}
-----------------------------------------------------------------------
Summary of changes:
libs/loaders/GP_BMP.c | 8 +-
libs/loaders/GP_BMP_RLE.h | 316 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 323 insertions(+), 1 deletions(-)
create mode 100644 libs/loaders/GP_BMP_RLE.h
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
31 May '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via 71f52a5f96a206b5aeb9562de37143a731d6bbc4 (commit)
via aab22729cba114c6be378df856d356d3d1bd4ea8 (commit)
from c70943a639eabdf53615fb48e6206ed4ed020d1b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/71f52a5f96a206b5aeb9562de37143a731d6…
commit 71f52a5f96a206b5aeb9562de37143a731d6bbc4
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 31 23:56:16 2013 +0200
loaders: BMP: Fix progress callback percentage.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index 70f701d..7530794 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -526,7 +526,7 @@ static int read_palette(FILE *f, struct bitmap_info_header *header,
GP_PutPixel_Raw_24BPP(context, x, ry, p);
}
- if (GP_ProgressCallbackReport(callback, header->h - y -1,
+ if (GP_ProgressCallbackReport(callback, y,
context->h, context->w)) {
GP_DEBUG(1, "Operation aborted");
return ECANCELED;
@@ -575,7 +575,7 @@ static int read_bitfields_or_rgb(FILE *f, struct bitmap_info_header *header,
break;
}
- if (GP_ProgressCallbackReport(callback, header->h - y -1,
+ if (GP_ProgressCallbackReport(callback, y,
context->h, context->w)) {
GP_DEBUG(1, "Operation aborted");
return ECANCELED;
http://repo.or.cz/w/gfxprim.git/commit/aab22729cba114c6be378df856d356d3d1bd…
commit aab22729cba114c6be378df856d356d3d1bd4ea8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 31 16:49:43 2013 +0200
core: Remove now unused GP_WritePixel.gen.c.t
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/core/GP_WritePixel.gen.c.t b/libs/core/GP_WritePixel.gen.c.t
deleted file mode 100644
index 89ecc1f..0000000
--- a/libs/core/GP_WritePixel.gen.c.t
+++ /dev/null
@@ -1,59 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-%% extends 'base.h.t'
-
-{% block description %}Write pixel{% endblock %}
-
-{% block body %}
-
-#include "core/GP_GetSetBits.h"
-#include "core/GP_GetPutPixel.h"
-#include "core/GP_WritePixel.gen.h"
-#include "core/GP_Debug.h"
-
-{# Some pixel types has hand written optimized functions #}
-%% set hand_optimized = ['1BPP_LE', '1BPP_BE',
- '2BPP_LE', '2BPP_BE',
- '4BPP_LE', '4BPP_BE',
- '8BPP', '16BPP',
- '24BPP', '32BPP']
-
-%% for ps in pixelsizes
-%% if ps.suffix not in hand_optimized
-%% if ps.needs_bit_endian()
-void GP_WritePixels_{{ ps.suffix }}(void *start, uint8_t off,
- size_t cnt, unsigned int val)
-{
- GP_TODO("Unimplemented");
-}
-%% else
-void GP_WritePixels_{{ ps.suffix }}(void *start, size_t cnt, unsigned int val)
-{
- GP_TODO("Unimplemented");
-}
-%% endif
-
-%% endif
-%% endfor
-
-{% endblock body %}
diff --git a/libs/core/Makefile b/libs/core/Makefile
index 46a46d3..c392a2b 100644
--- a/libs/core/Makefile
+++ b/libs/core/Makefile
@@ -2,7 +2,7 @@ TOPDIR=../..
include $(TOPDIR)/pre.mk
GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c - GP_GammaCorrection.gen.c GP_WritePixel.gen.c
+ GP_GammaCorrection.gen.c
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=core
-----------------------------------------------------------------------
Summary of changes:
libs/core/GP_WritePixel.gen.c.t | 59 ---------------------------------------
libs/core/Makefile | 2 +-
libs/loaders/GP_BMP.c | 4 +-
3 files changed, 3 insertions(+), 62 deletions(-)
delete mode 100644 libs/core/GP_WritePixel.gen.c.t
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
31 May '13
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project gfxprim.git.
The branch, master has been updated
via c70943a639eabdf53615fb48e6206ed4ed020d1b (commit)
from 8ab5ac0d39286dd025fcc5df44db7d5530209899 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/gfxprim.git/commit/c70943a639eabdf53615fb48e6206ed4ed02…
commit c70943a639eabdf53615fb48e6206ed4ed020d1b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri May 31 16:13:19 2013 +0200
loaders: BMP: Add support for BITFIELDS formats.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index ca2fe29..70f701d 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -22,9 +22,9 @@
/*
- BMP loader.
+ BMP loader and writer.
- Thanks wikipedia for the format specification.
+ Thanks Wikipedia for the format specification.
*/
@@ -76,6 +76,13 @@ struct bitmap_info_header {
* if 0 image uses whole range (2^bpp colors)
*/
uint32_t palette_colors;
+ /*
+ * RGBA masks for bitfields compression
+ */
+ uint32_t R_mask;
+ uint32_t G_mask;
+ uint32_t B_mask;
+ uint32_t A_mask;
};
enum bitmap_compress {
@@ -148,6 +155,50 @@ static uint32_t get_palette_size(struct bitmap_info_header *header)
return (1 << header->bpp);
}
+static int read_bitfields(FILE *f, struct bitmap_info_header *header)
+{
+ int ret;
+
+ ret = GP_FRead(f, "L4 L4 L4",
+ &header->R_mask,
+ &header->G_mask,
+ &header->B_mask);
+
+ if (ret != 3) {
+ GP_DEBUG(1, "Failed to read BITFIELDS");
+ return EIO;
+ }
+
+ header->A_mask = 0;
+
+ GP_DEBUG(1, "BITFIELDS R=0x%08x, G=0x%08x, B=0x%08x",
+ header->R_mask, header->G_mask, header->B_mask);
+
+ return 0;
+}
+
+static int read_alphabitfields(FILE *f, struct bitmap_info_header *header)
+{
+ int ret;
+
+ ret = GP_FRead(f, "L4 L4 L4 L4",
+ &header->R_mask,
+ &header->G_mask,
+ &header->B_mask,
+ &header->A_mask);
+
+ if (ret != 4) {
+ GP_DEBUG(1, "Failed to read BITFIELDS");
+ return EIO;
+ }
+
+ GP_DEBUG(1, "BITFILES R=0x%08x, G=0x%08x, B=0x%08x, A=0x%08x",
+ header->R_mask, header->G_mask, header->B_mask,
+ header->A_mask);
+
+ return 0;
+}
+
static int read_bitmap_info_header(FILE *f, struct bitmap_info_header *header)
{
uint16_t nr_planes;
@@ -171,6 +222,24 @@ static int read_bitmap_info_header(FILE *f, struct bitmap_info_header *header)
get_palette_size(header),
bitmap_compress_name(header->compress_type));
+ switch (header->compress_type) {
+ case COMPRESS_BITFIELDS:
+ switch (header->header_size) {
+ case BITMAPINFOHEADER:
+ case BITMAPINFOHEADER2:
+ return read_bitfields(f, header);
+ default:
+ /* Alpha is default in BITMAPINFOHEADER3 and newer */
+ return read_alphabitfields(f, header);
+ }
+ /* Only in BITMAPINFOHEADER */
+ case COMPRESS_ALPHABITFIELDS:
+ if (header->header_size != BITMAPINFOHEADER)
+ GP_DEBUG(1, "Unexpected ALPHABITFIELDS in %s",
+ bitmap_header_size_name(header->header_size));
+ return read_alphabitfields(f, header);
+ }
+
return 0;
}
@@ -244,7 +313,7 @@ static int read_bitmap_header(FILE *f, struct bitmap_info_header *header)
err = read_bitmap_info_header(f, header);
break;
};
-
+
return err;
}
@@ -318,17 +387,35 @@ static int seek_pixels_offset(struct bitmap_info_header *header, FILE *f)
static GP_PixelType match_pixel_type(struct bitmap_info_header *header)
{
+ /* handle bitfields */
+ switch (header->compress_type) {
+ case COMPRESS_BITFIELDS:
+ case COMPRESS_ALPHABITFIELDS:
+ return GP_PixelRGBMatch(header->R_mask, header->G_mask,
+ header->B_mask, header->A_mask,
+ header->bpp);
+ }
+
switch (header->bpp) {
+ /* palette formats -> expanded to RGB888 */
case 1:
case 2:
case 4:
case 8:
+ /* RGB888 */
case 24:
return GP_PIXEL_RGB888;
-#ifdef GP_PIXEL_RGB555
case 16:
+#ifdef GP_PIXEL_RGB555
+ //TODO: May have 1-bit ALPHA channel for BITMAPINFOHEADER3 and newer
return GP_PIXEL_RGB555;
+#else
+ //TODO: Conversion to RGB888?
+ break;
#endif
+ case 32:
+ //TODO: May have ALPHA channel for BITMAPINFOHEADER3 and newer
+ return GP_PIXEL_xRGB8888;
}
return GP_PIXEL_UNKNOWN;
@@ -450,8 +537,9 @@ static int read_palette(FILE *f, struct bitmap_info_header *header,
return 0;
}
-static int read_rgb(FILE *f, struct bitmap_info_header *header,
- GP_Context *context, GP_ProgressCallback *callback)
+static int read_bitfields_or_rgb(FILE *f, struct bitmap_info_header *header,
+ GP_Context *context,
+ GP_ProgressCallback *callback)
{
uint32_t row_size = header->w * (header->bpp / 8);
int32_t y;
@@ -486,7 +574,7 @@ static int read_rgb(FILE *f, struct bitmap_info_header *header,
case 0:
break;
}
-
+
if (GP_ProgressCallbackReport(callback, header->h - y -1,
context->h, context->w)) {
GP_DEBUG(1, "Operation aborted");
@@ -508,11 +596,10 @@ static int read_bitmap_pixels(FILE *f, struct bitmap_info_header *header,
case 4:
case 8:
return read_palette(f, header, context, callback);
-#ifdef GP_PIXEL_RGB555
case 16:
-#endif
case 24:
- return read_rgb(f, header, context, callback);
+ case 32:
+ return read_bitfields_or_rgb(f, header, context, callback);
}
return ENOSYS;
@@ -588,8 +675,13 @@ GP_Context *GP_ReadBMP(FILE *f, GP_ProgressCallback *callback)
goto err1;
}
- if (header.compress_type != COMPRESS_RGB) {
- GP_DEBUG(2, "Unknown compression type");
+ switch (header.compress_type) {
+ case COMPRESS_RGB:
+ case COMPRESS_BITFIELDS:
+ case COMPRESS_ALPHABITFIELDS:
+ break;
+ default:
+ GP_DEBUG(2, "Unknown/Unimplemented compression type");
err = ENOSYS;
goto err1;
}
@@ -599,7 +691,7 @@ GP_Context *GP_ReadBMP(FILE *f, GP_ProgressCallback *callback)
err = ENOSYS;
goto err1;
}
-
+
context = GP_ContextAlloc(header.w, GP_ABS(header.h), pixel_type);
if (context == NULL) {
-----------------------------------------------------------------------
Summary of changes:
libs/loaders/GP_BMP.c | 118 +++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 105 insertions(+), 13 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0