Gfxprim
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
June 2014
- 1 participants
- 11 discussions
25 Jun '14
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 334730ba119db655383ca862373271fb11fd9d87 (commit)
via ec22f36da6e391b7eeb08d02f860ae12371ef1a4 (commit)
via 273279db3fb62bc3757a213b231a88b8e107383b (commit)
from 25054131fde91ee366211edb541a0628ffa4b2e3 (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/334730ba119db655383ca862373271fb11fd…
commit 334730ba119db655383ca862373271fb11fd9d87
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 25 21:43:17 2014 +0200
loaders: IO; Fix IOMem and IOSubIO seeks
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_IO.c b/libs/loaders/GP_IO.c
index c8dd9038..ae29eb93 100644
--- a/libs/loaders/GP_IO.c
+++ b/libs/loaders/GP_IO.c
@@ -65,7 +65,7 @@ static off_t file_seek(GP_IO *self, off_t off, enum GP_IOWhence whence)
default:
GP_WARN("Invalid whence");
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
return lseek(file_io->fd, off, whence);
@@ -173,31 +173,32 @@ static off_t mem_seek(GP_IO *io, off_t off, enum GP_IOWhence whence)
switch (whence) {
case GP_IO_SEEK_CUR:
- if (off + mem_io->pos > mem_io->size) {
+ if (-off > (off_t)mem_io->pos ||
+ off + mem_io->pos > mem_io->size) {
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
mem_io->pos += off;
break;
case GP_IO_SEEK_SET:
- if (off < 0 || off > (off_t)mem_io->pos) {
+ if (off < 0 || off > (off_t)mem_io->size) {
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
mem_io->pos = off;
break;
case GP_IO_SEEK_END:
- if (off) {
+ if (off > 0 || off + (off_t)mem_io->size < 0) {
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
- mem_io->pos = mem_io->size;
+ mem_io->pos = mem_io->size + off;
break;
default:
GP_WARN("Invalid whence");
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
return mem_io->pos;
@@ -295,7 +296,7 @@ static off_t sub_seek(GP_IO *io, off_t off, enum GP_IOWhence whence)
if (poff < sub_io->start || poff > sub_io->end) {
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
ret = GP_IOSeek(sub_io->io, off, whence);
@@ -305,7 +306,7 @@ static off_t sub_seek(GP_IO *io, off_t off, enum GP_IOWhence whence)
if (off > io_size || off < 0) {
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
ret = GP_IOSeek(sub_io->io, sub_io->start + off, whence);
@@ -315,19 +316,19 @@ static off_t sub_seek(GP_IO *io, off_t off, enum GP_IOWhence whence)
if (off + io_size < 0 || off > 0) {
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
- ret = GP_IOSeek(sub_io->io, sub_io->end + off, whence);
+ ret = GP_IOSeek(sub_io->io, sub_io->end + off, GP_IO_SEEK_SET);
break;
default:
GP_WARN("Invalid whence");
errno = EINVAL;
- return (off_t)-1;
+ return -1;
}
- if (ret == (off_t)-1)
- return (off_t)-1;
+ if (ret == -1)
+ return -1;
sub_io->cur = ret;
@@ -467,8 +468,8 @@ int GP_IOMark(GP_IO *self, enum GP_IOMarkTypes type)
return -1;
}
- if (ret == (off_t)-1) {
- GP_WARN("Failed to lseek IO Stream");
+ if (ret == -1) {
+ GP_WARN("Failed to seek I/O Stream");
return -1;
}
@@ -483,12 +484,12 @@ off_t GP_IOSize(GP_IO *io)
ret = GP_IOSeek(io, 0, GP_IO_SEEK_END);
- if (ret == (off_t)-1)
+ if (ret == -1)
return ret;
GP_IOSeek(io, cur, GP_IO_SEEK_SET);
- GP_DEBUG(2, "IO Size = %lli", (long long)ret);
+ GP_DEBUG(2, "I/O Size = %lli", (long long)ret);
return ret;
}
http://repo.or.cz/w/gfxprim.git/commit/ec22f36da6e391b7eeb08d02f860ae12371e…
commit ec22f36da6e391b7eeb08d02f860ae12371ef1a4
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 25 21:33:39 2014 +0200
tests: loaders: IO: Much more tests.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/tests/loaders/IO.c b/tests/loaders/IO.c
index c193098d..2d08d831 100644
--- a/tests/loaders/IO.c
+++ b/tests/loaders/IO.c
@@ -28,20 +28,85 @@
#include "tst_test.h"
+static const char *whence_name(int whence)
+{
+ switch (whence) {
+ case GP_IO_SEEK_SET:
+ return "SEEK_SET";
+ case GP_IO_SEEK_CUR:
+ return "SEEK_CUR";
+ case GP_IO_SEEK_END:
+ return "SEEK_END";
+ }
+
+ return "INVALID";
+}
+
+static int seek_and_tell(GP_IO *io, off_t off, int whence, off_t exp_off)
+{
+ if (GP_IOSeek(io, off, whence) == -1) {
+ tst_msg("Failed to seek %zi %s", off, whence_name(whence));
+ return 1;
+ }
+
+ off = GP_IOTell(io);
+
+ if (off != exp_off) {
+ tst_msg("Wrong offset %zi expected %zi", off, exp_off);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int seek_fail(GP_IO *io, off_t off, int whence)
+{
+ off_t ret, start, end;
+
+ start = GP_IOTell(io);
+
+ ret = GP_IOSeek(io, off, whence);
+
+ if (ret != -1) {
+ tst_msg("Seek succeded unexpectedly %zi %s",
+ off, whence_name(whence));
+ return 1;
+ }
+
+ end = GP_IOTell(io);
+
+ if (start != end) {
+ tst_msg("Seek %zi %s failed but offset changed %zi -> %zi",
+ off, whence_name(whence), start, end);
+ return 1;
+ }
+
+ return 0;
+}
+
/*
* Expects IO buffer filled with monotonically increasing bytes, i.e.
* 0x00 0x01 0x02 ...
*/
-static int do_test(GP_IO *io)
+static int do_test(GP_IO *io, off_t io_size, int is_file)
{
int ret;
uint8_t buf[10];
unsigned int i;
+ off_t off;
+ int failed = 0;
+
+ off = GP_IOTell(io);
+
+ if (off != 0) {
+ tst_msg("Wrong offset before first read %zu", off);
+ return TST_FAILED;
+ }
ret = GP_IORead(io, buf, 10);
if (ret != 10) {
- tst_msg("First IO read failed");
+ tst_msg("First I/O read failed");
return TST_FAILED;
}
@@ -52,10 +117,10 @@ static int do_test(GP_IO *io)
}
}
- ret = GP_IOTell(io);
+ off = GP_IOTell(io);
- if (ret != 10) {
- tst_msg("Have wrong offset %u, after read 10", ret);
+ if (off != 10) {
+ tst_msg("Have wrong offset %zu, after read 10", off);
return TST_FAILED;
}
@@ -63,7 +128,7 @@ static int do_test(GP_IO *io)
ret = GP_IORead(io, buf, 10);
if (ret != 10) {
- tst_msg("Second IO read failed");
+ tst_msg("Second I/O read failed");
return TST_FAILED;
}
@@ -99,7 +164,7 @@ static int do_test(GP_IO *io)
uint16_t val;
if (GP_IOReadF(io, header, &byte, &val) != 5) {
- tst_msg("Failed to ReadF from Memory IO");
+ tst_msg("Failed to ReadF from I/O");
return TST_FAILED;
}
@@ -113,6 +178,49 @@ static int do_test(GP_IO *io)
return TST_FAILED;
}
+ /* Seek tests */
+ if (seek_and_tell(io, 0, GP_IO_SEEK_END, io_size))
+ failed++;
+
+ if (seek_and_tell(io, -io_size, GP_IO_SEEK_END, 0))
+ failed++;
+
+ if (seek_and_tell(io, io_size, GP_IO_SEEK_SET, io_size))
+ failed++;
+
+ if (seek_and_tell(io, 0, GP_IO_SEEK_SET, 0))
+ failed++;
+
+ if (seek_and_tell(io, io_size, GP_IO_SEEK_CUR, io_size))
+ failed++;
+
+ if (seek_and_tell(io, -io_size, GP_IO_SEEK_CUR, 0))
+ failed++;
+
+ if (seek_fail(io, -1, GP_IO_SEEK_CUR))
+ failed++;
+
+ if (!is_file && seek_fail(io, io_size+1, GP_IO_SEEK_CUR))
+ failed++;
+
+ if (seek_fail(io, -1, GP_IO_SEEK_SET))
+ failed++;
+
+ if (!is_file && seek_fail(io, io_size + 1, GP_IO_SEEK_SET))
+ failed++;
+
+ if (!is_file && seek_fail(io, 1, GP_IO_SEEK_END))
+ failed++;
+
+ if (seek_fail(io, -io_size - 1, GP_IO_SEEK_END))
+ failed++;
+
+ if (seek_fail(io, 0, 100))
+ failed++;
+
+ if (failed)
+ return TST_FAILED;
+
return TST_SUCCESS;
}
@@ -129,16 +237,18 @@ static int test_IOMem(void)
io = GP_IOMem(buffer, sizeof(buffer), NULL);
if (!io) {
- tst_msg("Failed to initialize memory IO");
+ tst_msg("Failed to initialize memory I/O");
return TST_FAILED;
}
- ret = do_test(io);
- if (ret)
+ ret = do_test(io, sizeof(buffer), 0);
+ if (ret) {
+ GP_IOClose(io);
return ret;
+ }
if (GP_IOClose(io)) {
- tst_msg("Failed to close memory IO");
+ tst_msg("Failed to close memory I/O");
return TST_FAILED;
}
@@ -160,7 +270,7 @@ static int test_IOFile(void)
io = GP_IOFile(TFILE, GP_IO_WRONLY);
if (!io) {
- tst_msg("Failed to open file IO for writing: %s",
+ tst_msg("Failed to open file I/O for writing: %s",
strerror(errno));
return TST_FAILED;
}
@@ -173,28 +283,101 @@ static int test_IOFile(void)
}
if (GP_IOClose(io)) {
- tst_msg("Failed to close file IO: %s", strerror(errno));
+ tst_msg("Failed to close file I/O: %s", strerror(errno));
return TST_FAILED;
}
io = GP_IOFile(TFILE, GP_IO_RDONLY);
if (!io) {
- tst_msg("Failed to open file IO for reading: %s",
+ tst_msg("Failed to open file I/O for reading: %s",
strerror(errno));
return TST_FAILED;
}
- ret = do_test(io);
- if (ret)
+ ret = do_test(io, sizeof(buffer), 1);
+ if (ret) {
+ GP_IOClose(io);
+ return ret;
+ }
+
+ if (GP_IOClose(io)) {
+ tst_msg("Failed to close file I/O: %s", strerror(errno));
+ return TST_FAILED;
+ }
+
+ return TST_SUCCESS;
+}
+
+static int test_IOSubIO(void)
+{
+ uint8_t buffer[128];
+ unsigned int i;
+ GP_IO *io, *pio;
+ off_t off;
+ int ret;
+
+ for (i = 0; i < sizeof(buffer); i++)
+ buffer[i] = i;
+
+ pio = GP_IOMem(buffer, sizeof(buffer), NULL);
+
+ if (!pio) {
+ tst_msg("Failed to initialize memory I/O");
+ return TST_FAILED;
+ }
+
+ io = GP_IOSubIO(pio, 100);
+
+ if (!io) {
+ tst_msg("Failed to initialize sub I/O");
+ GP_IOClose(io);
+ return TST_FAILED;
+ }
+
+ ret = do_test(io, 100, 0);
+ if (ret) {
+ GP_IOClose(pio);
+ GP_IOClose(io);
return ret;
+ }
+
+ if (GP_IOSeek(io, 0, GP_IO_SEEK_END) == (off_t)-1) {
+ tst_msg("Failed to seek to the end of sub I/O: %s",
+ tst_strerr(errno));
+ goto failed;
+ }
+
+ ret = GP_IORead(io, buffer, sizeof(buffer));
+
+ if (ret != 0) {
+ tst_msg("Read at the end of sub I/O returned %i", ret);
+ goto failed;
+ }
+
+ off = GP_IOTell(pio);
+
+ if (off != 100) {
+ tst_msg("Wrong offset at the parent I/O: %zu", off);
+ goto failed;
+ }
if (GP_IOClose(io)) {
- tst_msg("Failed to close file IO: %s", strerror(errno));
+ tst_msg("Failed to close sub I/O");
+ GP_IOClose(pio);
+ return TST_FAILED;
+ }
+
+ if (GP_IOClose(pio)) {
+ tst_msg("Failed to close memory I/O");
return TST_FAILED;
}
return TST_SUCCESS;
+failed:
+ GP_IOClose(io);
+ GP_IOClose(pio);
+ return TST_FAILED;
}
static ssize_t test_IOFill_read(GP_IO GP_UNUSED(*io), void *buf, size_t size)
@@ -369,6 +552,10 @@ const struct tst_suite tst_suite = {
.tst_fn = test_IOMem,
.flags = TST_CHECK_MALLOC},
+ {.name = "IOSubIO",
+ .tst_fn = test_IOSubIO,
+ .flags = TST_CHECK_MALLOC},
+
{.name = "IOFile",
.tst_fn = test_IOFile,
.flags = TST_CHECK_MALLOC | TST_TMPDIR},
http://repo.or.cz/w/gfxprim.git/commit/273279db3fb62bc3757a213b231a88b8e107…
commit 273279db3fb62bc3757a213b231a88b8e107383b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jun 25 20:50:07 2014 +0200
doc: loaders_io: Add GP_IOSubIO() documentation
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/doc/loaders_io.txt b/doc/loaders_io.txt
index d3d00a7e..64656fd6 100644
--- a/doc/loaders_io.txt
+++ b/doc/loaders_io.txt
@@ -248,6 +248,32 @@ Creates an IO stream from a file.
Returns a pointer to initialized I/O stream, or in case of failure NULL and
errno is set.
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+GP_IO *GP_IOSubIO(GP_IO *pio, size_t size);
+-------------------------------------------------------------------------------
+
+Creates an readable I/O on the top of an existing readable I/O.
+
+The stream position in the parent I/O is advanced when reading or seeking the
+sub I/O.
+
+The sub I/O is limited to an interval starting at current position and can
+advance size bytes at max; then it behaves like the stream has ended i.e.
+'GP_IORead()' returns zero.
+
+You can seek in the resulting I/O if:
+
+* The parent I/O is seekable
+
+* The the combination of 'off' and 'whence' fits inside the sub I/O
+
+WARNING: If you combine reading or seeking in the parent I/O and sub I/O the
+ result is undefined.
[source,c]
-------------------------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
doc/loaders_io.txt | 26 ++++++
libs/loaders/GP_IO.c | 41 +++++-----
tests/loaders/IO.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 251 insertions(+), 37 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
20 Jun '14
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
discards e0a04e8ae2d7a772cab0eb49858bb6d3045c025d (commit)
via 25054131fde91ee366211edb541a0628ffa4b2e3 (commit)
via 96f9ca184489a22e585571f01592fa2dcb93c588 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (e0a04e8ae2d7a772cab0eb49858bb6d3045c025d)
N -- N -- N (25054131fde91ee366211edb541a0628ffa4b2e3)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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/25054131fde91ee366211edb541a0628ffa4…
commit 25054131fde91ee366211edb541a0628ffa4b2e3
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jun 17 18:39:38 2014 +0200
tests: loaders: Add GP_IOFlush() test.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/tests/loaders/IO.c b/tests/loaders/IO.c
index 723c17d0..c193098d 100644
--- a/tests/loaders/IO.c
+++ b/tests/loaders/IO.c
@@ -257,6 +257,50 @@ static int test_IOFill(void)
static size_t counter;
+static ssize_t flush_write(GP_IO GP_UNUSED(*io), void *buf, size_t size)
+{
+ size_t to_write = GP_MIN(7u, size);
+
+ if (((uint8_t*)buf)[0] != counter)
+ return -1;
+
+ counter += to_write;
+
+ return to_write;
+}
+
+static int test_IOFlush(void)
+{
+ GP_IO io = {.Write = flush_write};
+ unsigned int i;
+ int fail = 0;
+ uint8_t buf[255];
+
+ for (i = 0; i < 255; i++)
+ buf[i] = i;
+
+ for (i = 1; i < 255; i++) {
+ counter = 0;
+ if (GP_IOFlush(&io, buf, i)) {
+ if (!fail)
+ tst_msg("GP_IOFlush failed");
+ fail++;
+ }
+
+ if (counter != i) {
+ if (!fail)
+ tst_msg("Bytes written %zu expected %u",
+ counter, i);
+ fail++;
+ }
+ }
+
+ if (fail)
+ return TST_FAILED;
+
+ return TST_SUCCESS;
+}
+
static ssize_t wbuf_write(GP_IO GP_UNUSED(*io), void *buf, size_t size)
{
unsigned int i;
@@ -318,7 +362,6 @@ static int test_IOWBuffer(void)
return TST_SUCCESS;
}
-
const struct tst_suite tst_suite = {
.suite_name = "IO",
.tests = {
@@ -333,8 +376,12 @@ const struct tst_suite tst_suite = {
{.name = "IOFill",
.tst_fn = test_IOFill},
+ {.name = "IOFlush",
+ .tst_fn = test_IOFlush},
+
{.name = "IOWBuffer",
- .tst_fn = test_IOWBuffer},
+ .tst_fn = test_IOWBuffer,
+ .flags = TST_CHECK_MALLOC},
{.name = NULL},
}
http://repo.or.cz/w/gfxprim.git/commit/96f9ca184489a22e585571f01592fa2dcb93…
commit 96f9ca184489a22e585571f01592fa2dcb93c588
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jun 17 00:02:09 2014 +0200
doc: loaders: Update I/O documentation.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/doc/loaders_io.txt b/doc/loaders_io.txt
index 2e010bbc..d3d00a7e 100644
--- a/doc/loaders_io.txt
+++ b/doc/loaders_io.txt
@@ -73,7 +73,21 @@ This is a wrapper to 'io->Read()'.
Reads at most 'size' bytes from an 'IO' stream and stores them into the
buffer. Returns number of bytes read.
-On failure the return value is negative and errno is set.
+On failure negative value is returned and errno is set.
+
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+int GP_IOFill(GP_IO *io, void *buf, size_t size);
+-------------------------------------------------------------------------------
+
+Similar to 'GP_IORead()' but either reads the whole buffer or fails.
+
+Returns zero on success and non-zero on failure.
[source,c]
@@ -90,7 +104,34 @@ This is a wrapper to 'io->Write()'.
Writes at most 'size' bytes from an 'IO' stream and stores them into the
buffer. Returns number of bytes read.
-On failure the return value is negative and errno is set.
+On failure negative value is returned and errno is set.
+
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+int GP_IOFlush(GP_IO *io, void *buf, size_t size);
+-------------------------------------------------------------------------------
+
+Similar to 'GP_IOWrite()' but either writes the whole buffer or fails.
+
+Returns zero on success and non-zero on failure.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+int GP_IOPrintF(GP_IO *io, const char *fmt, ...);
+-------------------------------------------------------------------------------
+
+Printf-like function for an I/O stream.
+
+Returns zero on success and non-zero on failure.
[source,c]
-------------------------------------------------------------------------------
@@ -106,7 +147,7 @@ This is a wrapper to 'io->Close()'.
Finalizes reading/writing, closes file descriptors (in case of file IO), frees
memory buffers.
-Returns zero on success, non-zero on IO failure and errno is set.
+Returns zero on success, non-zero on I/O failure and errno is set.
[source,c]
@@ -115,13 +156,30 @@ Returns zero on success, non-zero on IO failure and errno is set.
/* or */
#include <GP.h>
+enum GP_IOWhence {
+ GP_IO_SEEK_SET = 0,
+ GP_IO_SEEK_CUR = 1,
+ GP_IO_SEEK_END = 2,
+};
+
off_t GP_IOSeek(GP_IO *io, off_t off, enum GP_IOWhence whence);
-------------------------------------------------------------------------------
This is a wrapper to 'io->Seek()'.
-//TODO
+Returns '(off_t)-1' on failure and errno is set.
+
+Generally not all read I/O streams are seekable back (zlib/rle decompression
+streams, etc.) but all streams should be able to seek to the start of the
+stream, to the end and forward.
+
+.Most common errno values
+|==============================================================================
+| 'EINVAL' | Invalid 'whence' or 'off' points outside the stream.
+| 'ENOSYS' | Operation not supported, combination of 'whence' and 'off' points
+ inside the stream (is valid) but action cannot be done.
+|==============================================================================
[source,c]
-------------------------------------------------------------------------------
@@ -132,7 +190,7 @@ This is a wrapper to 'io->Seek()'.
off_t GP_IOTell(GP_IO *io);
-------------------------------------------------------------------------------
-Wrapper to 'GP_IOSeek()', returns current position in IO stream.
+Wrapper to 'GP_IOSeek()', returns current position in I/O stream.
[source,c]
@@ -144,7 +202,7 @@ Wrapper to 'GP_IOSeek()', returns current position in IO stream.
off_t GP_IORewind(GP_IO *io)
-------------------------------------------------------------------------------
-Wrapper to 'GP_IOSeek()', rewinds to the start of the IO stream.
+Wrapper to 'GP_IOSeek()', rewinds to the start of the I/O stream.
Returns zero on success, non-zero on failure and errno is set.
@@ -158,16 +216,17 @@ Returns zero on success, non-zero on failure and errno is set.
GP_IO *GP_IOMem(void *buf, size_t size, void (*free)(void *));
-------------------------------------------------------------------------------
-Creates an read-only IO from a memory buffer.
+Creates an read-only I/O from a memory buffer.
-Returns initialized IO or in case of failure NULL and errno is set.
+Returns initialized I/O or in case of failure NULL and errno is set.
The 'buf' is pointer to the start of the buffer, the 'size' is size in bytes.
The 'free()' callback if not NULL is called with the start of the buffer as
an argument on 'IOClose()'.
-TIP: See link:example_memory_io.html[memory IO example].
+TIP: See link:example_memory_io.html[memory I/O example].
+
[source,c]
-------------------------------------------------------------------------------
@@ -186,5 +245,24 @@ GP_IO *GP_IOFile(const char *path, enum GP_IOFileMode mode);
Creates an IO stream from a file.
-Returns a pointer to initialized IO stream, or in case of failure NULL and
+Returns a pointer to initialized I/O stream, or in case of failure NULL and
errno is set.
+
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+GP_IO *GP_IOWBuffer(GP_IO *io, size_t bsize);
+-------------------------------------------------------------------------------
+
+Creates write buffered I/O on the top of an existing I/O.
+
+Generally you should create a buffered I/O if you are about to write data a
+few bytes at the time.
+
+If 'bsize' is zero default size is choosen.
+
+TIP: See link:example_loader_registration.html[example buffered I/O usage].
-----------------------------------------------------------------------
Summary of changes:
tests/loaders/IO.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 2 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
17 Jun '14
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 e0a04e8ae2d7a772cab0eb49858bb6d3045c025d (commit)
via 271d541c7c6b1cf431dec46bf577770ad5a32d30 (commit)
via 948e9d7dc2253e7086c2f94792b9a3989a372a80 (commit)
from 76277f09b9ea5b7884309cfe4625ed82811cdfb9 (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/e0a04e8ae2d7a772cab0eb49858bb6d3045c…
commit e0a04e8ae2d7a772cab0eb49858bb6d3045c025d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jun 17 00:02:09 2014 +0200
doc: loaders; Update I/O documentation.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/doc/loaders_io.txt b/doc/loaders_io.txt
index 2e010bbc..d3d00a7e 100644
--- a/doc/loaders_io.txt
+++ b/doc/loaders_io.txt
@@ -73,7 +73,21 @@ This is a wrapper to 'io->Read()'.
Reads at most 'size' bytes from an 'IO' stream and stores them into the
buffer. Returns number of bytes read.
-On failure the return value is negative and errno is set.
+On failure negative value is returned and errno is set.
+
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+int GP_IOFill(GP_IO *io, void *buf, size_t size);
+-------------------------------------------------------------------------------
+
+Similar to 'GP_IORead()' but either reads the whole buffer or fails.
+
+Returns zero on success and non-zero on failure.
[source,c]
@@ -90,7 +104,34 @@ This is a wrapper to 'io->Write()'.
Writes at most 'size' bytes from an 'IO' stream and stores them into the
buffer. Returns number of bytes read.
-On failure the return value is negative and errno is set.
+On failure negative value is returned and errno is set.
+
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+int GP_IOFlush(GP_IO *io, void *buf, size_t size);
+-------------------------------------------------------------------------------
+
+Similar to 'GP_IOWrite()' but either writes the whole buffer or fails.
+
+Returns zero on success and non-zero on failure.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+int GP_IOPrintF(GP_IO *io, const char *fmt, ...);
+-------------------------------------------------------------------------------
+
+Printf-like function for an I/O stream.
+
+Returns zero on success and non-zero on failure.
[source,c]
-------------------------------------------------------------------------------
@@ -106,7 +147,7 @@ This is a wrapper to 'io->Close()'.
Finalizes reading/writing, closes file descriptors (in case of file IO), frees
memory buffers.
-Returns zero on success, non-zero on IO failure and errno is set.
+Returns zero on success, non-zero on I/O failure and errno is set.
[source,c]
@@ -115,13 +156,30 @@ Returns zero on success, non-zero on IO failure and errno is set.
/* or */
#include <GP.h>
+enum GP_IOWhence {
+ GP_IO_SEEK_SET = 0,
+ GP_IO_SEEK_CUR = 1,
+ GP_IO_SEEK_END = 2,
+};
+
off_t GP_IOSeek(GP_IO *io, off_t off, enum GP_IOWhence whence);
-------------------------------------------------------------------------------
This is a wrapper to 'io->Seek()'.
-//TODO
+Returns '(off_t)-1' on failure and errno is set.
+
+Generally not all read I/O streams are seekable back (zlib/rle decompression
+streams, etc.) but all streams should be able to seek to the start of the
+stream, to the end and forward.
+
+.Most common errno values
+|==============================================================================
+| 'EINVAL' | Invalid 'whence' or 'off' points outside the stream.
+| 'ENOSYS' | Operation not supported, combination of 'whence' and 'off' points
+ inside the stream (is valid) but action cannot be done.
+|==============================================================================
[source,c]
-------------------------------------------------------------------------------
@@ -132,7 +190,7 @@ This is a wrapper to 'io->Seek()'.
off_t GP_IOTell(GP_IO *io);
-------------------------------------------------------------------------------
-Wrapper to 'GP_IOSeek()', returns current position in IO stream.
+Wrapper to 'GP_IOSeek()', returns current position in I/O stream.
[source,c]
@@ -144,7 +202,7 @@ Wrapper to 'GP_IOSeek()', returns current position in IO stream.
off_t GP_IORewind(GP_IO *io)
-------------------------------------------------------------------------------
-Wrapper to 'GP_IOSeek()', rewinds to the start of the IO stream.
+Wrapper to 'GP_IOSeek()', rewinds to the start of the I/O stream.
Returns zero on success, non-zero on failure and errno is set.
@@ -158,16 +216,17 @@ Returns zero on success, non-zero on failure and errno is set.
GP_IO *GP_IOMem(void *buf, size_t size, void (*free)(void *));
-------------------------------------------------------------------------------
-Creates an read-only IO from a memory buffer.
+Creates an read-only I/O from a memory buffer.
-Returns initialized IO or in case of failure NULL and errno is set.
+Returns initialized I/O or in case of failure NULL and errno is set.
The 'buf' is pointer to the start of the buffer, the 'size' is size in bytes.
The 'free()' callback if not NULL is called with the start of the buffer as
an argument on 'IOClose()'.
-TIP: See link:example_memory_io.html[memory IO example].
+TIP: See link:example_memory_io.html[memory I/O example].
+
[source,c]
-------------------------------------------------------------------------------
@@ -186,5 +245,24 @@ GP_IO *GP_IOFile(const char *path, enum GP_IOFileMode mode);
Creates an IO stream from a file.
-Returns a pointer to initialized IO stream, or in case of failure NULL and
+Returns a pointer to initialized I/O stream, or in case of failure NULL and
errno is set.
+
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_IO.h>
+/* or */
+#include <GP.h>
+
+GP_IO *GP_IOWBuffer(GP_IO *io, size_t bsize);
+-------------------------------------------------------------------------------
+
+Creates write buffered I/O on the top of an existing I/O.
+
+Generally you should create a buffered I/O if you are about to write data a
+few bytes at the time.
+
+If 'bsize' is zero default size is choosen.
+
+TIP: See link:example_loader_registration.html[example buffered I/O usage].
http://repo.or.cz/w/gfxprim.git/commit/271d541c7c6b1cf431dec46bf577770ad5a3…
commit 271d541c7c6b1cf431dec46bf577770ad5a32d30
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jun 17 00:01:07 2014 +0200
loaders: IO: Two fixes.
* Fix IOWBuffer close().
* Set errno on invalid whence.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_IO.c b/libs/loaders/GP_IO.c
index 329fdd43..c8dd9038 100644
--- a/libs/loaders/GP_IO.c
+++ b/libs/loaders/GP_IO.c
@@ -64,6 +64,7 @@ static off_t file_seek(GP_IO *self, off_t off, enum GP_IOWhence whence)
break;
default:
GP_WARN("Invalid whence");
+ errno = EINVAL;
return (off_t)-1;
}
@@ -389,7 +390,7 @@ static int wbuf_close(GP_IO *io)
GP_DEBUG(1, "Closing BufferIO (from %p)", buf_io->io);
if (buf_io->bpos) {
- if (GP_IOFlush(buf_io->io, buf_io->buf, buf_io->bsize))
+ if (GP_IOFlush(buf_io->io, buf_io->buf, buf_io->bpos))
ret = 1;
}
http://repo.or.cz/w/gfxprim.git/commit/948e9d7dc2253e7086c2f94792b9a3989a37…
commit 948e9d7dc2253e7086c2f94792b9a3989a372a80
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Jun 17 00:00:14 2014 +0200
tests: loaders: Add IOWBuffer test.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/tests/loaders/IO.c b/tests/loaders/IO.c
index 32cfa2a1..723c17d0 100644
--- a/tests/loaders/IO.c
+++ b/tests/loaders/IO.c
@@ -255,6 +255,70 @@ static int test_IOFill(void)
return TST_SUCCESS;
}
+static size_t counter;
+
+static ssize_t wbuf_write(GP_IO GP_UNUSED(*io), void *buf, size_t size)
+{
+ unsigned int i;
+
+ for (i = 0; i < size; i++) {
+ if (((uint8_t*)buf)[i] != 'a') {
+ tst_msg("Wrong data in buffer");
+ return -1;
+ }
+ }
+
+ counter += size;
+ return size;
+}
+
+static int wbuf_close(GP_IO GP_UNUSED(*io))
+{
+ return 0;
+}
+
+static int test_IOWBuffer(void)
+{
+ GP_IO *bio;
+ size_t cnt = 0;
+ unsigned int i;
+ GP_IO io = {
+ .Write = wbuf_write,
+ .Close = wbuf_close,
+ };
+
+ counter = 0;
+
+ bio = GP_IOWBuffer(&io, 100);
+
+ if (!bio)
+ return TST_FAILED;
+
+ for (i = 0; i < 100; i++) {
+ size_t to_write = i % 10 + 1;
+ if (GP_IOFlush(bio, "aaaaaaaaaaa", to_write)) {
+ tst_msg("Failed to write data: %s", tst_strerr(errno));
+ GP_IOClose(bio);
+ return TST_FAILED;
+ }
+ cnt += to_write;
+ }
+
+ if (GP_IOClose(bio)) {
+ tst_msg("Failed to close I/O: %s", tst_strerr(errno));
+ return TST_FAILED;
+ }
+
+ if (counter != cnt) {
+ tst_msg("Wrong number of bytes written have %zu expected %zu",
+ counter, cnt);
+ return TST_FAILED;
+ }
+
+ return TST_SUCCESS;
+}
+
+
const struct tst_suite tst_suite = {
.suite_name = "IO",
.tests = {
@@ -269,6 +333,9 @@ const struct tst_suite tst_suite = {
{.name = "IOFill",
.tst_fn = test_IOFill},
+ {.name = "IOWBuffer",
+ .tst_fn = test_IOWBuffer},
+
{.name = NULL},
}
};
-----------------------------------------------------------------------
Summary of changes:
doc/loaders_io.txt | 98 ++++++++++++++++++++++++++++++++++++++++++++-----
libs/loaders/GP_IO.c | 3 +-
tests/loaders/IO.c | 67 ++++++++++++++++++++++++++++++++++
3 files changed, 157 insertions(+), 11 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
16 Jun '14
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 76277f09b9ea5b7884309cfe4625ed82811cdfb9 (commit)
from 3568538bbc1602c05313b9224c1884a42a411ad6 (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/76277f09b9ea5b7884309cfe4625ed82811c…
commit 76277f09b9ea5b7884309cfe4625ed82811cdfb9
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Jun 16 00:42:12 2014 +0200
loaders: Remove now unused ByteUtils
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt
index 2654ae54..24d0e037 100644
--- a/build/syms/Loaders_symbols.txt
+++ b/build/syms/Loaders_symbols.txt
@@ -1,4 +1,3 @@
-GP_FWrite
GP_MatchJPG
GP_ReadJPG
diff --git a/include/loaders/GP_ByteUtils.h b/include/loaders/GP_ByteUtils.h
deleted file mode 100644
index 92b2fec7..00000000
--- a/include/loaders/GP_ByteUtils.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
- /*
-
- Utils to read/write values with specified endianity.
-
- */
-
-#ifndef LOADERS_GP_BYTE_UTILS_H
-#define LOADERS_GP_BYTE_UTILS_H
-
-#include <stdio.h>
-
-/*
- * Printf-like function to write file headers.
- *
- * Returns number of items sucessfully written.
- */
-int GP_FWrite(FILE *f, const char *fmt, ...);
-
-#endif /* LOADERS_GP_BYTE_UTILS_H */
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index 24aa2b04..efb4c9f3 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -40,7 +40,6 @@
#include "core/GP_Pixel.h"
#include "core/GP_GetPutPixel.h"
-#include "loaders/GP_ByteUtils.h"
#include "loaders/GP_LineConvert.h"
#include "loaders/GP_BMP.h"
diff --git a/libs/loaders/GP_ByteUtils.c b/libs/loaders/GP_ByteUtils.c
deleted file mode 100644
index 4a83d5d1..00000000
--- a/libs/loaders/GP_ByteUtils.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/*****************************************************************************
- * This file is part of gfxprim library. *
- * *
- * Gfxprim is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * Gfxprim is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with gfxprim; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301 USA *
- * *
- * Copyright (C) 2009-2013 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include <stdarg.h>
-
-#include "core/GP_ByteOrder.h"
-#include "core/GP_Debug.h"
-#include "core/GP_Common.h"
-
-#include "loaders/GP_ByteUtils.h"
-
-enum fmt_type {
- BYTE_ARRAY,
- BIG_ENDIAN_VAR,
- LITTLE_ENDIAN_VAR,
- IGNORE,
- CONST_BYTE,
-};
-
-static int ctoi(char c, int *i)
-{
- switch (c) {
- case '0' ... '9':
- *i = c - '0';
- break;
- default:
- return 1;
- }
-
- return 0;
-}
-
-static int ctoh(char c, int *i)
-{
- switch (c) {
- case '0' ... '9':
- *i += c - '0';
- break;
- case 'a' ... 'f':
- *i += c - 'a' + 10;
- break;
- case 'A' ... 'F':
- *i += c - 'A' + 10;
- break;
- case '0':
- GP_BUG("Unexpected end of the format string");
- return 1;
- default:
- GP_BUG("Expected [0-9]|[a-f][A-F] in hex constant, got '%c'", c);
- return 1;
- }
-
- return 0;
-}
-
-static const char *get_hex(const char *fmt, int *type, int *val)
-{
- *type = CONST_BYTE;
-
- *val = 0;
-
- if (fmt[0] != 'x') {
- GP_BUG("Expected x after 0 in hex constant");
- return NULL;
- }
-
- if (ctoh(fmt[1], val))
- return NULL;
-
- (*val)<<=4;
-
- if (ctoh(fmt[2], val))
- return NULL;
-
- return fmt + 3;
-}
-
-static const char *get_int(const char *fmt, int *val)
-{
- int i = 0, add = 0;
-
- *val = 0;
-
- if (ctoi(fmt[i++], val))
- return fmt;
-
- while (!ctoi(fmt[i], &add)) {
- *val *= 10;
- *val += add;
- i++;
- }
-
- return fmt + i;
-}
-
-static const char *get_array(const char *fmt, int *type, int *val)
-{
- *type = BYTE_ARRAY;
-
- fmt = get_int(fmt, val);
-
- /* array for one element "%a" */
- if (*val == 0)
- *val = 1;
-
- return fmt;
-}
-
-static const char *get_lb_size(const char *fmt, int *val)
-{
- if (ctoi(fmt[0], val)) {
- GP_WARN("Expected number got '%c'", fmt[0]);
- return NULL;
- }
-
- switch (*val) {
- case 1:
- case 2:
- case 4:
- return fmt + 1;
- }
-
- GP_BUG("Invalid little/big endian variable size '%i'", *val);
- return NULL;
-}
-
-static const char *get_next(const char *fmt, int *type, int *val)
-{
- /* Eat spaces */
- while (fmt[0] == ' ')
- fmt++;
-
- switch (fmt[0]) {
- /* Byte array */
- case 'A':
- return get_array(fmt + 1, type, val);
- break;
- /* Hexadecimal constant */
- case '0':
- return get_hex(fmt + 1, type, val);
- break;
- /* 1, 2, 4 bytes long variable in defined endianity */
- case 'L':
- *type = LITTLE_ENDIAN_VAR;
- return get_lb_size(fmt + 1, val);
- break;
- case 'B':
- *type = BIG_ENDIAN_VAR;
- return get_lb_size(fmt + 1, val);
- break;
- case 'I':
- *type = IGNORE;
- return get_int(fmt + 1, val);
- break;
- case '0':
- return NULL;
- break;
- }
-
- GP_BUG("Unexpected character in format string '%c'", fmt[0]);
- return NULL;
-}
-
-static void swap_bytes(void *ptr, int len, int type)
-{
- if (__BYTE_ORDER == __LITTLE_ENDIAN && type == LITTLE_ENDIAN_VAR)
- return;
-
- if (__BYTE_ORDER == __BIG_ENDIAN && type == BIG_ENDIAN_VAR)
- return;
-
- char *buf = ptr;
-
- switch (len) {
- case 1:
- break;
- case 2:
- GP_SWAP(buf[0], buf[1]);
- break;
- case 4:
- GP_SWAP(buf[0], buf[3]);
- GP_SWAP(buf[1], buf[2]);
- break;
- default:
- GP_BUG("Invalid size %i", len);
- }
-}
-
-int GP_FWrite(FILE *f, const char *fmt, ...)
-{
- int type, val, ret = 0;
- va_list va;
- uint8_t u8;
- uint16_t u16;
- uint32_t u32;
-
- 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 (fwrite(va_arg(va, void*), val, 1, f) != 1)
- goto end;
- break;
- case CONST_BYTE:
- if (fwrite(&val, 1, 1, f) != 1)
- goto end;
- break;
- case LITTLE_ENDIAN_VAR:
- case BIG_ENDIAN_VAR:
- switch (val) {
- case 1:
- u8 = va_arg(va, int);
- if (fwrite(&u8, 1, 1, f) != 1)
- goto end;
- break;
- case 2:
- u16 = va_arg(va, int);
-
- swap_bytes(&u16, 2, type);
-
- if (fwrite(&u16, 2, 1, f) != 1)
- goto end;
- break;
- case 4:
- u32 = va_arg(va, int);
-
- swap_bytes(&u32, 4, type);
-
- if (fwrite(&u32, 4, 1, f) != 1)
- goto end;
- break;
- }
- break;
- default:
- GP_BUG("Wrong format type for writing (%i)", type);
- goto end;
- }
-
- ret++;
- }
-end:
- va_end(va);
- return ret;
-}
diff --git a/libs/loaders/GP_ZIP.c b/libs/loaders/GP_ZIP.c
index 55d1cdaa..728f3841 100644
--- a/libs/loaders/GP_ZIP.c
+++ b/libs/loaders/GP_ZIP.c
@@ -37,7 +37,6 @@
#include <core/GP_Common.h>
#include <core/GP_Debug.h>
-#include <loaders/GP_ByteUtils.h>
#include <loaders/GP_Loader.h>
#include <loaders/GP_IOZlib.h>
#include "loaders/GP_ZIP.h"
-----------------------------------------------------------------------
Summary of changes:
build/syms/Loaders_symbols.txt | 1 -
include/loaders/GP_ByteUtils.h | 41 ------
libs/loaders/GP_BMP.c | 1 -
libs/loaders/GP_ByteUtils.c | 270 ----------------------------------------
libs/loaders/GP_ZIP.c | 1 -
5 files changed, 0 insertions(+), 314 deletions(-)
delete mode 100644 include/loaders/GP_ByteUtils.h
delete mode 100644 libs/loaders/GP_ByteUtils.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
15 Jun '14
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 3568538bbc1602c05313b9224c1884a42a411ad6 (commit)
via 983c8bab63c33eef9e7de3278cd5a8329486ab93 (commit)
from 7044b9ef7967a50a1f0b437ad5a0554325484296 (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/3568538bbc1602c05313b9224c1884a42a41…
commit 3568538bbc1602c05313b9224c1884a42a411ad6
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 15 19:05:29 2014 +0200
loaders: Implement Write() instead of Save()
This change implements Write() functions instead of the Save() functions
for all loaders and removes Write() callback from GP_Loader structure.
It also adds a generic GP_LoaderSaveImage() function and bunch of
GP_WriteFOO() functions.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt
index bf8cb76c..2654ae54 100644
--- a/build/syms/Loaders_symbols.txt
+++ b/build/syms/Loaders_symbols.txt
@@ -3,6 +3,7 @@ GP_FWrite
GP_MatchJPG
GP_ReadJPG
GP_LoadJPG
+GP_WriteJPG
GP_SaveJPG
GP_ReadJPGMetaData
GP_LoadJPGMetaData
@@ -13,6 +14,7 @@ GP_ReadPNG
GP_LoadPNG
GP_ReadPNGMetaData
GP_LoadPNGMetaData
+GP_WritePNG
GP_SavePNG
GP_PNG
@@ -36,29 +38,34 @@ GP_GIF
GP_MatchTIFF
GP_ReadTIFF
GP_LoadTIFF
+GP_WriteTIFF
GP_SaveTIFF
GP_TIFF
GP_ReadPBM
GP_LoadPBM
+GP_WritePBM
GP_SavePBM
GP_MatchPBM
GP_PBM
GP_ReadPGM
GP_LoadPGM
+GP_WritePGM
GP_SavePGM
GP_MatchPGM
GP_PGM
GP_ReadPPM
GP_LoadPPM
+GP_WritePPM
GP_SavePPM
GP_MatchPPM
GP_PPM
GP_ReadPNM
GP_LoadPNM
+GP_WritePNM
GP_SavePNM
GP_MatchPNM
GP_PNM
@@ -84,6 +91,7 @@ GP_LoadTmpFile
GP_LoaderBySignature
GP_LoaderByFilename
GP_LoaderLoadImage
+GP_LoaderSaveImage
GP_ReadImage
GP_LoadImage
GP_SaveImage
diff --git a/demos/c_simple/loaders_register.c b/demos/c_simple/loaders_register.c
index 4c596c40..5152d6b5 100644
--- a/demos/c_simple/loaders_register.c
+++ b/demos/c_simple/loaders_register.c
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2014 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -24,7 +24,7 @@
Shows how to register custom image loader/saver.
- Feed it with small image (cca 60x60 pixels) to produce ascii art version.
+ Feed it with small image (cca 60x60 pixels) to produce ASCII art version.
*/
@@ -37,17 +37,21 @@
/*
* Saves 2 bpp grayscale image as ASCII Art
*/
-static int save(const GP_Context *img, const char *dst_path,
- GP_ProgressCallback *callback)
+static int write_data(const GP_Context *img, GP_IO *io,
+ GP_ProgressCallback *callback)
{
+ GP_IO *bio;
+ int err;
+
if (img->pixel_type != GP_PIXEL_G2) {
errno = ENOSYS;
return 1;
}
- FILE *f = fopen(dst_path, "w");
+ /* Create buffered I/O */
+ bio = GP_IOWBuffer(io, 0);
- if (f == NULL)
+ if (!bio)
return 1;
unsigned int i, j;
@@ -58,35 +62,33 @@ static int save(const GP_Context *img, const char *dst_path,
switch (p) {
case 0:
- fprintf(f, " ");
+ err = GP_IOFlush(bio, " ", 2);
break;
case 1:
- fprintf(f, "..");
+ err = GP_IOFlush(bio, "..", 2);
break;
case 2:
- fprintf(f, "()");
+ err = GP_IOFlush(bio, "()", 2);
break;
case 3:
- fprintf(f, "OO");
+ err = GP_IOFlush(bio, "OO", 2);
break;
}
+
+ if (err)
+ return 1;
}
- fprintf(f, "n");
+ if (GP_IOFlush(bio, "n", 1))
+ return 1;
if (GP_ProgressCallbackReport(callback, img->h, j, img->w)) {
- fclose(f);
- unlink(dst_path);
errno = ECANCELED;
return 1;
}
}
- if (fclose(f))
- return 1;
-
GP_ProgressCallbackDone(callback);
-
return 0;
}
@@ -96,7 +98,7 @@ static GP_PixelType save_ptypes[] = {
};
GP_Loader loader = {
- .Save = save,
+ .Write = write_data,
.save_ptypes = save_ptypes,
.fmt_name = "ASCII Art",
.extensions = {"txt", NULL},
diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h
index 381c084c..ff57d2c3 100644
--- a/include/loaders/GP_JPG.h
+++ b/include/loaders/GP_JPG.h
@@ -32,7 +32,7 @@
#include "loaders/GP_Loader.h"
/*
- * Reads a JPEG from an IO stream.
+ * Reads a JPEG from an I/O stream.
*
* Returns newly allocated context cotaining the loaded image or in case of
* failure NULL and errno is set.
@@ -51,6 +51,12 @@ int GP_ReadJPGMetaData(GP_IO *io, GP_MetaData *data);
int GP_LoadJPGMetaData(const char *src_path, GP_MetaData *data);
/*
+ * Writes JPEG into an I/O stream.
+ */
+int GP_WriteJPG(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback);
+
+/*
* Saves JPEG to a file.
*/
int GP_SaveJPG(const GP_Context *src, const char *dst_path,
diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h
index 90aeebb7..e0afc5aa 100644
--- a/include/loaders/GP_Loader.h
+++ b/include/loaders/GP_Loader.h
@@ -34,7 +34,6 @@
#include "loaders/GP_IO.h"
#include "loaders/GP_MetaData.h"
-
/*
* Reads an image from a IO stream.
*
@@ -77,7 +76,7 @@ int GP_SaveImage(const GP_Context *src, const char *dst_path,
*/
typedef struct GP_Loader {
/*
- * Reads an image from an IO stream.
+ * Reads an image from an I/O stream.
*
* Returns newly allocated context cotaining the loaded image or in
* case of failure NULL and errno is set.
@@ -85,11 +84,12 @@ typedef struct GP_Loader {
GP_Context *(*Read)(GP_IO *io, GP_ProgressCallback *callback);
/*
- * Save an image.
+ * Writes an image into an I/O stream.
*
- * Returns zero on succes, non-zero on failure and errno must be set.
+ * Returns zero on success, non-zero on failure and errno must be set.
*/
- int (*Save)(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback);
+ int (*Write)(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback);
/*
* GP_PIXEL_UNKNOWN terminated array of formats loader supports for save.
@@ -154,6 +154,15 @@ GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path,
GP_ProgressCallback *callback);
/*
+ * Generic SaveImage for a given loader.
+ *
+ * The function/ prepares the IO from file, calls the loader Write() method,
+ * closes the IO and returns the context.
+ */
+int GP_LoaderSaveImage(const GP_Loader *self, const GP_Context *src,
+ const char *dst_path, GP_ProgressCallback *callback);
+
+/*
* List loaders into the stdout
*/
void GP_ListLoaders(void);
diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h
index eb607010..0ef1e7c6 100644
--- a/include/loaders/GP_PNG.h
+++ b/include/loaders/GP_PNG.h
@@ -51,8 +51,13 @@ int GP_ReadPNGMetaData(GP_IO *io, GP_MetaData *data);
int GP_LoadPNGMetaData(const char *src_path, GP_MetaData *data);
/*
- * Saves PNG to a file. Zero is returned on succes. Upon failure non-zero is
- * returned and errno is filled accordingly.
+ * Writes PNG into an I/O stream.
+ */
+int GP_SavePNG(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback);
+
+/*
+ * Saves PNG to a file.
*/
int GP_SavePNG(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
diff --git a/include/loaders/GP_PNM.h b/include/loaders/GP_PNM.h
index 13d5f4b4..4397c636 100644
--- a/include/loaders/GP_PNM.h
+++ b/include/loaders/GP_PNM.h
@@ -32,6 +32,9 @@ GP_Context *GP_ReadPBM(GP_IO *io, GP_ProgressCallback *callback);
GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback);
+int GP_WritePBM(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback);
+
int GP_SavePBM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
@@ -43,6 +46,9 @@ GP_Context *GP_ReadPGM(GP_IO *io, GP_ProgressCallback *callback);
GP_Context *GP_LoadPGM(const char *src_path,
GP_ProgressCallback *callback);
+int GP_WritePGM(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback);
+
int GP_SavePGM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
@@ -53,6 +59,9 @@ GP_Context *GP_ReadPPM(GP_IO *io, GP_ProgressCallback *callback);
GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback);
+int GP_WritePPM(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback);
+
int GP_SavePPM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
@@ -63,6 +72,9 @@ GP_Context *GP_ReadPNM(GP_IO *io, GP_ProgressCallback *callback);
GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback);
+int GP_WritePNM(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback);
+
int GP_SavePNM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback);
diff --git a/include/loaders/GP_TIFF.h b/include/loaders/GP_TIFF.h
index ef5e4f33..e7fc9bc9 100644
--- a/include/loaders/GP_TIFF.h
+++ b/include/loaders/GP_TIFF.h
@@ -39,10 +39,16 @@ GP_Context *GP_ReadTIFF(GP_IO *io, GP_ProgressCallback *callback);
GP_Context *GP_LoadTIFF(const char *src_path, GP_ProgressCallback *callback);
/*
+ * Writes TIFF into an I/O stream.
+ */
+int GP_WriteTIFF(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback);
+
+/*
* Saves TIFF.
*/
int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback);
+ GP_ProgressCallback *callback);
/*
* Looks for TIFF file signature. Returns non-zero if found.
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index 2d042bf2..24aa2b04 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -850,6 +850,8 @@ int GP_WriteBMP(const GP_Context *src, GP_IO *io,
struct bitmap_info_header header;
int err;
+ GP_DEBUG(1, "Writing BMP to I/O (%p)", io);
+
if ((err = bmp_fill_header(src, &header)))
goto err;
@@ -865,36 +867,15 @@ err:
return 1;
}
-
int GP_SaveBMP(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
- GP_IO *io;
-
- GP_DEBUG(1, "Saving BMP Image '%s'", dst_path);
-
- io = GP_IOFile(dst_path, GP_IO_WRONLY);
-
- if (!io)
- return 1;
-
- if (GP_WriteBMP(src, io, callback)) {
- GP_IOClose(io);
- unlink(dst_path);
- return 1;
- }
-
- if (GP_IOClose(io)) {
- unlink(dst_path);
- return 1;
- }
-
- return 0;
+ return GP_LoaderSaveImage(&GP_BMP, src, dst_path, callback);
}
struct GP_Loader GP_BMP = {
.Read = GP_ReadBMP,
- .Save = GP_SaveBMP,
+ .Write = GP_WriteBMP,
.save_ptypes = out_pixel_types,
.Match = GP_MatchBMP,
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index dfca66fa..fa2713a9 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -40,10 +40,6 @@
#include "loaders/GP_LineConvert.h"
#include "loaders/GP_JPG.h"
-#ifdef HAVE_JPEG
-
-#include <jpeglib.h>
-
/*
* 0xff 0xd8 - start of image
* 0xff 0x.. - start of frame
@@ -56,6 +52,10 @@ int GP_MatchJPG(const void *buf)
return !memcmp(buf, JPEG_SIGNATURE, JPEG_SIGNATURE_LEN);
}
+#ifdef HAVE_JPEG
+
+#include <jpeglib.h>
+
struct my_jpg_err {
struct jpeg_error_mgr error_mgr;
jmp_buf setjmp_buf;
@@ -144,7 +144,7 @@ struct my_source_mgr {
GP_IO *io;
};
-static void dummy(j_decompress_ptr GP_UNUSED(cinfo))
+static void dummy_src(j_decompress_ptr GP_UNUSED(cinfo))
{
}
@@ -157,12 +157,12 @@ static boolean fill_input_buffer(struct jpeg_decompress_struct *cinfo)
if (ret < 0) {
GP_WARN("Failed to fill buffer");
- return 0;
+ return FALSE;
}
src->mgr.next_input_byte = src->buffer;
src->mgr.bytes_in_buffer = ret;
- return 1;
+ return TRUE;
}
static void skip_input_data(struct jpeg_decompress_struct *cinfo, long num_bytes)
@@ -187,9 +187,9 @@ static void skip_input_data(struct jpeg_decompress_struct *cinfo, long num_bytes
static inline void init_source_mgr(struct my_source_mgr *src, GP_IO *io,
void *buf, size_t buf_size)
{
- src->mgr.init_source = dummy;
+ src->mgr.init_source = dummy_src;
src->mgr.resync_to_restart = jpeg_resync_to_restart;
- src->mgr.term_source = dummy;
+ src->mgr.term_source = dummy_src;
src->mgr.fill_input_buffer = fill_input_buffer;
src->mgr.skip_input_data = skip_input_data;
src->mgr.bytes_in_buffer = 0;
@@ -431,22 +431,77 @@ static int save(struct jpeg_compress_struct *cinfo,
return 0;
}
+struct my_dest_mgr {
+ struct jpeg_destination_mgr mgr;
+ void *buffer;
+ ssize_t size;
+ GP_IO *io;
+};
+
+static void dummy_dst(j_compress_ptr GP_UNUSED(cinfo))
+{
+}
+
+static boolean empty_output_buffer(j_compress_ptr cinfo)
+{
+ struct my_dest_mgr *dest = (void*)cinfo->dest;
+
+ if (GP_IOWrite(dest->io, dest->buffer, dest->size) != dest->size) {
+ GP_DEBUG(1, "Failed to write JPEG buffer");
+ return FALSE;
+ }
+
+ dest->mgr.next_output_byte = dest->buffer;
+ dest->mgr.free_in_buffer = dest->size;
+
+ return TRUE;
+}
+
+static void term_destination(j_compress_ptr cinfo)
+{
+ struct my_dest_mgr *dest = (void*)cinfo->dest;
+ ssize_t to_write = dest->size - dest->mgr.free_in_buffer;
+
+ if (to_write > 0) {
+ if (GP_IOWrite(dest->io, dest->buffer, to_write) != to_write) {
+ GP_DEBUG(1, "Failed to write JPEG buffer");
+ //TODO: Error handling
+ return;
+ }
+ }
+}
+
+static inline void init_dest_mgr(struct my_dest_mgr *dst, GP_IO *io,
+ void *buf, size_t buf_size)
+{
+ dst->mgr.init_destination = dummy_dst;
+ dst->mgr.empty_output_buffer = empty_output_buffer;
+ dst->mgr.term_destination = term_destination;
+ dst->mgr.next_output_byte = buf;
+ dst->mgr.free_in_buffer = buf_size;
+
+ dst->io = io;
+ dst->buffer = buf;
+ dst->size = buf_size;
+}
+
static GP_PixelType out_pixel_types[] = {
GP_PIXEL_BGR888,
GP_PIXEL_G8,
GP_PIXEL_UNKNOWN
};
-int GP_SaveJPG(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback)
+int GP_WriteJPG(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback)
{
- FILE *f;
struct jpeg_compress_struct cinfo;
GP_PixelType out_pix;
struct my_jpg_err my_err;
+ struct my_dest_mgr dst;
+ uint8_t buf[1024];
int err;
- GP_DEBUG(1, "Saving JPG Image '%s'", dst_path);
+ GP_DEBUG(1, "Writing JPG Image to I/O (%p)", io);
out_pix = GP_LineConvertible(src->pixel_type, out_pixel_types);
@@ -457,19 +512,10 @@ int GP_SaveJPG(const GP_Context *src, const char *dst_path,
return 1;
}
- f = fopen(dst_path, "wb");
-
- if (f == NULL) {
- err = errno;
- GP_DEBUG(1, "Failed to open '%s' for writing: %s",
- dst_path, strerror(errno));
- goto err0;
- }
-
if (setjmp(my_err.setjmp_buf)) {
- err = EIO;
- //TODO: is cinfo allocated?
- goto err2;
+ errno = EIO;
+ return 1;
+
}
cinfo.err = jpeg_std_error(&my_err.error_mgr);
@@ -477,7 +523,8 @@ int GP_SaveJPG(const GP_Context *src, const char *dst_path,
jpeg_create_compress(&cinfo);
- jpeg_stdio_dest(&cinfo, f);
+ init_dest_mgr(&dst, io, buf, sizeof(buf));
+ cinfo.dest = (void*)&dst;
cinfo.image_width = src->w;
cinfo.image_height = src->h;
@@ -504,40 +551,22 @@ int GP_SaveJPG(const GP_Context *src, const char *dst_path,
else
err = save(&cinfo, src, callback);
- if (err)
- goto err3;
+ if (err) {
+ jpeg_destroy_compress(&cinfo);
+ errno = err;
+ return 1;
+ }
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
- if (fclose(f)) {
- err = errno;
- GP_DEBUG(1, "Failed to close file '%s': %s",
- dst_path, strerror(errno));
- goto err1;
- }
GP_ProgressCallbackDone(callback);
return 0;
-err3:
- jpeg_destroy_compress(&cinfo);
-err2:
- fclose(f);
-err1:
- unlink(dst_path);
-err0:
- errno = err;
- return 1;
}
#else
-int GP_MatchJPG(const void GP_UNUSED(*buf))
-{
- errno = ENOSYS;
- return -1;
-}
-
GP_Context *GP_ReadJPG(GP_IO GP_UNUSED(*io),
GP_ProgressCallback GP_UNUSED(*callback))
{
@@ -545,22 +574,21 @@ GP_Context *GP_ReadJPG(GP_IO GP_UNUSED(*io),
return NULL;
}
-int GP_ReadJPGMetaData(GP_IO GP_UNUSED(*io), GP_MetaData GP_UNUSED(*data))
+int GP_WriteJPG(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback)
{
errno = ENOSYS;
return 1;
}
-int GP_LoadJPGMetaData(const char GP_UNUSED(*src_path),
- GP_MetaData GP_UNUSED(*data))
+int GP_ReadJPGMetaData(GP_IO GP_UNUSED(*io), GP_MetaData GP_UNUSED(*data))
{
errno = ENOSYS;
return 1;
}
-int GP_SaveJPG(const GP_Context GP_UNUSED(*src),
- const char GP_UNUSED(*dst_path),
- GP_ProgressCallback GP_UNUSED(*callback))
+int GP_LoadJPGMetaData(const char GP_UNUSED(*src_path),
+ GP_MetaData GP_UNUSED(*data))
{
errno = ENOSYS;
return 1;
@@ -573,10 +601,16 @@ GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback)
return GP_LoaderLoadImage(&GP_JPG, src_path, callback);
}
+int GP_SaveJPG(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ return GP_LoaderSaveImage(&GP_JPG, src, dst_path, callback);
+}
+
struct GP_Loader GP_JPG = {
#ifdef HAVE_JPEG
.Read = GP_ReadJPG,
- .Save = GP_SaveJPG,
+ .Write = GP_WriteJPG,
.save_ptypes = out_pixel_types,
#endif
.Match = GP_MatchJPG,
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index 12ca2fc8..f1d51f24 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -126,9 +126,9 @@ void GP_ListLoaders(void)
for (i = 0; loaders[i]; i++) {
printf("Format: %sn", loaders[i]->fmt_name);
printf("Read:t%sn", loaders[i]->Read ? "Yes" : "No");
- printf("Save:t%sn", loaders[i]->Save ? "Yes" : "No");
+ printf("Write:t%sn", loaders[i]->Write ? "Yes" : "No");
if (loaders[i]->save_ptypes) {
- printf("Saves Pixel Types: ");
+ printf("Write Pixel Types: ");
for (j = 0; loaders[i]->save_ptypes[j]; j++) {
GP_PixelType ptype = loaders[i]->save_ptypes[j];
printf("%s ", GP_PixelTypeName(ptype));
@@ -282,6 +282,8 @@ GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path,
GP_Context *res;
int err;
+ GP_DEBUG(1, "Loading Image '%s'", src_path);
+
if (!self->Read) {
errno = ENOSYS;
return NULL;
@@ -384,6 +386,37 @@ out:
return 1;
}
+int GP_LoaderSaveImage(const GP_Loader *self, const GP_Context *src,
+ const char *dst_path, GP_ProgressCallback *callback)
+{
+ GP_IO *io;
+
+ GP_DEBUG(1, "Saving image '%s' format %s", dst_path, self->fmt_name);
+
+ if (!self->Write) {
+ errno = ENOSYS;
+ return 1;
+ }
+
+ io = GP_IOFile(dst_path, GP_IO_WRONLY);
+
+ if (!io)
+ return 1;
+
+ if (self->Write(src, io, callback)) {
+ GP_IOClose(io);
+ unlink(dst_path);
+ return 1;
+ }
+
+ if (GP_IOClose(io)) {
+ unlink(dst_path);
+ return 1;
+ }
+
+ return 0;
+}
+
int GP_SaveImage(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -394,11 +427,7 @@ int GP_SaveImage(const GP_Context *src, const char *dst_path,
return 1;
}
- if (l->Save)
- return l->Save(src, dst_path, callback);
-
- errno = ENOSYS;
- return 1;
+ return GP_LoaderSaveImage(l, src, dst_path, callback);
}
const GP_Loader *GP_LoaderBySignature(const void *buf)
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index deabf9ab..924eae37 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -522,38 +522,41 @@ static int write_png_data(const GP_Context *src, png_structp png,
return 0;
}
-int GP_SavePNG(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback)
+static void write_data(png_structp png_ptr, png_bytep data, png_size_t len)
+{
+ GP_IO *io = png_get_io_ptr(png_ptr);
+
+ if (GP_IOWrite(io, data, len) != (ssize_t)len)
+ png_error(png_ptr, "Write Error");
+}
+
+static void flush_data(png_structp png_ptr)
+{
+ (void)png_ptr;
+}
+
+int GP_WritePNG(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback)
{
- FILE *f;
png_structp png;
png_infop png_info = NULL;
int err;
- GP_DEBUG(1, "Saving PNG Image '%s'", dst_path);
+ GP_DEBUG(1, "Writing PNG Image to I/O (%p)", io);
if (prepare_png_header(src, NULL, NULL, NULL)) {
GP_DEBUG(1, "Can't save png with %s pixel type",
GP_PixelTypeName(src->pixel_type));
- err = ENOSYS;
- goto err0;
- }
-
- f = fopen(dst_path, "wb");
-
- if (f == NULL) {
- err = errno;
- GP_DEBUG(1, "Failed to open '%s' for writing: %s",
- dst_path, strerror(errno));
- goto err0;
+ errno = ENOSYS;
+ return 1;
}
png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png == NULL) {
GP_DEBUG(1, "Failed to allocate PNG write buffer");
- err = ENOMEM;
- goto err2;
+ errno = ENOMEM;
+ return 1;
}
png_info = png_create_info_struct(png);
@@ -561,17 +564,17 @@ int GP_SavePNG(const GP_Context *src, const char *dst_path,
if (png_info == NULL) {
GP_DEBUG(1, "Failed to allocate PNG info buffer");
err = ENOMEM;
- goto err3;
+ goto err;
}
if (setjmp(png_jmpbuf(png))) {
GP_DEBUG(1, "Failed to write PNG file :(");
//TODO: should we get better error description from libpng?
err = EIO;
- goto err3;
+ goto err;
}
- png_init_io(png, f);
+ png_set_write_fn(png, io, write_data, flush_data);
int bit_endian_flag = 0;
/* Fill png header and prepare for data */
@@ -579,28 +582,15 @@ int GP_SavePNG(const GP_Context *src, const char *dst_path,
/* Write bitmap buffer */
if ((err = write_png_data(src, png, callback, bit_endian_flag)))
- goto err3;
+ goto err;
png_write_end(png, png_info);
png_destroy_write_struct(&png, &png_info);
- if (fclose(f)) {
- err = errno;
- GP_DEBUG(1, "Failed to close file '%s': %s",
- dst_path, strerror(errno));
- goto err1;
- }
-
GP_ProgressCallbackDone(callback);
-
return 0;
-err3:
+err:
png_destroy_write_struct(&png, png_info == NULL ? NULL : &png_info);
-err2:
- fclose(f);
-err1:
- unlink(dst_path);
-err0:
errno = err;
return 1;
}
@@ -632,9 +622,8 @@ int GP_LoadPNGMetaData(const char GP_UNUSED(*src_path), GP_MetaData GP_UNUSED(*d
return 1;
}
-int GP_SavePNG(const GP_Context GP_UNUSED(*src),
- const char GP_UNUSED(*dst_path),
- GP_ProgressCallback GP_UNUSED(*callback))
+int GP_WritePNG(const GP_Context *src, GP_IO GP_UNUSED(*io),
+ GP_ProgressCallback *callback)
{
errno = ENOSYS;
return 1;
@@ -647,10 +636,16 @@ GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback)
return GP_LoaderLoadImage(&GP_PNG, src_path, callback);
}
+int GP_SavePNG(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ return GP_LoaderSaveImage(&GP_PNG, src, dst_path, callback);
+}
+
GP_Loader GP_PNG = {
#ifdef HAVE_LIBPNG
.Read = GP_ReadPNG,
- .Save = GP_SavePNG,
+ .Write = GP_WritePNG,
.save_ptypes = save_ptypes,
#endif
.Match = GP_MatchPNG,
diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c
index ba459183..4f3f646d 100644
--- a/libs/loaders/GP_PNM.c
+++ b/libs/loaders/GP_PNM.c
@@ -348,17 +348,17 @@ static int get_ascii_int(struct buf *buf, int *val)
/*
* Five times faster than printf("%u", byte)
*/
-static inline int write_ascii_byte(FILE *f, uint8_t byte)
+static inline int write_ascii_byte(GP_IO *io, uint8_t byte)
{
if (byte >= 100)
- fputc_unlocked('0' + byte/100, f);
+ GP_IOPutC(io, '0' + byte/100);
if (byte >= 10)
- fputc_unlocked('0' + (byte%100)/10, f);
+ GP_IOPutC(io, '0' + (byte%100)/10);
- fputc_unlocked('0' + (byte%10), f);
+ GP_IOPutC(io, '0' + (byte%10));
- return fputc_unlocked(' ', f) == EOF;
+ return GP_IOPutC(io, ' ');
}
/*
@@ -631,7 +631,7 @@ static int load_bin_rgb888(struct buf *buf, GP_Context *ctx,
return 0;
}
-static int save_ascii(FILE *f, const GP_Context *ctx,
+static int save_ascii(GP_IO *io, const GP_Context *ctx,
GP_ProgressCallback *cb, int inv)
{
uint32_t x, y;
@@ -644,7 +644,7 @@ static int save_ascii(FILE *f, const GP_Context *ctx,
if (inv)
val = !val;
- if (write_ascii_byte(f, val)) {
+ if (write_ascii_byte(io, val)) {
err = errno;
GP_DEBUG(1, "Failed to write data");
return err;
@@ -655,7 +655,9 @@ static int save_ascii(FILE *f, const GP_Context *ctx,
GP_DEBUG(1, "Operation aborted");
return ECANCELED;
}
- fprintf(f, "n");
+
+ if (GP_IOPutC(io, 'n'))
+ return errno;
}
GP_ProgressCallbackDone(cb);
@@ -717,14 +719,13 @@ static GP_PixelType pbm_save_pixels[] = {
GP_PIXEL_UNKNOWN,
};
-int GP_SavePBM(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback)
+int GP_WritePBM(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback)
{
- FILE *f;
+ GP_IO *bio;
int err;
- GP_DEBUG(1, "Saving context %ux%u %s to '%s'",
- src->w, src->h, GP_PixelTypeName(src->pixel_type), dst_path);
+ GP_DEBUG(1, "Writing PBM into I/O (%p)", io);
if (src->pixel_type != GP_PIXEL_G1) {
GP_DEBUG(1, "Invalid pixel type '%s'",
@@ -733,27 +734,22 @@ int GP_SavePBM(const GP_Context *src, const char *dst_path,
return 1;
}
- f = fopen(dst_path, "w");
-
- if (f == NULL)
+ bio = GP_IOWBuffer(io, 0);
+ if (!bio)
return 1;
- if (fprintf(f, "P1n%u %un",
- (unsigned int) src->w, (unsigned int) src->h) < 0) {
- err = EIO;
- goto err0;
+ if (GP_IOPrintF(io, "P1n%u %un",
+ (unsigned int) src->w, (unsigned int) src->h)) {
+ err = errno;
+ goto err;
}
- if ((err = save_ascii(f, src, callback, 1)))
- goto err0;
+ if ((err = save_ascii(bio, src, callback, 1)))
+ goto err;
- if (fclose(f))
- goto err0;
-
- return 0;
-err0:
- fclose(f);
- unlink(dst_path);
+ return GP_IOClose(bio);
+err:
+ GP_IOClose(bio);
errno = err;
return 1;
}
@@ -892,15 +888,13 @@ static GP_PixelType pgm_save_pixels[] = {
GP_PIXEL_UNKNOWN,
};
-int GP_SavePGM(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback)
+int GP_WritePGM(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback)
{
- FILE *f;
- int depth;
- int err = EIO;
+ int err, depth;
+ GP_IO *bio;
- GP_DEBUG(1, "Saving context %ux%u %s to '%s'",
- src->w, src->h, GP_PixelTypeName(src->pixel_type), dst_path);
+ GP_DEBUG(1, "Writing PGM to I/O (%p)", io);
if ((depth = pixel_to_depth(src->pixel_type)) == -1) {
GP_DEBUG(1, "Invalid pixel type '%s'",
@@ -909,34 +903,22 @@ int GP_SavePGM(const GP_Context *src, const char *dst_path,
return 1;
}
- f = fopen(dst_path, "w");
+ bio = GP_IOWBuffer(io, 0);
+ if (!bio)
+ return 1;
- if (f == NULL) {
+ if (GP_IOPrintF(io, "P2n%u %un%un",
+ (unsigned int) src->w, (unsigned int) src->h, depth)) {
err = errno;
- GP_DEBUG(1, "Failed to open file '%s': %s",
- dst_path, strerror(errno));
- goto err0;
+ goto err;
}
- if (fprintf(f, "P2n%u %un%un",
- (unsigned int) src->w, (unsigned int) src->h, depth) < 0)
- goto err1;
-
- if ((err = save_ascii(f, src, callback, 0)))
- goto err1;
-
- if (fclose(f)) {
- err = errno;
- GP_DEBUG(1, "Failed to close file '%s': %s",
- dst_path, strerror(errno));
- goto err0;
- }
+ if ((err = save_ascii(bio, src, callback, 0)))
+ goto err;
- return 0;
-err1:
- fclose(f);
-err0:
- unlink(dst_path);
+ return GP_IOClose(bio);
+err:
+ GP_IOClose(bio);
errno = err;
return 1;
}
@@ -1020,7 +1002,7 @@ static int write_binary_ppm(FILE *f, GP_Context *src)
return 0;
}
-static int save_ascii_rgb888(FILE *f, const GP_Context *ctx,
+static int save_ascii_rgb888(GP_IO *io, const GP_Context *ctx,
GP_LineConvert Convert, GP_ProgressCallback *cb)
{
uint32_t x, y;
@@ -1037,9 +1019,9 @@ static int save_ascii_rgb888(FILE *f, const GP_Context *ctx,
}
for (x = 0; x < ctx->w; x++) {
- ret |= write_ascii_byte(f, addr[2]);
- ret |= write_ascii_byte(f, addr[1]);
- ret |= write_ascii_byte(f, addr[0]);
+ ret |= write_ascii_byte(io, addr[2]);
+ ret |= write_ascii_byte(io, addr[1]);
+ ret |= write_ascii_byte(io, addr[0]);
if (ret)
return errno;
@@ -1052,7 +1034,7 @@ static int save_ascii_rgb888(FILE *f, const GP_Context *ctx,
return ECANCELED;
}
- if (fprintf(f, "n") < 0)
+ if (GP_IOPutC(io, 'n'))
return errno;
}
@@ -1065,16 +1047,15 @@ static GP_PixelType ppm_save_pixels[] = {
GP_PIXEL_UNKNOWN,
};
-int GP_SavePPM(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback)
+int GP_WritePPM(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback)
{
GP_Pixel out_pix;
GP_LineConvert Convert;
- FILE *f;
- int err = EIO;
+ GP_IO *bio;
+ int err = 0;
- GP_DEBUG(1, "Saving context %ux%u %s to '%s'",
- src->w, src->h, GP_PixelTypeName(src->pixel_type), dst_path);
+ GP_DEBUG(1, "Writing PPM into I/O (%p)", io);
out_pix = GP_LineConvertible(src->pixel_type, ppm_save_pixels);
@@ -1085,37 +1066,25 @@ int GP_SavePPM(const GP_Context *src, const char *dst_path,
return 1;
}
- f = fopen(dst_path, "w");
+ bio = GP_IOWBuffer(io, 0);
+ if (!bio)
+ return 1;
- if (f == NULL) {
+ if (GP_IOPrintF(io, "P3n%u %un255n",
+ (unsigned int) src->w, (unsigned int) src->h)) {
err = errno;
- GP_DEBUG(1, "Failed to open file '%s': %s",
- dst_path, strerror(errno));
- goto err0;
+ goto err;
}
- if (fprintf(f, "P3n%u %un255n",
- (unsigned int) src->w, (unsigned int) src->h) < 0)
- goto err1;
-
Convert = GP_LineConvertGet(src->pixel_type, out_pix);
- if ((err = save_ascii_rgb888(f, src, Convert, callback)))
- goto err1;
+ if ((err = save_ascii_rgb888(bio, src, Convert, callback)))
+ goto err;
- 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:
+ return GP_IOClose(bio);
+err:
+ GP_IOClose(bio);
errno = err;
- unlink(dst_path);
return 1;
}
@@ -1153,20 +1122,20 @@ static GP_PixelType pnm_save_pixels[] = {
GP_PIXEL_UNKNOWN,
};
-int GP_SavePNM(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback)
+int GP_WritePNM(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback)
{
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);
+ return GP_WritePGM(src, io, callback);
case GP_PIXEL_RGB888:
- return GP_SavePPM(src, dst_path, callback);
+ return GP_WritePPM(src, io, callback);
default:
if (GP_LineConvertible(src->pixel_type, ppm_save_pixels))
- return GP_SavePPM(src, dst_path, callback);
+ return GP_WritePPM(src, io, callback);
errno = EINVAL;
return 1;
@@ -1178,24 +1147,48 @@ GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback)
return GP_LoaderLoadImage(&GP_PBM, src_path, callback);
}
+int GP_SavePBM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ return GP_LoaderSaveImage(&GP_PBM, src, dst_path, callback);
+}
+
GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback)
{
return GP_LoaderLoadImage(&GP_PGM, src_path, callback);
}
+int GP_SavePGM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ return GP_LoaderSaveImage(&GP_PGM, src, dst_path, callback);
+}
+
GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback)
{
return GP_LoaderLoadImage(&GP_PPM, src_path, callback);
}
+int GP_SavePPM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ return GP_LoaderSaveImage(&GP_PPM, src, dst_path, callback);
+}
+
GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback)
{
return GP_LoaderLoadImage(&GP_PNM, src_path, callback);
}
+int GP_SavePNM(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ return GP_LoaderSaveImage(&GP_PNM, src, dst_path, callback);
+}
+
struct GP_Loader GP_PBM = {
.Read = GP_ReadPBM,
- .Save = GP_SavePBM,
+ .Write = GP_WritePBM,
.save_ptypes = pbm_save_pixels,
.Match = GP_MatchPBM,
@@ -1205,7 +1198,7 @@ struct GP_Loader GP_PBM = {
struct GP_Loader GP_PGM = {
.Read = GP_ReadPGM,
- .Save = GP_SavePGM,
+ .Write = GP_WritePGM,
.save_ptypes = pgm_save_pixels,
.Match = GP_MatchPGM,
@@ -1215,7 +1208,7 @@ struct GP_Loader GP_PGM = {
struct GP_Loader GP_PPM = {
.Read = GP_ReadPPM,
- .Save = GP_SavePPM,
+ .Write = GP_WritePPM,
.save_ptypes = ppm_save_pixels,
.Match = GP_MatchPPM,
@@ -1225,7 +1218,7 @@ struct GP_Loader GP_PPM = {
struct GP_Loader GP_PNM = {
.Read = GP_ReadPNM,
- .Save = GP_SavePNM,
+ .Write = GP_WritePNM,
.save_ptypes = pnm_save_pixels,
/*
* Avoid double Match
diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c
index 400d6734..29f4812e 100644
--- a/libs/loaders/GP_TIFF.c
+++ b/libs/loaders/GP_TIFF.c
@@ -40,10 +40,6 @@
#include "GP_TIFF.h"
-#ifdef HAVE_TIFF
-
-#include <tiffio.h>
-
#define TIFF_HEADER_LITTLE "IIx2a0"
#define TIFF_HEADER_BIG "MM0x2a"
@@ -58,6 +54,10 @@ int GP_MatchTIFF(const void *buf)
return 0;
}
+#ifdef HAVE_TIFF
+
+#include <tiffio.h>
+
static const char *compression_name(uint16_t compression)
{
switch (compression) {
@@ -442,10 +442,7 @@ static tsize_t tiff_io_read(thandle_t io, void *buf, tsize_t size)
static tsize_t tiff_io_write(thandle_t io, void *buf, tsize_t size)
{
- (void) io;
- (void) buf;
- GP_WARN("stub called");
- return size;
+ return GP_IOWrite(io, buf, size);
}
static toff_t tiff_io_seek(thandle_t io, toff_t offset, int whence)
@@ -643,12 +640,14 @@ static GP_PixelType save_ptypes[] = {
GP_PIXEL_UNKNOWN,
};
-int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
- GP_ProgressCallback *callback)
+int GP_WriteTIFF(const GP_Context *src, GP_IO *io,
+ GP_ProgressCallback *callback)
{
TIFF *tiff;
int err = 0;
+ GP_DEBUG(1, "Writing TIFF to I/O (%p)", io);
+
if (GP_PixelHasFlags(src->pixel_type, GP_PIXEL_HAS_ALPHA)) {
GP_DEBUG(1, "Alpha channel not supported yet");
errno = ENOSYS;
@@ -673,11 +672,13 @@ int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
}
/* Open TIFF image */
- tiff = TIFFOpen(dst_path, "w");
+ tiff = TIFFClientOpen("GFXprim IO", "w", io, tiff_io_read,
+ tiff_io_write, tiff_io_seek, tiff_io_close,
+ tiff_io_size, NULL, NULL);
- if (tiff == NULL) {
- GP_DEBUG(1, "Failed to open tiff '%s'", dst_path);
- //ERRNO?
+ if (!tiff) {
+ GP_DEBUG(1, "TIFFClientOpen failed");
+ errno = EIO;
return 1;
}
@@ -706,7 +707,6 @@ int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
if (err) {
TIFFClose(tiff);
- unlink(dst_path);
errno = err;
return 1;
}
@@ -718,19 +718,6 @@ int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
#else
-int GP_MatchTIFF(const void GP_UNUSED(*buf))
-{
- errno = ENOSYS;
- return -1;
-}
-
-int GP_OpenTIFF(const char GP_UNUSED(*src_path),
- void GP_UNUSED(**t))
-{
- errno = ENOSYS;
- return 1;
-}
-
GP_Context *GP_ReadTIFF(GP_IO GP_UNUSED(*io),
GP_ProgressCallback GP_UNUSED(*callback))
{
@@ -738,9 +725,8 @@ GP_Context *GP_ReadTIFF(GP_IO GP_UNUSED(*io),
return NULL;
}
-int GP_SaveTIFF(const GP_Context GP_UNUSED(*src),
- const char GP_UNUSED(*dst_path),
- GP_ProgressCallback GP_UNUSED(*callback))
+int GP_WriteTIFF(const GP_Context GP_UNUSED(*src), GP_IO GP_UNUSED(*io),
+ GP_ProgressCallback GP_UNUSED(*callback))
{
errno = ENOSYS;
return 1;
@@ -753,10 +739,16 @@ GP_Context *GP_LoadTIFF(const char *src_path, GP_ProgressCallback *callback)
return GP_LoaderLoadImage(&GP_TIFF, src_path, callback);
}
+int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
+ GP_ProgressCallback *callback)
+{
+ return GP_LoaderSaveImage(&GP_TIFF, src, dst_path, callback);
+}
+
struct GP_Loader GP_TIFF = {
#ifdef HAVE_TIFF
.Read = GP_ReadTIFF,
- .Save = GP_SaveTIFF,
+ .Write = GP_WriteTIFF,
.save_ptypes = save_ptypes,
#endif
.Match = GP_MatchTIFF,
http://repo.or.cz/w/gfxprim.git/commit/983c8bab63c33eef9e7de3278cd5a8329486…
commit 983c8bab63c33eef9e7de3278cd5a8329486ab93
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jun 15 21:16:50 2014 +0200
loaders: IO: Add new functions
* Add GP_IOFlush() that works like Write() but either writes whole
or returns an error.
* Add GP_IOWBuffer a write buffered I/O that can be created on the top of an I/O.
* Add GP_IOPutC() unlike the libc putc() it returns zero on success.
* Add GP_IOPrintF()
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt
index bb834f97..bf8cb76c 100644
--- a/build/syms/Loaders_symbols.txt
+++ b/build/syms/Loaders_symbols.txt
@@ -118,13 +118,16 @@ GP_LineConvertGet
GP_IOFile
GP_IOMem
GP_IOSubIO
+GP_IOWBuffer
GP_IOMark
GP_IOSize
GP_IOFill
+GP_IOFlush
GP_IOReadF
GP_IOReadB2
GP_IOReadB4
GP_IOWriteF
+GP_IOPrintF
GP_IOZlib
GP_IOZlibReset
diff --git a/include/loaders/GP_IO.h b/include/loaders/GP_IO.h
index 19a1c78e..041321a3 100644
--- a/include/loaders/GP_IO.h
+++ b/include/loaders/GP_IO.h
@@ -79,6 +79,14 @@ static inline off_t GP_IOSeek(GP_IO *io, off_t off, enum GP_IOWhence whence)
return io->Seek(io, off, whence);
}
+/*
+ * PutC returns zero on success, non-zero on failure.
+ */
+static inline int GP_IOPutC(GP_IO *io, char c)
+{
+ return io->Write(io, &c, 1) != 1;
+}
+
//static inline void *GP_IOMap(GP_IO *io, size_t len, off_t off)
//{
// return io->Map(io, len, off);
@@ -120,6 +128,13 @@ off_t GP_IOSize(GP_IO *io);
int GP_IOFill(GP_IO *io, void *buf, size_t size);
/*
+ * Like Write but either writes whole buffer or retuns error.
+ *
+ * Returns zero on succes non-zero on failure.
+ */
+int GP_IOFlush(GP_IO *io, void *buf, size_t size);
+
+/*
* Marks a current position, returns to mark in I/O stream.
*/
enum GP_IOMarkTypes {
@@ -134,7 +149,7 @@ int GP_IOMark(GP_IO *self, enum GP_IOMarkTypes type);
*
*
*/
-enum GP_IOReadFTypes {
+enum GP_IOFTypes {
/* Constant byte in lower half */
GP_IO_CONST = 0x0000,
/* Pointer to one byte */
@@ -176,6 +191,14 @@ int GP_IOReadF(GP_IO *self, uint16_t *types, ...);
int GP_IOWriteF(GP_IO *self, uint16_t *types, ...);
/*
+ * Printf like function.
+ *
+ * Returns zero on success, non-zero on failure.
+ */
+int GP_IOPrintF(GP_IO *self, const char *fmt, ...)
+ __attribute__ ((format (printf, 2, 3)));
+
+/*
* GP_IOReadF wrappers for convinient reading of single value
*/
int GP_IOReadB4(GP_IO *io, uint32_t *val);
@@ -213,4 +236,11 @@ GP_IO *GP_IOMem(void *buf, size_t size, void (*free)(void *));
*/
GP_IO *GP_IOSubIO(GP_IO *pio, size_t size);
+/*
+ * Creates a writeable buffered I/O on the top of the existing I/O.
+ *
+ * Passing zero as bsize select default buffer size.
+ */
+GP_IO *GP_IOWBuffer(GP_IO *pio, size_t bsize);
+
#endif /* LOADERS_GP_IO_H */
diff --git a/libs/loaders/GP_IO.c b/libs/loaders/GP_IO.c
index 145058b8..329fdd43 100644
--- a/libs/loaders/GP_IO.c
+++ b/libs/loaders/GP_IO.c
@@ -374,6 +374,82 @@ GP_IO *GP_IOSubIO(GP_IO *pio, size_t size)
return io;
}
+struct buf_io {
+ GP_IO *io;
+ size_t bsize;
+ size_t bpos;
+ uint8_t buf[];
+};
+
+static int wbuf_close(GP_IO *io)
+{
+ struct buf_io *buf_io = GP_IO_PRIV(io);
+ int ret = 0;
+
+ GP_DEBUG(1, "Closing BufferIO (from %p)", buf_io->io);
+
+ if (buf_io->bpos) {
+ if (GP_IOFlush(buf_io->io, buf_io->buf, buf_io->bsize))
+ ret = 1;
+ }
+
+ free(io);
+ return ret;
+}
+
+static ssize_t buf_write(GP_IO *io, void *buf, size_t size)
+{
+ struct buf_io *buf_io = GP_IO_PRIV(io);
+ size_t bfree = buf_io->bsize - buf_io->bpos;
+
+ if (bfree < size) {
+ GP_DEBUG(1, "Flusing BufferIO (%p)", io);
+ if (GP_IOFlush(buf_io->io, buf_io->buf, buf_io->bpos))
+ return -1;
+ buf_io->bpos = 0;
+ }
+
+ if (size > buf_io->bsize) {
+ GP_DEBUG(1, "Buffer too large, doing direct write (%p)", io);
+ if (GP_IOFlush(buf_io->io, buf, size))
+ return -1;
+ return size;
+ }
+
+ memcpy(buf_io->buf + buf_io->bpos, buf, size);
+ buf_io->bpos += size;
+ return size;
+}
+
+GP_IO *GP_IOWBuffer(GP_IO *pio, size_t bsize)
+{
+ GP_IO *io;
+ struct buf_io *buf_io;
+
+ if (!bsize)
+ bsize = 512;
+
+ GP_DEBUG(1, "Creating IOWBuffer (from %p) size=%zu", pio, bsize);
+
+ //TODO: Do not create buffer IO for MemIO, just copy the callbacks to new IO
+ io = malloc(sizeof(GP_IO) + sizeof(*buf_io) + bsize);
+
+ if (!io)
+ return NULL;
+
+ io->Write = buf_write;
+ io->Close = wbuf_close;
+ io->Read = NULL;
+ io->Seek = NULL;
+
+ buf_io = GP_IO_PRIV(io);
+ buf_io->io = pio;
+ buf_io->bsize = bsize;
+ buf_io->bpos = 0;
+
+ return io;
+}
+
int GP_IOMark(GP_IO *self, enum GP_IOMarkTypes type)
{
off_t ret;
@@ -441,6 +517,58 @@ int GP_IOFill(GP_IO *io, void *buf, size_t size)
return 0;
}
+int GP_IOFlush(GP_IO *io, void *buf, size_t size)
+{
+ size_t wrote = 0;
+ int ret;
+
+ do {
+ ret = GP_IOWrite(io, (char*)buf + wrote, size - wrote);
+
+ if (ret <= 0) {
+ GP_DEBUG(1, "Failed to flush buffer: %s",
+ strerror(errno));
+ return 1;
+ }
+
+ wrote += ret;
+
+ } while (wrote < size);
+
+ return 0;
+}
+
+int GP_IOPrintF(GP_IO *io, const char *fmt, ...)
+{
+ va_list va, vac;
+ size_t size;
+ int ret;
+ char buf[1024];
+ char *bufp = buf;
+
+ va_start(va, fmt);
+ va_copy(vac, va);
+ size = vsnprintf(buf, sizeof(buf), fmt, vac);
+ va_end(vac);
+
+ if (size >= sizeof(buf)) {
+ bufp = malloc(size+1);
+ if (!bufp)
+ return 1;
+
+ vsnprintf(bufp, size, fmt, va);
+ }
+
+ ret = GP_IOFlush(io, bufp, size);
+
+ if (size >= sizeof(buf))
+ free(bufp);
+
+ va_end(va);
+
+ return ret;
+}
+
#define TYPE(x) ((x) & GP_IO_TYPE_MASK)
#define VAL(x) ((x) & ~GP_IO_TYPE_MASK)
-----------------------------------------------------------------------
Summary of changes:
build/syms/Loaders_symbols.txt | 11 ++
demos/c_simple/loaders_register.c | 38 ++++----
include/loaders/GP_IO.h | 32 ++++++-
include/loaders/GP_JPG.h | 8 ++-
include/loaders/GP_Loader.h | 19 +++-
include/loaders/GP_PNG.h | 9 ++-
include/loaders/GP_PNM.h | 12 +++
include/loaders/GP_TIFF.h | 8 ++-
libs/loaders/GP_BMP.c | 27 +-----
libs/loaders/GP_IO.c | 128 ++++++++++++++++++++++++
libs/loaders/GP_JPG.c | 146 +++++++++++++++++-----------
libs/loaders/GP_Loader.c | 43 +++++++--
libs/loaders/GP_PNG.c | 73 +++++++-------
libs/loaders/GP_PNM.c | 197 ++++++++++++++++++-------------------
libs/loaders/GP_TIFF.c | 56 +++++------
15 files changed, 520 insertions(+), 287 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
14 Jun '14
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 7044b9ef7967a50a1f0b437ad5a0554325484296 (commit)
via 004c0cb918280c3a03cd9f1b3b1e5d27476defcb (commit)
via 11ff1196e509567cea23f3bf71653f75c23ac1e8 (commit)
from e0193a071feaf04b54c65348bf11db0d8db6c4ac (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/7044b9ef7967a50a1f0b437ad5a055432548…
commit 7044b9ef7967a50a1f0b437ad5a0554325484296
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jun 14 01:13:06 2014 +0200
loaders: ZIP: Seek to the end of the Zlib IO.
We need to Seek to the end of the Zlib I/O because:
* Files that are not images are not read at all
* There may be bytes that are not consumed by the loader
(known to happen)
and we have to get to the next ZIP header.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_ZIP.c b/libs/loaders/GP_ZIP.c
index 440aabbf..55d1cdaa 100644
--- a/libs/loaders/GP_ZIP.c
+++ b/libs/loaders/GP_ZIP.c
@@ -324,6 +324,7 @@ static GP_Context *zip_next_file(struct zip_priv *priv,
GP_IOClose(io);
goto out;
*/
+
io = GP_IOZlib(priv->io, header.comp_size);
if (!io)
goto out;
@@ -333,6 +334,15 @@ static GP_Context *zip_next_file(struct zip_priv *priv,
if (errno == ECANCELED)
err = errno;
+ /*
+ * We need to finish the Zlib IO for any of:
+ *
+ * - File is not image -> need to get to the end of the record
+ * - All image data were not consumed by loader (may happen)
+ */
+ if (GP_IOSeek(io, 0, GP_IO_SEEK_END) == (off_t)-1)
+ GP_DEBUG(1, "Failed to seek Zlib IO");
+
GP_IOClose(io);
if (header.flags & FLAG_DATA_DESC_HEADER) {
http://repo.or.cz/w/gfxprim.git/commit/004c0cb918280c3a03cd9f1b3b1e5d27476d…
commit 004c0cb918280c3a03cd9f1b3b1e5d27476defcb
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jun 14 01:12:30 2014 +0200
loaders; IOZlib: Add Seek to end with offset=0
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_IOZlib.c b/libs/loaders/GP_IOZlib.c
index f62c831e..21675d60 100644
--- a/libs/loaders/GP_IOZlib.c
+++ b/libs/loaders/GP_IOZlib.c
@@ -146,6 +146,20 @@ static int zlib_reset(struct priv *priv)
return 0;
}
+static off_t zlib_seek_end(GP_IO *io)
+{
+ struct priv *priv = GP_IO_PRIV(io);
+ char buf[BUFS];
+ int ret;
+
+ while ((ret = zlib_read(io, buf, sizeof(buf))) > 0);
+
+ if (ret < 0)
+ return (off_t)-1;
+
+ return priv->bytes_read;
+}
+
static off_t zlib_seek(GP_IO *io, off_t offset, enum GP_IOWhence whence)
{
struct priv *priv = GP_IO_PRIV(io);
@@ -175,6 +189,10 @@ static off_t zlib_seek(GP_IO *io, off_t offset, enum GP_IOWhence whence)
return 0;
}
+
+ if (whence == GP_IO_SEEK_END && offset == 0)
+ return zlib_seek_end(io);
+
out:
errno = ENOSYS;
return (off_t)-1;
http://repo.or.cz/w/gfxprim.git/commit/11ff1196e509567cea23f3bf71653f75c23a…
commit 11ff1196e509567cea23f3bf71653f75c23ac1e8
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jun 14 00:07:18 2014 +0200
doc: Updates for python core and loaders.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/doc/core_python.txt b/doc/core_python.txt
index 6e488244..487b903c 100644
--- a/doc/core_python.txt
+++ b/doc/core_python.txt
@@ -3,12 +3,12 @@ Python Core module
The python binding maps mostly to the C API with the 'GP_' prefix stripped.
-Structures like 'GP_Context' are not created by the 'GP_ContextAlloc()'
+However structures as 'GP_Context' are not created by the 'GP_ContextAlloc()'
function but have proper constructor and destructor to keep the Python
reference counting happy.
-There there are more complicated problems like 'GP_ProgressCallback' which
-needs a proxy function to call the python callback from the C code.
+Then there are a bit more tricky solutions, such as 'GP_ProgressCallback'
+which needs a proxy function to call the python callback from the C code.
Context
~~~~~~~
@@ -29,7 +29,13 @@ Creates a context of a particular size and pixel type.
First two parameters are 'width' and 'height' third is pixel type which is an
enumeration
-May raise 'OSError' with 'ENOMEM' errno if allocation has failed.
+|===============================================================================
+| May raise 'OSError' with errno set to 'ENOMEM' if allocation has failed.
+
+| May raise 'OSError' with errno set to 'EINVAL' for invalid pixel type and/or
+ zero width or height.
+
+|===============================================================================
[source,python]
-------------------------------------------------------------------------------
@@ -88,18 +94,18 @@ import gfxprim.core as core
Copy a rectangle from self to target.
-The blits can do simple conversions same as the 'Convert' functions however
-such blits are slower.
+The blits can do naive conversions (same as 'Convert') however such blits are
+a bit slower.
Blit is clipped.
-TIP: See link:example_py_showimage.html[example] Blit usage.
+TIP: See link:example_py_showimage.html[example Blit usage].
[[Colors_and_Pixels]]
Colors and Pixels
~~~~~~~~~~~~~~~~~
-Pixel in gfxprim is a number large enough to store a pixel value. Pixel is
+Pixel in GFXprim is a number large enough to store a pixel value. Pixel is
passed as a parameter to all drawing functions.
Color is a more abstract representation for example RGB triplet.
@@ -139,9 +145,12 @@ The PixelTypes array stores all supported pixel types
Progress Callback
~~~~~~~~~~~~~~~~~
-Progress callback is a last parameter of link:loaders_python.html[loaders] and
-link:filters_python.html[filters]. It can be either a python function or a
-touple with a function at the first position.
+Progress callback is the last parameter of link:loaders_python.html[loaders]
+and link:filters_python.html[filters]. It can be either a python function or a
+touple with a function at first position. In the latter case the second touple
+element is passed to the callback function as a second parameter. First
+parameter of the callback is a floating point number with the current progress
+in percents.
Progress callback must return an integer number. Returning non-zero will abort
the operation and the function, called with the callback as a parameter, will
@@ -164,8 +173,5 @@ import gfxprim.core as core
Sets and gets the GFXprim debug level. See link:debug.html[debug messages]
description for more details.
-
-
-
These are basic 'Context' methods from core module. Importing other modules
will add some other (for example gfx module adds all drawing functions).
diff --git a/doc/loaders_python.txt b/doc/loaders_python.txt
index a73d1f0e..5f230841 100644
--- a/doc/loaders_python.txt
+++ b/doc/loaders_python.txt
@@ -31,7 +31,7 @@ Loads an image from a file.
First one is general purpose loader function that automatically detects the
file format. The format is detected from file extension first and if this
-fails files signature is used.
+fails link:signatures.html[file signature] is used.
|===============================================================================
| May raise 'OSError' with errno set to 'EPERM', 'EISDIR', 'ENOENT' or any other
-----------------------------------------------------------------------
Summary of changes:
doc/core_python.txt | 34 ++++++++++++++++++++--------------
doc/loaders_python.txt | 2 +-
libs/loaders/GP_IOZlib.c | 18 ++++++++++++++++++
libs/loaders/GP_ZIP.c | 10 ++++++++++
4 files changed, 49 insertions(+), 15 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
13 Jun '14
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 e0193a071feaf04b54c65348bf11db0d8db6c4ac (commit)
via f701094e0e12d08c7f236d086f21887385240097 (commit)
via dc0555059702ca7ce621ebda8c8aa934da6aadd2 (commit)
via 5465a3982ed5266489faac926e1eb6f3288fdb35 (commit)
via 0ae6c2fe86b9fb25483cfd7389096912441a3400 (commit)
from f41246cb1b727024fe62f46daceefc3e810e330a (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/e0193a071feaf04b54c65348bf11db0d8db6…
commit e0193a071feaf04b54c65348bf11db0d8db6c4ac
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 23:38:58 2014 +0200
loaders: Rename Match functions + constify + doc
* Rename MatchExtension to LoaderByFilename
and MatchSignature to LoaderBySignature
* Constify GP_Loader arguments where possible
* Update loaders docs
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt
index 20b54d9d..bb834f97 100644
--- a/build/syms/Loaders_symbols.txt
+++ b/build/syms/Loaders_symbols.txt
@@ -81,8 +81,9 @@ GP_PSD
GP_SaveTmpFile
GP_LoadTmpFile
-GP_MatchSignature
-GP_MatchExtension
+GP_LoaderBySignature
+GP_LoaderByFilename
+GP_LoaderLoadImage
GP_ReadImage
GP_LoadImage
GP_SaveImage
diff --git a/demos/spiv/image_list.c b/demos/spiv/image_list.c
index 9d7a3ff4..be6532c0 100644
--- a/demos/spiv/image_list.c
+++ b/demos/spiv/image_list.c
@@ -69,7 +69,7 @@ static int dir_filter(const struct dirent *d)
//TODO: filter out directories
- if (GP_MatchExtension(d->d_name) == NULL)
+ if (!GP_LoaderByFilename(d->d_name))
return 0;
GP_DEBUG(4, "Adding file '%s'", d->d_name);
diff --git a/doc/loaders.txt b/doc/loaders.txt
index c1d94e8e..0b83df55 100644
--- a/doc/loaders.txt
+++ b/doc/loaders.txt
@@ -36,7 +36,7 @@ returned.
'write()', ...
| 'ENOENT' if file doesn't exist
| 'EACCES' if process doesn't have rights to open the file
-| 'ENOSYS' if GFXprim wasn't compiled with particular library support
+| 'ENOSYS' if GFXprim wasn't compiled with particular format support
| 'ENOMEM' if returned by 'malloc()'
| 'EIO', 'EINVAL' invalid image data (wrong signature, wrong or too short
header or image data)
@@ -110,12 +110,12 @@ Advanced Interface
-------------------------------------------------------------------------------
typedef struct GP_Loader {
/*
- * Loads an image.
+ * Reads an image from an IO stream.
*
- * Returns allocated and initialized bitmap on success, NULL on failure
- * and errno must be set.
+ * Returns newly allocated context cotaining the loaded image or in
+ * case of failure NULL and errno is set.
*/
- GP_Context *(*Load)(const char *src_path, GP_ProgressCallback *callback);
+ GP_Context *(*Read)(GP_IO *io, GP_ProgressCallback *callback);
/*
* Save an image.
@@ -126,6 +126,14 @@ typedef struct GP_Loader {
GP_ProgressCallback *callback);
/*
+ * GP_PIXEL_UNKNOWN terminated array of formats loader supports for save.
+ *
+ * This is _NOT_ a complete list loaders is able to save, due to automatic
+ * conversions (i.e. RGB888 vs BRG888).
+ */
+ const GP_PixelType *save_ptypes;
+
+ /*
* The buffer is filled with 32 bytes from an image start, returns 1 if
* image signature was found zero otherwise.
*/
@@ -136,49 +144,49 @@ typedef struct GP_Loader {
*/
const char *fmt_name;
- /* don't touch */
- struct GP_Loader *next;
-
/*
* NULL terminated array of file extensions.
*/
const char *extensions[];
} GP_Loader;
-
-/*
- * List loaders into the stdout.
- */
-void GP_ListLoaders(void);
-
-/*
- * Register a loader.
- */
-void GP_LoaderRegister(GP_Loader *self);
-
-/*
- * Unregister loader.
- */
-void GP_LoaderUnregister(GP_Loader *self);
-------------------------------------------------------------------------------
The 'GP_Loader' structure describes an image loader.
-The 'Load', 'Save' and 'Match' functions could be NULL if the particular
+The 'Read', 'Save' and 'Match' functions could be NULL if the particular
functionality is not implemented.
The 'fmt_name' is a short string that describes the format. For example:
'Netbpm portable pixmap'.
-The extensions is NULL-terminated array of strings that holds all possible
+The 'extensions' is NULL-terminated array of strings that holds all possible
extensions that are commonly used for this image format.
-All internal loaders are all described in list of this structures which is
-used to implement functions such as 'GP_LoadImage()'.
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_Loader.h>
+/* or */
+#include <GP.h>
+
+void GP_ListLoaders(void);
-You can print currently active loaders via the 'GP_ListLoaders()'. Register and
-unregister your own loaders by 'GP_LoaderRegister()' and
-'GP_LoaderUnregister()'. Once image loader is registered the generic loading
-functions can use it to load and save images.
+int GP_LoaderRegister(const GP_Loader *self);
+
+void GP_LoaderUnregister(const GP_Loader *self);
+-------------------------------------------------------------------------------
+
+The 'GP_ListLoaders()' function prints all currently registered loaders and
+their capabilities into the stdout.
+
+You can register and unregister your own loader by 'GP_LoaderRegister()' and
+'GP_LoaderUnregister()'. Once image loader is registered it's automatically
+used by all loaders functions.
+
+The 'GP_LoaderRegister()' can fail (return non-zero) if you try to register
+loader that is allready registered or if the loaders table is full (the table
+size is compile time constant and there should be space for at least fifty
+user defined loaders). I this cases the errno would be set to 'EEXIST' or
+'ENOSPC' respectively.
TIP: For example usage see image loader registration
link:example_loader_registration.html[example].
@@ -189,7 +197,7 @@ link:example_loader_registration.html[example].
/* or */
#include <GP.h>
-const GP_Loader *GP_MatchSignature(const void *buf)
+const GP_Loader *GP_LoaderBySignature(const void *buf)
-------------------------------------------------------------------------------
Returns pointer to image loader accordingly to image signature or NULL if no
@@ -202,15 +210,30 @@ bytes long.
/* or */
#include <GP.h>
-const GP_Loader *GP_MatchExtension(const char *path)
+const GP_Loader *GP_LoaderByFilename(const char *path)
-------------------------------------------------------------------------------
Matches loader by the file extension. This function does not check that the
-file exists or that it could be opened it only looks at the extension (i.e.
-string after the dot) and matches it against known extensions.
+file exists or that it could be opened etc. It only looks at the file
+extension (i.e. string at the end of the path after a dot) and matches it
+against extensions defined by loaders.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include <loaders/GP_Loader.h>
+/* or */
+#include <GP.h>
+
+GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path,
+ GP_ProgressCallback *callback);
+-------------------------------------------------------------------------------
+
+Loads an image given a loader structure.
+
+Returns NULL and sets errno to 'ENOSYS' loader 'Read()' callback is NULL.
-WARNING: If you attempt to modify the content of the structure the behavior is
- undefined. Most likely the program will crash.
+Otherwise prepares a link:loaders_io.html[GP_IO] from the 'src_path' file,
+calls the 'Read()' callbacks and closes the 'IO' before the call returns.
[[PNG]]
PNG Loader
diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h
index 5277fb41..90aeebb7 100644
--- a/include/loaders/GP_Loader.h
+++ b/include/loaders/GP_Loader.h
@@ -120,19 +120,20 @@ typedef struct GP_Loader {
* Takes pointer to buffer at least 32 bytes long and returns a pointer to
* matched loader or NULL.
*/
-const GP_Loader *GP_MatchSignature(const void *buf);
+const GP_Loader *GP_LoaderBySignature(const void *buf);
/*
- * Tries to match loader by extension. Returns NULL if no loader was found.
+ * Tries to match loader by filename extension. Returns NULL if no loader was
+ * found.
*/
-const GP_Loader *GP_MatchExtension(const char *path);
+const GP_Loader *GP_LoaderByFilename(const char *path);
/*
* Registers additional loader.
*
* Returns zero on success, non-zero if table of loaders was is full.
*/
-int GP_LoaderRegister(GP_Loader *self);
+int GP_LoaderRegister(const GP_Loader *self);
/*
* Unregisters a loader.
@@ -141,7 +142,7 @@ int GP_LoaderRegister(GP_Loader *self);
*
* You can unregister them using this function if you want.
*/
-void GP_LoaderUnregister(GP_Loader *self);
+void GP_LoaderUnregister(const GP_Loader *self);
/*
* Generic LoadImage for a given loader.
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index aa8911b2..12ca2fc8 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -41,7 +41,7 @@
#define MAX_LOADERS 64
-static GP_Loader *loaders[MAX_LOADERS] = {
+static const GP_Loader *loaders[MAX_LOADERS] = {
&GP_JPG,
&GP_PNG,
&GP_TIFF,
@@ -69,7 +69,7 @@ static unsigned int get_last_loader(void)
return i - 1;
}
-int GP_LoaderRegister(GP_Loader *self)
+int GP_LoaderRegister(const GP_Loader *self)
{
unsigned int i;
@@ -99,7 +99,7 @@ int GP_LoaderRegister(GP_Loader *self)
return 0;
}
-void GP_LoaderUnregister(GP_Loader *self)
+void GP_LoaderUnregister(const GP_Loader *self)
{
unsigned int i, last = get_last_loader();
@@ -146,7 +146,7 @@ void GP_ListLoaders(void)
}
}
-static struct GP_Loader *loader_by_extension(const char *ext)
+static const GP_Loader *loader_by_extension(const char *ext)
{
unsigned int i, j;
@@ -178,7 +178,7 @@ static const char *get_ext(const char *path)
return path + i + 1;
}
-static struct GP_Loader *loader_by_filename(const char *path)
+const GP_Loader *GP_LoaderByFilename(const char *path)
{
const char *ext = get_ext(path);
@@ -216,7 +216,7 @@ static const GP_Loader *loader_by_signature(const char *path)
fclose(f);
- ret = GP_MatchSignature(buf);
+ ret = GP_LoaderBySignature(buf);
if (ret == NULL)
errno = ENOSYS;
@@ -254,7 +254,7 @@ GP_Context *GP_ReadImage(GP_IO *io, GP_ProgressCallback *callback)
return NULL;
}
- loader = GP_MatchSignature(buf);
+ loader = GP_LoaderBySignature(buf);
if (!loader) {
GP_DEBUG(1, "Failed to find a loader by signature for"
@@ -325,7 +325,7 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
GP_Context *img;
const GP_Loader *ext_load = NULL, *sig_load;
- ext_load = loader_by_filename(src_path);
+ ext_load = GP_LoaderByFilename(src_path);
if (ext_load) {
img = GP_LoaderLoadImage(ext_load, src_path, callback);
@@ -387,7 +387,7 @@ out:
int GP_SaveImage(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
- struct GP_Loader *l = loader_by_filename(dst_path);
+ const GP_Loader *l = GP_LoaderByFilename(dst_path);
if (l == NULL) {
errno = EINVAL;
@@ -401,7 +401,7 @@ int GP_SaveImage(const GP_Context *src, const char *dst_path,
return 1;
}
-const GP_Loader *GP_MatchSignature(const void *buf)
+const GP_Loader *GP_LoaderBySignature(const void *buf)
{
unsigned int i;
@@ -416,8 +416,3 @@ const GP_Loader *GP_MatchSignature(const void *buf)
return NULL;
}
-
-const GP_Loader *GP_MatchExtension(const char *path)
-{
- return loader_by_filename(path);
-}
diff --git a/tests/loaders/Loader.c b/tests/loaders/Loader.c
index 4494825e..dcc9b921 100644
--- a/tests/loaders/Loader.c
+++ b/tests/loaders/Loader.c
@@ -117,7 +117,7 @@ static int loader_by_extension(void)
return TST_FAILED;
}
- loader = GP_MatchExtension("file.jpg");
+ loader = GP_LoaderByFilename("file.jpg");
if (loader != &GP_JPG) {
tst_msg("Failed to get JPEG loader");
@@ -126,7 +126,7 @@ static int loader_by_extension(void)
tst_msg("Succeded to get JPEG loader");
}
- loader = GP_MatchExtension("file.test");
+ loader = GP_LoaderByFilename("file.test");
if (loader != &test_loader) {
tst_msg("Failed to get registered TEST loader");
@@ -155,7 +155,7 @@ const struct tst_suite tst_suite = {
.tst_fn = register_loader_twice,
.flags = TST_CHECK_MALLOC},
- {.name = "MatchExtension()",
+ {.name = "LoaderByFilename()",
.tst_fn = loader_by_extension,
.flags = TST_CHECK_MALLOC},
http://repo.or.cz/w/gfxprim.git/commit/f701094e0e12d08c7f236d086f2188738524…
commit f701094e0e12d08c7f236d086f21887385240097
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 23:28:32 2014 +0200
loaders; GP_Loader: Fix typo in loaders table.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index 442a8329..aa8911b2 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -48,7 +48,7 @@ static GP_Loader *loaders[MAX_LOADERS] = {
&GP_GIF,
&GP_BMP,
&GP_PBM,
- &GP_PNM,
+ &GP_PGM,
&GP_PPM,
&GP_PNM,
&GP_JP2,
http://repo.or.cz/w/gfxprim.git/commit/dc0555059702ca7ce621ebda8c8aa934da6a…
commit dc0555059702ca7ce621ebda8c8aa934da6aadd2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 23:22:38 2014 +0200
loaders: Add save_ptypes to GP_Loader structure
Add save_ptypes, an array of pixel types supported by the Loader's
Save() method.
Note that these arrays does _NOT_ describe all formats that could be
saved by the loader because most of the loaders use LineConvert() for
trivial conversions (i.e. RGB888 to BRG888 to xRGB888 etc.)
Convinient interface to query if particular pixel type coud be saved by
particular loader will be added later.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/demos/c_simple/loaders_register.c b/demos/c_simple/loaders_register.c
index 246394a5..4c596c40 100644
--- a/demos/c_simple/loaders_register.c
+++ b/demos/c_simple/loaders_register.c
@@ -90,8 +90,14 @@ static int save(const GP_Context *img, const char *dst_path,
return 0;
}
+static GP_PixelType save_ptypes[] = {
+ GP_PIXEL_G2,
+ GP_PIXEL_UNKNOWN,
+};
+
GP_Loader loader = {
.Save = save,
+ .save_ptypes = save_ptypes,
.fmt_name = "ASCII Art",
.extensions = {"txt", NULL},
};
diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h
index 6f07d2ea..5277fb41 100644
--- a/include/loaders/GP_Loader.h
+++ b/include/loaders/GP_Loader.h
@@ -92,6 +92,14 @@ typedef struct GP_Loader {
int (*Save)(const GP_Context *src, const char *dst_path, GP_ProgressCallback *callback);
/*
+ * GP_PIXEL_UNKNOWN terminated array of formats loader supports for save.
+ *
+ * This is _NOT_ a complete list loaders is able to save, due to automatic
+ * conversions (i.e. RGB888 vs BRG888).
+ */
+ const GP_PixelType *save_ptypes;
+
+ /*
* The buffer is filled with 32 bytes from an image start, returns 1 if
* image signature was found zero otherwise.
*/
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index 4313e2de..2d042bf2 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -895,6 +895,7 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path,
struct GP_Loader GP_BMP = {
.Read = GP_ReadBMP,
.Save = GP_SaveBMP,
+ .save_ptypes = out_pixel_types,
.Match = GP_MatchBMP,
.fmt_name = "BMP",
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index ea891712..dfca66fa 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -577,6 +577,7 @@ struct GP_Loader GP_JPG = {
#ifdef HAVE_JPEG
.Read = GP_ReadJPG,
.Save = GP_SaveJPG,
+ .save_ptypes = out_pixel_types,
#endif
.Match = GP_MatchJPG,
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index 763e819b..442a8329 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -127,9 +127,17 @@ void GP_ListLoaders(void)
printf("Format: %sn", loaders[i]->fmt_name);
printf("Read:t%sn", loaders[i]->Read ? "Yes" : "No");
printf("Save:t%sn", loaders[i]->Save ? "Yes" : "No");
+ if (loaders[i]->save_ptypes) {
+ printf("Saves Pixel Types: ");
+ for (j = 0; loaders[i]->save_ptypes[j]; j++) {
+ GP_PixelType ptype = loaders[i]->save_ptypes[j];
+ printf("%s ", GP_PixelTypeName(ptype));
+ }
+ printf("n");
+ }
printf("Match:t%sn", loaders[i]->Match ? "Yes" : "No");
printf("Extensions: ");
- for (j = 0; loaders[i]->extensions[j] != NULL; j++)
+ for (j = 0; loaders[i]->extensions[j]; j++)
printf("%s ", loaders[i]->extensions[j]);
printf("n");
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 1a73c9a8..deabf9ab 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -386,6 +386,20 @@ int GP_LoadPNGMetaData(const char *src_path, GP_MetaData *data)
return ret;
}
+static GP_PixelType save_ptypes[] = {
+ GP_PIXEL_BGR888,
+ GP_PIXEL_RGB888,
+ GP_PIXEL_G1,
+ GP_PIXEL_G2,
+ GP_PIXEL_G4,
+ GP_PIXEL_G8,
+#ifdef GP_PIXEL_G16
+ GP_PIXEL_G16,
+#endif
+ GP_PIXEL_RGBA8888,
+ GP_PIXEL_UNKNOWN,
+};
+
/*
* Maps gfxprim Pixel Type to the PNG format
*/
@@ -637,6 +651,7 @@ GP_Loader GP_PNG = {
#ifdef HAVE_LIBPNG
.Read = GP_ReadPNG,
.Save = GP_SavePNG,
+ .save_ptypes = save_ptypes,
#endif
.Match = GP_MatchPNG,
diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c
index 93bc1b68..ba459183 100644
--- a/libs/loaders/GP_PNM.c
+++ b/libs/loaders/GP_PNM.c
@@ -712,6 +712,11 @@ GP_Context *GP_ReadPBM(GP_IO *io, GP_ProgressCallback *callback)
return read_bitmap(&buf, &header, callback);
}
+static GP_PixelType pbm_save_pixels[] = {
+ GP_PIXEL_G1,
+ GP_PIXEL_UNKNOWN,
+};
+
int GP_SavePBM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -879,6 +884,14 @@ static int pixel_to_depth(GP_Pixel pixel)
}
}
+static GP_PixelType pgm_save_pixels[] = {
+ GP_PIXEL_G1,
+ GP_PIXEL_G2,
+ GP_PIXEL_G4,
+ GP_PIXEL_G8,
+ GP_PIXEL_UNKNOWN,
+};
+
int GP_SavePGM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -1131,6 +1144,15 @@ GP_Context *GP_ReadPNM(GP_IO *io, GP_ProgressCallback *callback)
return ret;
}
+static GP_PixelType pnm_save_pixels[] = {
+ GP_PIXEL_G1,
+ GP_PIXEL_G2,
+ GP_PIXEL_G4,
+ GP_PIXEL_G8,
+ GP_PIXEL_RGB888,
+ GP_PIXEL_UNKNOWN,
+};
+
int GP_SavePNM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -1174,6 +1196,7 @@ GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback)
struct GP_Loader GP_PBM = {
.Read = GP_ReadPBM,
.Save = GP_SavePBM,
+ .save_ptypes = pbm_save_pixels,
.Match = GP_MatchPBM,
.fmt_name = "Netpbm portable Bitmap",
@@ -1183,6 +1206,7 @@ struct GP_Loader GP_PBM = {
struct GP_Loader GP_PGM = {
.Read = GP_ReadPGM,
.Save = GP_SavePGM,
+ .save_ptypes = pgm_save_pixels,
.Match = GP_MatchPGM,
.fmt_name = "Netpbm portable Graymap",
@@ -1192,6 +1216,7 @@ struct GP_Loader GP_PGM = {
struct GP_Loader GP_PPM = {
.Read = GP_ReadPPM,
.Save = GP_SavePPM,
+ .save_ptypes = ppm_save_pixels,
.Match = GP_MatchPPM,
.fmt_name = "Netpbm portable Pixmap",
@@ -1201,6 +1226,7 @@ struct GP_Loader GP_PPM = {
struct GP_Loader GP_PNM = {
.Read = GP_ReadPNM,
.Save = GP_SavePNM,
+ .save_ptypes = pnm_save_pixels,
/*
* Avoid double Match
* This format is covered by PBM, PGM and PPM
diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c
index bcc23b21..400d6734 100644
--- a/libs/loaders/GP_TIFF.c
+++ b/libs/loaders/GP_TIFF.c
@@ -632,6 +632,17 @@ static int save_rgb(TIFF *tiff, const GP_Context *src,
return 0;
}
+static GP_PixelType save_ptypes[] = {
+ GP_PIXEL_BGR888,
+ GP_PIXEL_RGB888,
+ GP_PIXEL_xRGB8888,
+ GP_PIXEL_G1,
+ GP_PIXEL_G2,
+ GP_PIXEL_G4,
+ GP_PIXEL_G8,
+ GP_PIXEL_UNKNOWN,
+};
+
int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -746,6 +757,7 @@ struct GP_Loader GP_TIFF = {
#ifdef HAVE_TIFF
.Read = GP_ReadTIFF,
.Save = GP_SaveTIFF,
+ .save_ptypes = save_ptypes,
#endif
.Match = GP_MatchTIFF,
http://repo.or.cz/w/gfxprim.git/commit/5465a3982ed5266489faac926e1eb6f3288f…
commit 5465a3982ed5266489faac926e1eb6f3288fdb35
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 14:51:51 2014 +0200
core: include: Fix non-linux compatibility ifdefs
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/include/core/GP_ByteOrder.h b/include/core/GP_ByteOrder.h
index f756d45a..7fac23a8 100644
--- a/include/core/GP_ByteOrder.h
+++ b/include/core/GP_ByteOrder.h
@@ -30,6 +30,9 @@
# include <endian.h>
#else /* BSD Family */
# include <machine/endian.h>
+# define __BYTE_ORDER _BYTE_ORDER
+# define __BIG_ENDIAN _BIG_ENDIAN
+# define __LITTLE_ENDIAN _LITTLE_ENDIAN
#endif
#endif /* CORE_GP_BYTE_ORDER_H */
diff --git a/include/core/GP_TempAlloc.h b/include/core/GP_TempAlloc.h
index 925b112e..e17adffb 100644
--- a/include/core/GP_TempAlloc.h
+++ b/include/core/GP_TempAlloc.h
@@ -47,7 +47,9 @@
#ifndef CORE_GP_TEMP_ALLOC_H
#define CORE_GP_TEMP_ALLOC_H
-#include <alloca.h>
+#ifdef __linux__
+# include <alloca.h>
+#endif
#include <stdlib.h>
#include "core/GP_Common.h"
http://repo.or.cz/w/gfxprim.git/commit/0ae6c2fe86b9fb25483cfd7389096912441a…
commit 0ae6c2fe86b9fb25483cfd7389096912441a3400
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 14:47:55 2014 +0200
demos, tests: Use /bin/sh instead of /bin/bash
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/demos/bogoman/runtest.sh b/demos/bogoman/runtest.sh
index 07947072..dac7bc8b 100755
--- a/demos/bogoman/runtest.sh
+++ b/demos/bogoman/runtest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Run dynamically linked test.
#
diff --git a/demos/c_simple/runtest.sh b/demos/c_simple/runtest.sh
index 07947072..dac7bc8b 100755
--- a/demos/c_simple/runtest.sh
+++ b/demos/c_simple/runtest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Run dynamically linked test.
#
diff --git a/demos/grinder/runtest.sh b/demos/grinder/runtest.sh
index 163c76c4..eed2e0e5 100755
--- a/demos/grinder/runtest.sh
+++ b/demos/grinder/runtest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Run dynamically linked test.
#
diff --git a/demos/particle/runtest.sh b/demos/particle/runtest.sh
index 07947072..dac7bc8b 100755
--- a/demos/particle/runtest.sh
+++ b/demos/particle/runtest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Run dynamically linked test.
#
diff --git a/demos/py_simple/runpytest.sh b/demos/py_simple/runpytest.sh
index 264af15a..9afbb927 100755
--- a/demos/py_simple/runpytest.sh
+++ b/demos/py_simple/runpytest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Run python test with dynamically linked libGP.
#
diff --git a/demos/spiv/runtest.sh b/demos/spiv/runtest.sh
index 07947072..dac7bc8b 100755
--- a/demos/spiv/runtest.sh
+++ b/demos/spiv/runtest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Run dynamically linked test.
#
diff --git a/demos/ttf2img/runtest.sh b/demos/ttf2img/runtest.sh
index 07947072..dac7bc8b 100755
--- a/demos/ttf2img/runtest.sh
+++ b/demos/ttf2img/runtest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Run dynamically linked test.
#
diff --git a/tests/drivers/runtest.sh b/tests/drivers/runtest.sh
index ff2a001d..fc29b596 100755
--- a/tests/drivers/runtest.sh
+++ b/tests/drivers/runtest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# Run dynamically linked test.
#
-----------------------------------------------------------------------
Summary of changes:
build/syms/Loaders_symbols.txt | 5 +-
demos/bogoman/runtest.sh | 2 +-
demos/c_simple/loaders_register.c | 6 ++
demos/c_simple/runtest.sh | 2 +-
demos/grinder/runtest.sh | 2 +-
demos/particle/runtest.sh | 2 +-
demos/py_simple/runpytest.sh | 2 +-
demos/spiv/image_list.c | 2 +-
demos/spiv/runtest.sh | 2 +-
demos/ttf2img/runtest.sh | 2 +-
doc/loaders.txt | 97 +++++++++++++++++++++++--------------
include/core/GP_ByteOrder.h | 3 +
include/core/GP_TempAlloc.h | 4 +-
include/loaders/GP_Loader.h | 19 +++++--
libs/loaders/GP_BMP.c | 1 +
libs/loaders/GP_JPG.c | 1 +
libs/loaders/GP_Loader.c | 37 ++++++++-------
libs/loaders/GP_PNG.c | 15 ++++++
libs/loaders/GP_PNM.c | 26 ++++++++++
libs/loaders/GP_TIFF.c | 12 +++++
tests/drivers/runtest.sh | 2 +-
tests/loaders/Loader.c | 6 +-
22 files changed, 176 insertions(+), 74 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
13 Jun '14
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
discards 14a68f948a63033de7c8d8dcf12978edb29b5fa2 (commit)
discards 069262b67e2bd246c98f76a4f9ddbbf9bf3c992f (commit)
via f41246cb1b727024fe62f46daceefc3e810e330a (commit)
via e30b2b00bee284d3e1b7f2055f278e023a950254 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (14a68f948a63033de7c8d8dcf12978edb29b5fa2)
N -- N -- N (f41246cb1b727024fe62f46daceefc3e810e330a)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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/f41246cb1b727024fe62f46daceefc3e810e…
commit f41246cb1b727024fe62f46daceefc3e810e330a
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 11:40:39 2014 +0200
build: Fix Debian build, core should link with -lrt
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/Makefile b/build/Makefile
index 3053edfa..5f88872b 100644
--- a/build/Makefile
+++ b/build/Makefile
@@ -37,10 +37,10 @@ endif
$(DYNAMIC_LIB): $(LIB_OBJECTS)
ifdef VERBOSE
- $(CC) -fPIC -dPIC --shared -Wl,-soname -Wl,$(SONAME) $^ -lm $(LDLIBS_core) -o $@
+ $(CC) -fPIC -dPIC --shared -Wl,-soname -Wl,$(SONAME) $^ -lm -lrt $(LDLIBS_core) -o $@
else
@echo "LD $@"
- @$(CC) -fPIC -dPIC --shared -Wl,-soname -Wl,$(SONAME) $^ -lm $(LDLIBS_core) -o $@
+ @$(CC) -fPIC -dPIC --shared -Wl,-soname -Wl,$(SONAME) $^ -lm -lrt $(LDLIBS_core) -o $@
endif
$(SYMLINKS): $(DYNAMIC_LIB)
http://repo.or.cz/w/gfxprim.git/commit/e30b2b00bee284d3e1b7f2055f278e023a95…
commit e30b2b00bee284d3e1b7f2055f278e023a950254
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 11:32:22 2014 +0200
loaders: GP_Loader: Get rid of unneeded members
This commit cleanups a few aspects of loaders implementation.
It creates GP_LoaderLoadImage() function that can be used to load
image from path for a given loader pointer which allows us to.
* Get rid of the Load() callback from GP_Loader
* Unify GP_LoadFOO implementation
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/demos/c_simple/loaders_register.c b/demos/c_simple/loaders_register.c
index 4b36461a..246394a5 100644
--- a/demos/c_simple/loaders_register.c
+++ b/demos/c_simple/loaders_register.c
@@ -91,9 +91,7 @@ static int save(const GP_Context *img, const char *dst_path,
}
GP_Loader loader = {
- .Load = NULL,
.Save = save,
- .Match = NULL,
.fmt_name = "ASCII Art",
.extensions = {"txt", NULL},
};
diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h
index 3860ac10..6f07d2ea 100644
--- a/include/loaders/GP_Loader.h
+++ b/include/loaders/GP_Loader.h
@@ -85,13 +85,6 @@ typedef struct GP_Loader {
GP_Context *(*Read)(GP_IO *io, GP_ProgressCallback *callback);
/*
- * Loads an image from a file.
- *
- * TODO: Remove due to Read
- */
- GP_Context *(*Load)(const char *src_path, GP_ProgressCallback *callback);
-
- /*
* Save an image.
*
* Returns zero on succes, non-zero on failure and errno must be set.
@@ -109,9 +102,6 @@ typedef struct GP_Loader {
*/
const char *fmt_name;
- /* don't touch */
- struct GP_Loader *next;
-
/*
* NULL terminated array of file extensions.
*/
@@ -146,6 +136,15 @@ int GP_LoaderRegister(GP_Loader *self);
void GP_LoaderUnregister(GP_Loader *self);
/*
+ * Generic LoadImage for a given loader.
+ *
+ * The function prepares the IO from file, calls the loader Read() method,
+ * closes the IO and returns the context.
+ */
+GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path,
+ GP_ProgressCallback *callback);
+
+/*
* List loaders into the stdout
*/
void GP_ListLoaders(void);
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index 9fcff422..4313e2de 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -703,21 +703,7 @@ err1:
GP_Context *GP_LoadBMP(const char *src_path, GP_ProgressCallback *callback)
{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadBMP(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
+ return GP_LoaderLoadImage(&GP_BMP, src_path, callback);
}
/*
@@ -908,7 +894,6 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path,
struct GP_Loader GP_BMP = {
.Read = GP_ReadBMP,
- .Load = GP_LoadBMP,
.Save = GP_SaveBMP,
.Match = GP_MatchBMP,
diff --git a/libs/loaders/GP_GIF.c b/libs/loaders/GP_GIF.c
index 6425d60a..a4f3afc0 100644
--- a/libs/loaders/GP_GIF.c
+++ b/libs/loaders/GP_GIF.c
@@ -358,25 +358,6 @@ err1:
return NULL;
}
-GP_Context *GP_LoadGIF(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadGIF(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
#else
int GP_MatchGIF(const void GP_UNUSED(*buf))
@@ -392,20 +373,19 @@ GP_Context *GP_ReadGIF(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadGIF(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
+#endif /* HAVE_GIFLIB */
+
+GP_Context *GP_LoadGIF(const char *src_path, GP_ProgressCallback *callback)
{
- errno = ENOSYS;
- return NULL;
+ return GP_LoaderLoadImage(&GP_GIF, src_path, callback);
}
-#endif /* HAVE_GIFLIB */
-
struct GP_Loader GP_GIF = {
+#ifdef HAVE_GIFLIB
.Read = GP_ReadGIF,
- .Load = GP_LoadGIF,
- .Save = NULL,
+#endif
.Match = GP_MatchGIF,
+
.fmt_name = "Graphics Interchange Format",
.extensions = {"gif", NULL},
};
diff --git a/libs/loaders/GP_JP2.c b/libs/loaders/GP_JP2.c
index f451b6f1..941849b2 100644
--- a/libs/loaders/GP_JP2.c
+++ b/libs/loaders/GP_JP2.c
@@ -225,25 +225,6 @@ err0:
return res;
}
-GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadJP2(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
#else
GP_Context *GP_ReadJP2(GP_IO GP_UNUSED(*io),
@@ -253,19 +234,17 @@ GP_Context *GP_ReadJP2(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadJP2(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
+#endif /* HAVE_OPENJPEG */
+
+GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback)
{
- errno = ENOSYS;
- return NULL;
+ return GP_LoaderLoadImage(&GP_JP2, src_path, callback);
}
-#endif /* HAVE_OPENJPEG */
-
struct GP_Loader GP_JP2 = {
+#ifdef HAVE_OPENJPEG
.Read = GP_ReadJP2,
- .Load = GP_LoadJP2,
- .Save = NULL,
+#endif
.Match = GP_MatchJP2,
.fmt_name = "JPEG 2000",
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index ca14b180..ea891712 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -290,25 +290,6 @@ err1:
return NULL;
}
-GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadJPG(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
#define JPEG_COM_MAX 128
static void read_jpg_metadata(struct jpeg_decompress_struct *cinfo,
@@ -564,13 +545,6 @@ GP_Context *GP_ReadJPG(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadJPG(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
-{
- errno = ENOSYS;
- return NULL;
-}
-
int GP_ReadJPGMetaData(GP_IO GP_UNUSED(*io), GP_MetaData GP_UNUSED(*data))
{
errno = ENOSYS;
@@ -594,10 +568,16 @@ int GP_SaveJPG(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_JPEG */
+GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_JPG, src_path, callback);
+}
+
struct GP_Loader GP_JPG = {
+#ifdef HAVE_JPEG
.Read = GP_ReadJPG,
- .Load = GP_LoadJPG,
.Save = GP_SaveJPG,
+#endif
.Match = GP_MatchJPG,
.fmt_name = "JPEG",
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index c3b74feb..763e819b 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -126,7 +126,6 @@ void GP_ListLoaders(void)
for (i = 0; loaders[i]; i++) {
printf("Format: %sn", loaders[i]->fmt_name);
printf("Read:t%sn", loaders[i]->Read ? "Yes" : "No");
- printf("Load:t%sn", loaders[i]->Load ? "Yes" : "No");
printf("Save:t%sn", loaders[i]->Save ? "Yes" : "No");
printf("Match:t%sn", loaders[i]->Match ? "Yes" : "No");
printf("Extensions: ");
@@ -268,6 +267,31 @@ GP_Context *GP_ReadImage(GP_IO *io, GP_ProgressCallback *callback)
return loader->Read(io, callback);
}
+GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path,
+ GP_ProgressCallback *callback)
+{
+ GP_IO *io;
+ GP_Context *res;
+ int err;
+
+ if (!self->Read) {
+ errno = ENOSYS;
+ return NULL;
+ }
+
+ io = GP_IOFile(src_path, GP_IO_RDONLY);
+ if (!io)
+ return NULL;
+
+ res = self->Read(io, callback);
+
+ err = errno;
+ GP_IOClose(io);
+ errno = err;
+
+ return res;
+}
+
GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
{
int err;
@@ -295,8 +319,8 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
ext_load = loader_by_filename(src_path);
- if (ext_load != NULL && ext_load->Load != NULL) {
- img = ext_load->Load(src_path, callback);
+ if (ext_load) {
+ img = GP_LoaderLoadImage(ext_load, src_path, callback);
if (img)
return img;
@@ -316,8 +340,8 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
src_path, ext_load->fmt_name, sig_load->fmt_name);
}
- if (sig_load && sig_load->Load != NULL)
- return sig_load->Load(src_path, callback);
+ if (sig_load)
+ return GP_LoaderLoadImage(sig_load, src_path, callback);
errno = ENOSYS;
return NULL;
diff --git a/libs/loaders/GP_PCX.c b/libs/loaders/GP_PCX.c
index b04dc41b..330b0a7f 100644
--- a/libs/loaders/GP_PCX.c
+++ b/libs/loaders/GP_PCX.c
@@ -549,27 +549,11 @@ err0:
GP_Context *GP_LoadPCX(const char *src_path, GP_ProgressCallback *callback)
{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPCX(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
+ return GP_LoaderLoadImage(&GP_PCX, src_path, callback);
}
struct GP_Loader GP_PCX = {
.Read = GP_ReadPCX,
- .Load = GP_LoadPCX,
- .Save = NULL,
.Match = GP_MatchPCX,
.fmt_name = "ZSoft PCX",
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 2da8bcef..1a73c9a8 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -264,25 +264,6 @@ err1:
return NULL;
}
-GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPNG(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
static void load_meta_data(png_structp png, png_infop png_info, GP_MetaData *data)
{
double gamma;
@@ -625,13 +606,6 @@ GP_Context *GP_ReadPNG(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadPNG(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
-{
- errno = ENOSYS;
- return NULL;
-}
-
int GP_ReadPNGMetaData(GP_IO GP_UNUSED(*io), GP_MetaData GP_UNUSED(*data))
{
errno = ENOSYS;
@@ -654,10 +628,16 @@ int GP_SavePNG(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_LIBPNG */
+GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PNG, src_path, callback);
+}
+
GP_Loader GP_PNG = {
+#ifdef HAVE_LIBPNG
.Read = GP_ReadPNG,
- .Load = GP_LoadPNG,
.Save = GP_SavePNG,
+#endif
.Match = GP_MatchPNG,
.fmt_name = "Portable Network Graphics",
diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c
index 63bb5361..93bc1b68 100644
--- a/libs/loaders/GP_PNM.c
+++ b/libs/loaders/GP_PNM.c
@@ -712,25 +712,6 @@ GP_Context *GP_ReadPBM(GP_IO *io, GP_ProgressCallback *callback)
return read_bitmap(&buf, &header, callback);
}
-GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPBM(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
int GP_SavePBM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -882,25 +863,6 @@ GP_Context *GP_ReadPGM(GP_IO *io, GP_ProgressCallback *callback)
return read_graymap(&buf, &header, callback);
}
-GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPGM(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
static int pixel_to_depth(GP_Pixel pixel)
{
switch (pixel) {
@@ -1026,25 +988,6 @@ GP_Context *GP_ReadPPM(GP_IO *io, GP_ProgressCallback *callback)
return read_pixmap(&buf, &header, callback);
}
-GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPPM(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
static int write_binary_ppm(FILE *f, GP_Context *src)
{
uint32_t x, y;
@@ -1188,25 +1131,6 @@ GP_Context *GP_ReadPNM(GP_IO *io, GP_ProgressCallback *callback)
return ret;
}
-GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPNM(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
int GP_SavePNM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -1227,9 +1151,28 @@ int GP_SavePNM(const GP_Context *src, const char *dst_path,
}
}
+GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PBM, src_path, callback);
+}
+
+GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PGM, src_path, callback);
+}
+
+GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PPM, src_path, callback);
+}
+
+GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PNM, src_path, callback);
+}
+
struct GP_Loader GP_PBM = {
.Read = GP_ReadPBM,
- .Load = GP_LoadPBM,
.Save = GP_SavePBM,
.Match = GP_MatchPBM,
@@ -1239,7 +1182,6 @@ struct GP_Loader GP_PBM = {
struct GP_Loader GP_PGM = {
.Read = GP_ReadPGM,
- .Load = GP_LoadPGM,
.Save = GP_SavePGM,
.Match = GP_MatchPGM,
@@ -1249,7 +1191,6 @@ struct GP_Loader GP_PGM = {
struct GP_Loader GP_PPM = {
.Read = GP_ReadPPM,
- .Load = GP_LoadPPM,
.Save = GP_SavePPM,
.Match = GP_MatchPPM,
@@ -1259,7 +1200,6 @@ struct GP_Loader GP_PPM = {
struct GP_Loader GP_PNM = {
.Read = GP_ReadPNM,
- .Load = GP_LoadPNM,
.Save = GP_SavePNM,
/*
* Avoid double Match
diff --git a/libs/loaders/GP_PSD.c b/libs/loaders/GP_PSD.c
index 5ef73f11..ba86cb4e 100644
--- a/libs/loaders/GP_PSD.c
+++ b/libs/loaders/GP_PSD.c
@@ -813,27 +813,11 @@ err:
GP_Context *GP_LoadPSD(const char *src_path, GP_ProgressCallback *callback)
{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPSD(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
+ return GP_LoaderLoadImage(&GP_PSD, src_path, callback);
}
struct GP_Loader GP_PSD = {
.Read = GP_ReadPSD,
- .Load = GP_LoadPSD,
- .Save = NULL,
.Match = GP_MatchPSD,
.fmt_name = "Adobe Photoshop Image",
diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c
index bacd4b9b..64cdeaa6 100644
--- a/libs/loaders/GP_PSP.c
+++ b/libs/loaders/GP_PSP.c
@@ -491,27 +491,11 @@ err0:
GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback)
{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPSP(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
+ return GP_LoaderLoadImage(&GP_PSP, src_path, callback);
}
struct GP_Loader GP_PSP = {
.Read = GP_ReadPSP,
- .Load = GP_LoadPSP,
- .Save = NULL,
.Match = GP_MatchPSP,
.fmt_name = "Paint Shop Pro Image",
.extensions = {"psp", "pspimage", NULL},
diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c
index 1ea06554..bcc23b21 100644
--- a/libs/loaders/GP_TIFF.c
+++ b/libs/loaders/GP_TIFF.c
@@ -536,25 +536,6 @@ err0:
return NULL;
}
-GP_Context *GP_LoadTIFF(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadTIFF(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
static int save_grayscale(TIFF *tiff, const GP_Context *src,
GP_ProgressCallback *callback)
{
@@ -746,13 +727,6 @@ GP_Context *GP_ReadTIFF(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadTIFF(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
-{
- errno = ENOSYS;
- return NULL;
-}
-
int GP_SaveTIFF(const GP_Context GP_UNUSED(*src),
const char GP_UNUSED(*dst_path),
GP_ProgressCallback GP_UNUSED(*callback))
@@ -763,10 +737,16 @@ int GP_SaveTIFF(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_TIFF */
+GP_Context *GP_LoadTIFF(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_TIFF, src_path, callback);
+}
+
struct GP_Loader GP_TIFF = {
+#ifdef HAVE_TIFF
.Read = GP_ReadTIFF,
- .Load = GP_LoadTIFF,
.Save = GP_SaveTIFF,
+#endif
.Match = GP_MatchTIFF,
.fmt_name = "Tag Image File Format",
-----------------------------------------------------------------------
Summary of changes:
demos/c_simple/loaders_register.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
13 Jun '14
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 14a68f948a63033de7c8d8dcf12978edb29b5fa2 (commit)
from 069262b67e2bd246c98f76a4f9ddbbf9bf3c992f (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/14a68f948a63033de7c8d8dcf12978edb29b…
commit 14a68f948a63033de7c8d8dcf12978edb29b5fa2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 11:40:39 2014 +0200
build: Fix Debian build, core should link with -lrt
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/Makefile b/build/Makefile
index 3053edfa..5f88872b 100644
--- a/build/Makefile
+++ b/build/Makefile
@@ -37,10 +37,10 @@ endif
$(DYNAMIC_LIB): $(LIB_OBJECTS)
ifdef VERBOSE
- $(CC) -fPIC -dPIC --shared -Wl,-soname -Wl,$(SONAME) $^ -lm $(LDLIBS_core) -o $@
+ $(CC) -fPIC -dPIC --shared -Wl,-soname -Wl,$(SONAME) $^ -lm -lrt $(LDLIBS_core) -o $@
else
@echo "LD $@"
- @$(CC) -fPIC -dPIC --shared -Wl,-soname -Wl,$(SONAME) $^ -lm $(LDLIBS_core) -o $@
+ @$(CC) -fPIC -dPIC --shared -Wl,-soname -Wl,$(SONAME) $^ -lm -lrt $(LDLIBS_core) -o $@
endif
$(SYMLINKS): $(DYNAMIC_LIB)
-----------------------------------------------------------------------
Summary of changes:
build/Makefile | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
13 Jun '14
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 069262b67e2bd246c98f76a4f9ddbbf9bf3c992f (commit)
via 2d816b6c01944b146c69c1db821eea6147e2b5cb (commit)
via 4bec01e5af42cb68e680f3a6d452d543b8c4d004 (commit)
via e341668ccad607f9843386e206105f086ae307d0 (commit)
from 13195186d44e871af057bda262ddf8467ff8049c (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/069262b67e2bd246c98f76a4f9ddbbf9bf3c…
commit 069262b67e2bd246c98f76a4f9ddbbf9bf3c992f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 11:32:22 2014 +0200
loaders: GP_Loader: Get rid of unneeded members
This commit cleanups a few aspects of loaders implementation.
It creates GP_LoaderLoadImage() function that can be used to load
image from path for a given loader pointer which allows us to.
* Get rid of the Load() callback from GP_Loader
* Unify GP_LoadFOO implementation
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h
index 3860ac10..6f07d2ea 100644
--- a/include/loaders/GP_Loader.h
+++ b/include/loaders/GP_Loader.h
@@ -85,13 +85,6 @@ typedef struct GP_Loader {
GP_Context *(*Read)(GP_IO *io, GP_ProgressCallback *callback);
/*
- * Loads an image from a file.
- *
- * TODO: Remove due to Read
- */
- GP_Context *(*Load)(const char *src_path, GP_ProgressCallback *callback);
-
- /*
* Save an image.
*
* Returns zero on succes, non-zero on failure and errno must be set.
@@ -109,9 +102,6 @@ typedef struct GP_Loader {
*/
const char *fmt_name;
- /* don't touch */
- struct GP_Loader *next;
-
/*
* NULL terminated array of file extensions.
*/
@@ -146,6 +136,15 @@ int GP_LoaderRegister(GP_Loader *self);
void GP_LoaderUnregister(GP_Loader *self);
/*
+ * Generic LoadImage for a given loader.
+ *
+ * The function prepares the IO from file, calls the loader Read() method,
+ * closes the IO and returns the context.
+ */
+GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path,
+ GP_ProgressCallback *callback);
+
+/*
* List loaders into the stdout
*/
void GP_ListLoaders(void);
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index 9fcff422..4313e2de 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -703,21 +703,7 @@ err1:
GP_Context *GP_LoadBMP(const char *src_path, GP_ProgressCallback *callback)
{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadBMP(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
+ return GP_LoaderLoadImage(&GP_BMP, src_path, callback);
}
/*
@@ -908,7 +894,6 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path,
struct GP_Loader GP_BMP = {
.Read = GP_ReadBMP,
- .Load = GP_LoadBMP,
.Save = GP_SaveBMP,
.Match = GP_MatchBMP,
diff --git a/libs/loaders/GP_GIF.c b/libs/loaders/GP_GIF.c
index 6425d60a..a4f3afc0 100644
--- a/libs/loaders/GP_GIF.c
+++ b/libs/loaders/GP_GIF.c
@@ -358,25 +358,6 @@ err1:
return NULL;
}
-GP_Context *GP_LoadGIF(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadGIF(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
#else
int GP_MatchGIF(const void GP_UNUSED(*buf))
@@ -392,20 +373,19 @@ GP_Context *GP_ReadGIF(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadGIF(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
+#endif /* HAVE_GIFLIB */
+
+GP_Context *GP_LoadGIF(const char *src_path, GP_ProgressCallback *callback)
{
- errno = ENOSYS;
- return NULL;
+ return GP_LoaderLoadImage(&GP_GIF, src_path, callback);
}
-#endif /* HAVE_GIFLIB */
-
struct GP_Loader GP_GIF = {
+#ifdef HAVE_GIFLIB
.Read = GP_ReadGIF,
- .Load = GP_LoadGIF,
- .Save = NULL,
+#endif
.Match = GP_MatchGIF,
+
.fmt_name = "Graphics Interchange Format",
.extensions = {"gif", NULL},
};
diff --git a/libs/loaders/GP_JP2.c b/libs/loaders/GP_JP2.c
index f451b6f1..941849b2 100644
--- a/libs/loaders/GP_JP2.c
+++ b/libs/loaders/GP_JP2.c
@@ -225,25 +225,6 @@ err0:
return res;
}
-GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadJP2(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
#else
GP_Context *GP_ReadJP2(GP_IO GP_UNUSED(*io),
@@ -253,19 +234,17 @@ GP_Context *GP_ReadJP2(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadJP2(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
+#endif /* HAVE_OPENJPEG */
+
+GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback)
{
- errno = ENOSYS;
- return NULL;
+ return GP_LoaderLoadImage(&GP_JP2, src_path, callback);
}
-#endif /* HAVE_OPENJPEG */
-
struct GP_Loader GP_JP2 = {
+#ifdef HAVE_OPENJPEG
.Read = GP_ReadJP2,
- .Load = GP_LoadJP2,
- .Save = NULL,
+#endif
.Match = GP_MatchJP2,
.fmt_name = "JPEG 2000",
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index ca14b180..ea891712 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -290,25 +290,6 @@ err1:
return NULL;
}
-GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadJPG(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
#define JPEG_COM_MAX 128
static void read_jpg_metadata(struct jpeg_decompress_struct *cinfo,
@@ -564,13 +545,6 @@ GP_Context *GP_ReadJPG(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadJPG(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
-{
- errno = ENOSYS;
- return NULL;
-}
-
int GP_ReadJPGMetaData(GP_IO GP_UNUSED(*io), GP_MetaData GP_UNUSED(*data))
{
errno = ENOSYS;
@@ -594,10 +568,16 @@ int GP_SaveJPG(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_JPEG */
+GP_Context *GP_LoadJPG(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_JPG, src_path, callback);
+}
+
struct GP_Loader GP_JPG = {
+#ifdef HAVE_JPEG
.Read = GP_ReadJPG,
- .Load = GP_LoadJPG,
.Save = GP_SaveJPG,
+#endif
.Match = GP_MatchJPG,
.fmt_name = "JPEG",
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index c3b74feb..763e819b 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -126,7 +126,6 @@ void GP_ListLoaders(void)
for (i = 0; loaders[i]; i++) {
printf("Format: %sn", loaders[i]->fmt_name);
printf("Read:t%sn", loaders[i]->Read ? "Yes" : "No");
- printf("Load:t%sn", loaders[i]->Load ? "Yes" : "No");
printf("Save:t%sn", loaders[i]->Save ? "Yes" : "No");
printf("Match:t%sn", loaders[i]->Match ? "Yes" : "No");
printf("Extensions: ");
@@ -268,6 +267,31 @@ GP_Context *GP_ReadImage(GP_IO *io, GP_ProgressCallback *callback)
return loader->Read(io, callback);
}
+GP_Context *GP_LoaderLoadImage(const GP_Loader *self, const char *src_path,
+ GP_ProgressCallback *callback)
+{
+ GP_IO *io;
+ GP_Context *res;
+ int err;
+
+ if (!self->Read) {
+ errno = ENOSYS;
+ return NULL;
+ }
+
+ io = GP_IOFile(src_path, GP_IO_RDONLY);
+ if (!io)
+ return NULL;
+
+ res = self->Read(io, callback);
+
+ err = errno;
+ GP_IOClose(io);
+ errno = err;
+
+ return res;
+}
+
GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
{
int err;
@@ -295,8 +319,8 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
ext_load = loader_by_filename(src_path);
- if (ext_load != NULL && ext_load->Load != NULL) {
- img = ext_load->Load(src_path, callback);
+ if (ext_load) {
+ img = GP_LoaderLoadImage(ext_load, src_path, callback);
if (img)
return img;
@@ -316,8 +340,8 @@ GP_Context *GP_LoadImage(const char *src_path, GP_ProgressCallback *callback)
src_path, ext_load->fmt_name, sig_load->fmt_name);
}
- if (sig_load && sig_load->Load != NULL)
- return sig_load->Load(src_path, callback);
+ if (sig_load)
+ return GP_LoaderLoadImage(sig_load, src_path, callback);
errno = ENOSYS;
return NULL;
diff --git a/libs/loaders/GP_PCX.c b/libs/loaders/GP_PCX.c
index b04dc41b..330b0a7f 100644
--- a/libs/loaders/GP_PCX.c
+++ b/libs/loaders/GP_PCX.c
@@ -549,27 +549,11 @@ err0:
GP_Context *GP_LoadPCX(const char *src_path, GP_ProgressCallback *callback)
{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPCX(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
+ return GP_LoaderLoadImage(&GP_PCX, src_path, callback);
}
struct GP_Loader GP_PCX = {
.Read = GP_ReadPCX,
- .Load = GP_LoadPCX,
- .Save = NULL,
.Match = GP_MatchPCX,
.fmt_name = "ZSoft PCX",
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 2da8bcef..1a73c9a8 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -264,25 +264,6 @@ err1:
return NULL;
}
-GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPNG(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
static void load_meta_data(png_structp png, png_infop png_info, GP_MetaData *data)
{
double gamma;
@@ -625,13 +606,6 @@ GP_Context *GP_ReadPNG(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadPNG(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
-{
- errno = ENOSYS;
- return NULL;
-}
-
int GP_ReadPNGMetaData(GP_IO GP_UNUSED(*io), GP_MetaData GP_UNUSED(*data))
{
errno = ENOSYS;
@@ -654,10 +628,16 @@ int GP_SavePNG(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_LIBPNG */
+GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PNG, src_path, callback);
+}
+
GP_Loader GP_PNG = {
+#ifdef HAVE_LIBPNG
.Read = GP_ReadPNG,
- .Load = GP_LoadPNG,
.Save = GP_SavePNG,
+#endif
.Match = GP_MatchPNG,
.fmt_name = "Portable Network Graphics",
diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c
index 63bb5361..93bc1b68 100644
--- a/libs/loaders/GP_PNM.c
+++ b/libs/loaders/GP_PNM.c
@@ -712,25 +712,6 @@ GP_Context *GP_ReadPBM(GP_IO *io, GP_ProgressCallback *callback)
return read_bitmap(&buf, &header, callback);
}
-GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPBM(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
int GP_SavePBM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -882,25 +863,6 @@ GP_Context *GP_ReadPGM(GP_IO *io, GP_ProgressCallback *callback)
return read_graymap(&buf, &header, callback);
}
-GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPGM(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
static int pixel_to_depth(GP_Pixel pixel)
{
switch (pixel) {
@@ -1026,25 +988,6 @@ GP_Context *GP_ReadPPM(GP_IO *io, GP_ProgressCallback *callback)
return read_pixmap(&buf, &header, callback);
}
-GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPPM(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
static int write_binary_ppm(FILE *f, GP_Context *src)
{
uint32_t x, y;
@@ -1188,25 +1131,6 @@ GP_Context *GP_ReadPNM(GP_IO *io, GP_ProgressCallback *callback)
return ret;
}
-GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPNM(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
int GP_SavePNM(const GP_Context *src, const char *dst_path,
GP_ProgressCallback *callback)
{
@@ -1227,9 +1151,28 @@ int GP_SavePNM(const GP_Context *src, const char *dst_path,
}
}
+GP_Context *GP_LoadPBM(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PBM, src_path, callback);
+}
+
+GP_Context *GP_LoadPGM(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PGM, src_path, callback);
+}
+
+GP_Context *GP_LoadPPM(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PPM, src_path, callback);
+}
+
+GP_Context *GP_LoadPNM(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_PNM, src_path, callback);
+}
+
struct GP_Loader GP_PBM = {
.Read = GP_ReadPBM,
- .Load = GP_LoadPBM,
.Save = GP_SavePBM,
.Match = GP_MatchPBM,
@@ -1239,7 +1182,6 @@ struct GP_Loader GP_PBM = {
struct GP_Loader GP_PGM = {
.Read = GP_ReadPGM,
- .Load = GP_LoadPGM,
.Save = GP_SavePGM,
.Match = GP_MatchPGM,
@@ -1249,7 +1191,6 @@ struct GP_Loader GP_PGM = {
struct GP_Loader GP_PPM = {
.Read = GP_ReadPPM,
- .Load = GP_LoadPPM,
.Save = GP_SavePPM,
.Match = GP_MatchPPM,
@@ -1259,7 +1200,6 @@ struct GP_Loader GP_PPM = {
struct GP_Loader GP_PNM = {
.Read = GP_ReadPNM,
- .Load = GP_LoadPNM,
.Save = GP_SavePNM,
/*
* Avoid double Match
diff --git a/libs/loaders/GP_PSD.c b/libs/loaders/GP_PSD.c
index 5ef73f11..ba86cb4e 100644
--- a/libs/loaders/GP_PSD.c
+++ b/libs/loaders/GP_PSD.c
@@ -813,27 +813,11 @@ err:
GP_Context *GP_LoadPSD(const char *src_path, GP_ProgressCallback *callback)
{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPSD(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
+ return GP_LoaderLoadImage(&GP_PSD, src_path, callback);
}
struct GP_Loader GP_PSD = {
.Read = GP_ReadPSD,
- .Load = GP_LoadPSD,
- .Save = NULL,
.Match = GP_MatchPSD,
.fmt_name = "Adobe Photoshop Image",
diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c
index bacd4b9b..64cdeaa6 100644
--- a/libs/loaders/GP_PSP.c
+++ b/libs/loaders/GP_PSP.c
@@ -491,27 +491,11 @@ err0:
GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback)
{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadPSP(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
+ return GP_LoaderLoadImage(&GP_PSP, src_path, callback);
}
struct GP_Loader GP_PSP = {
.Read = GP_ReadPSP,
- .Load = GP_LoadPSP,
- .Save = NULL,
.Match = GP_MatchPSP,
.fmt_name = "Paint Shop Pro Image",
.extensions = {"psp", "pspimage", NULL},
diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c
index 1ea06554..bcc23b21 100644
--- a/libs/loaders/GP_TIFF.c
+++ b/libs/loaders/GP_TIFF.c
@@ -536,25 +536,6 @@ err0:
return NULL;
}
-GP_Context *GP_LoadTIFF(const char *src_path, GP_ProgressCallback *callback)
-{
- GP_IO *io;
- GP_Context *res;
- int err;
-
- io = GP_IOFile(src_path, GP_IO_RDONLY);
- if (!io)
- return NULL;
-
- res = GP_ReadTIFF(io, callback);
-
- err = errno;
- GP_IOClose(io);
- errno = err;
-
- return res;
-}
-
static int save_grayscale(TIFF *tiff, const GP_Context *src,
GP_ProgressCallback *callback)
{
@@ -746,13 +727,6 @@ GP_Context *GP_ReadTIFF(GP_IO GP_UNUSED(*io),
return NULL;
}
-GP_Context *GP_LoadTIFF(const char GP_UNUSED(*src_path),
- GP_ProgressCallback GP_UNUSED(*callback))
-{
- errno = ENOSYS;
- return NULL;
-}
-
int GP_SaveTIFF(const GP_Context GP_UNUSED(*src),
const char GP_UNUSED(*dst_path),
GP_ProgressCallback GP_UNUSED(*callback))
@@ -763,10 +737,16 @@ int GP_SaveTIFF(const GP_Context GP_UNUSED(*src),
#endif /* HAVE_TIFF */
+GP_Context *GP_LoadTIFF(const char *src_path, GP_ProgressCallback *callback)
+{
+ return GP_LoaderLoadImage(&GP_TIFF, src_path, callback);
+}
+
struct GP_Loader GP_TIFF = {
+#ifdef HAVE_TIFF
.Read = GP_ReadTIFF,
- .Load = GP_LoadTIFF,
.Save = GP_SaveTIFF,
+#endif
.Match = GP_MatchTIFF,
.fmt_name = "Tag Image File Format",
http://repo.or.cz/w/gfxprim.git/commit/2d816b6c01944b146c69c1db821eea6147e2…
commit 2d816b6c01944b146c69c1db821eea6147e2b5cb
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 00:47:44 2014 +0200
loaders: Move GP_Loader structures to loaders
This commit moves the GP_Loader structures from GP_Loader.c to
respecitive loaders which is preparation for additional members
that will be added to GP_Loader structure.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/build/syms/Loaders_symbols.txt b/build/syms/Loaders_symbols.txt
index b73506dd..20b54d9d 100644
--- a/build/syms/Loaders_symbols.txt
+++ b/build/syms/Loaders_symbols.txt
@@ -6,6 +6,7 @@ GP_LoadJPG
GP_SaveJPG
GP_ReadJPGMetaData
GP_LoadJPGMetaData
+GP_JPG
GP_MatchPNG
GP_ReadPNG
@@ -13,57 +14,69 @@ GP_LoadPNG
GP_ReadPNGMetaData
GP_LoadPNGMetaData
GP_SavePNG
+GP_PNG
GP_MatchBMP
GP_WriteBMP
GP_LoadBMP
GP_ReadBMP
GP_SaveBMP
+GP_BMP
GP_MatchPSP
GP_ReadPSP
GP_LoadPSP
+GP_PSP
GP_MatchGIF
GP_LoadGIF
GP_ReadGIF
+GP_GIF
GP_MatchTIFF
GP_ReadTIFF
GP_LoadTIFF
GP_SaveTIFF
+GP_TIFF
GP_ReadPBM
GP_LoadPBM
GP_SavePBM
GP_MatchPBM
+GP_PBM
GP_ReadPGM
GP_LoadPGM
GP_SavePGM
GP_MatchPGM
+GP_PGM
GP_ReadPPM
GP_LoadPPM
GP_SavePPM
GP_MatchPPM
+GP_PPM
GP_ReadPNM
GP_LoadPNM
GP_SavePNM
GP_MatchPNM
+GP_PNM
GP_ReadJP2
GP_LoadJP2
GP_MatchJP2
+GP_JP2
GP_ReadPCX
GP_LoadPCX
GP_MatchPCX
+GP_PCX
GP_ReadPSD
GP_LoadPSD
GP_MatchPSD
+GP_PSD
GP_SaveTmpFile
GP_LoadTmpFile
diff --git a/include/loaders/GP_BMP.h b/include/loaders/GP_BMP.h
index 047d7733..982de158 100644
--- a/include/loaders/GP_BMP.h
+++ b/include/loaders/GP_BMP.h
@@ -23,9 +23,7 @@
#ifndef LOADERS_GP_BMP_H
#define LOADERS_GP_BMP_H
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-#include "loaders/GP_IO.h"
+#include "loaders/GP_Loader.h"
/*
* Reads a BMP from an IO stream.
@@ -60,4 +58,7 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path,
*/
int GP_MatchBMP(const void *buf);
+
+extern GP_Loader GP_BMP;
+
#endif /* LOADERS_GP_BMP_H */
diff --git a/include/loaders/GP_GIF.h b/include/loaders/GP_GIF.h
index 23405e20..989259f4 100644
--- a/include/loaders/GP_GIF.h
+++ b/include/loaders/GP_GIF.h
@@ -29,9 +29,7 @@
#ifndef LOADERS_GP_GIF_H
#define LOADERS_GP_GIF_H
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-#include "loaders/GP_IO.h"
+#include "loaders/GP_Loader.h"
/*
* Reads first image found in GIF container from an IO stream.
@@ -51,4 +49,6 @@ GP_Context *GP_LoadGIF(const char *src_path, GP_ProgressCallback *callback);
*/
int GP_MatchGIF(const void *buf);
+extern GP_Loader GP_GIF;
+
#endif /* LOADERS_GP_GIF_H */
diff --git a/include/loaders/GP_JP2.h b/include/loaders/GP_JP2.h
index 574cfbc5..ca2a029e 100644
--- a/include/loaders/GP_JP2.h
+++ b/include/loaders/GP_JP2.h
@@ -29,9 +29,7 @@
#ifndef LOADERS_GP_JP2_H
#define LOADERS_GP_JP2_H
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-#include "loaders/GP_IO.h"
+#include "loaders/GP_Loader.h"
/*
* Reads a JPEG2000 from an IO stream.
@@ -51,4 +49,6 @@ GP_Context *GP_LoadJP2(const char *src_path, GP_ProgressCallback *callback);
*/
int GP_MatchJP2(const void *buf);
+extern GP_Loader GP_JP2;
+
#endif /* LOADERS_GP_JP2_H */
diff --git a/include/loaders/GP_JPG.h b/include/loaders/GP_JPG.h
index 93cd2df2..381c084c 100644
--- a/include/loaders/GP_JPG.h
+++ b/include/loaders/GP_JPG.h
@@ -29,10 +29,7 @@
#ifndef LOADERS_GP_JPG_H
#define LOADERS_GP_JPG_H
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-#include "loaders/GP_IO.h"
-#include "loaders/GP_MetaData.h"
+#include "loaders/GP_Loader.h"
/*
* Reads a JPEG from an IO stream.
@@ -64,4 +61,6 @@ int GP_SaveJPG(const GP_Context *src, const char *dst_path,
*/
int GP_MatchJPG(const void *buf);
+extern GP_Loader GP_JPG;
+
#endif /* LOADERS_GP_JPG_H */
diff --git a/include/loaders/GP_Loader.h b/include/loaders/GP_Loader.h
index 3b5bc8f0..3860ac10 100644
--- a/include/loaders/GP_Loader.h
+++ b/include/loaders/GP_Loader.h
@@ -129,8 +129,20 @@ const GP_Loader *GP_MatchSignature(const void *buf);
*/
const GP_Loader *GP_MatchExtension(const char *path);
-void GP_LoaderRegister(GP_Loader *self);
+/*
+ * Registers additional loader.
+ *
+ * Returns zero on success, non-zero if table of loaders was is full.
+ */
+int GP_LoaderRegister(GP_Loader *self);
+/*
+ * Unregisters a loader.
+ *
+ * All library loaders are registered by default.
+ *
+ * You can unregister them using this function if you want.
+ */
void GP_LoaderUnregister(GP_Loader *self);
/*
diff --git a/include/loaders/GP_PCX.h b/include/loaders/GP_PCX.h
index f5ce05c1..bb57233a 100644
--- a/include/loaders/GP_PCX.h
+++ b/include/loaders/GP_PCX.h
@@ -29,9 +29,7 @@
#ifndef LOADERS_GP_PCX_H
#define LOADERS_GP_PCX_H
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-#include "loaders/GP_IO.h"
+#include "loaders/GP_Loader.h"
/*
* Reads a PCX from an IO stream.
@@ -51,4 +49,6 @@ GP_Context *GP_LoadPCX(const char *src_path, GP_ProgressCallback *callback);
*/
int GP_MatchPCX(const void *buf);
+extern GP_Loader GP_PCX;
+
#endif /* LOADERS_GP_PCX_H */
diff --git a/include/loaders/GP_PNG.h b/include/loaders/GP_PNG.h
index b99e7280..eb607010 100644
--- a/include/loaders/GP_PNG.h
+++ b/include/loaders/GP_PNG.h
@@ -29,10 +29,7 @@
#ifndef LOADERS_GP_PNG_H
#define LOADERS_GP_PNG_H
-#include "core/GP_ProgressCallback.h"
-#include "core/GP_Context.h"
-#include "loaders/GP_IO.h"
-#include "loaders/GP_MetaData.h"
+#include "loaders/GP_Loader.h"
/*
* Reads a PNG from an IO stream.
@@ -65,4 +62,6 @@ int GP_SavePNG(const GP_Context *src, const char *dst_path,
*/
int GP_MatchPNG(const void *buf);
+extern GP_Loader GP_PNG;
+
#endif /* LOADERS_GP_PNG_H */
diff --git a/include/loaders/GP_PNM.h b/include/loaders/GP_PNM.h
index 4f2dd11d..13d5f4b4 100644
--- a/include/loaders/GP_PNM.h
+++ b/include/loaders/GP_PNM.h
@@ -23,9 +23,7 @@
#ifndef LOADERS_GP_PNM_H
#define LOADERS_GP_PNM_H
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-#include "loaders/GP_IO.h"
+#include "loaders/GP_Loader.h"
/*
* PBM Bitmap
@@ -88,4 +86,9 @@ int GP_MatchPPM(const void *buf);
*/
int GP_MatchPNM(const void *buf);
+extern GP_Loader GP_PBM;
+extern GP_Loader GP_PGM;
+extern GP_Loader GP_PPM;
+extern GP_Loader GP_PNM;
+
#endif /* LOADERS_GP_PNM_H */
diff --git a/include/loaders/GP_PSD.h b/include/loaders/GP_PSD.h
index d8cd2213..7c4bcf6c 100644
--- a/include/loaders/GP_PSD.h
+++ b/include/loaders/GP_PSD.h
@@ -29,9 +29,7 @@
#ifndef LOADERS_GP_PSD_H
#define LOADERS_GP_PSD_H
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-#include "loaders/GP_IO.h"
+#include "loaders/GP_Loader.h"
/*
* Reads a PSD from an IO stream.
@@ -55,4 +53,6 @@ GP_Context *GP_LoadPSD(const char *src_path, GP_ProgressCallback *callback);
*/
int GP_MatchPSD(const void *buf);
+extern GP_Loader GP_PSD;
+
#endif /* LOADERS_GP_PSD_H */
diff --git a/include/loaders/GP_PSP.h b/include/loaders/GP_PSP.h
index 1109bd9e..9cf6c058 100644
--- a/include/loaders/GP_PSP.h
+++ b/include/loaders/GP_PSP.h
@@ -31,9 +31,7 @@
#ifndef LOADERS_GP_PSP_H
#define LOADERS_GP_PSP_H
-#include "core/GP_ProgressCallback.h"
-#include "core/GP_Context.h"
-#include "loaders/GP_IO.h"
+#include "loaders/GP_Loader.h"
/*
* Reads a BMP from an IO stream.
@@ -53,4 +51,6 @@ GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback);
*/
int GP_MatchPSP(const void *buf);
+extern GP_Loader GP_PSP;
+
#endif /* LOADERS_GP_PSP_H */
diff --git a/include/loaders/GP_TIFF.h b/include/loaders/GP_TIFF.h
index 8c7c45fd..ef5e4f33 100644
--- a/include/loaders/GP_TIFF.h
+++ b/include/loaders/GP_TIFF.h
@@ -23,9 +23,7 @@
#ifndef LOADERS_GP_TIFF_H
#define LOADERS_GP_TIFF_H
-#include "core/GP_Context.h"
-#include "core/GP_ProgressCallback.h"
-#include "loaders/GP_IO.h"
+#include "loaders/GP_Loader.h"
/*
* Reads first image in TIFF from an IO stream.
@@ -51,4 +49,6 @@ int GP_SaveTIFF(const GP_Context *src, const char *dst_path,
*/
int GP_MatchTIFF(const void *buf);
+extern GP_Loader GP_TIFF;
+
#endif /* LOADERS_GP_TIFF_H */
diff --git a/libs/loaders/GP_BMP.c b/libs/loaders/GP_BMP.c
index 1d9e9c20..9fcff422 100644
--- a/libs/loaders/GP_BMP.c
+++ b/libs/loaders/GP_BMP.c
@@ -905,3 +905,13 @@ int GP_SaveBMP(const GP_Context *src, const char *dst_path,
return 0;
}
+
+struct GP_Loader GP_BMP = {
+ .Read = GP_ReadBMP,
+ .Load = GP_LoadBMP,
+ .Save = GP_SaveBMP,
+ .Match = GP_MatchBMP,
+
+ .fmt_name = "BMP",
+ .extensions = {"bmp", "dib", NULL},
+};
diff --git a/libs/loaders/GP_GIF.c b/libs/loaders/GP_GIF.c
index 0c286b97..6425d60a 100644
--- a/libs/loaders/GP_GIF.c
+++ b/libs/loaders/GP_GIF.c
@@ -400,3 +400,12 @@ GP_Context *GP_LoadGIF(const char GP_UNUSED(*src_path),
}
#endif /* HAVE_GIFLIB */
+
+struct GP_Loader GP_GIF = {
+ .Read = GP_ReadGIF,
+ .Load = GP_LoadGIF,
+ .Save = NULL,
+ .Match = GP_MatchGIF,
+ .fmt_name = "Graphics Interchange Format",
+ .extensions = {"gif", NULL},
+};
diff --git a/libs/loaders/GP_JP2.c b/libs/loaders/GP_JP2.c
index ef412ca8..f451b6f1 100644
--- a/libs/loaders/GP_JP2.c
+++ b/libs/loaders/GP_JP2.c
@@ -261,3 +261,13 @@ GP_Context *GP_LoadJP2(const char GP_UNUSED(*src_path),
}
#endif /* HAVE_OPENJPEG */
+
+struct GP_Loader GP_JP2 = {
+ .Read = GP_ReadJP2,
+ .Load = GP_LoadJP2,
+ .Save = NULL,
+ .Match = GP_MatchJP2,
+
+ .fmt_name = "JPEG 2000",
+ .extensions = {"jp2", "jpx", NULL},
+};
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
index 6fd5dd28..ca14b180 100644
--- a/libs/loaders/GP_JPG.c
+++ b/libs/loaders/GP_JPG.c
@@ -593,3 +593,13 @@ int GP_SaveJPG(const GP_Context GP_UNUSED(*src),
}
#endif /* HAVE_JPEG */
+
+struct GP_Loader GP_JPG = {
+ .Read = GP_ReadJPG,
+ .Load = GP_LoadJPG,
+ .Save = GP_SaveJPG,
+ .Match = GP_MatchJPG,
+
+ .fmt_name = "JPEG",
+ .extensions = {"jpg", "jpeg", NULL},
+};
diff --git a/libs/loaders/GP_Loader.c b/libs/loaders/GP_Loader.c
index d88bf5f6..c3b74feb 100644
--- a/libs/loaders/GP_Loader.c
+++ b/libs/loaders/GP_Loader.c
@@ -39,205 +39,116 @@
#include "loaders/GP_Loaders.h"
#include "loaders/GP_Loader.h"
-static GP_Loader psd_loader = {
- .Read = GP_ReadPSD,
- .Load = GP_LoadPSD,
- .Save = NULL,
- .Match = GP_MatchPSD,
- .fmt_name = "Adobe Photoshop Image",
- .next = NULL,
- .extensions = {"psd", NULL},
+#define MAX_LOADERS 64
+
+static GP_Loader *loaders[MAX_LOADERS] = {
+ &GP_JPG,
+ &GP_PNG,
+ &GP_TIFF,
+ &GP_GIF,
+ &GP_BMP,
+ &GP_PBM,
+ &GP_PNM,
+ &GP_PPM,
+ &GP_PNM,
+ &GP_JP2,
+ &GP_PCX,
+ &GP_PSP,
+ &GP_PSD,
};
-static GP_Loader psp_loader = {
- .Read = GP_ReadPSP,
- .Load = GP_LoadPSP,
- .Save = NULL,
- .Match = GP_MatchPSP,
- .fmt_name = "Paint Shop Pro Image",
- .next = &psd_loader,
- .extensions = {"psp", "pspimage", NULL},
-};
-
-static GP_Loader pcx_loader = {
- .Read = GP_ReadPCX,
- .Load = GP_LoadPCX,
- .Save = NULL,
- .Match = GP_MatchPCX,
- .fmt_name = "ZSoft PCX",
- .next = &psp_loader,
- .extensions = {"pcx", NULL},
-};
-
-static GP_Loader pbm_loader = {
- .Read = GP_ReadPBM,
- .Load = GP_LoadPBM,
- .Save = GP_SavePBM,
- .Match = GP_MatchPBM,
- .fmt_name = "Netpbm portable Bitmap",
- .next = &pcx_loader,
- .extensions = {"pbm", NULL},
-};
-
-static GP_Loader pgm_loader = {
- .Read = GP_ReadPGM,
- .Load = GP_LoadPGM,
- .Save = GP_SavePGM,
- .Match = GP_MatchPGM,
- .fmt_name = "Netpbm portable Graymap",
- .next = &pbm_loader,
- .extensions = {"pgm", NULL},
-};
-
-static GP_Loader ppm_loader = {
- .Read = GP_ReadPPM,
- .Load = GP_LoadPPM,
- .Save = GP_SavePPM,
- .Match = GP_MatchPPM,
- .fmt_name = "Netpbm portable Pixmap",
- .next = &pgm_loader,
- .extensions = {"ppm", NULL},
-};
-
-static GP_Loader pnm_loader = {
- .Read = GP_ReadPNM,
- .Load = GP_LoadPNM,
- .Save = GP_SavePNM,
- /*
- * Avoid double Match
- * This format is covered by PBM, PGM and PPM
- */
- .Match = NULL,
- .fmt_name = "Netpbm portable Anymap",
- .next = &ppm_loader,
- .extensions = {"pnm", NULL},
-};
+static unsigned int get_last_loader(void)
+{
+ unsigned int i;
-static GP_Loader jp2_loader = {
- .Read = GP_ReadJP2,
- .Load = GP_LoadJP2,
- .Save = NULL,
- .Match = GP_MatchJP2,
- .fmt_name = "JPEG 2000",
- .next = &pnm_loader,
- .extensions = {"jp2", "jpx", NULL},
-};
+ for (i = 0; i < MAX_LOADERS; i++) {
+ if (!loaders[i])
+ return i ? i - 1 : 0;
+ }
-static GP_Loader bmp_loader = {
- .Read = GP_ReadBMP,
- .Load = GP_LoadBMP,
- .Save = GP_SaveBMP,
- .Match = GP_MatchBMP,
- .fmt_name = "BMP",
- .next = &jp2_loader,
- .extensions = {"bmp", "dib", NULL},
-};
+ return i - 1;
+}
-static GP_Loader gif_loader = {
- .Read = GP_ReadGIF,
- .Load = GP_LoadGIF,
- .Save = NULL,
- .Match = GP_MatchGIF,
- .fmt_name = "Graphics Interchange Format",
- .next = &bmp_loader,
- .extensions = {"gif", NULL},
-};
+int GP_LoaderRegister(GP_Loader *self)
+{
+ unsigned int i;
-static GP_Loader tiff_loader = {
- .Read = GP_ReadTIFF,
- .Load = GP_LoadTIFF,
- .Save = GP_SaveTIFF,
- .Match = GP_MatchTIFF,
- .fmt_name = "Tag Image File Format",
- .next = &gif_loader,
- .extensions = {"tif", "tiff", NULL},
-};
+ GP_DEBUG(1, "Registering loader for '%s'", self->fmt_name);
-static GP_Loader png_loader = {
- .Read = GP_ReadPNG,
- .Load = GP_LoadPNG,
- .Save = GP_SavePNG,
- .Match = GP_MatchPNG,
- .fmt_name = "Portable Network Graphics",
- .next = &tiff_loader,
- .extensions = {"png", NULL},
-};
+ /* We have to keep the last terminating NULL */
+ for (i = 0; i < MAX_LOADERS - 2; i++) {
+ if (loaders[i] == self) {
+ GP_DEBUG(1, "Loader '%s' allready registered",
+ self->fmt_name);
+ errno = EEXIST;
+ return 1;
+ }
-static GP_Loader jpeg_loader = {
- .Read = GP_ReadJPG,
- .Load = GP_LoadJPG,
- .Save = GP_SaveJPG,
- .Match = GP_MatchJPG,
- .fmt_name = "JPEG",
- .next = &png_loader,
- .extensions = {"jpg", "jpeg", NULL},
-};
+ if (!loaders[i])
+ break;
+ }
-static GP_Loader *loaders = &jpeg_loader;
-static GP_Loader *loaders_last = &psp_loader;
+ if (loaders[i]) {
+ GP_DEBUG(1, "Loaders table is full");
+ errno = ENOSPC;
+ return 1;
+ }
-void GP_LoaderRegister(GP_Loader *self)
-{
- GP_DEBUG(1, "Registering loader for '%s'", self->fmt_name);
+ loaders[i] = self;
- self->next = NULL;
- loaders_last->next = self;
+ return 0;
}
void GP_LoaderUnregister(GP_Loader *self)
{
- struct GP_Loader *i;
+ unsigned int i, last = get_last_loader();
if (self == NULL)
return;
GP_DEBUG(1, "Unregistering loader for '%s'", self->fmt_name);
- for (i = loaders; i != NULL; i = i->next) {
- if (i->next == self)
- break;
- }
-
- if (i == NULL) {
- GP_WARN("Loader '%s' (%p) wasn't registered",
- self->fmt_name, self);
- return;
+ for (i = 0; loaders[i]; i++) {
+ if (loaders[i] == self) {
+ loaders[i] = loaders[last];
+ loaders[last] = NULL;
+ return;
+ }
}
- i->next = self->next;
+ GP_WARN("Loader '%s' (%p) wasn't registered", self->fmt_name, self);
}
void GP_ListLoaders(void)
{
- struct GP_Loader *i;
- int j;
-
- 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");
+ unsigned int i, j;
+
+ for (i = 0; loaders[i]; i++) {
+ printf("Format: %sn", loaders[i]->fmt_name);
+ printf("Read:t%sn", loaders[i]->Read ? "Yes" : "No");
+ printf("Load:t%sn", loaders[i]->Load ? "Yes" : "No");
+ printf("Save:t%sn", loaders[i]->Save ? "Yes" : "No");
+ printf("Match:t%sn", loaders[i]->Match ? "Yes" : "No");
printf("Extensions: ");
- for (j = 0; i->extensions[j] != NULL; j++)
- printf("%s ", i->extensions[j]);
+ for (j = 0; loaders[i]->extensions[j] != NULL; j++)
+ printf("%s ", loaders[i]->extensions[j]);
printf("n");
- if (i->next != NULL)
+ if (loaders[i+1] != NULL)
printf("n");
}
}
static struct GP_Loader *loader_by_extension(const char *ext)
{
- struct GP_Loader *i;
- int j;
-
- for (i = loaders; i != NULL; i = i->next) {
- for (j = 0; i->extensions[j] != NULL; j++) {
- if (!strcasecmp(ext, i->extensions[j])) {
- GP_DEBUG(1, "Found loader '%s'", i->fmt_name);
- return i;
+ unsigned int i, j;
+
+ for (i = 0; loaders[i]; i++) {
+ for (j = 0; loaders[i]->extensions[j] != NULL; j++) {
+ if (!strcasecmp(ext, loaders[i]->extensions[j])) {
+ GP_DEBUG(1, "Found loader '%s'",
+ loaders[i]->fmt_name);
+ return loaders[i];
}
}
}
@@ -460,12 +371,12 @@ int GP_SaveImage(const GP_Context *src, const char *dst_path,
const GP_Loader *GP_MatchSignature(const void *buf)
{
- struct GP_Loader *i;
+ unsigned int i;
- for (i = loaders; i != NULL; i = i->next) {
- if (i->Match && i->Match(buf) == 1) {
- GP_DEBUG(1, "Found loader '%s'", i->fmt_name);
- return i;
+ for (i = 0; loaders[i]; i++) {
+ if (loaders[i]->Match && loaders[i]->Match(buf) == 1) {
+ GP_DEBUG(1, "Found loader '%s'", loaders[i]->fmt_name);
+ return loaders[i];
}
}
diff --git a/libs/loaders/GP_PCX.c b/libs/loaders/GP_PCX.c
index 8d92c0f2..b04dc41b 100644
--- a/libs/loaders/GP_PCX.c
+++ b/libs/loaders/GP_PCX.c
@@ -565,3 +565,13 @@ GP_Context *GP_LoadPCX(const char *src_path, GP_ProgressCallback *callback)
return res;
}
+
+struct GP_Loader GP_PCX = {
+ .Read = GP_ReadPCX,
+ .Load = GP_LoadPCX,
+ .Save = NULL,
+ .Match = GP_MatchPCX,
+
+ .fmt_name = "ZSoft PCX",
+ .extensions = {"pcx", NULL},
+};
diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c
index 50f5fcdf..2da8bcef 100644
--- a/libs/loaders/GP_PNG.c
+++ b/libs/loaders/GP_PNG.c
@@ -653,3 +653,13 @@ int GP_SavePNG(const GP_Context GP_UNUSED(*src),
}
#endif /* HAVE_LIBPNG */
+
+GP_Loader GP_PNG = {
+ .Read = GP_ReadPNG,
+ .Load = GP_LoadPNG,
+ .Save = GP_SavePNG,
+ .Match = GP_MatchPNG,
+
+ .fmt_name = "Portable Network Graphics",
+ .extensions = {"png", NULL},
+};
diff --git a/libs/loaders/GP_PNM.c b/libs/loaders/GP_PNM.c
index 1a17e530..63bb5361 100644
--- a/libs/loaders/GP_PNM.c
+++ b/libs/loaders/GP_PNM.c
@@ -1226,3 +1226,47 @@ int GP_SavePNM(const GP_Context *src, const char *dst_path,
return 1;
}
}
+
+struct GP_Loader GP_PBM = {
+ .Read = GP_ReadPBM,
+ .Load = GP_LoadPBM,
+ .Save = GP_SavePBM,
+ .Match = GP_MatchPBM,
+
+ .fmt_name = "Netpbm portable Bitmap",
+ .extensions = {"pbm", NULL},
+};
+
+struct GP_Loader GP_PGM = {
+ .Read = GP_ReadPGM,
+ .Load = GP_LoadPGM,
+ .Save = GP_SavePGM,
+ .Match = GP_MatchPGM,
+
+ .fmt_name = "Netpbm portable Graymap",
+ .extensions = {"pgm", NULL},
+};
+
+struct GP_Loader GP_PPM = {
+ .Read = GP_ReadPPM,
+ .Load = GP_LoadPPM,
+ .Save = GP_SavePPM,
+ .Match = GP_MatchPPM,
+
+ .fmt_name = "Netpbm portable Pixmap",
+ .extensions = {"ppm", NULL},
+};
+
+struct GP_Loader GP_PNM = {
+ .Read = GP_ReadPNM,
+ .Load = GP_LoadPNM,
+ .Save = GP_SavePNM,
+ /*
+ * Avoid double Match
+ * This format is covered by PBM, PGM and PPM
+ */
+ .Match = NULL,
+
+ .fmt_name = "Netpbm portable Anymap",
+ .extensions = {"pnm", NULL},
+};
diff --git a/libs/loaders/GP_PSD.c b/libs/loaders/GP_PSD.c
index a3e5030d..5ef73f11 100644
--- a/libs/loaders/GP_PSD.c
+++ b/libs/loaders/GP_PSD.c
@@ -829,3 +829,13 @@ GP_Context *GP_LoadPSD(const char *src_path, GP_ProgressCallback *callback)
return res;
}
+
+struct GP_Loader GP_PSD = {
+ .Read = GP_ReadPSD,
+ .Load = GP_LoadPSD,
+ .Save = NULL,
+ .Match = GP_MatchPSD,
+
+ .fmt_name = "Adobe Photoshop Image",
+ .extensions = {"psd", NULL},
+};
diff --git a/libs/loaders/GP_PSP.c b/libs/loaders/GP_PSP.c
index d99ca03d..bacd4b9b 100644
--- a/libs/loaders/GP_PSP.c
+++ b/libs/loaders/GP_PSP.c
@@ -507,3 +507,12 @@ GP_Context *GP_LoadPSP(const char *src_path, GP_ProgressCallback *callback)
return res;
}
+
+struct GP_Loader GP_PSP = {
+ .Read = GP_ReadPSP,
+ .Load = GP_LoadPSP,
+ .Save = NULL,
+ .Match = GP_MatchPSP,
+ .fmt_name = "Paint Shop Pro Image",
+ .extensions = {"psp", "pspimage", NULL},
+};
diff --git a/libs/loaders/GP_TIFF.c b/libs/loaders/GP_TIFF.c
index 65513c77..1ea06554 100644
--- a/libs/loaders/GP_TIFF.c
+++ b/libs/loaders/GP_TIFF.c
@@ -762,3 +762,13 @@ int GP_SaveTIFF(const GP_Context GP_UNUSED(*src),
}
#endif /* HAVE_TIFF */
+
+struct GP_Loader GP_TIFF = {
+ .Read = GP_ReadTIFF,
+ .Load = GP_LoadTIFF,
+ .Save = GP_SaveTIFF,
+ .Match = GP_MatchTIFF,
+
+ .fmt_name = "Tag Image File Format",
+ .extensions = {"tif", "tiff", NULL},
+};
diff --git a/tests/loaders/Loader.c b/tests/loaders/Loader.c
new file mode 100644
index 00000000..4494825e
--- /dev/null
+++ b/tests/loaders/Loader.c
@@ -0,0 +1,164 @@
+/*****************************************************************************
+ * 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(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <errno.h>
+#include <core/GP_Common.h>
+#include <loaders/GP_Loaders.h>
+
+#include "tst_test.h"
+
+static GP_Loader dummy_loaders[1000];
+
+static int register_max_loaders(void)
+{
+ unsigned int cnt = 0, i;
+
+ for (;;) {
+ if (GP_LoaderRegister(&dummy_loaders[cnt])) {
+ if (errno != ENOSPC) {
+ tst_msg("Wrong errno %s (%i), expected ENOSPC",
+ tst_strerr(errno), errno);
+ return TST_FAILED;
+ }
+ break;
+ }
+ cnt++;
+
+ if (cnt >= GP_ARRAY_SIZE(dummy_loaders)) {
+ tst_msg("Failed to reach the max after %u", cnt);
+ return TST_FAILED;
+ }
+ }
+
+ tst_msg("Registered %u loaders", cnt);
+
+ /* Let's provoke SEGFAULT by walking the loaders list */
+ GP_ListLoaders();
+
+ for (i = 0; i < cnt; i++)
+ GP_LoaderUnregister(&dummy_loaders[i]);
+
+ for (i = 0; i < cnt; i++) {
+ if (GP_LoaderRegister(&dummy_loaders[i])) {
+ tst_msg("Failed to register %u loader (max=%u)",
+ i, cnt);
+ return TST_FAILED;
+ }
+ }
+
+ for (i = 0; i < cnt; i++)
+ GP_LoaderUnregister(&dummy_loaders[cnt - i - 1]);
+
+ return TST_SUCCESS;
+}
+
+static int register_loader_twice(void)
+{
+ int ret;
+
+ if (GP_LoaderRegister(dummy_loaders)) {
+ tst_msg("Failed to register loader %s (%i)",
+ tst_strerr(errno), errno);
+ return TST_FAILED;
+ }
+
+ if (GP_LoaderRegister(dummy_loaders)) {
+ if (errno != EEXIST) {
+ tst_msg("Loader failed but errno %s (%i)",
+ tst_strerr(errno), errno);
+ ret = TST_FAILED;
+ goto exit;
+ }
+
+ tst_msg("Second attempt to register loader fails with EEXIST");
+ ret = TST_SUCCESS;
+ goto exit;
+ }
+
+ tst_msg("Second attempt to register loader succeded");
+ ret = TST_FAILED;
+exit:
+ GP_LoaderUnregister(dummy_loaders);
+ return ret;
+}
+
+static GP_Loader test_loader = {
+ .fmt_name = "TEST",
+ .extensions = {"test", NULL},
+};
+
+static int loader_by_extension(void)
+{
+ const GP_Loader *loader;
+ int err = 0;
+
+ if (GP_LoaderRegister(&test_loader)) {
+ tst_msg("Failed to register loader %s (%i)",
+ tst_strerr(errno), errno);
+ return TST_FAILED;
+ }
+
+ loader = GP_MatchExtension("file.jpg");
+
+ if (loader != &GP_JPG) {
+ tst_msg("Failed to get JPEG loader");
+ err++;
+ } else {
+ tst_msg("Succeded to get JPEG loader");
+ }
+
+ loader = GP_MatchExtension("file.test");
+
+ if (loader != &test_loader) {
+ tst_msg("Failed to get registered TEST loader");
+ err++;
+ } else {
+ tst_msg("Succeded to get TEST loader");
+ }
+
+ GP_LoaderUnregister(&test_loader);
+
+ if (err)
+ return TST_FAILED;
+
+ return TST_SUCCESS;
+}
+
+const struct tst_suite tst_suite = {
+ .suite_name = "Loader",
+ .tests = {
+ /* Loader Register tests */
+ {.name = "LoaderRegister() max",
+ .tst_fn = register_max_loaders,
+ .flags = TST_CHECK_MALLOC},
+
+ {.name = "LoaderRegister() twice",
+ .tst_fn = register_loader_twice,
+ .flags = TST_CHECK_MALLOC},
+
+ {.name = "MatchExtension()",
+ .tst_fn = loader_by_extension,
+ .flags = TST_CHECK_MALLOC},
+
+ {.name = NULL},
+ }
+};
diff --git a/tests/loaders/Makefile b/tests/loaders/Makefile
index fb56086d..c483d412 100644
--- a/tests/loaders/Makefile
+++ b/tests/loaders/Makefile
@@ -2,11 +2,11 @@ TOPDIR=../..
include $(TOPDIR)/pre.mk
CSOURCES=loaders_suite.c PNG.c PBM.c PGM.c PPM.c ZIP.c GIF.c IO.c PNM.c PCX.c- JPG.c
+ JPG.c Loader.c
GENSOURCES=SaveLoad.gen.c SaveAbort.gen.c
APPS=loaders_suite PNG PBM PGM PPM PNM SaveLoad.gen SaveAbort.gen ZIP GIF PCX- IO JPG
+ IO JPG Loader
include ../tests.mk
diff --git a/tests/loaders/test_list.txt b/tests/loaders/test_list.txt
index adf857ea..dacb0f56 100644
--- a/tests/loaders/test_list.txt
+++ b/tests/loaders/test_list.txt
@@ -10,5 +10,6 @@ PNM
PCX
ZIP
IO
+Loader
SaveLoad.gen
SaveAbort.gen
http://repo.or.cz/w/gfxprim.git/commit/4bec01e5af42cb68e680f3a6d452d543b8c4…
commit 4bec01e5af42cb68e680f3a6d452d543b8c4d004
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 10:51:41 2014 +0200
tests: filters: Fix Makefile.
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/tests/filters/Makefile b/tests/filters/Makefile
index 8834428e..75889b5b 100644
--- a/tests/filters/Makefile
+++ b/tests/filters/Makefile
@@ -1,7 +1,7 @@
TOPDIR=../..
include $(TOPDIR)/pre.mk
-CSOURCES=FilterMirrorH.c
+CSOURCES=FilterMirrorH.c common.c
GENSOURCES=APICoverage.gen.c FiltersCompare.gen.c
@@ -11,8 +11,6 @@ include ../tests.mk
FilterMirrorH: common.o
-CLEAN+=common.o
-
include $(TOPDIR)/gen.mk
include $(TOPDIR)/app.mk
include $(TOPDIR)/post.mk
http://repo.or.cz/w/gfxprim.git/commit/e341668ccad607f9843386e206105f086ae3…
commit e341668ccad607f9843386e206105f086ae307d0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Jun 13 10:43:37 2014 +0200
tests: framework add tst_strerr()
Signed-off-by: Cyril Hrubis <metan(a)ucw.cz>
diff --git a/tests/framework/tst_msg.c b/tests/framework/tst_msg.c
index b4f150fb..e3fd07f5 100644
--- a/tests/framework/tst_msg.c
+++ b/tests/framework/tst_msg.c
@@ -92,3 +92,58 @@ void tst_msg_print(const struct tst_msg_store *self)
for (msg = self->first; msg != NULL; msg = msg->next)
fprintf(stderr, "%c: %sn", type_to_char(msg->type), msg->msg);
}
+
+#define ERR(err) + case err: + return #err +
+const char *tst_strerr(int err)
+{
+ switch (err) {
+ case 0:
+ return "SUCCESS";
+ /* asm-generic/errno-base.h */
+ ERR(EPERM);
+ ERR(ENOENT);
+ ERR(ESRCH);
+ ERR(EINTR);
+ ERR(EIO);
+ ERR(ENXIO);
+ ERR(E2BIG);
+ ERR(ENOEXEC);
+ ERR(EBADF);
+ ERR(ECHILD);
+ ERR(EAGAIN);
+ ERR(ENOMEM);
+ ERR(EACCES);
+ ERR(EFAULT);
+ ERR(ENOTBLK);
+ ERR(EBUSY);
+ ERR(EEXIST);
+ ERR(EXDEV);
+ ERR(ENODEV);
+ ERR(ENOTDIR);
+ ERR(EISDIR);
+ ERR(EINVAL);
+ ERR(ENFILE);
+ ERR(EMFILE);
+ ERR(ENOTTY);
+ ERR(ETXTBSY);
+ ERR(EFBIG);
+ ERR(ENOSPC);
+ ERR(ESPIPE);
+ ERR(EROFS);
+ ERR(EMLINK);
+ ERR(EPIPE);
+ ERR(EDOM);
+ ERR(ERANGE);
+
+ /* a few from asm-generic/errno.h */
+ ERR(EDEADLK);
+ ERR(ENAMETOOLONG);
+ ERR(ENOSYS);
+ ERR(ECANCELED);
+ default:
+ return "???";
+ }
+}
diff --git a/tests/framework/tst_test.h b/tests/framework/tst_test.h
index 4d65b1b6..182d96f5 100644
--- a/tests/framework/tst_test.h
+++ b/tests/framework/tst_test.h
@@ -130,4 +130,9 @@ int tst_warn(const char *fmt, ...)
int tst_err(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
+/*
+ * Translates errno number into short string, i.e. EFOO
+ */
+const char *tst_strerr(int err);
+
#endif /* TST_TEST_H */
-----------------------------------------------------------------------
Summary of changes:
build/syms/Loaders_symbols.txt | 13 ++
include/loaders/GP_BMP.h | 7 +-
include/loaders/GP_GIF.h | 6 +-
include/loaders/GP_JP2.h | 6 +-
include/loaders/GP_JPG.h | 7 +-
include/loaders/GP_Loader.h | 33 +++--
include/loaders/GP_PCX.h | 6 +-
include/loaders/GP_PNG.h | 7 +-
include/loaders/GP_PNM.h | 9 +-
include/loaders/GP_PSD.h | 6 +-
include/loaders/GP_PSP.h | 6 +-
include/loaders/GP_TIFF.h | 6 +-
libs/loaders/GP_BMP.c | 25 ++--
libs/loaders/GP_GIF.c | 37 ++----
libs/loaders/GP_JP2.c | 37 ++----
libs/loaders/GP_JPG.c | 42 +++----
libs/loaders/GP_Loader.c | 279 +++++++++++++++------------------------
libs/loaders/GP_PCX.c | 22 +--
libs/loaders/GP_PNG.c | 42 +++----
libs/loaders/GP_PNM.c | 136 +++++++++-----------
libs/loaders/GP_PSD.c | 22 +--
libs/loaders/GP_PSP.c | 23 +--
libs/loaders/GP_TIFF.c | 42 +++----
tests/filters/Makefile | 4 +-
tests/framework/tst_msg.c | 55 ++++++++
tests/framework/tst_test.h | 5 +
tests/loaders/Loader.c | 164 +++++++++++++++++++++++
tests/loaders/Makefile | 4 +-
tests/loaders/test_list.txt | 1 +
29 files changed, 572 insertions(+), 480 deletions(-)
create mode 100644 tests/loaders/Loader.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0