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 2dacc1816fc4a182ba2054ec12b2c2b7de223565 (commit) via ce4f03056c460eee0a3ff777c1a05fe1f927b268 (commit) via e388310e407c77e1510e5ffa9d7b5653273c5dbe (commit) from 1969d4407b36047206e4e846594570086f4d5dde (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/2dacc1816fc4a182ba2054ec12b2c2b7de223...
commit 2dacc1816fc4a182ba2054ec12b2c2b7de223565 Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 18 20:11:36 2013 +0200
loaders: PNM: Implemented GP_SavePPM, GP_SavePNM
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/include/loaders/GP_PNM.h b/include/loaders/GP_PNM.h index 917a10d..150ff21 100644 --- a/include/loaders/GP_PNM.h +++ b/include/loaders/GP_PNM.h @@ -48,7 +48,7 @@ int GP_SavePGM(const GP_Context *src, const char *dst_path, */ GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback);
-int GP_SavePPM(GP_Context *src, const char *dst_path, +int GP_SavePPM(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback);
/* diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c index b08e783..dc4c29c 100644 --- a/libs/loaders/GP_PNM.c +++ b/libs/loaders/GP_PNM.c @@ -770,7 +770,7 @@ int GP_SavePGM(const GP_Context *src, const char *dst_path, }
if (fprintf(f, "P2n%u %un%un", - (unsigned int) src->w, (unsigned int) src->h, depth) < 3) + (unsigned int) src->w, (unsigned int) src->h, depth) < 0) goto err1;
if ((err = save_ascii(f, src, callback))) @@ -873,9 +873,83 @@ static int write_binary_ppm(FILE *f, GP_Context *src) return 0; }
-int GP_SavePPM(GP_Context *src, const char *dst_path, +static int save_ascii_rgb888(FILE *f, const GP_Context *ctx, + GP_ProgressCallback *cb) +{ + uint32_t x, y; + int ret; + + for (y = 0; y < ctx->h; y++) { + for (x = 0; x < ctx->w; x++) { + GP_Pixel pix = GP_GetPixel_Raw_24BPP(ctx, x, y); + + ret = fprintf(f, "%u %u %u ", + GP_Pixel_GET_R_RGB888(pix), + GP_Pixel_GET_G_RGB888(pix), + GP_Pixel_GET_B_RGB888(pix)); + + if (ret < 0) + return errno; + } + + if (GP_ProgressCallbackReport(cb, y, ctx->h, ctx->w)) { + GP_DEBUG(1, "Operation aborted"); + return ECANCELED; + } + + if (fprintf(f, "n") < 0) + return errno; + } + + GP_ProgressCallbackDone(cb); + return 0; +} + +int GP_SavePPM(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { + FILE *f; + int err = EIO; + + GP_DEBUG(1, "Saving context %ux%u %s to '%s'", + src->w, src->h, GP_PixelTypeName(src->pixel_type), dst_path); + + if (src->pixel_type != GP_PIXEL_RGB888) { + GP_DEBUG(1, "Invalid pixel type '%s'", + GP_PixelTypeName(src->pixel_type)); + errno = EINVAL; + return 1; + } + + 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, "P3n%u %un255n", + (unsigned int) src->w, (unsigned int) src->h) < 0) + goto err1; + + if ((err = save_ascii_rgb888(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 0; +err1: + fclose(f); +err0: + errno = err; + return 1; errno = ENOSYS; return -1; } @@ -920,6 +994,16 @@ err0: int GP_SavePNM(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback) { - errno = ENOSYS; - return -1; + switch (src->pixel_type) { + case GP_PIXEL_G1: + case GP_PIXEL_G2: + case GP_PIXEL_G4: + case GP_PIXEL_G8: + return GP_SavePGM(src, dst_path, callback); + case GP_PIXEL_RGB888: + return GP_SavePPM(src, dst_path, callback); + default: + errno = EINVAL; + return 1; + } }
http://repo.or.cz/w/gfxprim.git/commit/ce4f03056c460eee0a3ff777c1a05fe1f927b...
commit ce4f03056c460eee0a3ff777c1a05fe1f927b268 Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 18 19:38:36 2013 +0200
loaders: PNM: Fix a few issues found by tests.
* The fprintf() returns number of bytes not number of converted formatting chars, ouch.
* Fix errno propagation from read_header()
* The PBM has inverted the black and white but the PGM is normal again.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c index 1104f8f..b08e783 100644 --- a/libs/loaders/GP_PNM.c +++ b/libs/loaders/GP_PNM.c @@ -289,7 +289,10 @@ static int get_ascii_int(FILE *f, int *val) } }
-static int load_ascii_g1(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb) +/* + * The PBM has the values inverted + */ +static int load_ascii_g1_inv(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb) { uint32_t x, y; int val, err; @@ -313,6 +316,35 @@ static int load_ascii_g1(FILE *f, GP_Context *ctx, GP_ProgressCallback *cb) return 0; }
+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; + + if (val > 1) { + GP_WARN("Value too large for 2BPP (%i)", val); + val = 1; + } + + 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; @@ -484,7 +516,7 @@ static int save_ascii(FILE *f, const GP_Context *ctx, GP_ProgressCallback *cb) 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) { + if (fprintf(f, "%i ", GP_GetPixel_Raw(ctx, x, y)) < 0) { err = errno; GP_DEBUG(1, "Failed to write data"); return err; @@ -514,6 +546,7 @@ static FILE *read_header(const char *src_path, struct pnm_header *header)
if ((err = load_header(f, header))) { fclose(f); + errno = err; return NULL; }
@@ -539,7 +572,7 @@ static GP_Context *read_bitmap(FILE *f, struct pnm_header *header, int flag, goto err1; }
- if ((err = load_ascii_g1(f, ret, callback))) + if ((err = load_ascii_g1_inv(f, ret, callback))) goto err1;
if (flag) @@ -574,7 +607,12 @@ int GP_SavePBM(const GP_Context *src, const char *dst_path, { FILE *f;
+ GP_DEBUG(1, "Saving context %ux%u %s to '%s'", + src->w, src->h, GP_PixelTypeName(src->pixel_type), dst_path); + if (src->pixel_type != GP_PIXEL_G1) { + GP_DEBUG(1, "Invalid pixel type '%s'", + GP_PixelTypeName(src->pixel_type)); errno = EINVAL; return 1; } @@ -584,8 +622,8 @@ int GP_SavePBM(const GP_Context *src, const char *dst_path, if (f == NULL) return 1;
- if (fprintf(f, "P1n%u %u", - (unsigned int) src->w, (unsigned int) src->h) < 2) + if (fprintf(f, "P1n%u %un", + (unsigned int) src->w, (unsigned int) src->h) < 0) goto err;
if (save_ascii(f, src, callback)) @@ -712,6 +750,9 @@ int GP_SavePGM(const GP_Context *src, const char *dst_path, int depth; int err = EIO;
+ GP_DEBUG(1, "Saving context %ux%u %s to '%s'", + src->w, src->h, GP_PixelTypeName(src->pixel_type), dst_path); + if ((depth = pixel_to_depth(src->pixel_type)) == -1) { GP_DEBUG(1, "Invalid pixel type '%s'", GP_PixelTypeName(src->pixel_type)); @@ -728,7 +769,7 @@ int GP_SavePGM(const GP_Context *src, const char *dst_path, goto err0; }
- if (fprintf(f, "P2n%u %un%un# Generated by gfxprimn", + if (fprintf(f, "P2n%u %un%un", (unsigned int) src->w, (unsigned int) src->h, depth) < 3) goto err1;
http://repo.or.cz/w/gfxprim.git/commit/e388310e407c77e1510e5ffa9d7b5653273c5...
commit e388310e407c77e1510e5ffa9d7b5653273c5dbe Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 18 18:04:45 2013 +0200
tests: loaders: PBM, PGM, PPM, more tests.
Add more tests for the PNM image loaders.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/loaders/PBM.c b/tests/loaders/Loader.h similarity index 56% copy from tests/loaders/PBM.c copy to tests/loaders/Loader.h index 2c76792..d8a916d 100644 --- a/tests/loaders/PBM.c +++ b/tests/loaders/Loader.h @@ -20,16 +20,6 @@ * * *****************************************************************************/
-#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; @@ -37,14 +27,14 @@ struct testcase { char *path; };
-static int test_load_PBM(struct testcase *test) +static int test_load(struct testcase *test) { GP_Context *img; unsigned int x, y, err = 0;
errno = 0;
- img = GP_LoadPBM(test->path, NULL); + img = LOAD(test->path, NULL);
if (img == NULL) { switch (errno) { @@ -86,13 +76,13 @@ static int test_load_PBM(struct testcase *test) return TST_SUCCESS; }
-static int test_load_fail_PBM(const char *path) +static int test_load_fail(const char *path) { GP_Context *img;
errno = 0;
- img = GP_LoadPBM(path, NULL); + img = LOAD(path, NULL);
if (img != NULL) { tst_msg("Succeeded unexpectedly"); @@ -104,93 +94,86 @@ static int test_load_fail_PBM(const char *path) case ENOSYS: tst_msg("Not Implemented"); return TST_SKIPPED; + case 0: + tst_msg("Load failed and errno == 0"); + return TST_FAILED; 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", +/* + * Saves and loads image using the SAVE and LOAD functions + * and compares the results. + */ +struct testcase_save_load { + GP_PixelType pixel_type; + GP_Size w, h; };
-struct testcase black_1x1_2 = { - .w = 1, - .h = 1, - .pix = 0, - .path = "black_1x1_2.pbm", -}; +static int test_save_load(struct testcase_save_load *test) +{ + GP_Context *img, *img2;
-struct testcase black_1x1_3 = { - .w = 1, - .h = 1, - .pix = 0, - .path = "black_1x1_3.pbm", -}; + img = GP_ContextAlloc(test->w, test->h, test->pixel_type);
-struct testcase black_1x1_4 = { - .w = 1, - .h = 1, - .pix = 0, - .path = "black_1x1_4.pbm", -}; + if (img == NULL) { + tst_msg("Failed to allocate context %ux%u %s", + test->w, test->h, GP_PixelTypeName(test->pixel_type)); + return TST_FAILED; + }
-struct testcase white_1x1 = { - .w = 1, - .h = 1, - .pix = 1, - .path = "white_1x1.pbm", -}; + errno = 0; + + if (SAVE(img, "testfile", NULL)) { + if (errno == ENOSYS) { + tst_msg("Not implemented"); + return TST_SKIPPED; + }
-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}, + tst_msg("Failed to save context %ux%u %s: %s", + test->w, test->h, GP_PixelTypeName(test->pixel_type), + strerror(errno)); + return TST_FAILED; } -}; + + + img2 = LOAD("testfile", NULL); + + if (img2 == NULL) { + switch (errno) { + case ENOSYS: + tst_msg("Not Implemented"); + GP_ContextFree(img); + return TST_SKIPPED; + default: + tst_msg("Got %s", strerror(errno)); + GP_ContextFree(img); + return TST_FAILED; + } + } + + if (img->w != img2->w || img->h != img2->h) { + tst_msg("Source size %ux%u and loaded size %ux%u differs", + img->w, img->h, img2->w, img2->h); + GP_ContextFree(img); + GP_ContextFree(img2); + return TST_FAILED; + } + + if (img->pixel_type != img2->pixel_type) { + GP_ContextFree(img); + GP_ContextFree(img2); + tst_msg("Source pixel type %s and loaded type %s differs", + GP_PixelTypeName(img->pixel_type), + GP_PixelTypeName(img2->pixel_type)); + } + + GP_ContextFree(img); + GP_ContextFree(img2); + + //TODO: Check pixels + + return TST_SUCCESS; +} diff --git a/tests/loaders/Makefile b/tests/loaders/Makefile index 304e956..1d8cc2e 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 PBM +APPS=loaders_suite PNG PBM PGM PPM
include ../tests.mk
diff --git a/tests/loaders/PBM.c b/tests/loaders/PBM.c index 2c76792..290d5a9 100644 --- a/tests/loaders/PBM.c +++ b/tests/loaders/PBM.c @@ -30,85 +30,9 @@
#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; - } -} +#define LOAD GP_LoadPBM +#define SAVE GP_SavePBM +#include "Loader.h"
struct testcase black_1x1_1 = { .w = 1, @@ -145,51 +69,68 @@ struct testcase white_1x1 = { .path = "white_1x1.pbm", };
+struct testcase_save_load save_load = { + .w = 100, + .h = 100, + .pixel_type = GP_PIXEL_G1, +}; + const struct tst_suite tst_suite = { .suite_name = "PBM", .tests = { {.name = "PBM Load 1x1 (black)", - .tst_fn = test_load_PBM, + .tst_fn = test_load, //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, + .tst_fn = test_load, .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, + .tst_fn = test_load, .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, + .tst_fn = test_load, .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, + .tst_fn = test_load, .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, + .tst_fn = test_load_fail, .res_path = "data/pbm/corrupt/short.pbm", .data = "short.pbm", .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + {.name = "PBM Load wrong header", + .tst_fn = test_load_fail, + .res_path = "data/pbm/corrupt/wrong_header.pbm", + .data = "wrong_header.pbm", + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + {.name = "PBM Load empty", - .tst_fn = test_load_fail_PBM, + .tst_fn = test_load_fail, .res_path = "data/pbm/corrupt/empty.pbm", .data = "empty.pbm", .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PBM Save Load", + .tst_fn = test_save_load, + .data = &save_load, + .flags = TST_TMPDIR | TST_CHECK_MALLOC},
{.name = NULL}, } diff --git a/tests/loaders/PGM.c b/tests/loaders/PGM.c new file mode 100644 index 0000000..f914a8e --- /dev/null +++ b/tests/loaders/PGM.c @@ -0,0 +1,150 @@ +/***************************************************************************** + * 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 * + * * + *****************************************************************************/ + +#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_LoadPGM +#define SAVE GP_SavePGM +#include "Loader.h" + +struct testcase black_1x1_1bpp = { + .w = 1, + .h = 1, + .pix = 0, + .path = "black_1x1_1bpp.pgm", +}; + +struct testcase black_1x1_2bpp = { + .w = 1, + .h = 1, + .pix = 0, + .path = "black_1x1_2bpp.pgm", +}; + +struct testcase black_1x1_4bpp = { + .w = 1, + .h = 1, + .pix = 0, + .path = "black_1x1_4bpp.pgm", +}; + +struct testcase black_1x1_8bpp = { + .w = 1, + .h = 1, + .pix = 0, + .path = "black_1x1_8bpp.pgm", +}; + +struct testcase_save_load save_load_1bpp = { + .w = 100, + .h = 100, + .pixel_type = GP_PIXEL_G1, +}; + +struct testcase_save_load save_load_2bpp = { + .w = 100, + .h = 100, + .pixel_type = GP_PIXEL_G2, +}; + +struct testcase_save_load save_load_4bpp = { + .w = 100, + .h = 100, + .pixel_type = GP_PIXEL_G4, +}; + +struct testcase_save_load save_load_8bpp = { + .w = 100, + .h = 100, + .pixel_type = GP_PIXEL_G8, +}; + +const struct tst_suite tst_suite = { + .suite_name = "PGM", + .tests = { + {.name = "PGM Load 1x1 1bpp (black)", + .tst_fn = test_load, + .res_path = "data/pgm/valid/black_1x1_1bpp.pgm", + .data = &black_1x1_1bpp, + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Load 1x1 2bpp (black)", + .tst_fn = test_load, + .res_path = "data/pgm/valid/black_1x1_2bpp.pgm", + .data = &black_1x1_2bpp, + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Load 1x1 4bpp (black)", + .tst_fn = test_load, + .res_path = "data/pgm/valid/black_1x1_4bpp.pgm", + .data = &black_1x1_4bpp, + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Load 1x1 8bpp (black)", + .tst_fn = test_load, + .res_path = "data/pgm/valid/black_1x1_8bpp.pgm", + .data = &black_1x1_8bpp, + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Save Load 1bpp", + .tst_fn = test_save_load, + .data = &save_load_1bpp, + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Save Load 2bpp", + .tst_fn = test_save_load, + .data = &save_load_2bpp, + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Save Load 4bpp", + .tst_fn = test_save_load, + .data = &save_load_4bpp, + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Save Load 8bpp", + .tst_fn = test_save_load, + .data = &save_load_8bpp, + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Load wrong header", + .tst_fn = test_load_fail, + .res_path = "data/pgm/corrupt/wrong_header.pgm", + .data = "wrong_header.pgm", + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = "PGM Load incomplete", + .tst_fn = test_load_fail, + .res_path = "data/pgm/corrupt/incomplete.pgm", + .data = "incomplete.pgm", + .flags = TST_TMPDIR | TST_CHECK_MALLOC}, + + {.name = NULL}, + } +}; diff --git a/tests/loaders/PPM.c b/tests/loaders/PPM.c new file mode 100644 index 0000000..b4790cf --- /dev/null +++ b/tests/loaders/PPM.c @@ -0,0 +1,78 @@ +/***************************************************************************** + * 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 * + * * + *****************************************************************************/ + +#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 = { + .w = 1, + .h = 1, + .pix = 0, + .path = "black_1x1.ppm", +}; + +struct testcase_save_load save_load = { + .w = 100, + .h = 100, + .pixel_type = GP_PIXEL_RGB888, +}; + +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}, + + {.name = NULL}, + } +}; diff --git a/tests/loaders/data/pbm/corrupt/wrong_header.pbm b/tests/loaders/data/pbm/corrupt/wrong_header.pbm new file mode 100644 index 0000000..19a875f --- /dev/null +++ b/tests/loaders/data/pbm/corrupt/wrong_header.pbm @@ -0,0 +1,2 @@ +P1 +10 A diff --git a/tests/loaders/data/pgm/corrupt/incomplete.pgm b/tests/loaders/data/pgm/corrupt/incomplete.pgm new file mode 100644 index 0000000..03fa100 --- /dev/null +++ b/tests/loaders/data/pgm/corrupt/incomplete.pgm @@ -0,0 +1,4 @@ +P2 +1 3 +15 +0 0 diff --git a/tests/loaders/data/pgm/corrupt/wrong_header.pgm b/tests/loaders/data/pgm/corrupt/wrong_header.pgm new file mode 100644 index 0000000..5dab55e --- /dev/null +++ b/tests/loaders/data/pgm/corrupt/wrong_header.pgm @@ -0,0 +1,2 @@ +P2 +1 3 diff --git a/tests/loaders/data/pgm/valid/black_1x1_1bpp.pgm b/tests/loaders/data/pgm/valid/black_1x1_1bpp.pgm new file mode 100644 index 0000000..ff6cb6d --- /dev/null +++ b/tests/loaders/data/pgm/valid/black_1x1_1bpp.pgm @@ -0,0 +1,4 @@ +P2 +1 1 +1 +0 diff --git a/tests/loaders/data/pgm/valid/black_1x1_2bpp.pgm b/tests/loaders/data/pgm/valid/black_1x1_2bpp.pgm new file mode 100644 index 0000000..41adfe6 --- /dev/null +++ b/tests/loaders/data/pgm/valid/black_1x1_2bpp.pgm @@ -0,0 +1,4 @@ +P2 +1 1 +3 +0 diff --git a/tests/loaders/data/pgm/valid/black_1x1_4bpp.pgm b/tests/loaders/data/pgm/valid/black_1x1_4bpp.pgm new file mode 100644 index 0000000..6fceab5 --- /dev/null +++ b/tests/loaders/data/pgm/valid/black_1x1_4bpp.pgm @@ -0,0 +1,4 @@ +P2 +1 1 +15 +0 diff --git a/tests/loaders/data/pgm/valid/black_1x1_8bpp.pgm b/tests/loaders/data/pgm/valid/black_1x1_8bpp.pgm new file mode 100644 index 0000000..d999143 --- /dev/null +++ b/tests/loaders/data/pgm/valid/black_1x1_8bpp.pgm @@ -0,0 +1,4 @@ +P2 +1 1 +255 +0 diff --git a/tests/loaders/data/ppm/corrupt/incomplete.ppm b/tests/loaders/data/ppm/corrupt/incomplete.ppm new file mode 100644 index 0000000..0903994 --- /dev/null +++ b/tests/loaders/data/ppm/corrupt/incomplete.ppm @@ -0,0 +1,4 @@ +P3 +3 2 +255 +0 diff --git a/tests/loaders/data/ppm/corrupt/wrong_header.ppm b/tests/loaders/data/ppm/corrupt/wrong_header.ppm new file mode 100644 index 0000000..e55f93a --- /dev/null +++ b/tests/loaders/data/ppm/corrupt/wrong_header.ppm @@ -0,0 +1,3 @@ +P3 +2 3 +# diff --git a/tests/loaders/data/ppm/valid/black_1x1.ppm b/tests/loaders/data/ppm/valid/black_1x1.ppm new file mode 100644 index 0000000..ca9e908 --- /dev/null +++ b/tests/loaders/data/ppm/valid/black_1x1.ppm @@ -0,0 +1,4 @@ +P3 +1 1 +255 +0 0 0 diff --git a/tests/loaders/test_list.txt b/tests/loaders/test_list.txt index 8a20a1d..1593ff6 100644 --- a/tests/loaders/test_list.txt +++ b/tests/loaders/test_list.txt @@ -2,3 +2,5 @@ loaders_suite PNG PBM +PGM +PPM
-----------------------------------------------------------------------
Summary of changes: include/loaders/GP_PNM.h | 2 +- libs/loaders/GP_PNM.c | 145 ++++++++++++++++-- tests/loaders/{PBM.c => Loader.h} | 165 +++++++++----------- tests/loaders/Makefile | 2 +- tests/loaders/PBM.c | 113 ++++---------- tests/loaders/PGM.c | 150 ++++++++++++++++++ tests/{core/Pixel.c => loaders/PPM.c} | 80 +++++----- tests/loaders/data/pbm/corrupt/wrong_header.pbm | 2 + tests/loaders/data/pgm/corrupt/incomplete.pgm | 4 + tests/loaders/data/pgm/corrupt/wrong_header.pgm | 2 + .../valid/black_1x1_1bpp.pgm} | 3 +- .../white_1x1.pbm => pgm/valid/black_1x1_2bpp.pgm} | 3 +- .../white_1x1.pbm => pgm/valid/black_1x1_4bpp.pgm} | 3 +- tests/loaders/data/pgm/valid/black_1x1_8bpp.pgm | 4 + tests/loaders/data/ppm/corrupt/incomplete.ppm | 4 + tests/loaders/data/ppm/corrupt/wrong_header.ppm | 3 + tests/loaders/data/ppm/valid/black_1x1.ppm | 4 + tests/loaders/test_list.txt | 2 + 18 files changed, 462 insertions(+), 229 deletions(-) copy tests/loaders/{PBM.c => Loader.h} (56%) create mode 100644 tests/loaders/PGM.c copy tests/{core/Pixel.c => loaders/PPM.c} (62%) create mode 100644 tests/loaders/data/pbm/corrupt/wrong_header.pbm create mode 100644 tests/loaders/data/pgm/corrupt/incomplete.pgm create mode 100644 tests/loaders/data/pgm/corrupt/wrong_header.pgm copy tests/loaders/data/{pbm/valid/black_1x1_1.pbm => pgm/valid/black_1x1_1bpp.pgm} (54%) copy tests/loaders/data/{pbm/valid/white_1x1.pbm => pgm/valid/black_1x1_2bpp.pgm} (54%) copy tests/loaders/data/{pbm/valid/white_1x1.pbm => pgm/valid/black_1x1_4bpp.pgm} (50%) create mode 100644 tests/loaders/data/pgm/valid/black_1x1_8bpp.pgm create mode 100644 tests/loaders/data/ppm/corrupt/incomplete.ppm create mode 100644 tests/loaders/data/ppm/corrupt/wrong_header.ppm create mode 100644 tests/loaders/data/ppm/valid/black_1x1.ppm
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.