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 690b25c07649dab4d217e1d0ecbf9c56a20fc48b (commit) via a3aacf197945a7d0473b8710f3b67fa1e6232f31 (commit) via 349102348826ddb75fa961b9fa8c26ba6b545977 (commit) via dca1a2fe0c5bb6597965e33f0bf4907216d97bc2 (commit) via 52d18d34cd935319a82de09923943ccf96b0219f (commit) via c4b0e581c43bb9bfc6ca3738d19aa9ff5b15e836 (commit) via 5955c59467a2b043812d2fa02c783b1c9e4e2562 (commit) via 503fa7970aed181aa853406c3e04f6debaa7d5dd (commit) via 9fa629c10033f45505f2348eae343f6eb4a2b01b (commit) via 1486958906f687d667ff7c47c2af60c4110bd0c9 (commit) via c7a22b3bf489a9a42e29e66af3890f250e4a42df (commit) from 2ac9facaf575685be1e6ab95492f2c5bf0562567 (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/690b25c07649dab4d217e1d0ecbf9c56a20fc...
commit 690b25c07649dab4d217e1d0ecbf9c56a20fc48b Author: Cyril Hrubis metan@ucw.cz Date: Thu Jan 16 00:33:50 2014 +0100
loaders: IO: Fix empty variable array in GP_IOReadF()
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_IO.c b/libs/loaders/GP_IO.c index a1409a6..e09df1b 100644 --- a/libs/loaders/GP_IO.c +++ b/libs/loaders/GP_IO.c @@ -356,12 +356,14 @@ static int needs_swap(uint16_t type) int GP_IOReadF(GP_IO *self, uint16_t *types, ...) { unsigned int size = readf_size(types); - uint8_t buffer[size], *buf = buffer; int ret; va_list va; uint8_t *ptr;
- buf[0] = 0; + if (size == 0) + return 0; + + uint8_t buffer[size], *buf = buffer;
if (GP_IOFill(self, buf, size)) return -1;
http://repo.or.cz/w/gfxprim.git/commit/a3aacf197945a7d0473b8710f3b67fa1e6232...
commit a3aacf197945a7d0473b8710f3b67fa1e6232f31 Author: Cyril Hrubis metan@ucw.cz Date: Thu Jan 16 00:28:59 2014 +0100
loaders: GIF: Set errno correctly on no image record
Set errno correctly if there was no image record found in a GIF image.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_GIF.c b/libs/loaders/GP_GIF.c index 88bddee..0c286b9 100644 --- a/libs/loaders/GP_GIF.c +++ b/libs/loaders/GP_GIF.c @@ -346,8 +346,8 @@ GP_Context *GP_ReadGIF(GP_IO *io, GP_ProgressCallback *callback) DGifCloseFile(gf);
/* No Image record found :( */ - if (res == NULL) - err = EIO; + if (!res) + errno = EINVAL;
return res; err2:
http://repo.or.cz/w/gfxprim.git/commit/349102348826ddb75fa961b9fa8c26ba6b545...
commit 349102348826ddb75fa961b9fa8c26ba6b545977 Author: Cyril Hrubis metan@ucw.cz Date: Thu Jan 16 00:15:23 2014 +0100
loaders: Remove now unused GP_FRead()
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt index bac234f..7b40c8c 100644 --- a/build/syms/Loaders_symbols.txt +++ b/build/syms/Loaders_symbols.txt @@ -1,5 +1,4 @@ GP_FWrite -GP_FRead
GP_MatchJPG GP_ReadJPG diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile index 68fa14a..ed75f7a 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 sin_AA x11_windows- debug_handler gaussian_noise byte_utils version pretty_print timers+ debug_handler gaussian_noise version pretty_print timers zip_container backend_timers_example memory_io
ifeq ($(HAVE_LIBSDL),yes) @@ -52,7 +52,6 @@ fonttest: LDLIBS+=$(LDLIBS_BACKENDS) textaligntest: LDLIBS+=$(LDLIBS_BACKENDS) loaders_register: LDLIBS+=$(LDLIBS_LOADERS) gaussian_noise: LDLIBS+=$(LDLIBS_LOADERS) -byte_utils: LDLIBS+=$(LDLIBS_LOADERS) blittest: LDLIBS+=$(LDLIBS_BACKENDS) $(LDLIBS_LOADERS) sin_AA: LDLIBS+=$(LDLIBS_BACKENDS) x11_windows: LDLIBS+=$(LDLIBS_BACKENDS) diff --git a/demos/c_simple/byte_utils.c b/demos/c_simple/byte_utils.c deleted file mode 100644 index 4c9053f..0000000 --- a/demos/c_simple/byte_utils.c +++ /dev/null @@ -1,93 +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@ucw.cz * - * * - *****************************************************************************/ - -/* - * Byte utils are utils to ease reading and parsing various image headers. - * - * This is internal API for loaders. - */ - -#include <stdint.h> -#include <stdio.h> - -#include <loaders/GP_ByteUtils.h> - -#define FILENAME "file.tmp" - -static void write_file(void) -{ - FILE *f; - int ret; - - f = fopen(FILENAME, "wb"); - - if (f == NULL) { - fprintf(stderr, "Failed to open file '" FILENAME "'"); - return; - } - - uint16_t w = 800; - uint16_t h = 600; - uint8_t bpp = 4; - char *sig = "MG"; - - ret = GP_FWrite(f, "A2 0x00 0x00 B2 B2 B1", sig, w, h, bpp); - - if (ret != 6) - printf("Failed to write header, ret = %in", ret); - - fclose(f); -} - -static void read_file(void) -{ - FILE *f; - int ret; - - f = fopen(FILENAME, "rb"); - - if (f == NULL) { - fprintf(stderr, "Failed to open file '" FILENAME "'"); - return; - } - - uint16_t w; - uint16_t h; - uint8_t bpp; - char sig[3] = {0}; - - ret = GP_FRead(f, "A2 I2 B2 B2 B1", sig, &w, &h, &bpp); - - if (ret != 5) - printf("Failed to read header, ret = %in", ret); - - printf("SIG=%s, w=%u, h=%u, bpp=%un", sig, w, h, bpp); - - fclose(f); -} - -int main(void) -{ - write_file(); - read_file(); - return 0; -} diff --git a/include/loaders/GP_ByteUtils.h b/include/loaders/GP_ByteUtils.h index 8916fd7..92b2fec 100644 --- a/include/loaders/GP_ByteUtils.h +++ b/include/loaders/GP_ByteUtils.h @@ -32,39 +32,6 @@ #include <stdio.h>
/* - * The format string examples: - * - * Type Modifiers: - * - * L - little endian (passed as value to write, passed as pointer to read) - * B - big endian - * A - byte array (passed as bointer for both read and write) - * I - ignore xxx bytes, GP_Fread() only - * - * Size Modifiers are just numbers. - * - * To read and write header with two byte signature, two reserved zero bytes - * and size in 16 bit unsigned little endian variables. - * - * uint16_t w; - * uint16_t h; - * char sig[2]; - * - * if (GP_FWrite(f, "A2 0x00 0x00 L2 L2", "SG", w, h) != 5) - * //ERROR - * - * if (GP_FRead(f, "A2 I2 L2 L2", sig, &w, &h) != 4) - * //ERROR - */ - -/* - * Printf-like function to read file headers. - * - * Returns number of items successfully matched/converted. - */ -int GP_FRead(FILE *f, const char *fmt, ...); - -/* * Printf-like function to write file headers. * * Returns number of items sucessfully written. diff --git a/libs/loaders/GP_ByteUtils.c b/libs/loaders/GP_ByteUtils.c index b56c20d..4a83d5d 100644 --- a/libs/loaders/GP_ByteUtils.c +++ b/libs/loaders/GP_ByteUtils.c @@ -205,56 +205,6 @@ static void swap_bytes(void *ptr, int len, int type) } }
-int GP_FRead(FILE *f, const char *fmt, ...) -{ - int type, val, ret = 0; - void *ptr; - va_list va; - - va_start(va, fmt); - - for (;;) { - fmt = get_next(fmt, &type, &val); - - /* end of the string or error */ - if (fmt == NULL) - goto end; - - switch (type) { - case BYTE_ARRAY: - if (fread(va_arg(va, void*), val, 1, f) != 1) - goto end; - break; - case CONST_BYTE: - if (fgetc(f) != val) - goto end; - break; - case LITTLE_ENDIAN_VAR: - case BIG_ENDIAN_VAR: - ptr = va_arg(va, void*); - - if (fread(ptr, val, 1, f) != 1) - goto end; - - swap_bytes(ptr, val, type); - break; - case IGNORE: - while (val--) - fgetc(f); - break; - default: - GP_BUG("Wrong format type for reading (%i)", type); - goto end; - } - - ret++; - - } -end: - va_end(va); - return ret; -} - int GP_FWrite(FILE *f, const char *fmt, ...) { int type, val, ret = 0;
http://repo.or.cz/w/gfxprim.git/commit/dca1a2fe0c5bb6597965e33f0bf4907216d97...
commit dca1a2fe0c5bb6597965e33f0bf4907216d97bc2 Author: Cyril Hrubis metan@ucw.cz Date: Thu Jan 16 00:02:58 2014 +0100
pywrap: loaders.i: Cleanup Loaders wrappings.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/pylib/gfxprim/loaders/loaders.i b/pylib/gfxprim/loaders/loaders.i index f310e74..bab032c 100644 --- a/pylib/gfxprim/loaders/loaders.i +++ b/pylib/gfxprim/loaders/loaders.i @@ -10,81 +10,62 @@
%import ../core/core.i
+/* TODO IO from fd */ + +%define LOADER_FUNC(FMT) +%newobject GP_Load ## FMT; +ERROR_ON_NULL(GP_Load ## FMT); +%newobject GP_Read ## FMT; +ERROR_ON_NULL(GP_Read ## FMT); +%enddef + ERROR_ON_NULL(GP_LoadImage); -ERROR_ON_NONZERO(GP_LoadMetaData); +ERROR_ON_NONZERO(GP_ReadImage); ERROR_ON_NONZERO(GP_SaveImage);
%newobject GP_LoadImage;
%include "GP_Loader.h"
-ERROR_ON_NONZERO(GP_OpenJPG); -ERROR_ON_NULL(GP_ReadJPG); -ERROR_ON_NULL(GP_LoadJPG); -ERROR_ON_NONZERO(GP_ReadJPGMetaData); -ERROR_ON_NONZERO(GP_LoadJPGMetaData); +LOADER_FUNC(JPG); ERROR_ON_NONZERO(GP_SaveJPG);
-%newobject GP_LoadJPG; - %include "GP_JPG.h"
-ERROR_ON_NONZERO(GP_OpenBMP); -ERROR_ON_NULL(GP_ReadBMP); -ERROR_ON_NULL(GP_LoadBMP); - -%newobject GP_LoadBMP; +LOADER_FUNC(BMP); +ERROR_ON_NONZERO(GP_SaveBMP);
%include "GP_BMP.h"
-ERROR_ON_NONZERO(GP_OpenGIF); -ERROR_ON_NULL(GP_ReadGIF); -ERROR_ON_NULL(GP_LoadGIF); - -%newobject GP_LoadGIF; +LOADER_FUNC(GIF);
%include "GP_GIF.h"
-ERROR_ON_NONZERO(GP_OpenPNG); -ERROR_ON_NULL(GP_ReadPNG); -ERROR_ON_NULL(GP_LoadPNG); -ERROR_ON_NONZERO(GP_ReadPNGMetaData); -ERROR_ON_NONZERO(GP_LoadPNGMetaData); +LOADER_FUNC(PNG); ERROR_ON_NONZERO(GP_SavePNG);
-%newobject GP_LoadPNG; - %include "GP_PNG.h"
-ERROR_ON_NULL(GP_LoadPBM); -ERROR_ON_NULL(GP_LoadPGM); -ERROR_ON_NULL(GP_LoadPPM); -ERROR_ON_NULL(GP_LoadPNM); +LOADER_FUNC(PBM); +LOADER_FUNC(PGM); +LOADER_FUNC(PPM); +LOADER_FUNC(PNM); ERROR_ON_NONZERO(GP_SavePBM); ERROR_ON_NONZERO(GP_SavePGM); ERROR_ON_NONZERO(GP_SavePPM); ERROR_ON_NONZERO(GP_SavePNM);
-%newobject GP_LoadPBM; -%newobject GP_LoadPGM; -%newobject GP_LoadPPM; -%newobject GP_LoadPNM; - %include "GP_PNM.h"
-ERROR_ON_NULL(GP_LoadTIFF); +LOADER_FUNC(TIFF); ERROR_ON_NONZERO(GP_SaveTIFF);
-%newobject GP_LoadTIFF; - %include "GP_TIFF.h"
-ERROR_ON_NULL(GP_LoadPSP); -%newobject GP_LoadPSP; +LOADER_FUNC(PSP);
%include "GP_PSP.h"
-ERROR_ON_NULL(GP_LoadJP2); -%newobject GP_LoadJP2; +LOADER_FUNC(JP2);
%include "GP_JP2.h"
http://repo.or.cz/w/gfxprim.git/commit/52d18d34cd935319a82de09923943ccf96b02...
commit 52d18d34cd935319a82de09923943ccf96b0219f Author: Cyril Hrubis metan@ucw.cz Date: Wed Jan 15 23:34:07 2014 +0100
gfx: GP_Polygon: Remove unused initialization.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/gfx/GP_Polygon.c b/libs/gfx/GP_Polygon.c index e76babe..dd397b5 100644 --- a/libs/gfx/GP_Polygon.c +++ b/libs/gfx/GP_Polygon.c @@ -186,7 +186,7 @@ void GP_FillPolygon_Raw(GP_Context *context, unsigned int nvert, */ float inter[nedges]; unsigned int ninter; - int y = ymin; + int y; for (y = ymin; y <= ymax; y++) {
/* mark edges we have just reached as active */
http://repo.or.cz/w/gfxprim.git/commit/c4b0e581c43bb9bfc6ca3738d19aa9ff5b15e...
commit c4b0e581c43bb9bfc6ca3738d19aa9ff5b15e836 Author: Cyril Hrubis metan@ucw.cz Date: Wed Jan 15 23:20:42 2014 +0100
tests: loaders: Now 100% coverage for reading PNM
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/loaders/test_list.txt b/tests/loaders/.gitignore similarity index 77% copy from tests/loaders/test_list.txt copy to tests/loaders/.gitignore index add0cb3..047646e 100644 --- a/tests/loaders/test_list.txt +++ b/tests/loaders/.gitignore @@ -1,11 +1,11 @@ -# Loaders testsuite -loaders_suite -PNG +GIF +IO PBM PGM +PNG +PNM PPM -ZIP -GIF -IO -SaveLoad.gen SaveAbort.gen +SaveLoad.gen +ZIP +loaders_suite diff --git a/tests/loaders/Loader.h b/tests/loaders/Loader.h index 36b20ef..ec1fe62 100644 --- a/tests/loaders/Loader.h +++ b/tests/loaders/Loader.h @@ -16,10 +16,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
+#ifndef TESTS_LOADER_H +#define TESTS_LOADER_H + +#include "loaders/GP_IO.h" + struct testcase { GP_Size w; GP_Size h; @@ -27,26 +32,10 @@ struct testcase { char *path; };
-static int test_load(struct testcase *test) +static int test_check(struct testcase *test, GP_Context *img) { - GP_Context *img; unsigned int x, y, err = 0;
- errno = 0; - - img = LOAD(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); @@ -68,7 +57,8 @@ static int test_load(struct testcase *test) } }
- GP_ContextFree(img); + if (err > 5) + tst_msg("And %u errors...", err);
if (err) return TST_FAILED; @@ -76,6 +66,72 @@ static int test_load(struct testcase *test) return TST_SUCCESS; }
+static int test_read(struct testcase *test) +{ + GP_Context *img; + GP_IO *io; + int err; + + io = GP_IOMem(test->path, strlen(test->path), NULL); + + if (!io) { + tst_msg("Failed to initialize memory IO: %s", strerror(errno)); + return TST_UNTESTED; + } + + img = READ(io, NULL); + + if (!img) { + switch (errno) { + case ENOSYS: + tst_msg("Not Implemented"); + err = TST_SKIPPED; + goto out; + default: + tst_msg("Got %s", strerror(errno)); + err = TST_FAILED; + goto out; + } + } + + err = test_check(test, img); + + GP_ContextFree(img); +out: + GP_IOClose(io); + return err; +} + +# ifdef LOAD + +static int test_load(struct testcase *test) +{ + GP_Context *img; + int err; + + errno = 0; + + img = LOAD(test->path, NULL); + + if (!img) { + switch (errno) { + case ENOSYS: + tst_msg("Not Implemented"); + return TST_SKIPPED; + default: + tst_msg("Got %s", strerror(errno)); + return TST_FAILED; + } + } + + err = test_check(test, img); + + GP_ContextFree(img); + + return err; +} + + static int test_load_fail(const char *path) { GP_Context *img; @@ -103,6 +159,11 @@ static int test_load_fail(const char *path) } }
+# endif /* LOAD */ + + +# if defined(SAVE) && defined(LOAD) + /* * Saves and loads image using the SAVE and LOAD functions * and compares the results. @@ -188,3 +249,7 @@ static int test_save_load(struct testcase_save_load *test)
return TST_SUCCESS; } + +# endif /* SAVE && LOAD */ + +#endif /* TESTS_LOADER_H */ diff --git a/tests/loaders/Makefile b/tests/loaders/Makefile index 6678352..31eaea4 100644 --- a/tests/loaders/Makefile +++ b/tests/loaders/Makefile @@ -1,10 +1,10 @@ TOPDIR=../.. include $(TOPDIR)/pre.mk
-CSOURCES=loaders_suite.c PNG.c PBM.c PGM.c PPM.c ZIP.c GIF.c IO.c +CSOURCES=loaders_suite.c PNG.c PBM.c PGM.c PPM.c ZIP.c GIF.c IO.c PNM.c GENSOURCES=SaveLoad.gen.c SaveAbort.gen.c
-APPS=loaders_suite PNG PBM PGM PPM SaveLoad.gen SaveAbort.gen ZIP GIF IO +APPS=loaders_suite PNG PBM PGM PPM PNM SaveLoad.gen SaveAbort.gen ZIP GIF IO
include ../tests.mk
diff --git a/tests/loaders/PBM.c b/tests/loaders/PBM.c index 86a20a5..9b71f04 100644 --- a/tests/loaders/PBM.c +++ b/tests/loaders/PBM.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -32,7 +32,9 @@
#define LOAD GP_LoadPBM #define SAVE GP_SavePBM +#define READ GP_ReadPBM #include "Loader.h" +#include "PBM.h"
struct testcase black_1x1_1 = { .w = 1, @@ -148,6 +150,26 @@ const struct tst_suite tst_suite = { .data = &black_3x9_bin, .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+ {.name = "PBM Read 1x1 (black)", + .tst_fn = test_read, + .data = &PBM_ascii_1x1_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PBM Read 1x1 (white)", + .tst_fn = test_read, + .data = &PBM_ascii_1x1_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PBM Read 1x1 (black) Raw", + .tst_fn = test_read, + .data = &PBM_bin_1x1_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PBM Read 1x1 (white) Raw", + .tst_fn = test_read, + .data = &PBM_bin_1x1_white, + .flags = TST_CHECK_MALLOC}, + {.name = "PBM Load corrupt", .tst_fn = test_load_fail, .res_path = "data/pbm/corrupt/short.pbm", diff --git a/tests/loaders/PPM.c b/tests/loaders/PBM.h similarity index 57% copy from tests/loaders/PPM.c copy to tests/loaders/PBM.h index 3082ce4..3a45967 100644 --- a/tests/loaders/PPM.c +++ b/tests/loaders/PBM.h @@ -16,63 +16,48 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@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" - -#define LOAD GP_LoadPPM -#define SAVE GP_SavePPM #include "Loader.h"
-struct testcase black_1x1 = { +static struct testcase PBM_ascii_1x1_black = { .w = 1, .h = 1, .pix = 0, - .path = "black_1x1.ppm", + .path = "P1n" + "# 1x1 black PBM ascii imagen" + "1 1n" + "1" };
-struct testcase_save_load save_load = { - .w = 100, - .h = 100, - .pixel_type = GP_PIXEL_RGB888, +static struct testcase PBM_ascii_1x1_white = { + .w = 1, + .h = 1, + .pix = 1, + .path = "P1n" + "# 1x1 black PBM ascii imagen" + "1 1n" + "0" };
-const struct tst_suite tst_suite = { - .suite_name = "PPM", - .tests = { - {.name = "PPM Load 1x1 (black)", - .tst_fn = test_load, - .res_path = "data/ppm/valid/black_1x1.ppm", - .data = &black_1x1, - .flags = TST_TMPDIR | TST_CHECK_MALLOC}, - - {.name = "PPM Save Load", - .tst_fn = test_save_load, - .data = &save_load, - .flags = TST_TMPDIR | TST_CHECK_MALLOC}, - - {.name = "PPM Load wrong header", - .tst_fn = test_load_fail, - .res_path = "data/ppm/corrupt/wrong_header.ppm", - .data = "wrong_header.ppm", - .flags = TST_TMPDIR | TST_CHECK_MALLOC}, - - {.name = "PPM Load incomplete", - .tst_fn = test_load_fail, - .res_path = "data/ppm/corrupt/incomplete.ppm", - .data = "incomplete.ppm", - .flags = TST_TMPDIR | TST_CHECK_MALLOC}, +static struct testcase PBM_bin_1x1_black = { + .w = 1, + .h = 1, + .pix = 0, + .path = "P4n" + "# 1x1 black PBM binary imagen" + "1 1n" + "x80" +};
- {.name = NULL}, - } +static struct testcase PBM_bin_1x1_white = { + .w = 1, + .h = 1, + .pix = 1, + .path = "P4n" + "# 1x1 black PBM binary imagen" + "1 1n" + "x01" }; diff --git a/tests/loaders/PGM.c b/tests/loaders/PGM.c index 6bac05a..1fae867 100644 --- a/tests/loaders/PGM.c +++ b/tests/loaders/PGM.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -32,7 +32,9 @@
#define LOAD GP_LoadPGM #define SAVE GP_SavePGM +#define READ GP_ReadPGM #include "Loader.h" +#include "PGM.h"
struct testcase black_1x1_1bpp = { .w = 1, @@ -113,6 +115,66 @@ const struct tst_suite tst_suite = { .data = &black_1x1_8bpp, .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+ {.name = "PGM Read 1x1 1bpp (black)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_1bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 2bpp (black)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_2bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 4bpp (black)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_4bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 8bpp (black)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_8bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 1bpp (white)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_1bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 2bpp (white)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_2bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 4bpp (white)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_4bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 8bpp (white)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_8bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 1bpp (white) Raw", + .tst_fn = test_read, + .data = &PGM_bin_1x1_1bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 2bpp (white) Raw", + .tst_fn = test_read, + .data = &PGM_bin_1x1_2bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 4bpp (white) Raw", + .tst_fn = test_read, + .data = &PGM_bin_1x1_4bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 8bpp (white) Raw", + .tst_fn = test_read, + .data = &PGM_bin_1x1_8bpp_white, + .flags = TST_CHECK_MALLOC}, + {.name = "PGM Save Load 1bpp", .tst_fn = test_save_load, .data = &save_load_1bpp, diff --git a/tests/loaders/PGM.h b/tests/loaders/PGM.h new file mode 100644 index 0000000..a4f406e --- /dev/null +++ b/tests/loaders/PGM.h @@ -0,0 +1,155 @@ +/***************************************************************************** + * 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-2014 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include "Loader.h" + +static struct testcase PGM_ascii_1x1_1bpp_black = { + .w = 1, + .h = 1, + .pix = 0, + .path = "P2n" + "# 1x1 black PGM 1bpp ascii imagen" + "1 1n" + "1n" + "0" +}; + +static struct testcase PGM_ascii_1x1_2bpp_black = { + .w = 1, + .h = 1, + .pix = 0, + .path = "P2n" + "# 1x1 black PGM 2bpp ascii imagen" + "1 1n" + "3n" + "0" +}; + +static struct testcase PGM_ascii_1x1_4bpp_black = { + .w = 1, + .h = 1, + .pix = 0, + .path = "P2n" + "# 1x1 black PGM 4bpp ascii imagen" + "1 1n" + "15n" + "0" +}; + +static struct testcase PGM_ascii_1x1_8bpp_black = { + .w = 1, + .h = 1, + .pix = 0, + .path = "P2n" + "# 1x1 black PGM 8bpp ascii imagen" + "1 1n" + "255n" + "0" +}; + +static struct testcase PGM_ascii_1x1_1bpp_white = { + .w = 1, + .h = 1, + .pix = 1, + .path = "P2n" + "# 1x1 white PGM 1bpp ascii imagen" + "1 1n" + "1n" + "1" +}; + +static struct testcase PGM_ascii_1x1_2bpp_white = { + .w = 1, + .h = 1, + .pix = 3, + .path = "P2n" + "# 1x1 white PGM 2bpp ascii imagen" + "1 1n" + "3n" + "3" +}; + +static struct testcase PGM_ascii_1x1_4bpp_white = { + .w = 1, + .h = 1, + .pix = 15, + .path = "P2n" + "# 1x1 white PGM 4bpp ascii imagen" + "1 1n" + "15n" + "15" +}; + +static struct testcase PGM_ascii_1x1_8bpp_white = { + .w = 1, + .h = 1, + .pix = 255, + .path = "P2n" + "# 1x1 white PGM 8bpp ascii imagen" + "1 1n" + "255n" + "255" +}; + +static struct testcase PGM_bin_1x1_1bpp_white = { + .w = 1, + .h = 1, + .pix = 1, + .path = "P5n" + "# 1x1 white PGM 1bpp binary imagen" + "1 1n" + "1n" + "x01" +}; + +static struct testcase PGM_bin_1x1_2bpp_white = { + .w = 1, + .h = 1, + .pix = 3, + .path = "P5n" + "# 1x1 white PGM 2bpp binary imagen" + "1 1n" + "3n" + "x03" +}; + +static struct testcase PGM_bin_1x1_4bpp_white = { + .w = 1, + .h = 1, + .pix = 15, + .path = "P5n" + "# 1x1 white PGM 4bpp binary imagen" + "1 1n" + "15n" + "x0f" +}; + +static struct testcase PGM_bin_1x1_8bpp_white = { + .w = 1, + .h = 1, + .pix = 255, + .path = "P5n" + "# 1x1 white PGM 8bpp binary imagen" + "1 1n" + "255n" + "xff" +}; diff --git a/tests/loaders/PNM.c b/tests/loaders/PNM.c new file mode 100644 index 0000000..c1f75b7 --- /dev/null +++ b/tests/loaders/PNM.c @@ -0,0 +1,147 @@ +/***************************************************************************** + * 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-2014 Cyril Hrubis metan@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" + +#define READ GP_ReadPNM +#include "Loader.h" +#include "PBM.h" +#include "PGM.h" +#include "PPM.h" + +const struct tst_suite tst_suite = { + .suite_name = "PNM", + .tests = { + /* PBM tests */ + {.name = "PBM Read 1x1 (black)", + .tst_fn = test_read, + .data = &PBM_ascii_1x1_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PBM Read 1x1 (white)", + .tst_fn = test_read, + .data = &PBM_ascii_1x1_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PBM Read 1x1 (black) Raw", + .tst_fn = test_read, + .data = &PBM_bin_1x1_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PBM Read 1x1 (white) Raw", + .tst_fn = test_read, + .data = &PBM_bin_1x1_white, + .flags = TST_CHECK_MALLOC}, + + /* PGM tests */ + {.name = "PGM Read 1x1 1bpp (black)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_1bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 2bpp (black)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_2bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 4bpp (black)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_4bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 8bpp (black)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_8bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 1bpp (white)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_1bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 2bpp (white)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_2bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 4bpp (white)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_4bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 8bpp (white)", + .tst_fn = test_read, + .data = &PGM_ascii_1x1_8bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 1bpp (white) Raw", + .tst_fn = test_read, + .data = &PGM_bin_1x1_1bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 2bpp (white) Raw", + .tst_fn = test_read, + .data = &PGM_bin_1x1_2bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 4bpp (white) Raw", + .tst_fn = test_read, + .data = &PGM_bin_1x1_4bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PGM Read 1x1 8bpp (white) Raw", + .tst_fn = test_read, + .data = &PGM_bin_1x1_8bpp_white, + .flags = TST_CHECK_MALLOC}, + + /* PPM tests */ + {.name = "PPM Read 1x1 4bpp (black)", + .tst_fn = test_read, + .data = &PPM_ascii_1x1_4bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PPM Read 1x1 8bpp (black)", + .tst_fn = test_read, + .data = &PPM_ascii_1x1_8bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PPM Read 1x1 8bpp (white)", + .tst_fn = test_read, + .data = &PPM_ascii_1x1_8bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PPM Read 1x1 8bpp (white) Raw", + .tst_fn = test_read, + .data = &PPM_bin_1x1_8bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = NULL}, + } +}; diff --git a/tests/loaders/PPM.c b/tests/loaders/PPM.c index 3082ce4..a3c7b84 100644 --- a/tests/loaders/PPM.c +++ b/tests/loaders/PPM.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -32,16 +32,18 @@
#define LOAD GP_LoadPPM #define SAVE GP_SavePPM +#define READ GP_ReadPPM #include "Loader.h" +#include "PPM.h"
-struct testcase black_1x1 = { +static struct testcase PPM_black_1x1 = { .w = 1, .h = 1, .pix = 0, .path = "black_1x1.ppm", };
-struct testcase_save_load save_load = { +static struct testcase_save_load PPM_save_load = { .w = 100, .h = 100, .pixel_type = GP_PIXEL_RGB888, @@ -53,12 +55,32 @@ const struct tst_suite tst_suite = { {.name = "PPM Load 1x1 (black)", .tst_fn = test_load, .res_path = "data/ppm/valid/black_1x1.ppm", - .data = &black_1x1, + .data = &PPM_black_1x1, .flags = TST_TMPDIR | TST_CHECK_MALLOC},
+ {.name = "PPM Read 1x1 4bpp (black)", + .tst_fn = test_read, + .data = &PPM_ascii_1x1_4bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PPM Read 1x1 8bpp (black)", + .tst_fn = test_read, + .data = &PPM_ascii_1x1_8bpp_black, + .flags = TST_CHECK_MALLOC}, + + {.name = "PPM Read 1x1 8bpp (white)", + .tst_fn = test_read, + .data = &PPM_ascii_1x1_8bpp_white, + .flags = TST_CHECK_MALLOC}, + + {.name = "PPM Read 1x1 8bpp (white) Raw", + .tst_fn = test_read, + .data = &PPM_bin_1x1_8bpp_white, + .flags = TST_CHECK_MALLOC}, + {.name = "PPM Save Load", .tst_fn = test_save_load, - .data = &save_load, + .data = &PPM_save_load, .flags = TST_TMPDIR | TST_CHECK_MALLOC},
{.name = "PPM Load wrong header", diff --git a/tests/loaders/PPM.c b/tests/loaders/PPM.h similarity index 57% copy from tests/loaders/PPM.c copy to tests/loaders/PPM.h index 3082ce4..7de53a7 100644 --- a/tests/loaders/PPM.c +++ b/tests/loaders/PPM.h @@ -16,63 +16,52 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@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" - -#define LOAD GP_LoadPPM -#define SAVE GP_SavePPM #include "Loader.h"
-struct testcase black_1x1 = { +static struct testcase PPM_ascii_1x1_4bpp_black = { .w = 1, .h = 1, .pix = 0, - .path = "black_1x1.ppm", + .path = "P3n" + "# 1x1 black PPM ascii 4bpp imagen" + "1 1n" + "15n" + "0 0 0" };
-struct testcase_save_load save_load = { - .w = 100, - .h = 100, - .pixel_type = GP_PIXEL_RGB888, +static struct testcase PPM_ascii_1x1_8bpp_black = { + .w = 1, + .h = 1, + .pix = 0, + .path = "P3n" + "# 1x1 black PPM ascii 8bpp imagen" + "1 1n" + "255n" + "0 0 0" };
-const struct tst_suite tst_suite = { - .suite_name = "PPM", - .tests = { - {.name = "PPM Load 1x1 (black)", - .tst_fn = test_load, - .res_path = "data/ppm/valid/black_1x1.ppm", - .data = &black_1x1, - .flags = TST_TMPDIR | TST_CHECK_MALLOC}, - - {.name = "PPM Save Load", - .tst_fn = test_save_load, - .data = &save_load, - .flags = TST_TMPDIR | TST_CHECK_MALLOC}, - - {.name = "PPM Load wrong header", - .tst_fn = test_load_fail, - .res_path = "data/ppm/corrupt/wrong_header.ppm", - .data = "wrong_header.ppm", - .flags = TST_TMPDIR | TST_CHECK_MALLOC}, - - {.name = "PPM Load incomplete", - .tst_fn = test_load_fail, - .res_path = "data/ppm/corrupt/incomplete.ppm", - .data = "incomplete.ppm", - .flags = TST_TMPDIR | TST_CHECK_MALLOC}, +static struct testcase PPM_ascii_1x1_8bpp_white = { + .w = 1, + .h = 1, + .pix = 0xffffff, + .path = "P3n" + "# 1x1 white PPM ascii 8bpp imagen" + "1 1n" + "255n" + "255 255 255" +};
- {.name = NULL}, - } +static struct testcase PPM_bin_1x1_8bpp_white = { + .w = 1, + .h = 1, + .pix = 0xffffff, + .path = "P6n" + "# 1x1 white PPM binary 8bpp imagen" + "1 1n" + "255n" + "xffxffxff" }; diff --git a/tests/loaders/test_list.txt b/tests/loaders/test_list.txt index add0cb3..d4410cb 100644 --- a/tests/loaders/test_list.txt +++ b/tests/loaders/test_list.txt @@ -4,6 +4,7 @@ PNG PBM PGM PPM +PNM ZIP GIF IO
http://repo.or.cz/w/gfxprim.git/commit/5955c59467a2b043812d2fa02c783b1c9e4e2...
commit 5955c59467a2b043812d2fa02c783b1c9e4e2562 Author: Cyril Hrubis metan@ucw.cz Date: Wed Jan 15 22:03:58 2014 +0100
text: Fix GP_VALIGN_BASELINE.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/c_simple/textaligntest.c b/demos/c_simple/textaligntest.c index 1e8a77d..70b2fd2 100644 --- a/demos/c_simple/textaligntest.c +++ b/demos/c_simple/textaligntest.c @@ -19,14 +19,15 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
+#include <stdio.h> #include <GP.h>
static GP_Pixel black_pixel, red_pixel, yellow_pixel, green_pixel, blue_pixel, - darkgray_pixel; + darkgray_pixel, white_pixel;
static int font_flag = 0;
@@ -34,6 +35,7 @@ static int X = 640; static int Y = 480;
static GP_FontFace *font = NULL; +static GP_TextStyle style = GP_DEFAULT_TEXT_STYLE;
static GP_Backend *win;
@@ -45,8 +47,6 @@ void redraw_screen(void) GP_HLine(win->context, 0, X, Y/2, darkgray_pixel); GP_VLine(win->context, X/2, 0, Y, darkgray_pixel);
- GP_TextStyle style = GP_DEFAULT_TEXT_STYLE; - switch (font_flag) { case 0: style.font = &GP_DefaultProportionalFont; @@ -55,6 +55,15 @@ void redraw_screen(void) style.font = &GP_DefaultConsoleFont; break; case 2: + style.font = GP_FontTinyMono; + break; + case 3: + style.font = GP_FontTiny; + break; + case 4: + style.font = GP_FontC64; + break; + case 5: style.font = font; break; } @@ -67,6 +76,10 @@ void redraw_screen(void) blue_pixel, black_pixel, "top right"); GP_Text(win->context, &style, X/2, Y/2, GP_ALIGN_LEFT|GP_VALIGN_ABOVE, green_pixel, black_pixel, "top left"); + + GP_HLine(win->context, 0, X, Y/3, darkgray_pixel); + GP_Text(win->context, &style, X/2, Y/3, GP_ALIGN_CENTER|GP_VALIGN_BASELINE, + white_pixel, black_pixel, "x center y baseline"); }
static void event_loop(void) @@ -96,13 +109,29 @@ static void event_loop(void) font_flag++;
if (font) { - if (font_flag >= 3) + if (font_flag > 5) font_flag = 0; } else { - if (font_flag >= 2) + if (font_flag > 4) font_flag = 0; } break; + case GP_KEY_UP: + style.pixel_xspace++; + style.pixel_yspace++; + break; + case GP_KEY_DOWN: + style.pixel_xspace--; + style.pixel_yspace--; + break; + case GP_KEY_RIGHT: + style.pixel_xmul++; + style.pixel_ymul++; + break; + case GP_KEY_LEFT: + style.pixel_xmul--; + style.pixel_ymul--; + break; case GP_KEY_ESC: GP_BackendExit(win); exit(0); @@ -127,10 +156,12 @@ static void event_loop(void) void print_instructions(void) { printf("Use the following keys to control the test:n"); - printf(" Space ........ toggle proportional/nonproportional fontn"); + printf(" Space ........ toggle fontn"); printf(" X ............ mirror Xn"); printf(" Y ............ mirror Yn"); printf(" R ............ reverse X and Yn"); + printf(" UP/DOWN ...... increase/decrease X and Y spacen"); + printf(" RIGHT/LEFT ... increase/decrease X and Y muln"); }
int main(int argc, char *argv[]) @@ -138,7 +169,7 @@ int main(int argc, char *argv[]) const char *backend_opts = "X11";
if (argc > 1) - font = GP_FontFaceLoad(argv[1], 0, 16); + font = GP_FontFaceLoad(argv[1], 0, 20);
print_instructions();
@@ -155,6 +186,7 @@ int main(int argc, char *argv[]) blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, win->context); green_pixel = GP_ColorToContextPixel(GP_COL_GREEN, win->context); yellow_pixel = GP_ColorToContextPixel(GP_COL_YELLOW, win->context); + white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, win->context); darkgray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win->context);
redraw_screen(); diff --git a/libs/text/GP_Text.c b/libs/text/GP_Text.c index 07df462..14a28e7 100644 --- a/libs/text/GP_Text.c +++ b/libs/text/GP_Text.c @@ -19,13 +19,14 @@ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
#include "gfx/GP_Gfx.h" #include "core/GP_FnPerBpp.h" #include "core/GP_Debug.h" +#include "GP_TextMetric.h" #include "GP_Text.h"
GP_TextStyle GP_DefaultStyle = GP_DEFAULT_TEXT_STYLE; @@ -34,7 +35,7 @@ static int do_align(GP_Coord *topleft_x, GP_Coord *topleft_y, int align, GP_Coord x, GP_Coord y, const GP_TextStyle *style, GP_Size width) { - int height = GP_TextHeight(style); + GP_Size height = GP_TextHeight(style);
switch (align & 0x0f) { case GP_ALIGN_LEFT: @@ -59,7 +60,7 @@ static int do_align(GP_Coord *topleft_x, GP_Coord *topleft_y, int align, *topleft_y = y - height/2; break; case GP_VALIGN_BASELINE: - // *topleft_y = y - height + style->font->baseline; + *topleft_y = y - GP_TextAscent(style) + 1; break; case GP_VALIGN_BELOW: *topleft_y = y; @@ -86,6 +87,7 @@ void GP_Text(GP_Context *context, const GP_TextStyle *style, style = &GP_DefaultStyle;
GP_Coord topleft_x, topleft_y; + GP_Size w = GP_TextWidth(style, str);
GP_ASSERT(do_align(&topleft_x, &topleft_y, align, x, y, style, w) == 0, diff --git a/libs/text/GP_TextMetric.c b/libs/text/GP_TextMetric.c index 9c98ad7..d1a4ea6 100644 --- a/libs/text/GP_TextMetric.c +++ b/libs/text/GP_TextMetric.c @@ -123,9 +123,9 @@ static const GP_TextStyle *assert_style(const GP_TextStyle *style) * * There are two problems with text width it's start and it's end. * - * At the start the first letter may have bearing_x negative, making it - * overflow out of the bouding box and even in case it's possitive the returned - * size would be slightly bigger. This one is easy to fix. + * First letter may have bearing_x negative, making it overflow out of the + * bouding box and even in case it's possitive the returned size would be + * slightly bigger. This one is easy to fix. * * The end of the string is problematic too, some of the glyphs may have * advance smaller than sum of the bitmap width and bearing_x that way we would @@ -145,9 +145,8 @@ unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str) return 0;
/* special case, one letter */ - if (str[1] == '0') { + if (str[1] == '0') return glyph_width(style, str[0]); - }
/* first letter */ len = first_glyph_width(style, str[0]) + style->char_xspace;
http://repo.or.cz/w/gfxprim.git/commit/503fa7970aed181aa853406c3e04f6debaa7d...
commit 503fa7970aed181aa853406c3e04f6debaa7d5dd Author: Cyril Hrubis metan@ucw.cz Date: Wed Jan 15 21:45:54 2014 +0100
GP_Text: Fix rendering xspace handling and ymul.
The xspace should be multiplied by (width - 1) not by width in order to be consistent with GP_TextWidth().
Moreover the 8 BPP ymul was never working, fix it.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/text/GP_Text.gen.c.t b/libs/text/GP_Text.gen.c.t index 479cfb7..b15d33a 100644 --- a/libs/text/GP_Text.gen.c.t +++ b/libs/text/GP_Text.gen.c.t @@ -1,3 +1,28 @@ +/***************************************************************************** + * 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-2011 Jiri "BlueBear" Dluhos * + * jiri.bluebear.dluhos@gmail.com * + * * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + %% extends "base.c.t"
{% block descr %}Text rendering rutines{% endblock %} @@ -12,6 +37,11 @@
#define WIDTH_TO_1BPP_BPP(width) ((width)/8 + ((width)%8 != 0))
+static int get_width(GP_TextStyle *style, int width) +{ + return width * style->pixel_xmul + (width - 1) * style->pixel_xspace; +} + %% for pt in pixeltypes %% if not pt.is_unknown()
@@ -58,10 +88,10 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl y += style->pixel_ymul + style->pixel_yspace; }
- x += glyph->advance_x * x_mul + style->char_xspace; + x += get_width(style, glyph->advance_x) + style->char_xspace;
if (p == str) - x -= glyph->bearing_x * x_mul; + x -= get_width(style, glyph->bearing_x); } }
@@ -118,14 +148,14 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int
for (k = 0; k < style->pixel_ymul; k++) { %% if use_bg - GP_HLine(context, x_start, x_start + style->pixel_xmul - 1, cur_y, + GP_HLine(context, x_start, x_start + style->pixel_xmul - 1, cur_y + k, GP_MIX_PIXELS_{{ pt.name }}(fg, bg, gray)); %% else unsigned int l;
for (l = x_start; l < x_start + style->pixel_xmul; l++) { unsigned int px = l; - unsigned int py = cur_y; + unsigned int py = cur_y + k; //TODO: optimize this GP_TRANSFORM_POINT(context, px, py); GP_MixPixel_Raw_Clipped_{{ pt.name }}(context, px, py, fg, gray); @@ -137,10 +167,10 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int y += style->pixel_ymul + style->pixel_yspace; }
- x += glyph->advance_x * x_mul + style->char_xspace; + x += get_width(style, glyph->advance_x) + style->char_xspace;
if (p == str) - x -= glyph->bearing_x * x_mul; + x -= get_width(style, glyph->bearing_x); } %% endmacro
http://repo.or.cz/w/gfxprim.git/commit/9fa629c10033f45505f2348eae343f6eb4a2b...
commit 9fa629c10033f45505f2348eae343f6eb4a2b01b Author: Cyril Hrubis metan@ucw.cz Date: Wed Jan 15 21:17:18 2014 +0100
GP_Text.gen.c.t: Fix whitespaces.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/text/GP_Text.gen.c.t b/libs/text/GP_Text.gen.c.t index 8df9c36..479cfb7 100644 --- a/libs/text/GP_Text.gen.c.t +++ b/libs/text/GP_Text.gen.c.t @@ -28,7 +28,7 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl
if (glyph == NULL) glyph = GP_GetGlyphBitmap(style->font, ' '); - + int i, j, k;
unsigned int x_mul = style->pixel_xmul + style->pixel_xspace; @@ -41,15 +41,15 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl for (j = 0; j < glyph->height; j++) { for (i = 0; i < glyph->width; i++) { uint8_t bit = (glyph->bitmap[i/8 + j * bpp]) & (0x80>>(i%8)); - + unsigned int x_start = x + (i + glyph->bearing_x) * x_mul; - + if (p == str) x_start -= glyph->bearing_x * x_mul;
if (!bit) continue; - + for (k = 0; k < style->pixel_ymul; k++) GP_HLine(context, x_start, x_start + style->pixel_xmul - 1, y - (glyph->bearing_y - style->font->ascend) * y_mul + k, fg); @@ -57,9 +57,9 @@ static void text_draw_1BPP_{{ pt.name }}(GP_Context *context, GP_TextStyle *styl
y += style->pixel_ymul + style->pixel_yspace; } - + x += glyph->advance_x * x_mul + style->char_xspace; - + if (p == str) x -= glyph->bearing_x * x_mul; } @@ -94,7 +94,7 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int
if (glyph == NULL) glyph = GP_GetGlyphBitmap(style->font, ' '); - + int i, j, k;
unsigned int x_mul = style->pixel_xmul + style->pixel_xspace; @@ -105,12 +105,12 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int for (j = 0; j < glyph->height; j++) { for (i = 0; i < glyph->width; i++) { uint8_t gray = glyph->bitmap[i + j * glyph->width]; - + unsigned int x_start = x + (i + glyph->bearing_x) * x_mul; - + if (p == str) x_start -= glyph->bearing_x * x_mul; - + if (!gray) continue;
@@ -119,10 +119,10 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int for (k = 0; k < style->pixel_ymul; k++) { %% if use_bg GP_HLine(context, x_start, x_start + style->pixel_xmul - 1, cur_y, - GP_MIX_PIXELS_{{ pt.name }}(fg, bg, gray)); + GP_MIX_PIXELS_{{ pt.name }}(fg, bg, gray)); %% else unsigned int l; - + for (l = x_start; l < x_start + style->pixel_xmul; l++) { unsigned int px = l; unsigned int py = cur_y; @@ -138,7 +138,7 @@ static void text_draw_1BPP(GP_Context *context, GP_TextStyle *style, int x, int }
x += glyph->advance_x * x_mul + style->char_xspace; - + if (p == str) x -= glyph->bearing_x * x_mul; }
http://repo.or.cz/w/gfxprim.git/commit/1486958906f687d667ff7c47c2af60c4110bd...
commit 1486958906f687d667ff7c47c2af60c4110bd0c9 Author: Cyril Hrubis metan@ucw.cz Date: Wed Jan 15 19:47:21 2014 +0100
spiv: image action: Fix command buffer allocation.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/spiv/image_actions.c b/demos/spiv/image_actions.c index afeebe6..ad875d1 100644 --- a/demos/spiv/image_actions.c +++ b/demos/spiv/image_actions.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -204,6 +204,23 @@ static char *cmd = NULL; static size_t cmd_size; static size_t cmd_pos;
+#define CMD_CHUNK 1024 + +static int cmd_resize(void) +{ + char *new_cmd = realloc(cmd, cmd_size + CMD_CHUNK); + + if (!new_cmd) { + fprintf(stderr, "Failed to allocate command buffern"); + return 1; + } + + cmd = new_cmd; + cmd_size += CMD_CHUNK; + + return 0; +} + static int cmd_append(const char *str, size_t len) { if (len == 0) @@ -211,8 +228,8 @@ static int cmd_append(const char *str, size_t len)
/* Initial allocation size */ if (!cmd) { - cmd = malloc(1024); - cmd_size = 1024; + cmd = malloc(CMD_CHUNK); + cmd_size = CMD_CHUNK; }
if (!cmd) { @@ -220,13 +237,9 @@ static int cmd_append(const char *str, size_t len) return 1; }
- if (cmd_size - cmd_pos <= len) { - char *new_cmd = realloc(cmd, cmd_size + 1024); - - if (new_cmd == NULL) { - fprintf(stderr, "Failed to allocated command buffern"); + while (cmd_size - cmd_pos <= len) { + if (cmd_resize()) return 1; - } }
memcpy(cmd + cmd_pos, str, len); @@ -244,12 +257,8 @@ static int cmd_append_escape(const char *str, size_t len) len = strlen(str);
while ((ret = escape(str, len, cmd + cmd_pos, cmd_size - cmd_pos)) < 0) { - char *new_cmd = realloc(cmd, cmd_size + 1024); - - if (new_cmd == NULL) { - fprintf(stderr, "Failed to allocated command buffern"); + if (cmd_resize()) return 1; - } }
cmd_pos += ret;
http://repo.or.cz/w/gfxprim.git/commit/c7a22b3bf489a9a42e29e66af3890f250e4a4...
commit c7a22b3bf489a9a42e29e66af3890f250e4a42df Author: Cyril Hrubis metan@ucw.cz Date: Wed Jan 15 19:44:43 2014 +0100
spiv: help: Fix email address.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/spiv/spiv.1 b/demos/spiv/spiv.1 index 6599330..386706e 100644 --- a/demos/spiv/spiv.1 +++ b/demos/spiv/spiv.1 @@ -309,12 +309,12 @@ spiv -b 'X11:create_root' -t 10 images/ Bugs happen. If you find one, report it on the GFXprim mailing list at .I gfxprim@ucw.cz .SH AUTHORS -Spiv is developed by Cyril Hrubis chrubis@ucw.cz +Spiv is developed by Cyril Hrubis metan@ucw.cz .PP GFXprim was/is developed by: .PP .nf -Cyril Hrubis chrubis@ucw.cz +Cyril Hrubis metan@ucw.cz .nf Jiri "BlueBear" Dluhos jiri.bluebear.dluhos@gmail.com .nf diff --git a/demos/spiv/spiv_help.c b/demos/spiv/spiv_help.c index 0f9e222..3af2b03 100644 --- a/demos/spiv/spiv_help.c +++ b/demos/spiv/spiv_help.c @@ -181,9 +181,9 @@ static const char *man_tail = "Bugs happen. If you find one, report it on the GFXprim mailing list atn" ".I gfxprim@ucw.czn" ".SH AUTHORSn" - "Spiv is developed by Cyril Hrubis chrubis@ucw.czn" + "Spiv is developed by Cyril Hrubis metan@ucw.czn" ".PPnGFXprim was/is developed by:n" - ".PPn.nfnCyril Hrubis chrubis@ucw.czn" + ".PPn.nfnCyril Hrubis metan@ucw.czn" ".nfnJiri "BlueBear" Dluhos jiri.bluebear.dluhos@gmail.comn" ".nfnTomas Gavenciak gavento@ucw.czn";
-----------------------------------------------------------------------
Summary of changes: build/syms/Loaders_symbols.txt | 1 - demos/c_simple/Makefile | 3 +- demos/c_simple/byte_utils.c | 93 -------------- demos/c_simple/textaligntest.c | 48 ++++++-- demos/spiv/image_actions.c | 37 ++++-- demos/spiv/spiv.1 | 4 +- demos/spiv/spiv_help.c | 4 +- include/loaders/GP_ByteUtils.h | 33 ----- libs/gfx/GP_Polygon.c | 2 +- libs/loaders/GP_ByteUtils.c | 50 -------- libs/loaders/GP_GIF.c | 4 +- libs/loaders/GP_IO.c | 6 +- libs/text/GP_Text.c | 8 +- libs/text/GP_Text.gen.c.t | 68 +++++++--- libs/text/GP_TextMetric.c | 9 +- pylib/gfxprim/loaders/loaders.i | 63 ++++------ tests/loaders/{test_list.txt => .gitignore} | 14 +- tests/loaders/Loader.h | 103 ++++++++++++--- tests/loaders/Makefile | 4 +- tests/loaders/PBM.c | 24 ++++- include/loaders/GP_JP2.h => tests/loaders/PBM.h | 73 ++++++----- tests/loaders/PGM.c | 64 +++++++++- tests/loaders/PGM.h | 155 +++++++++++++++++++++++ tests/loaders/PNM.c | 147 +++++++++++++++++++++ tests/loaders/PPM.c | 32 ++++- include/loaders/GP_GIF.h => tests/loaders/PPM.h | 69 ++++++---- tests/loaders/test_list.txt | 1 + 27 files changed, 746 insertions(+), 373 deletions(-) delete mode 100644 demos/c_simple/byte_utils.c copy tests/loaders/{test_list.txt => .gitignore} (77%) copy include/loaders/GP_JP2.h => tests/loaders/PBM.h (70%) create mode 100644 tests/loaders/PGM.h create mode 100644 tests/loaders/PNM.c copy include/loaders/GP_GIF.h => tests/loaders/PPM.h (68%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.