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 8a2d9db9af54358efd9752da3299edb678abd8c3 (commit) via bdbe0d6c43da1d7db6e81916f8672ff1df583c40 (commit) via da87f51a835bae627bf9e1365fd504d04063b312 (commit) from 68bfb03b0e8eb136310c54be62f50802631fa428 (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/8a2d9db9af54358efd9752da3299edb678abd...
commit 8a2d9db9af54358efd9752da3299edb678abd8c3 Author: Cyril Hrubis metan@ucw.cz Date: Sun Jan 5 22:13:37 2014 +0100
loaders: ZIP: Make use of GP_ReadImage()
Now we can finally read any supported image format from a zip file.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_ZIP.c b/libs/loaders/GP_ZIP.c index d6cbdd1..c0b417a 100644 --- a/libs/loaders/GP_ZIP.c +++ b/libs/loaders/GP_ZIP.c @@ -38,8 +38,7 @@ #include "core/GP_Debug.h"
#include "loaders/GP_ByteUtils.h" -#include "loaders/GP_JPG.h" -#include "loaders/GP_PNG.h" +#include "loaders/GP_Loader.h"
#include "loaders/GP_ZIP.h"
@@ -181,8 +180,6 @@ static int deflate_out(void *out_desc, unsigned char *buf, unsigned len) struct deflate_outbuf *out = out_desc;
out->crc = crc32(out->crc, buf, len); - out->size += len; - memcpy(out->buf + out->size, buf, len); out->size += len;
@@ -381,29 +378,19 @@ static GP_Context *zip_next_file(struct zip_priv *priv,
GP_IOMark(priv->io, GP_IO_MARK);
- ret = GP_ReadJPG(priv->io, callback); - - if (!ret) { - GP_IOMark(priv->io, GP_IO_REWIND); - ret = GP_ReadPNG(priv->io, callback); - } + ret = GP_ReadImage(priv->io, callback);
GP_IOSeek(priv->io, priv->io->mark + header.comp_size, GP_IO_SEEK_SET);
goto out; break; case COMPRESS_DEFLATE: - if (read_deflate(priv->io, &header, &io)) { + if ((err = read_deflate(priv->io, &header, &io))) { err = errno; goto out; } - - ret = GP_ReadJPG(io, callback); - - if (!ret) { - GP_IORewind(io); - ret = GP_ReadPNG(io, callback); - } + GP_DEBUG(1, "Reading image"); + ret = GP_ReadImage(io, callback);
GP_IOClose(io); goto out;
http://repo.or.cz/w/gfxprim.git/commit/bdbe0d6c43da1d7db6e81916f8672ff1df583...
commit bdbe0d6c43da1d7db6e81916f8672ff1df583c40 Author: Cyril Hrubis metan@ucw.cz Date: Sun Jan 5 22:11:17 2014 +0100
loaders: Add GP_ReadImage()
Add a function that can read an image from an IO stream.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt index d2121fe..bac234f 100644 --- a/build/syms/Loaders_symbols.txt +++ b/build/syms/Loaders_symbols.txt @@ -62,6 +62,7 @@ GP_LoadTmpFile
GP_MatchSignature GP_MatchExtension +GP_ReadImage GP_LoadImage GP_SaveImage GP_LoadMetaData diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h index 925f358..3b5bc8f 100644 --- a/include/loaders/GP_Loader.h +++ b/include/loaders/GP_Loader.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2014 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -31,8 +31,17 @@
#include "core/GP_Context.h" #include "core/GP_ProgressCallback.h" +#include "loaders/GP_IO.h" +#include "loaders/GP_MetaData.h"
-#include "GP_MetaData.h" + +/* + * Reads an image from a IO stream. + * + * The image format is matched from the file signature (first few bytes of the + * IO stream). + */ +GP_Context *GP_ReadImage(GP_IO *io, GP_ProgressCallback *callback);
/* * Tries to load image accordingly to the file extension. @@ -64,14 +73,21 @@ int GP_SaveImage(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback);
/* - * You can register your own loader here. + * Describes image loader/saver. */ typedef struct GP_Loader { /* - * Loads an image. + * Reads an image from an IO stream. + * + * Returns newly allocated context cotaining the loaded image or in + * case of failure NULL and errno is set. + */ + GP_Context *(*Read)(GP_IO *io, GP_ProgressCallback *callback); + + /* + * Loads an image from a file. * - * Returns allocated and initialized bitmap on success, NULL on failure - * and errno must be set. + * TODO: Remove due to Read */ GP_Context *(*Load)(const char *src_path, GP_ProgressCallback *callback);
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c index 0abd6d5..aa793ba 100644 --- a/libs/loaders/GP_Loader.c +++ b/libs/loaders/GP_Loader.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,14 +32,15 @@ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> +#include <ctype.h>
#include "core/GP_Debug.h"
-#include "GP_Loaders.h" - -#include "GP_Loader.h" +#include "loaders/GP_Loaders.h" +#include "loaders/GP_Loader.h"
static GP_Loader psp_loader = { + .Read = GP_ReadPSP, .Load = GP_LoadPSP, .Save = NULL, .Match = GP_MatchPSP, @@ -49,6 +50,7 @@ static GP_Loader psp_loader = { };
static GP_Loader pbm_loader = { + .Read = GP_ReadPBM, .Load = GP_LoadPBM, .Save = GP_SavePBM, .Match = GP_MatchPBM, @@ -58,6 +60,7 @@ static GP_Loader pbm_loader = { };
static GP_Loader pgm_loader = { + .Read = GP_ReadPGM, .Load = GP_LoadPGM, .Save = GP_SavePGM, .Match = GP_MatchPGM, @@ -67,8 +70,9 @@ static GP_Loader pgm_loader = { };
static GP_Loader ppm_loader = { + .Read = GP_ReadPPM, .Load = GP_LoadPPM, - .Save = NULL, + .Save = GP_SavePPM, .Match = GP_MatchPPM, .fmt_name = "Netpbm portable Pixmap", .next = &pgm_loader, @@ -76,8 +80,9 @@ static GP_Loader ppm_loader = { };
static GP_Loader pnm_loader = { + .Read = GP_ReadPNM, .Load = GP_LoadPNM, - .Save = NULL, + .Save = GP_SavePNM, /* * Avoid double Match * This format is covered by PBM, PGM and PPM @@ -89,6 +94,7 @@ static GP_Loader pnm_loader = { };
static GP_Loader jp2_loader = { + .Read = GP_ReadJP2, .Load = GP_LoadJP2, .Save = NULL, .Match = GP_MatchJP2, @@ -98,6 +104,7 @@ static GP_Loader jp2_loader = { };
static GP_Loader bmp_loader = { + .Read = GP_ReadBMP, .Load = GP_LoadBMP, .Save = GP_SaveBMP, .Match = GP_MatchBMP, @@ -107,6 +114,7 @@ static GP_Loader bmp_loader = { };
static GP_Loader gif_loader = { + .Read = GP_ReadGIF, .Load = GP_LoadGIF, .Save = NULL, .Match = GP_MatchGIF, @@ -116,6 +124,7 @@ static GP_Loader gif_loader = { };
static GP_Loader tiff_loader = { + .Read = GP_ReadTIFF, .Load = GP_LoadTIFF, .Save = GP_SaveTIFF, .Match = GP_MatchTIFF, @@ -125,6 +134,7 @@ static GP_Loader tiff_loader = { };
static GP_Loader png_loader = { + .Read = GP_ReadPNG, .Load = GP_LoadPNG, .Save = GP_SavePNG, .Match = GP_MatchPNG, @@ -134,6 +144,7 @@ static GP_Loader png_loader = { };
static GP_Loader jpeg_loader = { + .Read = GP_ReadJPG, .Load = GP_LoadJPG, .Save = GP_SaveJPG, .Match = GP_MatchJPG, @@ -183,6 +194,7 @@ void GP_ListLoaders(void)
for (i = loaders; i != NULL; i = i->next) { printf("Format: %sn", i->fmt_name); + printf("Read:t%sn", i->Read ? "Yes" : "No"); printf("Load:t%sn", i->Load ? "Yes" : "No"); printf("Save:t%sn", i->Save ? "Yes" : "No"); printf("Match:t%sn", i->Match ? "Yes" : "No"); @@ -279,6 +291,52 @@ err0: return NULL; }
+GP_Context *GP_ReadImage(GP_IO *io, GP_ProgressCallback *callback) +{ + char buf[32]; + off_t start; + const GP_Loader *loader; + + start = GP_IOTell(io); + if (start == (off_t)-1) { + GP_DEBUG(1, "Failed to get IO stream offset: %s", + strerror(errno)); + return NULL; + } + + if (GP_IOFill(io, buf, sizeof(buf))) { + GP_DEBUG(1, "Failed to read first 32 bytes: %s", + strerror(errno)); + return NULL; + } + + if (GP_IOSeek(io, start, GP_IO_SEEK_SET) != start) { + GP_DEBUG(1, "Failed to seek at the start of the stream: %s", + strerror(errno)); + return NULL; + } + + loader = GP_MatchSignature(buf); + + if (!loader) { + GP_DEBUG(1, "Failed to find a loader by signature for" + "(%x (%c) %x (%c)...)", + buf[0], isprint(buf[0]) ? buf[0] : ' ', + buf[1], isprint(buf[1]) ? buf[1] : ' '); + errno = ENOSYS; + return NULL; + } + + if (!loader->Read) { + GP_DEBUG(1, "Loader for '%s' does not support reading", + loader->fmt_name); + errno = ENOSYS; + return NULL; + } + + return loader->Read(io, callback); +} + GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback) { int err;
http://repo.or.cz/w/gfxprim.git/commit/da87f51a835bae627bf9e1365fd504d04063b...
commit da87f51a835bae627bf9e1365fd504d04063b312 Author: Cyril Hrubis metan@ucw.cz Date: Sun Jan 5 21:29:02 2014 +0100
core: Make GP_DebugPrint() preserve errno.
Now all variants of GP_DebugPrint() (i.e. GP_DEBUG(), GP_WARN(), ...) preserves errno which simplifies common pattern of:
if (failure) { err = errno; GP_DEBUG(1, "Foo has failed"); errno = err; return 1; }
to much clearer:
if (failure) { GP_DEBUG(1, "Foo has failed"); return 1; }
This commit also adds a test.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/debug.txt b/doc/debug.txt index 83cf91d..7424064 100644 --- a/doc/debug.txt +++ b/doc/debug.txt @@ -69,6 +69,8 @@ void GP_DebugPrint(int level, const char *file, const char *function, int line, Printf-like macros used to print debug messages. All of them calls the 'GP_DebugPrint()' function with slightly different parameters.
+NOTE: 'GP_DebugPrint()' function preserves 'errno'. + [source,c] ------------------------------------------------------------------------------- enum GP_DebugType { diff --git a/libs/core/GP_Debug.c b/libs/core/GP_Debug.c index 9605507..c53ad51 100644 --- a/libs/core/GP_Debug.c +++ b/libs/core/GP_Debug.c @@ -16,11 +16,12 @@ * 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 <stdarg.h> +#include <errno.h>
#include "core/GP_Version.h" #include "core/GP_Debug.h" @@ -49,7 +50,9 @@ void GP_SetDebugHandler(void (*handler)(const struct GP_DebugMsg *msg)) void GP_DebugPrint(int level, const char *file, const char *function, int line, const char *fmt, ...) { - int i; + int i, err; + + err = errno;
if (!env_used) { char *level = getenv("GP_DEBUG"); @@ -72,7 +75,7 @@ void GP_DebugPrint(int level, const char *file, const char *function, int line, }
if (level > (int)debug_level) - return; + goto end;
/* If handler is set, fill struct msg and call it */ if (debug_handler) { @@ -93,7 +96,7 @@ void GP_DebugPrint(int level, const char *file, const char *function, int line,
debug_handler(&msg);
- return; + goto end; }
for (i = 1; i < level; i++) @@ -124,4 +127,6 @@ void GP_DebugPrint(int level, const char *file, const char *function, int line, va_end(va);
fputc('n', stderr); +end: + errno = err; } diff --git a/tests/core/Debug.c b/tests/core/Debug.c new file mode 100644 index 0000000..a32e7fd --- /dev/null +++ b/tests/core/Debug.c @@ -0,0 +1,77 @@ +/***************************************************************************** + * 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 * + * * + *****************************************************************************/ + +/* + + Test that GP_DEBUG() preserves errno. + + */ +#include <errno.h> + +#include <core/GP_Debug.h> + +#include "tst_test.h" + +static int handler_called; + +static void debug_handler(const struct GP_DebugMsg *msg) +{ + (void)msg; + handler_called = 1; + errno = 0; + tst_msg("Errno changed in debug handler"); +} + +/* + * Check that GP_DEBUG() preserves errno. + */ +static int DEBUG_preserves_errno(void) +{ + GP_SetDebugHandler(debug_handler); + GP_SetDebugLevel(1); + + handler_called = 0; + errno = 1; + + GP_DEBUG(1, "Debug message"); + + if (!handler_called) { + tst_msg("Debug handler wasn't called"); + return TST_FAILED; + } + + if (errno != 1) { + tst_msg("Errno not preserved"); + return TST_FAILED; + } + + return TST_SUCCESS; +} + +const struct tst_suite tst_suite = { + .suite_name = "Debug", + .tests = { + {.name = "Debug messages preserves errno", + .tst_fn = DEBUG_preserves_errno}, + {.name = NULL}, + } +}; diff --git a/tests/core/Makefile b/tests/core/Makefile index 9ede6dc..737fc17 100644 --- a/tests/core/Makefile +++ b/tests/core/Makefile @@ -2,13 +2,13 @@ TOPDIR=../..
include $(TOPDIR)/pre.mk
-CSOURCES=Context.c Pixel.c BlitClipped.c +CSOURCES=Context.c Pixel.c BlitClipped.c Debug.c
GENSOURCES+=WritePixel.gen.c GetPutPixel.gen.c Convert.gen.c BlitConv.gen.c Convert_Scale.gen.c GetSetBits.gen.c
APPS=WritePixel.gen Pixel Context GetPutPixel.gen Convert.gen BlitConv.gen - Convert_Scale.gen GetSetBits.gen BlitClipped + Convert_Scale.gen GetSetBits.gen BlitClipped Debug
include ../tests.mk
diff --git a/tests/core/test_list.txt b/tests/core/test_list.txt index c728b8b..1ff15be 100644 --- a/tests/core/test_list.txt +++ b/tests/core/test_list.txt @@ -8,3 +8,4 @@ Convert.gen Convert_Scale.gen BlitConv.gen BlitClipped +Debug
-----------------------------------------------------------------------
Summary of changes: build/syms/Loaders_symbols.txt | 1 + doc/debug.txt | 2 + include/loaders/GP_Loader.h | 28 ++++++++++--- libs/core/GP_Debug.c | 13 ++++-- libs/loaders/GP_Loader.c | 70 ++++++++++++++++++++++++++++++--- libs/loaders/GP_ZIP.c | 23 ++-------- tests/{loaders/GIF.c => core/Debug.c} | 61 ++++++++++++++++------------ tests/core/Makefile | 4 +- tests/core/test_list.txt | 1 + 9 files changed, 141 insertions(+), 62 deletions(-) copy tests/{loaders/GIF.c => core/Debug.c} (71%)
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.